[Libav-user] Custom IO strange behavior.
Mohamed Moanis
mohamed_moanis at outlook.com
Sat Jun 27 18:25:24 CEST 2015
That's how I allocate the context.
if ( (avioCxt_buffer = (uint8_t *) av_malloc(4096)) == NULL) { avformat_close_input(outputFormatCxt);
fprintf(stderr, "TranscoderWrapper @%d : failed to allocate memory for buffer", __LINE__); return ERROR(ERR_OUT_MEMORY); }
if ( (avioCxt = avio_alloc_context(avioCxt_buffer, 4096, 0, &bd, read_packet, NULL, NULL)) == NULL) { av_free(avioCxt_buffer); avformat_close_input(outputFormatCxt);
fprintf(stderr, "TranscoderWrapper @%d : failed to allocate memory for context", __LINE__); return ERROR(ERR_OUT_MEMORY); }
// set the manually read data buffer to the context avioCxt->seekable = 0; (*outputFormatCxt)->pb = avioCxt;
if ( (ret = avformat_open_input(outputFormatCxt, NULL, NULL, NULL)) < 0)
then, I deallocate the context.
if (avioCxt) { av_freep(&avioCxt->buffer); av_freep(&avioCxt); }From: fxtalgorn-at-yahoo.fr at ffmpeg.org
Date: Sat, 27 Jun 2015 14:43:23 +0200
To: libav-user at ffmpeg.org
Subject: Re: [Libav-user] Custom IO strange behavior.
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.
_______________________________________________
Libav-user mailing list
Libav-user at ffmpeg.org
http://ffmpeg.org/mailman/listinfo/libav-user
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://ffmpeg.org/pipermail/libav-user/attachments/20150627/4619d73f/attachment.html>
More information about the Libav-user
mailing list