From 3a1e86081b9698e97fe8098167e8707097a773b5 Mon Sep 17 00:00:00 2001 From: Chris Tallon Date: Tue, 16 Nov 2021 18:18:45 +0000 Subject: [PATCH] Implement startup-to-live-TV Convert the ChannelList vector to be managed by shared_ptr - this allows either VChannelList or VVideoLiveTV to own it, and it still be deleted appropriately. Convert ChannelList vector to a subclass so its destructor can automatically delete the Channel objects. However, the net says "Thou shalt not subclass std::vector"... --- config.cc | 1 + config.json.sample | 3 ++- control.cc | 44 +++++++++++++++++++++++++++++++++++++++++++- playerradiolive.cc | 2 +- playerradiolive.h | 6 +++--- playervideolive.cc | 2 +- playervideolive.h | 5 +++-- vchannellist.cc | 13 +------------ vchannellist.h | 5 +++-- vdr.cc | 5 +++-- vdr.h | 18 +++++++++++++++--- vepg.cc | 2 +- vepg.h | 5 +++-- vepglistadvanced.cc | 2 +- vepglistadvanced.h | 5 +++-- vvideolivetv.cc | 7 +++---- vvideolivetv.h | 5 +++-- vwelcome.cc | 4 ++-- 18 files changed, 92 insertions(+), 42 deletions(-) diff --git a/config.cc b/config.cc index a6230a5..00e9365 100644 --- a/config.cc +++ b/config.cc @@ -35,6 +35,7 @@ void Config::applyDefaults() auto insertInt = [&] (const char* s, const char* k, int v) { if (jconfig[s][k].isNull()) jconfig[s][k] = v; }; insertBool("main", "daemonize", true); + insertInt("main", "start_to_live_tv", 0); insertBool("log", "enabled", false); insertString("log", "filename", "stdout"); diff --git a/config.json.sample b/config.json.sample index 235127b..3448df4 100644 --- a/config.json.sample +++ b/config.json.sample @@ -14,7 +14,8 @@ { "main": { - "daemonize": true + "daemonize": true, + "start_to_live_tv": 1 // Channel number }, "log": diff --git a/control.cc b/control.cc index 5e9ce2f..d2f61e4 100644 --- a/control.cc +++ b/control.cc @@ -59,6 +59,9 @@ #include "sleeptimer.h" #include "wjpeg.h" #include "osdvector.h" +#include "config.h" +#include "vvideolivetv.h" +#include "channel.h" #ifdef VOMP_PLATFORM_RASPBERRY @@ -1214,7 +1217,46 @@ void Control::doJustConnected(VConnect* vconnect) VWelcome* vw = new VWelcome(); vw->draw(); boxstack->add(vw); - boxstack->update(vw); + // No boxstack->update yet + + Config* localConfig = Config::getInstance(); + int startToLiveTV{}; + localConfig->getInt("main", "start_to_live_tv", startToLiveTV); + if (startToLiveTV) + { + std::shared_ptr chanList = VDR::getInstance()->getChannelsList(VDR::VIDEO); + if (chanList && chanList->size()) + { + Channel* chan = NULL; + for (UINT i = 0; i < chanList->size(); i++) + { + if ((*chanList)[i]->number == static_cast(startToLiveTV)) + { + chan = (*chanList)[i]; + break; + } + } + if (chan) + { + VVideoLiveTV* v = new VVideoLiveTV(chanList, chan->number, NULL); + boxstack->add(v); + v->go(); + } + else + { + // Could not find channel, no VVideoLiveTV was made, update vw instead + boxstack->update(vw); + } + } + else + { + Control::getInstance()->connectionLost(); + } + } + else // Not starting to live TV + { + boxstack->update(vw); + } // Enter pre-keys here // handleCommand(Input::OK); diff --git a/playerradiolive.cc b/playerradiolive.cc index af92f72..228a2d5 100644 --- a/playerradiolive.cc +++ b/playerradiolive.cc @@ -40,7 +40,7 @@ static const char* TAG = "PlayerRadioLive"; // ----------------------------------- Called from outside, one offs or info funcs -PlayerRadioLive::PlayerRadioLive(MessageQueue* tmessageQueue, MessageReceiver* tmessageReceiver, ChannelList* tchanList) +PlayerRadioLive::PlayerRadioLive(MessageQueue* tmessageQueue, MessageReceiver* tmessageReceiver, std::shared_ptr tchanList) : messageQueue(tmessageQueue), messageReceiver(tmessageReceiver), afeed(this), chanList(tchanList) { audio = Audio::getInstance(); diff --git a/playerradiolive.h b/playerradiolive.h index b2fa6e5..2347ced 100644 --- a/playerradiolive.h +++ b/playerradiolive.h @@ -23,8 +23,8 @@ #include #include #include - #include +#include #include "log.h" #include "playerlive.h" @@ -42,7 +42,7 @@ class DemuxerTS; class PlayerRadioLive : public PlayerLive, public Callback, public StreamReceiver { public: - PlayerRadioLive(MessageQueue* messageQueue, MessageReceiver* messageReceiver, ChannelList* chanList); + PlayerRadioLive(MessageQueue* messageQueue, MessageReceiver* messageReceiver, std::shared_ptr chanList); virtual ~PlayerRadioLive(); virtual int init(); @@ -83,7 +83,7 @@ class PlayerRadioLive : public PlayerLive, public Callback, public StreamReceive DemuxerTS* demuxer; VDR* vdr; AFeed afeed; - ChannelList* chanList; + std::shared_ptr chanList; std::queue instructions; const static UCHAR I_SETCHANNEL = 1; diff --git a/playervideolive.cc b/playervideolive.cc index 3a2e10e..9034576 100644 --- a/playervideolive.cc +++ b/playervideolive.cc @@ -44,7 +44,7 @@ static const char* TAG = "PlayerVideoLive"; // ----------------------------------- Called from outside, one offs or info funcs -PlayerVideoLive::PlayerVideoLive(MessageQueue* tmessageQueue, MessageReceiver* tmessageReceiver, OSDReceiver* tosdReceiver, ChannelList* tchanList) +PlayerVideoLive::PlayerVideoLive(MessageQueue* tmessageQueue, MessageReceiver* tmessageReceiver, OSDReceiver* tosdReceiver, std::shared_ptr tchanList) : vfeed(this), afeed(this), tfeed(this), messageQueue(tmessageQueue), messageReceiver(tmessageReceiver), osdReceiver(tosdReceiver), chanList(tchanList) { diff --git a/playervideolive.h b/playervideolive.h index e2ada19..786847b 100644 --- a/playervideolive.h +++ b/playervideolive.h @@ -23,6 +23,7 @@ #include #include #include +#include #include @@ -49,7 +50,7 @@ class DVBSubtitles; class PlayerVideoLive : public PlayerLive, public Callback, public StreamReceiver { public: - PlayerVideoLive(MessageQueue* messageQueue, MessageReceiver* messageReceiver, OSDReceiver* tosdReceiver, ChannelList* chanList); + PlayerVideoLive(MessageQueue* messageQueue, MessageReceiver* messageReceiver, OSDReceiver* tosdReceiver, std::shared_ptr chanList); virtual ~PlayerVideoLive(); virtual int init(); @@ -95,7 +96,7 @@ class PlayerVideoLive : public PlayerLive, public Callback, public StreamReceive MessageQueue* messageQueue; MessageReceiver* messageReceiver; OSDReceiver* osdReceiver; - ChannelList* chanList; + std::shared_ptr chanList; LogNT* logger; Audio* audio; Video* video; diff --git a/vchannellist.cc b/vchannellist.cc index f13368b..4783434 100644 --- a/vchannellist.cc +++ b/vchannellist.cc @@ -77,20 +77,9 @@ VChannelList::VChannelList(ULONG ttype) VChannelList::~VChannelList() { MessageQueue::getInstance()->removeReceiver(this); - - if (chanList) - { - for (UINT i = 0; i < chanList->size(); i++) - { - delete (*chanList)[i]; - } - - chanList->clear(); - delete chanList; - } } -void VChannelList::setList(ChannelList* tlist) +void VChannelList::setList(std::shared_ptr tlist) { char str[500]; OsdVector *osdv=dynamic_cast(Osd::getInstance()); diff --git a/vchannellist.h b/vchannellist.h index c3a82b2..6074801 100644 --- a/vchannellist.h +++ b/vchannellist.h @@ -24,6 +24,7 @@ #include #include #include +#include #include "tbboxx.h" #include "messagequeue.h" @@ -40,7 +41,7 @@ class VChannelList : public TBBoxx, public MessageReceiver VChannelList(ULONG type); virtual ~VChannelList(); - void setList(ChannelList* chanList); + void setList(std::shared_ptr chanList); void highlightChannel(Channel* channel); void processMessage(Message* m); int handleCommand(int command); @@ -48,7 +49,7 @@ class VChannelList : public TBBoxx, public MessageReceiver private: BoxStack* boxstack; - ChannelList* chanList; + std::shared_ptr chanList; WSelectList sl; ULONG type; diff --git a/vdr.cc b/vdr.cc index 376fe94..d4d301d 100644 --- a/vdr.cc +++ b/vdr.cc @@ -854,7 +854,7 @@ char* VDR::moveRecording(char* fileName, char* newPath) return toReturn; } -ChannelList* VDR::getChannelsList(ULONG type) +std::shared_ptr VDR::getChannelsList(ULONG type) { VDR_RequestPacket vrp; if (!vrp.init(VDR_GETCHANNELLIST, true, 0)) return NULL; @@ -862,7 +862,8 @@ ChannelList* VDR::getChannelsList(ULONG type) VDR_ResponsePacket* vresp = RequestResponse(&vrp); if (vresp->noResponse()) { delete vresp; return NULL; } - ChannelList* chanList = new ChannelList(); + //ChannelList* chanList = new ChannelList(); + std::shared_ptr chanList = std::make_shared(); bool h264support=Video::getInstance()->supportsh264(); bool mpeg2support=Video::getInstance()->supportsmpeg2(); diff --git a/vdr.h b/vdr.h index d4befe1..8f705c0 100644 --- a/vdr.h +++ b/vdr.h @@ -31,6 +31,7 @@ #include #include #include +#include #include "defines.h" #include "log.h" @@ -43,10 +44,11 @@ #include "i18n.h" #include "control.h" #include "tcp.h" +#include "channel.h" class RecInfo; class Event; -class Channel; +//class Channel; class VDR_RequestPacket; class VDR_ResponsePacket; #ifdef VOMP_MEDIAPLAYER @@ -57,9 +59,19 @@ class SeriesInfo; class TVMediaInfo; typedef std::vector EventList; -typedef std::vector ChannelList; +//typedef std::vector ChannelList; typedef std::vector RecTimerList; +// Subclass vector to add custom delete behaviour for the contents +class ChannelList : public std::vector +{ + public: + ~ChannelList() + { + for (Channel* p : *this) delete p; + } +}; + struct RecTimerSorter // : public binary_function { bool operator() (const RecTimer* a, const RecTimer* b) @@ -167,7 +179,7 @@ public ExternLogger // Direction: 0=backwards, 1=forwards MarkList* getMarks(char* fileName); int deleteTimer(RecTimer* delTimer); - ChannelList* getChannelsList(ULONG type); + std::shared_ptr getChannelsList(ULONG type); int streamChannel(ULONG number, StreamReceiver*); int streamChannel(ULONG number); void getChannelPids(Channel* channel); diff --git a/vepg.cc b/vepg.cc index 149d894..f0a11a8 100644 --- a/vepg.cc +++ b/vepg.cc @@ -50,7 +50,7 @@ static const char* TAG = "VEpg"; VEpg* VEpg::instance = NULL; -VEpg::VEpg(MessageReceiver* tparent, UINT tcurrentChannelIndex, ChannelList* tchanList) +VEpg::VEpg(MessageReceiver* tparent, UINT tcurrentChannelIndex, std::shared_ptr tchanList) { instance = this; currentChannelIndex = tcurrentChannelIndex; diff --git a/vepg.h b/vepg.h index c11c716..fe1c80b 100644 --- a/vepg.h +++ b/vepg.h @@ -21,6 +21,7 @@ #define VEPG_H #include +#include #include "boxx.h" #include "messagequeue.h" @@ -42,7 +43,7 @@ class VVideoLive; class VEpg : public Boxx, public MessageReceiver, public TimerReceiver { public: - VEpg(MessageReceiver* parent, UINT currentChannel, ChannelList* tchanList); + VEpg(MessageReceiver* parent, UINT currentChannel, std::shared_ptr tchanList); ~VEpg(); static VEpg* getInstance(); @@ -67,7 +68,7 @@ class VEpg : public Boxx, public MessageReceiver, public TimerReceiver Event thisEvent; // the selected event time_t selTime; // current selection time UINT e; // temp used to point to an event - ChannelList* chanList; // list of available channels + std::shared_ptr chanList; // list of available channels tm* epgtime; // selected time within epg tm* Ltime; // time of LHS of epg view time_t ltime; // time of LHS of epg view diff --git a/vepglistadvanced.cc b/vepglistadvanced.cc index 8f87ff3..d57c296 100644 --- a/vepglistadvanced.cc +++ b/vepglistadvanced.cc @@ -42,7 +42,7 @@ static const char* TAG = "VEpgListAdvanced"; -VEpgListAdvanced::VEpgListAdvanced(MessageReceiver* tvideolive, ChannelList* tchanList, ULONG initialChannelNumber) +VEpgListAdvanced::VEpgListAdvanced(MessageReceiver* tvideolive, std::shared_ptr tchanList, ULONG initialChannelNumber) { channelNumber = initialChannelNumber; chanList = tchanList; diff --git a/vepglistadvanced.h b/vepglistadvanced.h index 534a1b0..cc41828 100644 --- a/vepglistadvanced.h +++ b/vepglistadvanced.h @@ -21,6 +21,7 @@ #define VEPGLIST_ADVANCED_H #include +#include #include "tbboxx.h" #include "messagequeue.h" @@ -33,7 +34,7 @@ class BoxStack; class VEpgListAdvanced : public TBBoxx, public MessageReceiver { public: - VEpgListAdvanced(MessageReceiver* tvideolive, ChannelList* tchanList, ULONG initialChannelNumber); + VEpgListAdvanced(MessageReceiver* tvideolive, std::shared_ptr tchanList, ULONG initialChannelNumber); virtual ~VEpgListAdvanced(); void draw() { draw(false); } @@ -90,7 +91,7 @@ class VEpgListAdvanced : public TBBoxx, public MessageReceiver Event* getCurrentOptionEvent(ULONG& channel); - ChannelList* chanList; + std::shared_ptr chanList; ULONG channelNumber; MessageReceiver* videolive; diff --git a/vvideolivetv.cc b/vvideolivetv.cc index 2dcd8b3..cde08e4 100644 --- a/vvideolivetv.cc +++ b/vvideolivetv.cc @@ -52,7 +52,8 @@ static const char* TAG = "VVideoLiveTV"; -VVideoLiveTV::VVideoLiveTV(ChannelList* tchanList, ULONG initialChannelNumber, VChannelList* tvchannelList) +VVideoLiveTV::VVideoLiveTV(std::shared_ptr tchanList, ULONG initialChannelNumber, VChannelList* tvchannelList) +: chanList(tchanList), vchannelList(tvchannelList) { vdr = VDR::getInstance(); boxstack = BoxStack::getInstance(); @@ -60,8 +61,6 @@ VVideoLiveTV::VVideoLiveTV(ChannelList* tchanList, ULONG initialChannelNumber, V vas = NULL; - chanList = tchanList; - vchannelList = tvchannelList; numberWidth = VDR::getInstance()->getChannelNumberWidth(); currentChannelIndex = 0; @@ -326,7 +325,7 @@ int VVideoLiveTV::handleCommand(int command) case Input::STOP: { stop(); - vchannelList->highlightChannel((*chanList)[currentChannelIndex]); + if (vchannelList) vchannelList->highlightChannel((*chanList)[currentChannelIndex]); return BoxStack::DELETE_ME; } diff --git a/vvideolivetv.h b/vvideolivetv.h index baa4d76..fb7c96a 100644 --- a/vvideolivetv.h +++ b/vvideolivetv.h @@ -24,6 +24,7 @@ #include #include #include +#include #include "messagequeue.h" #include "boxx.h" @@ -49,7 +50,7 @@ class Bitmap; class VVideoLiveTV : public Boxx, public MessageReceiver, public TimerReceiver, public OSDReceiver { public: - VVideoLiveTV(ChannelList* chanList, ULONG initialChannelNumber, VChannelList* vchannelList); + VVideoLiveTV(std::shared_ptr chanList, ULONG initialChannelNumber, VChannelList* vchannelList); virtual ~VVideoLiveTV(); void preDelete(); int handleCommand(int command); @@ -81,7 +82,7 @@ class VVideoLiveTV : public Boxx, public MessageReceiver, public TimerReceiver, Video* video; PlayerLive* player; bool playing; - ChannelList* chanList; + std::shared_ptr chanList; VChannelList* vchannelList; EventList* eventList; int numberWidth; diff --git a/vwelcome.cc b/vwelcome.cc index e9468c1..8a94fdf 100644 --- a/vwelcome.cc +++ b/vwelcome.cc @@ -303,7 +303,7 @@ int VWelcome::handleCommand(int command) void VWelcome::doChannelsList() { - ChannelList* chanList = VDR::getInstance()->getChannelsList(VDR::VIDEO); + std::shared_ptr chanList = VDR::getInstance()->getChannelsList(VDR::VIDEO); if (chanList) { @@ -322,7 +322,7 @@ void VWelcome::doChannelsList() void VWelcome::doRadioList() { - ChannelList* chanList = VDR::getInstance()->getChannelsList(VDR::RADIO); + std::shared_ptr chanList = VDR::getInstance()->getChannelsList(VDR::RADIO); if (chanList) { -- 2.39.5