[Redbutton-devel] SF.net SVN: redbutton: [491] redbutton-browser/trunk
Brought to you by:
skilvington
|
From: <ski...@us...> - 2008-06-16 16:16:09
|
Revision: 491
http://redbutton.svn.sourceforge.net/redbutton/?rev=491&view=rev
Author: skilvington
Date: 2008-06-16 09:16:06 -0700 (Mon, 16 Jun 2008)
Log Message:
-----------
make MHEGStreamPlayer a singleton to avoid having to open the dvr device more than once
Modified Paths:
--------------
redbutton-browser/trunk/MHEGStreamPlayer.c
redbutton-browser/trunk/MHEGStreamPlayer.h
redbutton-browser/trunk/StreamClass.c
redbutton-browser/trunk/add_instance_vars.conf
Modified: redbutton-browser/trunk/MHEGStreamPlayer.c
===================================================================
--- redbutton-browser/trunk/MHEGStreamPlayer.c 2008-06-11 14:55:21 UTC (rev 490)
+++ redbutton-browser/trunk/MHEGStreamPlayer.c 2008-06-16 16:16:06 UTC (rev 491)
@@ -119,48 +119,88 @@
return;
}
+/*
+ * MHEGStreamPlayer is a singleton
+ * UK MHEG spec says we only need one video/audio decoder
+ * Linux only allows us to open the dvr device once, so we can't have more than one MHEGStreamPlayer
+ */
+
+static MHEGStreamPlayer player;
+
void
-MHEGStreamPlayer_init(MHEGStreamPlayer *p)
+MHEGStreamPlayer_init(MHEGStreamPlayer **p)
{
- bzero(p, sizeof(MHEGStreamPlayer));
+ static bool created = false;
- p->playing = false;
- p->stop = false;
+ /* have we created the singleton yet */
+ if(!created)
+ {
+ bzero(&player, sizeof(MHEGStreamPlayer));
- p->have_video = false;
- p->have_audio = false;
+ player.nusers = 0;
- p->video = NULL;
- p->audio = NULL;
+ player.playing = false;
+ player.stop = false;
- /* stream a/v components from the service we are currently tuned to */
- p->service_id = -1;
+ player.have_video = false;
+ player.have_audio = false;
- p->audio_codec = NULL;
+ player.video = NULL;
+ player.audio = NULL;
- pthread_mutex_init(&p->base_lock, NULL);
- pthread_cond_init(&p->base_cond, NULL);
+ /* stream a/v components from the service we are currently tuned to */
+ player.service_id = -1;
- pthread_mutex_init(&p->videoq_lock, NULL);
- p->videoq = NULL;
+ player.audio_codec = NULL;
- pthread_mutex_init(&p->audioq_lock, NULL);
- p->audioq = NULL;
+ pthread_mutex_init(&player.base_lock, NULL);
+ pthread_cond_init(&player.base_cond, NULL);
+ pthread_mutex_init(&player.videoq_lock, NULL);
+ player.videoq = NULL;
+
+ pthread_mutex_init(&player.audioq_lock, NULL);
+ player.audioq = NULL;
+
+ created = true;
+ }
+
+ player.nusers ++;
+
+ verbose("MHEGStreamPlayer: %u users", player.nusers);
+
+ *p = &player;
+
return;
}
void
-MHEGStreamPlayer_fini(MHEGStreamPlayer *p)
+MHEGStreamPlayer_fini(MHEGStreamPlayer **p)
{
- MHEGStreamPlayer_stop(p);
+ /* assert */
+ if(*p != &player)
+ fatal("MHEGStreamPlayer: *p=%p, &player=%p", *p, &player);
- pthread_mutex_destroy(&p->base_lock);
- pthread_cond_destroy(&p->base_cond);
+ if(player.nusers == 0)
+ fatal("MHEGStreamPlayer: nusers is 0");
- pthread_mutex_destroy(&p->videoq_lock);
- pthread_mutex_destroy(&p->audioq_lock);
+ MHEGStreamPlayer_stop(&player);
+ player.nusers --;
+
+ verbose("MHEGStreamPlayer: %u users", player.nusers);
+
+ *p = NULL;
+
+#if 0
+ /* this is how you would destroy it */
+ pthread_mutex_destroy(&player.base_lock);
+ pthread_cond_destroy(&player.base_cond);
+
+ pthread_mutex_destroy(&player.videoq_lock);
+ pthread_mutex_destroy(&player.audioq_lock);
+#endif
+
return;
}
@@ -173,6 +213,10 @@
void
MHEGStreamPlayer_setServiceID(MHEGStreamPlayer *p, int id)
{
+ /* assert */
+ if(p != &player)
+ fatal("MHEGStreamPlayer_setServiceID: p=%p, &player=%p", p, &player);
+
p->service_id = id;
return;
@@ -182,6 +226,11 @@
MHEGStreamPlayer_setVideoStream(MHEGStreamPlayer *p, VideoClass *video)
{
/* assert */
+ if(p != &player)
+ fatal("MHEGStreamPlayer_setVideoStream: p=%p, &player=%p", p, &player);
+
+/* TODO need to be able to handle this */
+ /* assert */
if(p->playing)
fatal("MHEGStreamPlayer_setVideoStream: trying to set stream while playing");
@@ -218,6 +267,11 @@
MHEGStreamPlayer_setAudioStream(MHEGStreamPlayer *p, AudioClass *audio)
{
/* assert */
+ if(p != &player)
+ fatal("MHEGStreamPlayer_setAudioStream: p=%p, &player=%p", p, &player);
+
+/* TODO need to be able to handle this */
+ /* assert */
if(p->playing)
fatal("MHEGStreamPlayer_setAudioStream: trying to set stream while playing");
@@ -256,6 +310,10 @@
void
MHEGStreamPlayer_play(MHEGStreamPlayer *p)
{
+ /* assert */
+ if(p != &player)
+ fatal("MHEGStreamPlayer_play: p=%p, &player=%p", p, &player);
+
verbose("MHEGStreamPlayer_play: service_id=%d audio_tag=%d video_tag=%d", p->service_id, p->audio_tag, p->video_tag);
/* make sure the VideoClass doesn't try to draw anything yet */
@@ -323,6 +381,10 @@
void
MHEGStreamPlayer_stop(MHEGStreamPlayer *p)
{
+ /* assert */
+ if(p != &player)
+ fatal("MHEGStreamPlayer_stop: p=%p, &player=%p", *p, &player);
+
verbose("MHEGStreamPlayer_stop");
/* are we playing */
Modified: redbutton-browser/trunk/MHEGStreamPlayer.h
===================================================================
--- redbutton-browser/trunk/MHEGStreamPlayer.h 2008-06-11 14:55:21 UTC (rev 490)
+++ redbutton-browser/trunk/MHEGStreamPlayer.h 2008-06-16 16:16:06 UTC (rev 491)
@@ -53,6 +53,7 @@
/* player state */
typedef struct
{
+ unsigned int nusers; /* reference count */
bool playing; /* true when our threads are active */
bool stop; /* true => stop playback */
bool have_video; /* false if we have no video stream */
@@ -81,8 +82,8 @@
LIST_OF(AudioFrame) *audioq; /* head of list is next to be played */
} MHEGStreamPlayer;
-void MHEGStreamPlayer_init(MHEGStreamPlayer *);
-void MHEGStreamPlayer_fini(MHEGStreamPlayer *);
+void MHEGStreamPlayer_init(MHEGStreamPlayer **);
+void MHEGStreamPlayer_fini(MHEGStreamPlayer **);
void MHEGStreamPlayer_setServiceID(MHEGStreamPlayer *, int);
void MHEGStreamPlayer_setVideoStream(MHEGStreamPlayer *, VideoClass *);
Modified: redbutton-browser/trunk/StreamClass.c
===================================================================
--- redbutton-browser/trunk/StreamClass.c 2008-06-11 14:55:21 UTC (rev 490)
+++ redbutton-browser/trunk/StreamClass.c 2008-06-16 16:16:06 UTC (rev 491)
@@ -108,7 +108,7 @@
*/
if(OctetString_strncmp(service, "dvb:", 4) == 0)
{
- MHEGStreamPlayer_setServiceID(&t->inst.player, si_get_service_id(service));
+ MHEGStreamPlayer_setServiceID(t->inst.player, si_get_service_id(service));
}
else if(OctetString_strncmp(service, "rec://svc/lcn/", 14) == 0)
{
@@ -118,7 +118,7 @@
else if(OctetString_strcmp(service, "rec://svc/def") == 0)
{
/* use the service ID we are currently tuned to */
- MHEGStreamPlayer_setServiceID(&t->inst.player, -1);
+ MHEGStreamPlayer_setServiceID(t->inst.player, -1);
}
/* leave player's service ID as it is for "rec://svc/cur" */
else if(OctetString_strcmp(service, "rec://svc/cur") != 0)
@@ -133,10 +133,10 @@
{
if((r = StreamComponent_rootClass(&comp->item)) != NULL
&& r->inst.RunningStatus)
- StreamComponent_play(&comp->item, &t->inst.player);
+ StreamComponent_play(&comp->item, t->inst.player);
comp = comp->next;
}
- MHEGStreamPlayer_play(&t->inst.player);
+ MHEGStreamPlayer_play(t->inst.player);
/* multiplex is now playing */
MHEGEngine_generateAsyncEvent(&t->rootClass.inst.ref, EventType_stream_playing, NULL);
@@ -177,13 +177,13 @@
}
/* stop playing all active StreamComponents */
- MHEGStreamPlayer_stop(&t->inst.player);
+ MHEGStreamPlayer_stop(t->inst.player);
comp = t->multiplex;
while(comp)
{
if((r = StreamComponent_rootClass(&comp->item)) != NULL
&& r->inst.RunningStatus)
- StreamComponent_stop(&comp->item, &t->inst.player);
+ StreamComponent_stop(&comp->item, t->inst.player);
comp = comp->next;
}
@@ -260,12 +260,12 @@
/* if we are activated, stop playing while we change the component */
if(t->rootClass.inst.RunningStatus)
- MHEGStreamPlayer_stop(&t->inst.player);
+ MHEGStreamPlayer_stop(t->inst.player);
- MHEGStreamPlayer_setVideoStream(&t->inst.player, c);
+ MHEGStreamPlayer_setVideoStream(t->inst.player, c);
if(t->rootClass.inst.RunningStatus)
- MHEGStreamPlayer_play(&t->inst.player);
+ MHEGStreamPlayer_play(t->inst.player);
return;
}
@@ -282,12 +282,12 @@
/* if we are activated, stop playing while we change the component */
if(t->rootClass.inst.RunningStatus)
- MHEGStreamPlayer_stop(&t->inst.player);
+ MHEGStreamPlayer_stop(t->inst.player);
- MHEGStreamPlayer_setAudioStream(&t->inst.player, c);
+ MHEGStreamPlayer_setAudioStream(t->inst.player, c);
if(t->rootClass.inst.RunningStatus)
- MHEGStreamPlayer_play(&t->inst.player);
+ MHEGStreamPlayer_play(t->inst.player);
return;
}
@@ -304,12 +304,12 @@
/* if we are activated, stop playing while we change the component */
if(t->rootClass.inst.RunningStatus)
- MHEGStreamPlayer_stop(&t->inst.player);
+ MHEGStreamPlayer_stop(t->inst.player);
- MHEGStreamPlayer_setVideoStream(&t->inst.player, NULL);
+ MHEGStreamPlayer_setVideoStream(t->inst.player, NULL);
if(t->rootClass.inst.RunningStatus)
- MHEGStreamPlayer_play(&t->inst.player);
+ MHEGStreamPlayer_play(t->inst.player);
return;
}
@@ -326,12 +326,12 @@
/* if we are activated, stop playing while we change the component */
if(t->rootClass.inst.RunningStatus)
- MHEGStreamPlayer_stop(&t->inst.player);
+ MHEGStreamPlayer_stop(t->inst.player);
- MHEGStreamPlayer_setAudioStream(&t->inst.player, NULL);
+ MHEGStreamPlayer_setAudioStream(t->inst.player, NULL);
if(t->rootClass.inst.RunningStatus)
- MHEGStreamPlayer_play(&t->inst.player);
+ MHEGStreamPlayer_play(t->inst.player);
return;
}
Modified: redbutton-browser/trunk/add_instance_vars.conf
===================================================================
--- redbutton-browser/trunk/add_instance_vars.conf 2008-06-11 14:55:21 UTC (rev 490)
+++ redbutton-browser/trunk/add_instance_vars.conf 2008-06-16 16:16:06 UTC (rev 491)
@@ -227,7 +227,7 @@
int CounterEndPosition;
LIST_OF(CounterTrigger) *CounterTriggers;
/* we add this */
- MHEGStreamPlayer player;
+ MHEGStreamPlayer *player;
} StreamClassInstanceVars;
</StreamClass>
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|