57 uint16_t
shift, result;
59 sample = (sample < 0x800) ? sample : sample | 0xf000;
60 shift = (sample & 0xf00) >> 8;
62 if (shift < 0x2 || shift > 0xd) {
64 }
else if (shift < 0x8) {
69 result = ((sample + ((256 *
shift) + 1)) << shift) - 1;
80 for (c = 0; c < 10; c++) {
83 if (c&1) offs = (80 * 6 + 80 * 16 * 0 + 3 + c*12000);
84 else offs = (80 * 6 + 80 * 16 * 3 + 3 + c*12000);
87 if (c&1) offs = (80 * 6 + 80 * 16 * 1 + 3 + c*12000);
88 else offs = (80 * 6 + 80 * 16 * 4 + 3 + c*12000);
91 if (c&1) offs = (80 * 3 + 8 + c*12000);
92 else offs = (80 * 5 + 48 + 5 + c*12000);
95 offs = (80*1 + 3 + 3);
100 if (frame[offs] == t)
104 return frame[offs] == t ? &frame[offs] :
NULL;
122 int size, chan, i, j, d, of, smpls, freq,
quant, half_ch;
131 smpls = as_pack[1] & 0x3f;
132 freq = as_pack[4] >> 3 & 0x07;
133 quant = as_pack[4] & 0x07;
146 ipcm = (sys->
height == 720 && !(frame[1] & 0x0C)) ? 2 : 0;
148 if (ipcm + sys->
n_difchan > (quant == 1 ? 2 : 4)) {
154 for (chan = 0; chan < sys->
n_difchan; chan++) {
163 if (quant == 1 && i == half_ch) {
172 for (j = 0; j < 9; j++) {
173 for (d = 8; d < 80; d += 2) {
182 pcm[of * 2] = frame[d + 1];
183 pcm[of * 2 + 1] = frame[d];
185 if (pcm[of * 2 + 1] == 0x80 && pcm[of * 2] == 0x00)
188 lc = ((uint16_t)frame[d] << 4) |
189 ((uint16_t)frame[d + 2] >> 4);
190 rc = ((uint16_t)frame[d + 1] << 4) |
191 ((uint16_t)frame[d + 2] & 0x0f);
202 pcm[of * 2] = lc & 0xff;
203 pcm[of * 2 + 1] = lc >> 8;
208 pcm[of * 2] = rc & 0xff;
209 pcm[of * 2 + 1] = rc >> 8;
225 int freq, stype, smpls,
quant, i, ach;
228 if (!as_pack || !c->
sys) {
233 smpls = as_pack[1] & 0x3f;
234 freq = as_pack[4] >> 3 & 0x07;
235 stype = as_pack[3] & 0x1f;
236 quant = as_pack[4] & 0x07;
240 "Unrecognized audio sample rate index (%d)\n", freq);
251 ach = ((
int[4]) { 1, 0, 2, 4 })[stype];
252 if (ach == 1 && quant && freq == 2)
256 for (i = 0; i < ach; i++) {
296 apt = frame[4] & 0x07;
297 is16_9 = (vsc_pack && ((vsc_pack[2] & 0x07) == 0x02 ||
298 (!apt && (vsc_pack[2] & 0x07) == 0x07)));
303 return c->sys->frame_size;
352 for (i = 0; i < c->
ach; i++) {
372 buf_size < c->sys->frame_size) {
379 for (i = 0; i < c->
ach; i++) {
418 int64_t timestamp,
int flags)
424 int64_t max_offset = ((size - 1) / frame_size) *
frame_size;
426 offset = frame_size * timestamp;
428 if (size >= 0 && offset > max_offset)
446 c->audio_pkt[0].size =
c->audio_pkt[1].size = 0;
447 c->audio_pkt[2].size =
c->audio_pkt[3].size = 0;
465 int partial_frame_size = 3 * 80;
473 ret =
avio_read(s->
pb, partial_frame, partial_frame_size);
477 if (ret < partial_frame_size) {
496 unsigned state, marker_pos = 0;
504 while ((state & 0xffffff7f) != 0x1f07003f) {
509 if (state == 0x003f0700 || state == 0xff3f0700)
511 if (state == 0xff3f0701 &&
avio_tell(s->
pb) - marker_pos == 80) {
529 "Can't determine profile of DV input stream.\n");
535 c->dv_demux->sys->time_base);
559 }
else if (ret == 0) {
570 int64_t timestamp,
int flags)
592 unsigned marker_pos = 0;
596 int secondary_matches = 0;
601 for (i = 0; i < p->
buf_size-4; i++) {
603 if ((state & 0x0007f840) == 0x00070000) {
606 if ((state & 0xff07ff7f) == 0x1f07003f) {
608 if ((state & 0xffffff7f) == 0x1f07003f) {
614 if (state == 0x003f0700 || state == 0xff3f0700)
616 if (state == 0xff3f0701 && i - marker_pos == 80)
621 if (matches && p->
buf_size / matches < 1024 * 1024) {
622 if (matches > 4 || firstmatch ||
623 (secondary_matches >= 10 &&
624 p->
buf_size / secondary_matches < 24000))
641 .extensions =
"dv,dif",
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
int64_t avio_size(AVIOContext *s)
Get the filesize.
static int shift(int a, int b)
int64_t pos
byte position in stream, -1 if unknown
static int read_seek(AVFormatContext *ctx, int stream_index, int64_t timestamp, int flags)
enum AVCodecID codec_id
Specific type of the encoded data (the codec used).
AVRational sample_aspect_ratio
sample aspect ratio (0 if unknown)
int index
stream index in AVFormatContext
int64_t avio_seek(AVIOContext *s, int64_t offset, int whence)
fseek() equivalent for AVIOContext.
AVFormatInternal * internal
An opaque field for libavformat internal usage.
int64_t bit_rate
Total stream bitrate in bit/s, 0 if not available.
void * av_mallocz(size_t size)
Allocate a memory block with alignment suitable for all memory accesses (including vectors if availab...
#define AV_CH_LAYOUT_STEREO
This struct describes the properties of an encoded stream.
uint8_t audio_buf[4][8192]
#define av_assert0(cond)
assert() equivalent, that is always enabled.
unsigned int avio_rb32(AVIOContext *s)
AVStream * avformat_new_stream(AVFormatContext *s, const AVCodec *c)
Add a new stream to a media file.
uint64_t_TMPL AV_WL64 unsigned int_TMPL AV_WL32 unsigned int_TMPL AV_WL24 unsigned int_TMPL AV_WL16 uint64_t_TMPL AV_WB64 unsigned int_TMPL AV_RB32
static av_cold int read_close(AVFormatContext *ctx)
static av_always_inline int64_t avio_tell(AVIOContext *s)
ftell() equivalent for AVIOContext.
uint64_t channel_layout
Audio only.
int avio_read(AVIOContext *s, unsigned char *buf, int size)
Read size bytes from AVIOContext into buf.
int64_t bit_rate
The average bitrate of the encoded data (in bits per second).
#define AV_PKT_FLAG_KEY
The packet contains a keyframe.
const uint8_t(* audio_shuffle)[9]
int64_t av_rescale_q(int64_t a, AVRational bq, AVRational cq)
Rescale a 64-bit integer by 2 rational numbers.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
AVDictionary * metadata
Metadata that applies to the whole file.
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
const AVDVProfile * av_dv_frame_profile(const AVDVProfile *sys, const uint8_t *frame, unsigned buf_size)
Get a DV profile for the provided compressed frame.
enum AVMediaType codec_type
General type of the encoded data.
simple assert() macros that are a bit more flexible than ISO C assert().
static const uint8_t offset[127][2]
AVRational avg_frame_rate
Average framerate.
int flags
A combination of AV_PKT_FLAG values.
int avio_r8(AVIOContext *s)
int buf_size
Size of buf except extra allocated bytes.
unsigned char * buf
Buffer must have AVPROBE_PADDING_SIZE of extra allocated bytes filled with zero.
audio channel layout utility functions
DVDemuxContext * dv_demux
#define FF_ARRAY_ELEMS(a)
static int read_header(FFV1Context *f)
static int read_packet(void *opaque, uint8_t *buf, int buf_size)
#define AVIO_SEEKABLE_NORMAL
Seeking works like for a local file.
AVIOContext * pb
I/O context.
#define DV_MAX_FRAME_SIZE
largest possible DV frame, in bytes (1080i50)
int av_dict_set(AVDictionary **pm, const char *key, const char *value, int flags)
Set the given entry in *pm, overwriting an existing entry.
Rational number (pair of numerator and denominator).
This structure contains the data a format has to probe a file.
char * av_timecode_make_smpte_tc_string(char *buf, uint32_t tcsmpte, int prevent_df)
Get the timecode string from the SMPTE timecode format.
static av_always_inline AVRational av_inv_q(AVRational q)
Invert a rational.
int sample_rate
Audio only.
int64_t start_time
Decoding: pts of the first frame of the stream in presentation order, in stream time base...
uint8_t buf[DV_MAX_FRAME_SIZE]
void av_init_packet(AVPacket *pkt)
Initialize optional fields of a packet with default values.
void * priv_data
Format private data.
AVCodecParameters * codecpar
int avio_feof(AVIOContext *s)
feof() equivalent for AVIOContext.
AVRational time_base
This is the fundamental unit of time (in seconds) in terms of which frame timestamps are represented...
This structure stores compressed data.
int64_t pts
Presentation timestamp in AVStream->time_base units; the time at which the decompressed packet will b...
#define AV_TIMECODE_STR_SIZE