aboutsummaryrefslogtreecommitdiffstats
path: root/libavformat/avienc.c
diff options
context:
space:
mode:
authorMats Peterson <matsp888@yahoo.com>2016-03-12 16:18:36 +0100
committerMichael Niedermayer <michael@niedermayer.cc>2016-03-13 16:06:09 +0100
commit9ee5b4096476d369157accc491b0f69a28cb9b6b (patch)
tree0831b7fb2150ce28d423213a166ea3f1d4ddacb8 /libavformat/avienc.c
parent4405ff2cae5066b68552bb529a7b49efc1413899 (diff)
downloadffmpeg-9ee5b4096476d369157accc491b0f69a28cb9b6b.tar.gz
avformat/avienc: factor out avi_add_ientry()
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
Diffstat (limited to 'libavformat/avienc.c')
-rw-r--r--libavformat/avienc.c68
1 files changed, 45 insertions, 23 deletions
diff --git a/libavformat/avienc.c b/libavformat/avienc.c
index ad503793f7..1090f14d98 100644
--- a/libavformat/avienc.c
+++ b/libavformat/avienc.c
@@ -44,7 +44,10 @@
*/
typedef struct AVIIentry {
- unsigned int flags, pos, len;
+ char tag[4];
+ unsigned int flags;
+ unsigned int pos;
+ unsigned int len;
} AVIIentry;
#define AVI_INDEX_CLUSTER_SIZE 16384
@@ -96,6 +99,43 @@ static inline AVIIentry *avi_get_ientry(const AVIIndex *idx, int ent_id)
return &idx->cluster[cl][id];
}
+static int avi_add_ientry(AVFormatContext *s, int stream_index, char *tag,
+ unsigned int flags, unsigned int size)
+{
+ AVIContext *avi = s->priv_data;
+ AVIOContext *pb = s->pb;
+ AVIStream *avist = s->streams[stream_index]->priv_data;
+ AVIIndex *idx = &avist->indexes;
+ int cl = idx->entry / AVI_INDEX_CLUSTER_SIZE;
+ int id = idx->entry % AVI_INDEX_CLUSTER_SIZE;
+
+ if (idx->ents_allocated <= idx->entry) {
+ idx->cluster = av_realloc_f(idx->cluster, sizeof(void*), cl+1);
+ if (!idx->cluster) {
+ idx->ents_allocated = 0;
+ idx->entry = 0;
+ return AVERROR(ENOMEM);
+ }
+ idx->cluster[cl] =
+ av_malloc(AVI_INDEX_CLUSTER_SIZE * sizeof(AVIIentry));
+ if (!idx->cluster[cl])
+ return AVERROR(ENOMEM);
+ idx->ents_allocated += AVI_INDEX_CLUSTER_SIZE;
+ }
+
+ if (tag)
+ memcpy(idx->cluster[cl][id].tag, tag, 4);
+ else
+ *(idx->cluster[cl][id].tag) = '\0';
+ idx->cluster[cl][id].flags = flags;
+ idx->cluster[cl][id].pos = avio_tell(pb) - avi->movi_list;
+ idx->cluster[cl][id].len = size;
+ avist->max_size = FFMAX(avist->max_size, size);
+ idx->entry++;
+
+ return 0;
+}
+
static int64_t avi_start_new_riff(AVFormatContext *s, AVIOContext *pb,
const char *riff_tag, const char *list_tag)
{
@@ -775,28 +815,10 @@ static int avi_write_packet_internal(AVFormatContext *s, AVPacket *pkt)
avist->audio_strm_length += size;
if (s->pb->seekable) {
- AVIIndex *idx = &avist->indexes;
- int cl = idx->entry / AVI_INDEX_CLUSTER_SIZE;
- int id = idx->entry % AVI_INDEX_CLUSTER_SIZE;
- if (idx->ents_allocated <= idx->entry) {
- idx->cluster = av_realloc_f(idx->cluster, sizeof(void*), cl+1);
- if (!idx->cluster) {
- idx->ents_allocated = 0;
- idx->entry = 0;
- return AVERROR(ENOMEM);
- }
- idx->cluster[cl] =
- av_malloc(AVI_INDEX_CLUSTER_SIZE * sizeof(AVIIentry));
- if (!idx->cluster[cl])
- return AVERROR(ENOMEM);
- idx->ents_allocated += AVI_INDEX_CLUSTER_SIZE;
- }
-
- idx->cluster[cl][id].flags = flags;
- idx->cluster[cl][id].pos = avio_tell(pb) - avi->movi_list;
- idx->cluster[cl][id].len = size;
- avist->max_size = FFMAX(avist->max_size, size);
- idx->entry++;
+ int ret;
+ ret = avi_add_ientry(s, stream_index, NULL, flags, size);
+ if (ret < 0)
+ return ret;
}
avio_write(pb, tag, 4);