56 uint16_t
shift, result;
61 if (shift < 0x2 || shift > 0xd) {
63 }
else if (
shift < 0x8) {
79 for (
c = 0;
c < 10;
c++) {
82 if (
c&1) offs = (80 * 6 + 80 * 16 * 0 + 3 +
c*12000);
83 else offs = (80 * 6 + 80 * 16 * 3 + 3 +
c*12000);
86 if (
c&1) offs = (80 * 6 + 80 * 16 * 1 + 3 +
c*12000);
87 else offs = (80 * 6 + 80 * 16 * 4 + 3 +
c*12000);
90 if (
c&1) offs = (80 * 3 + 8 +
c*12000);
91 else offs = (80 * 5 + 48 + 5 +
c*12000);
94 offs = (80*1 + 3 + 3);
121 int size, chan,
i, j, d, of, smpls, freq,
quant, half_ch;
130 smpls = as_pack[1] & 0x3f;
131 freq = as_pack[4] >> 3 & 0x07;
132 quant = as_pack[4] & 0x07;
145 ipcm = (sys->
height == 720 && !(
frame[1] & 0x0C)) ? 2 : 0;
153 for (chan = 0; chan < sys->
n_difchan; chan++) {
162 if (
quant == 1 &&
i == half_ch) {
171 for (j = 0; j < 9; j++) {
172 for (d = 8; d < 80; d += 2) {
181 pcm[of * 2] =
frame[d + 1];
182 pcm[of * 2 + 1] =
frame[d];
184 if (pcm[of * 2 + 1] == 0x80 && pcm[of * 2] == 0x00)
187 lc = ((uint16_t)
frame[d] << 4) |
188 ((uint16_t)
frame[d + 2] >> 4);
189 rc = ((uint16_t)
frame[d + 1] << 4) |
190 ((uint16_t)
frame[d + 2] & 0x0f);
201 pcm[of * 2] = lc & 0xff;
202 pcm[of * 2 + 1] = lc >> 8;
207 pcm[of * 2] = rc & 0xff;
208 pcm[of * 2 + 1] = rc >> 8;
224 int freq, stype, smpls,
quant,
i, ach;
227 if (!as_pack || !
c->sys) {
232 smpls = as_pack[1] & 0x3f;
233 freq = as_pack[4] >> 3 & 0x07;
234 stype = as_pack[3] & 0x1f;
235 quant = as_pack[4] & 0x07;
239 "Unrecognized audio sample rate index (%d)\n", freq);
250 ach = ((
int[4]) { 1, 0, 2, 4 })[stype];
251 if (ach == 1 &&
quant && freq == 2)
255 for (
i = 0;
i < ach;
i++) {
265 c->audio_pkt[
i].size = 0;
266 c->audio_pkt[
i].data =
c->audio_buf[
i];
267 c->audio_pkt[
i].stream_index =
c->ast[
i]->index;
271 c->ast[
i]->codecpar->channels = 2;
274 c->ast[
i]->start_time = 0;
278 return (
c->sys->audio_min_samples[freq] + smpls) * 4;
287 par =
c->vst->codecpar;
290 c->sys->time_base.den);
291 c->vst->avg_frame_rate =
av_inv_q(
c->vst->time_base);
295 apt =
frame[4] & 0x07;
296 is16_9 = (vsc_pack && ((vsc_pack[2] & 0x07) == 0x02 ||
297 (!apt && (vsc_pack[2] & 0x07) == 0x07)));
298 c->vst->sample_aspect_ratio =
c->sys->sar[is16_9];
302 return c->sys->frame_size;
312 int prevent_df =
c->sys->ltc_divisor == 25 ||
c->sys->ltc_divisor == 50;
332 c->vst->codecpar->bit_rate = 25000000;
333 c->vst->start_time = 0;
359 for (
i = 0;
i <
c->ach;
i++) {
360 if (
c->ast[
i] &&
c->audio_pkt[
i].size) {
361 *
pkt =
c->audio_pkt[
i];
362 c->audio_pkt[
i].size = 0;
379 buf_size < c->sys->frame_size) {
386 for (
i = 0;
i <
c->ach;
i++) {
387 c->audio_pkt[
i].pos =
pos;
388 c->audio_pkt[
i].size =
size;
389 c->audio_pkt[
i].pts = (
c->sys->height == 720) ? (
c->frames & ~1) :
c->frames;
390 ppcm[
i] =
c->audio_buf[
i];
397 if (
c->sys->height == 720) {
399 c->audio_pkt[2].size =
c->audio_pkt[3].size = 0;
401 c->audio_pkt[0].size =
c->audio_pkt[1].size = 0;
421 int64_t timestamp,
int flags)
436 return offset +
s->internal->data_offset;
441 c->frames = frame_offset;
442 c->audio_pkt[0].size =
c->audio_pkt[1].size = 0;
443 c->audio_pkt[2].size =
c->audio_pkt[3].size = 0;
461 #define PARTIAL_FRAME_SIZE (3 * 80)
487 unsigned state, marker_pos = 0;
495 while ((
state & 0xffffff7f) != 0x1f07003f) {
500 if (
state == 0x003f0700 ||
state == 0xff3f0700)
519 if (!
c->dv_demux.sys) {
521 "Can't determine profile of DV input stream.\n");
527 c->dv_demux.sys->time_base);
545 if (!
c->dv_demux.sys)
547 size =
c->dv_demux.sys->frame_size;
551 }
else if (ret == 0) {
562 int64_t timestamp,
int flags)
577 unsigned marker_pos = 0;
581 int secondary_matches = 0;
588 if ((
state & 0x0007f840) == 0x00070000) {
591 if ((
state & 0xff07ff7f) == 0x1f07003f) {
593 if ((
state & 0xffffff7f) == 0x1f07003f) {
599 if (
state == 0x003f0700 ||
state == 0xff3f0700)
601 if (
state == 0xff3f0701 &&
i - marker_pos == 80)
606 if (matches && p->
buf_size / matches < 1024 * 1024) {
607 if (matches > 4 || firstmatch ||
608 (secondary_matches >= 10 &&
609 p->
buf_size / secondary_matches < 24000))
625 .extensions =
"dv,dif",
simple assert() macros that are a bit more flexible than ISO C assert().
#define av_assert0(cond)
assert() equivalent, that is always enabled.
int64_t avio_seek(AVIOContext *s, int64_t offset, int whence)
fseek() equivalent for AVIOContext.
#define AVIO_SEEKABLE_NORMAL
Seeking works like for a local file.
int64_t avio_size(AVIOContext *s)
Get the filesize.
int avio_feof(AVIOContext *s)
Similar to feof() but also returns nonzero on read errors.
static av_always_inline int64_t avio_tell(AVIOContext *s)
ftell() equivalent for AVIOContext.
int avio_read(AVIOContext *s, unsigned char *buf, int size)
Read size bytes from AVIOContext into buf.
unsigned int avio_rb32(AVIOContext *s)
int avio_r8(AVIOContext *s)
static int read_packet(void *opaque, uint8_t *buf, int buf_size)
void av_init_packet(AVPacket *pkt)
#define flags(name, subs,...)
audio channel layout utility functions
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.
static int read_header(FFV1Context *f)
#define AV_CH_LAYOUT_STEREO
#define AV_PKT_FLAG_KEY
The packet contains a keyframe.
AVStream * avformat_new_stream(AVFormatContext *s, const AVCodec *c)
Add a new stream to a media file.
int av_dict_set(AVDictionary **pm, const char *key, const char *value, int flags)
Set the given entry in *pm, overwriting an existing entry.
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
static av_always_inline AVRational av_inv_q(AVRational q)
Invert a rational.
int64_t av_rescale_q(int64_t a, AVRational bq, AVRational cq)
Rescale a 64-bit integer by 2 rational numbers.
void * av_mallocz(size_t size)
Allocate a memory block with alignment suitable for all memory accesses (including vectors if availab...
#define DV_MAX_FRAME_SIZE
largest possible DV frame, in bytes (1080i50)
common internal API header
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
static int read_seek(AVFormatContext *ctx, int stream_index, int64_t timestamp, int flags)
#define FF_ARRAY_ELEMS(a)
static int shift(int a, int b)
This struct describes the properties of an encoded stream.
int64_t bit_rate
The average bitrate of the encoded data (in bits per second).
const uint8_t(* audio_shuffle)[9]
This structure stores compressed data.
int flags
A combination of AV_PKT_FLAG values.
int64_t pts
Presentation timestamp in AVStream->time_base units; the time at which the decompressed packet will b...
int64_t pos
byte position in stream, -1 if unknown
This structure contains the data a format has to probe a file.
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.
Rational number (pair of numerator and denominator).
uint8_t audio_buf[4][8192]
uint8_t buf[DV_MAX_FRAME_SIZE]
char * av_timecode_make_smpte_tc_string2(char *buf, AVRational rate, uint32_t tcsmpte, int prevent_df, int skip_field)
Get the timecode string from the SMPTE timecode format.
#define AV_TIMECODE_STR_SIZE
static const uint8_t offset[127][2]