[FFmpeg-devel] [PATCH 4/5] ogg: allow streams to update metadata
Ben Boeckel
mathstuf at gmail.com
Sat Oct 19 15:40:45 CEST 2013
---
libavformat/oggdec.c | 28 +++++++++++++++++++++++-----
libavformat/oggdec.h | 2 ++
2 files changed, 25 insertions(+), 5 deletions(-)
diff --git a/libavformat/oggdec.c b/libavformat/oggdec.c
index 9f8d665..3c0617e 100644
--- a/libavformat/oggdec.c
+++ b/libavformat/oggdec.c
@@ -77,6 +77,8 @@ static int ogg_save(AVFormatContext *s)
struct ogg_stream *os = ogg->streams + i;
os->buf = av_mallocz(os->bufsize + FF_INPUT_BUFFER_PADDING_SIZE);
memcpy(os->buf, ost->streams[i].buf, os->bufpos);
+ os->new_metadata = NULL;
+ os->new_metadata_size = 0;
}
ogg->state = ost;
@@ -142,6 +144,9 @@ static int ogg_reset(AVFormatContext *s)
if (start_pos <= s->data_offset) {
os->lastpts = 0;
}
+ av_free(os->new_metadata);
+ os->new_metadata = NULL;
+ os->new_metadata_size = 0;
}
ogg->page_pos = -1;
@@ -243,11 +248,13 @@ static int ogg_new_stream(AVFormatContext *s, uint32_t serial)
ogg->streams = os;
os = ogg->streams + idx;
memset(os, 0, sizeof(*os));
- os->serial = serial;
- os->bufsize = DECODER_BUFFER_SIZE;
- os->buf = av_malloc(os->bufsize + FF_INPUT_BUFFER_PADDING_SIZE);
- os->header = -1;
- os->start_granule = OGG_NOGRANULE_VALUE;
+ os->serial = serial;
+ os->bufsize = DECODER_BUFFER_SIZE;
+ os->buf = av_malloc(os->bufsize + FF_INPUT_BUFFER_PADDING_SIZE);
+ os->header = -1;
+ os->start_granule = OGG_NOGRANULE_VALUE;
+ os->new_metadata = NULL;
+ os->new_metadata_size = 0;
if (!os->buf)
return AVERROR(ENOMEM);
@@ -639,6 +646,7 @@ static int ogg_read_close(AVFormatContext *s)
ogg->streams[i].codec->cleanup(s, i);
}
av_free(ogg->streams[i].private);
+ av_free(ogg->streams[i].new_metadata);
}
av_free(ogg->streams);
return 0;
@@ -786,6 +794,16 @@ retry:
AV_WL32(side_data + 4, os->end_trimming);
}
+ if (os->new_metadata) {
+ uint8_t *side_data = av_packet_new_side_data(pkt,
+ AV_PKT_DATA_STRINGS_METADATA,
+ os->new_metadata_size);
+ memcpy(side_data, os->new_metadata, os->new_metadata_size);
+ av_free(os->new_metadata);
+ os->new_metadata = NULL;
+ os->new_metadata_size = 0;
+ }
+
return psize;
}
diff --git a/libavformat/oggdec.h b/libavformat/oggdec.h
index c31859f..cad1950 100644
--- a/libavformat/oggdec.h
+++ b/libavformat/oggdec.h
@@ -85,6 +85,8 @@ struct ogg_stream {
int got_data; ///< 1 if the stream got some data (non-initial packets), 0 otherwise
int nb_header; ///< set to the number of parsed headers
int end_trimming; ///< set the number of packets to drop from the end
+ uint8_t *new_metadata;
+ unsigned int new_metadata_size;
void *private;
};
--
1.8.3.1
More information about the ffmpeg-devel
mailing list