* [FFmpeg-devel] [PATCH 1/2] avcodec/codec_par: always clear extradata_size in avcodec_parameters_to_context()
@ 2024-04-20 23:43 James Almer
2024-04-20 23:43 ` [FFmpeg-devel] [PATCH 2/2] avformat/demux: extract extradata from packets when context update is requested James Almer
2024-04-23 13:57 ` [FFmpeg-devel] [PATCH 1/2] avcodec/codec_par: always clear extradata_size in avcodec_parameters_to_context() James Almer
0 siblings, 2 replies; 8+ messages in thread
From: James Almer @ 2024-04-20 23:43 UTC (permalink / raw)
To: ffmpeg-devel
Missed in d383ae43c266b160348db04f2fd17ccf30286784.
Signed-off-by: James Almer <jamrial@gmail.com>
---
libavcodec/codec_par.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/libavcodec/codec_par.c b/libavcodec/codec_par.c
index 212cb97d77..790ea01d10 100644
--- a/libavcodec/codec_par.c
+++ b/libavcodec/codec_par.c
@@ -250,6 +250,7 @@ int avcodec_parameters_to_context(AVCodecContext *codec,
}
av_freep(&codec->extradata);
+ codec->extradata_size = 0;
if (par->extradata) {
codec->extradata = av_mallocz(par->extradata_size + AV_INPUT_BUFFER_PADDING_SIZE);
if (!codec->extradata)
--
2.44.0
_______________________________________________
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] 8+ messages in thread
* [FFmpeg-devel] [PATCH 2/2] avformat/demux: extract extradata from packets when context update is requested
2024-04-20 23:43 [FFmpeg-devel] [PATCH 1/2] avcodec/codec_par: always clear extradata_size in avcodec_parameters_to_context() James Almer
@ 2024-04-20 23:43 ` James Almer
2024-04-21 15:18 ` [FFmpeg-devel] [PATCH 2/2 v2] " James Almer
2024-04-23 13:57 ` [FFmpeg-devel] [PATCH 1/2] avcodec/codec_par: always clear extradata_size in avcodec_parameters_to_context() James Almer
1 sibling, 1 reply; 8+ messages in thread
From: James Almer @ 2024-04-20 23:43 UTC (permalink / raw)
To: ffmpeg-devel
If the demuxer doesn't set extradata in the stream's codecpar, a
need_context_update request will delete the previously extracted extradata in
the stream's internal AVCodecContext.
As we can't ensure the old extradata is valid for the stream in its post
context update request state, try to get extradata from the new packet instead
of preserving the old in some form.
Signed-off-by: James Almer <jamrial@gmail.com>
---
libavformat/demux.c | 9 +++++++++
1 file changed, 9 insertions(+)
diff --git a/libavformat/demux.c b/libavformat/demux.c
index abfd5fee7d..253a4783c4 100644
--- a/libavformat/demux.c
+++ b/libavformat/demux.c
@@ -1319,6 +1319,8 @@ fail:
return ret;
}
+static int extract_extradata(FFFormatContext *si, AVStream *st, const AVPacket *pkt);
+
static int read_frame_internal(AVFormatContext *s, AVPacket *pkt)
{
FFFormatContext *const si = ffformatcontext(s);
@@ -1373,6 +1375,11 @@ static int read_frame_internal(AVFormatContext *s, AVPacket *pkt)
return ret;
}
+ if (!sti->avctx->extradata &&
+ (ret = extract_extradata(si, st, pkt)) < 0) {
+ av_packet_unref(pkt);
+ return ret;
+ }
sti->codec_desc = avcodec_descriptor_get(sti->avctx->codec_id);
sti->need_context_update = 0;
@@ -2470,6 +2477,8 @@ static int extract_extradata(FFFormatContext *si, AVStream *st, const AVPacket *
if (ret < 0)
return ret;
+ av_bsf_flush(sti->extract_extradata.bsf);
+
ret = av_bsf_send_packet(sti->extract_extradata.bsf, pkt_ref);
if (ret < 0) {
av_packet_unref(pkt_ref);
--
2.44.0
_______________________________________________
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] 8+ messages in thread
* [FFmpeg-devel] [PATCH 2/2 v2] avformat/demux: extract extradata from packets when context update is requested
2024-04-20 23:43 ` [FFmpeg-devel] [PATCH 2/2] avformat/demux: extract extradata from packets when context update is requested James Almer
@ 2024-04-21 15:18 ` James Almer
2024-04-21 15:32 ` Andreas Rheinhardt
0 siblings, 1 reply; 8+ messages in thread
From: James Almer @ 2024-04-21 15:18 UTC (permalink / raw)
To: ffmpeg-devel
If the demuxer doesn't set extradata in the stream's codecpar, a
need_context_update request will delete the previously extracted extradata in
the stream's internal AVCodecContext.
As we can't ensure the old extradata is valid for the stream in its post
context update request state, try to get extradata from the new packet instead
of attempting to preserve the old in some form.
Signed-off-by: James Almer <jamrial@gmail.com>
---
libavformat/demux.c | 12 +++++++++++-
1 file changed, 11 insertions(+), 1 deletion(-)
diff --git a/libavformat/demux.c b/libavformat/demux.c
index abfd5fee7d..39aa1cd4e3 100644
--- a/libavformat/demux.c
+++ b/libavformat/demux.c
@@ -1319,6 +1319,8 @@ fail:
return ret;
}
+static int extract_extradata(FFFormatContext *si, AVStream *st, const AVPacket *pkt);
+
static int read_frame_internal(AVFormatContext *s, AVPacket *pkt)
{
FFFormatContext *const si = ffformatcontext(s);
@@ -1373,6 +1375,11 @@ static int read_frame_internal(AVFormatContext *s, AVPacket *pkt)
return ret;
}
+ if (!sti->avctx->extradata &&
+ (ret = extract_extradata(si, st, pkt)) < 0) {
+ av_packet_unref(pkt);
+ return ret;
+ }
sti->codec_desc = avcodec_descriptor_get(sti->avctx->codec_id);
sti->need_context_update = 0;
@@ -2470,6 +2477,8 @@ static int extract_extradata(FFFormatContext *si, AVStream *st, const AVPacket *
if (ret < 0)
return ret;
+ av_bsf_flush(sti->extract_extradata.bsf);
+
ret = av_bsf_send_packet(sti->extract_extradata.bsf, pkt_ref);
if (ret < 0) {
av_packet_unref(pkt_ref);
@@ -3090,7 +3099,8 @@ find_stream_info_err:
err = codec_close(sti);
if (err < 0 && ret >= 0)
ret = err;
- av_bsf_free(&sti->extract_extradata.bsf);
+ if (sti->extract_extradata.bsf)
+ av_bsf_flush(sti->extract_extradata.bsf);
}
if (ic->pb) {
FFIOContext *const ctx = ffiocontext(ic->pb);
--
2.44.0
_______________________________________________
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] 8+ messages in thread
* Re: [FFmpeg-devel] [PATCH 2/2 v2] avformat/demux: extract extradata from packets when context update is requested
2024-04-21 15:18 ` [FFmpeg-devel] [PATCH 2/2 v2] " James Almer
@ 2024-04-21 15:32 ` Andreas Rheinhardt
2024-04-21 15:52 ` James Almer
0 siblings, 1 reply; 8+ messages in thread
From: Andreas Rheinhardt @ 2024-04-21 15:32 UTC (permalink / raw)
To: ffmpeg-devel
James Almer:
> If the demuxer doesn't set extradata in the stream's codecpar, a
> need_context_update request will delete the previously extracted extradata in
> the stream's internal AVCodecContext.
> As we can't ensure the old extradata is valid for the stream in its post
> context update request state, try to get extradata from the new packet instead
> of attempting to preserve the old in some form.
>
> Signed-off-by: James Almer <jamrial@gmail.com>
> ---
> libavformat/demux.c | 12 +++++++++++-
> 1 file changed, 11 insertions(+), 1 deletion(-)
>
> diff --git a/libavformat/demux.c b/libavformat/demux.c
> index abfd5fee7d..39aa1cd4e3 100644
> --- a/libavformat/demux.c
> +++ b/libavformat/demux.c
> @@ -1319,6 +1319,8 @@ fail:
> return ret;
> }
>
> +static int extract_extradata(FFFormatContext *si, AVStream *st, const AVPacket *pkt);
> +
> static int read_frame_internal(AVFormatContext *s, AVPacket *pkt)
> {
> FFFormatContext *const si = ffformatcontext(s);
> @@ -1373,6 +1375,11 @@ static int read_frame_internal(AVFormatContext *s, AVPacket *pkt)
> return ret;
> }
>
> + if (!sti->avctx->extradata &&
> + (ret = extract_extradata(si, st, pkt)) < 0) {
> + av_packet_unref(pkt);
> + return ret;
> + }
> sti->codec_desc = avcodec_descriptor_get(sti->avctx->codec_id);
>
> sti->need_context_update = 0;
> @@ -2470,6 +2477,8 @@ static int extract_extradata(FFFormatContext *si, AVStream *st, const AVPacket *
> if (ret < 0)
> return ret;
>
> + av_bsf_flush(sti->extract_extradata.bsf);
> +
> ret = av_bsf_send_packet(sti->extract_extradata.bsf, pkt_ref);
> if (ret < 0) {
> av_packet_unref(pkt_ref);
> @@ -3090,7 +3099,8 @@ find_stream_info_err:
> err = codec_close(sti);
> if (err < 0 && ret >= 0)
> ret = err;
> - av_bsf_free(&sti->extract_extradata.bsf);
> + if (sti->extract_extradata.bsf)
> + av_bsf_flush(sti->extract_extradata.bsf);
> }
> if (ic->pb) {
> FFIOContext *const ctx = ffiocontext(ic->pb);
This will keep the BSF around for longer than necessary, although only a
tiny minority of demuxers ever set need_context_update at all.
- Andreas
_______________________________________________
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] 8+ messages in thread
* Re: [FFmpeg-devel] [PATCH 2/2 v2] avformat/demux: extract extradata from packets when context update is requested
2024-04-21 15:32 ` Andreas Rheinhardt
@ 2024-04-21 15:52 ` James Almer
2024-04-21 16:48 ` Andreas Rheinhardt
0 siblings, 1 reply; 8+ messages in thread
From: James Almer @ 2024-04-21 15:52 UTC (permalink / raw)
To: ffmpeg-devel
On 4/21/2024 12:32 PM, Andreas Rheinhardt wrote:
> James Almer:
>> If the demuxer doesn't set extradata in the stream's codecpar, a
>> need_context_update request will delete the previously extracted extradata in
>> the stream's internal AVCodecContext.
>> As we can't ensure the old extradata is valid for the stream in its post
>> context update request state, try to get extradata from the new packet instead
>> of attempting to preserve the old in some form.
>>
>> Signed-off-by: James Almer <jamrial@gmail.com>
>> ---
>> libavformat/demux.c | 12 +++++++++++-
>> 1 file changed, 11 insertions(+), 1 deletion(-)
>>
>> diff --git a/libavformat/demux.c b/libavformat/demux.c
>> index abfd5fee7d..39aa1cd4e3 100644
>> --- a/libavformat/demux.c
>> +++ b/libavformat/demux.c
>> @@ -1319,6 +1319,8 @@ fail:
>> return ret;
>> }
>>
>> +static int extract_extradata(FFFormatContext *si, AVStream *st, const AVPacket *pkt);
>> +
>> static int read_frame_internal(AVFormatContext *s, AVPacket *pkt)
>> {
>> FFFormatContext *const si = ffformatcontext(s);
>> @@ -1373,6 +1375,11 @@ static int read_frame_internal(AVFormatContext *s, AVPacket *pkt)
>> return ret;
>> }
>>
>> + if (!sti->avctx->extradata &&
>> + (ret = extract_extradata(si, st, pkt)) < 0) {
>> + av_packet_unref(pkt);
>> + return ret;
>> + }
>> sti->codec_desc = avcodec_descriptor_get(sti->avctx->codec_id);
>>
>> sti->need_context_update = 0;
>> @@ -2470,6 +2477,8 @@ static int extract_extradata(FFFormatContext *si, AVStream *st, const AVPacket *
>> if (ret < 0)
>> return ret;
>>
>> + av_bsf_flush(sti->extract_extradata.bsf);
>> +
>> ret = av_bsf_send_packet(sti->extract_extradata.bsf, pkt_ref);
>> if (ret < 0) {
>> av_packet_unref(pkt_ref);
>> @@ -3090,7 +3099,8 @@ find_stream_info_err:
>> err = codec_close(sti);
>> if (err < 0 && ret >= 0)
>> ret = err;
>> - av_bsf_free(&sti->extract_extradata.bsf);
>> + if (sti->extract_extradata.bsf)
>> + av_bsf_flush(sti->extract_extradata.bsf);
>> }
>> if (ic->pb) {
>> FFIOContext *const ctx = ffiocontext(ic->pb);
>
> This will keep the BSF around for longer than necessary, although only a
> tiny minority of demuxers ever set need_context_update at all.
It's not exactly a massive context, so i don't think it's a problem. But
if you prefer, i could add an FF_INFMT_FLAG_ for this.
_______________________________________________
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] 8+ messages in thread
* Re: [FFmpeg-devel] [PATCH 2/2 v2] avformat/demux: extract extradata from packets when context update is requested
2024-04-21 15:52 ` James Almer
@ 2024-04-21 16:48 ` Andreas Rheinhardt
2024-04-22 3:01 ` [FFmpeg-devel] [PATCH 2/2 v3] " James Almer
0 siblings, 1 reply; 8+ messages in thread
From: Andreas Rheinhardt @ 2024-04-21 16:48 UTC (permalink / raw)
To: ffmpeg-devel
James Almer:
> On 4/21/2024 12:32 PM, Andreas Rheinhardt wrote:
>> James Almer:
>>> If the demuxer doesn't set extradata in the stream's codecpar, a
>>> need_context_update request will delete the previously extracted
>>> extradata in
>>> the stream's internal AVCodecContext.
>>> As we can't ensure the old extradata is valid for the stream in its post
>>> context update request state, try to get extradata from the new
>>> packet instead
>>> of attempting to preserve the old in some form.
>>>
>>> Signed-off-by: James Almer <jamrial@gmail.com>
>>> ---
>>> libavformat/demux.c | 12 +++++++++++-
>>> 1 file changed, 11 insertions(+), 1 deletion(-)
>>>
>>> diff --git a/libavformat/demux.c b/libavformat/demux.c
>>> index abfd5fee7d..39aa1cd4e3 100644
>>> --- a/libavformat/demux.c
>>> +++ b/libavformat/demux.c
>>> @@ -1319,6 +1319,8 @@ fail:
>>> return ret;
>>> }
>>> +static int extract_extradata(FFFormatContext *si, AVStream *st,
>>> const AVPacket *pkt);
>>> +
>>> static int read_frame_internal(AVFormatContext *s, AVPacket *pkt)
>>> {
>>> FFFormatContext *const si = ffformatcontext(s);
>>> @@ -1373,6 +1375,11 @@ static int read_frame_internal(AVFormatContext
>>> *s, AVPacket *pkt)
>>> return ret;
>>> }
>>> + if (!sti->avctx->extradata &&
>>> + (ret = extract_extradata(si, st, pkt)) < 0) {
>>> + av_packet_unref(pkt);
>>> + return ret;
>>> + }
>>> sti->codec_desc =
>>> avcodec_descriptor_get(sti->avctx->codec_id);
>>> sti->need_context_update = 0;
>>> @@ -2470,6 +2477,8 @@ static int extract_extradata(FFFormatContext
>>> *si, AVStream *st, const AVPacket *
>>> if (ret < 0)
>>> return ret;
>>> + av_bsf_flush(sti->extract_extradata.bsf);
>>> +
>>> ret = av_bsf_send_packet(sti->extract_extradata.bsf, pkt_ref);
>>> if (ret < 0) {
>>> av_packet_unref(pkt_ref);
>>> @@ -3090,7 +3099,8 @@ find_stream_info_err:
>>> err = codec_close(sti);
>>> if (err < 0 && ret >= 0)
>>> ret = err;
>>> - av_bsf_free(&sti->extract_extradata.bsf);
>>> + if (sti->extract_extradata.bsf)
>>> + av_bsf_flush(sti->extract_extradata.bsf);
>>> }
>>> if (ic->pb) {
>>> FFIOContext *const ctx = ffiocontext(ic->pb);
>>
>> This will keep the BSF around for longer than necessary, although only a
>> tiny minority of demuxers ever set need_context_update at all.
>
> It's not exactly a massive context, so i don't think it's a problem. But
> if you prefer, i could add an FF_INFMT_FLAG_ for this.
Actually, it is worse: It is legal for the codec id to change upon
need_context_update and then the BSF would still be configured for the
old BSF.
Anyway, an FF_INFMT_FLAG flag is overkill for this: Just reset the
extract_extradata.inited flag.
- Andreas
_______________________________________________
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] 8+ messages in thread
* [FFmpeg-devel] [PATCH 2/2 v3] avformat/demux: extract extradata from packets when context update is requested
2024-04-21 16:48 ` Andreas Rheinhardt
@ 2024-04-22 3:01 ` James Almer
0 siblings, 0 replies; 8+ messages in thread
From: James Almer @ 2024-04-22 3:01 UTC (permalink / raw)
To: ffmpeg-devel
If the demuxer doesn't set extradata in the stream's codecpar, a
need_context_update request will delete the previously extracted extradata in
the stream's internal AVCodecContext.
As we can't ensure the old extradata is valid for the stream in its post
context update request state, try to get extradata from the new packet instead
of attempting to preserve the old in some form.
Signed-off-by: James Almer <jamrial@gmail.com>
---
libavformat/demux.c | 13 +++++++++++++
1 file changed, 13 insertions(+)
diff --git a/libavformat/demux.c b/libavformat/demux.c
index abfd5fee7d..ecefe7e0a7 100644
--- a/libavformat/demux.c
+++ b/libavformat/demux.c
@@ -1319,6 +1319,8 @@ fail:
return ret;
}
+static int extract_extradata(FFFormatContext *si, AVStream *st, const AVPacket *pkt);
+
static int read_frame_internal(AVFormatContext *s, AVPacket *pkt)
{
FFFormatContext *const si = ffformatcontext(s);
@@ -1373,6 +1375,16 @@ static int read_frame_internal(AVFormatContext *s, AVPacket *pkt)
return ret;
}
+ if (!sti->avctx->extradata) {
+ sti->extract_extradata.inited = 0;
+
+ ret = extract_extradata(si, st, pkt);
+ if (ret < 0) {
+ av_packet_unref(pkt);
+ return ret;
+ }
+ }
+
sti->codec_desc = avcodec_descriptor_get(sti->avctx->codec_id);
sti->need_context_update = 0;
@@ -2427,6 +2439,7 @@ static int extract_extradata_init(AVStream *st)
if (!ret)
goto finish;
+ av_bsf_free(&sti->extract_extradata.bsf);
ret = av_bsf_alloc(f, &sti->extract_extradata.bsf);
if (ret < 0)
return ret;
--
2.44.0
_______________________________________________
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] 8+ messages in thread
* Re: [FFmpeg-devel] [PATCH 1/2] avcodec/codec_par: always clear extradata_size in avcodec_parameters_to_context()
2024-04-20 23:43 [FFmpeg-devel] [PATCH 1/2] avcodec/codec_par: always clear extradata_size in avcodec_parameters_to_context() James Almer
2024-04-20 23:43 ` [FFmpeg-devel] [PATCH 2/2] avformat/demux: extract extradata from packets when context update is requested James Almer
@ 2024-04-23 13:57 ` James Almer
1 sibling, 0 replies; 8+ messages in thread
From: James Almer @ 2024-04-23 13:57 UTC (permalink / raw)
To: ffmpeg-devel
On 4/20/2024 8:43 PM, James Almer wrote:
> Missed in d383ae43c266b160348db04f2fd17ccf30286784.
>
> Signed-off-by: James Almer <jamrial@gmail.com>
> ---
> libavcodec/codec_par.c | 1 +
> 1 file changed, 1 insertion(+)
>
> diff --git a/libavcodec/codec_par.c b/libavcodec/codec_par.c
> index 212cb97d77..790ea01d10 100644
> --- a/libavcodec/codec_par.c
> +++ b/libavcodec/codec_par.c
> @@ -250,6 +250,7 @@ int avcodec_parameters_to_context(AVCodecContext *codec,
> }
>
> av_freep(&codec->extradata);
> + codec->extradata_size = 0;
> if (par->extradata) {
> codec->extradata = av_mallocz(par->extradata_size + AV_INPUT_BUFFER_PADDING_SIZE);
> if (!codec->extradata)
Will apply the set.
_______________________________________________
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] 8+ messages in thread
end of thread, other threads:[~2024-04-23 13:57 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-04-20 23:43 [FFmpeg-devel] [PATCH 1/2] avcodec/codec_par: always clear extradata_size in avcodec_parameters_to_context() James Almer
2024-04-20 23:43 ` [FFmpeg-devel] [PATCH 2/2] avformat/demux: extract extradata from packets when context update is requested James Almer
2024-04-21 15:18 ` [FFmpeg-devel] [PATCH 2/2 v2] " James Almer
2024-04-21 15:32 ` Andreas Rheinhardt
2024-04-21 15:52 ` James Almer
2024-04-21 16:48 ` Andreas Rheinhardt
2024-04-22 3:01 ` [FFmpeg-devel] [PATCH 2/2 v3] " James Almer
2024-04-23 13:57 ` [FFmpeg-devel] [PATCH 1/2] avcodec/codec_par: always clear extradata_size in avcodec_parameters_to_context() James Almer
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