[FFmpeg-devel] [PATCH] Bluray Subtitle Support, v7 (Updated patch to v9)
stev391 at exemail.com.au
stev391
Mon Aug 10 13:32:40 CEST 2009
On Mon, 2009-08-10 at 11:31 +0200, Reimar D?ffinger wrote:
> On Mon, Aug 03, 2009 at 07:37:11PM +1000, stev391 at exemail.com.au wrote:
> > > Also you should maybe use av_fast_malloc
> > Not sure if this is a good idea, as the subtitle size is constantly
> > fluctuating, what happens if I specify a smaller buffer then already
> > provided and then the next round increase it to larger then ever
> > provided? Will the the little bit that was not used be released properly
> > (i.e not leak) along with the specified buffer length (old width * old
> > height)?
>
> Not sure what exactly you are asking.
> It will keep allocated the largest size it ever had, though if really
> important to someone this behaviour could be changed in one single
> place.
> Also it might not be that important since on the other hand it reduces
> memory wasted due to heap fragmentation.
> Even realloc might be better than free+malloc, except that it might
> uselessly copy around the old content in some cases...
I agreed with the idea, but did not understand the implementation,
however after a little poking around in the code, I think I have worked
it out.
My question was: The 'size' variable I have to pass av_fast_malloc, is
this the previous utilised size of buffer (subtitles width * height), or
is this the maximum size of the allocated memory (for all occurrences in
the past since I initialise the decoder)? And do I have to update the
'size' variable myself?
However the answer seems to be:
Add a variable to the context to keep track of the size of buffer and
initialise to 0:
unsigned int bitmap_size;
bitmap_size = 0;
Then when allocating just call:
av_fast_malloc(&ctx->picture->bitmap, &ctx->picture->bitmap_size, width
* height);
and it will update the bitmap_size variable with the actual size of the
buffer which is always equal or exceeding width * height, unless it
fails:
if (!ctx->picture->bitmap)
return AVERROR(ENOMEM);
Is this summary correct?
(Patch attached with these changes, also cosmetics changes to mpegts.c
after subtitle patch applied [no change to previous cosmetics])
Sorry for the slight confusion.
Thanks,
Stephen.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: bluray_subtitles_ffmpeg_19613_v9.diff
Type: text/x-patch
Size: 15914 bytes
Desc: not available
URL: <http://lists.mplayerhq.hu/pipermail/ffmpeg-devel/attachments/20090810/19c3035f/attachment.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: bluray_subtitles_ffmpeg_19613_v8_cosmetics.diff
Type: text/x-patch
Size: 588 bytes
Desc: not available
URL: <http://lists.mplayerhq.hu/pipermail/ffmpeg-devel/attachments/20090810/19c3035f/attachment-0001.bin>
More information about the ffmpeg-devel
mailing list