FFmpeg
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 
36  pkt->pos = -1;
37  pkt->time_base = av_make_q(0, 1);
38 }
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 {
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) {
53  get_packet_defaults(&pktl->pkt);
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 
90  AVPacket *pkt)
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 }
flags
const SwsFlags flags[]
Definition: swscale.c:85
av_packet_unref
void av_packet_unref(AVPacket *pkt)
Wipe the packet.
Definition: packet.c:434
PacketList::head
PacketListEntry * head
Definition: packet_internal.h:30
AVERROR
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFrame structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample they are references to shared objects When the negotiation mechanism computes the intersection of the formats supported at each end of a all references to both lists are replaced with a reference to the intersection And when a single format is eventually chosen for a link amongst the remaining all references to the list are updated That means that if a filter requires that its input and output have the same format amongst a supported all it has to do is use a reference to the same list of formats query_formats can leave some formats unset and return AVERROR(EAGAIN) to cause the negotiation mechanism toagain later. That can be used by filters with complex requirements to use the format negotiated on one link to set the formats supported on another. Frame references ownership and permissions
ff_packet_list_get
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
rational.h
PacketList
Definition: packet_internal.h:29
get_packet_defaults
static void get_packet_defaults(AVPacket *pkt)
Definition: packet_list.c:30
FF_PACKETLIST_FLAG_PREPEND
#define FF_PACKETLIST_FLAG_PREPEND
Prepend created AVPacketList instead of appending.
Definition: packet_internal.h:33
ff_packet_list_free
void ff_packet_list_free(PacketList *pkt_buf)
Wipe the list and unref all the packets in it.
Definition: packet_list.c:103
ff_packet_list_put
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
tmp
static uint8_t tmp[40]
Definition: aes_ctr.c:52
PacketList::tail
PacketListEntry * tail
Definition: packet_internal.h:30
NULL
#define NULL
Definition: coverity.c:32
av_packet_move_ref
void av_packet_move_ref(AVPacket *dst, AVPacket *src)
Move every field in src to dst and reset src.
Definition: packet.c:491
PacketListEntry::next
struct PacketListEntry * next
Definition: packet_internal.h:25
error.h
copy
static void copy(const float *p1, float *p2, const int length)
Definition: vf_vaguedenoiser.c:186
dst
uint8_t ptrdiff_t const uint8_t ptrdiff_t int intptr_t intptr_t int int16_t * dst
Definition: dsp.h:87
av_make_q
static AVRational av_make_q(int num, int den)
Create an AVRational.
Definition: rational.h:71
AV_NOPTS_VALUE
#define AV_NOPTS_VALUE
Undefined timestamp value.
Definition: avutil.h:247
PacketListEntry::pkt
AVPacket pkt
Definition: packet_internal.h:26
AVPacket::dts
int64_t dts
Decompression timestamp in AVStream->time_base units; the time at which the packet is decompressed.
Definition: packet.h:602
packet_internal.h
av_packet_make_refcounted
int av_packet_make_refcounted(AVPacket *pkt)
Ensure the data described by a given packet is reference counted.
Definition: packet.c:497
PacketListEntry
Definition: packet_internal.h:24
av_malloc
#define av_malloc(s)
Definition: ops_asmgen.c:44
AVPacket::pts
int64_t pts
Presentation timestamp in AVStream->time_base units; the time at which the decompressed packet will b...
Definition: packet.h:596
packet.h
ret
ret
Definition: filter_design.txt:187
avutil.h
mem.h
av_free
#define av_free(p)
Definition: tableprint_vlc.h:34
AVPacket
This structure stores compressed data.
Definition: packet.h:580
av_freep
#define av_freep(p)
Definition: tableprint_vlc.h:35
AVPacket::pos
int64_t pos
byte position in stream, -1 if unknown
Definition: packet.h:623
pkt
static AVPacket * pkt
Definition: demux_decode.c:55
src
#define src
Definition: vp8dsp.c:248
AVPacket::time_base
AVRational time_base
Time base of the packet's timestamps.
Definition: packet.h:647