summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSascha Volkenandt <sascha (at) akv-soft (dot) de>2007-05-04 18:53:31 +0000
committerSascha Volkenandt <sascha (at) akv-soft (dot) de>2007-05-04 18:53:31 +0000
commitf9fa26c1990e7fb7fc7f4a8f3c19175d2b5eb9c4 (patch)
treebd46c03a167be729b08f595b7c569489c4f098f9
parent71cd02a970f6cb1844c9e94d8a8dcdb71b1bc295 (diff)
downloadvdr-plugin-live-f9fa26c1990e7fb7fc7f4a8f3c19175d2b5eb9c4.tar.gz
vdr-plugin-live-f9fa26c1990e7fb7fc7f4a8f3c19175d2b5eb9c4.tar.bz2
- moved grab task into mainthreadloop
-rw-r--r--Makefile5
-rw-r--r--grab.cpp69
-rw-r--r--grab.h39
-rw-r--r--pages/remote.ecpp2
-rw-r--r--pages/screenshot.ecpp18
-rw-r--r--tasks.cpp36
-rw-r--r--tasks.h26
7 files changed, 171 insertions, 24 deletions
diff --git a/Makefile b/Makefile
index 044c44a..363ce49 100644
--- a/Makefile
+++ b/Makefile
@@ -1,7 +1,7 @@
#
# Makefile for a Video Disk Recorder plugin
#
-# $Id: Makefile,v 1.32 2007/04/26 17:36:46 winni Exp $
+# $Id: Makefile,v 1.33 2007/05/04 18:53:31 lordjaxom Exp $
# The official name of this plugin.
# This name will be used in the '-P...' option of VDR to load the plugin.
@@ -59,7 +59,8 @@ SUBDIRS = httpd pages css images javascript
### The object files (add further files here):
PLUGINOBJS = $(PLUGIN).o thread.o tntconfig.o setup.o i18n.o timers.o \
- tools.o recordings.o tasks.o status.o epg_events.o epgsearch.o
+ tools.o recordings.o tasks.o status.o epg_events.o epgsearch.o \
+ grab.o
WEBLIBS = pages/libpages.a css/libcss.a images/libimages.a \
javascript/libjavascript.a
diff --git a/grab.cpp b/grab.cpp
new file mode 100644
index 0000000..9211b92
--- /dev/null
+++ b/grab.cpp
@@ -0,0 +1,69 @@
+#include <cstdlib>
+#include <vdr/device.h>
+#include "grab.h"
+
+namespace vdrlive {
+
+using namespace std;
+
+class GrabImageTask: public StickyTask
+{
+public:
+ explicit GrabImageTask( int quality = 80, int width = 320, int height = 240 )
+ : m_quality( quality )
+ , m_width( width )
+ , m_height( height )
+ {}
+
+private:
+ int m_quality;
+ int m_width;
+ int m_height;
+
+ virtual void Action();
+};
+
+void GrabImageTask::Action()
+{
+ cDevice* device = cDevice::PrimaryDevice();
+ if ( device == 0 ) {
+ SetError( tr("Couldn't aquire primary device") );
+ return;
+ }
+
+ int size = 0;
+ uchar* image = device->GrabImage( size, true, m_quality, m_width, m_height );
+ if ( image == 0 ) {
+ SetError( tr("Couldn't grab image from primary device") );
+ return;
+ }
+
+ LiveGrabImageManager().PutImage( reinterpret_cast< char* >( image ), size );
+}
+
+GrabImageManager::GrabImageManager()
+ : m_task( new GrabImageTask )
+ , m_image( 0, &free )
+ , m_size( 0 )
+{
+}
+
+GrabImageInfo GrabImageManager::GetImage() const
+{
+ cMutexLock lock( &LiveTaskManager() );
+ return make_pair( m_image, m_size );
+}
+
+void GrabImageManager::PutImage( char* image, int size )
+{
+ m_image.reset( image, &free );
+ m_size = size;
+}
+
+GrabImageManager& LiveGrabImageManager()
+{
+ static GrabImageManager instance;
+ return instance;
+}
+
+} // namespace vdrlive
diff --git a/grab.h b/grab.h
new file mode 100644
index 0000000..d583ef0
--- /dev/null
+++ b/grab.h
@@ -0,0 +1,39 @@
+#ifndef VDR_LIVE_GRAB_H
+#define VDR_LIVE_GRAB_H
+
+#include <boost/shared_array.hpp>
+#include "tasks.h"
+
+namespace vdrlive {
+
+typedef boost::shared_array< char > GrabImagePtr;
+typedef std::pair< GrabImagePtr, int > GrabImageInfo;
+
+class GrabImageTask;
+
+class GrabImageManager
+{
+ friend GrabImageManager& LiveGrabImageManager();
+ friend class GrabImageTask;
+
+public:
+ GrabImageInfo GetImage() const;
+
+private:
+ GrabImageManager();
+ GrabImageManager( GrabImageManager const& );
+
+ GrabImageManager& operator=( GrabImageManager const& );
+
+ void PutImage( char* image, int size );
+
+ std::auto_ptr< GrabImageTask > m_task;
+ GrabImagePtr m_image;
+ int m_size;
+};
+
+GrabImageManager& LiveGrabImageManager();
+
+} // namespace vdrlive
+
+#endif // VDR_LIVE_GRAB_H
diff --git a/pages/remote.ecpp b/pages/remote.ecpp
index 354f9b6..3ab8c35 100644
--- a/pages/remote.ecpp
+++ b/pages/remote.ecpp
@@ -59,7 +59,7 @@ if (!logged_in && LiveSetup().UseAuth()) return reply.redirect("login.html");
function FillIntervals()
{
var element = document.getElementsByName('interval').item(0);
- var items = new Array(100, 200, 500, 1000, 2000, 5000);
+ var items = new Array(1000, 2000, 5000);
element.options.length = items.length;
for (i = 0; i < items.length; ++i) {
element.options[i].value = items[i];
diff --git a/pages/screenshot.ecpp b/pages/screenshot.ecpp
index a84d82d..b8d8617 100644
--- a/pages/screenshot.ecpp
+++ b/pages/screenshot.ecpp
@@ -1,5 +1,8 @@
<%pre>
-#include <vdr/device.h>
+#include "grab.h"
+
+using namespace vdrlive;
+
</%pre>
<%args>
int quality = 80;
@@ -9,14 +12,7 @@ int height = 240;
<%cpp>
reply.setContentType("image/jpg");
- cDevice* device = cDevice::PrimaryDevice();
- if ( device == 0 )
- return DECLINED;
-
- int size;
- uchar* image = device->GrabImage( size, true, quality, width, height );
- if ( image == 0 )
- return DECLINED;
-
- reply.out().write( reinterpret_cast< char* >( image ), size );
+ GrabImageInfo image = LiveGrabImageManager().GetImage();
+ if ( image.second > 0 )
+ reply.out().write( image.first.get(), image.second );
</%cpp>
diff --git a/tasks.cpp b/tasks.cpp
index 5213588..0faa76f 100644
--- a/tasks.cpp
+++ b/tasks.cpp
@@ -1,3 +1,5 @@
+#include <algorithm>
+#include <boost/bind.hpp>
#include <vdr/channels.h>
#include <vdr/i18n.h>
#include <vdr/menu.h>
@@ -7,9 +9,20 @@
#include "tasks.h"
#include "tools.h"
+namespace vdrlive {
+
using namespace std;
+using namespace boost;
-namespace vdrlive {
+StickyTask::StickyTask()
+{
+ LiveTaskManager().AddStickyTask( *this );
+}
+
+StickyTask::~StickyTask()
+{
+ LiveTaskManager().RemoveStickyTask( *this );
+}
void SwitchChannelTask::Action()
{
@@ -44,6 +57,18 @@ TaskManager::TaskManager()
{
}
+void TaskManager::AddStickyTask( Task& task )
+{
+ cMutexLock lock( this );
+ m_stickyTasks.push_back( &task );
+}
+
+void TaskManager::RemoveStickyTask( Task& task )
+{
+ cMutexLock lock( this );
+ m_stickyTasks.erase( find( m_stickyTasks.begin(), m_stickyTasks.end(), &task ) );
+}
+
bool TaskManager::Execute( Task& task )
{
cMutexLock lock( this );
@@ -55,15 +80,18 @@ bool TaskManager::Execute( Task& task )
void TaskManager::DoScheduledTasks()
{
- if ( m_taskQueue.empty() )
+ if ( m_taskQueue.empty() && m_stickyTasks.empty() )
return;
cMutexLock lock( this );
- while ( !m_taskQueue.empty() ) {
+ /*while ( !m_taskQueue.empty() ) {
Task* current = m_taskQueue.front();
current->Action();
m_taskQueue.pop_front();
- }
+ }*/
+ for_each( m_taskQueue.begin(), m_taskQueue.end(), bind( &Task::Action, _1 ) );
+ for_each( m_stickyTasks.begin(), m_stickyTasks.end(), bind( &Task::Action, _1 ) );
+ m_taskQueue.clear();
m_scheduleWait.Broadcast();
}
diff --git a/tasks.h b/tasks.h
index 03aa2c8..841ee43 100644
--- a/tasks.h
+++ b/tasks.h
@@ -1,9 +1,9 @@
#ifndef VDR_LIVE_TASKS_H
#define VDR_LIVE_TASKS_H
-#include <deque>
#include <memory>
#include <string>
+#include <vector>
#include <vdr/channels.h>
#include <vdr/thread.h>
@@ -14,8 +14,9 @@ class Task;
class TaskManager: public cMutex
{
friend TaskManager& LiveTaskManager();
+ friend class StickyTask;
- typedef std::deque< Task* > TaskQueue;
+ typedef std::vector< Task* > TaskList;
public:
bool Execute( Task& task );
@@ -27,7 +28,11 @@ private:
TaskManager();
TaskManager( TaskManager const& );
- TaskQueue m_taskQueue;
+ void AddStickyTask( Task& task );
+ void RemoveStickyTask( Task& task );
+
+ TaskList m_taskQueue;
+ TaskList m_stickyTasks;
cCondVar m_scheduleWait;
};
@@ -42,16 +47,25 @@ public:
std::string const& Error() const { return m_error; }
protected:
- Task(): m_result( true ) {}
+ explicit Task()
+ : m_result( true )
+ {}
Task( Task const& );
void SetError( std::string const& error ) { m_result = false; m_error = error; }
- virtual void Action() = 0;
-
private:
bool m_result;
std::string m_error;
+
+ virtual void Action() = 0;
+};
+
+class StickyTask: public Task
+{
+protected:
+ explicit StickyTask();
+ virtual ~StickyTask();
};
class SwitchChannelTask: public Task