* [FFmpeg-devel] [PATCH v2] avformat/mpegts: add option max_packet_size
@ 2022-01-12 15:27 Gyan Doshi
2022-01-15 12:49 ` Gyan Doshi
0 siblings, 1 reply; 4+ messages in thread
From: Gyan Doshi @ 2022-01-12 15:27 UTC (permalink / raw)
To: ffmpeg-devel
Makes maximum size of emitted packet user-tunable.
---
doc/demuxers.texi | 4 ++++
libavformat/mpegts.c | 9 ++++++---
2 files changed, 10 insertions(+), 3 deletions(-)
diff --git a/doc/demuxers.texi b/doc/demuxers.texi
index 26ae768d7a..aef5976551 100644
--- a/doc/demuxers.texi
+++ b/doc/demuxers.texi
@@ -775,6 +775,10 @@ disabled). Default value is -1.
@item merge_pmt_versions
Re-use existing streams when a PMT's version is updated and elementary
streams move to different PIDs. Default value is 0.
+
+@item max_packet_size
+Set maximum size, in bytes, of packet emitted by the demuxer. Payloads above this size
+are split across multiple packets. Range is 1 to INT_MAX. Default is 204800 bytes.
@end table
@section mpjpeg
diff --git a/libavformat/mpegts.c b/libavformat/mpegts.c
index 2479cb6f7d..6ff1a54706 100644
--- a/libavformat/mpegts.c
+++ b/libavformat/mpegts.c
@@ -162,6 +162,7 @@ struct MpegTSContext {
int resync_size;
int merge_pmt_versions;
+ int max_packet_size;
/******************************************/
/* private mpegts data */
@@ -198,6 +199,8 @@ static const AVOption options[] = {
{.i64 = 0}, 0, 1, 0 },
{"skip_clear", "skip clearing programs", offsetof(MpegTSContext, skip_clear), AV_OPT_TYPE_BOOL,
{.i64 = 0}, 0, 1, 0 },
+ {"max_packet_size", "maximum size of emitted packet", offsetof(MpegTSContext, max_packet_size), AV_OPT_TYPE_INT,
+ {.i64 = MAX_PES_PAYLOAD}, 1, INT_MAX, AV_OPT_FLAG_DECODING_PARAM },
{ NULL },
};
@@ -1121,7 +1124,7 @@ 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);
+ int pool_size = FFMIN(ts->max_packet_size + AV_INPUT_BUFFER_PADDING_SIZE, 2 << index);
ts->pools[index] = av_buffer_pool_init(pool_size, NULL);
if (!ts->pools[index])
return NULL;
@@ -1368,7 +1371,7 @@ skip:
break;
case MPEGTS_PAYLOAD:
do {
- int max_packet_size = MAX_PES_PAYLOAD;
+ int max_packet_size = ts->max_packet_size;
if (pes->PES_packet_length && pes->PES_packet_length + PES_START_SIZE > pes->pes_header_size)
max_packet_size = pes->PES_packet_length + PES_START_SIZE - pes->pes_header_size;
@@ -1378,7 +1381,7 @@ skip:
if (ret < 0)
return ret;
pes->PES_packet_length = 0;
- max_packet_size = MAX_PES_PAYLOAD;
+ max_packet_size = ts->max_packet_size;
ts->stop_parse = 1;
} else if (pes->data_index == 0 &&
buf_size > max_packet_size) {
--
2.34.1
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [FFmpeg-devel] [PATCH v2] avformat/mpegts: add option max_packet_size
2022-01-12 15:27 [FFmpeg-devel] [PATCH v2] avformat/mpegts: add option max_packet_size Gyan Doshi
@ 2022-01-15 12:49 ` Gyan Doshi
2022-01-15 20:09 ` Marton Balint
0 siblings, 1 reply; 4+ messages in thread
From: Gyan Doshi @ 2022-01-15 12:49 UTC (permalink / raw)
To: ffmpeg-devel
Plan to push tomorrow.
On 2022-01-12 08:57 pm, Gyan Doshi wrote:
> Makes maximum size of emitted packet user-tunable.
> ---
> doc/demuxers.texi | 4 ++++
> libavformat/mpegts.c | 9 ++++++---
> 2 files changed, 10 insertions(+), 3 deletions(-)
>
> diff --git a/doc/demuxers.texi b/doc/demuxers.texi
> index 26ae768d7a..aef5976551 100644
> --- a/doc/demuxers.texi
> +++ b/doc/demuxers.texi
> @@ -775,6 +775,10 @@ disabled). Default value is -1.
> @item merge_pmt_versions
> Re-use existing streams when a PMT's version is updated and elementary
> streams move to different PIDs. Default value is 0.
> +
> +@item max_packet_size
> +Set maximum size, in bytes, of packet emitted by the demuxer. Payloads above this size
> +are split across multiple packets. Range is 1 to INT_MAX. Default is 204800 bytes.
> @end table
>
> @section mpjpeg
> diff --git a/libavformat/mpegts.c b/libavformat/mpegts.c
> index 2479cb6f7d..6ff1a54706 100644
> --- a/libavformat/mpegts.c
> +++ b/libavformat/mpegts.c
> @@ -162,6 +162,7 @@ struct MpegTSContext {
>
> int resync_size;
> int merge_pmt_versions;
> + int max_packet_size;
>
> /******************************************/
> /* private mpegts data */
> @@ -198,6 +199,8 @@ static const AVOption options[] = {
> {.i64 = 0}, 0, 1, 0 },
> {"skip_clear", "skip clearing programs", offsetof(MpegTSContext, skip_clear), AV_OPT_TYPE_BOOL,
> {.i64 = 0}, 0, 1, 0 },
> + {"max_packet_size", "maximum size of emitted packet", offsetof(MpegTSContext, max_packet_size), AV_OPT_TYPE_INT,
> + {.i64 = MAX_PES_PAYLOAD}, 1, INT_MAX, AV_OPT_FLAG_DECODING_PARAM },
> { NULL },
> };
>
> @@ -1121,7 +1124,7 @@ 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);
> + int pool_size = FFMIN(ts->max_packet_size + AV_INPUT_BUFFER_PADDING_SIZE, 2 << index);
> ts->pools[index] = av_buffer_pool_init(pool_size, NULL);
> if (!ts->pools[index])
> return NULL;
> @@ -1368,7 +1371,7 @@ skip:
> break;
> case MPEGTS_PAYLOAD:
> do {
> - int max_packet_size = MAX_PES_PAYLOAD;
> + int max_packet_size = ts->max_packet_size;
> if (pes->PES_packet_length && pes->PES_packet_length + PES_START_SIZE > pes->pes_header_size)
> max_packet_size = pes->PES_packet_length + PES_START_SIZE - pes->pes_header_size;
>
> @@ -1378,7 +1381,7 @@ skip:
> if (ret < 0)
> return ret;
> pes->PES_packet_length = 0;
> - max_packet_size = MAX_PES_PAYLOAD;
> + max_packet_size = ts->max_packet_size;
> ts->stop_parse = 1;
> } else if (pes->data_index == 0 &&
> buf_size > max_packet_size) {
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [FFmpeg-devel] [PATCH v2] avformat/mpegts: add option max_packet_size
2022-01-15 12:49 ` Gyan Doshi
@ 2022-01-15 20:09 ` Marton Balint
2022-01-16 4:07 ` Gyan Doshi
0 siblings, 1 reply; 4+ messages in thread
From: Marton Balint @ 2022-01-15 20:09 UTC (permalink / raw)
To: FFmpeg development discussions and patches
On Sat, 15 Jan 2022, Gyan Doshi wrote:
> Plan to push tomorrow.
>
> On 2022-01-12 08:57 pm, Gyan Doshi wrote:
>> Makes maximum size of emitted packet user-tunable.
>> ---
>> doc/demuxers.texi | 4 ++++
>> libavformat/mpegts.c | 9 ++++++---
>> 2 files changed, 10 insertions(+), 3 deletions(-)
>>
>> diff --git a/doc/demuxers.texi b/doc/demuxers.texi
>> index 26ae768d7a..aef5976551 100644
>> --- a/doc/demuxers.texi
>> +++ b/doc/demuxers.texi
>> @@ -775,6 +775,10 @@ disabled). Default value is -1.
>> @item merge_pmt_versions
>> Re-use existing streams when a PMT's version is updated and elementary
>> streams move to different PIDs. Default value is 0.
>> +
>> +@item max_packet_size
>> +Set maximum size, in bytes, of packet emitted by the demuxer. Payloads
>> above this size
>> +are split across multiple packets. Range is 1 to INT_MAX. Default is
>> 204800 bytes.
>> @end table
>>
>> @section mpjpeg
>> diff --git a/libavformat/mpegts.c b/libavformat/mpegts.c
>> index 2479cb6f7d..6ff1a54706 100644
>> --- a/libavformat/mpegts.c
>> +++ b/libavformat/mpegts.c
>> @@ -162,6 +162,7 @@ struct MpegTSContext {
>>
>> int resync_size;
>> int merge_pmt_versions;
>> + int max_packet_size;
>>
>> /******************************************/
>> /* private mpegts data */
>> @@ -198,6 +199,8 @@ static const AVOption options[] = {
>> {.i64 = 0}, 0, 1, 0 },
>> {"skip_clear", "skip clearing programs", offsetof(MpegTSContext,
>> skip_clear), AV_OPT_TYPE_BOOL,
>> {.i64 = 0}, 0, 1, 0 },
>> + {"max_packet_size", "maximum size of emitted packet",
>> offsetof(MpegTSContext, max_packet_size), AV_OPT_TYPE_INT,
>> + {.i64 = MAX_PES_PAYLOAD}, 1, INT_MAX, AV_OPT_FLAG_DECODING_PARAM },
INT_MAX/2 might be better to avoid possible overflows with padding or pes
header. Or simply 1 GiB, after all, a corrupt PID might consume RAM up to
this amount, so preferably it should not be too big... Docs needs update
accordingly.
Also since MAX_PES_PAYLOAD define is no longer used in the code, I'd just
remove it and put its value directly here as the default.
Thanks,
Marton
>> { NULL },
>> };
>>
>> @@ -1121,7 +1124,7 @@ 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);
>> + int pool_size = FFMIN(ts->max_packet_size +
>> AV_INPUT_BUFFER_PADDING_SIZE, 2 << index);
>> ts->pools[index] = av_buffer_pool_init(pool_size, NULL);
>> if (!ts->pools[index])
>> return NULL;
>> @@ -1368,7 +1371,7 @@ skip:
>> break;
>> case MPEGTS_PAYLOAD:
>> do {
>> - int max_packet_size = MAX_PES_PAYLOAD;
>> + int max_packet_size = ts->max_packet_size;
>> if (pes->PES_packet_length && pes->PES_packet_length +
>> PES_START_SIZE > pes->pes_header_size)
>> max_packet_size = pes->PES_packet_length +
>> PES_START_SIZE - pes->pes_header_size;
>> @@ -1378,7 +1381,7 @@ skip:
>> if (ret < 0)
>> return ret;
>> pes->PES_packet_length = 0;
>> - max_packet_size = MAX_PES_PAYLOAD;
>> + max_packet_size = ts->max_packet_size;
>> ts->stop_parse = 1;
>> } else if (pes->data_index == 0 &&
>> buf_size > max_packet_size) {
>
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
> To unsubscribe, visit link above, or email
> ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
>
>
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [FFmpeg-devel] [PATCH v2] avformat/mpegts: add option max_packet_size
2022-01-15 20:09 ` Marton Balint
@ 2022-01-16 4:07 ` Gyan Doshi
0 siblings, 0 replies; 4+ messages in thread
From: Gyan Doshi @ 2022-01-16 4:07 UTC (permalink / raw)
To: ffmpeg-devel
On 2022-01-16 01:39 am, Marton Balint wrote:
>
>
> On Sat, 15 Jan 2022, Gyan Doshi wrote:
>
>> Plan to push tomorrow.
>>
>> On 2022-01-12 08:57 pm, Gyan Doshi wrote:
>>> Makes maximum size of emitted packet user-tunable.
>>> ---
>>> doc/demuxers.texi | 4 ++++
>>> libavformat/mpegts.c | 9 ++++++---
>>> 2 files changed, 10 insertions(+), 3 deletions(-)
>>>
>>> diff --git a/doc/demuxers.texi b/doc/demuxers.texi
>>> index 26ae768d7a..aef5976551 100644
>>> --- a/doc/demuxers.texi
>>> +++ b/doc/demuxers.texi
>>> @@ -775,6 +775,10 @@ disabled). Default value is -1.
>>> @item merge_pmt_versions
>>> Re-use existing streams when a PMT's version is updated and
>>> elementary
>>> streams move to different PIDs. Default value is 0.
>>> +
>>> +@item max_packet_size
>>> +Set maximum size, in bytes, of packet emitted by the demuxer.
>>> Payloads
>>> above this size
>>> +are split across multiple packets. Range is 1 to INT_MAX. Default is
>>> 204800 bytes.
>>> @end table
>>>
>>> @section mpjpeg
>>> diff --git a/libavformat/mpegts.c b/libavformat/mpegts.c
>>> index 2479cb6f7d..6ff1a54706 100644
>>> --- a/libavformat/mpegts.c
>>> +++ b/libavformat/mpegts.c
>>> @@ -162,6 +162,7 @@ struct MpegTSContext {
>>>
>>> int resync_size;
>>> int merge_pmt_versions;
>>> + int max_packet_size;
>>>
>>> /******************************************/
>>> /* private mpegts data */
>>> @@ -198,6 +199,8 @@ static const AVOption options[] = {
>>> {.i64 = 0}, 0, 1, 0 },
>>> {"skip_clear", "skip clearing programs", offsetof(MpegTSContext,
>>> skip_clear), AV_OPT_TYPE_BOOL,
>>> {.i64 = 0}, 0, 1, 0 },
>>> + {"max_packet_size", "maximum size of emitted packet",
>>> offsetof(MpegTSContext, max_packet_size), AV_OPT_TYPE_INT,
>>> + {.i64 = MAX_PES_PAYLOAD}, 1, INT_MAX,
>>> AV_OPT_FLAG_DECODING_PARAM },
>
> INT_MAX/2 might be better to avoid possible overflows with padding or
> pes header. Or simply 1 GiB, after all, a corrupt PID might consume
> RAM up to this amount, so preferably it should not be too big... Docs
> needs update accordingly.
>
> Also since MAX_PES_PAYLOAD define is no longer used in the code, I'd
> just remove it and put its value directly here as the default.
Will change to INT_MAX/2 and push.
Thanks,
Gyan
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2022-01-16 4:08 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-01-12 15:27 [FFmpeg-devel] [PATCH v2] avformat/mpegts: add option max_packet_size Gyan Doshi
2022-01-15 12:49 ` Gyan Doshi
2022-01-15 20:09 ` Marton Balint
2022-01-16 4:07 ` Gyan Doshi
Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
This inbox may be cloned and mirrored by anyone:
git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git
# If you have public-inbox 1.1+ installed, you may
# initialize and index your mirror using the following commands:
public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \
ffmpegdev@gitmailbox.com
public-inbox-index ffmpegdev
Example config snippet for mirrors.
AGPL code for this site: git clone https://public-inbox.org/public-inbox.git