dont stop dvb subs pid data caching on pause

git-svn-id: file:///home/bas/coolstream_public_svn/THIRDPARTY/applications/neutrino-experimental@311 e54a6e83-5905-42d5-8d5c-058d10e6a962


Origin commit data
------------------
Commit: 6a7a057cf9
Author: [CST] Focus <focus.cst@gmail.com>
Date: 2010-02-10 (Wed, 10 Feb 2010)
This commit is contained in:
[CST] Focus
2010-02-10 15:34:26 +00:00
parent 0e0efb6f40
commit c80ada267e
3 changed files with 79 additions and 24 deletions

View File

@@ -39,10 +39,12 @@ static int dvbsub_running;
static int dvbsub_paused = true; static int dvbsub_paused = true;
static int dvbsub_pid; static int dvbsub_pid;
static int dvbsub_stopped; static int dvbsub_stopped;
static int pid_change_req;
cDvbSubtitleConverter *dvbSubtitleConverter; cDvbSubtitleConverter *dvbSubtitleConverter;
static void* reader_thread(void *arg); static void* reader_thread(void *arg);
static void* dvbsub_thread(void* arg); static void* dvbsub_thread(void* arg);
static void clear_queue();
int dvbsub_init() { int dvbsub_init() {
int trc; int trc;
@@ -50,6 +52,8 @@ int dvbsub_init() {
sub_debug.set_level(3); sub_debug.set_level(3);
reader_running = true; reader_running = true;
dvbsub_stopped = 1;
pid_change_req = 1;
// reader-Thread starten // reader-Thread starten
trc = pthread_create(&threadReader, 0, reader_thread, (void *) NULL); trc = pthread_create(&threadReader, 0, reader_thread, (void *) NULL);
if (trc) { if (trc) {
@@ -74,9 +78,9 @@ int dvbsub_pause()
{ {
if(reader_running) { if(reader_running) {
dvbsub_paused = true; dvbsub_paused = true;
if(dvbSubtitleConverter) { if(dvbSubtitleConverter)
dvbSubtitleConverter->Pause(true); dvbSubtitleConverter->Pause(true);
}
printf("[dvb-sub] paused\n"); printf("[dvb-sub] paused\n");
} }
@@ -90,16 +94,23 @@ int dvbsub_start(int pid)
} }
if(pid) { if(pid) {
if(pid != dvbsub_pid) if(pid != dvbsub_pid) {
dvbsub_pause(); dvbsub_pause();
if(dvbSubtitleConverter)
dvbSubtitleConverter->Reset();
dvbsub_pid = pid; dvbsub_pid = pid;
pid_change_req = 1;
} }
}
printf("[dvb-sub] ***************************************** start, stopped %d pid %x\n", dvbsub_stopped, dvbsub_pid);
#if 0
while(!dvbsub_stopped) while(!dvbsub_stopped)
usleep(10); usleep(10);
#endif
if(dvbsub_pid > 0) { if(dvbsub_pid > 0) {
dvbsub_stopped = 0;
dvbsub_paused = false; dvbsub_paused = false;
if(dvbSubtitleConverter)
dvbSubtitleConverter->Pause(false); dvbSubtitleConverter->Pause(false);
pthread_mutex_lock(&readerMutex); pthread_mutex_lock(&readerMutex);
pthread_cond_broadcast(&readerCond); pthread_cond_broadcast(&readerCond);
@@ -114,7 +125,9 @@ int dvbsub_stop()
{ {
dvbsub_pid = 0; dvbsub_pid = 0;
if(reader_running) { if(reader_running) {
dvbsub_stopped = 1;
dvbsub_pause(); dvbsub_pause();
pid_change_req = 1;
} }
return 0; return 0;
@@ -127,7 +140,18 @@ int dvbsub_getpid()
void dvbsub_setpid(int pid) void dvbsub_setpid(int pid)
{ {
clear_queue();
if(dvbSubtitleConverter)
dvbSubtitleConverter->Reset();
dvbsub_pid = pid; dvbsub_pid = pid;
pid_change_req = 1;
dvbsub_stopped = 0;
pthread_mutex_lock(&readerMutex);
pthread_cond_broadcast(&readerCond);
pthread_mutex_unlock(&readerMutex);
} }
int dvbsub_close() int dvbsub_close()
@@ -135,14 +159,22 @@ int dvbsub_close()
if(threadReader) { if(threadReader) {
dvbsub_pause(); dvbsub_pause();
reader_running = false; reader_running = false;
dvbsub_stopped = 1;
pthread_mutex_lock(&readerMutex); pthread_mutex_lock(&readerMutex);
pthread_cond_broadcast(&readerCond); pthread_cond_broadcast(&readerCond);
pthread_mutex_unlock(&readerMutex); pthread_mutex_unlock(&readerMutex);
pthread_join(threadReader, NULL); pthread_join(threadReader, NULL);
threadReader = NULL; threadReader = NULL;
} }
if(threadDvbsub) { if(threadDvbsub) {
dvbsub_running = false; dvbsub_running = false;
pthread_mutex_lock(&packetMutex);
pthread_cond_broadcast(&packetCond);
pthread_mutex_unlock(&packetMutex);
pthread_join(threadDvbsub, NULL); pthread_join(threadDvbsub, NULL);
threadDvbsub = NULL; threadDvbsub = NULL;
} }
@@ -188,6 +220,18 @@ static int64_t get_pts_stc_delta(int64_t pts)
return delta; return delta;
} }
static void clear_queue()
{
uint8_t* packet;
pthread_mutex_lock(&packetMutex);
while(packet_queue.size()) {
packet = packet_queue.pop();
free(packet);
}
pthread_mutex_unlock(&packetMutex);
}
static void* reader_thread(void * /*arg*/) static void* reader_thread(void * /*arg*/)
{ {
uint8_t tmp[16]; /* actually 6 should be enough */ uint8_t tmp[16]; /* actually 6 should be enough */
@@ -200,23 +244,32 @@ static void* reader_thread(void * /*arg*/)
dmx->Open(DMX_PES_CHANNEL, NULL, 64*1024); dmx->Open(DMX_PES_CHANNEL, NULL, 64*1024);
while (reader_running) { while (reader_running) {
if(dvbsub_paused) { if(dvbsub_stopped /*dvbsub_paused*/) {
sub_debug.print(Debug::VERBOSE, "%s stopped\n", __FUNCTION__); sub_debug.print(Debug::VERBOSE, "%s stopped\n", __FUNCTION__);
dmx->Stop(); dmx->Stop();
dvbsub_stopped = 1;
pthread_mutex_lock(&packetMutex);
pthread_cond_broadcast(&packetCond);
pthread_mutex_unlock(&packetMutex);
pthread_mutex_lock(&readerMutex ); pthread_mutex_lock(&readerMutex );
int ret = pthread_cond_wait(&readerCond, &readerMutex); int ret = pthread_cond_wait(&readerCond, &readerMutex);
pthread_mutex_unlock(&readerMutex); pthread_mutex_unlock(&readerMutex);
if (ret) { if (ret) {
sub_debug.print(Debug::VERBOSE, "pthread_cond_timedwait fails with %d\n", ret); sub_debug.print(Debug::VERBOSE, "pthread_cond_timedwait fails with %d\n", ret);
} }
if(reader_running) { if(!reader_running)
break;
dvbsub_stopped = 0;
sub_debug.print(Debug::VERBOSE, "%s (re)started with pid 0x%x\n", __FUNCTION__, dvbsub_pid);
}
if(pid_change_req) {
pid_change_req = 0;
clear_queue();
dmx->Stop();
dmx->pesFilter(dvbsub_pid); dmx->pesFilter(dvbsub_pid);
dmx->Start(); dmx->Start();
sub_debug.print(Debug::VERBOSE, "%s started: pid 0x%x\n", __FUNCTION__, dvbsub_pid); sub_debug.print(Debug::VERBOSE, "%s changed to pid 0x%x\n", __FUNCTION__, dvbsub_pid);
dvbsub_stopped = 0;
} else
break;
} }
len = 0; len = 0;
@@ -238,7 +291,7 @@ static void* reader_thread(void * /*arg*/)
memcpy(buf, tmp, 6); memcpy(buf, tmp, 6);
/* read rest of the packet */ /* read rest of the packet */
while((count < packlen) && !dvbsub_paused) { while((count < packlen) /* && !dvbsub_paused*/) {
len = dmx->Read(buf+count, packlen-count, 1000); len = dmx->Read(buf+count, packlen-count, 1000);
if (len < 0) { if (len < 0) {
continue; continue;
@@ -258,7 +311,7 @@ static void* reader_thread(void * /*arg*/)
} }
#endif #endif
if(!dvbsub_paused) { if(!dvbsub_stopped /*!dvbsub_paused*/) {
sub_debug.print(Debug::VERBOSE, "[subtitles] ******************* new packet, len %d buf 0x%x pts-stc diff %lld *******************\n", count, buf, get_pts_stc_delta(get_pts(buf))); sub_debug.print(Debug::VERBOSE, "[subtitles] ******************* new packet, len %d buf 0x%x pts-stc diff %lld *******************\n", count, buf, get_pts_stc_delta(get_pts(buf)));
/* Packet now in memory */ /* Packet now in memory */
packet_queue.push(buf); packet_queue.push(buf);
@@ -318,14 +371,14 @@ static void* dvbsub_thread(void* /*arg*/)
continue; continue;
} }
sub_debug.print(Debug::VERBOSE, "PES: Wakeup, queue size %d\n\n", packet_queue.size()); sub_debug.print(Debug::VERBOSE, "PES: Wakeup, queue size %d\n\n", packet_queue.size());
if(dvbsub_paused) { if(dvbsub_stopped /*dvbsub_paused*/) {
while(packet_queue.size()) { clear_queue();
packet = packet_queue.pop();
free(packet);
}
continue; continue;
} }
pthread_mutex_lock(&packetMutex);
packet = packet_queue.pop(); packet = packet_queue.pop();
pthread_mutex_unlock(&packetMutex);
if (!packet) { if (!packet) {
sub_debug.print(Debug::VERBOSE, "Error no packet found\n"); sub_debug.print(Debug::VERBOSE, "Error no packet found\n");
continue; continue;

View File

@@ -224,9 +224,9 @@ void cDvbSubtitleConverter::Pause(bool pause)
Clear(); Clear();
running = false; running = false;
Unlock(); Unlock();
Reset(); //Reset();
} else { } else {
Reset(); //Reset();
running = true; running = true;
} }
} }

View File

@@ -2224,6 +2224,8 @@ void CNeutrinoApp::InitZapper()
if(g_RemoteControl->current_PIDs.PIDs.vtxtpid != 0) if(g_RemoteControl->current_PIDs.PIDs.vtxtpid != 0)
tuxtxt_start(g_RemoteControl->current_PIDs.PIDs.vtxtpid); tuxtxt_start(g_RemoteControl->current_PIDs.PIDs.vtxtpid);
g_RCInput->postMsg(NeutrinoMessages::SHOW_INFOBAR, 0); g_RCInput->postMsg(NeutrinoMessages::SHOW_INFOBAR, 0);
//g_RCInput->postMsg(NeutrinoMessages::EVT_ZAP_COMPLETE, (neutrino_msg_data_t) &live_channel_id);
StartSubtitles();
} }
} }