Coverage Report

Created: 2026-07-15 07:31

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/ffmpeg/libavformat/packet_list.c
Line
Count
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
static void get_packet_defaults(AVPacket *pkt)
31
0
{
32
0
    memset(pkt, 0, sizeof(*pkt));
33
34
0
    pkt->pts             = AV_NOPTS_VALUE;
35
0
    pkt->dts             = AV_NOPTS_VALUE;
36
0
    pkt->pos             = -1;
37
0
    pkt->time_base       = av_make_q(0, 1);
38
0
}
39
40
int ff_packet_list_put(PacketList *packet_buffer,
41
                       AVPacket      *pkt,
42
                       int (*copy)(AVPacket *dst, const AVPacket *src),
43
                       int flags)
44
0
{
45
0
    PacketListEntry *pktl = av_malloc(sizeof(*pktl));
46
0
    unsigned int update_end_point = 1;
47
0
    int ret;
48
49
0
    if (!pktl)
50
0
        return AVERROR(ENOMEM);
51
52
0
    if (copy) {
53
0
        get_packet_defaults(&pktl->pkt);
54
0
        ret = copy(&pktl->pkt, pkt);
55
0
        if (ret < 0) {
56
0
            av_free(pktl);
57
0
            return ret;
58
0
        }
59
0
    } else {
60
0
        ret = av_packet_make_refcounted(pkt);
61
0
        if (ret < 0) {
62
0
            av_free(pktl);
63
0
            return ret;
64
0
        }
65
0
        av_packet_move_ref(&pktl->pkt, pkt);
66
0
    }
67
68
0
    pktl->next = NULL;
69
70
0
    if (packet_buffer->head) {
71
0
        if (flags & FF_PACKETLIST_FLAG_PREPEND) {
72
0
            pktl->next = packet_buffer->head;
73
0
            packet_buffer->head = pktl;
74
0
            update_end_point = 0;
75
0
        } else {
76
0
            packet_buffer->tail->next = pktl;
77
0
        }
78
0
    } else
79
0
        packet_buffer->head = pktl;
80
81
0
    if (update_end_point) {
82
        /* Add the packet in the buffered packet list. */
83
0
        packet_buffer->tail = pktl;
84
0
    }
85
86
0
    return 0;
87
0
}
88
89
int ff_packet_list_get(PacketList *pkt_buffer,
90
                       AVPacket      *pkt)
91
0
{
92
0
    PacketListEntry *pktl = pkt_buffer->head;
93
0
    if (!pktl)
94
0
        return AVERROR(EAGAIN);
95
0
    *pkt        = pktl->pkt;
96
0
    pkt_buffer->head = pktl->next;
97
0
    if (!pkt_buffer->head)
98
0
        pkt_buffer->tail = NULL;
99
0
    av_freep(&pktl);
100
0
    return 0;
101
0
}
102
103
void ff_packet_list_free(PacketList *pkt_buf)
104
1.57k
{
105
1.57k
    PacketListEntry *tmp = pkt_buf->head;
106
107
1.57k
    while (tmp) {
108
0
        PacketListEntry *pktl = tmp;
109
0
        tmp = pktl->next;
110
0
        av_packet_unref(&pktl->pkt);
111
0
        av_freep(&pktl);
112
0
    }
113
    pkt_buf->head = pkt_buf->tail = NULL;
114
1.57k
}