[Libav-user] Custom IO strange behavior.
Talgorn François-Xavier
fxtalgorn at yahoo.fr
Sat Jun 27 14:43:23 CEST 2015
Hi,
It would help if we could see how you allocate the AVIOContext, and your main loop.
Le 27 juin 2015 à 11:33, Mohamed Moanis <mohamed_moanis at outlook.com> a écrit :
> I am implementing a custom IO to read data packets then transcode them.
> The problem I have is memory leakage, which I guess is coming from the custom IO buffer I allocate to read the data.
> I am referring to the avio example. I have exactly the same callback function.
> struct buffer_data {
> uint8_t *ptr;
> size_t size; ///< size left in the buffer
> };
> static int read_packet(void *opaque, uint8_t *buf, int buf_size)
> {
> struct buffer_data *bd = (struct buffer_data *)opaque;
> buf_size = FFMIN(buf_size, bd->size);
> printf("ptr:%p size:%zu\n", bd->ptr, bd->size);
> /* copy internal buffer data to buf */
> memcpy(buf, bd->ptr, buf_size);
> bd->ptr += buf_size;
> bd->size -= buf_size;
> return buf_size;
> }
>
> When I debug my code, the function is called even after the data was all read. It is called more than a time with the buffer size is zero and later on the ptr itself is null. My question here is why does that happen?
>
> The second question, is how to free the buffer allocated. In my application I require reading a JPEG frame from a camera that is considerable in size. What I do, is that I free the AVIOContext and it's buffer just after I call avformat_open_input. But I can see the memory usage increasing by an estimate of the frame size each run.
>
> Regards.
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://ffmpeg.org/pipermail/libav-user/attachments/20150627/4d955286/attachment.html>
More information about the Libav-user
mailing list