Go to the documentation of this file.
32 #include "config_components.h"
69 uint8_t audio_buf[4][8192];
84 if (shift < 0x2 || shift > 0xd) {
86 }
else if (
shift < 0x8) {
97 static const uint8_t *dv_extract_pack(
const uint8_t *
frame,
enum DVPackType t)
102 for (
c = 0;
c < 10;
c++) {
105 if (
c&1) offs = (80 * 6 + 80 * 16 * 0 + 3 +
c*12000);
106 else offs = (80 * 6 + 80 * 16 * 3 + 3 +
c*12000);
109 if (
c&1) offs = (80 * 6 + 80 * 16 * 1 + 3 +
c*12000);
110 else offs = (80 * 6 + 80 * 16 * 4 + 3 +
c*12000);
113 if (
c&1) offs = (80 * 3 + 8 +
c*12000);
114 else offs = (80 * 5 + 48 + 5 +
c*12000);
117 offs = (80*1 + 3 + 3);
122 if (
frame[offs] == t)
129 static const int dv_audio_frequency[3] = {
141 static int dv_extract_audio(
const uint8_t *
frame, uint8_t **ppcm,
144 int size, chan,
i, j,
d, of, smpls, freq,
quant, half_ch;
146 const uint8_t *as_pack;
153 smpls = as_pack[1] & 0x3f;
154 freq = as_pack[4] >> 3 & 0x07;
155 quant = as_pack[4] & 0x07;
168 ipcm = (sys->
height == 720 && !(
frame[1] & 0x0C)) ? 2 : 0;
176 for (chan = 0; chan < sys->
n_difchan; chan++) {
185 if (
quant == 1 &&
i == half_ch) {
194 for (j = 0; j < 9; j++) {
195 for (
d = 8;
d < 80;
d += 2) {
204 pcm[of * 2] =
frame[
d + 1];
205 pcm[of * 2 + 1] =
frame[
d];
207 if (pcm[of * 2 + 1] == 0x80 && pcm[of * 2] == 0x00)
210 lc = ((uint16_t)
frame[
d] << 4) |
211 ((uint16_t)
frame[
d + 2] >> 4);
212 rc = ((uint16_t)
frame[
d + 1] << 4) |
213 ((uint16_t)
frame[
d + 2] & 0x0f);
224 pcm[of * 2] = lc & 0xff;
225 pcm[of * 2 + 1] = lc >> 8;
230 pcm[of * 2] = rc & 0xff;
231 pcm[of * 2 + 1] = rc >> 8;
246 const uint8_t *as_pack;
247 int freq, stype, smpls,
quant,
i, ach, sr;
250 if (!as_pack || !
c->sys) {
255 smpls = as_pack[1] & 0x3f;
256 freq = as_pack[4] >> 3 & 0x07;
257 stype = as_pack[3] & 0x1f;
258 quant = as_pack[4] & 0x07;
262 "Unrecognized audio sample rate index (%d)\n", freq);
265 sr = dv_audio_frequency[freq];
274 ach = ((
int[4]) { 1, 0, 2, 4 })[stype];
275 if (ach == 1 &&
quant && freq == 2)
280 for (
i = 0;
i < ach;
i++) {
290 c->ast[
i]->start_time = 0;
291 c->ast[
i]->codecpar->bit_rate = 2 * sr * 16;
293 c->ast[
i]->codecpar->sample_rate = sr;
294 c->audio_pkt[
i].last_sample_rate = sr;
296 c->audio_pkt[
i].size = 0;
297 c->audio_pkt[
i].data =
c->audio_buf[
i];
298 c->audio_pkt[
i].stream_index =
c->ast[
i]->index;
301 c->audio_pkt[
i].duration = 0;
302 c->audio_pkt[
i].pos = -1;
305 c->audio_pkt[
i].sample_rate = sr;
309 return (
c->sys->audio_min_samples[freq] + smpls) * 4;
314 const uint8_t *vsc_pack;
318 par =
c->vst->codecpar;
320 c->vst->avg_frame_rate =
av_inv_q(
c->vst->time_base);
324 apt =
frame[4] & 0x07;
325 is16_9 = (vsc_pack && ((vsc_pack[2] & 0x07) == 0x02 ||
326 (!apt && (vsc_pack[2] & 0x07) == 0x07)));
327 c->vst->sample_aspect_ratio =
c->sys->sar[is16_9];
331 return c->sys->frame_size;
336 const uint8_t *tc_pack;
341 int prevent_df =
c->sys->ltc_divisor == 25 ||
c->sys->ltc_divisor == 50;
361 c->vst->start_time = 0;
379 if (dv_init_demux(
s,
c)) {
392 for (
i = 0;
i <
c->ach;
i++) {
393 if (
c->ast[
i] &&
c->audio_pkt[
i].size) {
407 if (dpkt->last_sample_rate != dpkt->sample_rate) {
411 dpkt->last_sample_rate = dpkt->sample_rate;
426 uint8_t *ppcm[5] = { 0 };
436 size = dv_extract_audio_info(
c,
buf);
442 c->ast[0]->time_base);
446 c->ast[0]->time_base);
452 next_pts_video :
c->next_pts_audio;
457 for (
i = 0;
i <
c->ach;
i++) {
465 ppcm[
i] =
c->audio_buf[
i];
468 dv_extract_audio(
buf, ppcm,
c->sys);
472 if (
c->sys->height == 720) {
474 c->audio_pkt[2].size =
c->audio_pkt[3].size = 0;
476 c->audio_pkt[0].size =
c->audio_pkt[1].size = 0;
482 size = dv_extract_video_info(
c,
buf);
525 c->frames = !
c->sys ? 0 :
527 c->next_pts_video = ts;
531 c->audio_pkt[0].size =
c->audio_pkt[1].size = 0;
532 c->audio_pkt[2].size =
c->audio_pkt[3].size = 0;
539 typedef struct RawDVContext {
550 #define PARTIAL_FRAME_SIZE (3 * 80)
551 uint8_t partial_frame[PARTIAL_FRAME_SIZE];
552 RawDVContext *
c =
s->priv_data;
558 if (
ret < PARTIAL_FRAME_SIZE) {
563 ret = dv_extract_timecode(&
c->dv_demux, partial_frame, timecode);
576 unsigned state, marker_pos = 0;
577 RawDVContext *
c =
s->priv_data;
580 if ((
ret = dv_init_demux(
s, &
c->dv_demux)) < 0)
584 while ((
state & 0xffffff7f) != 0x1f07003f) {
589 if (
state == 0x003f0700 ||
state == 0xff3f0700)
608 if (!
c->dv_demux.sys) {
610 "Can't determine profile of DV input stream.\n");
616 c->dv_demux.sys->time_base);
627 RawDVContext *
c =
s->priv_data;
634 if (!
c->dv_demux.sys)
636 size =
c->dv_demux.sys->frame_size;
640 }
else if (
ret == 0) {
653 RawDVContext *
r =
s->priv_data;
658 if (stream_index !=
c->vst->index)
659 timestamp =
av_rescale_q(timestamp,
s->streams[stream_index]->time_base,
662 offset = dv_frame_offset(
s,
c, ×tamp);
673 unsigned marker_pos = 0;
677 int secondary_matches = 0;
684 if ((
state & 0x0007f840) == 0x00070000) {
687 if ((
state & 0xff07ff7f) == 0x1f07003f) {
689 if ((
state & 0xffffff7f) == 0x1f07003f) {
695 if (
state == 0x003f0700 ||
state == 0xff3f0700)
697 if (
state == 0xff3f0701 &&
i - marker_pos == 80)
702 if (matches && p->
buf_size / matches < 1024 * 1024) {
703 if (matches > 4 || firstmatch ||
704 (secondary_matches >= 10 &&
705 p->
buf_size / secondary_matches < 24000))
716 .p.extensions =
"dv,dif",
717 .priv_data_size =
sizeof(RawDVContext),
724 #else // CONFIG_DV_DEMUXER
740 #endif // CONFIG_DV_DEMUXER
#define AV_TIMECODE_STR_SIZE
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFrame structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample they are references to shared objects When the negotiation mechanism computes the intersection of the formats supported at each end of a all references to both lists are replaced with a reference to the intersection And when a single format is eventually chosen for a link amongst the remaining all references to the list are updated That means that if a filter requires that its input and output have the same format amongst a supported all it has to do is use a reference to the same list of formats query_formats can leave some formats unset and return AVERROR(EAGAIN) to cause the negotiation mechanism toagain later. That can be used by filters with complex requirements to use the format negotiated on one link to set the formats supported on another. Frame references ownership and permissions
#define AV_CHANNEL_LAYOUT_STEREO
This struct describes the properties of an encoded stream.
AVStream * avformat_new_stream(AVFormatContext *s, const struct AVCodec *c)
Add a new stream to a media file.
For DV, one packet corresponds exactly to one frame.
int64_t duration
Duration of this packet in AVStream->time_base units, 0 if unknown.
int buf_size
Size of buf except extra allocated bytes.
int64_t avio_size(AVIOContext *s)
Get the filesize.
#define AV_PKT_FLAG_KEY
The packet contains a keyframe.
static int read_seek(AVFormatContext *ctx, int stream_index, int64_t timestamp, int flags)
if it could not because there are no more frames
static av_always_inline int64_t avio_tell(AVIOContext *s)
ftell() equivalent for AVIOContext.
#define DV_TIMESCALE_AUDIO
static const uint8_t quant[64]
unsigned int avio_rb32(AVIOContext *s)
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
#define FF_ARRAY_ELEMS(a)
static int read_packet(void *opaque, uint8_t *buf, int buf_size)
unsigned char * buf
Buffer must have AVPROBE_PADDING_SIZE of extra allocated bytes filled with zero.
#define av_assert0(cond)
assert() equivalent, that is always enabled.
int64_t data_offset
offset of the first packet
int64_t av_rescale_q(int64_t a, AVRational bq, AVRational cq)
Rescale a 64-bit integer by 2 rational numbers.
#define FFABS(a)
Absolute value, Note, INT_MIN / INT64_MIN result in undefined behavior as they are not representable ...
#define DV_TIMESCALE_VIDEO
static int read_header(FFV1Context *f)
and forward the result(frame or status change) to the corresponding input. If nothing is possible
Rational number (pair of numerator and denominator).
This structure contains the data a format has to probe a file.
Undefined Behavior In the C some operations are like signed integer dereferencing freed accessing outside allocated Undefined Behavior must not occur in a C it is not safe even if the output of undefined operations is unused The unsafety may seem nit picking but Optimizing compilers have in fact optimized code on the assumption that no undefined Behavior occurs Optimizing code based on wrong assumptions can and has in some cases lead to effects beyond the output of computations The signed integer overflow problem in speed critical code Code which is highly optimized and works with signed integers sometimes has the problem that often the output of the computation does not c
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
An AVChannelLayout holds information about the channel layout of audio data.
static int shift(int a, int b)
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.
int ff_add_param_change(AVPacket *pkt, int32_t channels, uint64_t channel_layout, int32_t sample_rate, int32_t width, int32_t height)
Add side data to a packet for changing parameters to the given values.
static uint16_t dv_audio_12to16(uint16_t sample)
#define AV_NOPTS_VALUE
Undefined timestamp value.
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
#define DV_MAX_FRAME_SIZE
largest possible DV frame, in bytes (1080i50)
int avio_r8(AVIOContext *s)
it s the only field you need to keep assuming you have a context There is some magic you don t need to care about around this just let it vf offset
int flags
A combination of AV_PKT_FLAG values.
#define i(width, name, range_min, range_max)
int64_t pts
Presentation timestamp in AVStream->time_base units; the time at which the decompressed packet will b...
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.
void * av_mallocz(size_t size)
Allocate a memory block with alignment suitable for all memory accesses (including vectors if availab...
static av_always_inline AVRational av_inv_q(AVRational q)
Invert a rational.
int64_t avio_seek(AVIOContext *s, int64_t offset, int whence)
fseek() equivalent for AVIOContext.
uint8_t * buf
actual buffer data
#define AVIO_SEEKABLE_NORMAL
Seeking works like for a local file.
int avio_read(AVIOContext *s, unsigned char *buf, int size)
Read size bytes from AVIOContext into buf.
static int read_probe(const AVProbeData *p)
const uint8_t(* audio_shuffle)[9]
This structure stores compressed data.
int av_dict_set(AVDictionary **pm, const char *key, const char *value, int flags)
Set the given entry in *pm, overwriting an existing entry.
int64_t pos
byte position in stream, -1 if unknown
#define flags(name, subs,...)
int64_t bit_rate
The average bitrate of the encoded data (in bits per second).
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
int avio_feof(AVIOContext *s)
Similar to feof() but also returns nonzero on read errors.