FFmpeg coverage


Directory: ../../../ffmpeg/
File: src/libavcodec/tests/avpacket.c
Date: 2024-12-12 01:08:13
Exec Total Coverage
Lines: 38 58 65.5%
Functions: 3 3 100.0%
Branches: 9 18 50.0%

Line Branch Exec Source
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
29 1 static int setup_side_data_entry(AVPacket* avpkt)
30 {
31 1 const uint8_t *data_name = NULL;
32 1 int ret = 0, bytes;
33 1 uint8_t *extra_data = NULL;
34
35
36 /* get side_data_name string */
37 1 data_name = av_packet_side_data_name(AV_PKT_DATA_NEW_EXTRADATA);
38
39 /* Allocate a memory bloc */
40 1 bytes = strlen(data_name);
41
42
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 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 1 memcpy(extra_data, data_name, bytes);
49
50 /* create side data for AVPacket */
51 1 ret = av_packet_add_side_data(avpkt, AV_PKT_DATA_NEW_EXTRADATA,
52 extra_data, bytes);
53
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 if(ret < 0){
54 fprintf(stderr,
55 "Error occurred in av_packet_add_side_data: %s\n",
56 av_err2str(ret));
57 }
58
59 1 return ret;
60 }
61
62 1 static int initializations(AVPacket* avpkt)
63 {
64 const static uint8_t* data = "selftest for av_packet_clone(...)";
65 1 int ret = 0;
66
67 /* set values for avpkt */
68 1 avpkt->pts = 17;
69 1 avpkt->dts = 2;
70 1 avpkt->data = (uint8_t*)data;
71 1 avpkt->size = strlen(data);
72 1 avpkt->flags = AV_PKT_FLAG_DISCARD;
73 1 avpkt->duration = 100;
74 1 avpkt->pos = 3;
75
76 1 ret = setup_side_data_entry(avpkt);
77
78 1 return ret;
79 }
80
81 1 int main(void)
82 {
83 1 AVPacket *avpkt = NULL;
84 1 AVPacket *avpkt_clone = NULL;
85 1 int ret = 0;
86
87 /* test av_packet_alloc */
88 1 avpkt = av_packet_alloc();
89
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 if(!avpkt) {
90 av_log(NULL, AV_LOG_ERROR, "av_packet_alloc failed to allcoate AVPacket\n");
91 return 1;
92 }
93
94
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 if (initializations(avpkt) < 0) {
95 printf("failed to initialize variables\n");
96 av_packet_free(&avpkt);
97 return 1;
98 }
99 /* test av_packet_clone*/
100 1 avpkt_clone = av_packet_clone(avpkt);
101
102
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 if(!avpkt_clone) {
103 av_log(NULL, AV_LOG_ERROR,"av_packet_clone failed to clone AVPacket\n");
104 return 1;
105 }
106 /*test av_grow_packet*/
107
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 if(av_grow_packet(avpkt_clone, 20) < 0){
108 av_log(NULL, AV_LOG_ERROR, "av_grow_packet failed\n");
109 return 1;
110 }
111
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 if(av_grow_packet(avpkt_clone, INT_MAX) == 0){
112 printf( "av_grow_packet failed to return error "
113 "when \"grow_by\" parameter is too large.\n" );
114 ret = 1;
115 }
116 /* test size error check in av_new_packet*/
117
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 if(av_new_packet(avpkt_clone, INT_MAX) == 0){
118 printf( "av_new_packet failed to return error "
119 "when \"size\" parameter is too large.\n" );
120 ret = 1;
121 }
122 /*test size error check in av_packet_from_data*/
123
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 if(av_packet_from_data(avpkt_clone, avpkt_clone->data, INT_MAX) == 0){
124 printf("av_packet_from_data failed to return error "
125 "when \"size\" parameter is too large.\n" );
126 ret = 1;
127 }
128 /*clean up*/
129 1 av_packet_free(&avpkt_clone);
130 1 av_packet_free(&avpkt);
131
132
133 1 return ret;
134 }
135