Browse Source

Add av_shrink_packet function for use in av_get_packet that reduces pkt->size

and ensures the following padding is correctly initialized to 0.

Originally committed as revision 18378 to svn://svn.ffmpeg.org/ffmpeg/trunk
tags/v0.6
Reimar Döffinger 16 years ago
parent
commit
feb993e579
3 changed files with 16 additions and 1 deletions
  1. +8
    -0
      libavcodec/avcodec.h
  2. +7
    -0
      libavcodec/avpacket.c
  3. +1
    -1
      libavformat/utils.c

+ 8
- 0
libavcodec/avcodec.h View File

@@ -2654,6 +2654,14 @@ void av_init_packet(AVPacket *pkt);
*/
int av_new_packet(AVPacket *pkt, int size);

/**
* Reduce packet size, correctly zeroing padding
*
* @param pkt packet
* @param size new size
*/
void av_shrink_packet(AVPacket *pkt, int size);

/**
* @warning This is a hack - the packet memory allocation stuff is broken. The
* packet is allocated if it was not really allocated.


+ 7
- 0
libavcodec/avpacket.c View File

@@ -62,6 +62,13 @@ int av_new_packet(AVPacket *pkt, int size)
return 0;
}

void av_shrink_packet(AVPacket *pkt, int size)
{
if (pkt->size <= size) return;
pkt->size = size;
memset(pkt->data + size, 0, FF_INPUT_BUFFER_PADDING_SIZE);
}

int av_dup_packet(AVPacket *pkt)
{
if (((pkt->destruct == av_destruct_packet_nofree) || (pkt->destruct == NULL)) && pkt->data) {


+ 1
- 1
libavformat/utils.c View File

@@ -272,7 +272,7 @@ int av_get_packet(ByteIOContext *s, AVPacket *pkt, int size)
if(ret<=0)
av_free_packet(pkt);
else
pkt->size= ret;
av_shrink_packet(pkt, ret);

return ret;
}


Loading…
Cancel
Save