* [FFmpeg-devel] [PATCH v2 1/6] avutil: add an API to handle Three Dimensional Reference Displays Information
@ 2025-02-03 22:35 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
` (4 more replies)
0 siblings, 5 replies; 12+ messages in thread
From: James Almer @ 2025-02-03 22:35 UTC (permalink / raw)
To: ffmpeg-devel
As defined in section G.14.3.2.3 of ITU-T H.265, it's required for proper
signaling of MV-HEVC.
Signed-off-by: James Almer <jamrial@gmail.com>
---
Better namespace, and now only allocating the required display reference entries.
libavutil/Makefile | 2 +
libavutil/ref_displays_info.c | 53 +++++++++++
libavutil/ref_displays_info.h | 169 ++++++++++++++++++++++++++++++++++
3 files changed, 224 insertions(+)
create mode 100644 libavutil/ref_displays_info.c
create mode 100644 libavutil/ref_displays_info.h
diff --git a/libavutil/Makefile b/libavutil/Makefile
index f8031815bd..67e942243e 100644
--- a/libavutil/Makefile
+++ b/libavutil/Makefile
@@ -76,6 +76,7 @@ HEADERS = adler32.h \
random_seed.h \
rc4.h \
rational.h \
+ ref_displays_info.h \
refstruct.h \
replaygain.h \
ripemd.h \
@@ -166,6 +167,7 @@ OBJS = adler32.o \
pixelutils.o \
random_seed.o \
rational.o \
+ ref_displays_info.o \
refstruct.o \
reverse.o \
rc4.o \
diff --git a/libavutil/ref_displays_info.c b/libavutil/ref_displays_info.c
new file mode 100644
index 0000000000..a51aa42b54
--- /dev/null
+++ b/libavutil/ref_displays_info.c
@@ -0,0 +1,53 @@
+/*
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include <stddef.h>
+#include <stdint.h>
+
+#include "avassert.h"
+#include "mem.h"
+#include "ref_displays_info.h"
+
+AV3DReferenceDisplaysInfo *av_ref_displays_info_alloc(unsigned int num_ref_displays,
+ size_t *out_size)
+{
+ struct CombinedStruct {
+ AV3DReferenceDisplaysInfo i;
+ AV3DReferenceDisplay r;
+ };
+ const size_t ref_offset = offsetof(struct CombinedStruct, r);
+ size_t size = ref_offset;
+ AV3DReferenceDisplaysInfo *rdi;
+
+ if (num_ref_displays > (SIZE_MAX - size) / sizeof(AV3DReferenceDisplay))
+ return NULL;
+ size += sizeof(AV3DReferenceDisplay) * num_ref_displays;
+
+ rdi = av_mallocz(size);
+ if (!rdi)
+ return NULL;
+
+ rdi->num_ref_displays = num_ref_displays;
+ rdi->ref_size = sizeof(AV3DReferenceDisplay);
+ rdi->ref_offset = ref_offset;
+
+ if (out_size)
+ *out_size = size;
+
+ return rdi;
+}
diff --git a/libavutil/ref_displays_info.h b/libavutil/ref_displays_info.h
new file mode 100644
index 0000000000..02ff4fcd98
--- /dev/null
+++ b/libavutil/ref_displays_info.h
@@ -0,0 +1,169 @@
+/*
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+/**
+ * @file
+ * @ingroup lavu_video_3d_reference_displays_info
+ * 3D Reference Displays Information
+ */
+
+#ifndef AVUTIL_REF_DISPLAYS_INFO_H
+#define AVUTIL_REF_DISPLAYS_INFO_H
+
+#include <stddef.h>
+#include <stdint.h>
+
+#include "libavutil/avassert.h"
+
+/**
+ * @defgroup lavu_video_3d_reference_displays_info 3D Reference Displays Information
+ * @ingroup lavu_video
+ *
+ * The 3D Reference Displays Information describes information about the reference display
+ * width(s) and reference viewing distance(s) as well as information about the corresponding
+ * reference stereo pair(s).
+ * @{
+ */
+
+/**
+ * This structure describes information about the reference display width(s) and reference
+ * viewing distance(s) as well as information about the corresponding reference stereo pair(s).
+ * See section G.14.3.2.3 of ITU-T H.265 for more information.
+ *
+ * @note The struct must be allocated with av_ref_displays_info_alloc() and its size is not a
+ * part of the public ABI.
+ */
+typedef struct AV3DReferenceDisplaysInfo {
+ /**
+ * The number of reference displays that are signalled in this struct.
+ * Allowed range is 1 to 32, inclusive.
+ */
+ unsigned int num_ref_displays;
+
+ /**
+ * Offset in bytes from the beginning of this structure at which the array
+ * of reference displays starts.
+ */
+ size_t ref_offset;
+
+ /**
+ * Size of each reference display entry in bytes. May not match sizeof(AV3DReferenceDisplay).
+ */
+ size_t ref_size;
+
+ /**
+ * The exponent of the maximum allowable truncation error for
+ * {exponent,mantissa}_ref_display_width as given by 2<sup>(-prec_ref_display_width)</sup>.
+ */
+ uint8_t prec_ref_display_width;
+
+ /**
+ * A flag to indicate the presence of reference viewing distance.
+ * If false, the values of prec_ref_viewing_dist, exponent_ref_viewing_distance,
+ * and mantissa_ref_viewing_distance are undefined.
+ */
+ uint8_t ref_viewing_distance_flag;
+
+ /**
+ * The exponent of the maximum allowable truncation error for
+ * {exponent,mantissa}_ref_viewing_distance as given by 2<sup>^(-prec_ref_viewing_dist)</sup>.
+ * The value of prec_ref_viewing_dist shall be in the range of 0 to 31, inclusive.
+ */
+ uint8_t prec_ref_viewing_dist;
+} AV3DReferenceDisplaysInfo;
+
+/**
+ * Data structure for storing a reference display information.
+ * It is allocated as a part of AV3DReferenceDisplaysInfo and should be retrieved with
+ * av_ref_displays_info_display().
+ *
+ * sizeof(AV3DReferenceDisplay) is not a part of the ABI and new fields may be
+ * added to it.
+ */
+typedef struct AV3DReferenceDisplay {
+ /**
+ * The ViewId of the left view of a stereo pair corresponding to the n-th reference display.
+ */
+ uint16_t left_view_id;
+
+ /**
+ * The ViewId of the left view of a stereo pair corresponding to the n-th reference display.
+ */
+ uint16_t right_view_id;
+
+ /**
+ * The exponent part of the reference display width of the n-th reference display.
+ */
+ uint8_t exponent_ref_display_width;
+
+ /**
+ * The mantissa part of the reference display width of the n-th reference display.
+ */
+ uint8_t mantissa_ref_display_width;
+
+ /**
+ * Tthe exponent part of the reference viewing distance of the n-th reference display.
+ */
+ uint8_t exponent_ref_viewing_distance;
+
+ /**
+ * The mantissa part of the reference viewing distance of the n-th reference display.
+ */
+ uint8_t mantissa_ref_viewing_distance;
+
+ /**
+ * An array of flags to indicates that the information about additional horizontal shift of
+ * the left and right views for the n-th reference display is present.
+ */
+ uint8_t additional_shift_present_flag;
+
+ /**
+ * The recommended additional horizontal shift for a stereo pair corresponding to the n-th
+ * reference baseline and the n-th reference display.
+ */
+ int16_t num_sample_shift;
+} AV3DReferenceDisplay;
+
+/**
+ * Get the reference display at the specified {@code idx}.
+ * Must be between 0 and num_ref_displays - 1.
+ */
+static av_always_inline AV3DReferenceDisplay*
+av_ref_displays_info_display(AV3DReferenceDisplaysInfo *rdi, unsigned int idx)
+{
+ av_assert0(idx < rdi->num_ref_displays);
+ return (AV3DReferenceDisplay *)((uint8_t *)rdi + rdi->ref_offset +
+ idx * rdi->ref_size);
+}
+
+/**
+ * Allocates memory for AV3DReferenceDisplaysInfo, plus an array of
+ * {@code num_ref_displays} AV3DReferenceDisplay and initializes the variables.
+ * Can be freed with a normal av_free() call.
+ *
+ * @param num_ref_displays the number of reference displays.
+ * @return the newly allocated struct or NULL on failure
+ */
+AV3DReferenceDisplaysInfo *av_ref_displays_info_alloc(unsigned int num_ref_displays,
+ size_t *out_size);
+
+/**
+ * @}
+ */
+
+#endif /* AVUTIL_REF_DISPLAYS_INFO_H */
--
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".
^ permalink raw reply [flat|nested] 12+ messages in thread
* [FFmpeg-devel] [PATCH v2 2/6] avutil/frame: add a 3D Reference Displays Information side data type
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 ` 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
` (3 subsequent siblings)
4 siblings, 0 replies; 12+ messages in thread
From: James Almer @ 2025-02-03 22:35 UTC (permalink / raw)
To: ffmpeg-devel
Signed-off-by: James Almer <jamrial@gmail.com>
---
No changes since last version.
libavutil/frame.c | 1 +
libavutil/frame.h | 11 +++++++++++
2 files changed, 12 insertions(+)
diff --git a/libavutil/frame.c b/libavutil/frame.c
index 992115e04f..d1566298ae 100644
--- a/libavutil/frame.c
+++ b/libavutil/frame.c
@@ -59,6 +59,7 @@ static const AVSideDataDescriptor sd_props[] = {
[AV_FRAME_DATA_ICC_PROFILE] = { "ICC profile", AV_SIDE_DATA_PROP_GLOBAL | AV_SIDE_DATA_PROP_COLOR_DEPENDENT },
[AV_FRAME_DATA_SEI_UNREGISTERED] = { "H.26[45] User Data Unregistered SEI message", AV_SIDE_DATA_PROP_MULTI },
[AV_FRAME_DATA_VIDEO_HINT] = { "Encoding video hint", AV_SIDE_DATA_PROP_SIZE_DEPENDENT },
+ [AV_FRAME_DATA_3D_REFERENCE_DISPLAYS] = { "3D Reference Displays Information", AV_SIDE_DATA_PROP_GLOBAL },
};
static void get_frame_defaults(AVFrame *frame)
diff --git a/libavutil/frame.h b/libavutil/frame.h
index 49260ae2dd..f0de1921f4 100644
--- a/libavutil/frame.h
+++ b/libavutil/frame.h
@@ -243,6 +243,17 @@ enum AVFrameSideDataType {
* The data is an int storing the view ID.
*/
AV_FRAME_DATA_VIEW_ID,
+
+ /**
+ * This side data contains information about the reference display width(s)
+ * and reference viewing distance(s) as well as information about the
+ * corresponding reference stereo pair(s), i.e., the pair(s) of views to be
+ * displayed for the viewer's left and right eyes on the reference display
+ * at the reference viewing distance.
+ * The payload is the AV3DReferenceDisplaysInfo struct defined in
+ * libavutil/tdrdi.h.
+ */
+ AV_FRAME_DATA_3D_REFERENCE_DISPLAYS,
};
enum AVActiveFormatDescription {
--
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".
^ permalink raw reply [flat|nested] 12+ messages in thread
* [FFmpeg-devel] [PATCH v2 3/6] avfilter/vf_showinfo: add support for 3D Reference Displays Information side data
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 ` 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
` (2 subsequent siblings)
4 siblings, 0 replies; 12+ messages in thread
From: James Almer @ 2025-02-03 22:35 UTC (permalink / raw)
To: ffmpeg-devel
Signed-off-by: James Almer <jamrial@gmail.com>
---
No changes since last version.
libavfilter/vf_showinfo.c | 11 +++++++++++
1 file changed, 11 insertions(+)
diff --git a/libavfilter/vf_showinfo.c b/libavfilter/vf_showinfo.c
index 8109ca7fce..29700f5d68 100644
--- a/libavfilter/vf_showinfo.c
+++ b/libavfilter/vf_showinfo.c
@@ -38,6 +38,7 @@
#include "libavutil/pixdesc.h"
#include "libavutil/spherical.h"
#include "libavutil/stereo3d.h"
+#include "libavutil/ref_displays_info.h"
#include "libavutil/timestamp.h"
#include "libavutil/timecode.h"
#include "libavutil/mastering_display_metadata.h"
@@ -152,6 +153,13 @@ static void dump_roi(AVFilterContext *ctx, const AVFrameSideData *sd)
}
}
+static void dump_ref_displays_info(AVFilterContext *ctx, const AVFrameSideData *sd)
+{
+ const AV3DReferenceDisplaysInfo *rdi = (const AV3DReferenceDisplaysInfo *)sd->data;
+
+ av_log(ctx, AV_LOG_INFO, "number of reference displays: %u", rdi->num_ref_displays);
+}
+
static void dump_detection_bbox(AVFilterContext *ctx, const AVFrameSideData *sd)
{
int nb_bboxes;
@@ -860,6 +868,9 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *frame)
case AV_FRAME_DATA_VIEW_ID:
av_log(ctx, AV_LOG_INFO, "view id: %d\n", *(int*)sd->data);
break;
+ case AV_FRAME_DATA_3D_REFERENCE_DISPLAYS:
+ dump_ref_displays_info(ctx, sd);
+ break;
default:
if (name)
av_log(ctx, AV_LOG_INFO,
--
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".
^ permalink raw reply [flat|nested] 12+ messages in thread
* [FFmpeg-devel] [PATCH 4/6] avcodec/hevc/sei: ensure num_ref_displays is not set unless the SEI message is valid
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 ` 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-03 22:35 ` [FFmpeg-devel] [PATCH v2 6/6] avcodec/hevc/hevcdec: export 3D Reference Displays side data James Almer
4 siblings, 0 replies; 12+ messages in thread
From: James Almer @ 2025-02-03 22:35 UTC (permalink / raw)
To: ffmpeg-devel
This field can be used the same way "present" is used for other message types.
Signed-off-by: James Almer <jamrial@gmail.com>
---
libavcodec/hevc/sei.c | 11 +++++++----
1 file changed, 7 insertions(+), 4 deletions(-)
diff --git a/libavcodec/hevc/sei.c b/libavcodec/hevc/sei.c
index e11a33773c..8793d86fdc 100644
--- a/libavcodec/hevc/sei.c
+++ b/libavcodec/hevc/sei.c
@@ -152,6 +152,8 @@ static int decode_nal_sei_timecode(HEVCSEITimeCode *s, GetBitContext *gb)
static int decode_nal_sei_3d_reference_displays_info(HEVCSEITDRDI *s, GetBitContext *gb)
{
+ unsigned int num_ref_displays;
+
s->prec_ref_display_width = get_ue_golomb(gb);
if (s->prec_ref_display_width > 31)
return AVERROR_INVALIDDATA;
@@ -161,12 +163,12 @@ static int decode_nal_sei_3d_reference_displays_info(HEVCSEITDRDI *s, GetBitCont
if (s->prec_ref_viewing_dist > 31)
return AVERROR_INVALIDDATA;
}
- s->num_ref_displays = get_ue_golomb(gb);
- if (s->num_ref_displays > 31)
+ num_ref_displays = get_ue_golomb(gb);
+ if (num_ref_displays > 31)
return AVERROR_INVALIDDATA;
- s->num_ref_displays += 1;
+ num_ref_displays += 1;
- for (int i = 0; i < s->num_ref_displays; i++) {
+ for (int i = 0; i < num_ref_displays; i++) {
int length;
s->left_view_id[i] = get_ue_golomb(gb);
s->right_view_id[i] = get_ue_golomb(gb);
@@ -199,6 +201,7 @@ static int decode_nal_sei_3d_reference_displays_info(HEVCSEITDRDI *s, GetBitCont
}
}
s->three_dimensional_reference_displays_extension_flag = get_bits1(gb);
+ s->num_ref_displays = num_ref_displays;
return 0;
}
--
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".
^ permalink raw reply [flat|nested] 12+ messages in thread
* [FFmpeg-devel] [PATCH 5/6] avcodec/hevc/sei: dynamically allocate 3D Reference Displays Information SEI messages
2025-02-03 22:35 [FFmpeg-devel] [PATCH v2 1/6] avutil: add an API to handle Three Dimensional Reference Displays Information James Almer
` (2 preceding siblings ...)
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 ` James Almer
2025-02-06 1:56 ` Michael Niedermayer
2025-02-03 22:35 ` [FFmpeg-devel] [PATCH v2 6/6] avcodec/hevc/hevcdec: export 3D Reference Displays side data James Almer
4 siblings, 1 reply; 12+ messages in thread
From: James Almer @ 2025-02-03 22:35 UTC (permalink / raw)
To: ffmpeg-devel
Considerably reduces the size of HEVCSEI and eliminates data copy between threads.
Signed-off-by: James Almer <jamrial@gmail.com>
---
libavcodec/hevc/hevcdec.c | 4 ++--
libavcodec/hevc/refs.c | 4 ++--
libavcodec/hevc/sei.c | 6 +++++-
libavcodec/hevc/sei.h | 6 +++++-
4 files changed, 14 insertions(+), 6 deletions(-)
diff --git a/libavcodec/hevc/hevcdec.c b/libavcodec/hevc/hevcdec.c
index e9c045f7a1..f9ff22dbac 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;
@@ -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".
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [FFmpeg-devel] [PATCH 5/6] avcodec/hevc/sei: dynamically allocate 3D Reference Displays Information SEI messages
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 ` [FFmpeg-devel] [PATCH v2 " James Almer
0 siblings, 1 reply; 12+ messages in thread
From: Michael Niedermayer @ 2025-02-06 1:56 UTC (permalink / raw)
To: FFmpeg development discussions and patches
[-- Attachment #1.1: Type: text/plain, Size: 1861 bytes --]
On Mon, Feb 03, 2025 at 07:35:45PM -0300, James Almer wrote:
> Considerably reduces the size of HEVCSEI and eliminates data copy between threads.
>
> Signed-off-by: James Almer <jamrial@gmail.com>
> ---
> libavcodec/hevc/hevcdec.c | 4 ++--
> libavcodec/hevc/refs.c | 4 ++--
> libavcodec/hevc/sei.c | 6 +++++-
> libavcodec/hevc/sei.h | 6 +++++-
> 4 files changed, 14 insertions(+), 6 deletions(-)
this segfaults here, will probably retest tomorrow without other patches
but i removed the ones you pointed to
[vist#0:0/hevc @ 0x12015580] [dec:hevc @ 0x1201b240] View with index 1 requested, but only 1 views available in current video sequence (more views may or may not be available in later sequences).
==307141== Thread 6 dec0:0:hevc:
==307141== Invalid read of size 1
==307141== at 0x93F313: export_multilayer (in ffmpeg/ffmpeg_g)
==307141== by 0x94B51F: hevc_receive_frame (in ffmpeg/ffmpeg_g)
==307141== by 0x8798AA: ff_decode_receive_frame_internal (in ffmpeg/ffmpeg_g)
==307141== by 0x879F54: decode_receive_frame_internal (in ffmpeg/ffmpeg_g)
==307141== by 0x87A229: avcodec_send_packet (in ffmpeg/ffmpeg_g)
==307141== by 0x2FBE13: decoder_thread (in ffmpeg/ffmpeg_g)
==307141== by 0x31D6AE: task_wrapper (in ffmpeg/ffmpeg_g)
==307141== by 0x4A06608: start_thread (pthread_create.c:477)
==307141== by 0x772A352: clone (clone.S:95)
==307141== Address 0x3 is not stack'd, malloc'd or (recently) free'd
[...]
--
Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB
Any man who breaks a law that conscience tells him is unjust and willingly
accepts the penalty by staying in jail in order to arouse the conscience of
the community on the injustice of the law is at that moment expressing the
very highest respect for law. - Martin Luther King Jr
[-- Attachment #1.2: signature.asc --]
[-- Type: application/pgp-signature, Size: 195 bytes --]
[-- Attachment #2: Type: text/plain, Size: 251 bytes --]
_______________________________________________
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] 12+ messages in thread
* [FFmpeg-devel] [PATCH v2 5/6] avcodec/hevc/sei: dynamically allocate 3D Reference Displays Information SEI messages
2025-02-06 1:56 ` Michael Niedermayer
@ 2025-02-06 2:50 ` James Almer
0 siblings, 0 replies; 12+ messages in thread
From: James Almer @ 2025-02-06 2:50 UTC (permalink / raw)
To: ffmpeg-devel
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".
^ permalink raw reply [flat|nested] 12+ messages in thread
* [FFmpeg-devel] [PATCH v2 6/6] avcodec/hevc/hevcdec: export 3D Reference Displays side data
2025-02-03 22:35 [FFmpeg-devel] [PATCH v2 1/6] avutil: add an API to handle Three Dimensional Reference Displays Information James Almer
` (3 preceding siblings ...)
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-03 22:35 ` James Almer
2025-02-05 21:07 ` Michael Niedermayer
4 siblings, 1 reply; 12+ messages in thread
From: James Almer @ 2025-02-03 22:35 UTC (permalink / raw)
To: ffmpeg-devel
Signed-off-by: James Almer <jamrial@gmail.com>
---
libavcodec/hevc/hevcdec.c | 55 ++++++++++++++++++++++++++++++++++++++-
1 file changed, 54 insertions(+), 1 deletion(-)
diff --git a/libavcodec/hevc/hevcdec.c b/libavcodec/hevc/hevcdec.c
index f9ff22dbac..ffacbcad24 100644
--- a/libavcodec/hevc/hevcdec.c
+++ b/libavcodec/hevc/hevcdec.c
@@ -35,6 +35,7 @@
#include "libavutil/mem.h"
#include "libavutil/opt.h"
#include "libavutil/pixdesc.h"
+#include "libavutil/ref_displays_info.h"
#include "libavutil/stereo3d.h"
#include "libavutil/timecode.h"
@@ -4021,6 +4022,58 @@ static int hevc_update_thread_context(AVCodecContext *dst,
}
#endif
+static int hevc_sei_to_context(AVCodecContext *avctx, HEVCSEI *sei)
+{
+ const HEVCSEITDRDI *tdrdi = sei->tdrdi;
+ int ret;
+
+ if (tdrdi && tdrdi->num_ref_displays) {
+ AVBufferRef *buf;
+ size_t size;
+ AV3DReferenceDisplaysInfo *rdi = av_ref_displays_info_alloc(tdrdi->num_ref_displays, &size);
+
+ if (!rdi)
+ return AVERROR(ENOMEM);
+
+ buf = av_buffer_create((uint8_t *)rdi, size, NULL, NULL, 0);
+ if (!buf) {
+ av_free(rdi);
+ return AVERROR(ENOMEM);
+ }
+
+ rdi->prec_ref_display_width = tdrdi->prec_ref_display_width;
+ rdi->ref_viewing_distance_flag = tdrdi->ref_viewing_distance_flag;
+ rdi->prec_ref_viewing_dist = tdrdi->prec_ref_viewing_dist;
+ rdi->num_ref_displays = tdrdi->num_ref_displays;
+
+ for (int i = 0; i < rdi->num_ref_displays; i++) {
+ AV3DReferenceDisplay *ref = av_ref_displays_info_display(rdi, i);
+
+ ref->left_view_id = tdrdi->left_view_id[i];
+ ref->right_view_id = tdrdi->right_view_id[i];
+ ref->exponent_ref_display_width = tdrdi->exponent_ref_display_width[i];
+ ref->mantissa_ref_display_width = tdrdi->mantissa_ref_display_width[i];
+ ref->exponent_ref_viewing_distance = tdrdi->exponent_ref_viewing_distance[i];
+ ref->mantissa_ref_viewing_distance = tdrdi->mantissa_ref_viewing_distance[i];
+ ref->additional_shift_present_flag = tdrdi->additional_shift_present_flag[i];
+ ref->num_sample_shift = tdrdi->num_sample_shift[i];
+ }
+
+ ret = ff_frame_new_side_data_from_buf_ext(avctx, &avctx->decoded_side_data, &avctx->nb_decoded_side_data,
+ AV_FRAME_DATA_3D_REFERENCE_DISPLAYS, &buf);
+ if (ret < 0) {
+ av_buffer_unref(&buf);
+ return ret;
+ }
+ }
+
+ ret = ff_h2645_sei_to_context(avctx, &sei->common);
+ if (ret < 0)
+ return ret;
+
+ return 0;
+}
+
static av_cold int hevc_decode_init(AVCodecContext *avctx)
{
HEVCContext *s = avctx->priv_data;
@@ -4044,7 +4097,7 @@ static av_cold int hevc_decode_init(AVCodecContext *avctx)
return ret;
}
- ret = ff_h2645_sei_to_context(avctx, &s->sei.common);
+ ret = hevc_sei_to_context(avctx, &s->sei);
if (ret < 0)
return ret;
}
--
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".
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [FFmpeg-devel] [PATCH v2 6/6] avcodec/hevc/hevcdec: export 3D Reference Displays side data
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
0 siblings, 1 reply; 12+ messages in thread
From: Michael Niedermayer @ 2025-02-05 21:07 UTC (permalink / raw)
To: FFmpeg development discussions and patches
[-- Attachment #1.1: Type: text/plain, Size: 952 bytes --]
On Mon, Feb 03, 2025 at 07:35:46PM -0300, James Almer wrote:
> Signed-off-by: James Almer <jamrial@gmail.com>
> ---
> libavcodec/hevc/hevcdec.c | 55 ++++++++++++++++++++++++++++++++++++++-
> 1 file changed, 54 insertions(+), 1 deletion(-)
seems to fail to build
libavcodec/hevc/hevcdec.c: In function ‘hevc_sei_to_context’:
libavcodec/hevc/hevcdec.c:4060:15: error: too few arguments to function ‘ff_frame_new_side_data_from_buf_ext’
4060 | ret = ff_frame_new_side_data_from_buf_ext(avctx, &avctx->decoded_side_data, &avctx->nb_decoded_side_data,
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
[...]
thx
--
Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB
Rewriting code that is poorly written but fully understood is good.
Rewriting code that one doesnt understand is a sign that one is less smart
than the original author, trying to rewrite it will not make it better.
[-- Attachment #1.2: signature.asc --]
[-- Type: application/pgp-signature, Size: 195 bytes --]
[-- Attachment #2: Type: text/plain, Size: 251 bytes --]
_______________________________________________
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] 12+ messages in thread
* Re: [FFmpeg-devel] [PATCH v2 6/6] avcodec/hevc/hevcdec: export 3D Reference Displays side data
2025-02-05 21:07 ` Michael Niedermayer
@ 2025-02-05 21:16 ` James Almer
2025-02-05 21:36 ` Michael Niedermayer
0 siblings, 1 reply; 12+ messages in thread
From: James Almer @ 2025-02-05 21:16 UTC (permalink / raw)
To: ffmpeg-devel
[-- Attachment #1.1.1: Type: text/plain, Size: 920 bytes --]
On 2/5/2025 6:07 PM, Michael Niedermayer wrote:
> On Mon, Feb 03, 2025 at 07:35:46PM -0300, James Almer wrote:
>> Signed-off-by: James Almer <jamrial@gmail.com>
>> ---
>> libavcodec/hevc/hevcdec.c | 55 ++++++++++++++++++++++++++++++++++++++-
>> 1 file changed, 54 insertions(+), 1 deletion(-)
>
> seems to fail to build
> libavcodec/hevc/hevcdec.c: In function ‘hevc_sei_to_context’:
> libavcodec/hevc/hevcdec.c:4060:15: error: too few arguments to function ‘ff_frame_new_side_data_from_buf_ext’
> 4060 | ret = ff_frame_new_side_data_from_buf_ext(avctx, &avctx->decoded_side_data, &avctx->nb_decoded_side_data,
> | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Do you happen to have
https://patchwork.ffmpeg.org/project/ffmpeg/patch/20250204211256.10228-1-jamrial@gmail.com/
also in your tree? That's a separate patchset and currently incompatible
with this one.
[-- Attachment #1.2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 495 bytes --]
[-- Attachment #2: Type: text/plain, Size: 251 bytes --]
_______________________________________________
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] 12+ messages in thread
* Re: [FFmpeg-devel] [PATCH v2 6/6] avcodec/hevc/hevcdec: export 3D Reference Displays side data
2025-02-05 21:16 ` James Almer
@ 2025-02-05 21:36 ` Michael Niedermayer
0 siblings, 0 replies; 12+ messages in thread
From: Michael Niedermayer @ 2025-02-05 21:36 UTC (permalink / raw)
To: FFmpeg development discussions and patches
[-- Attachment #1.1: Type: text/plain, Size: 1279 bytes --]
On Wed, Feb 05, 2025 at 06:16:35PM -0300, James Almer wrote:
> On 2/5/2025 6:07 PM, Michael Niedermayer wrote:
> > On Mon, Feb 03, 2025 at 07:35:46PM -0300, James Almer wrote:
> > > Signed-off-by: James Almer <jamrial@gmail.com>
> > > ---
> > > libavcodec/hevc/hevcdec.c | 55 ++++++++++++++++++++++++++++++++++++++-
> > > 1 file changed, 54 insertions(+), 1 deletion(-)
> >
> > seems to fail to build
> > libavcodec/hevc/hevcdec.c: In function ‘hevc_sei_to_context’:
> > libavcodec/hevc/hevcdec.c:4060:15: error: too few arguments to function ‘ff_frame_new_side_data_from_buf_ext’
> > 4060 | ret = ff_frame_new_side_data_from_buf_ext(avctx, &avctx->decoded_side_data, &avctx->nb_decoded_side_data,
> > | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>
> Do you happen to have https://patchwork.ffmpeg.org/project/ffmpeg/patch/20250204211256.10228-1-jamrial@gmail.com/
> also in your tree? That's a separate patchset and currently incompatible
> with this one.
yes i had this locally too
thx
[...]
--
Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB
"Nothing to hide" only works if the folks in power share the values of
you and everyone you know entirely and always will -- Tom Scott
[-- Attachment #1.2: signature.asc --]
[-- Type: application/pgp-signature, Size: 195 bytes --]
[-- Attachment #2: Type: text/plain, Size: 251 bytes --]
_______________________________________________
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] 12+ messages in thread
* [FFmpeg-devel] [PATCH 6/6] avcodec/hevc/hevcdec: export 3D Reference Displays side data
@ 2025-01-31 14:00 James Almer
2025-01-31 20:58 ` [FFmpeg-devel] [PATCH v2 " James Almer
0 siblings, 1 reply; 12+ messages in thread
From: James Almer @ 2025-01-31 14:00 UTC (permalink / raw)
To: ffmpeg-devel
Signed-off-by: James Almer <jamrial@gmail.com>
---
libavcodec/hevc/hevcdec.c | 37 +++++++++++++++++++++++++++++++++++++
1 file changed, 37 insertions(+)
diff --git a/libavcodec/hevc/hevcdec.c b/libavcodec/hevc/hevcdec.c
index 7d3e844945..91119fbc58 100644
--- a/libavcodec/hevc/hevcdec.c
+++ b/libavcodec/hevc/hevcdec.c
@@ -36,6 +36,7 @@
#include "libavutil/opt.h"
#include "libavutil/pixdesc.h"
#include "libavutil/stereo3d.h"
+#include "libavutil/tdrdi.h"
#include "libavutil/timecode.h"
#include "aom_film_grain.h"
@@ -416,6 +417,42 @@ FF_ENABLE_DEPRECATION_WARNINGS
avctx->color_trc = s->sei.common.alternative_transfer.preferred_transfer_characteristics;
}
+ if (s->sei.tdrdi.num_ref_displays) {
+ const HEVCSEITDRDI *sei = &s->sei.tdrdi;
+ size_t size;
+ AV3DReferenceDisplaysInfo *tdrdi = av_tdrdi_alloc(&size);
+
+ if (!tdrdi)
+ return AVERROR(ENOMEM);
+
+ tdrdi->prec_ref_display_width = sei->prec_ref_display_width;
+ tdrdi->ref_viewing_distance_flag = sei->ref_viewing_distance_flag;
+ tdrdi->prec_ref_viewing_dist = sei->prec_ref_viewing_dist;
+ tdrdi->num_ref_displays = sei->num_ref_displays;
+ memcpy(tdrdi->left_view_id,
+ sei->left_view_id, sizeof(tdrdi->left_view_id));
+ memcpy(tdrdi->right_view_id,
+ sei->right_view_id, sizeof(tdrdi->right_view_id));
+ memcpy(tdrdi->exponent_ref_display_width,
+ sei->exponent_ref_display_width, sizeof(tdrdi->exponent_ref_display_width));
+ memcpy(tdrdi->mantissa_ref_display_width,
+ sei->mantissa_ref_display_width, sizeof(tdrdi->mantissa_ref_display_width));
+ memcpy(tdrdi->exponent_ref_viewing_distance,
+ sei->exponent_ref_viewing_distance, sizeof(tdrdi->exponent_ref_viewing_distance));
+ memcpy(tdrdi->mantissa_ref_viewing_distance,
+ sei->mantissa_ref_viewing_distance, sizeof(tdrdi->mantissa_ref_viewing_distance));
+ memcpy(tdrdi->additional_shift_present_flag,
+ sei->additional_shift_present_flag, sizeof(tdrdi->additional_shift_present_flag));
+ memcpy(tdrdi->num_sample_shift,
+ sei->num_sample_shift, sizeof(tdrdi->num_sample_shift));
+
+ if (!av_packet_side_data_add(&avctx->coded_side_data, &avctx->nb_coded_side_data,
+ AV_PKT_DATA_3D_REFERENCE_DISPLAYS, tdrdi, size, 0)) {
+ av_free(tdrdi);
+ return AVERROR(ENOMEM);
+ }
+ }
+
#if FF_API_CODEC_PROPS
FF_DISABLE_DEPRECATION_WARNINGS
if ((s->sei.common.film_grain_characteristics && s->sei.common.film_grain_characteristics->present) ||
--
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".
^ permalink raw reply [flat|nested] 12+ messages in thread
* [FFmpeg-devel] [PATCH v2 6/6] avcodec/hevc/hevcdec: export 3D Reference Displays side data
2025-01-31 14:00 [FFmpeg-devel] [PATCH " James Almer
@ 2025-01-31 20:58 ` James Almer
0 siblings, 0 replies; 12+ messages in thread
From: James Almer @ 2025-01-31 20:58 UTC (permalink / raw)
To: ffmpeg-devel
Signed-off-by: James Almer <jamrial@gmail.com>
---
libavcodec/hevc/hevcdec.c | 57 ++++++++++++++++++++++++++++++++++++++-
1 file changed, 56 insertions(+), 1 deletion(-)
Now actually filling the correct side data array.
diff --git a/libavcodec/hevc/hevcdec.c b/libavcodec/hevc/hevcdec.c
index 7d3e844945..db97d9b0a2 100644
--- a/libavcodec/hevc/hevcdec.c
+++ b/libavcodec/hevc/hevcdec.c
@@ -36,6 +36,7 @@
#include "libavutil/opt.h"
#include "libavutil/pixdesc.h"
#include "libavutil/stereo3d.h"
+#include "libavutil/tdrdi.h"
#include "libavutil/timecode.h"
#include "aom_film_grain.h"
@@ -4015,6 +4016,60 @@ static int hevc_update_thread_context(AVCodecContext *dst,
}
#endif
+static int hevc_sei_to_context(AVCodecContext *avctx, HEVCSEI *sei)
+{
+ int ret;
+
+ if (sei->tdrdi.num_ref_displays) {
+ AVBufferRef *buf;
+ size_t size;
+ AV3DReferenceDisplaysInfo *tdrdi = av_tdrdi_alloc(&size);
+
+ if (!tdrdi)
+ return AVERROR(ENOMEM);
+
+ buf = av_buffer_create((uint8_t *)tdrdi, size, NULL, NULL, 0);
+ if (!buf) {
+ av_free(tdrdi);
+ return AVERROR(ENOMEM);
+ }
+
+ tdrdi->prec_ref_display_width = sei->tdrdi.prec_ref_display_width;
+ tdrdi->ref_viewing_distance_flag = sei->tdrdi.ref_viewing_distance_flag;
+ tdrdi->prec_ref_viewing_dist = sei->tdrdi.prec_ref_viewing_dist;
+ tdrdi->num_ref_displays = sei->tdrdi.num_ref_displays;
+ memcpy(tdrdi->left_view_id,
+ sei->tdrdi.left_view_id, sizeof(tdrdi->left_view_id));
+ memcpy(tdrdi->right_view_id,
+ sei->tdrdi.right_view_id, sizeof(tdrdi->right_view_id));
+ memcpy(tdrdi->exponent_ref_display_width,
+ sei->tdrdi.exponent_ref_display_width, sizeof(tdrdi->exponent_ref_display_width));
+ memcpy(tdrdi->mantissa_ref_display_width,
+ sei->tdrdi.mantissa_ref_display_width, sizeof(tdrdi->mantissa_ref_display_width));
+ memcpy(tdrdi->exponent_ref_viewing_distance,
+ sei->tdrdi.exponent_ref_viewing_distance, sizeof(tdrdi->exponent_ref_viewing_distance));
+ memcpy(tdrdi->mantissa_ref_viewing_distance,
+ sei->tdrdi.mantissa_ref_viewing_distance, sizeof(tdrdi->mantissa_ref_viewing_distance));
+ memcpy(tdrdi->additional_shift_present_flag,
+ sei->tdrdi.additional_shift_present_flag, sizeof(tdrdi->additional_shift_present_flag));
+ memcpy(tdrdi->num_sample_shift,
+ sei->tdrdi.num_sample_shift, sizeof(tdrdi->num_sample_shift));
+
+ ret = ff_frame_new_side_data_from_buf_ext(avctx, &avctx->decoded_side_data, &avctx->nb_decoded_side_data,
+ AV_FRAME_DATA_3D_REFERENCE_DISPLAYS, &buf);
+ if (ret < 0) {
+ av_buffer_unref(&buf);
+ return ret;
+ }
+ }
+
+ ret = ff_h2645_sei_to_context(avctx, &sei->common);
+ if (ret < 0)
+ return ret;
+
+ return 0;
+}
+
static av_cold int hevc_decode_init(AVCodecContext *avctx)
{
HEVCContext *s = avctx->priv_data;
@@ -4038,7 +4093,7 @@ static av_cold int hevc_decode_init(AVCodecContext *avctx)
return ret;
}
- ret = ff_h2645_sei_to_context(avctx, &s->sei.common);
+ ret = hevc_sei_to_context(avctx, &s->sei);
if (ret < 0)
return ret;
}
--
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".
^ permalink raw reply [flat|nested] 12+ messages in thread
end of thread, other threads:[~2025-02-06 2:50 UTC | newest]
Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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 ` [FFmpeg-devel] [PATCH v2 " James Almer
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
-- strict thread matches above, loose matches on Subject: below --
2025-01-31 14:00 [FFmpeg-devel] [PATCH " James Almer
2025-01-31 20:58 ` [FFmpeg-devel] [PATCH v2 " 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