• Main Page
  • Related Pages
  • Modules
  • Data Structures
  • Files
  • File List
  • Globals

libavcodec/avpacket.c

Go to the documentation of this file.
00001 /*
00002  * AVPacket functions for libavcodec
00003  * Copyright (c) 2000, 2001, 2002 Fabrice Bellard
00004  *
00005  * This file is part of FFmpeg.
00006  *
00007  * FFmpeg is free software; you can redistribute it and/or
00008  * modify it under the terms of the GNU Lesser General Public
00009  * License as published by the Free Software Foundation; either
00010  * version 2.1 of the License, or (at your option) any later version.
00011  *
00012  * FFmpeg is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00015  * Lesser General Public License for more details.
00016  *
00017  * You should have received a copy of the GNU Lesser General Public
00018  * License along with FFmpeg; if not, write to the Free Software
00019  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
00020  */
00021 
00022 #include "avcodec.h"
00023 
00024 
00025 void av_destruct_packet_nofree(AVPacket *pkt)
00026 {
00027     pkt->data = NULL; pkt->size = 0;
00028 }
00029 
00030 void av_destruct_packet(AVPacket *pkt)
00031 {
00032     av_free(pkt->data);
00033     pkt->data = NULL; pkt->size = 0;
00034 }
00035 
00036 void av_init_packet(AVPacket *pkt)
00037 {
00038     pkt->pts   = AV_NOPTS_VALUE;
00039     pkt->dts   = AV_NOPTS_VALUE;
00040     pkt->pos   = -1;
00041     pkt->duration = 0;
00042     pkt->convergence_duration = 0;
00043     pkt->flags = 0;
00044     pkt->stream_index = 0;
00045     pkt->destruct= NULL;
00046 }
00047 
00048 int av_new_packet(AVPacket *pkt, int size)
00049 {
00050     uint8_t *data= NULL;
00051     if((unsigned)size < (unsigned)size + FF_INPUT_BUFFER_PADDING_SIZE)
00052         data = av_malloc(size + FF_INPUT_BUFFER_PADDING_SIZE);
00053     if (data){
00054         memset(data + size, 0, FF_INPUT_BUFFER_PADDING_SIZE);
00055     }else
00056         size=0;
00057 
00058     av_init_packet(pkt);
00059     pkt->data = data;
00060     pkt->size = size;
00061     pkt->destruct = av_destruct_packet;
00062     if(!data)
00063         return AVERROR(ENOMEM);
00064     return 0;
00065 }
00066 
00067 void av_shrink_packet(AVPacket *pkt, int size)
00068 {
00069     if (pkt->size <= size) return;
00070     pkt->size = size;
00071     memset(pkt->data + size, 0, FF_INPUT_BUFFER_PADDING_SIZE);
00072 }
00073 
00074 int av_dup_packet(AVPacket *pkt)
00075 {
00076     if (((pkt->destruct == av_destruct_packet_nofree) || (pkt->destruct == NULL)) && pkt->data) {
00077         uint8_t *data;
00078         /* We duplicate the packet and don't forget to add the padding again. */
00079         if((unsigned)pkt->size > (unsigned)pkt->size + FF_INPUT_BUFFER_PADDING_SIZE)
00080             return AVERROR(ENOMEM);
00081         data = av_malloc(pkt->size + FF_INPUT_BUFFER_PADDING_SIZE);
00082         if (!data) {
00083             return AVERROR(ENOMEM);
00084         }
00085         memcpy(data, pkt->data, pkt->size);
00086         memset(data + pkt->size, 0, FF_INPUT_BUFFER_PADDING_SIZE);
00087         pkt->data = data;
00088         pkt->destruct = av_destruct_packet;
00089     }
00090     return 0;
00091 }
00092 
00093 void av_free_packet(AVPacket *pkt)
00094 {
00095     if (pkt) {
00096         if (pkt->destruct) pkt->destruct(pkt);
00097         pkt->data = NULL; pkt->size = 0;
00098     }
00099 }

Generated on Fri Sep 16 2011 17:17:34 for FFmpeg by  doxygen 1.7.1