On 12/14/24 04:12, Anton Khirnov wrote:
Quoting Scott Theisen (2024-12-14 04:06:45)
On 12/13/24 17:39, Marth64 wrote:
Hi Scott,

Thanks for sharing this. I had read your original email also
([RFC] libavcodec/mpeg12dec.c: CC data from skipped frames)
and was thinking about the statement. The patch helps
visualize the issue a bit better.

I need to study this and test it to understand it better.
Meantime, I will apply locally and play around with it.

If any more seasoned EIA608 experts have any thoughts please share.
The problem is the use of av_buffer_realloc() instead of av_buffer_alloc().

| old_size |
realloc(new_size)
| old_size + (undefined values) | (new_size total bytes) (new_size is
always > old_size)
realloc copies data already in the buffer to the first old_size bytes.

The SCTE-20 code sets the extra space to 0, but the others leave it
undefined.

However, the old_size data is then overwritten, potentially partially, while
the size of the array is still new_size when there are only new_size -
old_size
valid bytes.

I think it is reasonable to concatenate the CC data until a frame can be
exported.
Since I don't know if there is a frame exported when all of the video
frame's data slices
have been skipped (e.g. B frame with open GOP),
what exactly do you mean by 'skipped' here?


In mpeg12dec.c, decode_chunks() (see lines 2400 - 2560) will skip the data slices when certain conditions are met and only when none are met will decode_chunks() call mpeg_field_start(), which attaches a53_buf_ref to the frame.

For example (line 2470),
```
if (!s2->last_pic.ptr) {
    /* Skip B-frames if we do not have reference frames and
     * GOP is not closed. */
    if (s2->pict_type == AV_PICTURE_TYPE_B) {
        if (!s->closed_gop) {
            skip_frame = 1;
            av_log(s2->avctx, AV_LOG_DEBUG,
                   "Skipping B slice due to open GOP\n");
            break;
        }
    }
}
```

This skips all of the data slices of one or more coded pictures of the coded B-frames immediately following the coded I-frame which follows the GOP header when skipping or at the beginning of the file for my ATSC samples.

Since mpeg_field_start() is not called, a53_buf_ref is not NULL when the CC user data for the next coded picture is found.  Also, as far as I can tell, skip_frame = 1 causes slice_end() to not be called, preventing a frame from being exported.

Regards,

Scott Theisen
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

Reply via email to