From: James Almer <jamrial@gmail.com>
To: ffmpeg-devel@ffmpeg.org
Subject: [FFmpeg-devel] [PATCH v2 5/6] avcodec/hevc/sei: dynamically allocate 3D Reference Displays Information SEI messages
Date: Wed, 5 Feb 2025 23:50:17 -0300
Message-ID: <20250206025017.14046-1-jamrial@gmail.com> (raw)
In-Reply-To: <20250206015614.GJ4991@pb2>
Considerably reduces the size of HEVCSEI.
Signed-off-by: James Almer <jamrial@gmail.com>
---
Fixed segfaults.
libavcodec/hevc/hevcdec.c | 10 +++++-----
libavcodec/hevc/refs.c | 4 ++--
libavcodec/hevc/sei.c | 6 +++++-
libavcodec/hevc/sei.h | 6 +++++-
4 files changed, 17 insertions(+), 9 deletions(-)
diff --git a/libavcodec/hevc/hevcdec.c b/libavcodec/hevc/hevcdec.c
index e9c045f7a1..881538fb91 100644
--- a/libavcodec/hevc/hevcdec.c
+++ b/libavcodec/hevc/hevcdec.c
@@ -429,7 +429,7 @@ FF_ENABLE_DEPRECATION_WARNINGS
static int export_multilayer(HEVCContext *s, const HEVCVPS *vps)
{
- const HEVCSEITDRDI *tdrdi = &s->sei.tdrdi;
+ const HEVCSEITDRDI *tdrdi = s->sei.tdrdi;
av_freep(&s->view_ids_available);
s->nb_view_ids_available = 0;
@@ -444,7 +444,7 @@ static int export_multilayer(HEVCContext *s, const HEVCVPS *vps)
if (!s->view_ids_available)
return AVERROR(ENOMEM);
- if (tdrdi->num_ref_displays) {
+ if (tdrdi && tdrdi->num_ref_displays) {
s->view_pos_available = av_calloc(vps->nb_layers, sizeof(*s->view_pos_available));
if (!s->view_pos_available)
return AVERROR(ENOMEM);
@@ -454,9 +454,9 @@ static int export_multilayer(HEVCContext *s, const HEVCVPS *vps)
s->view_ids_available[i] = vps->view_id[i];
if (s->view_pos_available) {
- s->view_pos_available[i] = vps->view_id[i] == tdrdi->left_view_id[0] ?
+ s->view_pos_available[i] = tdrdi && (vps->view_id[i] == tdrdi->left_view_id[0]) ?
AV_STEREO3D_VIEW_LEFT :
- vps->view_id[i] == tdrdi->right_view_id[0] ?
+ tdrdi && (vps->view_id[i] == tdrdi->right_view_id[0]) ?
AV_STEREO3D_VIEW_RIGHT : AV_STEREO3D_VIEW_UNSPEC;
}
}
@@ -4015,7 +4015,7 @@ static int hevc_update_thread_context(AVCodecContext *dst,
s->sei.common.frame_packing = s0->sei.common.frame_packing;
s->sei.common.display_orientation = s0->sei.common.display_orientation;
s->sei.common.alternative_transfer = s0->sei.common.alternative_transfer;
- s->sei.tdrdi = s0->sei.tdrdi;
+ av_refstruct_replace(&s->sei.tdrdi, s0->sei.tdrdi);
return 0;
}
diff --git a/libavcodec/hevc/refs.c b/libavcodec/hevc/refs.c
index dd7f7f95a8..d1d2f27a9b 100644
--- a/libavcodec/hevc/refs.c
+++ b/libavcodec/hevc/refs.c
@@ -104,7 +104,7 @@ static HEVCFrame *alloc_frame(HEVCContext *s, HEVCLayerContext *l)
// add view ID side data if it's nontrivial
if (vps->nb_layers > 1 || view_id) {
- HEVCSEITDRDI *tdrdi = &s->sei.tdrdi;
+ HEVCSEITDRDI *tdrdi = s->sei.tdrdi;
AVFrameSideData *sd = av_frame_side_data_new(&frame->f->side_data,
&frame->f->nb_side_data,
AV_FRAME_DATA_VIEW_ID,
@@ -113,7 +113,7 @@ static HEVCFrame *alloc_frame(HEVCContext *s, HEVCLayerContext *l)
goto fail;
*(int*)sd->data = view_id;
- if (tdrdi->num_ref_displays) {
+ if (tdrdi && tdrdi->num_ref_displays) {
AVStereo3D *stereo_3d;
stereo_3d = av_stereo3d_create_side_data(frame->f);
diff --git a/libavcodec/hevc/sei.c b/libavcodec/hevc/sei.c
index 8793d86fdc..588516043b 100644
--- a/libavcodec/hevc/sei.c
+++ b/libavcodec/hevc/sei.c
@@ -220,7 +220,11 @@ static int decode_nal_sei_prefix(GetBitContext *gb, GetByteContext *gbyte,
case SEI_TYPE_TIME_CODE:
return decode_nal_sei_timecode(&s->timecode, gb);
case SEI_TYPE_THREE_DIMENSIONAL_REFERENCE_DISPLAYS_INFO:
- return decode_nal_sei_3d_reference_displays_info(&s->tdrdi, gb);
+ av_refstruct_unref(&s->tdrdi);
+ s->tdrdi = av_refstruct_allocz(sizeof(*s->tdrdi));
+ if (!s->tdrdi)
+ return AVERROR(ENOMEM);
+ return decode_nal_sei_3d_reference_displays_info(s->tdrdi, gb);
default: {
int ret = ff_h2645_sei_message_decode(&s->common, type, AV_CODEC_ID_HEVC,
gb, gbyte, logctx);
diff --git a/libavcodec/hevc/sei.h b/libavcodec/hevc/sei.h
index ee640003bc..42ee6a20b7 100644
--- a/libavcodec/hevc/sei.h
+++ b/libavcodec/hevc/sei.h
@@ -24,6 +24,7 @@
#include <stdint.h>
#include "libavutil/buffer.h"
+#include "libavutil/refstruct.h"
#include "libavcodec/get_bits.h"
#include "libavcodec/h2645_sei.h"
@@ -101,7 +102,9 @@ typedef struct HEVCSEI {
HEVCSEIPictureTiming picture_timing;
int active_seq_parameter_set_id;
HEVCSEITimeCode timecode;
- HEVCSEITDRDI tdrdi;
+
+ // Dynamic allocations due to large size.
+ HEVCSEITDRDI *tdrdi;
} HEVCSEI;
struct HEVCParamSets;
@@ -118,6 +121,7 @@ int ff_hevc_decode_nal_sei(GetBitContext *gb, void *logctx, HEVCSEI *s,
*/
static inline void ff_hevc_reset_sei(HEVCSEI *sei)
{
+ av_refstruct_unref(&sei->tdrdi);
ff_h2645_sei_reset(&sei->common);
}
--
2.48.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".
next prev parent reply other threads:[~2025-02-06 2:50 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-02-03 22:35 [FFmpeg-devel] [PATCH v2 1/6] avutil: add an API to handle Three Dimensional Reference Displays Information James Almer
2025-02-03 22:35 ` [FFmpeg-devel] [PATCH v2 2/6] avutil/frame: add a 3D Reference Displays Information side data type James Almer
2025-02-03 22:35 ` [FFmpeg-devel] [PATCH v2 3/6] avfilter/vf_showinfo: add support for 3D Reference Displays Information side data James Almer
2025-02-03 22:35 ` [FFmpeg-devel] [PATCH 4/6] avcodec/hevc/sei: ensure num_ref_displays is not set unless the SEI message is valid James Almer
2025-02-03 22:35 ` [FFmpeg-devel] [PATCH 5/6] avcodec/hevc/sei: dynamically allocate 3D Reference Displays Information SEI messages James Almer
2025-02-06 1:56 ` Michael Niedermayer
2025-02-06 2:50 ` James Almer [this message]
2025-02-10 0:53 ` [FFmpeg-devel] [PATCH v2 " Michael Niedermayer
2025-02-10 0:59 ` James Almer
2025-02-11 17:38 ` Michael Niedermayer
2025-02-03 22:35 ` [FFmpeg-devel] [PATCH v2 6/6] avcodec/hevc/hevcdec: export 3D Reference Displays side data James Almer
2025-02-05 21:07 ` Michael Niedermayer
2025-02-05 21:16 ` James Almer
2025-02-05 21:36 ` Michael Niedermayer
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20250206025017.14046-1-jamrial@gmail.com \
--to=jamrial@gmail.com \
--cc=ffmpeg-devel@ffmpeg.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
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