[openbeos] Re: Media Kit Query

  • From: François Revol <revol@xxxxxxx>
  • To: openbeos@xxxxxxxxxxxxx
  • Date: Fri, 20 Sep 2002 22:59:47 +0200 (MEST)

En réponse à John Hedditch <jhedditc@xxxxxxxxxxxxxxxxxxxxxxx>:

> 
> OK. Thanks for the tips - I'm about halfway through BMediaFormats now.
> 
> So far I have done
> 
> MakeFormatFor
> GetFormatFor
> Get<whatever>FormatFor
> GetCodeFor
> Lock()
> Unlock()
> 
> I have a question to do with locking in this kit.
> 
> The idea of the Lock(), Unlock() calls seems to be to prevent the list
> of
> supported formats/descriptions changing whilst you're looking at it, i.e
> to
> prevent some sort of race condition between  RewindFormats/GetNextFormat
> and
> the MakeFormatFor routine, plus the obvious one where 
> 
> Thread 1           Thread 2
> 
> while(!last_format)
> 
> GetNextFormat
>                    RewindFormats
> loop
> 
> My question is, if MakeFormatFor is called with BMediaFormats locked,
> should
> it sleep and wait for the lock to be released, or should it return an 
> error?
> 
> Furthermore, although the BeBook says that Lock()/Unlock() is only
> necessary
> with the GetNextFormat/RewindFormats calls, the MakeFormatFor routine 
> would seem to need to acquire it as well, for the same reason.
> 
> Any ideas?
> 
> John
> 
> 


Here I can't help really. Though I can provide you a real example that use
MakeFormatFor(), taken from the last FFDecoders (no you know I can't give 
the source :P)
(part of register_decoder(), for those who know this stuff).
I cannot guarantee this stuff is exactly how it's meant to be used, because
there are not a single line of doc on the MediaKit codecs API that tells 
how to do (will be easy to do better :)))), but it looks like it works:

        media_format_description descr[num_codecs];
        memset(descr,0,sizeof(descr));

        for (i = 0;i < num_codecs;i++)
        {
                descr[i].family = gCodecTable[i].family;
                switch(descr[i].family) {
                        case B_WAV_FORMAT_FAMILY:
                                descr[i].u.wav.codec = gCodecTable[i].fourcc;
                                break;
                        case B_AVI_FORMAT_FAMILY:
                                descr[i].u.avi.codec = 
/*(long)*/gCodecTable[i].fourcc;
                                break;
                        case B_MPEG_FORMAT_FAMILY:
                                descr[i].u.mpeg.id = gCodecTable[i].fourcc;
                                break;
                        case B_QUICKTIME_FORMAT_FAMILY:
                                descr[i].u.quicktime.codec = 
gCodecTable[i].fourcc;
                                break;
                }
        }

        media_format *format = new media_format[num_codecs];

        for(i = 0; i < num_codecs; i++)
        {
                format[i].type = gCodecTable[i].type;
                if (format[i].type == B_MEDIA_ENCODED_AUDIO)
                        format[i].u.encoded_audio = 
media_encoded_audio_format::wildcard;
                else
                        format[i].u.encoded_video = 
media_encoded_video_format::wildcard;
                format[i].require_flags = 0;
                format[i].deny_flags = B_MEDIA_MAUI_UNDEFINED_FLAGS;
                
                BMediaFormats formats;
                if (formats.MakeFormatFor(&descr[i], 1, &format[i]) == B_OK)
                {
#if DEBUG
                        char buffer[1024];
                        string_for_format(format[i], buffer, sizeof(buffer));
                        PRINT(("  output_format=%s\n", buffer));
#endif
                }
        }

/* EOF */

gCodecTable is an array of:

struct codec_table { CodecID id; media_type type; media_format_family family; 
uint32 fourcc; const char *prettyname;};

const struct codec_table gCodecTable[] = {
        {CODEC_ID_MP2,          B_MEDIA_ENCODED_AUDIO,  B_MPEG_FORMAT_FAMILY,   
B_MPEG_1_AUDIO_LAYER_1, "MPEG Audio Layer 1"},
...
        {CODEC_ID_RV10,         B_MEDIA_ENCODED_VIDEO,  
B_QUICKTIME_FORMAT_FAMILY,      'rv10', "RealVideo v1"},
        {CODEC_ID_NONE,         B_MEDIA_UNKNOWN_TYPE,   B_ANY_FORMAT_FAMILY,    
0, "null codec !!!"}
};

const int num_codecs = (sizeof(gCodecTable) / sizeof(codec_table) - 1);

Can't tell much more, really.

Hope this helps anyway,
François.


Other related posts: