FFmpeg
avpacket.c
Go to the documentation of this file.
1 /*
2  * AVPacket functions for libavcodec
3  * Copyright (c) 2000, 2001, 2002 Fabrice Bellard
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 <string.h>
23 
24 #include "libavutil/avassert.h"
25 #include "libavutil/common.h"
26 #include "libavutil/internal.h"
27 #include "libavutil/mathematics.h"
28 #include "libavutil/mem.h"
29 
30 #include "bytestream.h"
31 #include "internal.h"
32 #include "packet.h"
33 #include "packet_internal.h"
34 
35 #if FF_API_INIT_PACKET
37 {
40  pkt->pos = -1;
41  pkt->duration = 0;
42 #if FF_API_CONVERGENCE_DURATION
44  pkt->convergence_duration = 0;
46 #endif
47  pkt->flags = 0;
48  pkt->stream_index = 0;
49  pkt->buf = NULL;
50  pkt->side_data = NULL;
51  pkt->side_data_elems = 0;
52 }
53 #endif
54 
56 {
57  memset(pkt, 0, sizeof(*pkt));
58 
61  pkt->pos = -1;
62 }
63 
65 {
66  AVPacket *pkt = av_mallocz(sizeof(AVPacket));
67  if (!pkt)
68  return pkt;
69 
71 
72  return pkt;
73 }
74 
76 {
77  if (!pkt || !*pkt)
78  return;
79 
81  av_freep(pkt);
82 }
83 
84 static int packet_alloc(AVBufferRef **buf, int size)
85 {
86  int ret;
87  if (size < 0 || size >= INT_MAX - AV_INPUT_BUFFER_PADDING_SIZE)
88  return AVERROR(EINVAL);
89 
91  if (ret < 0)
92  return ret;
93 
94  memset((*buf)->data + size, 0, AV_INPUT_BUFFER_PADDING_SIZE);
95 
96  return 0;
97 }
98 
100 {
101  AVBufferRef *buf = NULL;
102  int ret = packet_alloc(&buf, size);
103  if (ret < 0)
104  return ret;
105 
107  pkt->buf = buf;
108  pkt->data = buf->data;
109  pkt->size = size;
110 
111  return 0;
112 }
113 
115 {
116  if (pkt->size <= size)
117  return;
118  pkt->size = size;
119  memset(pkt->data + size, 0, AV_INPUT_BUFFER_PADDING_SIZE);
120 }
121 
122 int av_grow_packet(AVPacket *pkt, int grow_by)
123 {
124  int new_size;
125  av_assert0((unsigned)pkt->size <= INT_MAX - AV_INPUT_BUFFER_PADDING_SIZE);
126  if ((unsigned)grow_by >
127  INT_MAX - (pkt->size + AV_INPUT_BUFFER_PADDING_SIZE))
128  return AVERROR(ENOMEM);
129 
130  new_size = pkt->size + grow_by + AV_INPUT_BUFFER_PADDING_SIZE;
131  if (pkt->buf) {
132  size_t data_offset;
133  uint8_t *old_data = pkt->data;
134  if (pkt->data == NULL) {
135  data_offset = 0;
136  pkt->data = pkt->buf->data;
137  } else {
138  data_offset = pkt->data - pkt->buf->data;
139  if (data_offset > INT_MAX - new_size)
140  return AVERROR(ENOMEM);
141  }
142 
143  if (new_size + data_offset > pkt->buf->size ||
145  int ret = av_buffer_realloc(&pkt->buf, new_size + data_offset);
146  if (ret < 0) {
147  pkt->data = old_data;
148  return ret;
149  }
150  pkt->data = pkt->buf->data + data_offset;
151  }
152  } else {
153  pkt->buf = av_buffer_alloc(new_size);
154  if (!pkt->buf)
155  return AVERROR(ENOMEM);
156  if (pkt->size > 0)
157  memcpy(pkt->buf->data, pkt->data, pkt->size);
158  pkt->data = pkt->buf->data;
159  }
160  pkt->size += grow_by;
161  memset(pkt->data + pkt->size, 0, AV_INPUT_BUFFER_PADDING_SIZE);
162 
163  return 0;
164 }
165 
167 {
168  if (size >= INT_MAX - AV_INPUT_BUFFER_PADDING_SIZE)
169  return AVERROR(EINVAL);
170 
173  if (!pkt->buf)
174  return AVERROR(ENOMEM);
175 
176  pkt->data = data;
177  pkt->size = size;
178 
179  return 0;
180 }
181 
182 #if FF_API_AVPACKET_OLD_API
184 #define ALLOC_MALLOC(data, size) data = av_malloc(size)
185 #define ALLOC_BUF(data, size) \
186 do { \
187  av_buffer_realloc(&pkt->buf, size); \
188  data = pkt->buf ? pkt->buf->data : NULL; \
189 } while (0)
190 
191 #define DUP_DATA(dst, src, size, padding, ALLOC) \
192  do { \
193  void *data; \
194  if (padding) { \
195  if ((unsigned)(size) > \
196  (unsigned)(size) + AV_INPUT_BUFFER_PADDING_SIZE) \
197  goto failed_alloc; \
198  ALLOC(data, size + AV_INPUT_BUFFER_PADDING_SIZE); \
199  } else { \
200  ALLOC(data, size); \
201  } \
202  if (!data) \
203  goto failed_alloc; \
204  memcpy(data, src, size); \
205  if (padding) \
206  memset((uint8_t *)data + size, 0, \
207  AV_INPUT_BUFFER_PADDING_SIZE); \
208  dst = data; \
209  } while (0)
210 
211 /* Makes duplicates of data, side_data, but does not copy any other fields */
212 static int copy_packet_data(AVPacket *pkt, const AVPacket *src, int dup)
213 {
214  pkt->data = NULL;
215  pkt->side_data = NULL;
216  pkt->side_data_elems = 0;
217  if (pkt->buf) {
218  AVBufferRef *ref = av_buffer_ref(src->buf);
219  if (!ref)
220  return AVERROR(ENOMEM);
221  pkt->buf = ref;
222  pkt->data = ref->data;
223  } else {
224  DUP_DATA(pkt->data, src->data, pkt->size, 1, ALLOC_BUF);
225  }
226  if (src->side_data_elems && dup) {
227  pkt->side_data = src->side_data;
228  pkt->side_data_elems = src->side_data_elems;
229  }
230  if (src->side_data_elems && !dup) {
232  }
233  return 0;
234 
235 failed_alloc:
237  return AVERROR(ENOMEM);
238 }
239 
241 {
242  if (src->side_data_elems) {
243  int i;
244  DUP_DATA(pkt->side_data, src->side_data,
245  src->side_data_elems * sizeof(*src->side_data), 0, ALLOC_MALLOC);
246  if (src != pkt) {
247  memset(pkt->side_data, 0,
248  src->side_data_elems * sizeof(*src->side_data));
249  }
250  for (i = 0; i < src->side_data_elems; i++) {
251  DUP_DATA(pkt->side_data[i].data, src->side_data[i].data,
252  src->side_data[i].size, 1, ALLOC_MALLOC);
253  pkt->side_data[i].size = src->side_data[i].size;
254  pkt->side_data[i].type = src->side_data[i].type;
255  }
256  }
257  pkt->side_data_elems = src->side_data_elems;
258  return 0;
259 
260 failed_alloc:
262  return AVERROR(ENOMEM);
263 }
264 
266 {
267  AVPacket tmp_pkt;
268 
269  if (!pkt->buf && pkt->data) {
270  tmp_pkt = *pkt;
271  return copy_packet_data(pkt, &tmp_pkt, 1);
272  }
273  return 0;
274 }
275 
277 {
278  *dst = *src;
279  return copy_packet_data(dst, src, 0);
280 }
282 #endif
283 
285 {
286  int i;
287  for (i = 0; i < pkt->side_data_elems; i++)
290  pkt->side_data_elems = 0;
291 }
292 
293 #if FF_API_AVPACKET_OLD_API
296 {
297  if (pkt) {
298  if (pkt->buf)
300  pkt->data = NULL;
301  pkt->size = 0;
302 
304  }
305 }
307 #endif
308 
310  uint8_t *data, size_t size)
311 {
313  int i, elems = pkt->side_data_elems;
314 
315  for (i = 0; i < elems; i++) {
316  AVPacketSideData *sd = &pkt->side_data[i];
317 
318  if (sd->type == type) {
319  av_free(sd->data);
320  sd->data = data;
321  sd->size = size;
322  return 0;
323  }
324  }
325 
326  if ((unsigned)elems + 1 > AV_PKT_DATA_NB)
327  return AVERROR(ERANGE);
328 
329  tmp = av_realloc(pkt->side_data, (elems + 1) * sizeof(*tmp));
330  if (!tmp)
331  return AVERROR(ENOMEM);
332 
333  pkt->side_data = tmp;
334  pkt->side_data[elems].data = data;
335  pkt->side_data[elems].size = size;
336  pkt->side_data[elems].type = type;
337  pkt->side_data_elems++;
338 
339  return 0;
340 }
341 
342 
345 {
346  int ret;
347  uint8_t *data;
348 
349 #if FF_API_BUFFER_SIZE_T
350  if ((unsigned)size > INT_MAX - AV_INPUT_BUFFER_PADDING_SIZE)
351 #else
352  if (size > SIZE_MAX - AV_INPUT_BUFFER_PADDING_SIZE)
353 #endif
354  return NULL;
356  if (!data)
357  return NULL;
358 
360  if (ret < 0) {
361  av_freep(&data);
362  return NULL;
363  }
364 
365  return data;
366 }
367 
370 {
371  int i;
372 
373  for (i = 0; i < pkt->side_data_elems; i++) {
374  if (pkt->side_data[i].type == type) {
375  if (size)
376  *size = pkt->side_data[i].size;
377  return pkt->side_data[i].data;
378  }
379  }
380  if (size)
381  *size = 0;
382  return NULL;
383 }
384 
386 {
387  switch(type) {
388  case AV_PKT_DATA_PALETTE: return "Palette";
389  case AV_PKT_DATA_NEW_EXTRADATA: return "New Extradata";
390  case AV_PKT_DATA_PARAM_CHANGE: return "Param Change";
391  case AV_PKT_DATA_H263_MB_INFO: return "H263 MB Info";
392  case AV_PKT_DATA_REPLAYGAIN: return "Replay Gain";
393  case AV_PKT_DATA_DISPLAYMATRIX: return "Display Matrix";
394  case AV_PKT_DATA_STEREO3D: return "Stereo 3D";
395  case AV_PKT_DATA_AUDIO_SERVICE_TYPE: return "Audio Service Type";
396  case AV_PKT_DATA_QUALITY_STATS: return "Quality stats";
397  case AV_PKT_DATA_FALLBACK_TRACK: return "Fallback track";
398  case AV_PKT_DATA_CPB_PROPERTIES: return "CPB properties";
399  case AV_PKT_DATA_SKIP_SAMPLES: return "Skip Samples";
400  case AV_PKT_DATA_JP_DUALMONO: return "JP Dual Mono";
401  case AV_PKT_DATA_STRINGS_METADATA: return "Strings Metadata";
402  case AV_PKT_DATA_SUBTITLE_POSITION: return "Subtitle Position";
403  case AV_PKT_DATA_MATROSKA_BLOCKADDITIONAL: return "Matroska BlockAdditional";
404  case AV_PKT_DATA_WEBVTT_IDENTIFIER: return "WebVTT ID";
405  case AV_PKT_DATA_WEBVTT_SETTINGS: return "WebVTT Settings";
406  case AV_PKT_DATA_METADATA_UPDATE: return "Metadata Update";
407  case AV_PKT_DATA_MPEGTS_STREAM_ID: return "MPEGTS Stream ID";
408  case AV_PKT_DATA_MASTERING_DISPLAY_METADATA: return "Mastering display metadata";
409  case AV_PKT_DATA_CONTENT_LIGHT_LEVEL: return "Content light level metadata";
410  case AV_PKT_DATA_SPHERICAL: return "Spherical Mapping";
411  case AV_PKT_DATA_A53_CC: return "A53 Closed Captions";
412  case AV_PKT_DATA_ENCRYPTION_INIT_INFO: return "Encryption initialization data";
413  case AV_PKT_DATA_ENCRYPTION_INFO: return "Encryption info";
414  case AV_PKT_DATA_AFD: return "Active Format Description data";
415  case AV_PKT_DATA_PRFT: return "Producer Reference Time";
416  case AV_PKT_DATA_ICC_PROFILE: return "ICC Profile";
417  case AV_PKT_DATA_DOVI_CONF: return "DOVI configuration record";
418  case AV_PKT_DATA_S12M_TIMECODE: return "SMPTE ST 12-1:2014 timecode";
419  }
420  return NULL;
421 }
422 
423 #if FF_API_MERGE_SD_API
424 
425 #define FF_MERGE_MARKER 0x8c4d9d108e25e9feULL
426 
428  if(pkt->side_data_elems){
429  AVBufferRef *buf;
430  int i;
431  uint8_t *p;
432  uint64_t size= pkt->size + 8LL + AV_INPUT_BUFFER_PADDING_SIZE;
433  AVPacket old= *pkt;
434  for (i=0; i<old.side_data_elems; i++) {
435  size += old.side_data[i].size + 5LL;
436  }
437  if (size > INT_MAX)
438  return AVERROR(EINVAL);
439  buf = av_buffer_alloc(size);
440  if (!buf)
441  return AVERROR(ENOMEM);
442  pkt->buf = buf;
443  pkt->data = p = buf->data;
445  bytestream_put_buffer(&p, old.data, old.size);
446  for (i=old.side_data_elems-1; i>=0; i--) {
448  bytestream_put_be32(&p, old.side_data[i].size);
449  *p++ = old.side_data[i].type | ((i==old.side_data_elems-1)*128);
450  }
451  bytestream_put_be64(&p, FF_MERGE_MARKER);
452  av_assert0(p-pkt->data == pkt->size);
453  memset(p, 0, AV_INPUT_BUFFER_PADDING_SIZE);
454  av_packet_unref(&old);
455  pkt->side_data_elems = 0;
456  pkt->side_data = NULL;
457  return 1;
458  }
459  return 0;
460 }
461 
463  if (!pkt->side_data_elems && pkt->size >12 && AV_RB64(pkt->data + pkt->size - 8) == FF_MERGE_MARKER){
464  int i;
465  unsigned int size;
466  uint8_t *p;
467 
468  p = pkt->data + pkt->size - 8 - 5;
469  for (i=1; ; i++){
470  size = AV_RB32(p);
471  if (size>INT_MAX - 5 || p - pkt->data < size)
472  return 0;
473  if (p[4]&128)
474  break;
475  if (p - pkt->data < size + 5)
476  return 0;
477  p-= size+5;
478  }
479 
480  if (i > AV_PKT_DATA_NB)
481  return AVERROR(ERANGE);
482 
483  pkt->side_data = av_malloc_array(i, sizeof(*pkt->side_data));
484  if (!pkt->side_data)
485  return AVERROR(ENOMEM);
486 
487  p= pkt->data + pkt->size - 8 - 5;
488  for (i=0; ; i++){
489  size= AV_RB32(p);
490  av_assert0(size<=INT_MAX - 5 && p - pkt->data >= size);
492  pkt->side_data[i].size = size;
493  pkt->side_data[i].type = p[4]&127;
494  if (!pkt->side_data[i].data)
495  return AVERROR(ENOMEM);
496  memcpy(pkt->side_data[i].data, p-size, size);
497  pkt->size -= size + 5;
498  if(p[4]&128)
499  break;
500  p-= size+5;
501  }
502  pkt->size -= 8;
503  pkt->side_data_elems = i+1;
504  return 1;
505  }
506  return 0;
507 }
508 #endif
509 
510 #if FF_API_BUFFER_SIZE_T
512 #else
514 #endif
515 {
516  uint8_t *data = NULL;
517  *size = 0;
518 
519  if (!dict)
520  return NULL;
521 
522  for (int pass = 0; pass < 2; pass++) {
523  const AVDictionaryEntry *t = NULL;
524  size_t total_length = 0;
525 
526  while ((t = av_dict_get(dict, "", t, AV_DICT_IGNORE_SUFFIX))) {
527  for (int i = 0; i < 2; i++) {
528  const char *str = i ? t->value : t->key;
529  const size_t len = strlen(str) + 1;
530 
531  if (pass)
532  memcpy(data + total_length, str, len);
533 #if FF_API_BUFFER_SIZE_T
534  else if (len > INT_MAX - total_length)
535 #else
536  else if (len > SIZE_MAX - total_length)
537 #endif
538  return NULL;
539  total_length += len;
540  }
541  }
542  if (pass)
543  break;
544  data = av_malloc(total_length);
545  if (!data)
546  return NULL;
547  *size = total_length;
548  }
549 
550  return data;
551 }
552 
553 #if FF_API_BUFFER_SIZE_T
555 #else
557  AVDictionary **dict)
558 #endif
559 {
560  const uint8_t *end;
561  int ret;
562 
563  if (!dict || !data || !size)
564  return 0;
565  end = data + size;
566  if (size && end[-1])
567  return AVERROR_INVALIDDATA;
568  while (data < end) {
569  const uint8_t *key = data;
570  const uint8_t *val = data + strlen(key) + 1;
571 
572  if (val >= end || !*key)
573  return AVERROR_INVALIDDATA;
574 
575  ret = av_dict_set(dict, key, val, 0);
576  if (ret < 0)
577  return ret;
578  data = val + strlen(val) + 1;
579  }
580 
581  return 0;
582 }
583 
586 {
587  int i;
588 
589  for (i = 0; i < pkt->side_data_elems; i++) {
590  if (pkt->side_data[i].type == type) {
591  if (size > pkt->side_data[i].size)
592  return AVERROR(ENOMEM);
593  pkt->side_data[i].size = size;
594  return 0;
595  }
596  }
597  return AVERROR(ENOENT);
598 }
599 
601 {
602  int i;
603 
604  dst->pts = src->pts;
605  dst->dts = src->dts;
606  dst->pos = src->pos;
607  dst->duration = src->duration;
608 #if FF_API_CONVERGENCE_DURATION
610  dst->convergence_duration = src->convergence_duration;
612 #endif
613  dst->flags = src->flags;
614  dst->stream_index = src->stream_index;
615 
616  dst->side_data = NULL;
617  dst->side_data_elems = 0;
618  for (i = 0; i < src->side_data_elems; i++) {
619  enum AVPacketSideDataType type = src->side_data[i].type;
620  buffer_size_t size = src->side_data[i].size;
621  uint8_t *src_data = src->side_data[i].data;
622  uint8_t *dst_data = av_packet_new_side_data(dst, type, size);
623 
624  if (!dst_data) {
626  return AVERROR(ENOMEM);
627  }
628  memcpy(dst_data, src_data, size);
629  }
630 
631  return 0;
632 }
633 
635 {
639 }
640 
642 {
643  int ret;
644 
645  dst->buf = NULL;
646 
647  ret = av_packet_copy_props(dst, src);
648  if (ret < 0)
649  goto fail;
650 
651  if (!src->buf) {
652  ret = packet_alloc(&dst->buf, src->size);
653  if (ret < 0)
654  goto fail;
655  av_assert1(!src->size || src->data);
656  if (src->size)
657  memcpy(dst->buf->data, src->data, src->size);
658 
659  dst->data = dst->buf->data;
660  } else {
661  dst->buf = av_buffer_ref(src->buf);
662  if (!dst->buf) {
663  ret = AVERROR(ENOMEM);
664  goto fail;
665  }
666  dst->data = src->data;
667  }
668 
669  dst->size = src->size;
670 
671  return 0;
672 fail:
673  av_packet_unref(dst);
674  return ret;
675 }
676 
678 {
680 
681  if (!ret)
682  return ret;
683 
684  if (av_packet_ref(ret, src))
686 
687  return ret;
688 }
689 
691 {
692  *dst = *src;
694 }
695 
697 {
698  int ret;
699 
700  if (pkt->buf)
701  return 0;
702 
703  ret = packet_alloc(&pkt->buf, pkt->size);
704  if (ret < 0)
705  return ret;
706  av_assert1(!pkt->size || pkt->data);
707  if (pkt->size)
708  memcpy(pkt->buf->data, pkt->data, pkt->size);
709 
710  pkt->data = pkt->buf->data;
711 
712  return 0;
713 }
714 
716 {
717  AVBufferRef *buf = NULL;
718  int ret;
719 
720  if (pkt->buf && av_buffer_is_writable(pkt->buf))
721  return 0;
722 
723  ret = packet_alloc(&buf, pkt->size);
724  if (ret < 0)
725  return ret;
726  av_assert1(!pkt->size || pkt->data);
727  if (pkt->size)
728  memcpy(buf->data, pkt->data, pkt->size);
729 
731  pkt->buf = buf;
732  pkt->data = buf->data;
733 
734  return 0;
735 }
736 
738 {
739  if (pkt->pts != AV_NOPTS_VALUE)
740  pkt->pts = av_rescale_q(pkt->pts, src_tb, dst_tb);
741  if (pkt->dts != AV_NOPTS_VALUE)
742  pkt->dts = av_rescale_q(pkt->dts, src_tb, dst_tb);
743  if (pkt->duration > 0)
744  pkt->duration = av_rescale_q(pkt->duration, src_tb, dst_tb);
745 #if FF_API_CONVERGENCE_DURATION
747  if (pkt->convergence_duration > 0)
748  pkt->convergence_duration = av_rescale_q(pkt->convergence_duration, src_tb, dst_tb);
750 #endif
751 }
752 
753 int avpriv_packet_list_put(PacketList **packet_buffer,
754  PacketList **plast_pktl,
755  AVPacket *pkt,
756  int (*copy)(AVPacket *dst, const AVPacket *src),
757  int flags)
758 {
759  PacketList *pktl = av_mallocz(sizeof(PacketList));
760  int ret;
761 
762  if (!pktl)
763  return AVERROR(ENOMEM);
764 
765  if (copy) {
766  ret = copy(&pktl->pkt, pkt);
767  if (ret < 0) {
768  av_free(pktl);
769  return ret;
770  }
771  } else {
773  if (ret < 0) {
774  av_free(pktl);
775  return ret;
776  }
777  av_packet_move_ref(&pktl->pkt, pkt);
778  }
779 
780  if (*packet_buffer)
781  (*plast_pktl)->next = pktl;
782  else
783  *packet_buffer = pktl;
784 
785  /* Add the packet in the buffered packet list. */
786  *plast_pktl = pktl;
787  return 0;
788 }
789 
791  PacketList **pkt_buffer_end,
792  AVPacket *pkt)
793 {
794  PacketList *pktl;
795  if (!*pkt_buffer)
796  return AVERROR(EAGAIN);
797  pktl = *pkt_buffer;
798  *pkt = pktl->pkt;
799  *pkt_buffer = pktl->next;
800  if (!pktl->next)
801  *pkt_buffer_end = NULL;
802  av_freep(&pktl);
803  return 0;
804 }
805 
806 void avpriv_packet_list_free(PacketList **pkt_buf, PacketList **pkt_buf_end)
807 {
808  PacketList *tmp = *pkt_buf;
809 
810  while (tmp) {
811  PacketList *pktl = tmp;
812  tmp = pktl->next;
813  av_packet_unref(&pktl->pkt);
814  av_freep(&pktl);
815  }
816  *pkt_buf = NULL;
817  *pkt_buf_end = NULL;
818 }
819 
820 int ff_side_data_set_encoder_stats(AVPacket *pkt, int quality, int64_t *error, int error_count, int pict_type)
821 {
822  uint8_t *side_data;
823  buffer_size_t side_data_size;
824  int i;
825 
826  side_data = av_packet_get_side_data(pkt, AV_PKT_DATA_QUALITY_STATS, &side_data_size);
827  if (!side_data) {
828  side_data_size = 4+4+8*error_count;
830  side_data_size);
831  }
832 
833  if (!side_data || side_data_size < 4+4+8*error_count)
834  return AVERROR(ENOMEM);
835 
836  AV_WL32(side_data , quality );
837  side_data[4] = pict_type;
838  side_data[5] = error_count;
839  for (i = 0; i<error_count; i++)
840  AV_WL64(side_data+8 + 8*i , error[i]);
841 
842  return 0;
843 }
844 
845 int ff_side_data_set_prft(AVPacket *pkt, int64_t timestamp)
846 {
848  uint8_t *side_data;
849  buffer_size_t side_data_size;
850 
851  side_data = av_packet_get_side_data(pkt, AV_PKT_DATA_PRFT, &side_data_size);
852  if (!side_data) {
853  side_data_size = sizeof(AVProducerReferenceTime);
854  side_data = av_packet_new_side_data(pkt, AV_PKT_DATA_PRFT, side_data_size);
855  }
856 
857  if (!side_data || side_data_size < sizeof(AVProducerReferenceTime))
858  return AVERROR(ENOMEM);
859 
860  prft = (AVProducerReferenceTime *)side_data;
861  prft->wallclock = timestamp;
862  prft->flags = 0;
863 
864  return 0;
865 }
error
static void error(const char *err)
Definition: target_bsf_fuzzer.c:30
av_packet_unref
void av_packet_unref(AVPacket *pkt)
Wipe the packet.
Definition: avpacket.c:634
FF_ENABLE_DEPRECATION_WARNINGS
#define FF_ENABLE_DEPRECATION_WARNINGS
Definition: internal.h:84
av_buffer_alloc
AVBufferRef * av_buffer_alloc(buffer_size_t size)
Allocate an AVBuffer of the given size using av_malloc().
Definition: buffer.c:67
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
AV_PKT_DATA_NB
@ AV_PKT_DATA_NB
The number of side data types.
Definition: packet.h:301
av_packet_get_side_data
uint8_t * av_packet_get_side_data(const AVPacket *pkt, enum AVPacketSideDataType type, buffer_size_t *size)
Definition: avpacket.c:368
av_buffer_realloc
int av_buffer_realloc(AVBufferRef **pbuf, buffer_size_t size)
Reallocate a given buffer.
Definition: buffer.c:169
AV_WL32
#define AV_WL32(p, v)
Definition: intreadwrite.h:426
AV_PKT_DATA_MPEGTS_STREAM_ID
@ AV_PKT_DATA_MPEGTS_STREAM_ID
MPEGTS stream ID as uint8_t, this is required to pass the stream ID information from the demuxer to t...
Definition: packet.h:215
AV_PKT_DATA_PARAM_CHANGE
@ AV_PKT_DATA_PARAM_CHANGE
An AV_PKT_DATA_PARAM_CHANGE side data packet is laid out as follows:
Definition: packet.h:72
ff_side_data_set_encoder_stats
int ff_side_data_set_encoder_stats(AVPacket *pkt, int quality, int64_t *error, int error_count, int pict_type)
Definition: avpacket.c:820
AVBufferRef::data
uint8_t * data
The data buffer.
Definition: buffer.h:92
av_grow_packet
int av_grow_packet(AVPacket *pkt, int grow_by)
Increase packet size, correctly zeroing padding.
Definition: avpacket.c:122
AV_PKT_DATA_ENCRYPTION_INFO
@ AV_PKT_DATA_ENCRYPTION_INFO
This side data contains encryption info for how to decrypt the packet.
Definition: packet.h:255
tmp
static uint8_t tmp[11]
Definition: aes_ctr.c:27
AVPacketSideData
Definition: packet.h:306
AVProducerReferenceTime::wallclock
int64_t wallclock
A UTC timestamp, in microseconds, since Unix epoch (e.g, av_gettime()).
Definition: avcodec.h:507
internal.h
AVPacket::data
uint8_t * data
Definition: packet.h:369
AV_PKT_DATA_PALETTE
@ AV_PKT_DATA_PALETTE
An AV_PKT_DATA_PALETTE side data packet contains exactly AVPALETTE_SIZE bytes worth of palette.
Definition: packet.h:46
PacketList
Definition: packet_internal.h:26
data
const char data[16]
Definition: mxf.c:142
AV_PKT_DATA_ENCRYPTION_INIT_INFO
@ AV_PKT_DATA_ENCRYPTION_INIT_INFO
This side data is encryption initialization data.
Definition: packet.h:249
AV_DICT_IGNORE_SUFFIX
#define AV_DICT_IGNORE_SUFFIX
Return first entry in a dictionary whose first part corresponds to the search key,...
Definition: dict.h:70
AV_PKT_DATA_AFD
@ AV_PKT_DATA_AFD
Active Format Description data consisting of a single byte as specified in ETSI TS 101 154 using AVAc...
Definition: packet.h:261
av_buffer_create
AVBufferRef * av_buffer_create(uint8_t *data, buffer_size_t size, void(*free)(void *opaque, uint8_t *data), void *opaque, int flags)
Create an AVBuffer from an existing array.
Definition: buffer.c:29
AVPacket::duration
int64_t duration
Duration of this packet in AVStream->time_base units, 0 if unknown.
Definition: packet.h:387
mathematics.h
AVDictionary
Definition: dict.c:30
AV_PKT_DATA_SPHERICAL
@ AV_PKT_DATA_SPHERICAL
This side data should be associated with a video stream and corresponds to the AVSphericalMapping str...
Definition: packet.h:228
av_packet_free_side_data
FF_ENABLE_DEPRECATION_WARNINGS void av_packet_free_side_data(AVPacket *pkt)
Convenience function to free all the side data stored.
Definition: avpacket.c:284
packet_alloc
static int packet_alloc(AVBufferRef **buf, int size)
Definition: avpacket.c:84
av_packet_free
void av_packet_free(AVPacket **pkt)
Free the packet, if the packet is reference counted, it will be unreferenced first.
Definition: avpacket.c:75
quality
trying all byte sequences megabyte in length and selecting the best looking sequence will yield cases to try But a word about quality
Definition: rate_distortion.txt:12
av_malloc
#define av_malloc(s)
Definition: tableprint_vlc.h:31
AVBufferRef::size
int size
Size of data in bytes.
Definition: buffer.h:97
AVPacketSideData::size
size_t size
Definition: packet.h:311
av_packet_add_side_data
FF_ENABLE_DEPRECATION_WARNINGS int av_packet_add_side_data(AVPacket *pkt, enum AVPacketSideDataType type, uint8_t *data, size_t size)
Wrap an existing array as a packet side data.
Definition: avpacket.c:309
fail
#define fail()
Definition: checkasm.h:133
av_shrink_packet
void av_shrink_packet(AVPacket *pkt, int size)
Reduce packet size, correctly zeroing padding.
Definition: avpacket.c:114
ff_side_data_set_prft
int ff_side_data_set_prft(AVPacket *pkt, int64_t timestamp)
Definition: avpacket.c:845
val
static double val(void *priv, double ch)
Definition: aeval.c:76
type
it s the only field you need to keep assuming you have a context There is some magic you don t need to care about around this just let it vf type
Definition: writing_filters.txt:86
AV_PKT_DATA_DISPLAYMATRIX
@ AV_PKT_DATA_DISPLAYMATRIX
This side data contains a 3x3 transformation matrix describing an affine transformation that needs to...
Definition: packet.h:108
AV_PKT_DATA_STRINGS_METADATA
@ AV_PKT_DATA_STRINGS_METADATA
A list of zero terminated key/value strings.
Definition: packet.h:172
AV_PKT_DATA_REPLAYGAIN
@ AV_PKT_DATA_REPLAYGAIN
This side data should be associated with an audio stream and contains ReplayGain information in form ...
Definition: packet.h:99
av_packet_side_data_name
const char * av_packet_side_data_name(enum AVPacketSideDataType type)
Definition: avpacket.c:385
av_init_packet
void av_init_packet(AVPacket *pkt)
Definition: avpacket.c:36
avassert.h
AV_PKT_DATA_WEBVTT_SETTINGS
@ AV_PKT_DATA_WEBVTT_SETTINGS
The optional settings (rendering instructions) that immediately follow the timestamp specifier of a W...
Definition: packet.h:202
pkt
AVPacket * pkt
Definition: movenc.c:59
AV_PKT_DATA_AUDIO_SERVICE_TYPE
@ AV_PKT_DATA_AUDIO_SERVICE_TYPE
This side data should be associated with an audio stream and corresponds to enum AVAudioServiceType.
Definition: packet.h:120
av_dict_get
AVDictionaryEntry * av_dict_get(const AVDictionary *m, const char *key, const AVDictionaryEntry *prev, int flags)
Get a dictionary entry with matching key.
Definition: dict.c:40
av_new_packet
int av_new_packet(AVPacket *pkt, int size)
Allocate the payload of a packet and initialize its fields with default values.
Definition: avpacket.c:99
AV_PKT_DATA_STEREO3D
@ AV_PKT_DATA_STEREO3D
This side data should be associated with a video stream and contains Stereoscopic 3D information in f...
Definition: packet.h:114
AV_PKT_DATA_MASTERING_DISPLAY_METADATA
@ AV_PKT_DATA_MASTERING_DISPLAY_METADATA
Mastering display metadata (based on SMPTE-2086:2014).
Definition: packet.h:222
buffer_size_t
int buffer_size_t
Definition: internal.h:306
AVDictionaryEntry::key
char * key
Definition: dict.h:82
copy_packet_data
static int copy_packet_data(AVPacket *pkt, const AVPacket *src, int dup)
Definition: avpacket.c:212
av_packet_split_side_data
int av_packet_split_side_data(AVPacket *pkt)
Definition: avpacket.c:462
av_buffer_default_free
void av_buffer_default_free(void *opaque, uint8_t *data)
Default free callback, which calls av_free() on the buffer data.
Definition: buffer.c:62
av_assert0
#define av_assert0(cond)
assert() equivalent, that is always enabled.
Definition: avassert.h:37
AV_PKT_DATA_ICC_PROFILE
@ AV_PKT_DATA_ICC_PROFILE
ICC profile data consisting of an opaque octet buffer following the format described by ISO 15076-1.
Definition: packet.h:274
FF_MERGE_MARKER
#define FF_MERGE_MARKER
Definition: avpacket.c:425
AVPacketSideData::data
uint8_t * data
Definition: packet.h:307
av_rescale_q
int64_t av_rescale_q(int64_t a, AVRational bq, AVRational cq)
Rescale a 64-bit integer by 2 rational numbers.
Definition: mathematics.c:142
av_copy_packet_side_data
int av_copy_packet_side_data(AVPacket *pkt, const AVPacket *src)
Definition: avpacket.c:240
key
const char * key
Definition: hwcontext_opencl.c:168
AV_PKT_DATA_PRFT
@ AV_PKT_DATA_PRFT
Producer Reference Time data corresponding to the AVProducerReferenceTime struct, usually exported by...
Definition: packet.h:268
pass
#define pass
Definition: fft_template.c:603
ALLOC_MALLOC
#define ALLOC_MALLOC(data, size)
Definition: avpacket.c:184
AVPacket::buf
AVBufferRef * buf
A reference to the reference-counted buffer where the packet data is stored.
Definition: packet.h:352
NULL
#define NULL
Definition: coverity.c:32
av_buffer_unref
void av_buffer_unref(AVBufferRef **buf)
Free a given reference and automatically free the buffer if there are no more references to it.
Definition: buffer.c:125
AVRational
Rational number (pair of numerator and denominator).
Definition: rational.h:58
AVPacketSideData::type
enum AVPacketSideDataType type
Definition: packet.h:313
src
#define src
Definition: vp8dsp.c:255
PacketList::next
struct PacketList * next
Definition: packet_internal.h:28
av_dup_packet
int av_dup_packet(AVPacket *pkt)
Definition: avpacket.c:265
AV_PKT_DATA_SUBTITLE_POSITION
@ AV_PKT_DATA_SUBTITLE_POSITION
Subtitle event position.
Definition: packet.h:183
AVProducerReferenceTime
This structure supplies correlation between a packet timestamp and a wall clock production time.
Definition: avcodec.h:503
av_packet_ref
int av_packet_ref(AVPacket *dst, const AVPacket *src)
Setup a new reference to the data described by a given packet.
Definition: avpacket.c:641
av_packet_move_ref
void av_packet_move_ref(AVPacket *dst, AVPacket *src)
Move every field in src to dst and reset src.
Definition: avpacket.c:690
AVProducerReferenceTime::flags
int flags
Definition: avcodec.h:508
av_packet_from_data
int av_packet_from_data(AVPacket *pkt, uint8_t *data, int size)
Initialize a reference-counted packet from av_malloc()ed data.
Definition: avpacket.c:166
AVPacket::size
int size
Definition: packet.h:370
copy
static void copy(const float *p1, float *p2, const int length)
Definition: vf_vaguedenoiser.c:194
get_packet_defaults
static void get_packet_defaults(AVPacket *pkt)
Definition: avpacket.c:55
size
int size
Definition: twinvq_data.h:10344
AV_NOPTS_VALUE
#define AV_NOPTS_VALUE
Undefined timestamp value.
Definition: avutil.h:248
AV_RB32
uint64_t_TMPL AV_WL64 unsigned int_TMPL AV_WL32 unsigned int_TMPL AV_WL24 unsigned int_TMPL AV_WL16 uint64_t_TMPL AV_WB64 unsigned int_TMPL AV_RB32
Definition: bytestream.h:96
AV_PKT_DATA_H263_MB_INFO
@ AV_PKT_DATA_H263_MB_INFO
An AV_PKT_DATA_H263_MB_INFO side data packet contains a number of structures with info about macroblo...
Definition: packet.h:93
av_packet_unpack_dictionary
int av_packet_unpack_dictionary(const uint8_t *data, size_t size, AVDictionary **dict)
Unpack a dictionary from side_data.
Definition: avpacket.c:556
AVPacket::dts
int64_t dts
Decompression timestamp in AVStream->time_base units; the time at which the packet is decompressed.
Definition: packet.h:368
AV_WL64
#define AV_WL64(p, v)
Definition: intreadwrite.h:440
AVPacketSideDataType
AVPacketSideDataType
Definition: packet.h:40
av_packet_pack_dictionary
uint8_t * av_packet_pack_dictionary(AVDictionary *dict, size_t *size)
Pack a dictionary for use in side_data.
Definition: avpacket.c:513
AV_PKT_DATA_CONTENT_LIGHT_LEVEL
@ AV_PKT_DATA_CONTENT_LIGHT_LEVEL
Content light level (based on CTA-861.3).
Definition: packet.h:235
av_packet_make_refcounted
int av_packet_make_refcounted(AVPacket *pkt)
Ensure the data described by a given packet is reference counted.
Definition: avpacket.c:696
AVPacket::flags
int flags
A combination of AV_PKT_FLAG values.
Definition: packet.h:375
av_packet_alloc
AVPacket * av_packet_alloc(void)
Allocate an AVPacket and set its fields to default values.
Definition: avpacket.c:64
av_packet_rescale_ts
void av_packet_rescale_ts(AVPacket *pkt, AVRational src_tb, AVRational dst_tb)
Convert valid timing fields (timestamps / durations) in a packet from one timebase to another.
Definition: avpacket.c:737
PacketList::pkt
AVPacket pkt
Definition: packet_internal.h:27
AV_PKT_DATA_METADATA_UPDATE
@ AV_PKT_DATA_METADATA_UPDATE
A list of zero terminated key/value strings.
Definition: packet.h:209
av_realloc
void * av_realloc(void *ptr, size_t size)
Allocate, reallocate, or free a block of memory.
Definition: mem.c:134
AV_PKT_DATA_JP_DUALMONO
@ AV_PKT_DATA_JP_DUALMONO
An AV_PKT_DATA_JP_DUALMONO side data packet indicates that the packet may contain "dual mono" audio s...
Definition: packet.h:166
bytestream_put_buffer
static av_always_inline void bytestream_put_buffer(uint8_t **b, const uint8_t *src, unsigned int size)
Definition: bytestream.h:372
av_packet_copy_props
int av_packet_copy_props(AVPacket *dst, const AVPacket *src)
Copy only "properties" fields from src to dst.
Definition: avpacket.c:600
i
int i
Definition: input.c:407
AVPacket::pts
int64_t pts
Presentation timestamp in AVStream->time_base units; the time at which the decompressed packet will b...
Definition: packet.h:362
packet.h
DUP_DATA
#define DUP_DATA(dst, src, size, padding, ALLOC)
Definition: avpacket.c:191
internal.h
av_malloc_array
#define av_malloc_array(a, b)
Definition: tableprint_vlc.h:32
common.h
av_assert1
#define av_assert1(cond)
assert() equivalent, that does not lie in speed critical code.
Definition: avassert.h:53
AV_PKT_DATA_A53_CC
@ AV_PKT_DATA_A53_CC
ATSC A53 Part 4 Closed Captions.
Definition: packet.h:242
uint8_t
uint8_t
Definition: audio_convert.c:194
av_packet_merge_side_data
int av_packet_merge_side_data(AVPacket *pkt)
Definition: avpacket.c:427
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:237
AV_PKT_DATA_CPB_PROPERTIES
@ AV_PKT_DATA_CPB_PROPERTIES
This side data corresponds to the AVCPBProperties struct.
Definition: packet.h:145
AV_PKT_DATA_SKIP_SAMPLES
@ AV_PKT_DATA_SKIP_SAMPLES
Recommmends skipping the specified number of samples.
Definition: packet.h:156
len
int len
Definition: vorbis_enc_data.h:452
av_copy_packet
int av_copy_packet(AVPacket *dst, const AVPacket *src)
Definition: avpacket.c:276
av_packet_new_side_data
uint8_t * av_packet_new_side_data(AVPacket *pkt, enum AVPacketSideDataType type, buffer_size_t size)
Definition: avpacket.c:343
av_buffer_is_writable
int av_buffer_is_writable(const AVBufferRef *buf)
Definition: buffer.c:133
av_free_packet
FF_DISABLE_DEPRECATION_WARNINGS void av_free_packet(AVPacket *pkt)
Definition: avpacket.c:295
ALLOC_BUF
#define ALLOC_BUF(data, size)
Definition: avpacket.c:185
ret
ret
Definition: filter_design.txt:187
AV_PKT_DATA_DOVI_CONF
@ AV_PKT_DATA_DOVI_CONF
DOVI configuration ref: dolby-vision-bitstreams-within-the-iso-base-media-file-format-v2....
Definition: packet.h:283
av_packet_shrink_side_data
int av_packet_shrink_side_data(AVPacket *pkt, enum AVPacketSideDataType type, buffer_size_t size)
Definition: avpacket.c:584
avpriv_packet_list_get
int avpriv_packet_list_get(PacketList **pkt_buffer, PacketList **pkt_buffer_end, AVPacket *pkt)
Remove the oldest AVPacket in the list and return it.
Definition: avpacket.c:790
AVPacket::side_data
AVPacketSideData * side_data
Additional packet data that can be provided by the container.
Definition: packet.h:380
AV_PKT_DATA_S12M_TIMECODE
@ AV_PKT_DATA_S12M_TIMECODE
Timecode which conforms to SMPTE ST 12-1:2014.
Definition: packet.h:291
AV_INPUT_BUFFER_PADDING_SIZE
#define AV_INPUT_BUFFER_PADDING_SIZE
Definition: avcodec.h:215
AV_PKT_DATA_NEW_EXTRADATA
@ AV_PKT_DATA_NEW_EXTRADATA
The AV_PKT_DATA_NEW_EXTRADATA is used to notify the codec or the format that the extradata buffer was...
Definition: packet.h:55
av_packet_make_writable
int av_packet_make_writable(AVPacket *pkt)
Create a writable reference for the data described by a given packet, avoiding data copy if possible.
Definition: avpacket.c:715
ref
static int ref[MAX_W *MAX_W]
Definition: jpeg2000dwt.c:107
AVPacket::stream_index
int stream_index
Definition: packet.h:371
av_buffer_ref
AVBufferRef * av_buffer_ref(AVBufferRef *buf)
Create a new reference to an AVBuffer.
Definition: buffer.c:93
FF_DISABLE_DEPRECATION_WARNINGS
#define FF_DISABLE_DEPRECATION_WARNINGS
Definition: internal.h:83
mem.h
AVBufferRef
A reference to a data buffer.
Definition: buffer.h:84
packet_internal.h
AV_PKT_DATA_MATROSKA_BLOCKADDITIONAL
@ AV_PKT_DATA_MATROSKA_BLOCKADDITIONAL
Data found in BlockAdditional element of matroska container.
Definition: packet.h:191
av_free
#define av_free(p)
Definition: tableprint_vlc.h:34
AVDictionaryEntry
Definition: dict.h:81
AVPacket
This structure stores compressed data.
Definition: packet.h:346
av_freep
#define av_freep(p)
Definition: tableprint_vlc.h:35
av_dict_set
int av_dict_set(AVDictionary **pm, const char *key, const char *value, int flags)
Set the given entry in *pm, overwriting an existing entry.
Definition: dict.c:70
AVPacket::pos
int64_t pos
byte position in stream, -1 if unknown
Definition: packet.h:389
AV_PKT_DATA_FALLBACK_TRACK
@ AV_PKT_DATA_FALLBACK_TRACK
This side data contains an integer value representing the stream index of a "fallback" track.
Definition: packet.h:140
bytestream.h
convert_header.str
string str
Definition: convert_header.py:20
AV_PKT_DATA_QUALITY_STATS
@ AV_PKT_DATA_QUALITY_STATS
This side data contains quality related information from the encoder.
Definition: packet.h:132
flags
#define flags(name, subs,...)
Definition: cbs_av1.c:561
AVERROR_INVALIDDATA
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
Definition: error.h:59
AV_PKT_DATA_WEBVTT_IDENTIFIER
@ AV_PKT_DATA_WEBVTT_IDENTIFIER
The optional first identifier line of a WebVTT cue.
Definition: packet.h:196
AVDictionaryEntry::value
char * value
Definition: dict.h:83
avpriv_packet_list_put
int avpriv_packet_list_put(PacketList **packet_buffer, PacketList **plast_pktl, AVPacket *pkt, int(*copy)(AVPacket *dst, const AVPacket *src), int flags)
Append an AVPacket to the list.
Definition: avpacket.c:753
AV_RB64
uint64_t_TMPL AV_WL64 unsigned int_TMPL AV_WL32 unsigned int_TMPL AV_WL24 unsigned int_TMPL AV_WL16 uint64_t_TMPL AV_RB64
Definition: bytestream.h:95
avpriv_packet_list_free
void avpriv_packet_list_free(PacketList **pkt_buf, PacketList **pkt_buf_end)
Wipe the list and unref all the packets in it.
Definition: avpacket.c:806
AVPacket::side_data_elems
int side_data_elems
Definition: packet.h:381
av_packet_clone
AVPacket * av_packet_clone(const AVPacket *src)
Create a new packet that references the same data as src.
Definition: avpacket.c:677