FFmpeg
avpacket.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 #include <stdio.h>
20 #include <stdlib.h>
21 #include <inttypes.h>
22 #include <string.h>
23 #include "libavcodec/avcodec.h"
24 #include "libavutil/error.h"
25 
26 
27 
28 static int setup_side_data_entry(AVPacket* avpkt)
29 {
30  const uint8_t *data_name = NULL;
31  int ret = 0, bytes;
32  uint8_t *extra_data = NULL;
33 
34 
35  /* get side_data_name string */
37 
38  /* Allocate a memory bloc */
39  bytes = strlen(data_name);
40 
41  if(!(extra_data = av_malloc(bytes))){
42  ret = AVERROR(ENOMEM);
43  fprintf(stderr, "Error occurred: %s\n", av_err2str(ret));
44  exit(1);
45  }
46  /* copy side_data_name to extra_data array */
47  memcpy(extra_data, data_name, bytes);
48 
49  /* create side data for AVPacket */
51  extra_data, bytes);
52  if(ret < 0){
53  fprintf(stderr,
54  "Error occurred in av_packet_add_side_data: %s\n",
55  av_err2str(ret));
56  }
57 
58  return ret;
59 }
60 
61 static int initializations(AVPacket* avpkt)
62 {
63  const static uint8_t* data = "selftest for av_packet_clone(...)";
64  int ret = 0;
65 
66  /* initialize avpkt */
67  av_init_packet(avpkt);
68 
69  /* set values for avpkt */
70  avpkt->pts = 17;
71  avpkt->dts = 2;
72  avpkt->data = (uint8_t*)data;
73  avpkt->size = strlen(data);
74  avpkt->flags = AV_PKT_FLAG_DISCARD;
75  avpkt->duration = 100;
76  avpkt->pos = 3;
77 
78  ret = setup_side_data_entry(avpkt);
79 
80  return ret;
81 }
82 
83 int main(void)
84 {
85  AVPacket avpkt;
86  AVPacket *avpkt_clone = NULL;
87  int ret = 0;
88 
89  if(initializations(&avpkt) < 0){
90  printf("failed to initialize variables\n");
91  return 1;
92  }
93  /* test av_packet_clone*/
94  avpkt_clone = av_packet_clone(&avpkt);
95 
96  if(!avpkt_clone) {
97  av_log(NULL, AV_LOG_ERROR,"av_packet_clone failed to clone AVPacket\n");
98  return 1;
99  }
100  /*test av_grow_packet*/
101  if(av_grow_packet(avpkt_clone, 20) < 0){
102  av_log(NULL, AV_LOG_ERROR, "av_grow_packet failed\n");
103  return 1;
104  }
105  if(av_grow_packet(avpkt_clone, INT_MAX) == 0){
106  printf( "av_grow_packet failed to return error "
107  "when \"grow_by\" parameter is too large.\n" );
108  ret = 1;
109  }
110  /* test size error check in av_new_packet*/
111  if(av_new_packet(avpkt_clone, INT_MAX) == 0){
112  printf( "av_new_packet failed to return error "
113  "when \"size\" parameter is too large.\n" );
114  ret = 1;
115  }
116  /*test size error check in av_packet_from_data*/
117  if(av_packet_from_data(avpkt_clone, avpkt_clone->data, INT_MAX) == 0){
118  printf("av_packet_from_data failed to return error "
119  "when \"size\" parameter is too large.\n" );
120  ret = 1;
121  }
122  /*clean up*/
123  av_packet_free(&avpkt_clone);
124  av_packet_unref(&avpkt);
125 
126 
127  return ret;
128 }
av_packet_unref
void av_packet_unref(AVPacket *pkt)
Wipe the packet.
Definition: avpacket.c:599
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_FLAG_DISCARD
#define AV_PKT_FLAG_DISCARD
Flag is used to discard packets which are required to maintain valid decoder state but are not requir...
Definition: avcodec.h:1516
av_grow_packet
int av_grow_packet(AVPacket *pkt, int grow_by)
Increase packet size, correctly zeroing padding.
Definition: avpacket.c:109
AVPacket::data
uint8_t * data
Definition: avcodec.h:1477
data
const char data[16]
Definition: mxf.c:91
AVPacket::duration
int64_t duration
Duration of this packet in AVStream->time_base units, 0 if unknown.
Definition: avcodec.h:1495
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:62
av_malloc
#define av_malloc(s)
Definition: tableprint_vlc.h:31
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:295
av_packet_side_data_name
const char * av_packet_side_data_name(enum AVPacketSideDataType type)
Definition: avpacket.c:367
AV_LOG_ERROR
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:176
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:86
NULL
#define NULL
Definition: coverity.c:32
initializations
static int initializations(AVPacket *avpkt)
Definition: avpacket.c:61
error.h
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:152
AVPacket::size
int size
Definition: avcodec.h:1478
av_err2str
#define av_err2str(errnum)
Convenience macro, the return value should be used only directly in function arguments but never stan...
Definition: error.h:119
printf
printf("static const uint8_t my_array[100] = {\n")
AVPacket::dts
int64_t dts
Decompression timestamp in AVStream->time_base units; the time at which the packet is decompressed.
Definition: avcodec.h:1476
AVPacket::flags
int flags
A combination of AV_PKT_FLAG values.
Definition: avcodec.h:1483
AVPacket::pts
int64_t pts
Presentation timestamp in AVStream->time_base units; the time at which the decompressed packet will b...
Definition: avcodec.h:1470
uint8_t
uint8_t
Definition: audio_convert.c:194
avcodec.h
ret
ret
Definition: filter_design.txt:187
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: avcodec.h:1199
main
int main(void)
Definition: avpacket.c:83
AVPacket
This structure stores compressed data.
Definition: avcodec.h:1454
AVPacket::pos
int64_t pos
byte position in stream, -1 if unknown
Definition: avcodec.h:1497
av_log
#define av_log(a,...)
Definition: tableprint_vlc.h:28
av_packet_clone
AVPacket * av_packet_clone(const AVPacket *src)
Create a new packet that references the same data as src.
Definition: avpacket.c:642
av_init_packet
void av_init_packet(AVPacket *pkt)
Initialize optional fields of a packet with default values.
Definition: avpacket.c:33
setup_side_data_entry
static int setup_side_data_entry(AVPacket *avpkt)
Definition: avpacket.c:28