mirror of
https://github.com/FFmpeg/FFmpeg.git
synced 2025-01-13 21:28:01 +02:00
avformat/mpegts: use buffer pools for allocating PES payloads
This brings a performance improvement when demuxing files, most of the improvement comes from buffer pooling unbound packets. time ffprobe -i samples/ffmpeg-bugs/trac/ticket6132/Samsung_HDR_-_Chasing_the_Light.ts -show_packets >/dev/null 2>&1 Before: real 0m1.967s user 0m1.471s sys 0m0.493s After: real 0m1.497s user 0m1.364s sys 0m0.129s Based on a patch of James Almer. Signed-off-by: Marton Balint <cus@passwd.hu>
This commit is contained in:
parent
f04fe8aa4e
commit
944cb188ed
@ -170,6 +170,7 @@ struct MpegTSContext {
|
||||
int current_pid;
|
||||
|
||||
AVStream *epg_stream;
|
||||
AVBufferPool* pools[32];
|
||||
};
|
||||
|
||||
#define MPEGTS_OPTIONS \
|
||||
@ -1103,6 +1104,18 @@ static int read_sl_header(PESContext *pes, SLConfigDescr *sl,
|
||||
return (get_bits_count(&gb) + 7) >> 3;
|
||||
}
|
||||
|
||||
static AVBufferRef *buffer_pool_get(MpegTSContext *ts, int size)
|
||||
{
|
||||
int index = av_log2(size + AV_INPUT_BUFFER_PADDING_SIZE);
|
||||
if (!ts->pools[index]) {
|
||||
int pool_size = FFMIN(MAX_PES_PAYLOAD + AV_INPUT_BUFFER_PADDING_SIZE, 2 << index);
|
||||
ts->pools[index] = av_buffer_pool_init(pool_size, NULL);
|
||||
if (!ts->pools[index])
|
||||
return NULL;
|
||||
}
|
||||
return av_buffer_pool_get(ts->pools[index]);
|
||||
}
|
||||
|
||||
/* return non zero if a packet could be constructed */
|
||||
static int mpegts_push_data(MpegTSFilter *filter,
|
||||
const uint8_t *buf, int buf_size, int is_start,
|
||||
@ -1177,8 +1190,7 @@ static int mpegts_push_data(MpegTSFilter *filter,
|
||||
pes->total_size = MAX_PES_PAYLOAD;
|
||||
|
||||
/* allocate pes buffer */
|
||||
pes->buffer = av_buffer_alloc(pes->total_size +
|
||||
AV_INPUT_BUFFER_PADDING_SIZE);
|
||||
pes->buffer = buffer_pool_get(ts, pes->total_size);
|
||||
if (!pes->buffer)
|
||||
return AVERROR(ENOMEM);
|
||||
|
||||
@ -1351,8 +1363,7 @@ skip:
|
||||
if (ret < 0)
|
||||
return ret;
|
||||
pes->total_size = MAX_PES_PAYLOAD;
|
||||
pes->buffer = av_buffer_alloc(pes->total_size +
|
||||
AV_INPUT_BUFFER_PADDING_SIZE);
|
||||
pes->buffer = buffer_pool_get(ts, pes->total_size);
|
||||
if (!pes->buffer)
|
||||
return AVERROR(ENOMEM);
|
||||
ts->stop_parse = 1;
|
||||
@ -3200,6 +3211,9 @@ static void mpegts_free(MpegTSContext *ts)
|
||||
|
||||
clear_programs(ts);
|
||||
|
||||
for (i = 0; i < FF_ARRAY_ELEMS(ts->pools); i++)
|
||||
av_buffer_pool_uninit(&ts->pools[i]);
|
||||
|
||||
for (i = 0; i < NB_PID_MAX; i++)
|
||||
if (ts->pids[i])
|
||||
mpegts_close_filter(ts, ts->pids[i]);
|
||||
|
Loading…
Reference in New Issue
Block a user