aboutsummaryrefslogtreecommitdiffstats
path: root/libavformat
diff options
context:
space:
mode:
authorMichael Niedermayer <michaelni@gmx.at>2011-07-03 02:56:12 +0200
committerMichael Niedermayer <michaelni@gmx.at>2011-07-03 03:14:10 +0200
commitcbfdfbe846f872d4283579c8cbca42c90896905c (patch)
treeadc2aebfe0b12ffa1a889dc72ab57bcb1e0ad9e0 /libavformat
parent59bd0fef6691f5b23eebbd7dd2f3e74c8d60c6a7 (diff)
parent5dd045ebc11933dca4d6af06e6b1e62be56802f7 (diff)
downloadffmpeg-cbfdfbe846f872d4283579c8cbca42c90896905c.tar.gz
Merge remote-tracking branch 'qatar/master'
* qatar/master: ARM: ac3: update ff_ac3_extract_exponents_neon per 8b7b2d6 ARM: NEON optimised vector_clip_int32() swscale: disable full_chroma_int when converting to non-24/32bpp RGB. suggest to use av_get_bytes_per_sample() in av_get_bits_per_sample_format() doxy ffmpeg: use av_get_bytes_per_sample() in place of av_get_bits_per_sample_fmt() put_bits: remove ALT_BITSTREAM_WRITER put_bits: always use intreadwrite.h macros libavformat: Add an example how to use the metadata API doxygen: Prefer member groups over grouping into modules doxygen: be more permissive when searching for API examples avformat: doxify the Metadata API lavf: restore old behavior for custom AVIOContex with an AVFMT_NOFILE format. lavf: use the correct pointer in av_open_input_stream(). avidec: infer absolute vs relative index from first packet Conflicts: libavformat/Makefile libavformat/avidec.c Merged-by: Michael Niedermayer <michaelni@gmx.at>
Diffstat (limited to 'libavformat')
-rw-r--r--libavformat/Makefile1
-rw-r--r--libavformat/avformat.h75
-rw-r--r--libavformat/avidec.c35
-rw-r--r--libavformat/avio.h12
-rw-r--r--libavformat/metadata-example.c56
-rw-r--r--libavformat/rtmppkt.h2
-rw-r--r--libavformat/utils.c10
7 files changed, 138 insertions, 53 deletions
diff --git a/libavformat/Makefile b/libavformat/Makefile
index 6d7a342c9e..27a6a9b08e 100644
--- a/libavformat/Makefile
+++ b/libavformat/Makefile
@@ -341,6 +341,7 @@ OBJS-$(CONFIG_UDP_PROTOCOL) += udp.o
OBJS-$(CONFIG_ALSA_INDEV) += timefilter.o
OBJS-$(CONFIG_JACK_INDEV) += timefilter.o
+EXAMPLES = metadata
TESTPROGS = timefilter
include $(SRC_PATH)/subdir.mak
diff --git a/libavformat/avformat.h b/libavformat/avformat.h
index 6069f19950..558f3c5ea0 100644
--- a/libavformat/avformat.h
+++ b/libavformat/avformat.h
@@ -48,63 +48,70 @@ const char *avformat_license(void);
struct AVFormatContext;
-/*
- * Public Metadata API.
+/**
+ * @defgroup metadata_api Public Metadata API
+ * @{
* The metadata API allows libavformat to export metadata tags to a client
* application using a sequence of key/value pairs. Like all strings in FFmpeg,
* metadata must be stored as UTF-8 encoded Unicode. Note that metadata
* exported by demuxers isn't checked to be valid UTF-8 in most cases.
* Important concepts to keep in mind:
- * 1. Keys are unique; there can never be 2 tags with the same key. This is
+ * - Keys are unique; there can never be 2 tags with the same key. This is
* also meant semantically, i.e., a demuxer should not knowingly produce
* several keys that are literally different but semantically identical.
* E.g., key=Author5, key=Author6. In this example, all authors must be
* placed in the same tag.
- * 2. Metadata is flat, not hierarchical; there are no subtags. If you
+ * - Metadata is flat, not hierarchical; there are no subtags. If you
* want to store, e.g., the email address of the child of producer Alice
* and actor Bob, that could have key=alice_and_bobs_childs_email_address.
- * 3. Several modifiers can be applied to the tag name. This is done by
+ * - Several modifiers can be applied to the tag name. This is done by
* appending a dash character ('-') and the modifier name in the order
* they appear in the list below -- e.g. foo-eng-sort, not foo-sort-eng.
- * a) language -- a tag whose value is localized for a particular language
+ * - language -- a tag whose value is localized for a particular language
* is appended with the ISO 639-2/B 3-letter language code.
* For example: Author-ger=Michael, Author-eng=Mike
* The original/default language is in the unqualified "Author" tag.
* A demuxer should set a default if it sets any translated tag.
- * b) sorting -- a modified version of a tag that should be used for
+ * - sorting -- a modified version of a tag that should be used for
* sorting will have '-sort' appended. E.g. artist="The Beatles",
* artist-sort="Beatles, The".
*
- * 4. Demuxers attempt to export metadata in a generic format, however tags
+ * - Demuxers attempt to export metadata in a generic format, however tags
* with no generic equivalents are left as they are stored in the container.
* Follows a list of generic tag names:
*
- * album -- name of the set this work belongs to
- * album_artist -- main creator of the set/album, if different from artist.
- * e.g. "Various Artists" for compilation albums.
- * artist -- main creator of the work
- * comment -- any additional description of the file.
- * composer -- who composed the work, if different from artist.
- * copyright -- name of copyright holder.
- * creation_time-- date when the file was created, preferably in ISO 8601.
- * date -- date when the work was created, preferably in ISO 8601.
- * disc -- number of a subset, e.g. disc in a multi-disc collection.
- * encoder -- name/settings of the software/hardware that produced the file.
- * encoded_by -- person/group who created the file.
- * filename -- original name of the file.
- * genre -- <self-evident>.
- * language -- main language in which the work is performed, preferably
- * in ISO 639-2 format. Multiple languages can be specified by
- * separating them with commas.
- * performer -- artist who performed the work, if different from artist.
- * E.g for "Also sprach Zarathustra", artist would be "Richard
- * Strauss" and performer "London Philharmonic Orchestra".
- * publisher -- name of the label/publisher.
- * service_name -- name of the service in broadcasting (channel name).
- * service_provider -- name of the service provider in broadcasting.
- * title -- name of the work.
- * track -- number of this work in the set, can be in form current/total.
- * variant_bitrate -- the total bitrate of the bitrate variant that the current stream is part of
+ @verbatim
+ album -- name of the set this work belongs to
+ album_artist -- main creator of the set/album, if different from artist.
+ e.g. "Various Artists" for compilation albums.
+ artist -- main creator of the work
+ comment -- any additional description of the file.
+ composer -- who composed the work, if different from artist.
+ copyright -- name of copyright holder.
+ creation_time-- date when the file was created, preferably in ISO 8601.
+ date -- date when the work was created, preferably in ISO 8601.
+ disc -- number of a subset, e.g. disc in a multi-disc collection.
+ encoder -- name/settings of the software/hardware that produced the file.
+ encoded_by -- person/group who created the file.
+ filename -- original name of the file.
+ genre -- <self-evident>.
+ language -- main language in which the work is performed, preferably
+ in ISO 639-2 format. Multiple languages can be specified by
+ separating them with commas.
+ performer -- artist who performed the work, if different from artist.
+ E.g for "Also sprach Zarathustra", artist would be "Richard
+ Strauss" and performer "London Philharmonic Orchestra".
+ publisher -- name of the label/publisher.
+ service_name -- name of the service in broadcasting (channel name).
+ service_provider -- name of the service provider in broadcasting.
+ title -- name of the work.
+ track -- number of this work in the set, can be in form current/total.
+ variant_bitrate -- the total bitrate of the bitrate variant that the current stream is part of
+ @endverbatim
+ *
+ * Look in the examples section for an application example how to use the Metadata API.
+ *
+ * @}
*/
#if FF_API_OLD_METADATA2
diff --git a/libavformat/avidec.c b/libavformat/avidec.c
index 366914a64b..8e9cd07c17 100644
--- a/libavformat/avidec.c
+++ b/libavformat/avidec.c
@@ -861,7 +861,7 @@ static int get_stream_idx(int *d){
}
}
-static int avi_sync(AVFormatContext *s)
+static int avi_sync(AVFormatContext *s, int exit_early)
{
AVIContext *avi = s->priv_data;
AVIOContext *pb = s->pb;
@@ -941,7 +941,9 @@ start_sync:
if( (st->discard >= AVDISCARD_DEFAULT && size==0)
/*|| (st->discard >= AVDISCARD_NONKEY && !(pkt->flags & AV_PKT_FLAG_KEY))*/ //FIXME needs a little reordering
|| st->discard >= AVDISCARD_ALL){
- ast->frame_offset += get_duration(ast, size);
+ if (!exit_early) {
+ ast->frame_offset += get_duration(ast, size);
+ }
avio_skip(pb, size);
goto start_sync;
}
@@ -961,6 +963,8 @@ start_sync:
(d[2] == 'd' && d[3] == 'c') ||
(d[2] == 'w' && d[3] == 'b')*/) {
+ if (exit_early)
+ return 0;
//av_log(s, AV_LOG_DEBUG, "OK\n");
if(d[2]*256+d[3] == ast->prefix)
ast->prefix_count++;
@@ -1165,7 +1169,7 @@ resync:
return size;
}
- if ((err = avi_sync(s)) < 0)
+ if ((err = avi_sync(s, 0)) < 0)
return err;
goto resync;
}
@@ -1179,13 +1183,22 @@ static int avi_read_idx1(AVFormatContext *s, int size)
int nb_index_entries, i;
AVStream *st;
AVIStream *ast;
- unsigned int index, tag, flags, pos, len;
+ unsigned int index, tag, flags, pos, len, first_packet = 1;
unsigned last_pos= -1;
+ int64_t idx1_pos, first_packet_pos = 0, data_offset = 0;
nb_index_entries = size / 16;
if (nb_index_entries <= 0)
return -1;
+ idx1_pos = avio_tell(pb);
+ avio_seek(pb, avi->movi_list+4, SEEK_SET);
+ if (avi_sync(s, 1) == 0) {
+ first_packet_pos = avio_tell(pb) - 8;
+ }
+ avi->stream_index = -1;
+ avio_seek(pb, idx1_pos, SEEK_SET);
+
/* Read the entries and sort them in each stream component. */
for(i = 0; i < nb_index_entries; i++) {
tag = avio_rl32(pb);
@@ -1194,9 +1207,6 @@ static int avi_read_idx1(AVFormatContext *s, int size)
len = avio_rl32(pb);
av_dlog(s, "%d: tag=0x%x flags=0x%x pos=0x%x len=%d/",
i, tag, flags, pos, len);
- if(i==0 && pos > avi->movi_list)
- avi->movi_list= 0; //FIXME better check
- pos += avi->movi_list;
index = ((tag & 0xff) - '0') * 10;
index += ((tag >> 8) & 0xff) - '0';
@@ -1205,9 +1215,14 @@ static int avi_read_idx1(AVFormatContext *s, int size)
st = s->streams[index];
ast = st->priv_data;
-#if defined(DEBUG_SEEK)
- av_log(s, AV_LOG_DEBUG, "%d cum_len=%"PRId64"\n", len, ast->cum_len);
-#endif
+ if(first_packet && first_packet_pos && len) {
+ data_offset = first_packet_pos - pos;
+ first_packet = 0;
+ }
+ pos += data_offset;
+
+ av_dlog(s, "%d cum_len=%"PRId64"\n", len, ast->cum_len);
+
if(url_feof(pb))
return -1;
diff --git a/libavformat/avio.h b/libavformat/avio.h
index ed78ffaad9..8210cbd1da 100644
--- a/libavformat/avio.h
+++ b/libavformat/avio.h
@@ -145,7 +145,7 @@ typedef struct URLPollEntry {
attribute_deprecated int url_poll(URLPollEntry *poll_table, int n, int timeout);
/**
- * @defgroup open_modes URL open modes
+ * @name URL open modes
* The flags argument to url_open and cosins must be one of the following
* constants, optionally ORed with other flags.
* @{
@@ -176,7 +176,7 @@ extern URLInterruptCB *url_interrupt_cb;
/**
* @defgroup old_url_funcs Old url_* functions
- * @deprecated use the buffered API based on AVIOContext instead
+ * The following functions are deprecated. Use the buffered API based on #AVIOContext instead.
* @{
*/
attribute_deprecated int url_open_protocol (URLContext **puc, struct URLProtocol *up,
@@ -236,7 +236,7 @@ attribute_deprecated AVIOContext *av_alloc_put_byte(
/**
* @defgroup old_avio_funcs Old put_/get_*() functions
- * @deprecated use the avio_ -prefixed functions instead.
+ * The following functions are deprecated. Use the "avio_"-prefixed functions instead.
* @{
*/
attribute_deprecated int get_buffer(AVIOContext *s, unsigned char *buf, int size);
@@ -273,7 +273,7 @@ attribute_deprecated int64_t av_url_read_fseek (AVIOContext *h, int stream_in
/**
* @defgroup old_url_f_funcs Old url_f* functions
- * @deprecated use the avio_ -prefixed functions instead.
+ * The following functions are deprecated, use the "avio_"-prefixed functions instead.
* @{
*/
attribute_deprecated int url_fopen( AVIOContext **s, const char *url, int flags);
@@ -471,7 +471,7 @@ void avio_flush(AVIOContext *s);
int avio_read(AVIOContext *s, unsigned char *buf, int size);
/**
- * @defgroup avio_read Functions for reading from AVIOContext.
+ * @name Functions for reading from AVIOContext
* @{
*
* @note return 0 if EOF, so you cannot use it if EOF handling is
@@ -515,7 +515,7 @@ int avio_get_str16be(AVIOContext *pb, int maxlen, char *buf, int buflen);
/**
- * @defgroup open_modes URL open modes
+ * @name URL open modes
* The flags argument to avio_open must be one of the following
* constants, optionally ORed with other flags.
* @{
diff --git a/libavformat/metadata-example.c b/libavformat/metadata-example.c
new file mode 100644
index 0000000000..7bf77e7378
--- /dev/null
+++ b/libavformat/metadata-example.c
@@ -0,0 +1,56 @@
+/*
+ * Copyright (c) 2011 Reinhard Tartler
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+/**
+ * @file
+ * @example libavformat/metadata-example.c
+ * Shows how the metadata API can be used in application programs.
+ */
+
+#include <stdio.h>
+
+#include <libavformat/avformat.h>
+#include <libavutil/dict.h>
+
+int main (int argc, char **argv)
+{
+ AVFormatContext *fmt_ctx = NULL;
+ AVDictionaryEntry *tag = NULL;
+ int ret;
+
+ if (argc != 2) {
+ printf("usage: %s <input_file>\n"
+ "example program to demonstrate the use of the libavformat metadata API.\n"
+ "\n", argv[0]);
+ return 1;
+ }
+
+ av_register_all();
+ if ((ret = avformat_open_input(&fmt_ctx, argv[1], NULL, NULL)))
+ return ret;
+
+ while ((tag = av_dict_get(fmt_ctx->metadata, "", tag, AV_DICT_IGNORE_SUFFIX)))
+ printf("%s=%s\n", tag->key, tag->value);
+
+ avformat_free_context(fmt_ctx);
+ return 0;
+}
diff --git a/libavformat/rtmppkt.h b/libavformat/rtmppkt.h
index 4c28cd351e..8acbfc116b 100644
--- a/libavformat/rtmppkt.h
+++ b/libavformat/rtmppkt.h
@@ -138,7 +138,7 @@ int ff_rtmp_packet_write(URLContext *h, RTMPPacket *p,
void ff_rtmp_packet_dump(void *ctx, RTMPPacket *p);
/**
- * @defgroup amffuncs functions used to work with AMF format (which is also used in .flv)
+ * @name Functions used to work with the AMF format (which is also used in .flv)
* @see amf_* funcs in libavformat/flvdec.c
* @{
*/
diff --git a/libavformat/utils.c b/libavformat/utils.c
index da240f68e8..cfc70ecced 100644
--- a/libavformat/utils.c
+++ b/libavformat/utils.c
@@ -464,10 +464,16 @@ int av_open_input_stream(AVFormatContext **ic_ptr,
err = AVERROR(ENOMEM);
goto fail;
}
- ic->pb = pb;
+ if (pb && fmt && fmt->flags & AVFMT_NOFILE)
+ av_log(ic, AV_LOG_WARNING, "Custom AVIOContext makes no sense and "
+ "will be ignored with AVFMT_NOFILE format.\n");
+ else
+ ic->pb = pb;
- err = avformat_open_input(ic_ptr, filename, fmt, &opts);
+ err = avformat_open_input(&ic, filename, fmt, &opts);
+ ic->pb = ic->pb ? ic->pb : pb; // don't leak custom pb if it wasn't set above
+ *ic_ptr = ic;
fail:
av_dict_free(&opts);
return err;