22 #include "libavutil/channel_layout.h"
23 #include "libavutil/common.h"
43 int field = timecode & 0xff;
44 int frame = fields_per_frame ? field / fields_per_frame : field;
45 int second = (timecode >> 8) & 0xff;
46 int minute = (timecode >> 16) & 0xff;
47 int hour = (timecode >> 24) & 0x1f;
48 int drop = (timecode >> 29) & 1;
53 snprintf(tmp,
sizeof(tmp),
"%02d:%02d:%02d%c%02d",
54 hour, minute, second, drop ?
';' :
':', frame);
72 if ((*length >> 24) || *length < 16)
88 static const uint8_t startcode[] = {0, 0, 0, 0, 1, 0xbc};
89 static const uint8_t endcode[] = {0, 0, 0, 0, 0xe1, 0xe2};
90 if (!memcmp(p->
buf, startcode,
sizeof(startcode)) &&
91 !memcmp(&p->
buf[16 -
sizeof(endcode)], endcode,
sizeof(endcode)))
235 if (fps < 1 || fps > 9) fps = 9;
236 return frame_rate_tab[fps - 1];
245 static const AVRational map[] = {{50, 1}, {60000, 1001}, {24, 1},
246 {25, 1}, {30000, 1001}};
247 int idx =
av_log2((flags & 0x7c0) >> 6);
271 else if (tag ==
TRACK_FPF && (value == 1 || value == 2))
273 }
else if (tlen == 8 && tag ==
TRACK_AUX)
295 if (map_cnt > 1000) {
299 if (pkt_len < 4 * map_cnt) {
304 pkt_len -= 4 * map_cnt;
306 for (i = 0; i < map_cnt; i++)
308 i * (uint64_t)fields_per_map + 1, 0, 0, 0);
346 int track_type, track_id, track_len;
354 if (!(track_type & 0x80)) {
359 if ((track_id & 0xc0) != 0xc0) {
366 if (track_type == 7 || track_type == 8 || track_type == 24) {
375 if (idx < 0)
continue;
377 if (!main_timebase.
num || !main_timebase.
den) {
407 if (!main_timebase.
num || !main_timebase.
den) {
409 " This might give wrong results.\n");
411 main_timebase.
num = fps.
den;
412 main_timebase.
den = fps.
num * 2;
430 if (!main_timebase.
num || !main_timebase.
den)
441 if (!max_interval-- || url_feof(pb)) \
443 tmp = tmp << 8 | avio_r8(pb); \
456 uint64_t last_found_pos = 0;
473 if (
avio_seek(pb, last_pos, SEEK_SET) < 0)
481 if ((track >= 0 && track != cur_track) || (timestamp >= 0 && timestamp > cur_timestamp)) {
482 if (
avio_seek(pb, last_pos, SEEK_SET) >= 0)
488 return cur_timestamp;
499 int track_type, track_id,
ret;
500 int field_nr, field_info, skip = 0;
522 stream_index =
get_sindex(s, track_id, track_type);
523 if (stream_index < 0)
533 int first = field_info >> 16;
534 int last = field_info & 0xffff;
536 if (first <= last && last*bps <= pkt_len) {
538 skip = pkt_len - last*
bps;
539 pkt_len = (last-first)*bps;
561 uint64_t maxlen = 100 * 1024 * 1024;
566 if (timestamp < start_time) timestamp =
start_time;
572 if (idx < st->nb_index_entries - 2)
574 maxlen =
FFMAX(maxlen, 200 * 1024);
579 if (
FFABS(found - timestamp) > 4)
585 int64_t *pos, int64_t pos_limit) {
static int gxf_packet(AVFormatContext *s, AVPacket *pkt)
static void gxf_track_tags(AVIOContext *pb, int *len, struct gxf_stream_info *si)
filters out interesting tags from track information.
int av_add_index_entry(AVStream *st, int64_t pos, int64_t timestamp, int size, int distance, int flags)
Add an index entry into a sorted list.
static void gxf_material_tags(AVIOContext *pb, int *len, struct gxf_stream_info *si)
filters out interesting tags from material information.
#define AV_LOG_WARNING
Something somehow does not look correct.
AVCodecContext * codec
Codec context associated with this stream.
void av_log(void *avcl, int level, const char *fmt,...) av_printf_format(3
Send the specified message to the log if the level is less than or equal to the current av_log_level...
#define AV_CH_LAYOUT_STEREO
static void gxf_read_index(AVFormatContext *s, int pkt_len)
read index from FLT packet into stream 0 av_index
static int gxf_seek(AVFormatContext *s, int stream_index, int64_t timestamp, int flags)
int block_align
number of bytes per packet if constant and known or 0 Used by some WAV based audio codecs...
static int64_t start_time
unsigned char * buf
Buffer must have AVPROBE_PADDING_SIZE of extra allocated bytes filled with zero.
enum AVStreamParseType need_parsing
int id
Format-specific stream ID.
AVIndexEntry * index_entries
Only used if the format does not support seeking natively.
int bits_per_coded_sample
bits per sample/pixel from the demuxer (needed for huffyuv).
AVStream * avformat_new_stream(AVFormatContext *s, const AVCodec *c)
Add a new stream to a media file.
int duration
Duration of this packet in AVStream->time_base units, 0 if unknown.
static int parse_packet_header(AVIOContext *pb, GXFPktType *type, int *length)
parses a packet header, extracting type and length
static AVRational fps_umf2avr(uint32_t flags)
convert UMF attributes flags to AVRational fps
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
int av_get_bits_per_sample(enum AVCodecID codec_id)
Return codec bits per sample.
int av_index_search_timestamp(AVStream *st, int64_t timestamp, int flags)
Get the index for a specific timestamp.
void * priv_data
Format private data.
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
AVInputFormat ff_gxf_demuxer
uint64_t channel_layout
Audio channel layout.
unsigned int nb_streams
A list of all streams in the file.
int bit_rate
the average bitrate
Opaque data information usually continuous.
static int add_timecode_metadata(AVDictionary **pm, const char *key, uint32_t timecode, int fields_per_frame)
parse gxf timecode and add it to metadata
static AVRational fps_tag2avr(int32_t fps)
convert fps tag value to AVRational fps
static int get_sindex(AVFormatContext *s, int id, int format)
gets the stream index for the track with the specified id, creates new stream if not found ...
preferred ID for MPEG-1/2 video decoding
#define AV_LOG_INFO
Standard information.
enum AVMediaType codec_type
int sample_rate
samples per second
AVIOContext * pb
I/O context.
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 numerator/denominator
Usually treated as AVMEDIA_TYPE_DATA.
This structure contains the data a format has to probe a file.
static int gxf_header(AVFormatContext *s)
static const AVRational frame_rate_tab[]
int64_t duration
Decoding: duration of the stream, in stream time base.
AVRational frames_per_second
static int64_t gxf_resync_media(AVFormatContext *s, uint64_t max_interval, int track, int timestamp)
resync the stream on the next media packet with specified properties
int64_t start_time
Decoding: pts of the first frame of the stream in presentation order, in stream time base...
static int64_t gxf_read_timestamp(AVFormatContext *s, int stream_index, int64_t *pos, int64_t pos_limit)
static int gxf_probe(AVProbeData *p)
check if file starts with a PKT_MAP header
int eof_reached
true if eof reached
uint8_t pi<< 24) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_U8, uint8_t,(*(constuint8_t *) pi-0x80)*(1.0f/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_U8, uint8_t,(*(constuint8_t *) pi-0x80)*(1.0/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S16, int16_t,(*(constint16_t *) pi >>8)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S16, int16_t,*(constint16_t *) pi *(1.0f/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S16, int16_t,*(constint16_t *) pi *(1.0/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S32, int32_t,(*(constint32_t *) pi >>24)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S32, int32_t,*(constint32_t *) pi *(1.0f/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S32, int32_t,*(constint32_t *) pi *(1.0/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_FLT, float, av_clip_uint8(lrintf(*(constfloat *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_FLT, float, av_clip_int16(lrintf(*(constfloat *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_FLT, float, av_clipl_int32(llrintf(*(constfloat *) pi *(1U<< 31)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_DBL, double, av_clip_uint8(lrint(*(constdouble *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_DBL, double, av_clip_int16(lrint(*(constdouble *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_DBL, double, av_clipl_int32(llrint(*(constdouble *) pi *(1U<< 31))))#defineSET_CONV_FUNC_GROUP(ofmt, ifmt) staticvoidset_generic_function(AudioConvert *ac){}voidff_audio_convert_free(AudioConvert **ac){return;ff_dither_free(&(*ac) ->dc);av_freep(ac);}AudioConvert *ff_audio_convert_alloc(AVAudioResampleContext *avr, enumAVSampleFormatout_fmt, enumAVSampleFormatin_fmt, intchannels, intsample_rate, intapply_map){AudioConvert *ac;intin_planar, out_planar;ac=av_mallocz(sizeof(*ac));returnNULL;ac->avr=avr;ac->out_fmt=out_fmt;ac->in_fmt=in_fmt;ac->channels=channels;ac->apply_map=apply_map;if(avr->dither_method!=AV_RESAMPLE_DITHER_NONE &&av_get_packed_sample_fmt(out_fmt)==AV_SAMPLE_FMT_S16 &&av_get_bytes_per_sample(in_fmt)>2){ac->dc=ff_dither_alloc(avr, out_fmt, in_fmt, channels, sample_rate, apply_map);if(!ac->dc){av_free(ac);returnNULL;}returnac;}in_planar=av_sample_fmt_is_planar(in_fmt);out_planar=av_sample_fmt_is_planar(out_fmt);if(in_planar==out_planar){ac->func_type=CONV_FUNC_TYPE_FLAT;ac->planes=in_planar?ac->channels:1;}elseif(in_planar) ac->func_type=CONV_FUNC_TYPE_INTERLEAVE;elseac->func_type=CONV_FUNC_TYPE_DEINTERLEAVE;set_generic_function(ac);ff_audio_convert_init_arm(ac);ff_audio_convert_init_x86(ac);returnac;}intff_audio_convert(AudioConvert *ac, AudioData *out, AudioData *in){intuse_generic=1;intlen=in->nb_samples;intp;if(ac->dc){av_dlog(ac->avr,"%dsamples-audio_convert:%sto%s(dithered)\n", len, av_get_sample_fmt_name(ac->in_fmt), av_get_sample_fmt_name(ac->out_fmt));returnff_convert_dither(ac-> out
int channels
number of audio channels
int64_t dts
Decompression timestamp in AVStream->time_base units; the time at which the packet is decompressed...
#define AV_CH_LAYOUT_MONO
This structure stores compressed data.
#define AV_NOPTS_VALUE
Undefined timestamp value.