Changeset 823


Ignore:
Timestamp:
Feb 23, 2018, 1:59:55 AM (6 years ago)
Author:
roman
Message:

Sync and added MfGenerateFlac? sample

Location:
trunk/Utilities/DirectShowReferenceSource
Files:
7 added
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/Utilities/DirectShowReferenceSource/Sample/Generate/Generate.vcxproj

    r769 r823  
    11<?xml version="1.0" encoding="utf-8"?>
    2 <Project DefaultTargets="Build" ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
     2<Project DefaultTargets="Build" ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
    33  <ItemGroup Label="ProjectConfigurations">
    44    <ProjectConfiguration Include="Debug|Win32">
     
    2121    <ConfigurationType>Application</ConfigurationType>
    2222    <UseDebugLibraries>true</UseDebugLibraries>
    23     <PlatformToolset>v140</PlatformToolset>
     23    <PlatformToolset>v141</PlatformToolset>
    2424    <CharacterSet>Unicode</CharacterSet>
    2525  </PropertyGroup>
     
    2727    <ConfigurationType>Application</ConfigurationType>
    2828    <UseDebugLibraries>false</UseDebugLibraries>
    29     <PlatformToolset>v140</PlatformToolset>
     29    <PlatformToolset>v141</PlatformToolset>
    3030    <WholeProgramOptimization>true</WholeProgramOptimization>
    3131    <CharacterSet>Unicode</CharacterSet>
  • trunk/Utilities/DirectShowReferenceSource/Sample/MfGenerate/Application.cpp

    r769 r823  
    11////////////////////////////////////////////////////////////
    2 // Copyright (C) Roman Ryltsov, 2015-2017
     2// Copyright (C) Roman Ryltsov, 2015-2018
    33// Created by Roman Ryltsov roman@alax.info
    44//
     
    3838                #pragma region Media Source
    3939                CComQIPtr<IMFMediaSource> pMediaSource;
     40
    4041                //{
    4142                //      static const LPCTSTR g_pszPath =
     
    6869
    6970                const SIZE g_Extent = { 1920, 1080 };
    70                 const LONG g_nFrameRateNumerator = 25 * 1000; // frames/second
     71                const LONG g_nFrameRateNumerator = 50 * 1000; // frames/second
    7172                const LONG g_nFrameRateDenominator = 1000;
    7273                const LONG g_nDuration = 1 * 60; // minutes
    73                 const LONG g_nBitrate = (2 << 10) * 1000; // 2 MBps
     74                const LONG g_nBitrate = (10 * 1000) * 1000; // 10 MBps
    7475
    7576                //const SIZE g_Extent = { 4096, 2304 };
     
    7879                //const LONG g_nDuration = 5 * 60; // 5 minutes
    7980                //const LONG g_nBitrate = (2 << 10) * 1000; // 2 MBps
     81
     82                #pragma region DXGI Device Manager
     83                static SIZE_T g_nDxgiAdapterIndex = 0;
     84                MF::CDxgiDeviceManager pDxgiDeviceManager;
     85                {
     86                        #pragma region DXGI Adapter
     87                        DXGI::CFactory2 pFactory2;
     88                        pFactory2.DebugCreate();
     89                        CRoArrayT<DXGI::CAdapter1> AdapterArray;
     90                        _A(pFactory2.EnumerateAdapters(AdapterArray) == 3);
     91                        DXGI::CAdapter1& pAdapter1 = AdapterArray[g_nDxgiAdapterIndex];
     92                        #pragma region D3D11 Device
     93                        CComPtr<ID3D11Device> pDevice;
     94                        UINT nFlags = D3D11_CREATE_DEVICE_VIDEO_SUPPORT;
     95                        #if defined(_DEBUG)
     96                                nFlags |= D3D11_CREATE_DEVICE_DEBUG;
     97                        #endif // defined(_DEBUG)
     98                        static const D3D_FEATURE_LEVEL g_pFeatureLevels[] =
     99                        {
     100                                D3D_FEATURE_LEVEL_12_1,
     101                                D3D_FEATURE_LEVEL_12_0,
     102                                D3D_FEATURE_LEVEL_11_1,
     103                                D3D_FEATURE_LEVEL_11_0,
     104                                D3D_FEATURE_LEVEL_10_1,
     105                                D3D_FEATURE_LEVEL_10_0,
     106                                D3D_FEATURE_LEVEL_9_3,
     107                                D3D_FEATURE_LEVEL_9_2,
     108                                D3D_FEATURE_LEVEL_9_1,
     109                        };
     110                        D3D_FEATURE_LEVEL FeatureLevel;
     111                        CComPtr<ID3D11DeviceContext> pDeviceContext;
     112                        // SUGG: Reuse CVideoInput's CreateDevice doing D3D11CreateDevice
     113                        __C(D3D11CreateDevice(pAdapter1, D3D_DRIVER_TYPE_UNKNOWN, NULL, nFlags, g_pFeatureLevels, DIM(g_pFeatureLevels), D3D11_SDK_VERSION, &pDevice, &FeatureLevel, &pDeviceContext));
     114                        const CComQIPtr<ID3D11Multithread> pMultithread = pDevice;
     115                        __D(pMultithread, E_NOINTERFACE);
     116                        pMultithread->SetMultithreadProtected(TRUE);
     117                        #pragma endregion
     118                        #pragma endregion
     119                        pDxgiDeviceManager.Create();
     120                        pDxgiDeviceManager.Reset(pDevice);
     121                }
     122                #pragma endregion
    80123
    81124                {
     
    91134                #pragma endregion
    92135                CComPtr<IMFSourceReader> pSourceReader;
    93                 __C(MFCreateSourceReaderFromMediaSource(pMediaSource, NULL, &pSourceReader));
     136                {
     137                        MF::CAttributes pAttributes;
     138                        if(pDxgiDeviceManager)
     139                        {
     140                                pAttributes.Create(4);
     141                                pAttributes[MF_READWRITE_D3D_OPTIONAL] = (UINT32) 0;
     142                                pAttributes[MF_SOURCE_READER_D3D_MANAGER] = (IMFDXGIDeviceManager*) pDxgiDeviceManager;
     143                        }
     144                        __C(MFCreateSourceReaderFromMediaSource(pMediaSource, pAttributes, &pSourceReader));
     145                }
    94146                MF::CMediaType pMediaType;
    95147                __C(pSourceReader->GetCurrentMediaType(MF_SOURCE_READER_FIRST_VIDEO_STREAM, &pMediaType));
     
    99151                const CString sFileName = AtlFormatString(_T("%04d%02d%02d-%02d%02d%02d.mp4"), Time.wYear, Time.wMonth, Time.wDay, Time.wHour, Time.wMinute, Time.wSecond);
    100152                CComPtr<IMFSinkWriter> pSinkWriter;
    101                 __C(MFCreateSinkWriterFromURL(Combine(GetPathDirectory(GetModulePath()), sFileName), NULL, NULL, &pSinkWriter));
     153                {
     154                        MF::CAttributes pAttributes;
     155                        if(pDxgiDeviceManager)
     156                        {
     157                                pAttributes.Create(4);
     158                                pAttributes[MF_READWRITE_D3D_OPTIONAL] = (UINT32) 0;
     159                                pAttributes[MF_SINK_WRITER_D3D_MANAGER] = (IMFDXGIDeviceManager*) pDxgiDeviceManager;
     160                        }
     161                        __C(MFCreateSinkWriterFromURL(Combine(GetPathDirectory(GetModulePath()), sFileName), NULL, pAttributes, &pSinkWriter));
     162                }
    102163                MF::CMediaType pWriterMediaType;
    103164                pWriterMediaType.Create();
     
    105166                pWriterMediaType[MF_MT_MAJOR_TYPE] = MFMediaType_Video;
    106167                pWriterMediaType[MF_MT_SUBTYPE] = MFVideoFormat_H264;
     168                pWriterMediaType.CopyFrom(pMediaType, MF_MT_FRAME_RATE);
     169                pWriterMediaType.CopyFrom(pMediaType, MF_MT_FRAME_SIZE);
     170                pWriterMediaType.CopyFrom(pMediaType, MF_MT_INTERLACE_MODE);
     171                pWriterMediaType.CopyFrom(pMediaType, MF_MT_PIXEL_ASPECT_RATIO);
    107172                pWriterMediaType[MF_MT_AVG_BITRATE] = (UINT32) g_nBitrate;
    108                 pWriterMediaType[MF_MT_FRAME_RATE] = pMediaType.GetUINT64(MF_MT_FRAME_RATE);
    109                 pWriterMediaType[MF_MT_FRAME_SIZE] = pMediaType.GetUINT64(MF_MT_FRAME_SIZE);
    110                 pWriterMediaType[MF_MT_INTERLACE_MODE] = pMediaType.GetUINT32(MF_MT_INTERLACE_MODE);
    111                 pWriterMediaType[MF_MT_PIXEL_ASPECT_RATIO] = pMediaType.GetUINT64(MF_MT_PIXEL_ASPECT_RATIO);
    112 
    113         //pWriterMediaType[MF_MT_MPEG2_PROFILE] = (UINT32) eAVEncH264VProfile_High;
    114 
     173                //pWriterMediaType[MF_MT_MPEG2_PROFILE] = (UINT32) eAVEncH264VProfile_High;
    115174                pWriterMediaType.Trace();
    116175                DWORD nWriterStreamIndex;
    117176                __C(pSinkWriter->AddStream(pWriterMediaType, &nWriterStreamIndex));
    118177                // NOTE: Sink Writer Attributes https://msdn.microsoft.com/en-us/library/windows/desktop/dd389284
     178
     179                //class __declspec(uuid("4E498B6F-7DCA-403E-A523-912A73943341")) NvEncoderTransform;
     180                //MFT_REGISTER_TYPE_INFO pInputTypeInformation[] = { { MFMediaType_Video, MFVideoFormat_ARGB32 } };
     181                //MFT_REGISTER_TYPE_INFO pOutputTypeInformation[] = { { MFMediaType_Video, MFVideoFormat_H264 } };
     182                //__C(MFTRegisterLocalByCLSID(__uuidof(NvEncoderTransform), MFT_CATEGORY_VIDEO_ENCODER, L"Rainway H.264 Encoder for NVIDIA HW", MFT_ENUM_FLAG_ASYNCMFT, DIM(pInputTypeInformation), pInputTypeInformation, DIM(pOutputTypeInformation), pOutputTypeInformation));
    119183                {
    120184                        MF::CAttributes pAttributes;
     
    123187                        __C(pSinkWriter->SetInputMediaType(nWriterStreamIndex, pMediaType, pAttributes));
    124188                }
    125 
    126         //CRoArrayT<CComPtr<IMFTransform>> TransformArray;
    127         //MF::CSinkWriterHelper::GetTransforms(pSinkWriter, nWriterStreamIndex, TransformArray);
    128         //_A(!TransformArray.IsEmpty());
    129         //MF::CCodecApi pCodecApi(TransformArray[TransformArray.GetCount() - 1]);
    130         //// NOTE: H.264 Video Encoder https://msdn.microsoft.com/en-us/library/windows/desktop/dd797816
    131         //pCodecApi[CODECAPI_AVEncMPVGOPSize] = (UINT32) 16;
    132         //pCodecApi[CODECAPI_AVEncMPVDefaultBPictureCount] = (UINT32) 3;
    133 
     189                MF::CSinkWriterHelper::TraceTransformsT<MF::CSinkWriterHelper::CVideoTraceTraits>(pSinkWriter);
     190
     191                CRoArrayT<CComPtr<IMFTransform>> TransformArray;
     192                MF::CSinkWriterHelper::GetTransforms(pSinkWriter, nWriterStreamIndex, TransformArray);
     193                _A(!TransformArray.IsEmpty());
     194                MF::CCodecApi pCodecApi(TransformArray[TransformArray.GetCount() - 1]);
     195                pCodecApi[CODECAPI_AVEncCommonRateControlMode] = (UINT32) eAVEncCommonRateControlMode_CBR;
     196                pCodecApi[CODECAPI_AVEncCommonMeanBitRate] = (UINT32) g_nBitrate;
     197                pCodecApi[CODECAPI_AVEncMPVGOPSize] = (UINT32) 1;
     198                //pCodecApi[CODECAPI_AVEncMPVDefaultBPictureCount] = (UINT32) 0;
     199
     200                const ULONG nTimeA = GetTickCount();
    134201                __C(pSinkWriter->BeginWriting());
    135202                for(; ; )
     
    143210                        {
    144211                                pSample.Trace();
     212                                #pragma region Re-Configuration
     213                                #if defined(_DEBUG)
     214                                        static INT g_nState = 0;
     215                                        if(!g_nState && pSample.GetTime() >= 30000 * 10000i64)
     216                                        {
     217                                                g_nState = 1;
     218                                                const CComQIPtr<IMFSinkWriterEncoderConfig> pSinkWriterEncoderConfig = pSinkWriter;
     219                                                __D(pSinkWriterEncoderConfig, E_NOINTERFACE);
     220                                                MF::CAttributes pAttributes;
     221                                                pAttributes.Create(4);
     222                                                //pAttributes[CODECAPI_AVEncCommonRateControlMode] = (UINT32) eAVEncCommonRateControlMode_CBR;
     223                                                pAttributes[CODECAPI_AVEncCommonMeanBitRate] = (UINT32) g_nBitrate / 4;
     224                                                // NOTE: MF_SOURCE_READER_FIRST_VIDEO_STREAM results in MF_E_INVALIDSTREAMNUMBER
     225                                                __C(pSinkWriterEncoderConfig->PlaceEncodingParameters(0, pAttributes));
     226                                                // SUGG: Check IMFSinkWriterEncoderConfig::SetTargetMediaType as well
     227                                        }
     228                                #endif // defined(_DEBUG)
     229                                #pragma endregion
    145230                                __C(pSinkWriter->WriteSample(nWriterStreamIndex, pSample));
    146231                        }
     
    152237                }
    153238                __C(pSourceReader->Flush(MF_SOURCE_READER_ALL_STREAMS));
     239                const ULONG nTimeB = GetTickCount();
     240                _tprintf(_T("Elapsed Time: %.2f seconds\n"), (DOUBLE) (nTimeB - nTimeA) / 1E3);
    154241                __C(pSinkWriter->Finalize());
    155242        }
  • trunk/Utilities/DirectShowReferenceSource/Sample/MfGenerate/MfGenerate.vcxproj

    r769 r823  
    11<?xml version="1.0" encoding="utf-8"?>
    2 <Project DefaultTargets="Build" ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
     2<Project DefaultTargets="Build" ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
    33  <ItemGroup Label="ProjectConfigurations">
    44    <ProjectConfiguration Include="Debug|Win32">
     
    2929    <ConfigurationType>Application</ConfigurationType>
    3030    <UseDebugLibraries>true</UseDebugLibraries>
    31     <PlatformToolset>v140</PlatformToolset>
     31    <PlatformToolset>v141</PlatformToolset>
    3232    <CharacterSet>Unicode</CharacterSet>
    3333  </PropertyGroup>
     
    3535    <ConfigurationType>Application</ConfigurationType>
    3636    <UseDebugLibraries>true</UseDebugLibraries>
    37     <PlatformToolset>v140</PlatformToolset>
     37    <PlatformToolset>v141</PlatformToolset>
    3838    <CharacterSet>Unicode</CharacterSet>
    3939  </PropertyGroup>
     
    4141    <ConfigurationType>Application</ConfigurationType>
    4242    <UseDebugLibraries>false</UseDebugLibraries>
    43     <PlatformToolset>v140</PlatformToolset>
     43    <PlatformToolset>v141</PlatformToolset>
    4444    <WholeProgramOptimization>true</WholeProgramOptimization>
    4545    <CharacterSet>Unicode</CharacterSet>
     
    4848    <ConfigurationType>Application</ConfigurationType>
    4949    <UseDebugLibraries>false</UseDebugLibraries>
    50     <PlatformToolset>v140</PlatformToolset>
     50    <PlatformToolset>v141</PlatformToolset>
    5151    <WholeProgramOptimization>true</WholeProgramOptimization>
    5252    <CharacterSet>Unicode</CharacterSet>
  • trunk/Utilities/DirectShowReferenceSource/Sample/MfGenerate2/Application.cpp

    r770 r823  
    4949                //}
    5050                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
     51                const BOOL g_bVideo = TRUE;
     52                const SIZE g_Extent =
     53                        { 1920, 1080 };
     54                        //{ 7680 / 2, 4320 / 2 };
     55                        //{ 7680, 4320 };
     56                const LONG g_nFrameRateNumerator = 50000;
     57                const LONG g_nFrameRateDenominator = 1000;
     58                const LONG g_nVideoBitrate = (10 * 1000) * 1000; // MBps
     59                const BOOL g_bAudio = FALSE;
    5660                const LONG g_nSampleRate = 48000;
    5761                const LONG g_nChannelCount = 1;
    5862                const LONG g_nBitDepth = 16;
    59                 const LONG g_nAudioBitrate = 20 * 1000;
     63                const LONG g_nAudioBitrate = 20 * 1000; // kBps
     64                const LONG g_nDuration = 1 * 60; // minutes
    6065                #pragma region Video
    61                 if(TRUE)
     66                if(g_bVideo)
    6267                {
    6368                        using namespace AlaxInfoDirectShowReferenceSource;
    6469                        CComPtr<IVideoMediaSource> pSource;
    6570                        __C(pSource.CoCreateInstance(__uuidof(VideoMediaSource)));
    66                         __C(pSource->SetMediaType(g_Extent.cx, g_Extent.cy, CComVariant(_PersistHelper::StringFromIdentifier(MEDIASUBTYPE_ARGB32))));
     71                        __C(pSource->SetMediaType(g_Extent.cx, g_Extent.cy, CComVariant(_PersistHelper::StringFromIdentifier(MEDIASUBTYPE_RGB32))));
    6772                        //__C(pSource->SetMediaTypeAspectRatio(...));
    6873                        __C(pSource->SetMediaTypeRate(g_nFrameRateNumerator, g_nFrameRateDenominator));
     
    7277                #pragma endregion
    7378                #pragma region Audio
    74                 if(TRUE)
     79                if(g_bAudio)
    7580                {
    7681                        using namespace AlaxInfoDirectShowReferenceSource;
     
    146151                        #pragma endregion
    147152                        MF::CAttributes pAttributes;
    148                         pAttributes.Create(1);
    149                         pAttributes[MF_TRANSCODE_CONTAINERTYPE] = MFTranscodeContainerType_MPEG4;
     153                        pAttributes.Create(2);
     154                        pAttributes[MF_TRANSCODE_CONTAINERTYPE] =
     155                                MFTranscodeContainerType_MPEG4;
     156                                //MFTranscodeContainerType_FMPEG4;
     157                        pAttributes[MF_TRANSCODE_TOPOLOGYMODE] = (UINT32) MF_TRANSCODE_TOPOLOGYMODE_HARDWARE_ALLOWED;
    150158                        __C(pTranscodeProfile->SetContainerAttributes(pAttributes));
    151159                }
     
    233241        return 0;
    234242}
    235 
  • trunk/Utilities/DirectShowReferenceSource/Sample/MfGenerate2/MfGenerate2.vcxproj

    r770 r823  
    11<?xml version="1.0" encoding="utf-8"?>
    2 <Project DefaultTargets="Build" ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
     2<Project DefaultTargets="Build" ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
    33  <ItemGroup Label="ProjectConfigurations">
    44    <ProjectConfiguration Include="Debug|Win32">
     
    2929    <ConfigurationType>Application</ConfigurationType>
    3030    <UseDebugLibraries>true</UseDebugLibraries>
    31     <PlatformToolset>v140</PlatformToolset>
     31    <PlatformToolset>v141</PlatformToolset>
    3232    <CharacterSet>Unicode</CharacterSet>
    3333  </PropertyGroup>
     
    3535    <ConfigurationType>Application</ConfigurationType>
    3636    <UseDebugLibraries>true</UseDebugLibraries>
    37     <PlatformToolset>v140</PlatformToolset>
     37    <PlatformToolset>v141</PlatformToolset>
    3838    <CharacterSet>Unicode</CharacterSet>
    3939  </PropertyGroup>
     
    4141    <ConfigurationType>Application</ConfigurationType>
    4242    <UseDebugLibraries>false</UseDebugLibraries>
    43     <PlatformToolset>v140</PlatformToolset>
     43    <PlatformToolset>v141</PlatformToolset>
    4444    <WholeProgramOptimization>true</WholeProgramOptimization>
    4545    <CharacterSet>Unicode</CharacterSet>
     
    4848    <ConfigurationType>Application</ConfigurationType>
    4949    <UseDebugLibraries>false</UseDebugLibraries>
    50     <PlatformToolset>v140</PlatformToolset>
     50    <PlatformToolset>v141</PlatformToolset>
    5151    <WholeProgramOptimization>true</WholeProgramOptimization>
    5252    <CharacterSet>Unicode</CharacterSet>
Note: See TracChangeset for help on using the changeset viewer.