FFmpeg coverage


Directory: ../../../ffmpeg/
File: src/libavformat/packet_list.c
Date: 2026-09-13 11:21:06
Exec Total Coverage
Lines: 48 53 90.6%
Functions: 4 4 100.0%
Branches: 17 20 85.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 <string.h>
20
21 #include "libavutil/avutil.h"
22 #include "libavutil/error.h"
23 #include "libavutil/mem.h"
24 #include "libavutil/rational.h"
25
26 #include "libavcodec/packet.h"
27
28 #include "packet_internal.h"
29
30 133 static void get_packet_defaults(AVPacket *pkt)
31 {
32 133 memset(pkt, 0, sizeof(*pkt));
33
34 133 pkt->pts = AV_NOPTS_VALUE;
35 133 pkt->dts = AV_NOPTS_VALUE;
36 133 pkt->pos = -1;
37 133 pkt->time_base = av_make_q(0, 1);
38 133 }
39
40 496011 int ff_packet_list_put(PacketList *packet_buffer,
41 AVPacket *pkt,
42 int (*copy)(AVPacket *dst, const AVPacket *src),
43 int flags)
44 {
45 496011 PacketListEntry *pktl = av_malloc(sizeof(*pktl));
46 496011 unsigned int update_end_point = 1;
47 int ret;
48
49
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 496011 times.
496011 if (!pktl)
50 return AVERROR(ENOMEM);
51
52
2/2
✓ Branch 0 taken 133 times.
✓ Branch 1 taken 495878 times.
496011 if (copy) {
53 133 get_packet_defaults(&pktl->pkt);
54 133 ret = copy(&pktl->pkt, pkt);
55
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 133 times.
133 if (ret < 0) {
56 av_free(pktl);
57 return ret;
58 }
59 } else {
60 495878 ret = av_packet_make_refcounted(pkt);
61
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 495878 times.
495878 if (ret < 0) {
62 av_free(pktl);
63 return ret;
64 }
65 495878 av_packet_move_ref(&pktl->pkt, pkt);
66 }
67
68 496011 pktl->next = NULL;
69
70
2/2
✓ Branch 0 taken 310112 times.
✓ Branch 1 taken 185899 times.
496011 if (packet_buffer->head) {
71
2/2
✓ Branch 0 taken 20 times.
✓ Branch 1 taken 310092 times.
310112 if (flags & FF_PACKETLIST_FLAG_PREPEND) {
72 20 pktl->next = packet_buffer->head;
73 20 packet_buffer->head = pktl;
74 20 update_end_point = 0;
75 } else {
76 310092 packet_buffer->tail->next = pktl;
77 }
78 } else
79 185899 packet_buffer->head = pktl;
80
81
2/2
✓ Branch 0 taken 495991 times.
✓ Branch 1 taken 20 times.
496011 if (update_end_point) {
82 /* Add the packet in the buffered packet list. */
83 495991 packet_buffer->tail = pktl;
84 }
85
86 496011 return 0;
87 }
88
89 443064 int ff_packet_list_get(PacketList *pkt_buffer,
90 AVPacket *pkt)
91 {
92 443064 PacketListEntry *pktl = pkt_buffer->head;
93
2/2
✓ Branch 0 taken 54 times.
✓ Branch 1 taken 443010 times.
443064 if (!pktl)
94 54 return AVERROR(EAGAIN);
95 443010 *pkt = pktl->pkt;
96 443010 pkt_buffer->head = pktl->next;
97
2/2
✓ Branch 0 taken 181684 times.
✓ Branch 1 taken 261326 times.
443010 if (!pkt_buffer->head)
98 181684 pkt_buffer->tail = NULL;
99 443010 av_freep(&pktl);
100 443010 return 0;
101 }
102
103 58741 void ff_packet_list_free(PacketList *pkt_buf)
104 {
105 58741 PacketListEntry *tmp = pkt_buf->head;
106
107
2/2
✓ Branch 0 taken 83162 times.
✓ Branch 1 taken 58741 times.
141903 while (tmp) {
108 83162 PacketListEntry *pktl = tmp;
109 83162 tmp = pktl->next;
110 83162 av_packet_unref(&pktl->pkt);
111 83162 av_freep(&pktl);
112 }
113 58741 pkt_buf->head = pkt_buf->tail = NULL;
114 58741 }
115