FFmpeg  4.3
avc.c
Go to the documentation of this file.
1 /*
2  * AVC helper functions for muxers
3  * Copyright (c) 2006 Baptiste Coudurier <baptiste.coudurier@smartjog.com>
4  *
5  * This file is part of FFmpeg.
6  *
7  * FFmpeg is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public
9  * License as published by the Free Software Foundation; either
10  * version 2.1 of the License, or (at your option) any later version.
11  *
12  * FFmpeg is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with FFmpeg; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20  */
21 
22 #include "libavutil/intreadwrite.h"
23 #include "libavcodec/h264.h"
24 #include "libavcodec/get_bits.h"
25 #include "avformat.h"
26 #include "avio.h"
27 #include "avc.h"
28 #include "avio_internal.h"
29 
30 static const uint8_t *ff_avc_find_startcode_internal(const uint8_t *p, const uint8_t *end)
31 {
32  const uint8_t *a = p + 4 - ((intptr_t)p & 3);
33 
34  for (end -= 3; p < a && p < end; p++) {
35  if (p[0] == 0 && p[1] == 0 && p[2] == 1)
36  return p;
37  }
38 
39  for (end -= 3; p < end; p += 4) {
40  uint32_t x = *(const uint32_t*)p;
41 // if ((x - 0x01000100) & (~x) & 0x80008000) // little endian
42 // if ((x - 0x00010001) & (~x) & 0x00800080) // big endian
43  if ((x - 0x01010101) & (~x) & 0x80808080) { // generic
44  if (p[1] == 0) {
45  if (p[0] == 0 && p[2] == 1)
46  return p;
47  if (p[2] == 0 && p[3] == 1)
48  return p+1;
49  }
50  if (p[3] == 0) {
51  if (p[2] == 0 && p[4] == 1)
52  return p+2;
53  if (p[4] == 0 && p[5] == 1)
54  return p+3;
55  }
56  }
57  }
58 
59  for (end += 3; p < end; p++) {
60  if (p[0] == 0 && p[1] == 0 && p[2] == 1)
61  return p;
62  }
63 
64  return end + 3;
65 }
66 
67 const uint8_t *ff_avc_find_startcode(const uint8_t *p, const uint8_t *end){
69  if(p<out && out<end && !out[-1]) out--;
70  return out;
71 }
72 
73 int ff_avc_parse_nal_units(AVIOContext *pb, const uint8_t *buf_in, int size)
74 {
75  const uint8_t *p = buf_in;
76  const uint8_t *end = p + size;
77  const uint8_t *nal_start, *nal_end;
78 
79  size = 0;
80  nal_start = ff_avc_find_startcode(p, end);
81  for (;;) {
82  while (nal_start < end && !*(nal_start++));
83  if (nal_start == end)
84  break;
85 
86  nal_end = ff_avc_find_startcode(nal_start, end);
87  avio_wb32(pb, nal_end - nal_start);
88  avio_write(pb, nal_start, nal_end - nal_start);
89  size += 4 + nal_end - nal_start;
90  nal_start = nal_end;
91  }
92  return size;
93 }
94 
95 int ff_avc_parse_nal_units_buf(const uint8_t *buf_in, uint8_t **buf, int *size)
96 {
97  AVIOContext *pb;
98  int ret = avio_open_dyn_buf(&pb);
99  if(ret < 0)
100  return ret;
101 
102  ff_avc_parse_nal_units(pb, buf_in, *size);
103 
104  *size = avio_close_dyn_buf(pb, buf);
105  return 0;
106 }
107 
109 {
110  AVIOContext *sps_pb = NULL, *pps_pb = NULL, *sps_ext_pb = NULL;
111  uint8_t *buf, *end, *start;
112  uint8_t *sps, *pps, *sps_ext;
113  uint32_t sps_size = 0, pps_size = 0, sps_ext_size = 0;
114  int ret, nb_sps = 0, nb_pps = 0, nb_sps_ext = 0;
115 
116  if (len <= 6)
117  return AVERROR_INVALIDDATA;
118 
119  /* check for H.264 start code */
120  if (AV_RB32(data) != 0x00000001 &&
121  AV_RB24(data) != 0x000001) {
122  avio_write(pb, data, len);
123  return 0;
124  }
125 
127  if (ret < 0)
128  return ret;
129  start = buf;
130  end = buf + len;
131 
132  ret = avio_open_dyn_buf(&sps_pb);
133  if (ret < 0)
134  goto fail;
135  ret = avio_open_dyn_buf(&pps_pb);
136  if (ret < 0)
137  goto fail;
138  ret = avio_open_dyn_buf(&sps_ext_pb);
139  if (ret < 0)
140  goto fail;
141 
142  /* look for sps and pps */
143  while (end - buf > 4) {
144  uint32_t size;
145  uint8_t nal_type;
146  size = FFMIN(AV_RB32(buf), end - buf - 4);
147  buf += 4;
148  nal_type = buf[0] & 0x1f;
149 
150  if (nal_type == 7) { /* SPS */
151  nb_sps++;
152  if (size > UINT16_MAX || nb_sps >= H264_MAX_SPS_COUNT) {
154  goto fail;
155  }
156  avio_wb16(sps_pb, size);
157  avio_write(sps_pb, buf, size);
158  } else if (nal_type == 8) { /* PPS */
159  nb_pps++;
160  if (size > UINT16_MAX || nb_pps >= H264_MAX_PPS_COUNT) {
162  goto fail;
163  }
164  avio_wb16(pps_pb, size);
165  avio_write(pps_pb, buf, size);
166  } else if (nal_type == 13) { /* SPS_EXT */
167  nb_sps_ext++;
168  if (size > UINT16_MAX || nb_sps_ext >= 256) {
170  goto fail;
171  }
172  avio_wb16(sps_ext_pb, size);
173  avio_write(sps_ext_pb, buf, size);
174  }
175 
176  buf += size;
177  }
178  sps_size = avio_get_dyn_buf(sps_pb, &sps);
179  pps_size = avio_get_dyn_buf(pps_pb, &pps);
180  sps_ext_size = avio_get_dyn_buf(sps_ext_pb, &sps_ext);
181 
182  if (sps_size < 6 || !pps_size) {
184  goto fail;
185  }
186 
187  avio_w8(pb, 1); /* version */
188  avio_w8(pb, sps[3]); /* profile */
189  avio_w8(pb, sps[4]); /* profile compat */
190  avio_w8(pb, sps[5]); /* level */
191  avio_w8(pb, 0xff); /* 6 bits reserved (111111) + 2 bits nal size length - 1 (11) */
192  avio_w8(pb, 0xe0 | nb_sps); /* 3 bits reserved (111) + 5 bits number of sps */
193 
194  avio_write(pb, sps, sps_size);
195  avio_w8(pb, nb_pps); /* number of pps */
196  avio_write(pb, pps, pps_size);
197 
198  if (sps[3] != 66 && sps[3] != 77 && sps[3] != 88) {
199  H264SequenceParameterSet *seq = ff_avc_decode_sps(sps + 3, sps_size - 3);
200  if (!seq) {
201  ret = AVERROR(ENOMEM);
202  goto fail;
203  }
204  avio_w8(pb, 0xfc | seq->chroma_format_idc); /* 6 bits reserved (111111) + chroma_format_idc */
205  avio_w8(pb, 0xf8 | (seq->bit_depth_luma - 8)); /* 5 bits reserved (11111) + bit_depth_luma_minus8 */
206  avio_w8(pb, 0xf8 | (seq->bit_depth_chroma - 8)); /* 5 bits reserved (11111) + bit_depth_chroma_minus8 */
207  avio_w8(pb, nb_sps_ext); /* number of sps ext */
208  if (nb_sps_ext)
209  avio_write(pb, sps_ext, sps_ext_size);
210  av_free(seq);
211  }
212 
213 fail:
214  ffio_free_dyn_buf(&sps_pb);
215  ffio_free_dyn_buf(&pps_pb);
216  ffio_free_dyn_buf(&sps_ext_pb);
217  av_free(start);
218 
219  return ret;
220 }
221 
223 {
224  uint16_t sps_size, pps_size;
225  uint8_t *out;
226  int out_size;
227 
228  *buf = NULL;
229  if (*size >= 4 && (AV_RB32(in) == 0x00000001 || AV_RB24(in) == 0x000001))
230  return 0;
231  if (*size < 11 || in[0] != 1)
232  return AVERROR_INVALIDDATA;
233 
234  sps_size = AV_RB16(&in[6]);
235  if (11 + sps_size > *size)
236  return AVERROR_INVALIDDATA;
237  pps_size = AV_RB16(&in[9 + sps_size]);
238  if (11 + sps_size + pps_size > *size)
239  return AVERROR_INVALIDDATA;
240  out_size = 8 + sps_size + pps_size;
242  if (!out)
243  return AVERROR(ENOMEM);
244  AV_WB32(&out[0], 0x00000001);
245  memcpy(out + 4, &in[8], sps_size);
246  AV_WB32(&out[4 + sps_size], 0x00000001);
247  memcpy(out + 8 + sps_size, &in[11 + sps_size], pps_size);
248  *buf = out;
249  *size = out_size;
250  return 0;
251 }
252 
254  const uint8_t *end,
255  int nal_length_size)
256 {
257  unsigned int res = 0;
258 
259  if (end - start < nal_length_size)
260  return NULL;
261  while (nal_length_size--)
262  res = (res << 8) | *start++;
263 
264  if (res > end - start)
265  return NULL;
266 
267  return start + res;
268 }
269 
270 uint8_t *ff_nal_unit_extract_rbsp(const uint8_t *src, uint32_t src_len,
271  uint32_t *dst_len, int header_len)
272 {
273  uint8_t *dst;
274  uint32_t i, len;
275 
276  dst = av_malloc(src_len + AV_INPUT_BUFFER_PADDING_SIZE);
277  if (!dst)
278  return NULL;
279 
280  /* NAL unit header */
281  i = len = 0;
282  while (i < header_len && i < src_len)
283  dst[len++] = src[i++];
284 
285  while (i + 2 < src_len)
286  if (!src[i] && !src[i + 1] && src[i + 2] == 3) {
287  dst[len++] = src[i++];
288  dst[len++] = src[i++];
289  i++; // remove emulation_prevention_three_byte
290  } else
291  dst[len++] = src[i++];
292 
293  while (i < src_len)
294  dst[len++] = src[i++];
295 
296  memset(dst + len, 0, AV_INPUT_BUFFER_PADDING_SIZE);
297 
298  *dst_len = len;
299  return dst;
300 }
301 
303  { 0, 1 },
304  { 1, 1 },
305  { 12, 11 },
306  { 10, 11 },
307  { 16, 11 },
308  { 40, 33 },
309  { 24, 11 },
310  { 20, 11 },
311  { 32, 11 },
312  { 80, 33 },
313  { 18, 11 },
314  { 15, 11 },
315  { 64, 33 },
316  { 160, 99 },
317  { 4, 3 },
318  { 3, 2 },
319  { 2, 1 },
320 };
321 
322 static inline int get_ue_golomb(GetBitContext *gb) {
323  int i;
324  for (i = 0; i < 32 && !get_bits1(gb); i++)
325  ;
326  return get_bitsz(gb, i) + (1 << i) - 1;
327 }
328 
329 static inline int get_se_golomb(GetBitContext *gb) {
330  int v = get_ue_golomb(gb) + 1;
331  int sign = -(v & 1);
332  return ((v >> 1) ^ sign) - sign;
333 }
334 
336 {
337  int i, j, ret, rbsp_size, aspect_ratio_idc, pic_order_cnt_type;
338  int num_ref_frames_in_pic_order_cnt_cycle;
339  int delta_scale, lastScale = 8, nextScale = 8;
340  int sizeOfScalingList;
342  GetBitContext gb;
343  uint8_t *rbsp_buf;
344 
345  rbsp_buf = ff_nal_unit_extract_rbsp(buf, buf_size, &rbsp_size, 0);
346  if (!rbsp_buf)
347  return NULL;
348 
349  ret = init_get_bits8(&gb, rbsp_buf, rbsp_size);
350  if (ret < 0)
351  goto end;
352 
353  sps = av_mallocz(sizeof(*sps));
354  if (!sps)
355  goto end;
356 
357  sps->profile_idc = get_bits(&gb, 8);
358  sps->constraint_set_flags |= get_bits1(&gb) << 0; // constraint_set0_flag
359  sps->constraint_set_flags |= get_bits1(&gb) << 1; // constraint_set1_flag
360  sps->constraint_set_flags |= get_bits1(&gb) << 2; // constraint_set2_flag
361  sps->constraint_set_flags |= get_bits1(&gb) << 3; // constraint_set3_flag
362  sps->constraint_set_flags |= get_bits1(&gb) << 4; // constraint_set4_flag
363  sps->constraint_set_flags |= get_bits1(&gb) << 5; // constraint_set5_flag
364  skip_bits(&gb, 2); // reserved_zero_2bits
365  sps->level_idc = get_bits(&gb, 8);
366  sps->id = get_ue_golomb(&gb);
367 
368  if (sps->profile_idc == 100 || sps->profile_idc == 110 ||
369  sps->profile_idc == 122 || sps->profile_idc == 244 || sps->profile_idc == 44 ||
370  sps->profile_idc == 83 || sps->profile_idc == 86 || sps->profile_idc == 118 ||
371  sps->profile_idc == 128 || sps->profile_idc == 138 || sps->profile_idc == 139 ||
372  sps->profile_idc == 134) {
373  sps->chroma_format_idc = get_ue_golomb(&gb); // chroma_format_idc
374  if (sps->chroma_format_idc == 3) {
375  skip_bits1(&gb); // separate_colour_plane_flag
376  }
377  sps->bit_depth_luma = get_ue_golomb(&gb) + 8;
378  sps->bit_depth_chroma = get_ue_golomb(&gb) + 8;
379  skip_bits1(&gb); // qpprime_y_zero_transform_bypass_flag
380  if (get_bits1(&gb)) { // seq_scaling_matrix_present_flag
381  for (i = 0; i < ((sps->chroma_format_idc != 3) ? 8 : 12); i++) {
382  if (!get_bits1(&gb)) // seq_scaling_list_present_flag
383  continue;
384  lastScale = 8;
385  nextScale = 8;
386  sizeOfScalingList = i < 6 ? 16 : 64;
387  for (j = 0; j < sizeOfScalingList; j++) {
388  if (nextScale != 0) {
389  delta_scale = get_se_golomb(&gb);
390  nextScale = (lastScale + delta_scale) & 0xff;
391  }
392  lastScale = nextScale == 0 ? lastScale : nextScale;
393  }
394  }
395  }
396  } else {
397  sps->chroma_format_idc = 1;
398  sps->bit_depth_luma = 8;
399  sps->bit_depth_chroma = 8;
400  }
401 
402  get_ue_golomb(&gb); // log2_max_frame_num_minus4
403  pic_order_cnt_type = get_ue_golomb(&gb);
404 
405  if (pic_order_cnt_type == 0) {
406  get_ue_golomb(&gb); // log2_max_pic_order_cnt_lsb_minus4
407  } else if (pic_order_cnt_type == 1) {
408  skip_bits1(&gb); // delta_pic_order_always_zero
409  get_se_golomb(&gb); // offset_for_non_ref_pic
410  get_se_golomb(&gb); // offset_for_top_to_bottom_field
411  num_ref_frames_in_pic_order_cnt_cycle = get_ue_golomb(&gb);
412  for (i = 0; i < num_ref_frames_in_pic_order_cnt_cycle; i++)
413  get_se_golomb(&gb); // offset_for_ref_frame
414  }
415 
416  get_ue_golomb(&gb); // max_num_ref_frames
417  skip_bits1(&gb); // gaps_in_frame_num_value_allowed_flag
418  get_ue_golomb(&gb); // pic_width_in_mbs_minus1
419  get_ue_golomb(&gb); // pic_height_in_map_units_minus1
420 
421  sps->frame_mbs_only_flag = get_bits1(&gb);
422  if (!sps->frame_mbs_only_flag)
423  skip_bits1(&gb); // mb_adaptive_frame_field_flag
424 
425  skip_bits1(&gb); // direct_8x8_inference_flag
426 
427  if (get_bits1(&gb)) { // frame_cropping_flag
428  get_ue_golomb(&gb); // frame_crop_left_offset
429  get_ue_golomb(&gb); // frame_crop_right_offset
430  get_ue_golomb(&gb); // frame_crop_top_offset
431  get_ue_golomb(&gb); // frame_crop_bottom_offset
432  }
433 
434  if (get_bits1(&gb)) { // vui_parameters_present_flag
435  if (get_bits1(&gb)) { // aspect_ratio_info_present_flag
436  aspect_ratio_idc = get_bits(&gb, 8);
437  if (aspect_ratio_idc == 0xff) {
438  sps->sar.num = get_bits(&gb, 16);
439  sps->sar.den = get_bits(&gb, 16);
440  } else if (aspect_ratio_idc < FF_ARRAY_ELEMS(avc_sample_aspect_ratio)) {
441  sps->sar = avc_sample_aspect_ratio[aspect_ratio_idc];
442  }
443  }
444  }
445 
446  if (!sps->sar.den) {
447  sps->sar.num = 1;
448  sps->sar.den = 1;
449  }
450 
451  end:
452  av_free(rbsp_buf);
453  return sps;
454 }
H264SequenceParameterSet::bit_depth_luma
uint8_t bit_depth_luma
Definition: avc.h:45
AVERROR
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFrame structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample they are references to shared objects When the negotiation mechanism computes the intersection of the formats supported at each end of a all references to both lists are replaced with a reference to the intersection And when a single format is eventually chosen for a link amongst the remaining all references to the list are updated That means that if a filter requires that its input and output have the same format amongst a supported all it has to do is use a reference to the same list of formats query_formats can leave some formats unset and return AVERROR(EAGAIN) to cause the negotiation mechanism toagain later. That can be used by filters with complex requirements to use the format negotiated on one link to set the formats supported on another. Frame references ownership and permissions
out
FILE * out
Definition: movenc.c:54
out_size
int out_size
Definition: movenc.c:55
end
static av_cold int end(AVCodecContext *avctx)
Definition: avrndec.c:90
data
const char data[16]
Definition: mxf.c:91
AV_RB16
#define AV_RB16
Definition: intreadwrite.h:53
avio_get_dyn_buf
int avio_get_dyn_buf(AVIOContext *s, uint8_t **pbuffer)
Return the written size and a pointer to the buffer.
Definition: aviobuf.c:1368
av_malloc
#define av_malloc(s)
Definition: tableprint_vlc.h:31
skip_bits
static void skip_bits(GetBitContext *s, int n)
Definition: get_bits.h:467
get_bits
static unsigned int get_bits(GetBitContext *s, int n)
Read 1-25 bits.
Definition: get_bits.h:379
fail
#define fail()
Definition: checkasm.h:123
GetBitContext
Definition: get_bits.h:61
x
FFmpeg Automated Testing Environment ************************************Introduction Using FATE from your FFmpeg source directory Submitting the results to the FFmpeg result aggregation server Uploading new samples to the fate suite FATE makefile targets and variables Makefile targets Makefile variables Examples Introduction **************FATE is an extended regression suite on the client side and a means for results aggregation and presentation on the server side The first part of this document explains how you can use FATE from your FFmpeg source directory to test your ffmpeg binary The second part describes how you can run FATE to submit the results to FFmpeg’s FATE server In any way you can have a look at the publicly viewable FATE results by visiting this as it can be seen if some test on some platform broke with their recent contribution This usually happens on the platforms the developers could not test on The second part of this document describes how you can run FATE to submit your results to FFmpeg’s FATE server If you want to submit your results be sure to check that your combination of OS and compiler is not already listed on the above mentioned website In the third part you can find a comprehensive listing of FATE makefile targets and variables Using FATE from your FFmpeg source directory **********************************************If you want to run FATE on your machine you need to have the samples in place You can get the samples via the build target fate rsync Use this command from the top level source this will cause FATE to fail NOTE To use a custom wrapper to run the pass ‘ target exec’ to ‘configure’ or set the TARGET_EXEC Make variable Submitting the results to the FFmpeg result aggregation server ****************************************************************To submit your results to the server you should run fate through the shell script ‘tests fate sh’ from the FFmpeg sources This script needs to be invoked with a configuration file as its first argument tests fate sh path to fate_config A configuration file template with comments describing the individual configuration variables can be found at ‘doc fate_config sh template’ Create a configuration that suits your based on the configuration template The ‘slot’ configuration variable can be any string that is not yet but it is suggested that you name it adhering to the following pattern ‘ARCH OS COMPILER COMPILER VERSION’ The configuration file itself will be sourced in a shell therefore all shell features may be used This enables you to setup the environment as you need it for your build For your first test runs the ‘fate_recv’ variable should be empty or commented out This will run everything as normal except that it will omit the submission of the results to the server The following files should be present in $workdir as specified in the configuration it may help to try out the ‘ssh’ command with one or more ‘ v’ options You should get detailed output concerning your SSH configuration and the authentication process The only thing left is to automate the execution of the fate sh script and the synchronisation of the samples directory Uploading new samples to the fate suite *****************************************If you need a sample uploaded send a mail to samples request This is for developers who have an account on the fate suite server If you upload new please make sure they are as small as space on each network bandwidth and so on benefit from smaller test cases Also keep in mind older checkouts use existing sample that means in practice generally do not remove or overwrite files as it likely would break older checkouts or releases Also all needed samples for a commit should be ideally before the push If you need an account for frequently uploading samples or you wish to help others by doing that send a mail to ffmpeg devel rsync vauL Duo x
Definition: fate.txt:150
AV_RB24
#define AV_RB24
Definition: intreadwrite.h:64
get_se_golomb
static int get_se_golomb(GetBitContext *gb)
Definition: avc.c:329
avio_close_dyn_buf
int avio_close_dyn_buf(AVIOContext *s, uint8_t **pbuffer)
Return the written size and a pointer to the buffer.
Definition: aviobuf.c:1401
H264SequenceParameterSet::bit_depth_chroma
uint8_t bit_depth_chroma
Definition: avc.h:46
init_get_bits8
static int init_get_bits8(GetBitContext *s, const uint8_t *buffer, int byte_size)
Initialize GetBitContext.
Definition: get_bits.h:677
avio_open_dyn_buf
int avio_open_dyn_buf(AVIOContext **s)
Open a write only memory stream.
Definition: aviobuf.c:1356
intreadwrite.h
ff_nal_unit_extract_rbsp
uint8_t * ff_nal_unit_extract_rbsp(const uint8_t *src, uint32_t src_len, uint32_t *dst_len, int header_len)
Definition: avc.c:270
get_bits.h
av_mallocz
void * av_mallocz(size_t size)
Allocate a memory block with alignment suitable for all memory accesses (including vectors if availab...
Definition: mem.c:239
NULL
#define NULL
Definition: coverity.c:32
avc_sample_aspect_ratio
static const AVRational avc_sample_aspect_ratio[17]
Definition: avc.c:302
AVRational
Rational number (pair of numerator and denominator).
Definition: rational.h:58
get_ue_golomb
static int get_ue_golomb(GetBitContext *gb)
Definition: avc.c:322
get_bits1
static unsigned int get_bits1(GetBitContext *s)
Definition: get_bits.h:498
src
#define src
Definition: vp8dsp.c:254
avc.h
ff_avc_parse_nal_units_buf
int ff_avc_parse_nal_units_buf(const uint8_t *buf_in, uint8_t **buf, int *size)
Definition: avc.c:95
avio_w8
void avio_w8(AVIOContext *s, int b)
Definition: aviobuf.c:191
H264_MAX_PPS_COUNT
@ H264_MAX_PPS_COUNT
Definition: h264.h:73
AV_RB32
#define AV_RB32
Definition: intreadwrite.h:130
AV_WB32
#define AV_WB32(p, v)
Definition: intreadwrite.h:419
AVIOContext
Bytestream IO Context.
Definition: avio.h:161
ff_avc_parse_nal_units
int ff_avc_parse_nal_units(AVIOContext *pb, const uint8_t *buf_in, int size)
Definition: avc.c:73
pps
static int FUNC() pps(CodedBitstreamContext *ctx, RWContext *rw, H264RawPPS *current)
Definition: cbs_h264_syntax_template.c:404
ff_isom_write_avcc
int ff_isom_write_avcc(AVIOContext *pb, const uint8_t *data, int len)
Definition: avc.c:108
size
int size
Definition: twinvq_data.h:11134
avio.h
avio_write
void avio_write(AVIOContext *s, const unsigned char *buf, int size)
Definition: aviobuf.c:213
avio_wb32
void avio_wb32(AVIOContext *s, unsigned int val)
Definition: aviobuf.c:375
FFMIN
#define FFMIN(a, b)
Definition: common.h:96
a
The reader does not expect b to be semantically here and if the code is changed by maybe adding a a division or other the signedness will almost certainly be mistaken To avoid this confusion a new type was SUINT is the C unsigned type but it holds a signed int to use the same example SUINT a
Definition: undefined.txt:41
ff_avc_find_startcode_internal
static const uint8_t * ff_avc_find_startcode_internal(const uint8_t *p, const uint8_t *end)
Definition: avc.c:30
skip_bits1
static void skip_bits1(GetBitContext *s)
Definition: get_bits.h:538
in
uint8_t pi<< 24) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_U8, uint8_t,(*(const uint8_t *) pi - 0x80) *(1.0f/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_U8, uint8_t,(*(const uint8_t *) pi - 0x80) *(1.0/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S16, int16_t,(*(const int16_t *) pi >> 8)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S16, int16_t, *(const int16_t *) pi *(1.0f/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S16, int16_t, *(const int16_t *) pi *(1.0/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S32, int32_t,(*(const int32_t *) pi >> 24)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S32, int32_t, *(const int32_t *) pi *(1.0f/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S32, int32_t, *(const int32_t *) pi *(1.0/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_FLT, float, av_clip_uint8(lrintf(*(const float *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_FLT, float, av_clip_int16(lrintf(*(const float *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_FLT, float, av_clipl_int32(llrintf(*(const float *) pi *(1U<< 31)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_DBL, double, av_clip_uint8(lrint(*(const double *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_DBL, double, av_clip_int16(lrint(*(const double *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_DBL, double, av_clipl_int32(llrint(*(const double *) pi *(1U<< 31)))) #define SET_CONV_FUNC_GROUP(ofmt, ifmt) static void set_generic_function(AudioConvert *ac) { } void ff_audio_convert_free(AudioConvert **ac) { if(! *ac) return;ff_dither_free(&(*ac) ->dc);av_freep(ac);} AudioConvert *ff_audio_convert_alloc(AVAudioResampleContext *avr, enum AVSampleFormat out_fmt, enum AVSampleFormat in_fmt, int channels, int sample_rate, int apply_map) { AudioConvert *ac;int in_planar, out_planar;ac=av_mallocz(sizeof(*ac));if(!ac) return NULL;ac->avr=avr;ac->out_fmt=out_fmt;ac->in_fmt=in_fmt;ac->channels=channels;ac->apply_map=apply_map;if(avr->dither_method !=AV_RESAMPLE_DITHER_NONE &&av_get_packed_sample_fmt(out_fmt)==AV_SAMPLE_FMT_S16 &&av_get_bytes_per_sample(in_fmt) > 2) { ac->dc=ff_dither_alloc(avr, out_fmt, in_fmt, channels, sample_rate, apply_map);if(!ac->dc) { av_free(ac);return NULL;} return ac;} in_planar=ff_sample_fmt_is_planar(in_fmt, channels);out_planar=ff_sample_fmt_is_planar(out_fmt, channels);if(in_planar==out_planar) { ac->func_type=CONV_FUNC_TYPE_FLAT;ac->planes=in_planar ? ac->channels :1;} else if(in_planar) ac->func_type=CONV_FUNC_TYPE_INTERLEAVE;else ac->func_type=CONV_FUNC_TYPE_DEINTERLEAVE;set_generic_function(ac);if(ARCH_AARCH64) ff_audio_convert_init_aarch64(ac);if(ARCH_ARM) ff_audio_convert_init_arm(ac);if(ARCH_X86) ff_audio_convert_init_x86(ac);return ac;} int ff_audio_convert(AudioConvert *ac, AudioData *out, AudioData *in) { int use_generic=1;int len=in->nb_samples;int p;if(ac->dc) { av_log(ac->avr, AV_LOG_TRACE, "%d samples - audio_convert: %s to %s (dithered)\n", len, av_get_sample_fmt_name(ac->in_fmt), av_get_sample_fmt_name(ac->out_fmt));return ff_convert_dither(ac-> in
Definition: audio_convert.c:326
H264_MAX_SPS_COUNT
@ H264_MAX_SPS_COUNT
Definition: h264.h:71
i
#define i(width, name, range_min, range_max)
Definition: cbs_h2645.c:269
avio_internal.h
uint8_t
uint8_t
Definition: audio_convert.c:194
len
int len
Definition: vorbis_enc_data.h:452
ffio_free_dyn_buf
void ffio_free_dyn_buf(AVIOContext **s)
Free a dynamic buffer.
Definition: aviobuf.c:1431
ret
ret
Definition: filter_design.txt:187
sps
static int FUNC() sps(CodedBitstreamContext *ctx, RWContext *rw, H264RawSPS *current)
Definition: cbs_h264_syntax_template.c:260
avformat.h
H264SequenceParameterSet
Definition: avc.h:39
AV_INPUT_BUFFER_PADDING_SIZE
#define AV_INPUT_BUFFER_PADDING_SIZE
Definition: avcodec.h:215
FF_ARRAY_ELEMS
#define FF_ARRAY_ELEMS(a)
Definition: sinewin_tablegen_template.c:38
ff_avc_decode_sps
H264SequenceParameterSet * ff_avc_decode_sps(const uint8_t *buf, int buf_size)
Definition: avc.c:335
ff_avc_write_annexb_extradata
int ff_avc_write_annexb_extradata(const uint8_t *in, uint8_t **buf, int *size)
Definition: avc.c:222
get_bitsz
static av_always_inline int get_bitsz(GetBitContext *s, int n)
Read 0-25 bits.
Definition: get_bits.h:415
av_free
#define av_free(p)
Definition: tableprint_vlc.h:34
h264.h
avio_wb16
void avio_wb16(AVIOContext *s, unsigned int val)
Definition: aviobuf.c:453
AVERROR_INVALIDDATA
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
Definition: error.h:59
ff_avc_mp4_find_startcode
const uint8_t * ff_avc_mp4_find_startcode(const uint8_t *start, const uint8_t *end, int nal_length_size)
Definition: avc.c:253
H264SequenceParameterSet::chroma_format_idc
uint8_t chroma_format_idc
Definition: avc.h:44
ff_avc_find_startcode
const uint8_t * ff_avc_find_startcode(const uint8_t *p, const uint8_t *end)
Definition: avc.c:67