On 2014-01-16 03:55:44 +0100, Diego Biurrun wrote: > Also adjust some comment wording and spelling. > --- > libavformat/utils.c | 1666 > +++++++++++++++++++++++++++------------------------ > 1 file changed, 899 insertions(+), 767 deletions(-) > > diff --git a/libavformat/utils.c b/libavformat/utils.c > index db92f81..4fee6ec 100644 > --- a/libavformat/utils.c > +++ b/libavformat/utils.c > @@ -19,35 +19,35 @@ > * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 > USA > */ > > +#undef NDEBUG > +#include <assert.h> > +#include <stdarg.h> > #include <stdint.h> > > -#include "avformat.h" > -#include "avio_internal.h" > -#include "internal.h" > -#include "libavcodec/internal.h" > -#include "libavcodec/bytestream.h" > -#include "libavutil/opt.h" > -#include "libavutil/dict.h" > -#include "libavutil/internal.h" > -#include "libavutil/pixdesc.h" > -#include "metadata.h" > -#include "id3v2.h" > +#include "config.h" > #include "libavutil/avassert.h" > #include "libavutil/avstring.h" > #include "libavutil/mathematics.h" > #include "libavutil/parseutils.h" > #include "libavutil/time.h" > -#include "riff.h" > +#include "libavutil/opt.h" > +#include "libavutil/dict.h" > +#include "libavutil/internal.h" > +#include "libavutil/pixdesc.h" > +#include "libavcodec/bytestream.h" > +#include "libavcodec/internal.h" > #include "audiointerleave.h" > +#include "avformat.h" > +#include "avio_internal.h" > +#include "id3v2.h" > +#include "internal.h" > +#include "metadata.h" > +#include "riff.h" > #include "url.h" > -#include <stdarg.h> > #if CONFIG_NETWORK > #include "network.h" > #endif > > -#undef NDEBUG > -#include <assert.h> > -
also reorders headers, please add that to commit message > /** > * @file > * various utility functions for use within Libav > @@ -72,25 +72,21 @@ const char *avformat_license(void) > /* an arbitrarily chosen "sane" max packet size -- 50M */ > #define SANE_CHUNK_SIZE (50000000) > > -/* > - * Read the data in sane-sized chunks and append to pkt. > - * Return the number of bytes read or an error. > - */ > +/* Read the data in sane-sized chunks and append to pkt. > + * Return the number of bytes read or an error. */ > static int append_packet_chunked(AVIOContext *s, AVPacket *pkt, int size) > { > int64_t chunk_size = size; > - int64_t orig_pos = pkt->pos; // av_grow_packet might reset pos > - int orig_size = pkt->size; > + int64_t orig_pos = pkt->pos; // av_grow_packet might reset pos > + int orig_size = pkt->size; this incomplete vertical alignment looks strange after the patch, leave it as it is > int ret = 0; > > do { > int prev_size = pkt->size; > int read_size; > > - /* > - * When the caller requests a lot of data, limit it to the amount > left > - * in file or SANE_CHUNK_SIZE when it is not known > - */ > + /* When the caller requests a lot of data, limit it to the amount > + * left in file or SANE_CHUNK_SIZE when it is not known. */ > if (size > SANE_CHUNK_SIZE) { > int64_t filesize = avio_size(s) - avio_tell(s); > chunk_size = FFMAX(filesize, SANE_CHUNK_SIZE); > @@ -133,14 +129,15 @@ int av_append_packet(AVIOContext *s, AVPacket *pkt, int > size) > return append_packet_chunked(s, pkt, size); > } > > - > int av_filename_number_test(const char *filename) > { > char buf[1024]; > - return filename && (av_get_frame_filename(buf, sizeof(buf), filename, > 1)>=0); > + return filename && > + (av_get_frame_filename(buf, sizeof(buf), filename, 1) >= 0); > } > > -AVInputFormat *av_probe_input_format2(AVProbeData *pd, int is_opened, int > *score_max) > +AVInputFormat *av_probe_input_format2(AVProbeData *pd, int is_opened, > + int *score_max) > { > AVProbeData lpd = *pd; > AVInputFormat *fmt1 = NULL, *fmt; > @@ -149,7 +146,7 @@ AVInputFormat *av_probe_input_format2(AVProbeData *pd, > int is_opened, int *score > if (lpd.buf_size > 10 && ff_id3v2_match(lpd.buf, ID3v2_DEFAULT_MAGIC)) { > int id3len = ff_id3v2_tag_len(lpd.buf); > if (lpd.buf_size > id3len + 16) { > - lpd.buf += id3len; > + lpd.buf += id3len; > lpd.buf_size -= id3len; > } > id3 = 1; > @@ -163,21 +160,21 @@ AVInputFormat *av_probe_input_format2(AVProbeData *pd, > int is_opened, int *score > if (fmt1->read_probe) { > score = fmt1->read_probe(&lpd); > } else if (fmt1->extensions) { > - if (av_match_ext(lpd.filename, fmt1->extensions)) { > + if (av_match_ext(lpd.filename, fmt1->extensions)) > score = AVPROBE_SCORE_EXTENSION; > - } > } > if (score > *score_max) { > *score_max = score; > - fmt = fmt1; > - }else if (score == *score_max) > + fmt = fmt1; > + } else if (score == *score_max) > fmt = NULL; > } > > - /* a hack for files with huge id3v2 tags -- try to guess by file > extension. */ > + // A hack for files with huge id3v2 tags -- try to guess by file > extension sneaky way to shorten the line to 80 chars > if (!fmt && is_opened && *score_max < AVPROBE_SCORE_EXTENSION / 2) { > while ((fmt = av_iformat_next(fmt))) > - if (fmt->extensions && av_match_ext(lpd.filename, > fmt->extensions)) { > + if (fmt->extensions && > + av_match_ext(lpd.filename, fmt->extensions)) { > *score_max = AVPROBE_SCORE_EXTENSION / 2; > break; > } > @@ -194,23 +191,27 @@ AVInputFormat *av_probe_input_format2(AVProbeData *pd, > int is_opened, int *score > return fmt; > } > > -AVInputFormat *av_probe_input_format(AVProbeData *pd, int is_opened){ > - int score=0; > +AVInputFormat *av_probe_input_format(AVProbeData *pd, int is_opened) > +{ > + int score = 0; > return av_probe_input_format2(pd, is_opened, &score); > } > > -static int set_codec_from_probe_data(AVFormatContext *s, AVStream *st, > AVProbeData *pd, int score) > +static int set_codec_from_probe_data(AVFormatContext *s, AVStream *st, > + AVProbeData *pd, int score) > { > static const struct { > - const char *name; enum AVCodecID id; enum AVMediaType type; > + const char *name; > + enum AVCodecID id; > + enum AVMediaType type; > } fmt_id_type[] = { > - { "aac" , AV_CODEC_ID_AAC , AVMEDIA_TYPE_AUDIO }, > - { "ac3" , AV_CODEC_ID_AC3 , AVMEDIA_TYPE_AUDIO }, > - { "dts" , AV_CODEC_ID_DTS , AVMEDIA_TYPE_AUDIO }, > - { "eac3" , AV_CODEC_ID_EAC3 , AVMEDIA_TYPE_AUDIO }, > - { "h264" , AV_CODEC_ID_H264 , AVMEDIA_TYPE_VIDEO }, > - { "m4v" , AV_CODEC_ID_MPEG4 , AVMEDIA_TYPE_VIDEO }, > - { "mp3" , AV_CODEC_ID_MP3 , AVMEDIA_TYPE_AUDIO }, > + { "aac", AV_CODEC_ID_AAC, AVMEDIA_TYPE_AUDIO }, > + { "ac3", AV_CODEC_ID_AC3, AVMEDIA_TYPE_AUDIO }, > + { "dts", AV_CODEC_ID_DTS, AVMEDIA_TYPE_AUDIO }, > + { "eac3", AV_CODEC_ID_EAC3, AVMEDIA_TYPE_AUDIO }, > + { "h264", AV_CODEC_ID_H264, AVMEDIA_TYPE_VIDEO }, > + { "m4v", AV_CODEC_ID_MPEG4, AVMEDIA_TYPE_VIDEO }, > + { "mp3", AV_CODEC_ID_MP3, AVMEDIA_TYPE_AUDIO }, > { "mpegvideo", AV_CODEC_ID_MPEG2VIDEO, AVMEDIA_TYPE_VIDEO }, > { 0 } > }; > @@ -218,8 +219,10 @@ static int set_codec_from_probe_data(AVFormatContext *s, > AVStream *st, AVProbeDa > > if (fmt) { > int i; > - av_log(s, AV_LOG_DEBUG, "Probe with size=%d, packets=%d detected %s > with score=%d\n", > - pd->buf_size, MAX_PROBE_PACKETS - st->probe_packets, > fmt->name, score); > + av_log(s, AV_LOG_DEBUG, > + "Probe with size=%d, packets=%d detected %s with score=%d\n", > + pd->buf_size, MAX_PROBE_PACKETS - st->probe_packets, > + fmt->name, score); if you split the format string you could get rid of one line, also 'av_log(s, AV_LOG_DEBUG,\n' lloks ugly > for (i = 0; fmt_id_type[i].name; i++) { > if (!strcmp(fmt->name, fmt_id_type[i].name)) { > st->codec->codec_id = fmt_id_type[i].id; > @@ -236,7 +239,7 @@ static int set_codec_from_probe_data(AVFormatContext *s, > AVStream *st, AVProbeDa > > /** size of probe buffer, for guessing file type from file contents */ > #define PROBE_BUF_MIN 2048 > -#define PROBE_BUF_MAX (1<<20) > +#define PROBE_BUF_MAX (1 << 20) > > int av_probe_input_buffer(AVIOContext *pb, AVInputFormat **fmt, > const char *filename, void *logctx, > @@ -246,35 +249,35 @@ int av_probe_input_buffer(AVIOContext *pb, > AVInputFormat **fmt, > uint8_t *buf = NULL; > int ret = 0, probe_size; > > - if (!max_probe_size) { > + if (!max_probe_size) > max_probe_size = PROBE_BUF_MAX; > - } else if (max_probe_size > PROBE_BUF_MAX) { > + else if (max_probe_size > PROBE_BUF_MAX) > max_probe_size = PROBE_BUF_MAX; > - } else if (max_probe_size < PROBE_BUF_MIN) { > + else if (max_probe_size < PROBE_BUF_MIN) > return AVERROR(EINVAL); > - } > > - if (offset >= max_probe_size) { > + if (offset >= max_probe_size) > return AVERROR(EINVAL); > - } > avio_skip(pb, offset); > max_probe_size -= offset; > > - for(probe_size= PROBE_BUF_MIN; probe_size<=max_probe_size && !*fmt; > - probe_size = FFMIN(probe_size<<1, FFMAX(max_probe_size, > probe_size+1))) { > - int score = probe_size < max_probe_size ? AVPROBE_SCORE_MAX/4 : 0; > + for (probe_size = PROBE_BUF_MIN; probe_size <= max_probe_size && !*fmt; > + probe_size = FFMIN(probe_size << 1, > + FFMAX(max_probe_size, probe_size + 1))) { > + int score = probe_size < max_probe_size ? AVPROBE_SCORE_MAX / 4 : 0; > > /* read probe data */ > if ((ret = av_reallocp(&buf, probe_size + AVPROBE_PADDING_SIZE)) < 0) > return ret; > - if ((ret = avio_read(pb, buf + pd.buf_size, probe_size - > pd.buf_size)) < 0) { > + if ((ret = avio_read(pb, buf + pd.buf_size, > + probe_size - pd.buf_size)) < 0) { > /* fail if error was not end of file, otherwise, lower score */ > if (ret != AVERROR_EOF) { > av_free(buf); > return ret; > } > score = 0; > - ret = 0; /* error was end of file, nothing read */ > + ret = 0; /* error was end of file, nothing read */ > } > pd.buf_size += ret; > pd.buf = buf; > @@ -283,11 +286,15 @@ int av_probe_input_buffer(AVIOContext *pb, > AVInputFormat **fmt, > > /* guess file format */ > *fmt = av_probe_input_format2(&pd, 1, &score); > - if(*fmt){ > - if(score <= AVPROBE_SCORE_MAX/4){ //this can only be true in the > last iteration > - av_log(logctx, AV_LOG_WARNING, "Format detected only with > low score of %d, misdetection possible!\n", score); > - }else > - av_log(logctx, AV_LOG_DEBUG, "Probed with size=%d and > score=%d\n", probe_size, score); > + if (*fmt) { > + /* this can only be true in the last iteration */ > + if (score <= AVPROBE_SCORE_MAX / 4) { > + av_log(logctx, AV_LOG_WARNING, > + "Format detected only with low score of %d, " > + "misdetection possible!\n", score); > + } else > + av_log(logctx, AV_LOG_DEBUG, > + "Probed with size=%d and score=%d\n", probe_size, > score); see above > } > } > > @@ -296,29 +303,31 @@ int av_probe_input_buffer(AVIOContext *pb, > AVInputFormat **fmt, > return AVERROR_INVALIDDATA; > } > > - /* rewind. reuse probe buffer to avoid seeking */ > + /* Rewind. Reuse probe buffer to avoid seeking. */ > if ((ret = ffio_rewind_with_probe_data(pb, buf, pd.buf_size)) < 0) > av_free(buf); > > return ret; > } > > -/* open input file and probe the format if necessary */ > -static int init_input(AVFormatContext *s, const char *filename, AVDictionary > **options) > +/* Open input file and probe the format if necessary. */ > +static int init_input(AVFormatContext *s, const char *filename, > + AVDictionary **options) > { > int ret; > - AVProbeData pd = {filename, NULL, 0}; > + AVProbeData pd = { filename, NULL, 0 }; > > if (s->pb) { > s->flags |= AVFMT_FLAG_CUSTOM_IO; > if (!s->iformat) > - return av_probe_input_buffer(s->pb, &s->iformat, filename, s, 0, > s->probesize); > + return av_probe_input_buffer(s->pb, &s->iformat, filename, > + s, 0, s->probesize); > else if (s->iformat->flags & AVFMT_NOFILE) > return AVERROR(EINVAL); > return 0; > } > > - if ( (s->iformat && s->iformat->flags & AVFMT_NOFILE) || > + if ((s->iformat && s->iformat->flags & AVFMT_NOFILE) || > (!s->iformat && (s->iformat = av_probe_input_format(&pd, 0)))) > return 0; > > @@ -327,11 +336,13 @@ static int init_input(AVFormatContext *s, const char > *filename, AVDictionary **o > return ret; > if (s->iformat) > return 0; > - return av_probe_input_buffer(s->pb, &s->iformat, filename, s, 0, > s->probesize); > + return av_probe_input_buffer(s->pb, &s->iformat, filename, > + s, 0, s->probesize); > } > > static AVPacket *add_to_pktbuf(AVPacketList **packet_buffer, AVPacket *pkt, > - AVPacketList **plast_pktl){ > + AVPacketList **plast_pktl) > +{ > AVPacketList *pktl = av_mallocz(sizeof(AVPacketList)); > if (!pktl) > return NULL; > @@ -343,7 +354,7 @@ static AVPacket *add_to_pktbuf(AVPacketList > **packet_buffer, AVPacket *pkt, > > /* add the packet in the buffered packet list */ > *plast_pktl = pktl; > - pktl->pkt= *pkt; > + pktl->pkt = *pkt; > return &pktl->pkt; > } > > @@ -354,16 +365,18 @@ static int queue_attached_pictures(AVFormatContext *s) > if (s->streams[i]->disposition & AV_DISPOSITION_ATTACHED_PIC && > s->streams[i]->discard < AVDISCARD_ALL) { > AVPacket copy = s->streams[i]->attached_pic; > - copy.buf = av_buffer_ref(copy.buf); > + copy.buf = av_buffer_ref(copy.buf); > if (!copy.buf) > return AVERROR(ENOMEM); > > - add_to_pktbuf(&s->raw_packet_buffer, ©, > &s->raw_packet_buffer_end); > + add_to_pktbuf(&s->raw_packet_buffer, ©, > + &s->raw_packet_buffer_end); > } > return 0; > } > > -int avformat_open_input(AVFormatContext **ps, const char *filename, > AVInputFormat *fmt, AVDictionary **options) > +int avformat_open_input(AVFormatContext **ps, const char *filename, > + AVInputFormat *fmt, AVDictionary **options) > { > AVFormatContext *s = *ps; > int ret = 0; > @@ -402,7 +415,7 @@ int avformat_open_input(AVFormatContext **ps, const char > *filename, AVInputForma > goto fail; > } > if (s->iformat->priv_class) { > - *(const AVClass**)s->priv_data = s->iformat->priv_class; > + *(const AVClass **) s->priv_data = s->iformat->priv_class; > av_opt_set_defaults(s->priv_data); > if ((ret = av_opt_set_dict(s->priv_data, &tmp)) < 0) > goto fail; > @@ -451,7 +464,7 @@ fail: > > static int probe_codec(AVFormatContext *s, AVStream *st, const AVPacket *pkt) > { > - if(st->codec->codec_id == AV_CODEC_ID_PROBE){ > + if (st->codec->codec_id == AV_CODEC_ID_PROBE) { > AVProbeData *pd = &st->probe_data; > av_log(s, AV_LOG_DEBUG, "probing stream %d\n", st->index); > --st->probe_packets; > @@ -461,23 +474,24 @@ static int probe_codec(AVFormatContext *s, AVStream > *st, const AVPacket *pkt) > if ((err = av_reallocp(&pd->buf, pd->buf_size + pkt->size + > AVPROBE_PADDING_SIZE)) < 0) > return err; > - memcpy(pd->buf+pd->buf_size, pkt->data, pkt->size); > + memcpy(pd->buf + pd->buf_size, pkt->data, pkt->size); > pd->buf_size += pkt->size; > - memset(pd->buf+pd->buf_size, 0, AVPROBE_PADDING_SIZE); > + memset(pd->buf + pd->buf_size, 0, AVPROBE_PADDING_SIZE); > } else { > st->probe_packets = 0; > if (!pd->buf_size) { > - av_log(s, AV_LOG_ERROR, "nothing to probe for stream %d\n", > - st->index); > + av_log(s, AV_LOG_ERROR, > + "nothing to probe for stream %d\n", st->index); > return 0; > } > } > > if (!st->probe_packets || > av_log2(pd->buf_size) != av_log2(pd->buf_size - pkt->size)) { > - set_codec_from_probe_data(s, st, pd, st->probe_packets > 0 ? > AVPROBE_SCORE_MAX/4 : 0); > - if(st->codec->codec_id != AV_CODEC_ID_PROBE){ > - pd->buf_size=0; > + set_codec_from_probe_data(s, st, pd, st->probe_packets > 0 > + ? AVPROBE_SCORE_MAX / 4 : > 0); > + if (st->codec->codec_id != AV_CODEC_ID_PROBE) { > + pd->buf_size = 0; > av_freep(&pd->buf); > av_log(s, AV_LOG_DEBUG, "probed stream %d\n", st->index); > } > @@ -491,23 +505,23 @@ int ff_read_packet(AVFormatContext *s, AVPacket *pkt) > int ret, i, err; > AVStream *st; > > - for(;;){ > + for (;;) { > AVPacketList *pktl = s->raw_packet_buffer; > > if (pktl) { > *pkt = pktl->pkt; > - st = s->streams[pkt->stream_index]; > - if (st->codec->codec_id != AV_CODEC_ID_PROBE || > !st->probe_packets || > + st = s->streams[pkt->stream_index]; > + if (st->codec->codec_id != AV_CODEC_ID_PROBE || > + !st->probe_packets || > s->raw_packet_buffer_remaining_size < pkt->size) { > AVProbeData *pd; > - if (st->probe_packets) { > + if (st->probe_packets) > if ((err = probe_codec(s, st, NULL)) < 0) > return err; > - } > pd = &st->probe_data; > av_freep(&pd->buf); > pd->buf_size = 0; > - s->raw_packet_buffer = pktl->next; > + s->raw_packet_buffer = pktl->next; > s->raw_packet_buffer_remaining_size += pkt->size; > av_free(pktl); > return 0; > @@ -517,16 +531,15 @@ int ff_read_packet(AVFormatContext *s, AVPacket *pkt) > pkt->data = NULL; > pkt->size = 0; > av_init_packet(pkt); > - ret= s->iformat->read_packet(s, pkt); > + ret = s->iformat->read_packet(s, pkt); > if (ret < 0) { > if (!pktl || ret == AVERROR(EAGAIN)) > return ret; > for (i = 0; i < s->nb_streams; i++) { > st = s->streams[i]; > - if (st->probe_packets) { > + if (st->probe_packets) > if ((err = probe_codec(s, st, NULL)) < 0) > return err; > - } > } > continue; > } > @@ -540,22 +553,25 @@ int ff_read_packet(AVFormatContext *s, AVPacket *pkt) > continue; > } > > - st= s->streams[pkt->stream_index]; > + st = s->streams[pkt->stream_index]; > > - switch(st->codec->codec_type){ > + switch (st->codec->codec_type) { > case AVMEDIA_TYPE_VIDEO: > - if(s->video_codec_id) st->codec->codec_id= s->video_codec_id; > + if (s->video_codec_id) > + st->codec->codec_id = s->video_codec_id; > break; > case AVMEDIA_TYPE_AUDIO: > - if(s->audio_codec_id) st->codec->codec_id= s->audio_codec_id; > + if (s->audio_codec_id) > + st->codec->codec_id = s->audio_codec_id; > break; > case AVMEDIA_TYPE_SUBTITLE: > - if(s->subtitle_codec_id)st->codec->codec_id= > s->subtitle_codec_id; > + if (s->subtitle_codec_id) > + st->codec->codec_id = s->subtitle_codec_id; > break; > } > > - if(!pktl && (st->codec->codec_id != AV_CODEC_ID_PROBE || > - !st->probe_packets)) > + if (!pktl && (st->codec->codec_id != AV_CODEC_ID_PROBE || > + !st->probe_packets)) > return ret; > > add_to_pktbuf(&s->raw_packet_buffer, pkt, &s->raw_packet_buffer_end); > @@ -589,7 +605,6 @@ int ff_get_audio_frame_size(AVCodecContext *enc, int > size, int mux) > return -1; > } > > - > /** > * Return the frame duration in seconds. Return 0 if not available. > */ > @@ -600,15 +615,15 @@ void ff_compute_frame_duration(int *pnum, int *pden, > AVStream *st, > > *pnum = 0; > *pden = 0; > - switch(st->codec->codec_type) { > + switch (st->codec->codec_type) { > case AVMEDIA_TYPE_VIDEO: > if (st->avg_frame_rate.num) { > *pnum = st->avg_frame_rate.den; > *pden = st->avg_frame_rate.num; > - } else if(st->time_base.num*1000LL > st->time_base.den) { > + } else if (st->time_base.num * 1000LL > st->time_base.den) { > *pnum = st->time_base.num; > *pden = st->time_base.den; > - }else if(st->codec->time_base.num*1000LL > st->codec->time_base.den){ > + } else if (st->codec->time_base.num * 1000LL > > st->codec->time_base.den) { > *pnum = st->codec->time_base.num; > *pden = st->codec->time_base.den; > if (pc && pc->repeat_pict) { > @@ -617,11 +632,11 @@ void ff_compute_frame_duration(int *pnum, int *pden, > AVStream *st, > else > *pnum *= 1 + pc->repeat_pict; > } > - //If this codec can be interlaced or progressive then we need a > parser to compute duration of a packet > - //Thus if we have no parser in such case leave duration > undefined. > - if(st->codec->ticks_per_frame>1 && !pc){ > + /* If this codec can be interlaced or progressive then we need > + * a parser to compute duration of a packet. Thus if we have > + * no parser in such case leave duration undefined. */ > + if (st->codec->ticks_per_frame > 1 && !pc) > *pnum = *pden = 0; > - } > } > break; > case AVMEDIA_TYPE_AUDIO: > @@ -649,27 +664,28 @@ static int is_intra_only(enum AVCodecID id) > static void update_initial_timestamps(AVFormatContext *s, int stream_index, > int64_t dts, int64_t pts) > { > - AVStream *st= s->streams[stream_index]; > - AVPacketList *pktl= s->packet_buffer; > + AVStream *st = s->streams[stream_index]; > + AVPacketList *pktl = s->packet_buffer; > > - if(st->first_dts != AV_NOPTS_VALUE || dts == AV_NOPTS_VALUE || > st->cur_dts == AV_NOPTS_VALUE) > + if (st->first_dts != AV_NOPTS_VALUE || dts == AV_NOPTS_VALUE || > + st->cur_dts == AV_NOPTS_VALUE) > return; > > - st->first_dts= dts - st->cur_dts; > - st->cur_dts= dts; > + st->first_dts = dts - st->cur_dts; > + st->cur_dts = dts; > > - for(; pktl; pktl= pktl->next){ > - if(pktl->pkt.stream_index != stream_index) > + for (; pktl; pktl = pktl->next) { > + if (pktl->pkt.stream_index != stream_index) > continue; > - //FIXME think more about this check > - if(pktl->pkt.pts != AV_NOPTS_VALUE && pktl->pkt.pts == pktl->pkt.dts) > + // FIXME: think more about this check > + if (pktl->pkt.pts != AV_NOPTS_VALUE && pktl->pkt.pts == > pktl->pkt.dts) > pktl->pkt.pts += st->first_dts; > > - if(pktl->pkt.dts != AV_NOPTS_VALUE) > + if (pktl->pkt.dts != AV_NOPTS_VALUE) > pktl->pkt.dts += st->first_dts; > > - if(st->start_time == AV_NOPTS_VALUE && pktl->pkt.pts != > AV_NOPTS_VALUE) > - st->start_time= pktl->pkt.pts; > + if (st->start_time == AV_NOPTS_VALUE && pktl->pkt.pts != > AV_NOPTS_VALUE) > + st->start_time = pktl->pkt.pts; > } > if (st->start_time == AV_NOPTS_VALUE) > st->start_time = pts; > @@ -678,39 +694,42 @@ static void update_initial_timestamps(AVFormatContext > *s, int stream_index, > static void update_initial_durations(AVFormatContext *s, AVStream *st, > int stream_index, int duration) > { > - AVPacketList *pktl= s->packet_buffer; > - int64_t cur_dts= 0; > + AVPacketList *pktl = s->packet_buffer; > + int64_t cur_dts = 0; > > - if(st->first_dts != AV_NOPTS_VALUE){ > - cur_dts= st->first_dts; > - for(; pktl; pktl= pktl->next){ > - if(pktl->pkt.stream_index == stream_index){ > - if(pktl->pkt.pts != pktl->pkt.dts || pktl->pkt.dts != > AV_NOPTS_VALUE || pktl->pkt.duration) > + if (st->first_dts != AV_NOPTS_VALUE) { > + cur_dts = st->first_dts; > + for (; pktl; pktl = pktl->next) { > + if (pktl->pkt.stream_index == stream_index) { > + if (pktl->pkt.pts != pktl->pkt.dts || > + pktl->pkt.dts != AV_NOPTS_VALUE || > + pktl->pkt.duration) > break; > cur_dts -= duration; > } > } > - pktl= s->packet_buffer; > + pktl = s->packet_buffer; > st->first_dts = cur_dts; > - }else if(st->cur_dts) > + } else if (st->cur_dts) > return; > > - for(; pktl; pktl= pktl->next){ > - if(pktl->pkt.stream_index != stream_index) > + for (; pktl; pktl = pktl->next) { > + if (pktl->pkt.stream_index != stream_index) > continue; > - if(pktl->pkt.pts == pktl->pkt.dts && pktl->pkt.dts == AV_NOPTS_VALUE > - && !pktl->pkt.duration){ > - pktl->pkt.dts= cur_dts; > - if(!st->codec->has_b_frames) > - pktl->pkt.pts= cur_dts; > + if (pktl->pkt.pts == pktl->pkt.dts && > + pktl->pkt.dts == AV_NOPTS_VALUE && > + !pktl->pkt.duration) { > + pktl->pkt.dts = cur_dts; > + if (!st->codec->has_b_frames) > + pktl->pkt.pts = cur_dts; > cur_dts += duration; > if (st->codec->codec_type != AVMEDIA_TYPE_AUDIO) > pktl->pkt.duration = duration; > - }else > + } else > break; > } > - if(st->first_dts == AV_NOPTS_VALUE) > - st->cur_dts= cur_dts; > + if (st->first_dts == AV_NOPTS_VALUE) > + st->cur_dts = cur_dts; > } > > static void compute_pkt_fields(AVFormatContext *s, AVStream *st, > @@ -722,15 +741,15 @@ static void compute_pkt_fields(AVFormatContext *s, > AVStream *st, > if (s->flags & AVFMT_FLAG_NOFILLIN) > return; > > - if((s->flags & AVFMT_FLAG_IGNDTS) && pkt->pts != AV_NOPTS_VALUE) > - pkt->dts= AV_NOPTS_VALUE; > + if ((s->flags & AVFMT_FLAG_IGNDTS) && pkt->pts != AV_NOPTS_VALUE) > + pkt->dts = AV_NOPTS_VALUE; > > /* do we have a video B-frame ? */ > - delay= st->codec->has_b_frames; > + delay = st->codec->has_b_frames; > presentation_delayed = 0; > > /* XXX: need has_b_frame, but cannot get it if the codec is > - not initialized */ > + * not initialized */ > if (delay && > pc && pc->pict_type != AV_PICTURE_TYPE_B) > presentation_delayed = 1; > @@ -738,49 +757,58 @@ static void compute_pkt_fields(AVFormatContext *s, > AVStream *st, > if (pkt->pts != AV_NOPTS_VALUE && pkt->dts != AV_NOPTS_VALUE && > st->pts_wrap_bits < 63 && > pkt->dts - (1LL << (st->pts_wrap_bits - 1)) > pkt->pts) { > - pkt->dts -= 1LL<<st->pts_wrap_bits; > + pkt->dts -= 1LL << st->pts_wrap_bits; > } > > - // some mpeg2 in mpeg-ps lack dts (issue171 / input_file.mpg) > - // we take the conservative approach and discard both > - // Note, if this is misbehaving for a H.264 file then possibly > presentation_delayed is not set correctly. > - if(delay==1 && pkt->dts == pkt->pts && pkt->dts != AV_NOPTS_VALUE && > presentation_delayed){ > + /* Some MPEG-2 in MPEG-PS lack dts (issue171 / input_file.mpg). We take > the > + * conservative approach and discard both. Note, if this is misbehaving > for > + * a H.264 file then possibly presentation_delayed is not set correctly. > */ > + if (delay == 1 && pkt->dts == pkt->pts && > + pkt->dts != AV_NOPTS_VALUE && presentation_delayed) { > av_log(s, AV_LOG_DEBUG, "invalid dts/pts combination\n"); > - pkt->dts= pkt->pts= AV_NOPTS_VALUE; > + pkt->dts = pkt->pts = AV_NOPTS_VALUE; > } > > if (pkt->duration == 0 && st->codec->codec_type != AVMEDIA_TYPE_AUDIO) { > ff_compute_frame_duration(&num, &den, st, pc, pkt); > if (den && num) { > - pkt->duration = av_rescale_rnd(1, num * > (int64_t)st->time_base.den, den * (int64_t)st->time_base.num, AV_ROUND_DOWN); > + pkt->duration = av_rescale_rnd(1, > + num * (int64_t) st->time_base.den, > + den * (int64_t) st->time_base.num, > + AV_ROUND_DOWN); please don't this makes my eyes bleed. if the resulting is sligtly above 80 chars let it be sigh, just 20% but I don't want to review the rest Janne _______________________________________________ libav-devel mailing list libav-devel@libav.org https://lists.libav.org/mailman/listinfo/libav-devel