[FFmpeg-devel] [HACK] Remove MAX_STREAMS usages
Aurelien Jacobs
aurel
Sun Aug 29 17:03:42 CEST 2010
On Thu, Aug 12, 2010 at 10:13:20PM +0200, Aurelien Jacobs wrote:
> On Wed, Aug 11, 2010 at 02:41:49PM -0700, Baptiste Coudurier wrote:
> > Hi guys,
> >
> > On 8/11/10 8:28 AM, Aurelien Jacobs wrote:
> > >max_stream.diff
> > >
> > >
> > >commit eb4a2bfc996713e70f60b556ed776cae3ab1cc5b
> > >Author: Aurelien Jacobs<aurel at gnuage.org>
> > >Date: Tue Aug 10 00:21:06 2010 +0200
> > >
> > > dynamically use nb_streams instead of static use of MAX_STREAMS
> > >
> > >diff --git a/libavformat/utils.c b/libavformat/utils.c
> > >index 1aa965c..10e817d 100644
> > >--- a/libavformat/utils.c
> > >+++ b/libavformat/utils.c
> > > [...]
> > >@@ -2160,15 +2164,34 @@ int av_find_stream_info(AVFormatContext *ic)
> > > int i, count, ret, read_size, j;
> > > AVStream *st;
> > > AVPacket pkt1, *pkt;
> > >- int64_t last_dts[MAX_STREAMS];
> > >- int64_t duration_gcd[MAX_STREAMS]={0};
> > >- int duration_count[MAX_STREAMS]={0};
> > >- double (*duration_error)[MAX_STD_TIMEBASES];
> > >+ int64_t *last_dts = NULL;
> > >+ int64_t *duration_gcd = NULL;
> > >+ int *duration_count = NULL;
> > >+ double (*duration_error)[MAX_STD_TIMEBASES] = NULL;
> > > int64_t old_offset = url_ftell(ic->pb);
> > >- int64_t codec_info_duration[MAX_STREAMS]={0};
> > >+ int64_t *codec_info_duration = NULL;
> > >+ int nb_streams = 0;
> > >+ void *tmp;
> > >
> > >- duration_error = av_mallocz(MAX_STREAMS * sizeof(*duration_error));
> > >- if (!duration_error) return AVERROR(ENOMEM);
> > >+#define GROW_BUFFER(buf, old_size, new_size) \
> > >+ if (!(tmp = av_realloc(buf, new_size * sizeof(*buf)))) { \
> > >+ ret = AVERROR(ENOMEM); \
> > >+ goto err_out; \
> > >+ } \
> > >+ buf = tmp; \
> > >+ memset(buf+old_size, 0, (new_size-old_size) * sizeof(*buf)); \
> > >+
> > >+#define GROW_BUFFERS() \
> > >+ if (ic->nb_streams> nb_streams) { \
> > >+ GROW_BUFFER(last_dts, nb_streams, ic->nb_streams); \
> > >+ GROW_BUFFER(duration_gcd, nb_streams, ic->nb_streams); \
> > >+ GROW_BUFFER(duration_count, nb_streams, ic->nb_streams); \
> > >+ GROW_BUFFER(duration_error, nb_streams, ic->nb_streams); \
> > >+ GROW_BUFFER(codec_info_duration, nb_streams, ic->nb_streams); \
> > >+ } \
> >
> > I suggest to define a struct per stream to simplify the code.
>
> I thought about this too... And then I discarded the idea. I don't
> remember exactly why, but I guess I was just too lazy to change all
> usage of those vars...
> Anyway, I did it now. And it indeed looks a bit cleaner.
> I split this into 2 patches. First one moves those vars into a struct,
> and second one replace MAX_STREAMS usage by dynamic allocation.
Ping ?
Aurel
More information about the ffmpeg-devel
mailing list