FFmpeg
Loading...
Searching...
No Matches
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#include "libavutil/mem.h"
26
27
28
30{
31 const uint8_t *data_name = NULL;
32 int ret = 0, bytes;
33 uint8_t *extra_data = NULL;
34
35
36 /* get side_data_name string */
38
39 /* Allocate a memory bloc */
40 bytes = strlen(data_name);
41
42 if(!(extra_data = av_malloc(bytes))){
43 ret = AVERROR(ENOMEM);
44 fprintf(stderr, "Error occurred: %s\n", av_err2str(ret));
45 exit(1);
46 }
47 /* copy side_data_name to extra_data array */
48 memcpy(extra_data, data_name, bytes);
49
50 /* create side data for AVPacket */
52 extra_data, bytes);
53 if(ret < 0){
54 av_free(extra_data);
55 fprintf(stderr,
56 "Error occurred in av_packet_add_side_data: %s\n",
57 av_err2str(ret));
58 }
59
60 return ret;
61}
62
63static int initializations(AVPacket* avpkt)
64{
65 const static uint8_t* data = "selftest for av_packet_clone(...)";
66 int ret = 0;
67
68 /* set values for avpkt */
69 avpkt->pts = 17;
70 avpkt->dts = 2;
71 avpkt->data = (uint8_t*)data;
72 avpkt->size = strlen(data);
74 avpkt->duration = 100;
75 avpkt->pos = 3;
76
77 ret = setup_side_data_entry(avpkt);
78
79 return ret;
80}
81
82int main(void)
83{
84 AVPacket *avpkt = NULL;
85 AVPacket *avpkt_clone = NULL;
86 int ret = 0;
87
88 /* test av_packet_alloc */
89 avpkt = av_packet_alloc();
90 if(!avpkt) {
91 av_log(NULL, AV_LOG_ERROR, "av_packet_alloc failed to allocate AVPacket\n");
92 return 1;
93 }
94
95 if (initializations(avpkt) < 0) {
96 printf("failed to initialize variables\n");
97 av_packet_free(&avpkt);
98 return 1;
99 }
100 /* test av_packet_clone*/
101 avpkt_clone = av_packet_clone(avpkt);
102
103 if(!avpkt_clone) {
104 av_log(NULL, AV_LOG_ERROR,"av_packet_clone failed to clone AVPacket\n");
105 av_packet_free(&avpkt);
106 return 1;
107 }
108 /*test av_grow_packet*/
109 if(av_grow_packet(avpkt_clone, 20) < 0){
110 av_log(NULL, AV_LOG_ERROR, "av_grow_packet failed\n");
111 av_packet_free(&avpkt_clone);
112 av_packet_free(&avpkt);
113 return 1;
114 }
115 if(av_grow_packet(avpkt_clone, INT_MAX) == 0){
116 printf( "av_grow_packet failed to return error "
117 "when \"grow_by\" parameter is too large.\n" );
118 ret = 1;
119 }
120 /* test size error check in av_new_packet*/
121 if(av_new_packet(avpkt_clone, INT_MAX) == 0){
122 printf( "av_new_packet failed to return error "
123 "when \"size\" parameter is too large.\n" );
124 ret = 1;
125 }
126 /*test size error check in av_packet_from_data*/
127 if(av_packet_from_data(avpkt_clone, avpkt_clone->data, INT_MAX) == 0){
128 printf("av_packet_from_data failed to return error "
129 "when \"size\" parameter is too large.\n" );
130 ret = 1;
131 }
132 /*clean up*/
133 av_packet_free(&avpkt_clone);
134 av_packet_free(&avpkt);
135
136
137 return ret;
138}
Libavcodec external API header.
int main(void)
Definition avpacket.c:82
static int initializations(AVPacket *avpkt)
Definition avpacket.c:63
static int setup_side_data_entry(AVPacket *avpkt)
Definition avpacket.c:29
#define NULL
Definition coverity.c:32
__device__ int printf(const char *,...)
error code definitions
const char * av_packet_side_data_name(enum AVPacketSideDataType type)
Definition packet.c:269
@ 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:56
void av_packet_free(AVPacket **pkt)
Free the packet, if the packet is reference counted, it will be unreferenced first.
Definition packet.c:74
#define AV_PKT_FLAG_DISCARD
Flag is used to discard packets which are required to maintain valid decoder state but are not requir...
Definition packet.h:657
int av_grow_packet(AVPacket *pkt, int grow_by)
Increase packet size, correctly zeroing padding.
Definition packet.c:121
int av_packet_from_data(AVPacket *pkt, uint8_t *data, int size)
Initialize a reference-counted packet from av_malloc()ed data.
Definition packet.c:172
AVPacket * av_packet_clone(const AVPacket *src)
Create a new packet that references the same data as src.
Definition packet.c:478
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 packet.c:197
AVPacket * av_packet_alloc(void)
Allocate an AVPacket and set its fields to default values.
Definition packet.c:63
int av_new_packet(AVPacket *pkt, int size)
Allocate the payload of a packet and initialize its fields with default values.
Definition packet.c:98
#define av_err2str(errnum)
Convenience macro, the return value should be used only directly in function arguments but never stan...
Definition error.h:122
#define AVERROR(e)
Definition error.h:45
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition log.h:210
Memory handling functions.
const char data[16]
Definition mxf.c:149
#define av_malloc(s)
Definition ops_static.c:52
This structure stores compressed data.
Definition packet.h:580
int flags
A combination of AV_PKT_FLAG values.
Definition packet.h:609
int size
Definition packet.h:604
int64_t duration
Duration of this packet in AVStream->time_base units, 0 if unknown.
Definition packet.h:621
int64_t pts
Presentation timestamp in AVStream->time_base units; the time at which the decompressed packet will b...
Definition packet.h:596
int64_t dts
Decompression timestamp in AVStream->time_base units; the time at which the packet is decompressed.
Definition packet.h:602
uint8_t * data
Definition packet.h:603
int64_t pos
byte position in stream, -1 if unknown
Definition packet.h:623
#define av_free(p)
#define av_log(a,...)