int Av_packet_ref (Avpacket *dst, const avpacket *SRC) Source analysis

Source: Internet
Author: User
Tags goto shallow copy

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;

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.