[FFmpeg-devel] [RFC] Add AVStream.opaque

Nicolas George nicolas.george
Sun Aug 22 12:30:53 CEST 2010


Le quintidi 5 fructidor, an CCXVIII, Stefano Sabatini a ?crit?:
> I'm considering to add an opaque field to AVStream, which would be
> filled with application ad-hoc data.
> 
> This would allow the user to put in AVStream a pointer to an external
> struct, e.g. in the case of ffmpeg.c it would allow to avoid the use
> of an external ist_table, as each stream would contain the pointer to
> the AVInputStream struct, thus slightly simplifying the application
> logic.

An opaque field is often useful, so the change would not be useless IMHO.
But when there is not one, there is a useful trick that may be used, that I
would like to share, in case you or anyone else on the list do not know it:

The C standard guarantees that a pointer to a struct is also a valid pointer
to its first member field. So if you need to keep additional fields along
with struct foo, yu just need to do:
struct my_foo {
    struct foo f;
    ... additional fields...
};
and allocate a my_foo instead of a foo.

It only works if the surrounding code never allocates / reallocates / copies
the structure, but if it is so, it works pretty well.

Regards,

-- 
  Nicolas George
-------------- 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/20100822/af156dc9/attachment.pgp>



More information about the ffmpeg-devel mailing list