locked
Source Reader: Are there other ways to configure the audio decoder? RRS feed

  • Question

  • Hi again,

     

    Using the Source Reader from the Media Foundation SDK I'm able to decode lot's of video formats, but having trouble with audio. I need audio to be PCM, 2 channels, 16 bit, 48000 samples per second, block align 4, 192000 avg bytes per sec.

     

    I have 2 file samples with different audio formats. Under Directshow, I was able to decode their audio to the desired format, using native windows codecs. Using Media Foundation I wasn't enable to do it so far. I create the IMFSourceReader, create a fresh IMFMediaType and use the following commands:

    pType->SetGUID(MF_MT_SUBTYPE, MFAudioFormat_PCM);

    pType->SetUINT32( MF_MT_AUDIO_NUM_CHANNELS, 2);
    pType->SetUINT32( MF_MT_AUDIO_BITS_PER_SAMPLE, 16 );
    pType->SetUINT32( MF_MT_AUDIO_SAMPLES_PER_SECOND, 48000 );
    pType->SetUINT32( MF_MT_AUDIO_AVG_BYTES_PER_SECOND, 192000 );
    pType->SetUINT32( MF_MT_AUDIO_BLOCK_ALIGNMENT, 4 );

    And then:

    pReader->SetCurrentMediaType(MF_SOURCE_READER_FIRST_AUDIO_STREAM, NULL, pType);

    Wich returns the error code -1072875852.

    Here are the formats of both files audio streams (got using the MFMediaPropDump sample from the team blog):

     

    File 1: .wmv

    MF_MT_MAJOR_TYPE: MFMediaType_Audio
    MF_MT_AUDIO_PREFER_WAVEFORMATEX: 1
    MF_MT_SUBTYPE: MFAudioFormat_WMAudioV9
    MF_MT_AUDIO_NUM_CHANNELS: 6
    MF_MT_AUDIO_SAMPLES_PER_SECOND: 48000
    MF_MT_AUDIO_BLOCK_ALIGNMENT: 9387
    MF_MT_AUDIO_AVG_BYTES_PER_SECOND: 55002
    MF_MT_AUDIO_BITS_PER_SAMPLE: 24

    MF_MT_AUDIO_WMADRC_PEAKREF: 30927
    MF_MT_AUDIO_WMADRC_PEAKTARGET: 30927
    MF_MT_AUDIO_WMADRC_AVGREF: 6924
    MF_MT_AUDIO_WMADRC_AVGTARGET: 6924

    Under directshow, the WMAudio Decoder DMO filter is added to the graph and decode the audio stream to the desired format.

     

    File 2: .mov

    MF_MT_MAJOR_TYPE: MFMediaType_Audio
    MF_MT_AUDIO_PREFER_WAVEFORMATEX: 1
    MF_MT_AAC_PAYLOAD_TYPE: 0
    MF_MT_AAC_AUDIO_PROFILE_LEVEL_INDICATION: 0
    MF_MT_SUBTYPE: MFAudioFormat_AAC
    MF_MT_AUDIO_NUM_CHANNELS: 2
    MF_MT_AUDIO_SAMPLES_PER_SECOND: 44100
    MF_MT_AUDIO_BLOCK_ALIGNMENT: 1
    MF_MT_AUDIO_AVG_BYTES_PER_SECOND: 12000
    MF_MT_AUDIO_BITS_PER_SAMPLE: 16

    MF_MT_AM_FORMAT_TYPE: FORMAT_WaveFormatEx
    MF_MT_ALL_SAMPLES_INDEPENDENT: 1
    MF_MT_FIXED_SIZE_SAMPLES: 1
    MF_MT_SAMPLE_SIZE: 1

    Under directshow, the Microsoft DTV-DVD Audio Decoder changes the block align from 1 to 4, and then the ACM Wrapper filter gives me the desired format.

     

    I already tried getting the native media type and setting just the values I need, nothing. Also tried setting just the channel number, sample rate and bit depth, it didn't work. For what I understood reading the documentation for the Windows Media Audio Decoder and the AAC Decoder, they should be able to decode those streams to the format I need. Also reading the documentation for the Source Reader, I understood that all I should have to do is setting the desired output format and the API would add and configure the codecs as needed. That's why I'm asking: Am I right in those assumptions? Why am I not able to set that format? Is there another way to configure the codec, since I have to use the Source Reader approach to read these files?

     

    Any help would be greatly appreciated.

     

    Thanks,

    Ryan.

    Thursday, May 12, 2011 5:25 PM

Answers

  • The audio decoders typically output only two formats: the format that was encoded, in either PCM or Float.  If you want to change the audio format to a desired output format, you need to use the resampler DSP.  When using the media session, a resampler gets inserted automatically if needed, but for the source reader you would need to create the resampler and process samples through it manually.  The source reader supports very few conversions, and none for audio I believe.  It is more for quickly getting raw data out of media files than for more complex scenarios involving conversions.

    Tuesday, June 21, 2011 11:21 PM