[FFmpeg-cvslog] r22715 - trunk/libavcodec/bitstream.c
Loren Merritt
lorenm
Wed May 5 00:48:02 CEST 2010
On Tue, 4 May 2010, M?ns Rullg?rd wrote:
> Loren Merritt <lorenm at u.washington.edu> writes:
>
>> On Sun, 2 May 2010, M?ns Rullg?rd wrote:
>>
>>> lorenm <subversion at mplayerhq.hu> writes:
>>>
>>>> @@ -258,6 +275,9 @@ int init_vlc_sparse(VLC *vlc, int nb_bit
>>>> const void *symbols, int symbols_wrap, int symbols_size,
>>>> int flags)
>>>> {
>>>> + VLCcode buf[nb_codes];
>>>
>>> Sorry for not noticing this earlier, but is there any way that
>>> variable-length array could be removed? Such beasts are made of pure
>>> evil. We should be slaying them, not helping them spread.
>>
>> a) malloc.
>
> Would this have any measurable impact on performance? Is this
> function ever called more than once per frame?
No measurable difference in overall speed for ffvhuff, which has 3 tables
per frame.
START_TIMER says that the malloc is 400 cycles on linux/x86_64, which
should make it 0.01% of overall time, or less for large frames.
Otoh, there are systems with much slower malloc (OSX?).
--Loren Merritt
-------------- next part --------------
diff --git a/libavcodec/bitstream.c b/libavcodec/bitstream.c
index 03d70ac..d1493ca 100644
--- a/libavcodec/bitstream.c
+++ b/libavcodec/bitstream.c
@@ -268,8 +268,8 @@ int init_vlc_sparse(VLC *vlc, int nb_bits, int nb_codes,
const void *symbols, int symbols_wrap, int symbols_size,
int flags)
{
- VLCcode buf[nb_codes];
- int i, j;
+ VLCcode *buf;
+ int i, j, ret;
vlc->bits = nb_bits;
if(flags & INIT_VLC_USE_NEW_STATIC){
@@ -288,6 +288,8 @@ int init_vlc_sparse(VLC *vlc, int nb_bits, int nb_codes,
av_log(NULL,AV_LOG_DEBUG,"build table nb_codes=%d\n", nb_codes);
#endif
+ buf = av_malloc((nb_codes+1)*sizeof(VLCcode));
+
assert(symbols_size <= 2 || !symbols);
j = 0;
#define COPY(condition)\
@@ -312,7 +314,10 @@ int init_vlc_sparse(VLC *vlc, int nb_bits, int nb_codes,
COPY(buf[j].bits && buf[j].bits <= nb_bits);
nb_codes = j;
- if (build_table(vlc, nb_bits, nb_codes, buf, flags) < 0) {
+ ret = build_table(vlc, nb_bits, nb_codes, buf, flags);
+
+ av_free(buf);
+ if (ret < 0) {
av_freep(&vlc->table);
return -1;
}
More information about the ffmpeg-cvslog
mailing list