• R/O
  • HTTP
  • SSH
  • HTTPS

mfsample: Commit

Media Foundationを使用して音声から動画を自動生成するツールを作ってみます。


Commit MetaInfo

Revision092458570d187e69d08318e8a315de07a06e6338 (tree)
Time2013-02-19 06:24:35
Authorsfpg <sfpg@user...>
Commitersfpg

Log Message

コンパイルが通ったバージョン。まだ全然できていない。

Change Summary

Incremental Difference

--- a/SF.props
+++ b/SF.props
@@ -3,7 +3,7 @@
33 <ImportGroup Label="PropertySheets" />
44 <PropertyGroup Label="UserMacros" />
55 <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>
77 </PropertyGroup>
88 <PropertyGroup>
99 <LibraryPath>H:\libs\zlib125\zlib-1.2.5;H:\libs\boost\lib;$(LibraryPath)</LibraryPath>
--- a/mfsample/mfsample.vcxproj
+++ b/mfsample/mfsample.vcxproj
@@ -159,7 +159,9 @@
159159 <ClCompile Include="info_tab_dialog.cpp" />
160160 <ClCompile Include="jumplist.cpp" />
161161 <ClCompile Include="logger.cpp" />
162+ <ClCompile Include="media_foundation.cpp" />
162163 <ClCompile Include="player.cpp" />
164+ <ClCompile Include="sfmf.cpp" />
163165 <ClCompile Include="sf_com.cpp" />
164166 <ClCompile Include="sf_windows.cpp" />
165167 <ClCompile Include="stdafx.cpp">
@@ -182,9 +184,11 @@
182184 <ClInclude Include="info_tab_dialog.h" />
183185 <ClInclude Include="jumplist.h" />
184186 <ClInclude Include="logger.h" />
187+ <ClInclude Include="media_foundation.h" />
185188 <ClInclude Include="message_loop.h" />
186189 <ClInclude Include="player.h" />
187190 <ClInclude Include="resource.h" />
191+ <ClInclude Include="sfmf.h" />
188192 <ClInclude Include="sf_com.h" />
189193 <ClInclude Include="sf_memory.h" />
190194 <ClInclude Include="sf_windows.h" />
--- a/mfsample/player.cpp
+++ b/mfsample/player.cpp
@@ -9,6 +9,7 @@
99 #include "stdafx.h"
1010 #include "Player.h"
1111 #include <assert.h>
12+#include <iostream>
1213
1314 #if _DEBUG
1415 #define _CRTDBG_MAP_ALLOC
@@ -16,36 +17,13 @@
1617 #define new new(_NORMAL_BLOCK, __FILE__, __LINE__)
1718 #endif
1819
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"
2421
2522 //Mf.lib Mfidl.h
2623 namespace sf {
2724 namespace player {
28- template <class Q>
29- HRESULT GetEventObject(IMFMediaEvent *pEvent, Q **ppObject)
30- {
31- *ppObject = NULL; // zero output
25+ void print_mft();
3226
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- }
4927
5028 IMFMediaSourcePtr CreateMediaSource(const std::wstring& pszURL);
5129
@@ -66,6 +44,7 @@ namespace sf {
6644 throw win32_error_exception(E_OUTOFMEMORY);
6745 }
6846 p->process_event(ev::Init());
47+ print_mft();
6948 // p->processInitialize();
7049 return p;
7150 }
@@ -180,7 +159,6 @@ namespace sf {
180159 // {
181160 // throw win32_error_exception(E_UNEXPECTED);
182161 // }
183-
184162 THROW_IF_ERR(m_pSession->Pause());
185163 OnPause()(static_cast<this_type&>(*this));
186164
@@ -678,5 +656,69 @@ namespace sf {
678656 // Return the IMFTopology pointer to the caller.
679657 return pTopology;
680658 }
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+ }
681683 }
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+
682724 }
\ No newline at end of file
--- a/mfsample/player.h
+++ b/mfsample/player.h
@@ -10,31 +10,13 @@
1010 #include <assert.h>
1111 #include <strsafe.h>
1212
13-// Media Foundation headers
14-#include <mfapi.h>
15-#include <mfidl.h>
16-#include <mferror.h>
17-#include <evr.h>
13+#include "sfmf.h"
1814
1915 #include "resource.h"
2016
2117 #include <boost/msm/back/state_machine.hpp>
2218 #include <boost/msm/front/state_machine_def.hpp>
2319
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-
3820 namespace sf {
3921 namespace player {
4022 namespace msmf = boost::msm::front;
@@ -62,30 +44,6 @@ namespace sf {
6244 struct Stopped : msmf::state<> {};// セッションは停止している(演奏可能状態である)。
6345 struct Closing : msmf::state<> {};// アプリケーションはセッションを閉じたが、MESessionClosed状態を待っている。
6446
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-
8947 namespace ev
9048 {
9149 struct Init {}; // 初期化イベント
@@ -166,12 +124,13 @@ namespace sf {
166124
167125 // Playback
168126 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&)
175134 {
176135 OnOpenComplete()(static_cast<this_type&>(*this));
177136 }
@@ -220,11 +179,11 @@ struct transition_table : boost::mpl::vector
220179 a_row <Started ,ev::Pause ,Paused ,&sf::player::Player_::pause >,
221180 a_row <Started ,ev::Stop ,Stopped ,&sf::player::Player_::stop >,
222181 _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 >,
224183 a_row <Paused ,ev::Stop ,Stopped ,&sf::player::Player_::stop >,
225184 a_row <Stopped ,ev::Play ,Started ,&sf::player::Player_::play >,
226185 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>
228187 >
229188 {};
230189 typedef Closed initial_state;
@@ -236,6 +195,12 @@ struct transition_table : boost::mpl::vector
236195 throw exception(L"No Transition");
237196 }
238197
198+ template <class FSM>
199+ void no_transition(ev::Close const& e, FSM&,int state)
200+ {
201+ shutdown(ev::Close());
202+ }
203+
239204 };
240205
241206 typedef boost::msm::back::state_machine< Player_ > Player;
--- a/mfsample/stdafx.h
+++ b/mfsample/stdafx.h
@@ -151,3 +151,7 @@
151151 #include <agents.h>
152152
153153 #define _WRL_PTR_TYPEDEF(x) typedef Microsoft::WRL::ComPtr<x> x ## Ptr
154+
155+
156+//_WRL_PTR_TYPEDEF();
157+//_WRL_PTR_TYPEDEF();
--- a/mfsample/toplevel_window.cpp
+++ b/mfsample/toplevel_window.cpp
@@ -371,21 +371,21 @@ namespace sf
371371 sf::player::PlayerPtr player = application::instance()->Player();
372372 player->OnOpenComplete().connect([this](sf::player::Player &) -> void
373373 {
374- this->player_ready();
374+ player_ready();
375375 }
376376 );
377377
378378 // 再生時イベントの処理
379379 player->OnStart().connect([this](sf::player::Player &) -> void
380380 {
381- this->play_();
381+ play_();
382382 }
383383 );
384384
385385 // Pauseイベントの処理
386386 player->OnPause().connect([this](sf::player::Player &) -> void
387387 {
388- this->pause_();
388+ pause_();
389389 }
390390 );
391391
Show on old repository browser