History

avutil: add an API to handle 3D Reference Displays Information

As defined in section G.14.3.2.3 of ITU-T H.265, it's required for proper signaling of MV-HEVC.

James Almer committed 1 year ago

Commit 80a05be1 parent 3b9dbda4 files · +218 −1Browse files

Unified · Split

4 files
  1. libavutil/Makefile +2 −0
  2. libavutil/tdrdi.c +51 −0
  3. libavutil/tdrdi.h +164 −0
  4. libavutil/version.h +1 −1
libavutil/Makefile+2−0
@@ -85,6 +85,7 @@ HEADERS = adler32.h \ · 84 unmodified lines
85 sha512.h \85 sha512.h \
86 spherical.h \86 spherical.h \
87 stereo3d.h \87 stereo3d.h \
88 tdrdi.h \
88 threadmessage.h \89 threadmessage.h \
89 time.h \90 time.h \
90 timecode.h \91 timecode.h \
@@ -179,6 +180,7 @@ OBJS = adler32.o \ · 88 unmodified lines
179 slicethread.o \180 slicethread.o \
180 spherical.o \181 spherical.o \
181 stereo3d.o \182 stereo3d.o \
183 tdrdi.o \
182 threadmessage.o \184 threadmessage.o \
183 time.o \185 time.o \
184 timecode.o \186 timecode.o \
libavutil/tdrdi.c+51−0
@@ -0,0 +1,51 @@
1/*
2 * This file is part of FFmpeg.
3 *
4 * FFmpeg is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
8 *
9 * FFmpeg is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with FFmpeg; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17 */
18
19#include <stddef.h>
20#include <stdint.h>
21
22#include "mem.h"
23#include "tdrdi.h"
24
25AV3DReferenceDisplaysInfo *av_tdrdi_alloc(unsigned int nb_displays, size_t *out_size)
26{
27 struct TestStruct {
28 AV3DReferenceDisplaysInfo p;
29 AV3DReferenceDisplay b;
30 };
31 const size_t entries_offset = offsetof(struct TestStruct, b);
32 size_t size = entries_offset;
33 AV3DReferenceDisplaysInfo *tdrdi;
34
35 if (nb_displays > (SIZE_MAX - size) / sizeof(AV3DReferenceDisplay))
36 return NULL;
37 size += sizeof(AV3DReferenceDisplay) * nb_displays;
38
39 tdrdi = av_mallocz(size);
40 if (!tdrdi)
41 return NULL;
42
43 tdrdi->num_ref_displays = nb_displays;
44 tdrdi->entry_size = sizeof(AV3DReferenceDisplay);
45 tdrdi->entries_offset = entries_offset;
46
47 if (out_size)
48 *out_size = size;
49
50 return tdrdi;
51}
libavutil/tdrdi.h+164−0
@@ -0,0 +1,164 @@
1/*
2 * This file is part of FFmpeg.
3 *
4 * FFmpeg is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
8 *
9 * FFmpeg is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with FFmpeg; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17 */
18
19/**
20 * @file
21 * @ingroup lavu_video_3d_reference_displays_info
22 * Spherical video
23 */
24
25#ifndef AVUTIL_TDRDI_H
26#define AVUTIL_TDRDI_H
27
28#include <stddef.h>
29#include <stdint.h>
30
31#include "libavutil/avassert.h"
32
33/**
34 * @defgroup lavu_video_3d_reference_displays_info 3D Reference Displays Information
35 * @ingroup lavu_video
36 *
37 * The 3D Reference Displays Information describes information about the reference display
38 * width(s) and reference viewing distance(s) as well as information about the corresponding
39 * reference stereo pair(s).
40 * @{
41 */
42
43#define AV_TDRDI_MAX_NUM_REF_DISPLAY 32
44
45/**
46 * This structure describes information about the reference display width(s) and reference
47 * viewing distance(s) as well as information about the corresponding reference stereo pair(s).
48 * See section G.14.3.2.3 of ITU-T H.265 for more information.
49 *
50 * @note The struct must be allocated with av_tdrdi_alloc() and
51 * its size is not a part of the public ABI.
52 */
53typedef struct AV3DReferenceDisplaysInfo {
54 /**
55 * The exponent of the maximum allowable truncation error for
56 * {exponent,mantissa}_ref_display_width as given by 2<sup>(-prec_ref_display_width)</sup>.
57 */
58 uint8_t prec_ref_display_width;
59
60 /**
61 * A flag to indicate the presence of reference viewing distance.
62 * If false, the values of prec_ref_viewing_dist, exponent_ref_viewing_distance,
63 * and mantissa_ref_viewing_distance are undefined.
64 */
65 uint8_t ref_viewing_distance_flag;
66
67 /**
68 * The exponent of the maximum allowable truncation error for
69 * {exponent,mantissa}_ref_viewing_distance as given by 2<sup>^(-prec_ref_viewing_dist)</sup>.
70 * The value of prec_ref_viewing_dist shall be in the range of 0 to 31, inclusive.
71 */
72 uint8_t prec_ref_viewing_dist;
73
74 /**
75 * The number of reference displays that are signalled in this struct.
76 * Allowed range is 1 to 32, inclusive.
77 */
78 uint8_t num_ref_displays;
79
80 /**
81 * Offset in bytes from the beginning of this structure at which the array
82 * of reference displays starts.
83 */
84 size_t entries_offset;
85
86 /**
87 * Size of each entry in bytes. May not match sizeof(AV3DReferenceDisplay).
88 */
89 size_t entry_size;
90} AV3DReferenceDisplaysInfo;
91
92/**
93 * Data structure for single deference display information.
94 * It is allocated as a part of AV3DReferenceDisplaysInfo and should be retrieved with
95 * av_tdrdi_get_display().
96 *
97 * sizeof(AV3DReferenceDisplay) is not a part of the ABI and new fields may be
98 * added to it.
99*/
100typedef struct AV3DReferenceDisplay {
101 /**
102 * The ViewId of the left view of a stereo pair corresponding to the n-th reference display.
103 */
104 uint16_t left_view_id;
105
106 /**
107 * The ViewId of the left view of a stereo pair corresponding to the n-th reference display.
108 */
109 uint16_t right_view_id;
110
111 /**
112 * The exponent part of the reference display width of the n-th reference display.
113 */
114 uint8_t exponent_ref_display_width;
115
116 /**
117 * The mantissa part of the reference display width of the n-th reference display.
118 */
119 uint8_t mantissa_ref_display_width;
120
121 /**
122 * Tthe exponent part of the reference viewing distance of the n-th reference display.
123 */
124 uint8_t exponent_ref_viewing_distance;
125
126 /**
127 * The mantissa part of the reference viewing distance of the n-th reference display.
128 */
129 uint8_t mantissa_ref_viewing_distance;
130
131 /**
132 * An array of flags to indicates that the information about additional horizontal shift of
133 * the left and right views for the n-th reference display is present.
134 */
135 uint8_t additional_shift_present_flag;
136
137 /**
138 * The recommended additional horizontal shift for a stereo pair corresponding to the n-th
139 * reference baseline and the n-th reference display.
140 */
141 int16_t num_sample_shift;
142} AV3DReferenceDisplay;
143
144static av_always_inline AV3DReferenceDisplay*
145av_tdrdi_get_display(AV3DReferenceDisplaysInfo *tdrdi, unsigned int idx)
146{
147 av_assert0(idx < tdrdi->num_ref_displays);
148 return (AV3DReferenceDisplay *)((uint8_t *)tdrdi + tdrdi->entries_offset +
149 idx * tdrdi->entry_size);
150}
151
152/**
153 * Allocate a AV3DReferenceDisplaysInfo structure and initialize its fields to default
154 * values.
155 *
156 * @return the newly allocated struct or NULL on failure
157 */
158AV3DReferenceDisplaysInfo *av_tdrdi_alloc(unsigned int nb_displays, size_t *size);
159
160/**
161 * @}
162 */
163
164#endif /* AVUTIL_TDRDI_H */
libavutil/version.h+1−1
@@ -79,7 +79,7 @@ · 78 unmodified lines
79 */79 */
80 80
81#define LIBAVUTIL_VERSION_MAJOR 6081#define LIBAVUTIL_VERSION_MAJOR 60
82#define LIBAVUTIL_VERSION_MINOR 382#define LIBAVUTIL_VERSION_MINOR 4
83#define LIBAVUTIL_VERSION_MICRO 10083#define LIBAVUTIL_VERSION_MICRO 100
84 84
85#define LIBAVUTIL_VERSION_INT AV_VERSION_INT(LIBAVUTIL_VERSION_MAJOR, \85#define LIBAVUTIL_VERSION_INT AV_VERSION_INT(LIBAVUTIL_VERSION_MAJOR, \

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t