Media Foundationを使用して音声から動画を自動生成するツールを作ってみます。
Revision | 092458570d187e69d08318e8a315de07a06e6338 (tree) |
---|---|
Time | 2013-02-19 06:24:35 |
Author | sfpg <sfpg@user...> |
Commiter | sfpg |
コンパイルが通ったバージョン。まだ全然できていない。
@@ -3,7 +3,7 @@ | ||
3 | 3 | <ImportGroup Label="PropertySheets" /> |
4 | 4 | <PropertyGroup Label="UserMacros" /> |
5 | 5 | <PropertyGroup> |
6 | - <IncludePath>H:\libs\DirectXTK\Inc;H:\libs\boost\include\boost-1_52;H:\libs\xbyak\xbyak;H:\libs\zlib125\zlib-1.2.5;H:\libs\lpng150\lpng150;$(IncludePath)</IncludePath> | |
6 | + <IncludePath>H:\libs\DirectXTK\Inc;H:\libs\boost\include\boost-1_53;H:\libs\xbyak\xbyak;H:\libs\zlib125\zlib-1.2.5;H:\libs\lpng150\lpng150;$(IncludePath)</IncludePath> | |
7 | 7 | </PropertyGroup> |
8 | 8 | <PropertyGroup> |
9 | 9 | <LibraryPath>H:\libs\zlib125\zlib-1.2.5;H:\libs\boost\lib;$(LibraryPath)</LibraryPath> |
@@ -159,7 +159,9 @@ | ||
159 | 159 | <ClCompile Include="info_tab_dialog.cpp" /> |
160 | 160 | <ClCompile Include="jumplist.cpp" /> |
161 | 161 | <ClCompile Include="logger.cpp" /> |
162 | + <ClCompile Include="media_foundation.cpp" /> | |
162 | 163 | <ClCompile Include="player.cpp" /> |
164 | + <ClCompile Include="sfmf.cpp" /> | |
163 | 165 | <ClCompile Include="sf_com.cpp" /> |
164 | 166 | <ClCompile Include="sf_windows.cpp" /> |
165 | 167 | <ClCompile Include="stdafx.cpp"> |
@@ -182,9 +184,11 @@ | ||
182 | 184 | <ClInclude Include="info_tab_dialog.h" /> |
183 | 185 | <ClInclude Include="jumplist.h" /> |
184 | 186 | <ClInclude Include="logger.h" /> |
187 | + <ClInclude Include="media_foundation.h" /> | |
185 | 188 | <ClInclude Include="message_loop.h" /> |
186 | 189 | <ClInclude Include="player.h" /> |
187 | 190 | <ClInclude Include="resource.h" /> |
191 | + <ClInclude Include="sfmf.h" /> | |
188 | 192 | <ClInclude Include="sf_com.h" /> |
189 | 193 | <ClInclude Include="sf_memory.h" /> |
190 | 194 | <ClInclude Include="sf_windows.h" /> |
@@ -9,6 +9,7 @@ | ||
9 | 9 | #include "stdafx.h" |
10 | 10 | #include "Player.h" |
11 | 11 | #include <assert.h> |
12 | +#include <iostream> | |
12 | 13 | |
13 | 14 | #if _DEBUG |
14 | 15 | #define _CRTDBG_MAP_ALLOC |
@@ -16,36 +17,13 @@ | ||
16 | 17 | #define new new(_NORMAL_BLOCK, __FILE__, __LINE__) |
17 | 18 | #endif |
18 | 19 | |
19 | -#pragma comment(lib, "shlwapi") | |
20 | -#pragma comment(lib,"Mfplat.lib") | |
21 | -#pragma comment(lib,"Mf.lib") | |
22 | -#pragma comment(lib,"Mfuuid.lib") | |
23 | -#pragma comment(lib,"Strmiids.lib") | |
20 | +#include "sf_memory.h" | |
24 | 21 | |
25 | 22 | //Mf.lib Mfidl.h |
26 | 23 | namespace sf { |
27 | 24 | namespace player { |
28 | - template <class Q> | |
29 | - HRESULT GetEventObject(IMFMediaEvent *pEvent, Q **ppObject) | |
30 | - { | |
31 | - *ppObject = NULL; // zero output | |
25 | + void print_mft(); | |
32 | 26 | |
33 | - PROPVARIANT var; | |
34 | - HRESULT hr = pEvent->GetValue(&var); | |
35 | - if (SUCCEEDED(hr)) | |
36 | - { | |
37 | - if (var.vt == VT_UNKNOWN) | |
38 | - { | |
39 | - hr = var.punkVal->QueryInterface(ppObject); | |
40 | - } | |
41 | - else | |
42 | - { | |
43 | - hr = MF_E_INVALIDTYPE; | |
44 | - } | |
45 | - PropVariantClear(&var); | |
46 | - } | |
47 | - return hr; | |
48 | - } | |
49 | 27 | |
50 | 28 | IMFMediaSourcePtr CreateMediaSource(const std::wstring& pszURL); |
51 | 29 |
@@ -66,6 +44,7 @@ namespace sf { | ||
66 | 44 | throw win32_error_exception(E_OUTOFMEMORY); |
67 | 45 | } |
68 | 46 | p->process_event(ev::Init()); |
47 | + print_mft(); | |
69 | 48 | // p->processInitialize(); |
70 | 49 | return p; |
71 | 50 | } |
@@ -180,7 +159,6 @@ namespace sf { | ||
180 | 159 | // { |
181 | 160 | // throw win32_error_exception(E_UNEXPECTED); |
182 | 161 | // } |
183 | - | |
184 | 162 | THROW_IF_ERR(m_pSession->Pause()); |
185 | 163 | OnPause()(static_cast<this_type&>(*this)); |
186 | 164 |
@@ -678,5 +656,69 @@ namespace sf { | ||
678 | 656 | // Return the IMFTopology pointer to the caller. |
679 | 657 | return pTopology; |
680 | 658 | } |
659 | + | |
660 | + void print_mft_(const GUID& guid,std::wfstream& out) | |
661 | + { | |
662 | + co_task_memory<IMFActivate*> activate; | |
663 | + | |
664 | + UINT32 count = 0; | |
665 | + | |
666 | + HRESULT hr = MFTEnumEx(guid,MFT_ENUM_FLAG_ALL,NULL,NULL,&activate,&count); | |
667 | + | |
668 | + if(SUCCEEDED(hr) && count > 0) | |
669 | + { | |
670 | + for(int i = 0; i < count;++i) | |
671 | + { | |
672 | + UINT32 l = 0; | |
673 | + UINT32 l1 = 0; | |
674 | + activate.get()[i]->GetStringLength(MFT_FRIENDLY_NAME_Attribute,&l); | |
675 | + std::unique_ptr<wchar_t[]> name(new wchar_t[l+1]); | |
676 | + memset(name.get(),0,l+1); | |
677 | + hr = activate.get()[i]->GetString(MFT_FRIENDLY_NAME_Attribute,name.get(),l+1,&l1); | |
678 | + out << name.get() << std::endl; | |
679 | + activate.get()[i]->Release(); | |
680 | + } | |
681 | + //CoTaskMemFree(activate); | |
682 | + } | |
681 | 683 | } |
684 | + | |
685 | + void print_mft() | |
686 | + { | |
687 | + std::wfstream out(L"MFT.txt",std::ios_base::out | std::ios_base::trunc); | |
688 | + | |
689 | + out << std::endl << "**" << L"MFT_CATEGORY_AUDIO_DECODER" << L"**" << std::endl << std::endl; | |
690 | + | |
691 | + print_mft_(MFT_CATEGORY_AUDIO_DECODER,out); | |
692 | + | |
693 | + out << std::endl << L"**" << L"MFT_CATEGORY_AUDIO_EFFECT" << L"**" << std::endl << std::endl; | |
694 | + print_mft_(MFT_CATEGORY_AUDIO_EFFECT,out); | |
695 | + | |
696 | + out << std::endl << L"**" << L"MFT_CATEGORY_AUDIO_ENCODER" << L"**" << std::endl << std::endl; | |
697 | + print_mft_(MFT_CATEGORY_AUDIO_ENCODER,out); | |
698 | + | |
699 | + out << std::endl << L"**" << L"MFT_CATEGORY_DEMULTIPLEXER" << L"**" << std::endl << std::endl; | |
700 | + print_mft_(MFT_CATEGORY_DEMULTIPLEXER,out); | |
701 | + | |
702 | + out << std::endl << L"**" << L"MFT_CATEGORY_MULTIPLEXER" << L"**" << std::endl << std::endl; | |
703 | + print_mft_(MFT_CATEGORY_MULTIPLEXER,out); | |
704 | + | |
705 | + out << std::endl << L"**" << L"MFT_CATEGORY_OTHER" << L"**" << std::endl << std::endl; | |
706 | + print_mft_(MFT_CATEGORY_OTHER,out); | |
707 | + | |
708 | + out << std::endl << L"**" << L"MFT_CATEGORY_VIDEO_DECODER" << L"**" << std::endl << std::endl; | |
709 | + print_mft_(MFT_CATEGORY_VIDEO_DECODER,out); | |
710 | + | |
711 | + out << std::endl << L"**" << L"MFT_CATEGORY_VIDEO_EFFECT" << L"**" << std::endl << std::endl; | |
712 | + print_mft_(MFT_CATEGORY_VIDEO_EFFECT,out); | |
713 | + | |
714 | + out << std::endl << L"**" << L"MFT_CATEGORY_VIDEO_ENCODER" << L"**" << std::endl << std::endl; | |
715 | + print_mft_(MFT_CATEGORY_VIDEO_ENCODER,out); | |
716 | + | |
717 | + out << std::endl << L"**" << L"MFT_CATEGORY_VIDEO_PROCESSOR" << L"**" << std::endl << std::endl; | |
718 | + print_mft_(MFT_CATEGORY_VIDEO_PROCESSOR,out); | |
719 | + | |
720 | + out.close(); | |
721 | + } | |
722 | +} | |
723 | + | |
682 | 724 | } |
\ No newline at end of file |
@@ -10,31 +10,13 @@ | ||
10 | 10 | #include <assert.h> |
11 | 11 | #include <strsafe.h> |
12 | 12 | |
13 | -// Media Foundation headers | |
14 | -#include <mfapi.h> | |
15 | -#include <mfidl.h> | |
16 | -#include <mferror.h> | |
17 | -#include <evr.h> | |
13 | +#include "sfmf.h" | |
18 | 14 | |
19 | 15 | #include "resource.h" |
20 | 16 | |
21 | 17 | #include <boost/msm/back/state_machine.hpp> |
22 | 18 | #include <boost/msm/front/state_machine_def.hpp> |
23 | 19 | |
24 | -_WRL_PTR_TYPEDEF(IMFMediaSession); | |
25 | -_WRL_PTR_TYPEDEF(IMFMediaSource); | |
26 | -_WRL_PTR_TYPEDEF(IMFVideoDisplayControl); | |
27 | -_WRL_PTR_TYPEDEF(IMFTopology); | |
28 | -_WRL_PTR_TYPEDEF(IMFPresentationDescriptor); | |
29 | -_WRL_PTR_TYPEDEF(IMFMediaEvent); | |
30 | -_WRL_PTR_TYPEDEF(IMFSourceResolver); | |
31 | -_WRL_PTR_TYPEDEF(IMFStreamDescriptor); | |
32 | -_WRL_PTR_TYPEDEF(IMFTopologyNode); | |
33 | -_WRL_PTR_TYPEDEF(IMFActivate); | |
34 | -_WRL_PTR_TYPEDEF(IMFMediaTypeHandler); | |
35 | -//_WRL_PTR_TYPEDEF(); | |
36 | -//_WRL_PTR_TYPEDEF(); | |
37 | - | |
38 | 20 | namespace sf { |
39 | 21 | namespace player { |
40 | 22 | namespace msmf = boost::msm::front; |
@@ -62,30 +44,6 @@ namespace sf { | ||
62 | 44 | struct Stopped : msmf::state<> {};// セッションは停止している(演奏可能状態である)。 |
63 | 45 | struct Closing : msmf::state<> {};// アプリケーションはセッションを閉じたが、MESessionClosed状態を待っている。 |
64 | 46 | |
65 | - // プロパティ用バリアントのラッパ | |
66 | - struct prop_variant | |
67 | - { | |
68 | - prop_variant() | |
69 | - { | |
70 | - PropVariantInit(&value_);// | |
71 | - } | |
72 | - | |
73 | - ~prop_variant() | |
74 | - { | |
75 | - PropVariantClear(&value_); | |
76 | - } | |
77 | - | |
78 | - PROPVARIANT* get(){ return &value_;}; | |
79 | - | |
80 | - PROPVARIANT* operator &(){return get();} | |
81 | - | |
82 | - operator PROPVARIANT*() {return get();} | |
83 | - | |
84 | - private: | |
85 | - PROPVARIANT value_; | |
86 | - }; | |
87 | - | |
88 | - | |
89 | 47 | namespace ev |
90 | 48 | { |
91 | 49 | struct Init {}; // 初期化イベント |
@@ -166,12 +124,13 @@ namespace sf { | ||
166 | 124 | |
167 | 125 | // Playback |
168 | 126 | void initialize( ev::Init const& ev); |
169 | - void open_url( ev::OpenURL const& openurl); | |
170 | - void play( ev::Play const& ev); | |
171 | - void pause( ev::Pause const& ev); | |
172 | - void stop( ev::Stop const& ev); | |
173 | - void shutdown( ev::Close const& ev); | |
174 | - void open_complete(ev::OpenComplete const&) | |
127 | + void open_url( ev::OpenURL const& openurl); | |
128 | + void play( ev::Play const& ev); | |
129 | + void resume( ev::Pause const& ev){play(ev::Play());}; | |
130 | + void pause( ev::Pause const& ev); | |
131 | + void stop( ev::Stop const& ev); | |
132 | + void shutdown( ev::Close const& ev); | |
133 | + void open_complete(ev::OpenComplete const&) | |
175 | 134 | { |
176 | 135 | OnOpenComplete()(static_cast<this_type&>(*this)); |
177 | 136 | } |
@@ -220,11 +179,11 @@ struct transition_table : boost::mpl::vector | ||
220 | 179 | a_row <Started ,ev::Pause ,Paused ,&sf::player::Player_::pause >, |
221 | 180 | a_row <Started ,ev::Stop ,Stopped ,&sf::player::Player_::stop >, |
222 | 181 | _row <Started ,ev::End ,Stopped >, |
223 | - a_row <Paused ,ev::Play ,Started ,&sf::player::Player_::play >, | |
182 | + a_row <Paused ,ev::Pause ,Started ,&sf::player::Player_::resume >, | |
224 | 183 | a_row <Paused ,ev::Stop ,Stopped ,&sf::player::Player_::stop >, |
225 | 184 | a_row <Stopped ,ev::Play ,Started ,&sf::player::Player_::play >, |
226 | 185 | a_row <Stopped ,ev::OpenURL ,OpenPending ,&sf::player::Player_::open_url >//, |
227 | - // a_row <msmf::none ,ev::Close ,Closed ,&Player_::shutdown> | |
186 | + // a_row <msmf::interrupt_state ,ev::Close ,Closed ,&Player_::shutdown> | |
228 | 187 | > |
229 | 188 | {}; |
230 | 189 | typedef Closed initial_state; |
@@ -236,6 +195,12 @@ struct transition_table : boost::mpl::vector | ||
236 | 195 | throw exception(L"No Transition"); |
237 | 196 | } |
238 | 197 | |
198 | + template <class FSM> | |
199 | + void no_transition(ev::Close const& e, FSM&,int state) | |
200 | + { | |
201 | + shutdown(ev::Close()); | |
202 | + } | |
203 | + | |
239 | 204 | }; |
240 | 205 | |
241 | 206 | typedef boost::msm::back::state_machine< Player_ > Player; |
@@ -151,3 +151,7 @@ | ||
151 | 151 | #include <agents.h> |
152 | 152 | |
153 | 153 | #define _WRL_PTR_TYPEDEF(x) typedef Microsoft::WRL::ComPtr<x> x ## Ptr |
154 | + | |
155 | + | |
156 | +//_WRL_PTR_TYPEDEF(); | |
157 | +//_WRL_PTR_TYPEDEF(); |
@@ -371,21 +371,21 @@ namespace sf | ||
371 | 371 | sf::player::PlayerPtr player = application::instance()->Player(); |
372 | 372 | player->OnOpenComplete().connect([this](sf::player::Player &) -> void |
373 | 373 | { |
374 | - this->player_ready(); | |
374 | + player_ready(); | |
375 | 375 | } |
376 | 376 | ); |
377 | 377 | |
378 | 378 | // 再生時イベントの処理 |
379 | 379 | player->OnStart().connect([this](sf::player::Player &) -> void |
380 | 380 | { |
381 | - this->play_(); | |
381 | + play_(); | |
382 | 382 | } |
383 | 383 | ); |
384 | 384 | |
385 | 385 | // Pauseイベントの処理 |
386 | 386 | player->OnPause().connect([this](sf::player::Player &) -> void |
387 | 387 | { |
388 | - this->pause_(); | |
388 | + pause_(); | |
389 | 389 | } |
390 | 390 | ); |
391 | 391 |