aboutsummaryrefslogtreecommitdiffstats
path: root/libavformat
diff options
context:
space:
mode:
authorMichael Niedermayer <michaelni@gmx.at>2011-04-01 02:55:29 +0200
committerMichael Niedermayer <michaelni@gmx.at>2011-04-01 02:58:15 +0200
commit7ac167493e5404fd2d3f307d02127f23fca970f0 (patch)
treebea8a71cd59b1ea9a63692f7df1bdedb8446a9c1 /libavformat
parent859676dd426e7051b41b174886e6e64271e93cdc (diff)
parente006d71fa849542eb27146efac629288703b3d75 (diff)
downloadffmpeg-7ac167493e5404fd2d3f307d02127f23fca970f0.tar.gz
Merge remote-tracking branch 'newdev/master'
* newdev/master: mpegts: propagate avio EOF in read_packet() configure: Initial support for --target-os=symbian Fixed-point FFT and MDCT Include dependencies for test programs ac3enc: simplify sym_quant() flvdec: read index stored in the 'keyframes' tag. mov: Add support for zero-sized stsc runs. Merged-by: Michael Niedermayer <michaelni@gmx.at>
Diffstat (limited to 'libavformat')
-rw-r--r--libavformat/flvdec.c66
-rw-r--r--libavformat/mov.c2
-rw-r--r--libavformat/mpegts.c2
3 files changed, 68 insertions, 2 deletions
diff --git a/libavformat/flvdec.c b/libavformat/flvdec.c
index e3449a6746..697f8edbed 100644
--- a/libavformat/flvdec.c
+++ b/libavformat/flvdec.c
@@ -31,6 +31,10 @@
#include "avio_internal.h"
#include "flv.h"
+#define KEYFRAMES_TAG "keyframes"
+#define KEYFRAMES_TIMESTAMP_TAG "times"
+#define KEYFRAMES_BYTEOFFSET_TAG "filepositions"
+
typedef struct {
int wrong_dts; ///< wrong dts due to negative cts
} FLVContext;
@@ -125,6 +129,64 @@ static int amf_get_string(AVIOContext *ioc, char *buffer, int buffsize) {
return length;
}
+static int parse_keyframes_index(AVFormatContext *s, AVIOContext *ioc, AVStream *vstream, int64_t max_pos) {
+ unsigned int arraylen = 0, timeslen = 0, fileposlen = 0, i;
+ double num_val;
+ char str_val[256];
+ int64_t *times = NULL;
+ int64_t *filepositions = NULL;
+ int ret = 0;
+
+ while (avio_tell(ioc) < max_pos - 2 && amf_get_string(ioc, str_val, sizeof(str_val)) > 0) {
+ int64_t* current_array;
+
+ // Expect array object in context
+ if (avio_r8(ioc) != AMF_DATA_TYPE_ARRAY)
+ break;
+
+ arraylen = avio_rb32(ioc);
+ /*
+ * Expect only 'times' or 'filepositions' sub-arrays in other case refuse to use such metadata
+ * for indexing
+ */
+ if (!strcmp(KEYFRAMES_TIMESTAMP_TAG, str_val) && !times) {
+ if (!(times = av_mallocz(sizeof(*times) * arraylen))) {
+ ret = AVERROR(ENOMEM);
+ goto finish;
+ }
+ timeslen = arraylen;
+ current_array = times;
+ } else if (!strcmp(KEYFRAMES_BYTEOFFSET_TAG, str_val) && !filepositions) {
+ if (!(filepositions = av_mallocz(sizeof(*filepositions) * arraylen))) {
+ ret = AVERROR(ENOMEM);
+ goto finish;
+ }
+ fileposlen = arraylen;
+ current_array = filepositions;
+ } else // unexpected metatag inside keyframes, will not use such metadata for indexing
+ break;
+
+ for (i = 0; i < arraylen && avio_tell(ioc) < max_pos - 1; i++) {
+ if (avio_r8(ioc) != AMF_DATA_TYPE_NUMBER)
+ goto finish;
+ num_val = av_int2dbl(avio_rb64(ioc));
+ current_array[i] = num_val;
+ }
+ }
+
+ if (timeslen == fileposlen)
+ for(i = 0; i < arraylen; i++)
+ av_add_index_entry(vstream, filepositions[i], times[i]*1000, 0, 0, AVINDEX_KEYFRAME);
+ else
+ av_log(s, AV_LOG_WARNING, "Invalid keyframes object, skipping.\n");
+
+finish:
+ av_freep(&times);
+ av_freep(&filepositions);
+ avio_seek(ioc, max_pos, SEEK_SET);
+ return ret;
+}
+
static int amf_parse_object(AVFormatContext *s, AVStream *astream, AVStream *vstream, const char *key, int64_t max_pos, int depth) {
AVCodecContext *acodec, *vcodec;
AVIOContext *ioc;
@@ -149,6 +211,10 @@ static int amf_parse_object(AVFormatContext *s, AVStream *astream, AVStream *vst
case AMF_DATA_TYPE_OBJECT: {
unsigned int keylen;
+ if (!strcmp(KEYFRAMES_TAG, key) && depth == 1)
+ if (parse_keyframes_index(s, ioc, vstream, max_pos) < 0)
+ return -1;
+
while(avio_tell(ioc) < max_pos - 2 && (keylen = avio_rb16(ioc))) {
avio_skip(ioc, keylen); //skip key string
if(amf_parse_object(s, NULL, NULL, NULL, max_pos, depth + 1) < 0)
diff --git a/libavformat/mov.c b/libavformat/mov.c
index d819c87802..60dbbfca2e 100644
--- a/libavformat/mov.c
+++ b/libavformat/mov.c
@@ -1553,7 +1553,7 @@ static void mov_build_index(MOVContext *mov, AVStream *st)
for (i = 0; i < sc->chunk_count; i++) {
current_offset = sc->chunk_offsets[i];
- if (stsc_index + 1 < sc->stsc_count &&
+ while (stsc_index + 1 < sc->stsc_count &&
i + 1 == sc->stsc_data[stsc_index + 1].first)
stsc_index++;
for (j = 0; j < sc->stsc_data[stsc_index].count; j++) {
diff --git a/libavformat/mpegts.c b/libavformat/mpegts.c
index af0cadbb5a..803acb3ce3 100644
--- a/libavformat/mpegts.c
+++ b/libavformat/mpegts.c
@@ -1350,7 +1350,7 @@ static int read_packet(AVFormatContext *s, uint8_t *buf, int raw_packet_size)
for(;;) {
len = avio_read(pb, buf, TS_PACKET_SIZE);
if (len != TS_PACKET_SIZE)
- return AVERROR(EIO);
+ return len < 0 ? len : AVERROR_EOF;
/* check paquet sync byte */
if (buf[0] != 0x47) {
/* find a new packet start */