Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
 help / color / mirror / Atom feed
* [FFmpeg-devel] [PATCH] avformat/rtpdec_av1: Fix fragment continuation check when OBU_HAS_SIZE_FIELD is set
@ 2025-04-13 15:56 Parallelc
  2025-04-14  7:13 ` Chris Hodges
  0 siblings, 1 reply; 3+ messages in thread
From: Parallelc @ 2025-04-13 15:56 UTC (permalink / raw)
  To: ffmpeg-devel; +Cc: Parallelc

When OBU_HAS_SIZE_FIELD is set in the OBU header, frag_obu_size remains 0.
The code used !frag_obu_size to check for unexpected fragment continuation,
which resulted in incorrect drops. Introduce expect_frag_cont to explicitly
track continuation expectation.

Signed-off-by: Parallelc <realparallelc@gmail.com>
---
 libavformat/rtpdec_av1.c | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)

diff --git a/libavformat/rtpdec_av1.c b/libavformat/rtpdec_av1.c
index 7cfc83b03c..87f8cd2b0b 100644
--- a/libavformat/rtpdec_av1.c
+++ b/libavformat/rtpdec_av1.c
@@ -53,6 +53,7 @@ struct PayloadContext {
     unsigned int frag_pkt_leb_pos;  ///< offset in buffer where OBU LEB starts
     unsigned int frag_lebs_res;     ///< number of bytes reserved for LEB
     unsigned int frag_header_size;  ///< size of OBU header (1 or 2)
+    int expect_frag_cont;           ///< expect fragment continuation in packet
     int needs_td;                   ///< indicates that a TD should be output
     int drop_fragment;              ///< drop all fragments until next frame
     int keyframe_seen;              ///< keyframe was seen
@@ -165,7 +166,7 @@ static int av1_handle_packet(AVFormatContext *ctx, PayloadContext *data,
                    seq, expected_seq);
             goto drop_fragment;
         }
-        if (!pkt->size || !data->frag_obu_size) {
+        if (!pkt->size || !data->expect_frag_cont) {
             av_log(ctx, AV_LOG_WARNING, "Unexpected fragment continuation in AV1 RTP packet\n");
             goto drop_fragment; // avoid repeated output for the same fragment
         }
@@ -187,9 +188,11 @@ static int av1_handle_packet(AVFormatContext *ctx, PayloadContext *data,
             av_log(ctx, AV_LOG_TRACE, "Timestamp changed to %u (or first pkt %d), forcing TD\n", *timestamp, is_first_pkt);
             data->needs_td = 1;
             data->frag_obu_size = 0; // new temporal unit might have been caused by dropped packets
+            data->expect_frag_cont = 0;
         }
-        if (data->frag_obu_size) {
+        if (data->expect_frag_cont) {
             data->frag_obu_size = 0; // make sure we recover
+            data->expect_frag_cont = 0;
             av_log(ctx, AV_LOG_ERROR, "Missing fragment continuation in AV1 RTP packet\n");
             return AVERROR_INVALIDDATA;
         }
@@ -362,6 +365,7 @@ static int av1_handle_packet(AVFormatContext *ctx, PayloadContext *data,
             write_leb(lebptr, final_obu_size);
 
             data->frag_obu_size = 0; // signal end of fragment
+            data->expect_frag_cont = 0;
         } else if (is_last_fragmented && !rem_pkt_size) {
             // add to total OBU size, so we can fix that in OBU header
             // (but only if the OBU size was missing!)
@@ -370,6 +374,7 @@ static int av1_handle_packet(AVFormatContext *ctx, PayloadContext *data,
             }
             // fragment not yet finished!
             result = -1;
+            data->expect_frag_cont = 1;
         }
         is_frag_cont = 0;
 
@@ -391,6 +396,7 @@ static int av1_handle_packet(AVFormatContext *ctx, PayloadContext *data,
     if (!is_last_fragmented) {
         data->frag_obu_size = 0;
         data->frag_pkt_leb_pos = 0;
+        data->expect_frag_cont = 0;
     }
 
 #ifdef RTPDEC_AV1_VERBOSE_TRACE
@@ -409,6 +415,7 @@ drop_fragment:
     data->keyframe_seen = 0;
     data->drop_fragment = 1;
     data->frag_obu_size = 0;
+    data->expect_frag_cont = 0;
     data->needs_td = 1;
     if (pkt->size) {
         av_log(ctx, AV_LOG_TRACE, "Dumping current AV1 frame packet\n");
-- 
2.43.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] 3+ messages in thread

* Re: [FFmpeg-devel] [PATCH] avformat/rtpdec_av1: Fix fragment continuation check when OBU_HAS_SIZE_FIELD is set
  2025-04-13 15:56 [FFmpeg-devel] [PATCH] avformat/rtpdec_av1: Fix fragment continuation check when OBU_HAS_SIZE_FIELD is set Parallelc
@ 2025-04-14  7:13 ` Chris Hodges
  2025-04-14  9:57   ` Parallelc
  0 siblings, 1 reply; 3+ messages in thread
From: Chris Hodges @ 2025-04-14  7:13 UTC (permalink / raw)
  To: ffmpeg-devel

Hi there,

On 4/13/25 17:56, Parallelc wrote:

> When OBU_HAS_SIZE_FIELD is set in the OBU header, frag_obu_size remains 0.
> The code used !frag_obu_size to check for unexpected fragment continuation,
> which resulted in incorrect drops. Introduce expect_frag_cont to explicitly
> track continuation expectation.

Good find! I didn't have sources that kept the OBU size field (just curious,
what did you use to generate these RTP streams?), and your fix looks good
to me (although I didn't verify it).

-- 
Best regards,
Chris

_______________________________________________
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] 3+ messages in thread

* Re: [FFmpeg-devel] [PATCH] avformat/rtpdec_av1: Fix fragment continuation check when OBU_HAS_SIZE_FIELD is set
  2025-04-14  7:13 ` Chris Hodges
@ 2025-04-14  9:57   ` Parallelc
  0 siblings, 0 replies; 3+ messages in thread
From: Parallelc @ 2025-04-14  9:57 UTC (permalink / raw)
  To: FFmpeg development discussions and patches

On Mon, Apr 14, 2025 at 3:13 PM Chris Hodges <Chris.Hodges@axis.com> wrote:
>
> Hi there,
>
> On 4/13/25 17:56, Parallelc wrote:
>
> > When OBU_HAS_SIZE_FIELD is set in the OBU header, frag_obu_size remains 0.
> > The code used !frag_obu_size to check for unexpected fragment continuation,
> > which resulted in incorrect drops. Introduce expect_frag_cont to explicitly
> > track continuation expectation.
>
> Good find! I didn't have sources that kept the OBU size field (just curious,
> what did you use to generate these RTP streams?), and your fix looks good
> to me (although I didn't verify it).
>
> --
> Best regards,
> Chris

Hi Chris,

Thanks for your review!

I'm currently working on adding WHIP and WHEP support to FFmpeg using
libdatachannel
in my personal fork: https://github.com/parallelcc/FFmpeg-WHIP-WHEP

So in my tests, the RTP streams are generated by libdatachannel or
Chrome WebRTC. They
packetize the encoder output directly, without removing the size field
like rtpenc_av1 does.

Best regards,
Parallelc
_______________________________________________
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] 3+ messages in thread

end of thread, other threads:[~2025-04-14  9:57 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-04-13 15:56 [FFmpeg-devel] [PATCH] avformat/rtpdec_av1: Fix fragment continuation check when OBU_HAS_SIZE_FIELD is set Parallelc
2025-04-14  7:13 ` Chris Hodges
2025-04-14  9:57   ` Parallelc

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