annotate avpacket.c @ 9357:2108342734cc libavcodec

Move av_packet_*() functions from libavformat/ to libavcodec/, where the AVPacket structure now resides also. Patch by Thilo Borgmann thilo.borgmann googlemail com, see the mailinglist thread "Google Summer of Code participation" for additional discussion.
author rbultje
date Tue, 07 Apr 2009 18:31:14 +0000
parents
children 66e270967340
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
9357
2108342734cc Move av_packet_*() functions from libavformat/ to libavcodec/, where the
rbultje
parents:
diff changeset
1 /*
2108342734cc Move av_packet_*() functions from libavformat/ to libavcodec/, where the
rbultje
parents:
diff changeset
2 * AVPacket functions for libavcodec
2108342734cc Move av_packet_*() functions from libavformat/ to libavcodec/, where the
rbultje
parents:
diff changeset
3 * Copyright (c) 2000, 2001, 2002 Fabrice Bellard
2108342734cc Move av_packet_*() functions from libavformat/ to libavcodec/, where the
rbultje
parents:
diff changeset
4 *
2108342734cc Move av_packet_*() functions from libavformat/ to libavcodec/, where the
rbultje
parents:
diff changeset
5 * This file is part of FFmpeg.
2108342734cc Move av_packet_*() functions from libavformat/ to libavcodec/, where the
rbultje
parents:
diff changeset
6 *
2108342734cc Move av_packet_*() functions from libavformat/ to libavcodec/, where the
rbultje
parents:
diff changeset
7 * FFmpeg is free software; you can redistribute it and/or
2108342734cc Move av_packet_*() functions from libavformat/ to libavcodec/, where the
rbultje
parents:
diff changeset
8 * modify it under the terms of the GNU Lesser General Public
2108342734cc Move av_packet_*() functions from libavformat/ to libavcodec/, where the
rbultje
parents:
diff changeset
9 * License as published by the Free Software Foundation; either
2108342734cc Move av_packet_*() functions from libavformat/ to libavcodec/, where the
rbultje
parents:
diff changeset
10 * version 2.1 of the License, or (at your option) any later version.
2108342734cc Move av_packet_*() functions from libavformat/ to libavcodec/, where the
rbultje
parents:
diff changeset
11 *
2108342734cc Move av_packet_*() functions from libavformat/ to libavcodec/, where the
rbultje
parents:
diff changeset
12 * FFmpeg is distributed in the hope that it will be useful,
2108342734cc Move av_packet_*() functions from libavformat/ to libavcodec/, where the
rbultje
parents:
diff changeset
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
2108342734cc Move av_packet_*() functions from libavformat/ to libavcodec/, where the
rbultje
parents:
diff changeset
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
2108342734cc Move av_packet_*() functions from libavformat/ to libavcodec/, where the
rbultje
parents:
diff changeset
15 * Lesser General Public License for more details.
2108342734cc Move av_packet_*() functions from libavformat/ to libavcodec/, where the
rbultje
parents:
diff changeset
16 *
2108342734cc Move av_packet_*() functions from libavformat/ to libavcodec/, where the
rbultje
parents:
diff changeset
17 * You should have received a copy of the GNU Lesser General Public
2108342734cc Move av_packet_*() functions from libavformat/ to libavcodec/, where the
rbultje
parents:
diff changeset
18 * License along with FFmpeg; if not, write to the Free Software
2108342734cc Move av_packet_*() functions from libavformat/ to libavcodec/, where the
rbultje
parents:
diff changeset
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
2108342734cc Move av_packet_*() functions from libavformat/ to libavcodec/, where the
rbultje
parents:
diff changeset
20 */
2108342734cc Move av_packet_*() functions from libavformat/ to libavcodec/, where the
rbultje
parents:
diff changeset
21
2108342734cc Move av_packet_*() functions from libavformat/ to libavcodec/, where the
rbultje
parents:
diff changeset
22 #include "avcodec.h"
2108342734cc Move av_packet_*() functions from libavformat/ to libavcodec/, where the
rbultje
parents:
diff changeset
23
2108342734cc Move av_packet_*() functions from libavformat/ to libavcodec/, where the
rbultje
parents:
diff changeset
24
2108342734cc Move av_packet_*() functions from libavformat/ to libavcodec/, where the
rbultje
parents:
diff changeset
25 void av_destruct_packet_nofree(AVPacket *pkt)
2108342734cc Move av_packet_*() functions from libavformat/ to libavcodec/, where the
rbultje
parents:
diff changeset
26 {
2108342734cc Move av_packet_*() functions from libavformat/ to libavcodec/, where the
rbultje
parents:
diff changeset
27 pkt->data = NULL; pkt->size = 0;
2108342734cc Move av_packet_*() functions from libavformat/ to libavcodec/, where the
rbultje
parents:
diff changeset
28 }
2108342734cc Move av_packet_*() functions from libavformat/ to libavcodec/, where the
rbultje
parents:
diff changeset
29
2108342734cc Move av_packet_*() functions from libavformat/ to libavcodec/, where the
rbultje
parents:
diff changeset
30 void av_destruct_packet(AVPacket *pkt)
2108342734cc Move av_packet_*() functions from libavformat/ to libavcodec/, where the
rbultje
parents:
diff changeset
31 {
2108342734cc Move av_packet_*() functions from libavformat/ to libavcodec/, where the
rbultje
parents:
diff changeset
32 av_free(pkt->data);
2108342734cc Move av_packet_*() functions from libavformat/ to libavcodec/, where the
rbultje
parents:
diff changeset
33 pkt->data = NULL; pkt->size = 0;
2108342734cc Move av_packet_*() functions from libavformat/ to libavcodec/, where the
rbultje
parents:
diff changeset
34 }
2108342734cc Move av_packet_*() functions from libavformat/ to libavcodec/, where the
rbultje
parents:
diff changeset
35
2108342734cc Move av_packet_*() functions from libavformat/ to libavcodec/, where the
rbultje
parents:
diff changeset
36 void av_init_packet(AVPacket *pkt)
2108342734cc Move av_packet_*() functions from libavformat/ to libavcodec/, where the
rbultje
parents:
diff changeset
37 {
2108342734cc Move av_packet_*() functions from libavformat/ to libavcodec/, where the
rbultje
parents:
diff changeset
38 pkt->pts = AV_NOPTS_VALUE;
2108342734cc Move av_packet_*() functions from libavformat/ to libavcodec/, where the
rbultje
parents:
diff changeset
39 pkt->dts = AV_NOPTS_VALUE;
2108342734cc Move av_packet_*() functions from libavformat/ to libavcodec/, where the
rbultje
parents:
diff changeset
40 pkt->pos = -1;
2108342734cc Move av_packet_*() functions from libavformat/ to libavcodec/, where the
rbultje
parents:
diff changeset
41 pkt->duration = 0;
2108342734cc Move av_packet_*() functions from libavformat/ to libavcodec/, where the
rbultje
parents:
diff changeset
42 pkt->convergence_duration = 0;
2108342734cc Move av_packet_*() functions from libavformat/ to libavcodec/, where the
rbultje
parents:
diff changeset
43 pkt->flags = 0;
2108342734cc Move av_packet_*() functions from libavformat/ to libavcodec/, where the
rbultje
parents:
diff changeset
44 pkt->stream_index = 0;
2108342734cc Move av_packet_*() functions from libavformat/ to libavcodec/, where the
rbultje
parents:
diff changeset
45 pkt->destruct= av_destruct_packet_nofree;
2108342734cc Move av_packet_*() functions from libavformat/ to libavcodec/, where the
rbultje
parents:
diff changeset
46 }
2108342734cc Move av_packet_*() functions from libavformat/ to libavcodec/, where the
rbultje
parents:
diff changeset
47
2108342734cc Move av_packet_*() functions from libavformat/ to libavcodec/, where the
rbultje
parents:
diff changeset
48 int av_new_packet(AVPacket *pkt, int size)
2108342734cc Move av_packet_*() functions from libavformat/ to libavcodec/, where the
rbultje
parents:
diff changeset
49 {
2108342734cc Move av_packet_*() functions from libavformat/ to libavcodec/, where the
rbultje
parents:
diff changeset
50 uint8_t *data;
2108342734cc Move av_packet_*() functions from libavformat/ to libavcodec/, where the
rbultje
parents:
diff changeset
51 if((unsigned)size > (unsigned)size + FF_INPUT_BUFFER_PADDING_SIZE)
2108342734cc Move av_packet_*() functions from libavformat/ to libavcodec/, where the
rbultje
parents:
diff changeset
52 return AVERROR(ENOMEM);
2108342734cc Move av_packet_*() functions from libavformat/ to libavcodec/, where the
rbultje
parents:
diff changeset
53 data = av_malloc(size + FF_INPUT_BUFFER_PADDING_SIZE);
2108342734cc Move av_packet_*() functions from libavformat/ to libavcodec/, where the
rbultje
parents:
diff changeset
54 if (!data)
2108342734cc Move av_packet_*() functions from libavformat/ to libavcodec/, where the
rbultje
parents:
diff changeset
55 return AVERROR(ENOMEM);
2108342734cc Move av_packet_*() functions from libavformat/ to libavcodec/, where the
rbultje
parents:
diff changeset
56 memset(data + size, 0, FF_INPUT_BUFFER_PADDING_SIZE);
2108342734cc Move av_packet_*() functions from libavformat/ to libavcodec/, where the
rbultje
parents:
diff changeset
57
2108342734cc Move av_packet_*() functions from libavformat/ to libavcodec/, where the
rbultje
parents:
diff changeset
58 av_init_packet(pkt);
2108342734cc Move av_packet_*() functions from libavformat/ to libavcodec/, where the
rbultje
parents:
diff changeset
59 pkt->data = data;
2108342734cc Move av_packet_*() functions from libavformat/ to libavcodec/, where the
rbultje
parents:
diff changeset
60 pkt->size = size;
2108342734cc Move av_packet_*() functions from libavformat/ to libavcodec/, where the
rbultje
parents:
diff changeset
61 pkt->destruct = av_destruct_packet;
2108342734cc Move av_packet_*() functions from libavformat/ to libavcodec/, where the
rbultje
parents:
diff changeset
62 return 0;
2108342734cc Move av_packet_*() functions from libavformat/ to libavcodec/, where the
rbultje
parents:
diff changeset
63 }
2108342734cc Move av_packet_*() functions from libavformat/ to libavcodec/, where the
rbultje
parents:
diff changeset
64
2108342734cc Move av_packet_*() functions from libavformat/ to libavcodec/, where the
rbultje
parents:
diff changeset
65 int av_dup_packet(AVPacket *pkt)
2108342734cc Move av_packet_*() functions from libavformat/ to libavcodec/, where the
rbultje
parents:
diff changeset
66 {
2108342734cc Move av_packet_*() functions from libavformat/ to libavcodec/, where the
rbultje
parents:
diff changeset
67 if (((pkt->destruct == av_destruct_packet_nofree) || (pkt->destruct == NULL)) && pkt->data) {
2108342734cc Move av_packet_*() functions from libavformat/ to libavcodec/, where the
rbultje
parents:
diff changeset
68 uint8_t *data;
2108342734cc Move av_packet_*() functions from libavformat/ to libavcodec/, where the
rbultje
parents:
diff changeset
69 /* We duplicate the packet and don't forget to add the padding again. */
2108342734cc Move av_packet_*() functions from libavformat/ to libavcodec/, where the
rbultje
parents:
diff changeset
70 if((unsigned)pkt->size > (unsigned)pkt->size + FF_INPUT_BUFFER_PADDING_SIZE)
2108342734cc Move av_packet_*() functions from libavformat/ to libavcodec/, where the
rbultje
parents:
diff changeset
71 return AVERROR(ENOMEM);
2108342734cc Move av_packet_*() functions from libavformat/ to libavcodec/, where the
rbultje
parents:
diff changeset
72 data = av_malloc(pkt->size + FF_INPUT_BUFFER_PADDING_SIZE);
2108342734cc Move av_packet_*() functions from libavformat/ to libavcodec/, where the
rbultje
parents:
diff changeset
73 if (!data) {
2108342734cc Move av_packet_*() functions from libavformat/ to libavcodec/, where the
rbultje
parents:
diff changeset
74 return AVERROR(ENOMEM);
2108342734cc Move av_packet_*() functions from libavformat/ to libavcodec/, where the
rbultje
parents:
diff changeset
75 }
2108342734cc Move av_packet_*() functions from libavformat/ to libavcodec/, where the
rbultje
parents:
diff changeset
76 memcpy(data, pkt->data, pkt->size);
2108342734cc Move av_packet_*() functions from libavformat/ to libavcodec/, where the
rbultje
parents:
diff changeset
77 memset(data + pkt->size, 0, FF_INPUT_BUFFER_PADDING_SIZE);
2108342734cc Move av_packet_*() functions from libavformat/ to libavcodec/, where the
rbultje
parents:
diff changeset
78 pkt->data = data;
2108342734cc Move av_packet_*() functions from libavformat/ to libavcodec/, where the
rbultje
parents:
diff changeset
79 pkt->destruct = av_destruct_packet;
2108342734cc Move av_packet_*() functions from libavformat/ to libavcodec/, where the
rbultje
parents:
diff changeset
80 }
2108342734cc Move av_packet_*() functions from libavformat/ to libavcodec/, where the
rbultje
parents:
diff changeset
81 return 0;
2108342734cc Move av_packet_*() functions from libavformat/ to libavcodec/, where the
rbultje
parents:
diff changeset
82 }