int av_dup_packet(AVPacket *pkt)

AVPacket  的data 在内存中buffer有两种情况: 

1)由av_malloc申请的独立的buffer(unshared buffer); 

2)是其他AVPacket或者其他reuseable 内存的一部分(shared buffer); 

av_dup_packet, 通过调用 av_malloc、memcpy、memset等函数, 将shared buffer 的AVPacket duplicate(复制)到独立的buffer中。并且修改AVPacket的析构函数指针av_destruct_pkt。

av_dup_packet源码:

00092 int av_dup_packet(AVPacket *pkt)
00093 {
00094     if (((pkt->destruct == av_destruct_packet_nofree) || (pkt->destruct == NULL)) && pkt->data) {
00095         uint8_t *data;
00096         /* We duplicate the packet and don't forget to add the padding again. */
00097         if((unsigned)pkt->size > (unsigned)pkt->size + FF_INPUT_BUFFER_PADDING_SIZE)
00098             return AVERROR(ENOMEM);
00099         data = av_malloc(pkt->size + FF_INPUT_BUFFER_PADDING_SIZE);
00100         if (!data) {
00101             return AVERROR(ENOMEM);
00102         }
00103         memcpy(data, pkt->data, pkt->size);
00104         memset(data + pkt->size, 0, FF_INPUT_BUFFER_PADDING_SIZE);
00105         pkt->data = data;
00106         pkt->destruct = av_destruct_packet;
00107     }
00108     return 0;
00109 }

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 转载自:http://blog.csdn.net/cnbloggstar/article/details/6549230 
 


你可能感兴趣的:(int av_dup_packet(AVPacket *pkt))