X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=libavformat%2Futils.c;h=001c812bbfb19e437761194feb801ae656b71571;hb=f21c0b4c433aea33578a2f959820594c2b27ef01;hp=5a3af68e7406271578cf2d5e60a77d2ef652d425;hpb=c10824ea67e7faa3fda6e790af8efa0d07b9270e;p=ffmpeg diff --git a/libavformat/utils.c b/libavformat/utils.c index 5a3af68e740..001c812bbfb 100644 --- a/libavformat/utils.c +++ b/libavformat/utils.c @@ -17,6 +17,7 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ #include "avformat.h" +#include "allformats.h" #undef NDEBUG #include @@ -26,6 +27,10 @@ * Various utility functions for using ffmpeg library. */ +static void av_frac_init(AVFrac *f, int64_t val, int64_t num, int64_t den); +static void av_frac_add(AVFrac *f, int64_t incr); +static void av_frac_set(AVFrac *f, int64_t val); + /** head of registered input format linked list. */ AVInputFormat *first_iformat = NULL; /** head of registered output format linked list. */ @@ -85,11 +90,13 @@ AVOutputFormat *guess_format(const char *short_name, const char *filename, int score_max, score; /* specific test for image sequences */ +#ifdef CONFIG_IMAGE2_MUXER if (!short_name && filename && filename_number_test(filename) >= 0 && av_guess_image2_codec(filename) != CODEC_ID_NONE) { return guess_format("image2", NULL, NULL); } +#endif if (!short_name && filename && filename_number_test(filename) >= 0 && guess_image_format(filename)) { @@ -146,9 +153,11 @@ enum CodecID av_guess_codec(AVOutputFormat *fmt, const char *short_name, if(type == CODEC_TYPE_VIDEO){ enum CodecID codec_id= CODEC_ID_NONE; +#ifdef CONFIG_IMAGE2_MUXER if(!strcmp(fmt->name, "image2") || !strcmp(fmt->name, "image2pipe")){ codec_id= av_guess_image2_codec(filename); } +#endif if(codec_id == CODEC_ID_NONE) codec_id= fmt->video_codec; return codec_id; @@ -594,7 +603,7 @@ int av_open_input_file(AVFormatContext **ic_ptr, const char *filename, /* XXX: suppress this hack for redirectors */ #ifdef CONFIG_NETWORK - if (fmt == &redir_demux) { + if (fmt == &redir_demuxer) { err = redir_open(ic_ptr, pb); url_fclose(pb); return err; @@ -648,48 +657,17 @@ static int get_audio_frame_size(AVCodecContext *enc, int size) int frame_size; if (enc->frame_size <= 1) { - /* specific hack for pcm codecs because no frame size is - provided */ - switch(enc->codec_id) { - case CODEC_ID_PCM_S32LE: - case CODEC_ID_PCM_S32BE: - case CODEC_ID_PCM_U32LE: - case CODEC_ID_PCM_U32BE: - if (enc->channels == 0) - return -1; - frame_size = size / (4 * enc->channels); - break; - case CODEC_ID_PCM_S24LE: - case CODEC_ID_PCM_S24BE: - case CODEC_ID_PCM_U24LE: - case CODEC_ID_PCM_U24BE: - case CODEC_ID_PCM_S24DAUD: - if (enc->channels == 0) - return -1; - frame_size = size / (3 * enc->channels); - break; - case CODEC_ID_PCM_S16LE: - case CODEC_ID_PCM_S16BE: - case CODEC_ID_PCM_U16LE: - case CODEC_ID_PCM_U16BE: - if (enc->channels == 0) - return -1; - frame_size = size / (2 * enc->channels); - break; - case CODEC_ID_PCM_S8: - case CODEC_ID_PCM_U8: - case CODEC_ID_PCM_MULAW: - case CODEC_ID_PCM_ALAW: + int bits_per_sample = av_get_bits_per_sample(enc->codec_id); + + if (bits_per_sample) { if (enc->channels == 0) return -1; - frame_size = size / (enc->channels); - break; - default: + frame_size = (size << 3) / (bits_per_sample * enc->channels); + } else { /* used for example by ADPCM codecs */ if (enc->bit_rate == 0) return -1; frame_size = (size * 8 * enc->sample_rate) / enc->bit_rate; - break; } } else { frame_size = enc->frame_size; @@ -893,7 +871,7 @@ static int av_read_frame_internal(AVFormatContext *s, AVPacket *pkt) *pkt = s->cur_pkt; compute_pkt_fields(s, st, NULL, pkt); s->cur_st = NULL; - return 0; + break; } else if (s->cur_len > 0 && st->discard < AVDISCARD_ALL) { len = av_parser_parse(st->parser, st->codec, &pkt->data, &pkt->size, s->cur_ptr, s->cur_len, @@ -913,7 +891,7 @@ static int av_read_frame_internal(AVFormatContext *s, AVPacket *pkt) pkt->dts = st->parser->dts; pkt->destruct = av_destruct_packet_nofree; compute_pkt_fields(s, st, st->parser, pkt); - return 0; + break; } } else { /* free packet */ @@ -943,6 +921,12 @@ static int av_read_frame_internal(AVFormatContext *s, AVPacket *pkt) } st = s->streams[s->cur_pkt.stream_index]; + if(st->codec->debug & FF_DEBUG_PTS) + av_log(s, AV_LOG_DEBUG, "av_read_packet stream=%d, pts=%lld, dts=%lld, size=%d\n", + s->cur_pkt.stream_index, + s->cur_pkt.pts, + s->cur_pkt.dts, + s->cur_pkt.size); s->cur_st = st; s->cur_ptr = s->cur_pkt.data; @@ -958,6 +942,14 @@ static int av_read_frame_internal(AVFormatContext *s, AVPacket *pkt) } } } + if(st->codec->debug & FF_DEBUG_PTS) + av_log(s, AV_LOG_DEBUG, "av_read_frame_internal stream=%d, pts=%lld, dts=%lld, size=%d\n", + pkt->stream_index, + pkt->pts, + pkt->dts, + pkt->size); + + return 0; } /** @@ -1119,7 +1111,7 @@ static void av_read_frame_flush(AVFormatContext *s) * @param timestamp new dts expressed in time_base of param ref_st * @param ref_st reference stream giving time_base of param timestamp */ -static void av_update_cur_dts(AVFormatContext *s, AVStream *ref_st, int64_t timestamp){ +void av_update_cur_dts(AVFormatContext *s, AVStream *ref_st, int64_t timestamp){ int i; for(i = 0; i < s->nb_streams; i++) { @@ -1756,7 +1748,9 @@ static void av_estimate_timings(AVFormatContext *ic) } ic->file_size = file_size; - if ((ic->iformat == &mpegps_demux || ic->iformat == &mpegts_demux) && file_size && !ic->pb.is_streamed) { + if ((!strcmp(ic->iformat->name, "mpeg") || + !strcmp(ic->iformat->name, "mpegts")) && + file_size && !ic->pb.is_streamed) { /* get accurate estimate from the PTSes */ av_estimate_timings_from_pts(ic); } else if (av_has_timings(ic)) { @@ -1935,11 +1929,10 @@ int av_find_stream_info(AVFormatContext *ic) char buf[256]; avcodec_string(buf, sizeof(buf), st->codec, 0); av_log(ic, AV_LOG_INFO, "Could not find codec parameters (%s)\n", buf); - break; + } else { + ret = 0; } } - if (i == ic->nb_streams) - ret = 0; break; } @@ -1992,8 +1985,9 @@ int av_find_stream_info(AVFormatContext *ic) int i= st->parser->parser->split(st->codec, pkt->data, pkt->size); if(i){ st->codec->extradata_size= i; - st->codec->extradata= av_malloc(st->codec->extradata_size); + st->codec->extradata= av_malloc(st->codec->extradata_size + FF_INPUT_BUFFER_PADDING_SIZE); memcpy(st->codec->extradata, pkt->data, st->codec->extradata_size); + memset(st->codec->extradata + i, 0, FF_INPUT_BUFFER_PADDING_SIZE); } } @@ -2408,7 +2402,7 @@ int av_write_frame(AVFormatContext *s, AVPacket *pkt) int ret; ret=compute_pkt_fields2(s->streams[pkt->stream_index], pkt); - if(ret<0) + if(ret<0 && !(s->oformat->flags & AVFMT_NOTIMESTAMPS)) return ret; truncate_ts(s->streams[pkt->stream_index], pkt); @@ -2424,7 +2418,7 @@ int av_write_frame(AVFormatContext *s, AVPacket *pkt) * packets with pkt->destruct == av_destruct_packet will be freed inside this function. * so they cannot be used after it, note calling av_free_packet() on them is still safe */ -static int av_interleave_packet_per_dts(AVFormatContext *s, AVPacket *out, AVPacket *pkt, int flush){ +int av_interleave_packet_per_dts(AVFormatContext *s, AVPacket *out, AVPacket *pkt, int flush){ AVPacketList *pktl, **next_point, *this_pktl; int stream_count=0; int streams[MAX_STREAMS]; @@ -2515,7 +2509,7 @@ int av_interleaved_write_frame(AVFormatContext *s, AVPacket *pkt){ return 0; //av_log(NULL, AV_LOG_DEBUG, "av_interleaved_write_frame %d %Ld %Ld\n", pkt->size, pkt->dts, pkt->pts); - if(compute_pkt_fields2(st, pkt) < 0) + if(compute_pkt_fields2(st, pkt) < 0 && !(s->oformat->flags & AVFMT_NOTIMESTAMPS)) return -1; if(pkt->dts == AV_NOPTS_VALUE) @@ -3147,7 +3141,7 @@ void av_set_pts_info(AVStream *s, int pts_wrap_bits, * @param num must be >= 0 * @param den must be >= 1 */ -void av_frac_init(AVFrac *f, int64_t val, int64_t num, int64_t den) +static void av_frac_init(AVFrac *f, int64_t val, int64_t num, int64_t den) { num += (den >> 1); if (num >= den) { @@ -3162,7 +3156,7 @@ void av_frac_init(AVFrac *f, int64_t val, int64_t num, int64_t den) /** * Set f to (val + 0.5). */ -void av_frac_set(AVFrac *f, int64_t val) +static void av_frac_set(AVFrac *f, int64_t val) { f->val = val; f->num = f->den >> 1; @@ -3174,7 +3168,7 @@ void av_frac_set(AVFrac *f, int64_t val) * @param f fractional number * @param incr increment, can be positive or negative */ -void av_frac_add(AVFrac *f, int64_t incr) +static void av_frac_add(AVFrac *f, int64_t incr) { int64_t num, den;