Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "cinder/app/App.h"
- #include "cinder/app/RendererGl.h"
- #include "cinder/gl/gl.h"
- #include "ciWMFVideoPlayer.h"
- #include "cinder/Filesystem.h"
- using namespace ci;
- using namespace ci::app;
- using namespace std;
- class CinderVideoApp : public App {
- public:
- void setup() override;
- void mouseDown( MouseEvent event ) override;
- void update() override;
- void draw() override;
- private:
- void setupBlockingCreationAndLoadingOfWMFPlayer( ci::fs::path const& pathToVideo );
- void setupAsyncCreationAndLoadingofWMFPlayer( ci::fs::path const& pathToVideo );
- void setupAsyncLoadingofWMFPlayer( ci::fs::path const& pathToVideo );
- std::future<std::unique_ptr<ciWMFVideoPlayer>> asyncCreationAndLoadingOfWMFPlayer();
- std::future<void> asyncLoadingOfWMFPlayer();
- std::unique_ptr<ciWMFVideoPlayer> createWMFPlayerAndLoadVideo( gl::ContextRef ctx, ci::fs::path const& pathToVideo );
- void loadVideo( ciWMFVideoPlayer &wmfPlayer, ci::fs::path const& pathToVideo );
- std::future<std::unique_ptr<ciWMFVideoPlayer>> mAsyncCreatedWMFVideoPlayer;
- std::future<void> mAsyncLoadedWMFPlayer;
- std::unique_ptr<ciWMFVideoPlayer> mWMFPlayer;
- bool mWMFPlayerReady = false;
- };
- void CinderVideoApp::setup()
- {
- ci::fs::path videoFile = L"D:\\vjMovs\\output\\Original - Bad Audio Sync - Donald Duck's Playground-1.mp4";
- // Synchronous (Blocking) creation and loading of WMFPlayer
- //setupBlockingCreationAndLoadingOfWMFPlayer( videoFile );
- // Asynchronous (Non-blocking) creation and loading of WMFPlayer
- setupAsyncCreationAndLoadingofWMFPlayer( videoFile );
- // Synchronous creation, and asynchronous loading of WMFPlayer
- //setupAsyncLoadingofWMFPlayer( videoFile );
- }
- void CinderVideoApp::setupBlockingCreationAndLoadingOfWMFPlayer( ci::fs::path const& pathToVideo )
- {
- mWMFPlayer = std::make_unique<ciWMFVideoPlayer>();
- mWMFPlayer->loadMovie( pathToVideo );
- mWMFPlayer->play();
- mWMFPlayerReady = true;
- }
- void CinderVideoApp::setupAsyncCreationAndLoadingofWMFPlayer( ci::fs::path const& pathToVideo )
- {
- // We theorize that the problem is one of context between threads - we must share it... Let's try that...
- auto ctx = gl::env()->createSharedContext( gl::context() );
- if ( !ctx )
- assert(0);
- mAsyncCreatedWMFVideoPlayer = std::async( std::launch::async, &CinderVideoApp::createWMFPlayerAndLoadVideo, this, ctx, pathToVideo );
- }
- void CinderVideoApp::setupAsyncLoadingofWMFPlayer( ci::fs::path const& pathToVideo )
- {
- mWMFPlayer = std::make_unique<ciWMFVideoPlayer>();
- mAsyncLoadedWMFPlayer = std::async( std::launch::async, &CinderVideoApp::loadVideo, this, *mWMFPlayer, pathToVideo );
- }
- std::unique_ptr<ciWMFVideoPlayer> CinderVideoApp::createWMFPlayerAndLoadVideo( gl::ContextRef ctx, ci::fs::path const& pathToVideo )
- {
- // This only works if we can make the render context current.
- ctx->makeCurrent();
- auto wmfPlayer = std::make_unique<ciWMFVideoPlayer>();
- wmfPlayer->loadMovie( pathToVideo );
- //wmfPlayer->play();
- return std::move( wmfPlayer );
- }
- void CinderVideoApp::loadVideo( ciWMFVideoPlayer &wmfPlayer, ci::fs::path const& pathToVideo )
- {
- wmfPlayer.loadMovie( pathToVideo );
- }
- void CinderVideoApp::mouseDown( MouseEvent event )
- {
- }
- void CinderVideoApp::update()
- {
- if ( mAsyncCreatedWMFVideoPlayer.valid() )
- {
- if ( mAsyncCreatedWMFVideoPlayer.wait_for( std::chrono::seconds( 0 ) ) == std::future_status::ready )
- {
- mWMFPlayer = mAsyncCreatedWMFVideoPlayer.get();
- mWMFPlayer->play();
- mWMFPlayerReady = true;
- }
- }
- if ( mAsyncLoadedWMFPlayer.valid() )
- {
- if ( mAsyncLoadedWMFPlayer.wait_for( std::chrono::seconds( 0 ) ) == std::future_status::ready )
- {
- mWMFPlayerReady = true;
- }
- }
- if ( mWMFPlayerReady )
- mWMFPlayer->update();
- }
- void CinderVideoApp::draw()
- {
- gl::clear( Color( 0, 0, 0 ) );
- if (mWMFPlayerReady)
- mWMFPlayer->draw(10, 10);
- }
- CINDER_APP( CinderVideoApp, RendererGl )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement