IMFMediaSink fails to add second audio output stream on PCs with AMD GPUs

2

I'm trying to create a MP4 IMFMediaSink and add two audio inputs (pcm) encoded so I can have two audio AAC tracks in my mp4 file.

This works on PCs with Intel or NVidia GPUs installed. The audio is encoded from PCM to AAC and plays fine for both audio layers.

With AMD GPU (in my case R9) equipped PCs, I get an error when I try to add the second audio output stream.

The error doesn't tell me much:

"The request is invalid in the current state."

My AAC Audio MediaType is set up like this:

   hr = MFCreateMediaType(&pMediaType);

   hr = pMediaType->SetGUID(MF_MT_MAJOR_TYPE, MFMediaType_Audio);
   hr = pMediaType->SetGUID(MF_MT_SUBTYPE, MFAudioFormat_AAC);
   hr = pMediaType->SetUINT32(MF_MT_AUDIO_BITS_PER_SAMPLE, sampleBitSize);
   hr = pMediaType->SetUINT32(MF_MT_AUDIO_SAMPLES_PER_SECOND, sampleRate);
   hr = pMediaType->SetUINT32(MF_MT_AUDIO_NUM_CHANNELS, numChannels);
   hr = pMediaType->SetUINT32(MF_MT_AUDIO_AVG_BYTES_PER_SECOND, kAverageBytesPerSec);
   pMediaType->SetBlob(MF_MT_USER_DATA, userData, sizeof(userData));

The call to "AddStream()" fails the second time I call it:

   hr = pSinkWriter->AddStream(pOutputAudioMediaType, &audioLayerIdx);

My SinkWriter is initialized with these Attributes:

   MFCreateAttributes(&pAttributes, 2);
   pAttributes->SetUINT32(MF_READWRITE_ENABLE_HARDWARE_TRANSFORMS, 0);
   pAttributes->SetUINT32(MF_LOW_LATENCY, 1);
   pAttributes->SetGUID(MF_TRANSCODE_CONTAINERTYPE, MFTranscodeContainerType_MPEG4);
   MFCreateSinkWriterFromURL(NULL, pWriteStream, pAttributes, &pSinkWriter);

Has anybody hit this issue? Any idea what I might be doing wrong?

Any help would be greatly appreciated! I've been banging my head on this problem for a while, now.

The MFTrace (sorry for the big dump):

5460,1BC 12:21:04.53040 CKernel32ExportDetours::OutputDebugStringA @ ******************************************************** 111
5460,1BC 12:21:04.53043 CMFReadWriteExportDetours::MFCreateSinkWriterFromURL @ URL: '.mp4', bytestream @00000268FDFBFE90, MF_TRANSCODE_CONTAINERTYPE=MFTranscodeContainerType_MPEG4;MF_READWRITE_DISABLE_CONVERTERS=1;{9C27891A-ED7A-40E1-88E8-B22727A024EE}=1;MF_READWRITE_ENABLE_HARDWARE_TRANSFORMS=0
5460,1BC 12:21:04.53054 COle32ExportDetours::CoCreateInstance @ Created {48E2ED0F-98C2-4A37-BED5-166312DDD83F} MFReadWrite Class Factory (C:\Windows\System32\mfreadwrite.dll) @00000268BA21BCC0 - traced interfaces: IMFReadWriteClassFactory @00000268BA21BCC0, 
5460,1BC 12:21:04.53055 CMFReadWriteClassFactoryDetours::CreateInstanceFromObject @00000268BA21BCC0 Object @00000268FDFBFE90, MF_TRANSCODE_CONTAINERTYPE=MFTranscodeContainerType_MPEG4;MF_READWRITE_DISABLE_CONVERTERS=1;{9C27891A-ED7A-40E1-88E8-B22727A024EE}=1;MF_READWRITE_ENABLE_HARDWARE_TRANSFORMS=0
5460,1BC 12:21:04.53056 CMFAttributesDetours::GetUnknown @00000268C75EDD30 attribute not found guidKey = MF_SINK_WRITER_ASYNC_CALLBACK
5460,1BC 12:21:04.53056 CMFAttributesDetours::GetUINT32 @00000268C75EDD30 attribute not found guidKey = MF_SINK_WRITER_DISABLE_THROTTLING
5460,1BC 12:21:04.53057 CMFAttributesDetours::GetUnknown @00000268C75EDD30 attribute not found guidKey = {2ACF1917-3743-41DF-A564-E727A80EA33E}
5460,1BC 12:21:04.53057 CMFAttributesDetours::GetItemType @00000268C75EDD30 attribute not found guidKey = MF_SINK_WRITER_ASYNC_CALLBACK
5460,1BC 12:21:04.53058 CMFAttributesDetours::GetItemType @00000268C75EDD30 attribute not found guidKey = MF_SINK_WRITER_DISABLE_THROTTLING
5460,1BC 12:21:04.53058 CMFAttributesDetours::GetItemType @00000268C75EDD30 attribute not found guidKey = MF_SOURCE_READER_D3D_MANAGER
5460,1BC 12:21:04.53058 CMFAttributesDetours::GetUINT32 @00000268C75EDD30 attribute not found guidKey = {BDAD7BCA-0E5F-4B10-AB16-26DE381B6293}
5460,1BC 12:21:04.53059 CMFAttributesDetours::GetItemType @00000268C75EDD30 attribute not found guidKey = {39384300-D0EB-40B1-87A0-3318871B5A53}
5460,1BC 12:21:04.53059 CMFAttributesDetours::GetItemType @00000268C75EDD30 attribute not found guidKey = {430847DA-0890-4B0E-938C-054332C547E1}
5460,1BC 12:21:04.53059 CMFAttributesDetours::GetItemType @00000268C75EDD30 attribute not found guidKey = {43AD19CE-F33F-4BA9-A580-E4CD12F2D144}
5460,1BC 12:21:04.53060 CMFAttributesDetours::GetItemType @00000268C75EDD30 attribute not found guidKey = {273DB885-2DE2-4DB2-A6A7-FDB66FB40B61}
5460,1BC 12:21:04.53060 CMFReadWriteClassFactoryDetours::HandleObject @ New sink writer @00000268BA21E980

>>> adding video stream (input H264 ouput H264 : basically a passthrough) stream here....

5460,1BC 12:21:04.53062 CKernel32ExportDetours::OutputDebugStringA @ ******************************************************** 222
5460,1BC 12:21:04.53063 CKernel32ExportDetours::OutputDebugStringA @  
5460,1BC 12:21:04.53068 CMFAttributesDetours::GetUnknown @00000268C75EDD30 attribute not found guidKey = MF_SOURCE_READER_D3D_MANAGER
5460,1BC 12:21:04.53077 CMFSinkWriterDetours::AddStream @00000268BA21E980 Stream Index 0x0, MT: MF_MT_FRAME_SIZE=5497558139600 (1280,720);MF_MT_MPEG_SEQUENCE_HEADER=00 00 01 67 42 c0 1f 95 b0 14 01 6e c0 44 00 00 03 00 04 00 00 03 00 f0 36 82 21 1b 80 00 00 01 68 ca 8f 20 ;MF_MT_MAJOR_TYPE=MEDIATYPE_Video;MF_MT_FRAME_RATE=128849018881 (30,1);MF_MT_PIXEL_ASPECT_RATIO=4294967297 (1,1);MF_MT_INTERLACE_MODE=2;MF_MT_SUBTYPE=MEDIASUBTYPE_H264
5460,1BC 12:21:04.53085 CMFSinkWriterDetours::SetInputMediaType @00000268BA21E980 Stream Index 0x0, MT: MF_MT_FRAME_SIZE=5497558139600 (1280,720);MF_MT_MPEG_SEQUENCE_HEADER=00 00 01 67 42 c0 1f 95 b0 14 01 6e c0 44 00 00 03 00 04 00 00 03 00 f0 36 82 21 1b 80 00 00 01 68 ca 8f 20 ;MF_MT_MAJOR_TYPE=MEDIATYPE_Video;MF_MT_FRAME_RATE=128849018881 (30,1);MF_MT_PIXEL_ASPECT_RATIO=4294967297 (1,1);MF_MT_INTERLACE_MODE=2;MF_MT_SUBTYPE=MEDIASUBTYPE_H264

>>> adding FIRST audio stream here....

5460,1BC 12:21:04.53089 CKernel32ExportDetours::OutputDebugStringA @ ******************************************************** 333
5460,1BC 12:21:04.53092 CKernel32ExportDetours::OutputDebugStringA @  
5460,1BC 12:21:04.53095 CMFAttributesDetours::GetUnknown @00000268C75EDD30 attribute not found guidKey = MF_SOURCE_READER_D3D_MANAGER
5460,1BC 12:21:04.53098 CMFSinkWriterDetours::AddStream @00000268BA21E980 Stream Index 0x1, MT: MF_MT_AUDIO_AVG_BYTES_PER_SECOND=16000;MF_MT_AUDIO_NUM_CHANNELS=2;MF_MT_MAJOR_TYPE=MEDIATYPE_Audio;MF_MT_AUDIO_SAMPLES_PER_SECOND=44100;MF_MT_USER_DATA=00 00 29 00 00 00 00 00 00 00 00 00 12 10 ;MF_MT_AUDIO_BITS_PER_SAMPLE=16;MF_MT_SUBTYPE=MFAudioFormat_AAC
5460,1BC 12:21:04.53101 CKernel32ExportDetours::OutputDebugStringA @ ******************************************************** 444
5460,1BC 12:21:04.53102 CKernel32ExportDetours::OutputDebugStringA @  
5460,1BC 12:21:04.53106 CMFAttributesDetours::GetUnknown @00000268C75EDBB0 attribute not found guidKey = MF_SOURCE_READER_D3D_MANAGER
5460,1BC 12:21:04.53107 CMFAttributesDetours::GetUnknown @00000268C75EDBB0 attribute not found guidKey = MFT_FIELDOFUSE_UNLOCK_Attribute
5460,1BC 12:21:04.53107 CMFAttributesDetours::GetUINT32 @00000268C75EDBB0 attribute not found guidKey = {D91B0085-C86D-4F81-8822-8C68E1D7FA04}
5460,1BC 12:21:04.53108 CMFAttributesDetours::GetUINT32 @00000268C75EDBB0 attribute not found guidKey = {66B16DA9-ADD4-47E0-A16B-5AF1FB483634}
5460,1BC 12:21:04.53108 CMFAttributesDetours::GetUINT32 @00000268C75EDBB0 attribute not found guidKey = {FB683E7E-1CAC-4DBD-9E97-A321EF334D67}
5460,1BC 12:21:04.53109 CMFPlatExportDetours::MFTEnumEx @ Category: MFT_CATEGORY_AUDIO_ENCODER, Flags: 0x00000073, input MT: <NULL>, output MT: MF_MT_MAJOR_TYPE=MEDIATYPE_Audio;MF_MT_SUBTYPE=MFAudioFormat_AAC
5460,1BC 12:21:04.53144 CMFAttributesDetours::GetUINT32 @00000268C75EDEB0 attribute not found guidKey = MFT_CODEC_MERIT_Attribute
5460,1BC 12:21:04.53154 CMFAttributesDetours::GetUINT32 @00000268C75EDEB0 attribute not found guidKey = MFT_CODEC_MERIT_Attribute
5460,1BC 12:21:04.53164 CMFAttributesDetours::GetUINT32 @00000268C75EDEB0 attribute not found guidKey = MFT_CODEC_MERIT_Attribute
5460,1BC 12:21:04.53174 CMFAttributesDetours::GetUINT32 @00000268C75EDEB0 attribute not found guidKey = MFT_CODEC_MERIT_Attribute
5460,1BC 12:21:04.53184 CMFAttributesDetours::GetUINT32 @00000268C75EDEB0 attribute not found guidKey = MFT_CODEC_MERIT_Attribute
5460,1BC 12:21:04.53194 CMFAttributesDetours::GetUINT32 @00000268C75EDEB0 attribute not found guidKey = MFT_CODEC_MERIT_Attribute
5460,1BC 12:21:04.53204 CMFAttributesDetours::GetUINT32 @00000268C75EDEB0 attribute not found guidKey = MFT_CODEC_MERIT_Attribute
5460,1BC 12:21:04.53214 CMFAttributesDetours::GetUINT32 @00000268C75EDEB0 attribute not found guidKey = MFT_CODEC_MERIT_Attribute
5460,1BC 12:21:04.53228 CMFAttributesDetours::GetUINT32 @00000268C75EDEB0 attribute not found guidKey = MFT_CODEC_MERIT_Attribute
5460,1BC 12:21:04.53238 CMFAttributesDetours::GetUINT32 @00000268C75EDEB0 attribute not found guidKey = MFT_CODEC_MERIT_Attribute
5460,1BC 12:21:04.53314 COle32ExportDetours::CoCreateInstance @ Created {00000339-0000-0000-C000-000000000046}  () @000002688EB54A30 - traced interfaces: 
5460,1BC 12:21:04.53389 COle32ExportDetours::CoCreateInstance @ Created {00000339-0000-0000-C000-000000000046}  () @000002688EB55170 - traced interfaces: 
5460,1BC 12:21:04.53434 COle32ExportDetours::CoCreateInstance @ Created {00000339-0000-0000-C000-000000000046}  () @000002688EB57210 - traced interfaces: 
5460,1BC 12:21:04.53446 CMFActivateDetours::GetUINT32 @00000268C7FB49F0 attribute not found guidKey = {3C0FBE52-D034-4115-995D-95B356B9855C}
5460,1BC 12:21:04.53447 CMFActivateDetours::GetUINT32 @00000268C7FB49F0 attribute not found guidKey = MFT_CODEC_MERIT_Attribute
5460,1BC 12:21:04.53447 CMFActivateDetours::GetStringLength @00000268C7FB49F0 attribute not found guidKey = MFT_ENUM_HARDWARE_URL_Attribute
5460,1BC 12:21:04.53450 CMFPlatExportDetours::MFTEnumEx @ Activate 00 @00000268C7FB49F0, MFT_FRIENDLY_NAME_Attribute=Microsoft AAC Audio Encoder MFT;MFT_INPUT_TYPES_Attributes=61 75 64 73 00 00 10 00 80 00 00 aa 00 38 9b 71 01 00 00 00 00 00 10 00 80 00 00 aa 00 38 9b 71 ;MFT_TRANSFORM_CLSID_Attribute={93AF0C51-2275-45D2-A35B-F2BA21CAED00};MFT_OUTPUT_TYPES_Attributes=61 75 64 73 00 00 10 00 80 00 00 aa 00 38 9b 71 10 16 00 00 00 00 10 00 80 00 00 aa 00 38 9b 71 ;MF_TRANSFORM_FLAGS_Attribute=1;MF_TRANSFORM_CATEGORY_Attribute=MFT_CATEGORY_AUDIO_ENCODER
5460,1BC 12:21:04.53485 COle32ExportDetours::CoCreateInstance @ New MFT @00000268B94D8F48, <NULL>
5460,1BC 12:21:04.53485 COle32ExportDetours::CoCreateInstance @ Created {93AF0C51-2275-45D2-A35B-F2BA21CAED00}  (C:\Windows\System32\mfAACEnc.dll) @00000268B94D8F48 - traced interfaces: IMFTransform @00000268B94D8F48, 
5460,1BC 12:21:04.53486 CMFActivateDetours::GetUnknown @00000268C7FB49F0 attribute not found guidKey = MFT_PREFERRED_ENCODER_PROFILE
5460,1BC 12:21:04.53486 CMFActivateDetours::GetUnknown @00000268C7FB49F0 attribute not found guidKey = MFT_PREFERRED_OUTPUTTYPE_Attribute
5460,1BC 12:21:04.53486 CMFActivateDetours::GetUINT32 @00000268C7FB49F0 attribute not found guidKey = MFT_CODEC_MERIT_Attribute
5460,1BC 12:21:04.53486 CMFActivateDetours::ActivateObject @00000268C7FB49F0 New MFT @00000268B94D8F48
5460,1BC 12:21:04.53488 CMFAttributesDetours::GetUnknown @00000268C75EDBB0 attribute not found guidKey = MF_SOURCE_READER_D3D_MANAGER
5460,1BC 12:21:04.53488 CMFAttributesDetours::GetUINT32 @00000268C635CD80 attribute not found guidKey = MF_SA_D3D_AWARE
5460,1BC 12:21:04.53489 CMFAttributesDetours::GetUINT32 @00000268C75EDBB0 attribute not found guidKey = {EACF97AD-065C-4408-BEE3-FDCBFD128BE2}
5460,1BC 12:21:04.53489 CMFAttributesDetours::GetUINT32 @00000268C75EDBB0 attribute not found guidKey = {7B8F32C3-6D96-4B89-9203-DD38B61414F3}
5460,1BC 12:21:04.53489 CMFAttributesDetours::GetUINT32 @00000268C75EDBB0 attribute not found guidKey = {39DBD44D-2E44-4931-A4C8-352D3DC42115}
5460,1BC 12:21:04.53490 CMFAttributesDetours::GetUINT32 @00000268C75EDBB0 attribute not found guidKey = {1B320A5D-DEAB-4986-95A3-950E19B82CB0}
5460,1BC 12:21:04.53491 CMFTransformDetours::SetInputType @00000268B94D8F48 Succeeded MT: <NULL>
5460,1BC 12:21:04.53491 CMFTransformDetours::SetOutputType @00000268B94D8F48 Succeeded MT: <NULL>
5460,1BC 12:21:04.53495 CMFTransformDetours::SetInputType @00000268B94D8F48 Succeeded MT: MF_MT_AUDIO_AVG_BYTES_PER_SECOND=176400;MF_MT_AVG_BITRATE=1411200;MF_MT_AUDIO_BLOCK_ALIGNMENT=4;MF_MT_AUDIO_NUM_CHANNELS=2;MF_MT_COMPRESSED=0;MF_MT_MAJOR_TYPE=MEDIATYPE_Audio;MF_MT_AUDIO_SAMPLES_PER_SECOND=44100;MF_MT_AM_FORMAT_TYPE=FORMAT_WaveFormatEx;MF_MT_AUDIO_PREFER_WAVEFORMATEX=1;MF_MT_FIXED_SIZE_SAMPLES=1;MF_MT_ALL_SAMPLES_INDEPENDENT=1;MF_MT_AUDIO_BITS_PER_SAMPLE=16;MF_MT_SUBTYPE=MFAudioFormat_PCM
5460,1BC 12:21:04.53497 CMFTransformDetours::SetOutputType @00000268B94D8F48 Succeeded MT: MF_MT_AUDIO_AVG_BYTES_PER_SECOND=16000;MF_MT_AVG_BITRATE=128000;MF_MT_AUDIO_BLOCK_ALIGNMENT=1;MF_MT_AUDIO_NUM_CHANNELS=2;MF_MT_COMPRESSED=1;MF_MT_MAJOR_TYPE=MEDIATYPE_Audio;MF_MT_AUDIO_SAMPLES_PER_SECOND=44100;MF_MT_AM_FORMAT_TYPE=FORMAT_WaveFormatEx;MF_MT_AAC_AUDIO_PROFILE_LEVEL_INDICATION=41;MF_MT_AUDIO_PREFER_WAVEFORMATEX=1;MF_MT_USER_DATA=00 00 29 00 00 00 00 00 00 00 00 00 12 10 ;MF_MT_FIXED_SIZE_SAMPLES=0;MF_MT_AAC_PAYLOAD_TYPE=0;MF_MT_AUDIO_BITS_PER_SAMPLE=16;MF_MT_SUBTYPE=MFAudioFormat_AAC
5460,1BC 12:21:04.53498 CMFAttributesDetours::GetUnknown @00000268C75EDBB0 attribute not found guidKey = MF_SOURCE_READER_D3D_MANAGER
5460,1BC 12:21:04.53499 CMFAttributesDetours::GetUINT32 @00000268C635CD80 attribute not found guidKey = {039C0C90-25A9-4DD3-881D-5C1E1534E48B}
5460,1BC 12:21:04.53499 CMFAttributesDetours::GetString @00000268C75EDBB0 attribute not found guidKey = {430847DA-0890-4B0E-938C-054332C547E1}
5460,1BC 12:21:04.53500 CMFAttributesDetours::GetString @00000268C75EDBB0 attribute not found guidKey = {39384300-D0EB-40B1-87A0-3318871B5A53}
5460,1BC 12:21:04.53501 CMFSinkWriterDetours::SetInputMediaType @00000268BA21E980 Stream Index 0x1, MT: MF_MT_AUDIO_NUM_CHANNELS=2;MF_MT_MAJOR_TYPE=MEDIATYPE_Audio;MF_MT_AUDIO_SAMPLES_PER_SECOND=44100;MF_MT_AUDIO_BITS_PER_SAMPLE=16;MF_MT_SUBTYPE=MFAudioFormat_PCM

>>> adding SECOND audio stream here....

5460,1BC 12:21:04.53505 CKernel32ExportDetours::OutputDebugStringA @ ******************************************************** 333
5460,1BC 12:21:04.53507 CKernel32ExportDetours::OutputDebugStringA @  
5460,1BC 12:21:04.53509 CMFSinkWriterDetours::AddStream @00000268BA21E980 Failed MT: MF_MT_AUDIO_AVG_BYTES_PER_SECOND=16000;MF_MT_AVG_BITRATE=128000;MF_MT_AUDIO_BLOCK_ALIGNMENT=1;MF_MT_AUDIO_NUM_CHANNELS=2;MF_MT_COMPRESSED=1;MF_MT_MAJOR_TYPE=MEDIATYPE_Audio;MF_MT_AUDIO_SAMPLES_PER_SECOND=44100;MF_MT_AM_FORMAT_TYPE=FORMAT_WaveFormatEx;MF_MT_AAC_AUDIO_PROFILE_LEVEL_INDICATION=41;MF_MT_AUDIO_PREFER_WAVEFORMATEX=1;MF_MT_USER_DATA=00 00 29 00 00 00 00 00 00 00 00 00 12 10 ;MF_MT_FIXED_SIZE_SAMPLES=0;MF_MT_AAC_PAYLOAD_TYPE=0;MF_MT_AUDIO_BITS_PER_SAMPLE=16;MF_MT_SUBTYPE=MFAudioFormat_AAC

Here's the MFTrace on a PC where a second audio stream gets succefully added:

>> Add the SECOND Audio AAC output... 

8156,2600 14:17:59.04339 CKernel32ExportDetours::OutputDebugStringA @ ******************************************************** 333
8156,2600 14:17:59.04341 CKernel32ExportDetours::OutputDebugStringA @  
8156,2600 14:17:59.04343 CMFAttributesDetours::GetUnknown @000001A843796490 attribute not found guidKey = MF_SOURCE_READER_D3D_MANAGER
8156,2600 14:17:59.04345 CMFSinkWriterDetours::AddStream @000001A8411B0A50 Stream Index 0x2, MT: MF_MT_AUDIO_AVG_BYTES_PER_SECOND=16000;MF_MT_AVG_BITRATE=128000;MF_MT_AUDIO_BLOCK_ALIGNMENT=1;MF_MT_AUDIO_NUM_CHANNELS=2;MF_MT_COMPRESSED=1;MF_MT_MAJOR_TYPE=MEDIATYPE_Audio;MF_MT_AUDIO_SAMPLES_PER_SECOND=44100;MF_MT_AM_FORMAT_TYPE=FORMAT_WaveFormatEx;MF_MT_AAC_AUDIO_PROFILE_LEVEL_INDICATION=41;MF_MT_AUDIO_PREFER_WAVEFORMATEX=1;MF_MT_USER_DATA=00 00 29 00 00 00 00 00 00 00 00 00 12 10 ;MF_MT_FIXED_SIZE_SAMPLES=0;MF_MT_AAC_PAYLOAD_TYPE=0;MF_MT_AUDIO_BITS_PER_SAMPLE=16;MF_MT_SUBTYPE=MFAudioFormat_AAC

>> Add the SECOND Audio PCM input... 

    8156,2600 14:17:59.04346 CKernel32ExportDetours::OutputDebugStringA @ ******************************************************** 444
    8156,2600 14:17:59.04347 CKernel32ExportDetours::OutputDebugStringA @  
    8156,2600 14:17:59.04350 CMFAttributesDetours::GetUnknown @000001A8374F10F0 attribute not found guidKey = MF_SOURCE_READER_D3D_MANAGER
    8156,2600 14:17:59.04350 CMFAttributesDetours::GetUnknown @000001A8374F10F0 attribute not found guidKey = MFT_FIELDOFUSE_UNLOCK_Attribute
    8156,2600 14:17:59.04351 CMFAttributesDetours::GetUINT32 @000001A8374F10F0 attribute not found guidKey = {D91B0085-C86D-4F81-8822-8C68E1D7FA04}
    8156,2600 14:17:59.04351 CMFAttributesDetours::GetUINT32 @000001A8374F10F0 attribute not found guidKey = {66B16DA9-ADD4-47E0-A16B-5AF1FB483634}
    8156,2600 14:17:59.04351 CMFAttributesDetours::GetUINT32 @000001A8374F10F0 attribute not found guidKey = {6CE5CB40-ABD3-4A0D-849C-EDF871656C5E}
    8156,2600 14:17:59.04352 CMFAttributesDetours::GetUINT32 @000001A8374F10F0 attribute not found guidKey = {FB683E7E-1CAC-4DBD-9E97-A321EF334D67}
    8156,2600 14:17:59.04352 CMFAttributesDetours::GetBlobSize @000001A8374F10F0 attribute not found guidKey = {1D39518C-E220-4DA8-A07F-BA172552D6B1}
    8156,2600 14:17:59.04353 CMFPlatExportDetours::MFTEnumEx @ Category: MFT_CATEGORY_AUDIO_ENCODER, Flags: 0x00000073, input MT: <NULL>, output MT: MF_MT_MAJOR_TYPE=MEDIATYPE_Audio;MF_MT_SUBTYPE=MFAudioFormat_AAC
    8156,2600 14:17:59.04354 CMFAttributesDetours::GetUINT32 @000001A8437968B0 attribute not found guidKey = {3C0FBE52-D034-4115-995D-95B356B9855C}
    8156,2600 14:17:59.04356 CMFPlatExportDetours::MFTEnumEx @ Activate 00 @000001A85295DEC0, MFT_FRIENDLY_NAME_Attribute=Microsoft AAC Audio Encoder MFT;MFT_INPUT_TYPES_Attributes=61 75 64 73 00 00 10 00 80 00 00 aa 00 38 9b 71 01 00 00 00 00 00 10 00 80 00 00 aa 00 38 9b 71 ;MFT_TRANSFORM_CLSID_Attribute={93AF0C51-2275-45D2-A35B-F2BA21CAED00};MFT_OUTPUT_TYPES_Attributes=61 75 64 73 00 00 10 00 80 00 00 aa 00 38 9b 71 10 16 00 00 00 00 10 00 80 00 00 aa 00 38 9b 71 ;MF_TRANSFORM_FLAGS_Attribute=1;MF_TRANSFORM_CATEGORY_Attribute=MFT_CATEGORY_AUDIO_ENCODER
    8156,2600 14:17:59.04357 CMFAttributesDetours::GetUnknown @000001A8374F10F0 attribute not found guidKey = {2ACF1917-3743-41DF-A564-E727A80EA33E}
    8156,2600 14:17:59.04377 COle32ExportDetours::CoCreateInstance @ New MFT @000001A814078068, <NULL>
    8156,2600 14:17:59.04377 COle32ExportDetours::CoCreateInstance @ Created {93AF0C51-2275-45D2-A35B-F2BA21CAED00}  (C:\Windows\System32\mfAACEnc.dll) @000001A814078068 - traced interfaces: IMFTransform @000001A814078068, 
    8156,2600 14:17:59.04377 CMFActivateDetours::GetUnknown @000001A85295DEC0 attribute not found guidKey = MFT_PREFERRED_ENCODER_PROFILE
    8156,2600 14:17:59.04377 CMFActivateDetours::GetUnknown @000001A85295DEC0 attribute not found guidKey = MFT_PREFERRED_OUTPUTTYPE_Attribute
    8156,2600 14:17:59.04378 CMFActivateDetours::GetUINT32 @000001A85295DEC0 attribute not found guidKey = MFT_CODEC_MERIT_Attribute
    8156,2600 14:17:59.04378 CMFActivateDetours::ActivateObject @000001A85295DEC0 New MFT @000001A814078068
    8156,2600 14:17:59.04379 CMFAttributesDetours::GetUnknown @000001A8374F10F0 attribute not found guidKey = MF_SOURCE_READER_D3D_MANAGER
    8156,2600 14:17:59.04379 CMFAttributesDetours::GetUINT32 @000001A8374F0F10 attribute not found guidKey = MF_SA_D3D_AWARE
    8156,2600 14:17:59.04380 CMFAttributesDetours::GetUINT32 @000001A8374F10F0 attribute not found guidKey = {EACF97AD-065C-4408-BEE3-FDCBFD128BE2}
    8156,2600 14:17:59.04380 CMFAttributesDetours::GetUINT32 @000001A8374F10F0 attribute not found guidKey = {7B8F32C3-6D96-4B89-9203-DD38B61414F3}
    8156,2600 14:17:59.04380 CMFAttributesDetours::GetUINT32 @000001A8374F10F0 attribute not found guidKey = {39DBD44D-2E44-4931-A4C8-352D3DC42115}
    8156,2600 14:17:59.04381 CMFAttributesDetours::GetUINT32 @000001A8374F10F0 attribute not found guidKey = {1B320A5D-DEAB-4986-95A3-950E19B82CB0}
    8156,2600 14:17:59.04382 CMFTransformDetours::SetInputType @000001A814078068 Succeeded MT: <NULL>
    8156,2600 14:17:59.04382 CMFTransformDetours::SetOutputType @000001A814078068 Succeeded MT: <NULL>
    8156,2600 14:17:59.04385 CMFTransformDetours::SetInputType @000001A814078068 Succeeded MT: MF_MT_AUDIO_AVG_BYTES_PER_SECOND=176400;MF_MT_AVG_BITRATE=1411200;MF_MT_AUDIO_BLOCK_ALIGNMENT=4;MF_MT_AUDIO_NUM_CHANNELS=2;MF_MT_COMPRESSED=0;MF_MT_MAJOR_TYPE=MEDIATYPE_Audio;MF_MT_AUDIO_SAMPLES_PER_SECOND=44100;MF_MT_AM_FORMAT_TYPE=FORMAT_WaveFormatEx;MF_MT_AUDIO_PREFER_WAVEFORMATEX=1;MF_MT_FIXED_SIZE_SAMPLES=1;MF_MT_ALL_SAMPLES_INDEPENDENT=1;MF_MT_AUDIO_BITS_PER_SAMPLE=16;MF_MT_SUBTYPE=MFAudioFormat_PCM
    8156,2600 14:17:59.04388 CMFTransformDetours::SetOutputType @000001A814078068 Succeeded MT: MF_MT_AUDIO_AVG_BYTES_PER_SECOND=16000;MF_MT_AVG_BITRATE=128000;MF_MT_AUDIO_BLOCK_ALIGNMENT=1;MF_MT_AUDIO_NUM_CHANNELS=2;MF_MT_COMPRESSED=1;MF_MT_MAJOR_TYPE=MEDIATYPE_Audio;MF_MT_AUDIO_SAMPLES_PER_SECOND=44100;MF_MT_AM_FORMAT_TYPE=FORMAT_WaveFormatEx;MF_MT_AAC_AUDIO_PROFILE_LEVEL_INDICATION=41;MF_MT_AUDIO_PREFER_WAVEFORMATEX=1;MF_MT_USER_DATA=00 00 29 00 00 00 00 00 00 00 00 00 12 10 ;MF_MT_FIXED_SIZE_SAMPLES=0;MF_MT_AAC_PAYLOAD_TYPE=0;MF_MT_AUDIO_BITS_PER_SAMPLE=16;MF_MT_SUBTYPE=MFAudioFormat_AAC
    8156,2600 14:17:59.04388 CMFAttributesDetours::GetUnknown @000001A8374F10F0 attribute not found guidKey = MF_SOURCE_READER_D3D_MANAGER
    8156,2600 14:17:59.04389 CMFAttributesDetours::GetUINT32 @000001A8374F0F10 attribute not found guidKey = {039C0C90-25A9-4DD3-881D-5C1E1534E48B}
    8156,2600 14:17:59.04390 CMFAttributesDetours::GetString @000001A8374F10F0 attribute not found guidKey = {430847DA-0890-4B0E-938C-054332C547E1}
    8156,2600 14:17:59.04391 CMFAttributesDetours::GetString @000001A8374F10F0 attribute not found guidKey = {39384300-D0EB-40B1-87A0-3318871B5A53}
    8156,2600 14:17:59.04392 CMFSinkWriterDetours::SetInputMediaType @000001A8411B0A50 Stream Index 0x2, MT: MF_MT_AUDIO_NUM_CHANNELS=2;MF_MT_MAJOR_TYPE=MEDIATYPE_Audio;MF_MT_AUDIO_SAMPLES_PER_SECOND=44100;MF_MT_AUDIO_BITS_PER_SAMPLE=16;MF_MT_SUBTYPE=MFAudioFormat_PCM
windows
audio
mp4
ms-media-foundation
asked on Stack Overflow Apr 25, 2018 by xris • edited Apr 27, 2018 by xris

2 Answers

0

I see you already set MF_READWRITE_ENABLE_HARDWARE_TRANSFORMS to false, which shouldn't aware GPU acceleration.

How do you initialize your pOutputAudioMediaType? Please paste your code here.

ebugging tips I can share:
1. Log with mftrace and compare with the good case.
2. Open your input in topoedit, see if it the topology can be resolved correctly on AMD. You can find topoedit sourcecode from WindowsSDK or github archive and study how it's implemented.

Below is my code snippet to setup output types for AAC, see if it helps.

HRESULT UpdateAudioOutputTypeAttributes(IMFAttributes *pAttr)  
{  
    HRESULT hr = S_OK;  
    if (!pAttr){  
        hr = E_INVALIDARG;  
    }  
    if (SUCCEEDED(hr)){  
        hr = pAttr->SetGUID(MF_MT_MAJOR_TYPE, MFMediaType_Audio);  
    }  
    if (SUCCEEDED(hr)){  
        hr = pAttr->SetGUID(MF_MT_SUBTYPE, DEFAULT_AUDIO_OUT_FORMAT);  
    }  
    if (SUCCEEDED(hr)){  
        hr = pAttr->SetUINT32(MF_MT_COMPRESSED, 1);  
    }  
    if (SUCCEEDED(hr)){  
        hr = pAttr->SetUINT32(MF_MT_AVG_BITRATE, DEFAULT_AUDIO_OUT_AVG_BITRATE);  
    }  
    if (SUCCEEDED(hr)){  
        hr = pAttr->SetUINT32(MF_MT_AUDIO_BLOCK_ALIGNMENT, 1);  
    }  
    if (SUCCEEDED(hr)){  
        hr = pAttr->SetUINT32(MF_MT_AUDIO_PREFER_WAVEFORMATEX, 1);  
    }  
    if (SUCCEEDED(hr)){  
        hr = pAttr->SetGUID(MF_MT_AM_FORMAT_TYPE, FORMAT_WaveFormatEx);  
    }  
    if (SUCCEEDED(hr)){  
        hr = pAttr->SetUINT32(MF_MT_AAC_AUDIO_PROFILE_LEVEL_INDICATION, DEFAULT_AUDIO_OUT_PROFILE_LEVEL);  
    }  
    if (SUCCEEDED(hr)){  
        hr = pAttr->SetUINT32(MF_MT_FIXED_SIZE_SAMPLES, 0);  
    }  
    if (SUCCEEDED(hr)){  
        hr = pAttr->SetUINT32(MF_MT_AAC_PAYLOAD_TYPE, 0);  
    }  
    if (SUCCEEDED(hr)){  
        hr = pAttr->SetUINT32(MF_MT_AUDIO_NUM_CHANNELS, DEFAULT_AUDIO_OUT_NUM_CHANNELS);  
    }  
    if (SUCCEEDED(hr)){  
        hr = pAttr->SetUINT32(MF_MT_AUDIO_SAMPLES_PER_SECOND, DEFAULT_AUDIO_OUT_SAMPLES_PER_SECOND);  
    }  
    if (SUCCEEDED(hr)){  
        hr = pAttr->SetUINT32(MF_MT_AUDIO_AVG_BYTES_PER_SECOND, DEFAULT_AUDIO_OUT_AVG_BYTES_PER_SECOND);  
    }  
    if (SUCCEEDED(hr)){  
        hr = pAttr->SetUINT32(MF_MT_AUDIO_BITS_PER_SAMPLE, DEFAULT_AUDIO_OUT_BITS_PER_SAMPLE);  
    }  
    if (SUCCEEDED(hr)){  
        BYTE aacUserData[14] = { 0x00, 0x00, DEFAULT_AUDIO_OUT_PROFILE_LEVEL, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };  
        WORD AudioSpecificConfig = 0;  
        AudioSpecificConfig |= 2 << 11;  
        AudioSpecificConfig |= FindFreqIndex(g_pWaveFmt->nSamplesPerSec) << 7;  
        AudioSpecificConfig |= g_pWaveFmt->nChannels << 3;  
        aacUserData[12] = AudioSpecificConfig >> 8;  
        aacUserData[13] = AudioSpecificConfig & 0x00FF;  
        hr = pAttr->SetBlob(MF_MT_USER_DATA, (UINT8*)&(aacUserData), ARRAYSIZE(aacUserData));  
    }  
    return hr;  
}
answered on Stack Overflow Apr 26, 2018 by Ivellios
0

I turns out that Windows10(1709) now ships with MediaFoundation libraries that have a MediaSink implementation that supports more than one audio layer as input/ouput. Anything before this version does not (I tested Win10 1704 and older versions of Windows10 and they failed).

The question now remains: can I use these DLLs on Windows versions as old as Win7 (via redistributables installer)? This is the minimum spec OS that I'd like to support.

answered on Stack Overflow May 4, 2018 by xris

User contributions licensed under CC BY-SA 3.0