Changeset 770


Ignore:
Timestamp:
Jul 13, 2017, 8:02:57 AM (7 years ago)
Author:
roman
Message:

Added audio MF source; added audio track support in MfGenerate2 sample application

Location:
trunk/Utilities/DirectShowReferenceSource
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/Utilities/DirectShowReferenceSource/Sample/MfGenerate2/Application.cpp

    r655 r770  
    11////////////////////////////////////////////////////////////
    2 // Copyright (C) Roman Ryltsov, 2015-2016
     2// Copyright (C) Roman Ryltsov, 2015-2017
    33// Created by Roman Ryltsov roman@alax.info
    44//
     
    3737                __C(MFCreateSourceResolver(&pSourceResolver));
    3838                #pragma region Media Source
    39                 CComQIPtr<IMFMediaSource> pMediaSource;
     39                CComPtr<IMFMediaSource> pMediaSource;
    4040                //{
    4141                //      static const LPCTSTR g_pszPath =
     
    4848                //      __D(pMediaSource, E_NOINTERFACE);
    4949                //}
     50                CComPtr<IMFMediaSource> pVideoMediaSource, pAudioMediaSource;
     51                const SIZE g_Extent = { 640, 360 };
     52                const LONG g_nFrameRateNumerator = 30000;
     53                const LONG g_nFrameRateDenominator = 1001;
     54                const LONG g_nDuration = 1 * 60; // minutes
     55                const LONG g_nVideoBitrate = (2 << 10) * 1000; // 2 MBps
     56                const LONG g_nSampleRate = 48000;
     57                const LONG g_nChannelCount = 1;
     58                const LONG g_nBitDepth = 16;
     59                const LONG g_nAudioBitrate = 20 * 1000;
     60                #pragma region Video
     61                if(TRUE)
    5062                {
    5163                        using namespace AlaxInfoDirectShowReferenceSource;
    52                         CComPtr<IVideoMediaSource> pVideoMediaSource;
    53                         __C(pVideoMediaSource.CoCreateInstance(__uuidof(VideoMediaSource)));
    54                         __C(pVideoMediaSource->SetMediaType(640, 480, CComVariant(_PersistHelper::StringFromIdentifier(MEDIASUBTYPE_ARGB32))));
    55                         //__C(pVideoMediaSource->SetMediaTypeAspectRatio(...));
    56                         __C(pVideoMediaSource->SetMediaTypeRate(10000, 1000));
    57                         __C(pVideoMediaSource->put_Duration(5.0));
    58                         pMediaSource = pVideoMediaSource;
    59                 }
     64                        CComPtr<IVideoMediaSource> pSource;
     65                        __C(pSource.CoCreateInstance(__uuidof(VideoMediaSource)));
     66                        __C(pSource->SetMediaType(g_Extent.cx, g_Extent.cy, CComVariant(_PersistHelper::StringFromIdentifier(MEDIASUBTYPE_ARGB32))));
     67                        //__C(pSource->SetMediaTypeAspectRatio(...));
     68                        __C(pSource->SetMediaTypeRate(g_nFrameRateNumerator, g_nFrameRateDenominator));
     69                        __C(pSource->put_Duration((DOUBLE) g_nDuration));
     70                        pVideoMediaSource = pSource;
     71                }
     72                #pragma endregion
     73                #pragma region Audio
     74                if(TRUE)
     75                {
     76                        using namespace AlaxInfoDirectShowReferenceSource;
     77                        CComPtr<IAudioMediaSource> pSource;
     78                        __C(pSource.CoCreateInstance(__uuidof(AudioMediaSource)));
     79                        __C(pSource->SetMediaType(NULL, g_nSampleRate, g_nChannelCount, g_nBitDepth));
     80                        __C(pSource->put_Duration((DOUBLE) g_nDuration));
     81                        pAudioMediaSource = pSource;
     82                }
     83                #pragma endregion
     84                __D(pVideoMediaSource || pAudioMediaSource, E_UNNAMED);
     85                if(pVideoMediaSource && pAudioMediaSource)
     86                {
     87                    CComPtr<IMFCollection> pCollection;
     88                    __C(MFCreateCollection(&pCollection));
     89                __C(pCollection->AddElement(pVideoMediaSource));
     90                __C(pCollection->AddElement(pAudioMediaSource));
     91                __C(MFCreateAggregateSource(pCollection, &pMediaSource));
     92                } else
     93                        pMediaSource = pVideoMediaSource ? pVideoMediaSource : pAudioMediaSource;
     94                _A(pMediaSource);
    6095                #pragma endregion
    6196                CPath sFilePath;
     
    72107                MF::CTopology pTopology;
    73108                //pTopology.Create();
     109                #pragma region Profile
    74110                CComPtr<IMFTranscodeProfile> pTranscodeProfile;
    75111                {
    76112                        __C(MFCreateTranscodeProfile(&pTranscodeProfile));
     113                        #pragma region Video
     114                        if(pVideoMediaSource)
    77115                        {
    78116                                MF::CAttributes pAttributes;
    79117                                pAttributes.Create(8);
    80                                 pAttributes[MF_MT_SUBTYPE] = MFVideoFormat_H264;
    81                                 pAttributes[MF_MT_AVG_BITRATE] = (UINT32) (5 << 10) * 1000; // 12 MBps
    82                                 pAttributes[MF_MT_FRAME_SIZE].SetSize(640, 480);
    83                                 pAttributes[MF_MT_FRAME_RATE].SetRatio(10000, 1000);
     118                                pAttributes[MF_MT_SUBTYPE] =
     119                                        MFVideoFormat_H264;
     120                                        //MFVideoFormat_HEVC;
     121                                pAttributes[MF_MT_AVG_BITRATE] = (UINT32) g_nVideoBitrate;
     122                                pAttributes[MF_MT_FRAME_SIZE].SetSize(g_Extent.cx, g_Extent.cy);
     123                                pAttributes[MF_MT_FRAME_RATE].SetRatio(g_nFrameRateNumerator, g_nFrameRateDenominator);
    84124                                __C(pTranscodeProfile->SetVideoAttributes(pAttributes));
     125                                pAttributes.Trace();
    85126                        }
     127                        #pragma endregion
     128                        #pragma region Audio
     129                        if(pAudioMediaSource)
    86130                        {
     131                                // NOTE: The following audio attributes can be set: https://msdn.microsoft.com/en-us/library/windows/desktop/dd369143
     132                                //   Audio Media Types
     133                                //   MF_TRANSCODE_DONOT_INSERT_ENCODER
     134                                //   MF_TRANSCODE_ENCODINGPROFILE
     135                                //   MF_TRANSCODE_QUALITYVSSPEED
    87136                                MF::CAttributes pAttributes;
    88                                 pAttributes.Create(1);
    89                                 pAttributes[MF_TRANSCODE_CONTAINERTYPE] = MFTranscodeContainerType_MPEG4;
    90                                 __C(pTranscodeProfile->SetContainerAttributes(pAttributes));
     137                                pAttributes.Create(8);
     138                                pAttributes[MF_MT_SUBTYPE] = MFAudioFormat_AAC;
     139                                pAttributes[MF_MT_AUDIO_SAMPLES_PER_SECOND] = (UINT32) g_nSampleRate;
     140                                pAttributes[MF_MT_AUDIO_NUM_CHANNELS] = (UINT32) g_nChannelCount;
     141                                pAttributes[MF_MT_AUDIO_BITS_PER_SAMPLE] = (UINT32) g_nBitDepth;
     142                                pAttributes[MF_MT_AUDIO_AVG_BYTES_PER_SECOND] = (UINT32) g_nAudioBitrate;
     143                                __C(pTranscodeProfile->SetAudioAttributes(pAttributes));
     144                                pAttributes.Trace();
    91145                        }
    92                 }
     146                        #pragma endregion
     147                        MF::CAttributes pAttributes;
     148                        pAttributes.Create(1);
     149                        pAttributes[MF_TRANSCODE_CONTAINERTYPE] = MFTranscodeContainerType_MPEG4;
     150                        __C(pTranscodeProfile->SetContainerAttributes(pAttributes));
     151                }
     152                #pragma endregion
    93153                __C(MFCreateTranscodeTopology(pMediaSource, CT2CW((LPCTSTR) sFilePath), pTranscodeProfile, &pTopology.m_p));
    94154                pTopology.Trace();
     
    102162                        MF::CMediaEvent pMediaEvent;
    103163                        __C(pMediaSession->GetEvent(0, &pMediaEvent));
     164                        pMediaEvent.Trace();
    104165                        MediaEventType Type;
    105166                        __C(pMediaEvent->GetType(&Type));
    106167                        HRESULT nStatus;
    107168                        __C(pMediaEvent->GetStatus(&nStatus));
    108                         _Z4(atlTraceGeneral, 4, _T("Type %s, nStatus %s\n"), MF::CMediaEvent::FormatType(Type), MF::FormatResult(nStatus));
    109169                        switch(Type)
    110170                        {
    111171                        case MESessionTopologySet:
     172                                {
     173                                        MF::CPropVariant vValue;
     174                                        if(SUCCEEDED(pMediaEvent->GetValue(&vValue)) && vValue.vt == VT_UNKNOWN)
     175                                        {
     176                                                MF::CTopology pTopology;
     177                                                pTopology.m_p = CComQIPtr<IMFTopology>(vValue.punkVal);
     178                                                pTopology.Trace();
     179                                        }
     180                                }
    112181                                break;
    113182                        case MESessionTopologyStatus:
  • trunk/Utilities/DirectShowReferenceSource/Sample/MfGenerate2/MfGenerate2.vcxproj

    r655 r770  
    2323    <Keyword>Win32Proj</Keyword>
    2424    <RootNamespace>MfGenerate2</RootNamespace>
    25     <WindowsTargetPlatformVersion>10.0.10586.0</WindowsTargetPlatformVersion>
     25    <WindowsTargetPlatformVersion>10.0.15063.0</WindowsTargetPlatformVersion>
    2626  </PropertyGroup>
    2727  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
  • trunk/Utilities/DirectShowReferenceSource/Sample/MfGenerate2/targetver.h

    r655 r770  
    11////////////////////////////////////////////////////////////
    2 // Copyright (C) Roman Ryltsov, 2015
     2// Copyright (C) Roman Ryltsov, 2015-2017
    33// Created by Roman Ryltsov roman@alax.info
    44//
     
    1313// set the _WIN32_WINNT macro to the platform you wish to support before including SDKDDKVer.h.
    1414
    15 #include <SDKDDKVer.h>
     15#include <winsdkver.h>
     16#include <sdkddkver.h>
Note: See TracChangeset for help on using the changeset viewer.