FFmpeg
cbs_sei_syntax_template.c
Go to the documentation of this file.
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 static int FUNC(filler_payload)
22 {
23  int err, i;
24 
25  HEADER("Filler Payload");
26 
27 #ifdef READ
28  current->payload_size = state->payload_size;
29 #endif
30 
31  for (i = 0; i < current->payload_size; i++)
32  fixed(8, ff_byte, 0xff);
33 
34  return 0;
35 }
36 
37 static int FUNC(user_data_registered)
40 {
41  int err, i, j;
42 
43  HEADER("User Data Registered ITU-T T.35");
44 
45  u(8, itu_t_t35_country_code, 0x00, 0xff);
46  if (current->itu_t_t35_country_code != 0xff)
47  i = 1;
48  else {
49  u(8, itu_t_t35_country_code_extension_byte, 0x00, 0xff);
50  i = 2;
51  }
52 
53 #ifdef READ
54  if (state->payload_size < i) {
56  "Invalid SEI user data registered payload.\n");
57  return AVERROR_INVALIDDATA;
58  }
59  current->data_length = state->payload_size - i;
60 #endif
61 
62  allocate(current->data, current->data_length);
63  for (j = 0; j < current->data_length; j++)
64  xu(8, itu_t_t35_payload_byte[], current->data[j], 0x00, 0xff, 1, i + j);
65 
66  return 0;
67 }
68 
69 static int FUNC(user_data_unregistered)
72 {
73  int err, i;
74 
75  HEADER("User Data Unregistered");
76 
77 #ifdef READ
78  if (state->payload_size < 16) {
80  "Invalid SEI user data unregistered payload.\n");
81  return AVERROR_INVALIDDATA;
82  }
83  current->data_length = state->payload_size - 16;
84 #endif
85 
86  for (i = 0; i < 16; i++)
87  us(8, uuid_iso_iec_11578[i], 0x00, 0xff, 1, i);
88 
89  allocate(current->data, current->data_length);
90 
91  for (i = 0; i < current->data_length; i++)
92  xu(8, user_data_payload_byte[i], current->data[i], 0x00, 0xff, 1, i);
93 
94  return 0;
95 }
96 
100 {
101  int err, c;
102 
103  HEADER("Mastering Display Colour Volume");
104 
105  for (c = 0; c < 3; c++) {
106  ubs(16, display_primaries_x[c], 1, c);
107  ubs(16, display_primaries_y[c], 1, c);
108  }
109 
110  ub(16, white_point_x);
111  ub(16, white_point_y);
112 
113  ub(32, max_display_mastering_luminance);
114  ub(32, min_display_mastering_luminance);
115 
116  return 0;
117 }
118 
119 static int FUNC(content_light_level_info)
122 {
123  int err;
124 
125  HEADER("Content Light Level Information");
126 
127  ub(16, max_content_light_level);
128  ub(16, max_pic_average_light_level);
129 
130  return 0;
131 }
132 
137 {
138  int err;
139 
140  HEADER("Alternative Transfer Characteristics");
141 
142  ub(8, preferred_transfer_characteristics);
143 
144  return 0;
145 }
146 
148  SEIRawMessage *current)
149 {
151  int err, i;
152 
153  desc = ff_cbs_sei_find_type(ctx, current->payload_type);
154  if (desc) {
156  .payload_type = current->payload_type,
157  .payload_size = current->payload_size,
158  .extension_present = current->extension_bit_length > 0,
159  };
160  int start_position, current_position, bits_written;
161 
162 #ifdef READ
163  CHECK(ff_cbs_sei_alloc_message_payload(current, desc));
164 #endif
165 
166  start_position = bit_position(rw);
167 
168  CHECK(desc->READWRITE(ctx, rw, current->payload, &state));
169 
170  current_position = bit_position(rw);
171  bits_written = current_position - start_position;
172 
173  if (byte_alignment(rw) || state.extension_present ||
174  bits_written < 8 * current->payload_size) {
175  size_t bits_left;
176 
177 #ifdef READ
178  GetBitContext tmp = *rw;
179  int trailing_bits, trailing_zero_bits;
180 
181  bits_left = 8 * current->payload_size - bits_written;
182  if (bits_left > 8)
183  skip_bits_long(&tmp, bits_left - 8);
184  trailing_bits = get_bits(&tmp, FFMIN(bits_left, 8));
185  if (trailing_bits == 0) {
186  // The trailing bits must contain a bit_equal_to_one, so
187  // they can't all be zero.
188  return AVERROR_INVALIDDATA;
189  }
190  trailing_zero_bits = ff_ctz(trailing_bits);
191  current->extension_bit_length =
192  bits_left - 1 - trailing_zero_bits;
193 #endif
194 
195  if (current->extension_bit_length > 0) {
196  allocate(current->extension_data,
197  (current->extension_bit_length + 7) / 8);
198 
199  bits_left = current->extension_bit_length;
200  for (i = 0; bits_left > 0; i++) {
201  int length = FFMIN(bits_left, 8);
202  xu(length, reserved_payload_extension_data,
203  current->extension_data[i],
204  0, MAX_UINT_BITS(length), 0);
205  bits_left -= length;
206  }
207  }
208 
209  fixed(1, bit_equal_to_one, 1);
210  while (byte_alignment(rw))
211  fixed(1, bit_equal_to_zero, 0);
212  }
213 
214 #ifdef WRITE
215  current->payload_size = (put_bits_count(rw) - start_position) / 8;
216 #endif
217  } else {
218  uint8_t *data;
219 
220  allocate(current->payload, current->payload_size);
221  data = current->payload;
222 
223  for (i = 0; i < current->payload_size; i++)
224  xu(8, payload_byte[i], data[i], 0, 255, 1, i);
225  }
226 
227  return 0;
228 }
229 
231  SEIRawMessageList *current, int prefix)
232 {
234  int err, k;
235 
236 #ifdef READ
237  for (k = 0;; k++) {
238  uint32_t payload_type = 0;
239  uint32_t payload_size = 0;
240  uint32_t tmp;
241 
242  while (show_bits(rw, 8) == 0xff) {
243  fixed(8, ff_byte, 0xff);
244  payload_type += 255;
245  }
246  xu(8, last_payload_type_byte, tmp, 0, 254, 0);
247  payload_type += tmp;
248 
249  while (show_bits(rw, 8) == 0xff) {
250  fixed(8, ff_byte, 0xff);
251  payload_size += 255;
252  }
253  xu(8, last_payload_size_byte, tmp, 0, 254, 0);
254  payload_size += tmp;
255 
256  CHECK(ff_cbs_sei_list_add(current));
257  message = &current->messages[k];
258 
259  message->payload_type = payload_type;
260  message->payload_size = payload_size;
261 
262  CHECK(FUNC(message)(ctx, rw, message));
263 
265  break;
266  }
267 #else
268  for (k = 0; k < current->nb_messages; k++) {
269  PutBitContext start_state;
270  uint32_t tmp;
271  int trace, i;
272 
273  message = &current->messages[k];
274 
275  // We write the payload twice in order to find the size. Trace
276  // output is switched off for the first write.
277  trace = ctx->trace_enable;
278  ctx->trace_enable = 0;
279 
280  start_state = *rw;
281  for (i = 0; i < 2; i++) {
282  *rw = start_state;
283 
284  tmp = message->payload_type;
285  while (tmp >= 255) {
286  fixed(8, ff_byte, 0xff);
287  tmp -= 255;
288  }
289  xu(8, last_payload_type_byte, tmp, 0, 254, 0);
290 
291  tmp = message->payload_size;
292  while (tmp >= 255) {
293  fixed(8, ff_byte, 0xff);
294  tmp -= 255;
295  }
296  xu(8, last_payload_size_byte, tmp, 0, 254, 0);
297 
298  err = FUNC(message)(ctx, rw, message);
299  ctx->trace_enable = trace;
300  if (err < 0)
301  return err;
302  }
303  }
304 #endif
305 
306  return 0;
307 }
#define allocate(name, size)
Definition: cbs_h2645.c:432
static int FUNC() trailing_bits(CodedBitstreamContext *ctx, RWContext *rw, int nb_bits)
#define ff_ctz
Definition: intmath.h:106
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
Definition: error.h:59
ptrdiff_t const GLvoid * data
Definition: opengl_enc.c:100
#define fixed(width, name, value)
Definition: cbs_av1.c:566
const char * desc
Definition: libsvtav1.c:79
static unsigned int get_bits(GetBitContext *s, int n)
Read 1-25 bits.
Definition: get_bits.h:379
static void skip_bits_long(GetBitContext *s, int n)
Skips the specified number of bits.
Definition: get_bits.h:291
static int FUNC() user_data_registered(CodedBitstreamContext *ctx, RWContext *rw, SEIRawUserDataRegistered *current, SEIMessageState *state)
static int FUNC() message_list(CodedBitstreamContext *ctx, RWContext *rw, SEIRawMessageList *current, int prefix)
#define RWContext
Definition: cbs_av1.c:662
uint8_t extension_present
Definition: cbs_sei.h:97
#define us(width, name, range_min, range_max, subs,...)
Definition: cbs_h2645.c:278
static int FUNC() alternative_transfer_characteristics(CodedBitstreamContext *ctx, RWContext *rw, SEIRawAlternativeTransferCharacteristics *current, SEIMessageState *state)
static int FUNC() user_data_unregistered(CodedBitstreamContext *ctx, RWContext *rw, SEIRawUserDataUnregistered *current, SEIMessageState *state)
int trace_enable
Enable trace output during read/write operations.
Definition: cbs.h:208
uint8_t
#define byte_alignment(rw)
Definition: cbs_av1.c:719
const SEIMessageTypeDescriptor * ff_cbs_sei_find_type(CodedBitstreamContext *ctx, int payload_type)
Find the type descriptor for the given payload type.
Definition: cbs_h2645.c:1640
#define HEADER(name)
Definition: cbs_av1.c:533
#define MAX_UINT_BITS(length)
Definition: cbs_internal.h:169
Undefined Behavior In the C some operations are like signed integer dereferencing freed accessing outside allocated Undefined Behavior must not occur in a C it is not safe even if the output of undefined operations is unused The unsafety may seem nit picking but Optimizing compilers have in fact optimized code on the assumption that no undefined Behavior occurs Optimizing code based on wrong assumptions can and has in some cases lead to effects beyond the output of computations The signed integer overflow problem in speed critical code Code which is highly optimized and works with signed integers sometimes has the problem that often the output of the computation does not c
Definition: undefined.txt:32
#define u(width, name, range_min, range_max)
Definition: cbs_h2645.c:264
CHECK(-1) CHECK(-2)}}}}CHECK(1) CHECK(2)}}}}}if(diff0+diff1 > 0) temp-
static struct @321 state
#define av_log(a,...)
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:194
#define FUNC(a)
GLsizei GLsizei * length
Definition: opengl_enc.c:114
static int put_bits_count(PutBitContext *s)
Definition: put_bits.h:83
void * log_ctx
Logging context to be passed to all av_log() calls associated with this context.
Definition: cbs.h:175
static int FUNC() mastering_display_colour_volume(CodedBitstreamContext *ctx, RWContext *rw, SEIRawMasteringDisplayColourVolume *current, SEIMessageState *state)
#define FFMIN(a, b)
Definition: common.h:105
AVFormatContext * ctx
Definition: movenc.c:48
static unsigned int show_bits(GetBitContext *s, int n)
Show 1-25 bits.
Definition: get_bits.h:446
uint32_t payload_type
Definition: cbs_sei.h:69
static int FUNC() message(CodedBitstreamContext *ctx, RWContext *rw, SEIRawMessage *current)
#define ub(width, name)
Definition: cbs_h2645.c:266
#define xu(width, name, var, range_min, range_max, subs,...)
Definition: cbs_h2645.c:392
int ff_cbs_sei_list_add(SEIRawMessageList *list)
Allocate a new empty SEI message in a message list.
Definition: cbs_sei.c:74
Context structure for coded bitstream operations.
Definition: cbs.h:170
static int cbs_h2645_read_more_rbsp_data(GetBitContext *gbc)
Definition: cbs_h2645.c:337
static int FUNC() filler_payload(CodedBitstreamContext *ctx, RWContext *rw, SEIRawFillerPayload *current, SEIMessageState *state)
#define ubs(width, name, subs,...)
Definition: cbs_h2645.c:280
#define bit_position(rw)
Definition: cbs_h2645.c:429
int ff_cbs_sei_alloc_message_payload(SEIRawMessage *message, const SEIMessageTypeDescriptor *desc)
Allocate a new payload for the given SEI message.
Definition: cbs_sei.c:39
int i
Definition: input.c:407
uint32_t payload_size
Definition: cbs_sei.h:70
static int FUNC() content_light_level_info(CodedBitstreamContext *ctx, RWContext *rw, SEIRawContentLightLevelInfo *current, SEIMessageState *state)
static uint8_t tmp[11]
Definition: aes_ctr.c:27