[FFmpeg-devel] [RFC] Reintroduce sws_getContext() as sws_create_context()

Michael Niedermayer michaelni
Fri Nov 5 17:06:18 CET 2010

On Fri, Nov 05, 2010 at 03:41:57PM +0100, Cyril Russo wrote:
> Le 04/11/2010 20:46, Stefano Sabatini a ?crit :
>>> if (sws_create_context(context, 234, 243, ...etc...) != 0) {
>>> perror("error creating the context"); return -1; }
>> This is inflexible and inconsistent with the FFmpeg API, in general a
>> context is a complex beast and you may need to add new options without
>> to change the interface, as the number and type of the parameters may
>> change.
>> BTW this is also the reason for which the old interface was
>> deprecated.
> Ok, then what about following what FFmpeg's dev have done so far, that  
> is introducing av_func2, av_func3 version and so on, in that case ?
> Again, as you says, the context is a complex beast, so not having to  
> deal with its members would be better, IMHO.
>> This is internal code and that's not the supposed way to deal with the
>> swscale context, which is *opaque* so can't directly messed up by the
>> user.
> I agree that the context should be opaque. But, only with sws_alloc and  
> sws_init, how do you set the source & destination dimensions, without  
> touching the struct members ?
> I know about av_set_XX functions, but the documentation doesn't say  
> anything about them.
>>>      sws_setColorspaceDetails(c, ff_yuv2rgb_coeffs[SWS_CS_DEFAULT],
>>> c->srcRange, ff_yuv2rgb_coeffs[SWS_CS_DEFAULT] /* FIXME*/,
>>> c->dstRange, 0, 1<<16, 1<<16);
>>>      if(sws_init_context(c, srcFilter, dstFilter)<  0) {
>>>          sws_freeContext(c);
>>>          perror("error initializing the context");
>>>          return -1;
>>>      }
>>> Let me know if you think it's a good idea, before I try to write a patch.
>> libavcodec API:
>> avcodec_alloc_context() ->  creates a non-opaque context, sets the
>> fields to the default values.
>> the options can be set explicitely setting the fields or using the
>> libavutil/opt.h API.
>> avcodec_open() ->  opens the context, fails in case of invalid parameters
>> avcodec_close() ->  closes the context and frees all the structs
>> initialized in avcodec_open()
>> av_freep(&context) ->  frees the allocated struct
>> ...
>> libswscale (new) API:
>> swsc_alloc_context() ->  creates an opaque context, sets the values to
>> the default values (check libswscale/options.c).
>> The context is opaque, the options can only be set using the
>> sws_setColorspaceDetails() or the libavutil/opt.h API.
> Yes the context is opaque so you can't change the struct's members.
> How do you set, for example, the source width, or the destination width,  
> or the destination height with sws_setColorspaceDetails, or even 
> sws_scale ?
> So you're back to use alternative means (like av_set_ et al), meaning  
> you have to *guess* what are the members of the context, and it's not  
> clean at all.

You could try to read the source

Every AVOption struct (Like swscontext) has a class field that contains an
AVClass and that has a option field that contains a AVOption array and in that
are all options with type, help text, name and max/min/default.
Its a lot more convenient than func6() because a GUI can list all newly added
options with that array but not by adding a new func91()

Michael     GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

I know you won't believe me, but the highest form of Human Excellence is
to question oneself and others. -- Socrates
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 198 bytes
Desc: Digital signature
URL: <http://lists.mplayerhq.hu/pipermail/ffmpeg-devel/attachments/20101105/3a3fdf85/attachment.pgp>

More information about the ffmpeg-devel mailing list