Skip to content

Commit b67359a

Browse files
committed
Favoured unique_ptr over shared_ptr for MediaPlayerRef. Added new OnReady signal to notify when the source is aware of its duration and frame dimensions. Modified sample to detect ImGui and disable debug UI if not available
1 parent 498c8c5 commit b67359a

File tree

6 files changed

+36
-6
lines changed

6 files changed

+36
-6
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ but the audio related functions did _not_ like being called from the main thread
1212
way to perform a lambda on the MTA thread which seems to make it happy. `RunSynchronousInMTAThread ( ... )`.
1313

1414
There's no documentation, please just have a look at the provided sample to see the basic usage. It's all fairly straight forward
15-
video-related stuff. You should be able to just check this out into your cinder install's block's folder and off you go.
15+
video-related stuff. You should be able to just check this out into your cinder install's block's folder and off you go. The sample
16+
is built against cinder 0.9.3 to utilise the built-in imgui debug UI, but should also work with 0.9.2 without the UI
1617

1718
This was just a one night project for fun so it comes with absolutely no warranty. Hopefully it still comes in handy for someone :)
1819

samples/SimplePlayback/src/SimplePlaybackApp.cxx

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,17 @@
99
#include "cinder/app/RendererGl.h"
1010
#include "cinder/app/App.h"
1111
#include "cinder/gl/gl.h"
12-
#include "cinder/CinderImGui.h"
1312
#include "AX-MediaPlayer.h"
1413

14+
#if __has_include( "cinder/CinderImGui.h")
15+
#include "cinder/CinderImGui.h"
16+
//#define HAS_DEBUG_UI
17+
namespace ui = ImGui;
18+
#endif
19+
1520
using namespace ci;
1621
using namespace ci::app;
17-
namespace ui = ImGui;
22+
1823

1924
class SimplePlaybackApp : public app::App
2025
{
@@ -36,7 +41,9 @@ class SimplePlaybackApp : public app::App
3641

3742
void SimplePlaybackApp::setup ( )
3843
{
44+
#ifdef HAS_DEBUG_UI
3945
ui::Initialize ( );
46+
#endif
4047

4148
uint32_t flags = 0;
4249
if ( _hardwareAccelerated ) flags |= AX::Video::MediaPlayer::HardwareAccelerated;
@@ -45,6 +52,7 @@ void SimplePlaybackApp::setup ( )
4552
_player->OnSeekStart.connect ( [=] { std::cout << "OnSeekStart\n"; } );
4653
_player->OnSeekEnd.connect ( [=] { std::cout << "OnSeekEnd\n"; } );
4754
_player->OnComplete.connect ( [=] { std::cout << "OnComplete\n"; } );
55+
_player->OnReady.connect ( [=] { std::cout << "OnReady: " << _player->GetDurationInSeconds ( ) << std::endl; } );
4856
_player->OnError.connect ( [=] ( AX::Video::MediaPlayer::Error error ) { _error = error; } );
4957
_player->Play ( );
5058
}
@@ -60,6 +68,7 @@ void SimplePlaybackApp::fileDrop ( FileDropEvent event )
6068
_player->OnSeekStart.connect ( [=] { std::cout << "OnSeekStart\n"; } );
6169
_player->OnSeekEnd.connect ( [=] { std::cout << "OnSeekEnd\n"; } );
6270
_player->OnComplete.connect ( [=] { std::cout << "OnComplete\n"; } );
71+
_player->OnReady.connect ( [=] { std::cout << "OnReady: " << _player->GetDurationInSeconds ( ) << std::endl; } );
6372
_player->OnError.connect ( [=] ( AX::Video::MediaPlayer::Error error ) { _error = error; } );
6473
_player->Play ( );
6574
}
@@ -68,6 +77,7 @@ void SimplePlaybackApp::update ( )
6877
{
6978
}
7079

80+
#ifdef HAS_DEBUG_UI
7181
struct ScopedWindow2
7282
{
7383
ScopedWindow2 ( const char * title, uint32_t flags )
@@ -80,11 +90,13 @@ struct ScopedWindow2
8090
ui::End ( );
8191
}
8292
};
93+
#endif
8394

8495
void SimplePlaybackApp::draw ( )
8596
{
8697
gl::clear ( Colorf::black ( ) );
8798

99+
#ifdef HAS_DEBUG_UI
88100
{
89101
ScopedWindow2 window{ "Settings", ImGuiWindowFlags_AlwaysAutoResize };
90102

@@ -151,6 +163,7 @@ void SimplePlaybackApp::draw ( )
151163
}
152164
}
153165
}
166+
#endif
154167

155168
if ( _player->CheckNewFrame ( ) )
156169
{

src/AX-MediaPlayer.cxx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,11 @@ namespace AX
160160
return _impl->IsSeeking ( );
161161
}
162162

163+
bool MediaPlayer::IsReady ( ) const
164+
{
165+
return _impl->IsReady ( );
166+
}
167+
163168
bool MediaPlayer::HasAudio ( ) const
164169
{
165170
return _impl->HasAudio ( );

src/AX-MediaPlayer.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818

1919
namespace AX::Video
2020
{
21-
using MediaPlayerRef = std::shared_ptr<class MediaPlayer>;
21+
using MediaPlayerRef = std::unique_ptr<class MediaPlayer>;
2222
class MediaPlayer : public ci::Noncopyable
2323
{
2424
public:
@@ -88,10 +88,11 @@ namespace AX::Video
8888
bool IsPlaying ( ) const;
8989
bool IsPaused ( ) const;
9090
bool IsSeeking ( ) const;
91+
bool IsReady ( ) const;
9192

9293
bool HasAudio ( ) const;
9394
bool HasVideo ( ) const;
94-
95+
9596
void SeekToSeconds ( float seconds, bool approximate = false );
9697
void SeekToPercentage ( float normalizedTime, bool approximate = false );
9798

@@ -103,6 +104,7 @@ namespace AX::Video
103104
const ci::Surface8uRef & GetSurface ( ) const;
104105
FrameLeaseRef GetTexture ( ) const;
105106

107+
EventSignal OnReady;
106108
EventSignal OnComplete;
107109
EventSignal OnPlay;
108110
EventSignal OnPause;

src/Win32/AX-MediaPlayerWin32Impl.cxx

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -349,7 +349,9 @@ namespace AX::Video
349349
_size = ivec2 ( w, h );
350350
_duration = static_cast<float> ( _mediaEngine->GetDuration ( ) );
351351
_renderPath->InitializeRenderTarget ( _size );
352-
352+
_hasMetadata = true;
353+
_owner.OnReady.emit ( );
354+
353355
break;
354356
}
355357

@@ -606,6 +608,11 @@ namespace AX::Video
606608
return false;
607609
}
608610

611+
bool MediaPlayer::Impl::IsReady ( ) const
612+
{
613+
return _hasMetadata;
614+
}
615+
609616
bool MediaPlayer::Impl::HasAudio ( ) const
610617
{
611618
if ( _mediaEngine )

src/Win32/AX-MediaPlayerWin32Impl.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ namespace AX::Video
8181
bool IsPlaying ( ) const;
8282
bool IsPaused ( ) const;
8383
bool IsSeeking ( ) const;
84+
bool IsReady ( ) const;
8485

8586
bool HasAudio ( ) const;
8687
bool HasVideo ( ) const;
@@ -129,6 +130,7 @@ namespace AX::Video
129130
ci::ivec2 _size;
130131
uint32_t _flags{ 0 };
131132
float _duration{ 0.0f };
133+
bool _hasMetadata{ false };
132134
ci::Surface8uRef _surface{ nullptr };
133135
RenderPathRef _renderPath;
134136
ComPtr<IMFMediaEngine> _mediaEngine{ nullptr };

0 commit comments

Comments
 (0)