FFmpeg
Loading...
Searching...
No Matches
packet_list.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 <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
31{
32 memset(pkt, 0, sizeof(*pkt));
33
34 pkt->pts = AV_NOPTS_VALUE;
35 pkt->dts = AV_NOPTS_VALUE;
36 pkt->pos = -1;
37 pkt->time_base = av_make_q(0, 1);
38}
39
40int ff_packet_list_put(PacketList *packet_buffer,
42 int (*copy)(AVPacket *dst, const AVPacket *src),
43 int flags)
44{
45 PacketListEntry *pktl = av_malloc(sizeof(*pktl));
46 unsigned int update_end_point = 1;
47 int ret;
48
49 if (!pktl)
50 return AVERROR(ENOMEM);
51
52 if (copy) {
54 ret = copy(&pktl->pkt, pkt);
55 if (ret < 0) {
56 av_free(pktl);
57 return ret;
58 }
59 } else {
61 if (ret < 0) {
62 av_free(pktl);
63 return ret;
64 }
65 av_packet_move_ref(&pktl->pkt, pkt);
66 }
67
68 pktl->next = NULL;
69
70 if (packet_buffer->head) {
72 pktl->next = packet_buffer->head;
73 packet_buffer->head = pktl;
74 update_end_point = 0;
75 } else {
76 packet_buffer->tail->next = pktl;
77 }
78 } else
79 packet_buffer->head = pktl;
80
81 if (update_end_point) {
82 /* Add the packet in the buffered packet list. */
83 packet_buffer->tail = pktl;
84 }
85
86 return 0;
87}
88
91{
92 PacketListEntry *pktl = pkt_buffer->head;
93 if (!pktl)
94 return AVERROR(EAGAIN);
95 *pkt = pktl->pkt;
96 pkt_buffer->head = pktl->next;
97 if (!pkt_buffer->head)
98 pkt_buffer->tail = NULL;
99 av_freep(&pktl);
100 return 0;
101}
102
104{
105 PacketListEntry *tmp = pkt_buf->head;
106
107 while (tmp) {
108 PacketListEntry *pktl = tmp;
109 tmp = pktl->next;
110 av_packet_unref(&pktl->pkt);
111 av_freep(&pktl);
112 }
113 pkt_buf->head = pkt_buf->tail = NULL;
114}
uint8_t ptrdiff_t const uint8_t ptrdiff_t int intptr_t intptr_t int int16_t * dst
Definition dsp.h:87
Convenience header that includes libavutil's core.
#define flags(name, subs,...)
Definition cbs_h264.c:74
#define NULL
Definition coverity.c:32
static AVPacket * pkt
error code definitions
void av_packet_unref(AVPacket *pkt)
Wipe the packet.
Definition packet.c:434
int av_packet_make_refcounted(AVPacket *pkt)
Ensure the data described by a given packet is reference counted.
Definition packet.c:497
void av_packet_move_ref(AVPacket *dst, AVPacket *src)
Move every field in src to dst and reset src.
Definition packet.c:491
#define AVERROR(e)
Definition error.h:45
static AVRational av_make_q(int num, int den)
Create an AVRational.
Definition rational.h:71
#define AV_NOPTS_VALUE
Undefined timestamp value.
Definition avutil.h:247
#define FF_PACKETLIST_FLAG_PREPEND
Prepend created AVPacketList instead of appending.
int ff_packet_list_put(PacketList *packet_buffer, AVPacket *pkt, int(*copy)(AVPacket *dst, const AVPacket *src), int flags)
Append an AVPacket to the list.
Definition packet_list.c:40
static void get_packet_defaults(AVPacket *pkt)
Definition packet_list.c:30
int ff_packet_list_get(PacketList *pkt_buffer, AVPacket *pkt)
Remove the oldest AVPacket in the list and return it.
Definition packet_list.c:89
void ff_packet_list_free(PacketList *pkt_buf)
Wipe the list and unref all the packets in it.
Memory handling functions.
#define av_malloc(s)
Definition ops_static.c:52
Utilities for rational number calculation.
This structure stores compressed data.
Definition packet.h:580
struct PacketListEntry * next
PacketListEntry * tail
PacketListEntry * head
#define av_free(p)
#define av_freep(p)
static uint8_t tmp[40]
Definition aes_ctr.c:52
#define src
Definition vp8dsp.c:248
static void copy(const float *p1, float *p2, const int length)