[Libreoffice-commits] core.git: Branch 'feature/vlc' - 3 commits - avmedia/Library_avmediavlc.mk avmedia/source
Minh Ngo
nlminhtl at gmail.com
Sun Aug 18 14:51:39 PDT 2013
avmedia/Library_avmediavlc.mk | 3
avmedia/source/vlc/vlcframegrabber.cxx | 52 ++++++++--------
avmedia/source/vlc/vlcframegrabber.hxx | 4 -
avmedia/source/vlc/vlcmanager.cxx | 6 +
avmedia/source/vlc/vlcmanager.hxx | 4 -
avmedia/source/vlc/vlcplayer.cxx | 16 ++---
avmedia/source/vlc/vlcplayer.hxx | 3
avmedia/source/vlc/wrapper/EventHandler.cxx | 24 +++++++
avmedia/source/vlc/wrapper/EventHandler.hxx | 42 +++++++++++++
avmedia/source/vlc/wrapper/EventManager.cxx | 23 ++++---
avmedia/source/vlc/wrapper/EventManager.hxx | 18 +++--
avmedia/source/vlc/wrapper/Player.cxx | 2
avmedia/source/vlc/wrapper/Player.hxx | 1
avmedia/source/vlc/wrapper/ThreadsafeQueue.cxx | 1
avmedia/source/vlc/wrapper/ThreadsafeQueue.hxx | 79 +++++++++++++++++++++++++
15 files changed, 223 insertions(+), 55 deletions(-)
New commits:
commit 5366ba32fb854ffd59a6983346b8b7a60edc69fb
Author: Minh Ngo <nlminhtl at gmail.com>
Date: Mon Aug 19 00:50:58 2013 +0300
Playback loop
Change-Id: I1262f16e60f928481626ef952d929cc931335233
diff --git a/avmedia/source/vlc/vlcframegrabber.cxx b/avmedia/source/vlc/vlcframegrabber.cxx
index 4ca6add..adc59b7 100644
--- a/avmedia/source/vlc/vlcframegrabber.cxx
+++ b/avmedia/source/vlc/vlcframegrabber.cxx
@@ -23,10 +23,11 @@ const ::rtl::OUString AVMEDIA_VLC_GRABBER_IMPLEMENTATIONNAME = "com.sun.star.com
const ::rtl::OUString AVMEDIA_VLC_GRABBER_SERVICENAME = "com.sun.star.media.VLCFrameGrabber_VLC";
const int MSEC_IN_SEC = 1000;
-SAL_CALL VLCFrameGrabber::VLCFrameGrabber( VLC::Player& player, const rtl::OUString& url )
+SAL_CALL VLCFrameGrabber::VLCFrameGrabber( VLC::Player& player, boost::shared_ptr<VLC::EventHandler> eh, const rtl::OUString& url )
: FrameGrabber_BASE()
, mPlayer( player )
, mUrl( url )
+ , mEventHandler( eh )
{
}
@@ -34,39 +35,42 @@ SAL_CALL VLCFrameGrabber::VLCFrameGrabber( VLC::Player& player, const rtl::OUStr
{
osl::Condition condition;
- VLC::EventManager manager( mPlayer );
- manager.onPaused(boost::bind(&osl::Condition::set, &condition));
+ const rtl::OUString& fileName = utl::TempFile::CreateTempName();
+ {
+ VLC::EventManager manager( mPlayer, mEventHandler );
+ manager.onPaused(boost::bind(&osl::Condition::set, &condition));
- mPlayer.setMute( true );
+ mPlayer.setMute( true );
- if ( !mPlayer.play() )
- {
- std::cerr << "Couldn't play" << std::endl;
- }
+ if ( !mPlayer.play() )
+ {
+ std::cerr << "Couldn't play" << std::endl;
+ }
- mPlayer.setTime( ( fMediaTime > 0 ? fMediaTime : 0 ) * MSEC_IN_SEC );
- mPlayer.pause();
+ mPlayer.setTime( ( fMediaTime > 0 ? fMediaTime : 0 ) * MSEC_IN_SEC );
+ mPlayer.pause();
- const TimeValue timeout = {2, 0};
- condition.wait(&timeout);
+ const TimeValue timeout = {2, 0};
+ condition.wait(&timeout);
- if ( mUrl.isEmpty() || !mPlayer.hasVout() )
- {
- std::cerr << "Couldn't grab frame" << std::endl;
- mPlayer.setMute( false );
+ if ( mUrl.isEmpty() || !mPlayer.hasVout() )
+ {
+ std::cerr << "Couldn't grab frame" << std::endl;
+ mPlayer.setMute( false );
+
+ manager.onPaused();
+ return ::uno::Reference< css::graphic::XGraphic >();
+ }
- manager.onPaused();
- return ::uno::Reference< css::graphic::XGraphic >();
- }
- const rtl::OUString& fileName = utl::TempFile::CreateTempName();
- mPlayer.takeSnapshot( fileName );
+ mPlayer.takeSnapshot( fileName );
- mPlayer.setMute( false );
- mPlayer.stop();
+ mPlayer.setMute( false );
+ mPlayer.stop();
- manager.onPaused();
+ manager.onPaused();
+ }
rtl::OUString url;
utl::LocalFileHelper::ConvertPhysicalNameToURL( fileName, url );
diff --git a/avmedia/source/vlc/vlcframegrabber.hxx b/avmedia/source/vlc/vlcframegrabber.hxx
index 53dce41..923b63f 100644
--- a/avmedia/source/vlc/vlcframegrabber.hxx
+++ b/avmedia/source/vlc/vlcframegrabber.hxx
@@ -28,6 +28,7 @@
namespace VLC
{
class Player;
+ class EventHandler;
}
namespace avmedia {
@@ -40,8 +41,9 @@ class VLCFrameGrabber : public FrameGrabber_BASE
{
VLC::Player& mPlayer;
const rtl::OUString& mUrl;
+ boost::shared_ptr<VLC::EventHandler> mEventHandler;
public:
- SAL_CALL VLCFrameGrabber( VLC::Player& player, const rtl::OUString& url );
+ SAL_CALL VLCFrameGrabber( VLC::Player& player, boost::shared_ptr<VLC::EventHandler> eh, const rtl::OUString& url );
::com::sun::star::uno::Reference< css::graphic::XGraphic > SAL_CALL grabFrame( double fMediaTime );
diff --git a/avmedia/source/vlc/vlcmanager.cxx b/avmedia/source/vlc/vlcmanager.cxx
index a3e762b..6a5431d 100644
--- a/avmedia/source/vlc/vlcmanager.cxx
+++ b/avmedia/source/vlc/vlcmanager.cxx
@@ -10,8 +10,10 @@ const rtl::OUString VLC_IMPLEMENTATION_NAME = "com.sun.star.comp.avmedia.Manager
const ::rtl::OUString VLC_SERVICENAME = "com.sun.star.media.Manager_VLC";
Manager::Manager( const uno::Reference< lang::XMultiServiceFactory >& rxMgr )
- : mxMgr( rxMgr )
+ : mEventHandler(new VLC::EventHandler( "EventHandler" ) )
+ , mxMgr( rxMgr )
{
+ mEventHandler->launch();
}
Manager::~Manager()
@@ -23,7 +25,7 @@ uno::Reference< media::XPlayer > SAL_CALL Manager::createPlayer( const rtl::OUSt
{
if ( !rURL.isEmpty() || (mPlayer.is() && dynamic_cast<VLCPlayer*>( mPlayer.get() )->url() != rURL))
{
- VLCPlayer* pPlayer( new VLCPlayer( rURL/*, mxMgr */ ) );
+ VLCPlayer* pPlayer( new VLCPlayer( rURL, mEventHandler /*, mxMgr */ ) );
mPlayer = uno::Reference< media::XPlayer >( pPlayer );
}
diff --git a/avmedia/source/vlc/vlcmanager.hxx b/avmedia/source/vlc/vlcmanager.hxx
index 9417480..dbcaed6 100644
--- a/avmedia/source/vlc/vlcmanager.hxx
+++ b/avmedia/source/vlc/vlcmanager.hxx
@@ -19,10 +19,11 @@
#ifndef _VLCMANAGER_HXX
#define _VLCMANAGER_HXX
-
+#include <boost/shared_ptr.hpp>
#include "vlccommon.hxx"
#include "com/sun/star/media/XManager.hpp"
+#include "wrapper/EventHandler.hxx"
namespace avmedia {
namespace vlc {
@@ -30,6 +31,7 @@ namespace vlc {
class Manager : public ::cppu::WeakImplHelper2 < ::com::sun::star::media::XManager,
::com::sun::star::lang::XServiceInfo >
{
+ boost::shared_ptr<VLC::EventHandler> mEventHandler;
public:
Manager( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& rxMgr );
~Manager();
diff --git a/avmedia/source/vlc/vlcplayer.cxx b/avmedia/source/vlc/vlcplayer.cxx
index 945d7d9..a0887c2 100644
--- a/avmedia/source/vlc/vlcplayer.cxx
+++ b/avmedia/source/vlc/vlcplayer.cxx
@@ -24,12 +24,13 @@ const char * const VLC_ARGS[] = {
const int MS_IN_SEC = 1000; // Millisec in sec
-VLCPlayer::VLCPlayer( const rtl::OUString& url )
+VLCPlayer::VLCPlayer( const rtl::OUString& url, boost::shared_ptr<VLC::EventHandler> eh )
: VLC_Base(m_aMutex)
+ , mEventHandler( eh )
, mInstance( VLC_ARGS )
, mMedia( url, mInstance )
, mPlayer( mMedia )
- , mEventManager( mPlayer )
+ , mEventManager( mPlayer, mEventHandler )
, mUrl( url )
, mPlaybackLoop( false )
{
@@ -91,8 +92,10 @@ double SAL_CALL VLCPlayer::getRate()
void VLCPlayer::replay()
{
- mPlayer.stop();
- mPlayer.play();
+ setPlaybackLoop( false );
+ stop();
+ setMediaTime( 0 );
+ start();
}
void SAL_CALL VLCPlayer::setPlaybackLoop( ::sal_Bool bSet )
@@ -100,9 +103,6 @@ void SAL_CALL VLCPlayer::setPlaybackLoop( ::sal_Bool bSet )
::osl::MutexGuard aGuard(m_aMutex);
mPlaybackLoop = bSet;
- //TODO: Fix it
- return;
-
if ( bSet )
mEventManager.onEndReached(boost::bind(&VLCPlayer::replay, this));
else
@@ -190,7 +190,7 @@ uno::Reference< css::media::XPlayerWindow > SAL_CALL VLCPlayer::createPlayerWind
uno::Reference< css::media::XFrameGrabber > SAL_CALL VLCPlayer::createFrameGrabber()
{
::osl::MutexGuard aGuard(m_aMutex);
- VLCFrameGrabber *frameGrabber = new VLCFrameGrabber( mPlayer, mUrl );
+ VLCFrameGrabber *frameGrabber = new VLCFrameGrabber( mPlayer, mEventHandler, mUrl );
return uno::Reference< css::media::XFrameGrabber >( frameGrabber );
}
diff --git a/avmedia/source/vlc/vlcplayer.hxx b/avmedia/source/vlc/vlcplayer.hxx
index 3723f16..18e4e6f 100644
--- a/avmedia/source/vlc/vlcplayer.hxx
+++ b/avmedia/source/vlc/vlcplayer.hxx
@@ -41,6 +41,7 @@ typedef ::cppu::WeakComponentImplHelper2< ::com::sun::star::media::XPlayer,
class VLCPlayer : public ::cppu::BaseMutex,
public VLC_Base
{
+ boost::shared_ptr<VLC::EventHandler> mEventHandler;
VLC::Instance mInstance;
VLC::Media mMedia;
VLC::Player mPlayer;
@@ -48,7 +49,7 @@ class VLCPlayer : public ::cppu::BaseMutex,
const rtl::OUString mUrl;
bool mPlaybackLoop;
public:
- VLCPlayer( const rtl::OUString& url );
+ VLCPlayer( const rtl::OUString& url, boost::shared_ptr<VLC::EventHandler> eh );
const rtl::OUString& url() const;
diff --git a/avmedia/source/vlc/wrapper/EventManager.cxx b/avmedia/source/vlc/wrapper/EventManager.cxx
index bafd4a9..96e86b6 100644
--- a/avmedia/source/vlc/wrapper/EventManager.cxx
+++ b/avmedia/source/vlc/wrapper/EventManager.cxx
@@ -1,9 +1,11 @@
+#include <boost/thread.hpp>
#include <vlc/libvlc.h>
#include <vlc/libvlc_media.h>
#include <vlc/libvlc_events.h>
#include "EventManager.hxx"
#include "SymbolLoader.hxx"
+#include "EventHandler.hxx"
typedef void ( *libvlc_callback_t ) ( const struct libvlc_event_t *, void * );
@@ -35,15 +37,16 @@ void EventManagerEventHandler( const libvlc_event_t *event, void *pData )
switch ( event->type )
{
case libvlc_MediaPlayerPaused:
- instance->mOnPaused();
+ instance->mEventHandler->mCallbackQueue.push( instance->mOnPaused );
break;
case libvlc_MediaPlayerEndReached:
- instance->mOnEndReached();
+ instance->mEventHandler->mCallbackQueue.push( instance->mOnEndReached );
break;
}
}
-EventManager::EventManager(VLC::Player& player)
+EventManager::EventManager( VLC::Player& player, boost::shared_ptr<VLC::EventHandler> eh )
+ : mEventHandler( eh )
{
InitApiMap( VLC_EVENT_MANAGER_API );
mManager = libvlc_media_player_event_manager( player );
@@ -53,24 +56,26 @@ EventManager::~EventManager()
{
}
-void EventManager::registerSignal(int signal, const Callback& callback)
+void EventManager::registerSignal( int signal, const Callback& callback )
{
- if (callback.empty())
+ if ( callback.empty() )
libvlc_event_detach( mManager, signal, EventManagerEventHandler, this );
else
libvlc_event_attach( mManager, signal, EventManagerEventHandler, this );
}
-void EventManager::onPaused(const EventManager::Callback& callback)
+void EventManager::onPaused( const EventManager::Callback& callback )
{
mOnPaused = callback;
- registerSignal(libvlc_MediaPlayerPaused, callback);
+ registerSignal( libvlc_MediaPlayerPaused, callback );
}
-void EventManager::onEndReached(const Callback& callback)
+void EventManager::onEndReached( const Callback& callback )
{
mOnEndReached = callback;
- registerSignal(libvlc_MediaPlayerEndReached, callback);
+ registerSignal( libvlc_MediaPlayerEndReached, callback );
}
+
+
}
\ No newline at end of file
diff --git a/avmedia/source/vlc/wrapper/EventManager.hxx b/avmedia/source/vlc/wrapper/EventManager.hxx
index 9143b55..aad486d 100644
--- a/avmedia/source/vlc/wrapper/EventManager.hxx
+++ b/avmedia/source/vlc/wrapper/EventManager.hxx
@@ -19,30 +19,36 @@
#ifndef _WRAPPER_EVENT_MANAGER_HXX
#define _WRAPPER_EVENT_MANAGER_HXX
#include <boost/function.hpp>
+#include <boost/shared_ptr.hpp>
+
#include "Player.hxx"
struct libvlc_event_manager_t;
struct libvlc_event_t;
+
namespace VLC
{
+ class EventHandler;
class EventManager
{
friend void EventManagerEventHandler( const libvlc_event_t *event, void *pData );
public:
typedef boost::function<void()> Callback;
- EventManager(VLC::Player& player);
+ EventManager( VLC::Player& player, boost::shared_ptr<VLC::EventHandler> eh );
virtual ~EventManager();
- void onPaused(const Callback& callback = Callback());
- void onEndReached(const Callback& callback = Callback());
+ void onPaused( const Callback& callback = Callback() );
+ void onEndReached( const Callback& callback = Callback() );
private:
+ boost::shared_ptr<VLC::EventHandler> mEventHandler;
+ typedef boost::function< void() > TCallback;
libvlc_event_manager_t *mManager;
- boost::function<void()> mOnPaused;
- boost::function<void()> mOnEndReached;
+ TCallback mOnPaused;
+ TCallback mOnEndReached;
- void registerSignal(int signal, const Callback& callback);
+ void registerSignal( int signal, const Callback& callback );
};
}
diff --git a/avmedia/source/vlc/wrapper/Player.cxx b/avmedia/source/vlc/wrapper/Player.cxx
index 37779d1..a64b747 100644
--- a/avmedia/source/vlc/wrapper/Player.cxx
+++ b/avmedia/source/vlc/wrapper/Player.cxx
@@ -154,8 +154,6 @@ namespace VLC
{
return libvlc_media_player_has_vout( mPlayer );
}
-
-
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
\ No newline at end of file
diff --git a/avmedia/source/vlc/wrapper/Player.hxx b/avmedia/source/vlc/wrapper/Player.hxx
index 7832ad9..ed52062 100644
--- a/avmedia/source/vlc/wrapper/Player.hxx
+++ b/avmedia/source/vlc/wrapper/Player.hxx
@@ -64,7 +64,6 @@ namespace VLC
}
void setMouseHandling(bool flag);
-
private:
libvlc_media_player_t *mPlayer;
};
commit 37c8690857eb7cc62f62f2ba542b1c789ed7b4be
Author: Minh Ngo <nlminhtl at gmail.com>
Date: Mon Aug 19 00:49:40 2013 +0300
VLC Event handling in the separate thread.
Change-Id: I56daa508de79281df5536215222e5af224dae0f5
diff --git a/avmedia/Library_avmediavlc.mk b/avmedia/Library_avmediavlc.mk
index 5ab91d9..81e200b 100644
--- a/avmedia/Library_avmediavlc.mk
+++ b/avmedia/Library_avmediavlc.mk
@@ -36,6 +36,7 @@ $(eval $(call gb_Library_use_libraries,avmediavlc,\
tl \
vcl \
utl \
+ salhelper \
$(gb_UWINAPI) \
))
@@ -49,6 +50,8 @@ $(eval $(call gb_Library_add_exception_objects,avmediavlc,\
avmedia/source/vlc/wrapper/Media \
avmedia/source/vlc/wrapper/Player \
avmedia/source/vlc/wrapper/EventManager \
+ avmedia/source/vlc/wrapper/EventHandler \
+ avmedia/source/vlc/wrapper/ThreadsafeQueue \
))
# vim: set noet sw=4 ts=4:
diff --git a/avmedia/source/vlc/wrapper/EventHandler.cxx b/avmedia/source/vlc/wrapper/EventHandler.cxx
new file mode 100644
index 0000000..42fc0dc
--- /dev/null
+++ b/avmedia/source/vlc/wrapper/EventHandler.cxx
@@ -0,0 +1,24 @@
+#include "EventHandler.hxx"
+
+namespace VLC
+{
+EventHandler::EventHandler( const char *name )
+ : Thread( name )
+{
+}
+
+void EventHandler::execute()
+{
+ TCallback callback;
+ do
+ {
+ mCallbackQueue.pop( callback );
+
+ if ( callback.empty() )
+ return;
+ else
+ callback();
+ } while ( true );
+}
+
+}
diff --git a/avmedia/source/vlc/wrapper/EventHandler.hxx b/avmedia/source/vlc/wrapper/EventHandler.hxx
new file mode 100644
index 0000000..50700c2
--- /dev/null
+++ b/avmedia/source/vlc/wrapper/EventHandler.hxx
@@ -0,0 +1,42 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * This file incorporates work covered by the following license notice:
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed
+ * with this work for additional information regarding copyright
+ * ownership. The ASF licenses this file to you under the Apache
+ * License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of
+ * the License at http://www.apache.org/licenses/LICENSE-2.0 .
+ */
+#ifndef _WRAPPER_EVENT_HANDLER_HXX
+#define _WRAPPER_EVENT_HANDLER_HXX
+#include <boost/function.hpp>
+#include <salhelper/thread.hxx>
+#include "ThreadsafeQueue.hxx"
+
+namespace VLC
+{
+ class EventHandler : public salhelper::Thread
+ {
+ public:
+ EventHandler( const char* name );
+
+ protected:
+ virtual void execute();
+
+ public:
+ typedef boost::function< void() > TCallback;
+ avmedia::vlc::ThreadsafeQueue< TCallback > mCallbackQueue;
+ };
+}
+
+#endif // _WRAPPER_EVENT_HANDLER_HXX
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
\ No newline at end of file
commit b073853fc093a2d1be1ee546712f9ae27cf41e38
Author: Minh Ngo <nlminhtl at gmail.com>
Date: Mon Aug 19 00:47:43 2013 +0300
Thread safe queue for VLC Event Handling
Change-Id: I0e9b30639667a807cc316c89356803d99fa83ef8
diff --git a/avmedia/source/vlc/wrapper/ThreadsafeQueue.cxx b/avmedia/source/vlc/wrapper/ThreadsafeQueue.cxx
new file mode 100644
index 0000000..ea9294f
--- /dev/null
+++ b/avmedia/source/vlc/wrapper/ThreadsafeQueue.cxx
@@ -0,0 +1 @@
+#include "ThreadsafeQueue.hxx"
\ No newline at end of file
diff --git a/avmedia/source/vlc/wrapper/ThreadsafeQueue.hxx b/avmedia/source/vlc/wrapper/ThreadsafeQueue.hxx
new file mode 100644
index 0000000..7f428c4
--- /dev/null
+++ b/avmedia/source/vlc/wrapper/ThreadsafeQueue.hxx
@@ -0,0 +1,79 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * This file incorporates work covered by the following license notice:
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed
+ * with this work for additional information regarding copyright
+ * ownership. The ASF licenses this file to you under the Apache
+ * License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of
+ * the License at http://www.apache.org/licenses/LICENSE-2.0 .
+ */
+#ifndef _THREADSAFE_QUEUE_HXX
+#define _THREADSAFE_QUEUE_HXX
+#include <queue>
+#include <iostream>
+#include <osl/mutex.hxx>
+#include <osl/conditn.hxx>
+#include <boost/noncopyable.hpp>
+
+namespace avmedia {
+namespace vlc {
+
+template<class T>
+class ThreadsafeQueue : boost::noncopyable
+{
+public:
+ ThreadsafeQueue();
+
+ void push( const T& data );
+ void pop( T& data );
+
+private:
+ std::queue< T > mQueue;
+ mutable ::osl::Mutex mMutex;
+ ::osl::Condition mCondition;
+};
+
+template<class T>
+ThreadsafeQueue<T>::ThreadsafeQueue()
+{
+}
+
+template<class T>
+void ThreadsafeQueue<T>::push( const T& data )
+{
+ ::osl::MutexGuard guard( mMutex );
+ mQueue.push( data );
+ mCondition.set();
+}
+
+template<class T>
+void ThreadsafeQueue<T>::pop( T& data )
+{
+ mMutex.acquire();
+ if ( mQueue.empty() )
+ {
+ mMutex.release();
+ mCondition.wait();
+ mCondition.reset();
+ }
+
+ ::osl::MutexGuard guard( mMutex );
+
+ data = mQueue.front();
+ mQueue.pop();
+}
+
+}
+}
+
+#endif // _THREADSAFE_QUEUE_HXX
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
\ No newline at end of file
More information about the Libreoffice-commits
mailing list