FFmpeg coverage


Directory: ../../../ffmpeg/
File: src/libavformat/packet_list.c
Date: 2026-09-17 00:46:02
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 496189 int ff_packet_list_put(PacketList *packet_buffer,
41 AVPacket *pkt,
42 int (*copy)(AVPacket *dst, const AVPacket *src),
43 int flags)
44 {
45 496189 PacketListEntry *pktl = av_malloc(sizeof(*pktl));
46 496189 unsigned int update_end_point = 1;
47 int ret;
48
49
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 496189 times.
496189 if (!pktl)
50 return AVERROR(ENOMEM);
51
52
2/2
✓ Branch 0 taken 133 times.
✓ Branch 1 taken 496056 times.
496189 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 496056 ret = av_packet_make_refcounted(pkt);
61
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 496056 times.
496056 if (ret < 0) {
62 av_free(pktl);
63 return ret;
64 }
65 496056 av_packet_move_ref(&pktl->pkt, pkt);
66 }
67
68 496189 pktl->next = NULL;
69
70
2/2
✓ Branch 0 taken 310115 times.
✓ Branch 1 taken 186074 times.
496189 if (packet_buffer->head) {
71
2/2
✓ Branch 0 taken 20 times.
✓ Branch 1 taken 310095 times.
310115 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 310095 packet_buffer->tail->next = pktl;
77 }
78 } else
79 186074 packet_buffer->head = pktl;
80
81
2/2
✓ Branch 0 taken 496169 times.
✓ Branch 1 taken 20 times.
496189 if (update_end_point) {
82 /* Add the packet in the buffered packet list. */
83 496169 packet_buffer->tail = pktl;
84 }
85
86 496189 return 0;
87 }
88
89 443325 int ff_packet_list_get(PacketList *pkt_buffer,
90 AVPacket *pkt)
91 {
92 443325 PacketListEntry *pktl = pkt_buffer->head;
93
2/2
✓ Branch 0 taken 54 times.
✓ Branch 1 taken 443271 times.
443325 if (!pktl)
94 54 return AVERROR(EAGAIN);
95 443271 *pkt = pktl->pkt;
96 443271 pkt_buffer->head = pktl->next;
97
2/2
✓ Branch 0 taken 181860 times.
✓ Branch 1 taken 261411 times.
443271 if (!pkt_buffer->head)
98 181860 pkt_buffer->tail = NULL;
99 443271 av_freep(&pktl);
100 443271 return 0;
101 }
102
103 58760 void ff_packet_list_free(PacketList *pkt_buf)
104 {
105 58760 PacketListEntry *tmp = pkt_buf->head;
106
107
2/2
✓ Branch 0 taken 83079 times.
✓ Branch 1 taken 58760 times.
141839 while (tmp) {
108 83079 PacketListEntry *pktl = tmp;
109 83079 tmp = pktl->next;
110 83079 av_packet_unref(&pktl->pkt);
111 83079 av_freep(&pktl);
112 }
113 58760 pkt_buf->head = pkt_buf->tail = NULL;
114 58760 }
115