[vlc-commits] activex: add method to allow stopping the player asynchonously
Pierre Lamot
git at videolan.org
Tue Nov 21 16:25:28 CET 2017
npapi-vlc | branch: master | Pierre Lamot <pierre at videolabs.io> | Thu Oct 19 16:23:42 2017 +0200| [7177e3cb9c581223b21193571b247c7d8478a7ae] | committer: Jean-Baptiste Kempf
activex: add method to allow stopping the player asynchonously
Signed-off-by: Jean-Baptiste Kempf <jb at videolan.org>
> https://code.videolan.org/videolan/npapi-vlc/commit/7177e3cb9c581223b21193571b247c7d8478a7ae
---
activex/axvlc.idl | 6 +++++
activex/plugin.cpp | 7 ++++++
activex/plugin.h | 1 +
activex/vlccontrol2.cpp | 60 +++++++++++++++++++++++++++++++++++++++++++++++++
activex/vlccontrol2.h | 13 +++++++----
5 files changed, 83 insertions(+), 4 deletions(-)
diff --git a/activex/axvlc.idl b/activex/axvlc.idl
index 0109fa3..2d64279 100644
--- a/activex/axvlc.idl
+++ b/activex/axvlc.idl
@@ -90,6 +90,7 @@ library AXVLC
const int DISPID_MediaPlayerMutedEvent = 219;
const int DISPID_MediaPlayerUnmutedEvent = 220;
const int DISPID_MediaPlayerAudioVolumeEvent = 221;
+ const int DISPID_MediaPlayerStopAsyncDoneEvent = 222;
[
uuid(DF48072F-5EF8-434e-9B40-E2F3AE759B5F),
@@ -120,6 +121,8 @@ library AXVLC
void MediaPlayerEndReached();
[id(DISPID_MediaPlayerStoppedEvent), helpstring("Playback stopped")]
void MediaPlayerStopped();
+ [id(DISPID_MediaPlayerStopAsyncDoneEvent), helpstring("Playback stop async done")]
+ void MediaPlayerStopAsyncDone();
[id(DISPID_MediaPlayerTimeChangedEvent), helpstring("Time changed")]
void MediaPlayerTimeChanged([in] long time);
@@ -335,6 +338,9 @@ library AXVLC
[helpstring("Stop current clip.")]
HRESULT stop();
+ [helpstring("Stop current clip asynchronously.")]
+ HRESULT stop_async();
+
[helpstring("Advance to next item in playlist.")]
HRESULT next();
diff --git a/activex/plugin.cpp b/activex/plugin.cpp
index 6a0435f..6a4182a 100644
--- a/activex/plugin.cpp
+++ b/activex/plugin.cpp
@@ -1024,6 +1024,13 @@ void VLCPlugin::fireOnMediaPlayerStoppedEvent()
vlcConnectionPointContainer->fireEvent(DISPID_MediaPlayerStoppedEvent, &dispparamsNoArgs);
};
+void VLCPlugin::fireOnMediaPlayerStopAsyncDoneEvent()
+{
+ DISPPARAMS dispparamsNoArgs = {NULL, NULL, 0, 0};
+ vlcConnectionPointContainer->fireEvent(DISPID_MediaPlayerStopAsyncDoneEvent, &dispparamsNoArgs);
+};
+
+
void VLCPlugin::fireOnMediaPlayerForwardEvent()
{
DISPPARAMS dispparamsNoArgs = {NULL, NULL, 0, 0};
diff --git a/activex/plugin.h b/activex/plugin.h
index de7c9d9..0b844eb 100644
--- a/activex/plugin.h
+++ b/activex/plugin.h
@@ -250,6 +250,7 @@ public:
void fireOnMediaPlayerEncounteredErrorEvent();
void fireOnMediaPlayerEndReachedEvent();
void fireOnMediaPlayerStoppedEvent();
+ void fireOnMediaPlayerStopAsyncDoneEvent();
void fireOnMediaPlayerTimeChangedEvent(libvlc_time_t time);
void fireOnMediaPlayerPositionChangedEvent(float position);
diff --git a/activex/vlccontrol2.cpp b/activex/vlccontrol2.cpp
index 4e88e15..2cd9530 100644
--- a/activex/vlccontrol2.cpp
+++ b/activex/vlccontrol2.cpp
@@ -910,6 +910,30 @@ STDMETHODIMP VLCPlaylistItems::remove(long item)
}
/****************************************************************************/
+enum PlaylistAsyncMessages
+{
+ PM_INPUT_STOP = WM_USER +1,
+ PM_DESTROY
+};
+
+VLCPlaylist::VLCPlaylist(VLCPlugin *p):
+ VLCInterface<VLCPlaylist,IVLCPlaylist>(p),
+ _p_vlcplaylistitems(new VLCPlaylistItems(p))
+{
+ _async_thread = CreateThread ( NULL , 0 ,
+ (LPTHREAD_START_ROUTINE)VLCPlaylist::async_handler_cb,
+ (LPVOID)this , 0, &_async_thread_id );
+}
+
+VLCPlaylist::~VLCPlaylist()
+{
+ PostThreadMessage(_async_thread_id, PM_DESTROY, 0, 0);
+ WaitForSingleObject(_async_thread, INFINITE);
+ CloseHandle (_async_thread);
+
+ delete _p_vlcplaylistitems;
+}
+
STDMETHODIMP VLCPlaylist::get_itemCount(long* count)
{
@@ -1041,6 +1065,12 @@ STDMETHODIMP VLCPlaylist::stop()
return S_OK;
}
+STDMETHODIMP VLCPlaylist::stop_async()
+{
+ PostThreadMessage(_async_thread_id, PM_INPUT_STOP, 0, 0);
+ return S_OK;
+}
+
STDMETHODIMP VLCPlaylist::next()
{
_plug->get_player().mlp().next();
@@ -1089,6 +1119,36 @@ STDMETHODIMP VLCPlaylist::parse(long options, long timeout, long *status)
return S_OK;
}
+void VLCPlaylist::async_handler_cb(LPVOID obj)
+{
+ VLCPlaylist* that = (VLCPlaylist*) obj;
+ that->async_handler();
+}
+
+
+void VLCPlaylist::async_handler()
+{
+ MSG msg;
+ bool b_quit = false;
+ while (!b_quit && GetMessage(&msg, 0, 0, 0))
+ {
+ switch(msg.message)
+ {
+ case PM_INPUT_STOP:
+ this->stop();
+ _plug->fireOnMediaPlayerStopAsyncDoneEvent();
+ break;
+ case PM_DESTROY:
+ b_quit = true;
+ break;
+ default:
+ TranslateMessage(&msg);
+ DispatchMessage(&msg);
+ break;
+ }
+ }
+}
+
/****************************************************************************/
STDMETHODIMP VLCSubtitle::get_track(long* spu)
diff --git a/activex/vlccontrol2.h b/activex/vlccontrol2.h
index b9baf4c..8b7a4ae 100644
--- a/activex/vlccontrol2.h
+++ b/activex/vlccontrol2.h
@@ -289,10 +289,8 @@ public:
class VLCPlaylist: public VLCInterface<VLCPlaylist,IVLCPlaylist>
{
public:
- VLCPlaylist(VLCPlugin *p):
- VLCInterface<VLCPlaylist,IVLCPlaylist>(p),
- _p_vlcplaylistitems(new VLCPlaylistItems(p)) { }
- virtual ~VLCPlaylist() { delete _p_vlcplaylistitems; }
+ VLCPlaylist(VLCPlugin *p);
+ virtual ~VLCPlaylist();
// IVLCPlaylist methods
STDMETHODIMP get_itemCount(long*);
@@ -304,6 +302,7 @@ public:
STDMETHODIMP pause();
STDMETHODIMP togglePause();
STDMETHODIMP stop();
+ STDMETHODIMP stop_async();
STDMETHODIMP next();
STDMETHODIMP prev();
STDMETHODIMP clear();
@@ -312,7 +311,13 @@ public:
STDMETHODIMP parse(long options, long timeout, long* status);
private:
+ static void async_handler_cb(LPVOID obj);
+ void async_handler();
+
+private:
VLCPlaylistItems* _p_vlcplaylistitems;
+ HANDLE _async_thread;
+ DWORD _async_thread_id;
};
class VLCSubtitle: public VLCInterface<VLCSubtitle,IVLCSubtitle>
More information about the vlc-commits
mailing list