From b54d75c6b5850dfbda144833deef42289657058e Mon Sep 17 00:00:00 2001 From: Chris Tallon Date: Sun, 25 May 2008 17:01:12 +0000 Subject: [PATCH] Code cleanup, removal of old code. Boxstack locking. Timercall redraw done directly instead of using a message and postMessageFromOuterSpace --- boxstack.cc | 93 +++++++- boxstack.h | 12 ++ command.cc | 3 +- command.h | 3 +- objects.mk | 2 +- vchannellist.cc | 1 - vchannelselect.cc | 2 +- vepg.cc | 9 +- vlivebanner.cc | 346 ------------------------------ vlivebanner.h | 64 ------ vmedialist.cc | 1 - vpicture.cc | 1 - vradiorec.cc | 20 +- vtimerlist.cc | 16 +- vvideolive.cc | 524 ---------------------------------------------- vvideolive.h | 95 --------- vvideolivetv.cc | 18 +- vvideorec.cc | 16 +- vwelcome.cc | 8 +- 19 files changed, 122 insertions(+), 1112 deletions(-) delete mode 100644 vlivebanner.cc delete mode 100644 vlivebanner.h delete mode 100644 vvideolive.cc delete mode 100644 vvideolive.h diff --git a/boxstack.cc b/boxstack.cc index 9cee55c..bcace42 100644 --- a/boxstack.cc +++ b/boxstack.cc @@ -18,6 +18,30 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ + +/* + +#ifndef WIN32 + pthread_mutex_lock(&boxLock); +#else + WaitForSingleObject(boxLock, INFINITE); +#endif + + +#ifndef WIN32 + pthread_mutex_unlock(&boxLock); +#else + ReleaseMutex(boxLock); +#endif + + + + +*/ + + + + #include "boxstack.h" #include "command.h" @@ -48,6 +72,13 @@ int BoxStack::init() { if (initted) return 0; initted = 1; + +#ifndef WIN32 + pthread_mutex_init(&boxLock, NULL); +#else + boxLock = CreateMutex(NULL,FALSE,NULL); +#endif + return 1; } @@ -65,10 +96,22 @@ int BoxStack::shutdown() int BoxStack::add(Boxx* v) { if (!initted) return 0; + +#ifndef WIN32 + pthread_mutex_lock(&boxLock); +#else + WaitForSingleObject(boxLock, INFINITE); +#endif + if (numBoxes == 16) return 0; - boxes[numBoxes++] = v; +#ifndef WIN32 + pthread_mutex_unlock(&boxLock); +#else + ReleaseMutex(boxLock); +#endif + return 1; } @@ -77,6 +120,13 @@ int BoxStack::add(Boxx* v) int BoxStack::remove(Boxx* toDelete) { if (!initted) return 0; + +#ifndef WIN32 + pthread_mutex_lock(&boxLock); +#else + WaitForSingleObject(boxLock, INFINITE); +#endif + if (numBoxes == 0) return 0; // Log::getInstance()->log("BoxStack", Log::DEBUG, "entering remove, numBoxes=%i", numBoxes); @@ -124,6 +174,12 @@ int BoxStack::remove(Boxx* toDelete) Command::getInstance()->postMessageNoLock(m); } +#ifndef WIN32 + pthread_mutex_unlock(&boxLock); +#else + ReleaseMutex(boxLock); +#endif + return 1; } @@ -148,6 +204,13 @@ void BoxStack::update(Boxx* toUpdate, Region* regionToUpdate) // Log::getInstance()->log("BoxStack", Log::DEBUG, "Update called"); // Get the z index of the box +#ifndef WIN32 + pthread_mutex_lock(&boxLock); +#else + WaitForSingleObject(boxLock, INFINITE); +#endif + Log::getInstance()->log("BoxStack", Log::DEBUG, "Locked for update"); + int z; for (z = 0; z < numBoxes; z++) { @@ -187,6 +250,13 @@ void BoxStack::update(Boxx* toUpdate, Region* regionToUpdate) boxes[z]->blt(r2); rl.pop_front(); } + + Log::getInstance()->log("BoxStack", Log::DEBUG, "Unlocking"); +#ifndef WIN32 + pthread_mutex_unlock(&boxLock); +#else + ReleaseMutex(boxLock); +#endif } void BoxStack::repaintRevealed(int x, Region r) @@ -353,10 +423,27 @@ void BoxStack::boxSplit(Region r, int start, int end, int direction, RegionList& void BoxStack::removeAll() { // 1.. Don't delete wallpaper. No point. + + // Need locking on this one?? + +#ifndef WIN32 + pthread_mutex_lock(&boxLock); +#else + WaitForSingleObject(boxLock, INFINITE); +#endif + + for (; numBoxes > 1; --numBoxes) { delete boxes[numBoxes-1]; } + +#ifndef WIN32 + pthread_mutex_unlock(&boxLock); +#else + ReleaseMutex(boxLock); +#endif + } int BoxStack::handleCommand(int command) @@ -450,6 +537,10 @@ void BoxStack::processMessage(Message* m) } case Message::REDRAW: { + Log::getInstance()->log("BoxStack", Log::DEBUG, "=================================================================="); + Log::getInstance()->log("BoxStack", Log::DEBUG, "DEPRECATED BOXSTACK REDRAW MESSAGE CALL --------------------------"); + Log::getInstance()->log("BoxStack", Log::DEBUG, "=================================================================="); + abort(); Boxx* toRedraw = (Boxx*)m->from; Region* toRedrawRegion = (Region*)m->parameter; update(toRedraw, toRedrawRegion); diff --git a/boxstack.h b/boxstack.h index 558c416..97465ff 100644 --- a/boxstack.h +++ b/boxstack.h @@ -26,6 +26,10 @@ #include #include +#ifndef WIN32 +#include +#endif + #include "boxx.h" #include "region.h" #include "message.h" @@ -47,10 +51,12 @@ class BoxStack int init(); int shutdown(); + // These functions do internal locking, so can be called directly from any thread. Hopefully. int add(Boxx*); int remove(Boxx*); void removeAll(); void update(Boxx*, Region* regionToUpdate = NULL); + // -- end int handleCommand(int command); void processMessage(Message* m); @@ -62,6 +68,12 @@ class BoxStack Boxx* boxes[20]; int numBoxes; +#ifndef WIN32 + pthread_mutex_t boxLock; +#else + HANDLE boxLock; +#endif + void deleteBox(int z); void repaintRevealed(int x, Region r); void boxSplit(Region r, int start, int end, int direction, RegionList& rl); diff --git a/command.cc b/command.cc index 910db61..ded44e9 100644 --- a/command.cc +++ b/command.cc @@ -42,7 +42,6 @@ #include "timerreceiver.h" #include "timers.h" #include "wol.h" -#include "vvideolive.h" #include "vconnect.h" #include "message.h" #include "remote.h" @@ -368,7 +367,7 @@ void Command::processMessage(Message* m) } case Message::STREAM_END: { - VVideoLive::getInstance()->streamEnd(); + // Obselete. If you're using this, something is wrong. break; } // Also connection_lost comes from player - anywhere else? diff --git a/command.h b/command.h index d6ffbb9..4ce464b 100644 --- a/command.h +++ b/command.h @@ -30,9 +30,8 @@ #include #ifndef WIN32 #include -#else - #endif + #include #include "defines.h" diff --git a/objects.mk b/objects.mk index 2305844..77681f4 100644 --- a/objects.mk +++ b/objects.mk @@ -18,5 +18,5 @@ OBJECTS1 = command.o log.o tcp.o dsock.o thread.o timers.o i18n.o mutex.o \ vaudioplayer.o audioplayer.o demuxeraudio.o abstractoption.o \ eventdispatcher.o vdrrequestpacket.o vdrresponsepacket.o \ vvideolivetv.o \ - vvideolive.o vlivebanner.o playerlivetv.o playerliveradio.o \ + playerlivetv.o playerliveradio.o \ wprogressbar.o diff --git a/vchannellist.cc b/vchannellist.cc index d624b62..d0d0aa4 100644 --- a/vchannellist.cc +++ b/vchannellist.cc @@ -22,7 +22,6 @@ #include "remote.h" #include "wsymbol.h" -#include "vvideolive.h" #include "vvideolivetv.h" #include "colour.h" #include "video.h" diff --git a/vchannelselect.cc b/vchannelselect.cc index cf821ab..5408ee1 100644 --- a/vchannelselect.cc +++ b/vchannelselect.cc @@ -21,13 +21,13 @@ #include "vchannelselect.h" #include "remote.h" -#include "vvideolive.h" #include "message.h" #include "boxstack.h" #include "colour.h" #include "log.h" #include "timers.h" #include "command.h" +#include "vdr.h" // this class only works as it does because the remote command // values for the numbers are the numbers themselves ! diff --git a/vepg.cc b/vepg.cc index f9e06d1..f6dfb55 100644 --- a/vepg.cc +++ b/vepg.cc @@ -42,7 +42,6 @@ #include "wsymbol.h" #include "message.h" #include "colour.h" -#include "vvideolive.h" #include "boxstack.h" #include "channel.h" #include "i18n.h" @@ -330,13 +329,7 @@ void VEpg::drawData() void VEpg::timercall(int clientReference) { drawData(); - // Put updateView through master mutex since boxstack is not mutex protected - Message* m = new Message(); - m->message = Message::REDRAW; - m->to = boxstack; - m->from = this; - m->parameter = 0; - Command::getInstance()->postMessageFromOuterSpace(m); + boxstack->update(this); } int VEpg::handleCommand(int command) diff --git a/vlivebanner.cc b/vlivebanner.cc deleted file mode 100644 index d919000..0000000 --- a/vlivebanner.cc +++ /dev/null @@ -1,346 +0,0 @@ -/* - Copyright 2004-2005 Chris Tallon - - This file is part of VOMP. - - VOMP is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - VOMP is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with VOMP; if not, write to the Free Software - Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -*/ - -#include "vlivebanner.h" - -#include "vvideolive.h" -#include "remote.h" -#include "colour.h" -#include "video.h" -#include "event.h" -#include "vinfo.h" -#include "boxstack.h" -#include "i18n.h" -#include "timers.h" -#include "channel.h" -#include "command.h" - -VLiveBanner* VLiveBanner::instance = NULL; - -VLiveBanner::VLiveBanner(VVideoLive* tvvideoLive, Channel* channel, bool bannerTakesCommands) -{ - instance = this; - eventList = NULL; - vvideoLive = tvvideoLive; - takeCommands = bannerTakesCommands; - - clockRegion.x = 440; - clockRegion.y = 0; - clockRegion.w = 60; - clockRegion.h = 30; - - setSize(500, 120); - createBuffer(); - if (Video::getInstance()->getFormat() == Video::PAL) - { - setPosition(124, 410); - } - else - { - setPosition(114, 320); - } - - - setTitleBarOn(1); - setTitleBarColour(Colour::TITLEBARBACKGROUND); - - sl.setPosition(0, 30); - sl.setSize(area.w, area.h - 60); - sl.setNoLoop(); - add(&sl); - - setChannel(channel); -} - -VLiveBanner::~VLiveBanner() -{ - instance = NULL; - Timers::getInstance()->cancelTimer(this, 1); - Timers::getInstance()->cancelTimer(this, 2); - delData(); -} - -VLiveBanner* VLiveBanner::getInstance() -{ - return instance; -} - -void VLiveBanner::delData() -{ - if (eventList) - { - int eventListSize = eventList->size(); - for(int i = 0; i < eventListSize; i++) - { - delete (*eventList)[i]; - } - eventList->clear(); - delete eventList; - - } - sl.clear(); -} - -void VLiveBanner::setChannel(Channel* tChannel) -{ - delData(); - currentChannel = tChannel; - // get the data - - int numberWidth = (int)VDR::getInstance()->getChannelNumberWidth(); - - char ttitleText[100]; - SNPRINTF(ttitleText, 99, "%0*lu - %s", numberWidth, currentChannel->number, currentChannel->name); - - setTitleText(ttitleText); - eventList = VDR::getInstance()->getChannelSchedule(currentChannel->number); - - if (!eventList) - { - sl.addOption(tr("No channel data available"), 0, 1); - } - else - { - sort(eventList->begin(), eventList->end(), EventSorter()); - - char tempString[300]; - char tempString2[300]; - struct tm* btime; - Event* event; - int first = 1; - int eventListSize = eventList->size(); - for(int i = 0; i < eventListSize; i++) - { - event = (*eventList)[i]; - - //btime = localtime((time_t*)&event->time); - time_t etime = event->time; - btime = localtime(&etime); -#ifndef _MSC_VER - strftime(tempString2, 299, "%0H:%0M ", btime); -#else - strftime(tempString2, 299, "%H:%M ", btime); -#endif - SNPRINTF(tempString, 299, "%s %s", tempString2, event->title); - sl.addOption(tempString, (ULONG)event, first); - first = 0; - } - } - - // Reset the timer as it probably took 1-2 seconds to change the channel - Timers::getInstance()->setTimerD(this, 1, 4); -} - -void VLiveBanner::draw() -{ - TBBoxx::draw(); - rectangle(0, area.h - 30, area.w, 30, titleBarColour); - - rectangle(7, area.h - 24, 18, 16, Colour::RED); - drawText(tr("EPG"), 32, area.h - 25, Colour::LIGHTTEXT); - - rectangle(110, area.h - 24, 18, 16, Colour::GREEN); - drawText(tr("info"), 135, area.h - 25, Colour::LIGHTTEXT); - - drawClock(); -} - -int VLiveBanner::handleCommand(int command) -{ - switch (command) - { - case Remote::OK: - case Remote::BACK: - { - Timers::getInstance()->cancelTimer(this, 1); // if it exists - return 4; - } - case Remote::DF_UP: - { - if (!takeCommands) return 0; // banner was auto, old remote - } // else drop through - case Remote::UP: - { - sl.up(); - sl.draw(); - - BoxStack::getInstance()->update(this); - - // Arrows pressed, go to an 8s timer - Timers::getInstance()->setTimerD(this, 1, 8); - - return 2; - } - case Remote::DF_DOWN: - { - if (!takeCommands) return 0; // banner was auto, old remote - } // else drop through - case Remote::DOWN: - { - sl.down(); - sl.draw(); - - BoxStack::getInstance()->update(this); - - // Arrows pressed, go to an 8s timer - Timers::getInstance()->setTimerD(this, 1, 8); - - return 2; - } - case Remote::CHANNELUP: - { - // cancel timer so this view is still here later - Timers::getInstance()->cancelTimer(this, 1); // if it exists - vvideoLive->channelChange(VVideoLive::OFFSET, VVideoLive::UP); - return 2; - } - case Remote::CHANNELDOWN: - { - // cancel timer so this view is still here later - Timers::getInstance()->cancelTimer(this, 1); // if it exists - vvideoLive->channelChange(VVideoLive::OFFSET, VVideoLive::DOWN); - return 2; - } - case Remote::GREEN: - case Remote::MENU: - { - if (!eventList) return 2; - Event* event = (Event*)sl.getCurrentOptionData(); - Log::getInstance()->log("VLiveBanner", Log::DEBUG, "Found the option you pointed at. %s", event->title); - // First, cancel my delete timer - Timers::getInstance()->cancelTimer(this, 1); // if it exists - - VInfo* vi = new VInfo(); - vi->setTitleText(event->title); - vi->setBorderOn(1); - vi->setExitable(); - if (event->description) vi->setMainText(event->description); - else vi->setMainText(tr("Summary unavailable")); - if (Video::getInstance()->getFormat() == Video::PAL) - { - vi->setPosition(120, 130); - } - else - { - vi->setPosition(110, 90); - } - vi->setSize(510, 270); - vi->createBuffer(); - vi->draw(); - - BoxStack::getInstance()->add(vi); - BoxStack::getInstance()->update(vi); - - return 2; - } - case Remote::GUIDE: - case Remote::RED: - { - // full epg - Timers::getInstance()->cancelTimer(this, 1); // if it exists - Message* m = new Message(); // Must be done after this view deleted - m->message = Message::EPG; - m->to = vvideoLive; - m->from = this; - Command::getInstance()->postMessageNoLock(m); - return 4; - } - } - - return 1; -} - -void VLiveBanner::timercall(int clientReference) -{ - if (clientReference == 1) - { - // delete me! - Message* m = new Message(); // Delete self - m->message = Message::CLOSE_ME; - m->to = BoxStack::getInstance(); - m->from = this; - Command::getInstance()->postMessageFromOuterSpace(m); - } - else if (clientReference == 2) - { - // redraw clock - drawClock(); - Message* m = new Message(); - m->message = Message::REDRAW; - m->to = BoxStack::getInstance(); - m->from = this; - m->parameter = (ULONG)&clockRegion; - Command::getInstance()->postMessageFromOuterSpace(m); - } -} - -void VLiveBanner::drawClock() -{ - // Blank the area first - rectangle(area.w - 60, 0, 60, 30, titleBarColour); - - char timeString[20]; - time_t t; - time(&t); - struct tm* tms = localtime(&t); - strftime(timeString, 19, "%H:%M", tms); - drawTextRJ(timeString, 490, 5, Colour::LIGHTTEXT); - - time_t dt = 60 - (t % 60); // seconds to the next minute - if (dt == 0) dt = 60; // advance a whole minute if necessary - dt += t; // get a time_t value for it rather than using duration - // (so it will occur at the actual second and not second and a half) - - Timers::getInstance()->setTimerT(this, 2, dt); -} - -void VLiveBanner::processMessage(Message* m) -{ - if (m->message == Message::MOUSE_MOVE) - { - if (sl.mouseMove((m->parameter>>16)-getScreenX(),(m->parameter&0xFFFF)-getScreenY())) - { - sl.draw(); - BoxStack::getInstance()->update(this); - } - } - else if (m->message == Message::MOUSE_LBDOWN) - { - //check if press is outside this view! then simulate cancel - int x=(m->parameter>>16)-getScreenX(); - int y=(m->parameter&0xFFFF)-getScreenY(); - if (x<0 || y <0 || x>(int)getWidth() || y>(int)getHeight()) - { - BoxStack::getInstance()->handleCommand(Remote::BACK); //simulate cancel press - } - else if (y>=(int)area.h-24 && y<=(int)area.h-6) - { - //y coordinate is right! - if (x>=7 &&x<=25) - { - BoxStack::getInstance()->handleCommand(Remote::RED); //simulate red press - } - else if (x>=110 &&x<=128) - { - BoxStack::getInstance()->handleCommand(Remote::GREEN); //simulate red press - } - } - } -} diff --git a/vlivebanner.h b/vlivebanner.h deleted file mode 100644 index 90b239d..0000000 --- a/vlivebanner.h +++ /dev/null @@ -1,64 +0,0 @@ -/* - Copyright 2004-2005 Chris Tallon - - This file is part of VOMP. - - VOMP is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - VOMP is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with VOMP; if not, write to the Free Software - Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -*/ - -#ifndef VLIVEBANNER_H -#define VLIVEBANNER_H - -#include -#include -#include -#include - -#include "tbboxx.h" -#include "timerreceiver.h" -#include "wselectlist.h" -#include "region.h" -#include "vdr.h" - -class VVideoLive; -class Channel; - -class VLiveBanner : public TBBoxx, public TimerReceiver -{ - public: - VLiveBanner(VVideoLive* tvvideoLive, Channel* channel, bool bannerTakesCommands); - ~VLiveBanner(); - static VLiveBanner* getInstance(); - void delData(); - - void setChannel(Channel* channel); - - int handleCommand(int command); - void processMessage(Message* m); - void draw(); - void timercall(int clientReference); - - private: - static VLiveBanner* instance; - VVideoLive* vvideoLive; - WSelectList sl; - Channel* currentChannel; - EventList* eventList; - bool takeCommands; - void drawClock(); - Region clockRegion; -}; - -#endif diff --git a/vmedialist.cc b/vmedialist.cc index 0c77ea8..d096107 100644 --- a/vmedialist.cc +++ b/vmedialist.cc @@ -31,7 +31,6 @@ #include "remote.h" #include "wsymbol.h" #include "boxstack.h" -#include "vvideolive.h" #include "colour.h" #include "video.h" #include "i18n.h" diff --git a/vpicture.cc b/vpicture.cc index 60026e0..4540f0f 100644 --- a/vpicture.cc +++ b/vpicture.cc @@ -31,7 +31,6 @@ #include "boxstack.h" #include "vdr.h" #include "media.h" -#include "vvideolive.h" #include "video.h" #include "vinfo.h" #include "i18n.h" diff --git a/vradiorec.cc b/vradiorec.cc index 50959d0..a028d77 100644 --- a/vradiorec.cc +++ b/vradiorec.cc @@ -403,12 +403,8 @@ void VRadioRec::timercall(int clientReference) // Update clock if (!barShowing) break; drawBarClocks(); - Message* m = new Message(); - m->message = Message::REDRAW; - m->to = boxstack; - m->from = this; - m->parameter = (ULONG)&barRegion; - Command::getInstance()->postMessageFromOuterSpace(m); + boxstack->update(this, &barRegion); + timers->setTimerD(this, 2, 0, 200000000); break; } @@ -493,9 +489,6 @@ void VRadioRec::drawBarClocks() drawText(buffer, clocksRegion.x, clocksRegion.y, Colour::LIGHTTEXT); - - - // Draw progress bar int progBarXbase = barRegion.x + 300; @@ -544,11 +537,6 @@ void VRadioRec::removeBar() timers->cancelTimer(this, 2); barShowing = false; rectangle(barRegion, Colour::BLACK); - - Message* m = new Message(); - m->message = Message::REDRAW; - m->to = boxstack; - m->from = this; - m->parameter = (ULONG)&barRegion; - Command::getInstance()->postMessageFromOuterSpace(m); + boxstack->update(this, &barRegion); } + diff --git a/vtimerlist.cc b/vtimerlist.cc index b2bfd60..23d6cd7 100644 --- a/vtimerlist.cc +++ b/vtimerlist.cc @@ -223,23 +223,11 @@ void VTimerList::drawIndicators() void VTimerList::timercall(int clientReference) { drawClock(); - - Message* m = new Message(); - m->message = Message::REDRAW; - m->to = BoxStack::getInstance(); - m->from = this; - m->parameter = (ULONG)&clockRegion; - Command::getInstance()->postMessageFromOuterSpace(m); + BoxStack::getInstance()->update(this, &clockRegion); flipflop = !flipflop; drawIndicators(); - - m = new Message(); - m->message = Message::REDRAW; - m->to = BoxStack::getInstance(); - m->from = this; - m->parameter = (ULONG)&indicatorsRegion; - Command::getInstance()->postMessageFromOuterSpace(m); + BoxStack::getInstance()->update(this, &indicatorsRegion); } int VTimerList::handleCommand(int command) diff --git a/vvideolive.cc b/vvideolive.cc deleted file mode 100644 index a353034..0000000 --- a/vvideolive.cc +++ /dev/null @@ -1,524 +0,0 @@ -/* - Copyright 2004-2005 Chris Tallon - - This file is part of VOMP. - - VOMP is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - VOMP is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with VOMP; if not, write to the Free Software - Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -*/ - -#include "vvideolive.h" - -#include "vchannellist.h" -#include "video.h" -#include "player.h" -#include "playerradio.h" -#include "channel.h" -#include "vlivebanner.h" -#include "boxstack.h" -#include "vchannelselect.h" -#include "colour.h" -#include "osd.h" -#include "vinfo.h" -#include "command.h" -#include "i18n.h" -#include "vepg.h" -#include "wtextbox.h" -#include "remote.h" -#include "vaudioselector.h" - -VVideoLive* VVideoLive::instance = NULL; - -VVideoLive::VVideoLive(ChannelList* tchanList, ULONG tstreamType, VChannelList* tvchannelList) -{ - instance = this; - vdr = VDR::getInstance(); - boxstack = BoxStack::getInstance(); - video = Video::getInstance(); - - chanList = tchanList; - vchannelList = tvchannelList; - - currentChannel = 0; - previousChannel = 0; - unavailable = 0; - unavailableView = NULL; - streamType = tstreamType; - videoMode = video->getMode(); - - if (streamType == VDR::RADIO) - { - player = (void*)new PlayerRadio(Command::getInstance(), this, false); - ((PlayerRadio*)player)->init(0, 0); - } - else - { - player = (void*)new Player(Command::getInstance(), this, false); - ((Player*)player)->init(); - } - - setSize(video->getScreenWidth(), video->getScreenHeight()); - createBuffer(); - Colour transparent(0, 0, 0, 0); - fillColour(transparent); - - dowss = false; - char* optionWSS = vdr->configLoad("General", "WSS"); - if (optionWSS) - { - if (strstr(optionWSS, "Yes")) dowss = true; - delete[] optionWSS; - } - Log::getInstance()->log("VVideoLive", Log::DEBUG, "Do WSS: %u", dowss); - - if (dowss) - { - wss.setFormat(video->getFormat()); - wss.setWide(true); - add(&wss); - - wssRegion.x = 0; - wssRegion.y = 6; - wssRegion.w = video->getScreenWidth(); - wssRegion.h = 2; - } -} - -VVideoLive::~VVideoLive() -{ - if (streamType == VDR::RADIO) - { - delete (PlayerRadio*)player; - } - else - { - delete (Player*)player; - } - - instance = NULL; - video->setDefaultAspect(); -} - -VVideoLive* VVideoLive::getInstance() -{ - return instance; -} - -int VVideoLive::handleCommand(int command) -{ - switch(command) - { - case Remote::STOP: - case Remote::BACK: - case Remote::MENU: - { - if (unavailable) showUnavailable(0); - else stop(); - - vchannelList->highlightChannel((*chanList)[currentChannel]); - return 4; - } - // Take up and down from new remote and do live banner - case Remote::UP: - case Remote::DOWN: - { - doBanner(true); - return 2; - } - case Remote::DF_UP: - case Remote::CHANNELUP: - { - if (unavailable) showUnavailable(0); - else stop(); - channelChange(OFFSET, UP); - return 2; - } - case Remote::DF_DOWN: - case Remote::CHANNELDOWN: - { - if (unavailable) showUnavailable(0); - else stop(); - channelChange(OFFSET, DOWN); - return 2; - } - case Remote::PREVCHANNEL: - { - if (unavailable) showUnavailable(0); - else stop(); - channelChange(PREVIOUS, 0); - return 2; - } - case Remote::OK: - { - doBanner(true); - return 2; - } - case Remote::GUIDE: - case Remote::RED: - { - showEPG(); - return 2; - } - case Remote::FULL: - case Remote::TV: - { - toggleChopSides(); - return 2; - } - - case Remote::ZERO: - case Remote::ONE: - case Remote::TWO: - case Remote::THREE: - case Remote::FOUR: - case Remote::FIVE: - case Remote::SIX: - case Remote::SEVEN: - case Remote::EIGHT: - case Remote::NINE: - { - VChannelSelect* v = new VChannelSelect(this); - v->draw(); - boxstack->add(v); - boxstack->update(v); - - v->handleCommand(command); - - return 2; - } - case Remote::GREEN: - { - if (streamType == VDR::VIDEO) - { - VAudioSelector* vas = new VAudioSelector(this, (*chanList)[currentChannel], ((Player*)player)->getCurrentAudioChannel()); - vas->setBackgroundColour(Colour::VIEWBACKGROUND); - vas->setPosition(0, getHeight()-200); - vas->draw(); - BoxStack::getInstance()->add(vas); - BoxStack::getInstance()->update(vas); - } - } -#ifdef DEV - case Remote::YELLOW: - { - } - case Remote::BLUE: - { - } -#endif - } - - return 1; -} - -void VVideoLive::channelChange(UCHAR changeType, UINT newData) -{ - UINT newChannel = 0; - - if (changeType == INDEX) - { - newChannel = newData; - } - else if (changeType == NUMBER) - { - UINT i; - for(i = 0; i < chanList->size(); i++) - { - if ((*chanList)[i]->number == (UINT)newData) - { - newChannel = i; - break; - } - } - - if (i == chanList->size()) - { - doNoSuchChannel(); - return; - } - } - else if (changeType == OFFSET) - { - if (newData == UP) newChannel = upChannel(); - else newChannel = downChannel(); - } - else if (changeType == PREVIOUS) - { - newChannel = previousChannel; - } - else - { - return; // bad input! - } - - previousChannel = currentChannel; - currentChannel = newChannel; - - if (unavailable) showUnavailable(0); - else stop(1); - -// VEpg* vepg = VEpg::getInstance(); -// if(vepg) vepg->setCurrentChannel((*chanList)[currentChannel]->name); - - VLiveBanner* vlb = VLiveBanner::getInstance(); - if (vlb) - { - vlb->setChannel((*chanList)[currentChannel]); - vlb->draw(); - boxstack->update(vlb); - } - - play(); -} - -void VVideoLive::streamEnd() -{ - Log::getInstance()->log("VVideoLive", Log::DEBUG, "streamEnd"); - stop(1); - showUnavailable(1); -} - -void VVideoLive::processMessage(Message* m) -{ - if (m->message == Message::MOUSE_LBDOWN) - { - BoxStack::getInstance()->handleCommand(Remote::OK); //simulate rok press - } - else if (m->message == Message::CHANNEL_CHANGE) - { - channelChange(NUMBER, m->parameter); - } - else if (m->message == Message::EPG) - { - Log::getInstance()->log("VVideoLive", Log::DEBUG, "EPG requested from live banner"); - showEPG(); - } - else if (m->message == Message::EPG_CLOSE) - { - video->setMode(videoMode); - if (saveUnavailable) showUnavailable(1); - } - else if (m->message == Message::AUDIO_CHANGE_CHANNEL) - { - Log::getInstance()->log("VVideoLive", Log::DEBUG, "Received change audio channel to %i", m->parameter); - ((Player*)player)->setAudioChannel(m->parameter&0xFFFF,(m->parameter&0xFF0000)>>16); - } - else if (m->message == Message::PLAYER_EVENT) - { - switch(m->parameter) - { - case Player::CONNECTION_LOST: // connection lost detected - { - Log::getInstance()->log("VVideoLive", Log::DEBUG, "Received connection lost from player"); - // I can't handle this, send it to command - Message* m2 = new Message(); - m2->to = Command::getInstance(); - m2->message = Message::CONNECTION_LOST; - Command::getInstance()->postMessageNoLock(m2); - break; - } - case Player::STREAM_END: - { - // I can't handle this, send it to command - improve this - Message* m2 = new Message(); // Must be done after this thread finishes, and must break into master mutex - m2->to = Command::getInstance(); - m2->message = Message::STREAM_END; - Command::getInstance()->postMessageNoLock(m2); - break; - } - case Player::ASPECT43: - { - if (dowss) - { - Log::getInstance()->log("VVideoRec", Log::DEBUG, "Received do WSS 43"); - wss.setWide(false); - wss.draw(); - BoxStack::getInstance()->update(this, &wssRegion); - } - break; - } - case Player::ASPECT169: - { - if (dowss) - { - Log::getInstance()->log("VVideoRec", Log::DEBUG, "Received do WSS 169"); - wss.setWide(true); - wss.draw(); - BoxStack::getInstance()->update(this, &wssRegion); - } - break; - } - } - } -} - -void VVideoLive::doBanner(bool bannerTakesCommands) -{ - if (VEpg::getInstance()) return; - - if (VLiveBanner::getInstance()) return; // there already is one - - VLiveBanner* vlb = new VLiveBanner(this, (*chanList)[currentChannel], bannerTakesCommands); - - vlb->draw(); - boxstack->add(vlb); - boxstack->update(vlb); -} - -void VVideoLive::doNoSuchChannel() -{ - Log::getInstance()->log("VVideoLive", Log::ERR, "No such channel"); - // FIXME do gui for this -} - -void VVideoLive::showUnavailable(int active) -{ - if (active == unavailable) return; - - if (active) - { - unavailable = 1; - - unavailableView = new VInfo(); - unavailableView->setSize(400, 200); - unavailableView->createBuffer(); - if (video->getFormat() == Video::PAL) - { - unavailableView->setPosition(170, 200); - } - else - { - unavailableView->setPosition(160, 150); - } - unavailableView->setTitleText((*chanList)[currentChannel]->name); - unavailableView->setOneLiner(tr("Channel unavailable")); - unavailableView->setDropThrough(); - unavailableView->draw(); - boxstack->add(unavailableView); - boxstack->update(unavailableView); - } - else - { - unavailable = 0; - boxstack->remove(unavailableView); - unavailableView = NULL; - } -} - -void VVideoLive::play(int noShowVLB) -{ - showUnavailable(0); - - int available = vdr->streamChannel((*chanList)[currentChannel]->number); - - if (!available) - { - if (!noShowVLB) doBanner(false); - showUnavailable(1); - if (!vdr->isConnected()) { Command::getInstance()->connectionLost(); return; } - } - else - { - if (!noShowVLB) doBanner(false); - - // FIXME - change this streamType thingy to the new system using getPids - // FIXME - upgrade PlayerRadio to new getPids - - Channel* toPlay = (*chanList)[currentChannel]; - toPlay->loadPids(); - - if (streamType == VDR::RADIO) - { - ((PlayerRadio*)player)->play(toPlay->apids[0].pid); - } - else - { - ((Player*)player)->play(toPlay->vpid, toPlay->apids[0].pid); - } - } -} - -void VVideoLive::stop(int noRemoveVLB) -{ - if (unavailable) return; - if (!noRemoveVLB && VLiveBanner::getInstance()) boxstack->remove(VLiveBanner::getInstance()); // if live banner is present, remove it. won't cause damage if its not present - - if (streamType == VDR::RADIO) - { - ((PlayerRadio*)player)->stop(); - } - else - { - ((Player*)player)->stop(); - } - - Log::getInstance()->log("VVideoLive", Log::DEBUG, "Delay starts here due to time taken by plugin to stop"); - vdr->stopStreaming(); - if (!vdr->isConnected()) { Command::getInstance()->connectionLost(); return; } - Log::getInstance()->log("VVideoLive", Log::DEBUG, "Delay ends here due to time taken by plugin to stop"); -} - -UINT VVideoLive::upChannel() -{ - if (currentChannel == (chanList->size() - 1)) // at the end - return 0; // so go to start - else - return currentChannel + 1; -} - -UINT VVideoLive::downChannel() -{ - if (currentChannel == 0) // at the start - return chanList->size() - 1; // so go to end - else - return currentChannel - 1; -} - -void VVideoLive::showEPG() -{ - saveUnavailable = unavailable; - if (unavailable) showUnavailable(0); - - if (VEpg::getInstance()) return; // already showing! - - video->setMode(Video::QUARTER); - video->setPosition(170, 5); //TODO need to deal with 4:3 switching - - VEpg* vepg = new VEpg(this, currentChannel, streamType); - vepg->draw(); - - Log::getInstance()->log("VVideoLive", Log::DEBUG, "EPG draw finished"); - - boxstack->add(vepg); - boxstack->update(vepg); - - Log::getInstance()->log("VVideoLive", Log::DEBUG, "EPG blttd to screen"); -} - -void VVideoLive::toggleChopSides() -{ - if (video->getTVsize() == Video::ASPECT16X9) return; // Means nothing for 16:9 TVs - - if (videoMode == Video::NORMAL) - { - videoMode = Video::LETTERBOX; - video->setMode(Video::LETTERBOX); - } - else - { - videoMode = Video::NORMAL; - video->setMode(Video::NORMAL); - } -} - diff --git a/vvideolive.h b/vvideolive.h deleted file mode 100644 index d4249fe..0000000 --- a/vvideolive.h +++ /dev/null @@ -1,95 +0,0 @@ -/* - Copyright 2004-2005 Chris Tallon - - This file is part of VOMP. - - VOMP is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - VOMP is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with VOMP; if not, write to the Free Software - Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -*/ - -#ifndef VVIDEOLIVE_H -#define VVIDEOLIVE_H - -#include -#include - -#include "boxx.h" -#include "region.h" -#include "wwss.h" -#include "vdr.h" - -class VEpg; -class VChannelList; -class VLiveBanner; -class VInfo; -class Video; -class VChannelList; -class BoxStack; - -class VVideoLive : public Boxx -{ - public: - VVideoLive(ChannelList* chanList, ULONG streamType, VChannelList* vchannelList); - ~VVideoLive(); - static VVideoLive* getInstance(); - int handleCommand(int command); - void processMessage(Message* m); - void streamEnd(); // from command - - void channelChange(UCHAR changeType, UINT newData); - // changeType = INDEX = (newData is a channel index in the list) - // = NUMBER = (newData is a real channel number) - // = OFFSET = (newData is UP or DOWN) - - void play(int noShowVLB = 0); - void stop(int noRemoveVLB = 0); - - const static UCHAR INDEX = 1; - const static UCHAR NUMBER = 2; - const static UCHAR OFFSET = 3; - const static UCHAR PREVIOUS = 4; - const static UCHAR UP = 1; - const static UCHAR DOWN = 2; - - private: - static VVideoLive* instance; - BoxStack* boxstack; - VDR* vdr; - Video* video; - void* player; // HA HA FIXME - ChannelList* chanList; - VChannelList* vchannelList; - UINT currentChannel; // index in list - UINT previousChannel; // index in list - int unavailable; - VInfo* unavailableView; - ULONG streamType; - - UINT upChannel(); - UINT downChannel(); - void doBanner(bool takesCommands); - void showUnavailable(int active); - int xpos; - void showEPG(); - void doNoSuchChannel(); - void toggleChopSides(); - int videoMode; - int saveUnavailable; - - Wwss wss; - Region wssRegion; - bool dowss; -}; - -#endif diff --git a/vvideolivetv.cc b/vvideolivetv.cc index 925f6f4..8e6d4b4 100644 --- a/vvideolivetv.cc +++ b/vvideolivetv.cc @@ -724,8 +724,6 @@ void VVideoLiveTV::timercall(int ref) { if (keying) { - // Really, now that cancelTimer basically protects us from deletion, why can't we execute gui stuff here? - UINT newChannel = 0; for(int i = keying - 1; i >= 0; i--) newChannel += keyingInput[i] * (ULONG)pow(10., i); @@ -734,7 +732,7 @@ void VVideoLiveTV::timercall(int ref) m->to = this; m->parameter = newChannel; m->tag = 1; // signal to call displayOSD(); - Command::getInstance()->postMessageFromOuterSpace(m); // FIXME cjt yeah you know what. + Command::getInstance()->postMessageFromOuterSpace(m); } else { @@ -748,12 +746,7 @@ void VVideoLiveTV::timercall(int ref) osd.setVisible(false); draw(); - Message* m = new Message(); - m->message = Message::REDRAW; - m->to = BoxStack::getInstance(); - m->from = this; - m->parameter = (ULONG)osd.getRegion(); - Command::getInstance()->postMessageFromOuterSpace(m); // FIXME cjt yeah you know what. + boxstack->update(this, osd.getRegion()); } } else if (ref == 2) @@ -762,12 +755,7 @@ void VVideoLiveTV::timercall(int ref) if (osd.getVisible()) { clock.draw(); - Message* m = new Message(); - m->message = Message::REDRAW; - m->to = BoxStack::getInstance(); - m->from = this; - m->parameter = (ULONG)osd.getRegion(); - Command::getInstance()->postMessageFromOuterSpace(m); // FIXME cjt yeah you know what. + boxstack->update(this, osd.getRegion()); } } } diff --git a/vvideorec.cc b/vvideorec.cc index cea94c2..909a35f 100644 --- a/vvideorec.cc +++ b/vvideorec.cc @@ -680,12 +680,8 @@ void VVideoRec::timercall(int clientReference) // Update clock if (!barShowing) break; drawBarClocks(); - Message* m = new Message(); - m->message = Message::REDRAW; - m->to = BoxStack::getInstance(); - m->from = this; - m->parameter = (ULONG)&barRegion; - Command::getInstance()->postMessageFromOuterSpace(m); + boxstack->update(this, &barRegion); + timers->setTimerD(this, 2, 0, 200000000); break; } @@ -831,13 +827,7 @@ void VVideoRec::removeBar() barScanHold = false; barVasHold = false; rectangle(barRegion, transparent); - - Message* m = new Message(); - m->message = Message::REDRAW; - m->to = BoxStack::getInstance(); - m->from = this; - m->parameter = (ULONG)&barRegion; - Command::getInstance()->postMessageFromOuterSpace(m); + boxstack->update(this, &barRegion); } void VVideoRec::doSummary() diff --git a/vwelcome.cc b/vwelcome.cc index 8647dce..6325309 100644 --- a/vwelcome.cc +++ b/vwelcome.cc @@ -111,13 +111,7 @@ void VWelcome::drawClock() void VWelcome::timercall(int clientReference) { drawClock(); - // Put updateView through master mutex since boxstack is not mutex protected - Message* m = new Message(); - m->message = Message::REDRAW; - m->to = boxstack; - m->from = this; - m->parameter = (ULONG)&clockRegion; - Command::getInstance()->postMessageFromOuterSpace(m); + boxstack->update(this, &clockRegion); } int VWelcome::handleCommand(int command) -- 2.39.2