[MPlayer-dev-eng] [PATCH] allow builtin codecs table to be const

Uoti Urpala uoti.urpala at pp1.inet.fi
Mon Dec 3 04:17:18 CET 2007


On Mon, 2007-12-03 at 00:25 +0100, Reimar Döffinger wrote:
> I thought since the builtin codecs table is already several 100 kb it
> would be nice if it was in .rodata.

Less than 200 kB, so not really "several". It would be possible to make
it significantly smaller. The infmt and inflags fields do not seem to be
used for anything. Most codecs do not have many output formats or
fourccs, so storing a count plus a pointer to an array instead of a
constant-sized array per codec would use much less memory (though with
slightly more complicated code). I think that would drop the total size
to about one fifth.

> Unfortunately there is a bit extra work necessary for that, since
> currently one flag for each codec is stored in that table.
> Attached patch makes the changes necessary.
> What do you think?

+               selected_video = calloc(4, nr_vcodecs >> 5);
+               selected_audio = calloc(4, nr_acodecs >> 5);

Should round up not down. The arguments to calloc are in the opposite
order compared to the formal meaning.

+static int ptr2idx(const codecs_t *c, int audio) {
+       const codecs_t *start = audio ? audio_codecs : video_codecs;
+       int num = audio ? nr_acodecs : nr_vcodecs;
+       if (c < start || c > start + num - 1)
+               return -1;
+       return c - start;
+}

Strictly speaking comparison of pointers is only defined within the the
same object or malloc, so the return -1 case would be undefined
behavior.

+int get_codec_ptr_selected(const codecs_t *c) {
+       int offset;
+       uint32_t *field = selected_audio;
+       int index = ptr2idx(c, 1);
+       if (index < 0) {
+               field = selected_video;
+               index = ptr2idx(c, 0);
+       }
+       if (index < 0) return -1;
+       offset = index & 31;
+       index >>= 5;
+       return (field[index] >> offset) & 1;
+}

When is the return -1 case expected to happen?




More information about the MPlayer-dev-eng mailing list