Transfer from http://blog.csdn.net/fernandowei/article/details/50492815
In the front, literally speaking, this function is just to produce a avpacket reference (reference);
Personally, this function can help you to a certain extent, I understand the meaning of each parameter of avpacket structure;
int Av_packet_ref (Avpacket *dst, const avpacket *SRC)
{
int ret;
ret = av_packet_copy_props (DST, SRC); This function only makes some numerical copies (pts DTS stream_index, etc.) as well as deep copies of the Side_data;
if (Ret < 0)
return ret;
if (!SRC->BUF)//The if-else here is the key part; This means that if the source packet (that is, SRC) itself is not a ref, then it is equivalent to the first ref to be generated;
It can also be known whether the BUF member inside the avpacket is null, indicating whether the packet is a ref
{
ret = Packet_alloc (&dst->buf, src->size);
if (Ret < 0)
Goto fail;
memcpy (Dst->buf->data, Src->data, src->size); The end result is that this newly generated source packet ref (that is, DST),
It stores data in Dst->buf->data, size is dst->buf->size, and src->size
}
else//If the source packet (that is, SRC) itself is a ref of some packet, then it is very simple, just shallow copy the pointer,
Of course, one has to apply for a AVBUFFERREF structure of memory space
{
Dst->buf = Av_buffer_ref (SRC->BUF);
if (!DST->BUF) {
ret = Averror (ENOMEM);
Goto fail;
}
}
Dst->size = src->size;
Dst->data = dst->buf->data; As you can see from this sentence, in a packet ref packet, the data pointer is the same as the Buf->data pointer
return 0;
Fail
Av_packet_free_side_data (DST);
return ret;
}
From this function can also be seen, if a packet has more than one ref, then this packet data actually has two storage location, one is this packet own data pointer point, and the other is this packet all other ref
Buf->data pointer, and when there are multiple ref, the Buf->data data part is not writable, only read;