mirror of
https://github.com/FFmpeg/FFmpeg.git
synced 2025-05-17 23:17:41 +08:00
avformat/avienc: factor out avi_add_ientry()
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
This commit is contained in:

committed by
Michael Niedermayer

parent
4405ff2cae
commit
9ee5b40964
@ -44,7 +44,10 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
typedef struct AVIIentry {
|
typedef struct AVIIentry {
|
||||||
unsigned int flags, pos, len;
|
char tag[4];
|
||||||
|
unsigned int flags;
|
||||||
|
unsigned int pos;
|
||||||
|
unsigned int len;
|
||||||
} AVIIentry;
|
} AVIIentry;
|
||||||
|
|
||||||
#define AVI_INDEX_CLUSTER_SIZE 16384
|
#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];
|
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,
|
static int64_t avi_start_new_riff(AVFormatContext *s, AVIOContext *pb,
|
||||||
const char *riff_tag, const char *list_tag)
|
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;
|
avist->audio_strm_length += size;
|
||||||
|
|
||||||
if (s->pb->seekable) {
|
if (s->pb->seekable) {
|
||||||
AVIIndex *idx = &avist->indexes;
|
int ret;
|
||||||
int cl = idx->entry / AVI_INDEX_CLUSTER_SIZE;
|
ret = avi_add_ientry(s, stream_index, NULL, flags, size);
|
||||||
int id = idx->entry % AVI_INDEX_CLUSTER_SIZE;
|
if (ret < 0)
|
||||||
if (idx->ents_allocated <= idx->entry) {
|
return ret;
|
||||||
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++;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
avio_write(pb, tag, 4);
|
avio_write(pb, tag, 4);
|
||||||
|
Reference in New Issue
Block a user