From 0b950fe240936fa48fd41204bcfd04f35bbf39c3 Mon Sep 17 00:00:00 2001 From: Anton Khirnov Date: Sun, 22 May 2011 14:10:49 +0200 Subject: lavc: introduce avcodec_open2() as a replacement for avcodec_open(). Adds support for decoder-private options and makes setting other options simpler. --- libavfilter/vsrc_movie.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'libavfilter') diff --git a/libavfilter/vsrc_movie.c b/libavfilter/vsrc_movie.c index 7556fa2e9e..bd74f95545 100644 --- a/libavfilter/vsrc_movie.c +++ b/libavfilter/vsrc_movie.c @@ -139,7 +139,7 @@ static int movie_init(AVFilterContext *ctx) return AVERROR(EINVAL); } - if ((ret = avcodec_open(movie->codec_ctx, codec)) < 0) { + if ((ret = avcodec_open2(movie->codec_ctx, codec, NULL)) < 0) { av_log(ctx, AV_LOG_ERROR, "Failed to open codec\n"); return ret; } -- cgit v1.2.3 From a67c061e0f3b55ffcc96f336fc0998e44b86c8e4 Mon Sep 17 00:00:00 2001 From: Anton Khirnov Date: Sun, 22 May 2011 19:24:59 +0200 Subject: lavf: add avformat_find_stream_info() It supports passing options to codecs. --- libavfilter/vsrc_movie.c | 2 +- libavformat/avformat.h | 27 +++++++++++++++++++++++++++ libavformat/utils.c | 18 +++++++++++++----- 3 files changed, 41 insertions(+), 6 deletions(-) (limited to 'libavfilter') diff --git a/libavfilter/vsrc_movie.c b/libavfilter/vsrc_movie.c index bd74f95545..b018ba7418 100644 --- a/libavfilter/vsrc_movie.c +++ b/libavfilter/vsrc_movie.c @@ -96,7 +96,7 @@ static int movie_init(AVFilterContext *ctx) "Failed to avformat_open_input '%s'\n", movie->file_name); return ret; } - if ((ret = av_find_stream_info(movie->format_ctx)) < 0) + if ((ret = avformat_find_stream_info(movie->format_ctx, NULL)) < 0) av_log(ctx, AV_LOG_WARNING, "Failed to find stream info\n"); // if seeking requested, we execute it diff --git a/libavformat/avformat.h b/libavformat/avformat.h index 2cdf11be12..6e861de262 100644 --- a/libavformat/avformat.h +++ b/libavformat/avformat.h @@ -1093,6 +1093,7 @@ int avformat_open_input(AVFormatContext **ps, const char *filename, AVInputForma */ AVFormatContext *avformat_alloc_context(void); +#if FF_API_FORMAT_PARAMETERS /** * Read packets of a media file to get stream information. This * is useful for file formats with no headers such as MPEG. This @@ -1105,8 +1106,34 @@ AVFormatContext *avformat_alloc_context(void); * @return >=0 if OK, AVERROR_xxx on error * @todo Let the user decide somehow what information is needed so that * we do not waste time getting stuff the user does not need. + * + * @deprecated use avformat_find_stream_info. */ int av_find_stream_info(AVFormatContext *ic); +#endif + +/** + * Read packets of a media file to get stream information. This + * is useful for file formats with no headers such as MPEG. This + * function also computes the real framerate in case of MPEG-2 repeat + * frame mode. + * The logical file position is not changed by this function; + * examined packets may be buffered for later processing. + * + * @param ic media file handle + * @param options If non-NULL, an ic.nb_streams long array of pointers to + * dictionaries, where i-th member contains options for + * codec corresponding to i-th stream. + * On return each dictionary will be filled with options that were not found. + * @return >=0 if OK, AVERROR_xxx on error + * + * @note this function isn't guaranteed to open all the codecs, so + * options being non-empty at return is a perfectly normal behavior. + * + * @todo Let the user decide somehow what information is needed so that + * we do not waste time getting stuff the user does not need. + */ +int avformat_find_stream_info(AVFormatContext *ic, AVDictionary **options); /** * Find the "best" stream in the file. diff --git a/libavformat/utils.c b/libavformat/utils.c index e38d9efa60..a3825a0c93 100644 --- a/libavformat/utils.c +++ b/libavformat/utils.c @@ -2074,7 +2074,7 @@ static int has_decode_delay_been_guessed(AVStream *st) st->codec_info_nb_frames >= 6 + st->codec->has_b_frames; } -static int try_decode_frame(AVStream *st, AVPacket *avpkt) +static int try_decode_frame(AVStream *st, AVPacket *avpkt, AVDictionary **options) { int16_t *samples; AVCodec *codec; @@ -2085,7 +2085,7 @@ static int try_decode_frame(AVStream *st, AVPacket *avpkt) codec = avcodec_find_decoder(st->codec->codec_id); if (!codec) return -1; - ret = avcodec_open(st->codec, codec); + ret = avcodec_open2(st->codec, codec, options); if (ret < 0) return ret; } @@ -2204,12 +2204,20 @@ static int tb_unreliable(AVCodecContext *c){ return 0; } +#if FF_API_FORMAT_PARAMETERS int av_find_stream_info(AVFormatContext *ic) +{ + return avformat_find_stream_info(ic, NULL); +} +#endif + +int avformat_find_stream_info(AVFormatContext *ic, AVDictionary **options) { int i, count, ret, read_size, j; AVStream *st; AVPacket pkt1, *pkt; int64_t old_offset = avio_tell(ic->pb); + int orig_nb_streams = ic->nb_streams; // new streams might appear, no options for those for(i=0;inb_streams;i++) { AVCodec *codec; @@ -2235,12 +2243,12 @@ int av_find_stream_info(AVFormatContext *ic) /* Ensure that subtitle_header is properly set. */ if (st->codec->codec_type == AVMEDIA_TYPE_SUBTITLE && codec && !st->codec->codec) - avcodec_open(st->codec, codec); + avcodec_open2(st->codec, codec, options ? &options[i] : NULL); //try to just open decoders, in case this is enough to get parameters if(!has_codec_parameters(st->codec)){ if (codec && !st->codec->codec) - avcodec_open(st->codec, codec); + avcodec_open2(st->codec, codec, options ? &options[i] : NULL); } } @@ -2383,7 +2391,7 @@ int av_find_stream_info(AVFormatContext *ic) !has_decode_delay_been_guessed(st) || (st->codec->codec && st->codec->codec->capabilities & CODEC_CAP_CHANNEL_CONF)) - try_decode_frame(st, pkt); + try_decode_frame(st, pkt, (options && i <= orig_nb_streams )? &options[i] : NULL); st->codec_info_nb_frames++; count++; -- cgit v1.2.3 From 28e1c97916b026c8785f54ec591718379b251bbb Mon Sep 17 00:00:00 2001 From: Mans Rullgard Date: Sun, 10 Jul 2011 20:26:25 +0100 Subject: build: rework rules for things in the tools dir Declaring tools associated with each library in their respective makefiles allows these tools to easily depend on the correct prerequisites and link against the libs they need. Signed-off-by: Mans Rullgard --- Makefile | 21 ++++++++------------- common.mak | 6 ++++++ libavfilter/Makefile | 2 ++ libavformat/Makefile | 1 + subdir.mak | 4 ++-- tests/Makefile | 3 --- 6 files changed, 19 insertions(+), 18 deletions(-) (limited to 'libavfilter') diff --git a/Makefile b/Makefile index 9f7b4361d4..720936a604 100644 --- a/Makefile +++ b/Makefile @@ -58,6 +58,8 @@ PROGS := $(PROGS-yes:%=%$(EXESUF)) OBJS = $(PROGS-yes:%=%.o) cmdutils.o TESTTOOLS = audiogen videogen rotozoom tiny_psnr base64 HOSTPROGS := $(TESTTOOLS:%=tests/%) +TOOLS = qt-faststart trasher +TOOLS-$(CONFIG_ZLIB) += cws2fws BASENAMES = ffmpeg ffplay ffprobe ffserver ALLPROGS = $(BASENAMES:%=%$(EXESUF)) @@ -86,6 +88,11 @@ FF_DEP_LIBS := $(DEP_LIBS) all: $(FF_DEP_LIBS) $(PROGS) +$(TOOLS): %$(EXESUF): %.o + $(LD) $(LDFLAGS) -o $@ $< $(ELIBS) + +tools/cws2fws$(EXESUF): ELIBS = -lz + config.h: .config .config: $(wildcard $(FFLIBS:%=$(SRC_PATH)/lib%/all*.c)) @-tput bold 2>/dev/null @@ -94,7 +101,7 @@ config.h: .config SUBDIR_VARS := OBJS FFLIBS CLEANFILES DIRS TESTPROGS EXAMPLES SKIPHEADERS \ ALTIVEC-OBJS MMX-OBJS NEON-OBJS X86-OBJS YASM-OBJS-FFT YASM-OBJS \ - HOSTPROGS BUILT_HEADERS TESTOBJS ARCH_HEADERS ARMV6-OBJS + HOSTPROGS BUILT_HEADERS TESTOBJS ARCH_HEADERS ARMV6-OBJS TOOLS define RESET $(1) := @@ -116,18 +123,6 @@ ffserver$(EXESUF): FF_LDFLAGS += $(FFSERVERLDFLAGS) $(PROGS): %$(EXESUF): %.o cmdutils.o $(FF_DEP_LIBS) $(LD) $(FF_LDFLAGS) -o $@ $< cmdutils.o $(FF_EXTRALIBS) -TOOLS = cws2fws graph2dot lavfi-showfiltfmts pktdumper probetest qt-faststart trasher -TOOLOBJS := $(TOOLS:%=tools/%.o) -TOOLS := $(TOOLS:%=tools/%$(EXESUF)) - -alltools: $(TOOLS) - -tools/%$(EXESUF): tools/%.o - $(LD) $(FF_LDFLAGS) -o $@ $< $(FF_EXTRALIBS) - -$(TOOLOBJS): %.o: %.c | tools - $(CC) $(CPPFLAGS) $(CFLAGS) -c $(CC_O) $< - OBJDIRS += tools -include $(wildcard tools/*.d) diff --git a/common.mak b/common.mak index bd210462b9..da51495a16 100644 --- a/common.mak +++ b/common.mak @@ -20,6 +20,9 @@ TESTOBJS := $(TESTOBJS:%=$(SUBDIR)%) $(TESTPROGS:%=$(SUBDIR)%-test.o) TESTPROGS := $(TESTPROGS:%=$(SUBDIR)%-test$(EXESUF)) HOSTOBJS := $(HOSTPROGS:%=$(SUBDIR)%.o) HOSTPROGS := $(HOSTPROGS:%=$(SUBDIR)%$(HOSTEXESUF)) +TOOLS += $(TOOLS-yes) +TOOLOBJS := $(TOOLS:%=tools/%.o) +TOOLS := $(TOOLS:%=tools/%$(EXESUF)) DEP_LIBS := $(foreach NAME,$(FFLIBS),lib$(NAME)/$($(CONFIG_SHARED:yes=S)LIBNAME)) @@ -28,6 +31,8 @@ SKIPHEADERS += $(ARCH_HEADERS:%=$(ARCH)/%) $(SKIPHEADERS-) SKIPHEADERS := $(SKIPHEADERS:%=$(SUBDIR)%) checkheaders: $(filter-out $(SKIPHEADERS:.h=.ho),$(ALLHEADERS:.h=.ho)) +alltools: $(TOOLS) + $(HOSTOBJS): %.o: %.c $(HOSTCC) $(HOSTCFLAGS) -c -o $@ $< @@ -37,6 +42,7 @@ $(HOSTPROGS): %$(HOSTEXESUF): %.o $(OBJS): | $(dir $(OBJS)) $(HOSTOBJS): | $(dir $(HOSTOBJS)) $(TESTOBJS): | $(dir $(TESTOBJS)) +$(TOOLOBJS): | tools OBJDIRS := $(OBJDIRS) $(dir $(OBJS) $(HOSTOBJS) $(TESTOBJS)) diff --git a/libavfilter/Makefile b/libavfilter/Makefile index 02016076bf..1a6fd9b68f 100644 --- a/libavfilter/Makefile +++ b/libavfilter/Makefile @@ -62,4 +62,6 @@ OBJS-$(CONFIG_NULLSINK_FILTER) += vsink_nullsink.o DIRS = x86 +TOOLS = graph2dot lavfi-showfiltfmts + include $(SRC_PATH)/subdir.mak diff --git a/libavformat/Makefile b/libavformat/Makefile index a20db26b03..ca337e0167 100644 --- a/libavformat/Makefile +++ b/libavformat/Makefile @@ -335,6 +335,7 @@ OBJS-$(CONFIG_JACK_INDEV) += timefilter.o EXAMPLES = metadata output TESTPROGS = timefilter +TOOLS = pktdumper probetest include $(SRC_PATH)/subdir.mak diff --git a/subdir.mak b/subdir.mak index 3a38dafe63..a88955bdfb 100644 --- a/subdir.mak +++ b/subdir.mak @@ -34,7 +34,7 @@ install-libs-$(CONFIG_STATIC): install-lib$(NAME)-static install-libs-$(CONFIG_SHARED): install-lib$(NAME)-shared define RULES -$(SUBDIR)%$(EXESUF): $(SUBDIR)%.o +$(TESTPROGS) $(TOOLS): %$(EXESUF): %.o $$(LD) $(FFLDFLAGS) -o $$@ $$^ -l$(FULLNAME) $(FFEXTRALIBS) $$(ELIBS) $(SUBDIR)$(SLIBNAME): $(SUBDIR)$(SLIBNAME_WITH_MAJOR) @@ -91,7 +91,7 @@ endef $(eval $(RULES)) -$(EXAMPLES) $(TESTPROGS): $(THIS_LIB) $(DEP_LIBS) +$(EXAMPLES) $(TESTPROGS) $(TOOLS): $(THIS_LIB) $(DEP_LIBS) examples: $(EXAMPLES) testprogs: $(TESTPROGS) diff --git a/tests/Makefile b/tests/Makefile index 431a404219..501a72f879 100644 --- a/tests/Makefile +++ b/tests/Makefile @@ -31,9 +31,6 @@ tests/data/asynth1.sw tests/vsynth%/00.pgm: TAG = GEN tests/seek_test$(EXESUF): tests/seek_test.o $(FF_DEP_LIBS) $(LD) $(FF_LDFLAGS) -o $@ $< $(FF_EXTRALIBS) -tools/lavfi-showfiltfmts$(EXESUF): tools/lavfi-showfiltfmts.o $(FF_DEP_LIBS) - $(LD) $(FF_LDFLAGS) -o $@ $< $(FF_EXTRALIBS) - include $(SRC_PATH)/tests/fate.mak include $(SRC_PATH)/tests/fate2.mak -- cgit v1.2.3