]> git.vomp.tv Git - vompclient.git/commitdiff
Implement startup-to-live-TV
authorChris Tallon <chris@vomp.tv>
Tue, 16 Nov 2021 18:18:45 +0000 (18:18 +0000)
committerChris Tallon <chris@vomp.tv>
Tue, 16 Nov 2021 18:18:45 +0000 (18:18 +0000)
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"...

18 files changed:
config.cc
config.json.sample
control.cc
playerradiolive.cc
playerradiolive.h
playervideolive.cc
playervideolive.h
vchannellist.cc
vchannellist.h
vdr.cc
vdr.h
vepg.cc
vepg.h
vepglistadvanced.cc
vepglistadvanced.h
vvideolivetv.cc
vvideolivetv.h
vwelcome.cc

index a6230a56aacfcc8f120a57ba94f175c3b0121402..00e93653ad4deed37846bde53d7107999c0c2b35 100644 (file)
--- 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");
index 235127bd868897596d00d40695acf74810b79127..3448df47c9e2a057c1455237f67640c7ecdd430d 100644 (file)
@@ -14,7 +14,8 @@
 {
   "main":
   {
-    "daemonize": true
+    "daemonize": true,
+    "start_to_live_tv": 1 // Channel number
   },
 
   "log":
index 5e9ce2fe0915456dbd2f900ef1f1a16878d0b720..d2f61e436842b919d43b27e120ba49df026aefed 100644 (file)
@@ -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<ChannelList> 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<ULONG>(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);
index af92f726483a7bb864f9d5334d7dd83cfec27cad..228a2d5c2839f1f36299aeb21db06d0f57b69190 100644 (file)
@@ -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<ChannelList> tchanList)
 : messageQueue(tmessageQueue), messageReceiver(tmessageReceiver), afeed(this), chanList(tchanList)
 {
   audio = Audio::getInstance();
index b2fa6e5747b9963e7c2b7e06254603e668821d54..2347cede24baadfc1cd0ad0ac5ee78fea4457d93 100644 (file)
@@ -23,8 +23,8 @@
 #include <mutex>
 #include <thread>
 #include <condition_variable>
-
 #include <queue>
+#include <memory>
 
 #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<ChannelList> 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<ChannelList> chanList;
 
     std::queue<PLInstruction> instructions;
     const static UCHAR I_SETCHANNEL = 1;
index 3a2e10e537fd4c3885a2e505752ae1a8308259d5..90345762657d09b0c43b72f5684d71140407c0eb 100644 (file)
@@ -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<ChannelList> tchanList)
 : vfeed(this), afeed(this), tfeed(this),
   messageQueue(tmessageQueue), messageReceiver(tmessageReceiver), osdReceiver(tosdReceiver), chanList(tchanList)
 {
index e2ada193344a22a927ac2cde9a6cbb8bd23c98fe..786847b7c76c52be2c6a7f3d699c918f0e5b868e 100644 (file)
@@ -23,6 +23,7 @@
 #include <mutex>
 #include <thread>
 #include <condition_variable>
+#include <memory>
 
 #include <queue>
 
@@ -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<ChannelList> 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<ChannelList> chanList;
     LogNT* logger;
     Audio* audio;
     Video* video;
index f13368b7e309d6365ce8d99466e0575f720a211c..4783434fb2a953d13a68b01a46d71d4832641630 100644 (file)
@@ -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<ChannelList> tlist)
 {
   char str[500];
   OsdVector *osdv=dynamic_cast<OsdVector*>(Osd::getInstance());
index c3a82b2cfdb58f45a9f528f09a944cd16acec343..6074801c7e3eaa3087884ff6d3f904516c84521b 100644 (file)
@@ -24,6 +24,7 @@
 #include <stdio.h>
 #include <string.h>
 #include <vector>
+#include <memory>
 
 #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<ChannelList> 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<ChannelList> chanList;
 
     WSelectList sl;
     ULONG type;
diff --git a/vdr.cc b/vdr.cc
index 376fe94a1b231d295a5d4f331bef2c60ee352dac..d4d301d2d4958075f130e74d3acdd4169fe1b8fb 100644 (file)
--- 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<ChannelList> 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<ChannelList> chanList = std::make_shared<ChannelList>();
 
   bool h264support=Video::getInstance()->supportsh264();
   bool mpeg2support=Video::getInstance()->supportsmpeg2();
diff --git a/vdr.h b/vdr.h
index d4befe19cbe38151f16425aecbd76fbd7ddc0eda..8f705c0408aabf4725a9d26032e26ea095a4a5dc 100644 (file)
--- a/vdr.h
+++ b/vdr.h
@@ -31,6 +31,7 @@
 #include <algorithm>
 #include <thread>
 #include <mutex>
+#include <memory>
 
 #include "defines.h"
 #include "log.h"
 #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<Event*> EventList;
-typedef std::vector<Channel*> ChannelList;
+//typedef std::vector<Channel*> ChannelList;
 typedef std::vector<RecTimer*> RecTimerList;
 
+// Subclass vector to add custom delete behaviour for the contents
+class ChannelList : public std::vector<Channel*>
+{
+  public:
+    ~ChannelList()
+    {
+      for (Channel* p : *this) delete p;
+    }
+};
+
 struct RecTimerSorter     // : public binary_function<double, double, bool>
 {
   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<ChannelList> 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 149d8948d132910ed4ca6da86a9233b04387e826..f0a11a8cfebf6fa10629599278f8ae5b395b16f0 100644 (file)
--- 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<ChannelList> tchanList)
 {
   instance = this;
   currentChannelIndex = tcurrentChannelIndex;
diff --git a/vepg.h b/vepg.h
index c11c7164c3ef0da9063dbf1368a5783532c0dfff..fe1c80b6753b36ae2c552a5bb9325f59815daa65 100644 (file)
--- a/vepg.h
+++ b/vepg.h
@@ -21,6 +21,7 @@
 #define VEPG_H
 
 #include <vector>
+#include <memory>
 
 #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<ChannelList> 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<ChannelList> 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
index 8f87ff3f28f8b71cb6ff9602ff46555a06179590..d57c2967ea41fb1bacd0e0977363e8e23460462a 100644 (file)
@@ -42,7 +42,7 @@
 
 static const char* TAG = "VEpgListAdvanced";
 
-VEpgListAdvanced::VEpgListAdvanced(MessageReceiver* tvideolive, ChannelList* tchanList, ULONG initialChannelNumber)
+VEpgListAdvanced::VEpgListAdvanced(MessageReceiver* tvideolive, std::shared_ptr<ChannelList> tchanList, ULONG initialChannelNumber)
 {
   channelNumber = initialChannelNumber;
   chanList = tchanList;
index 534a1b035a618895fa3d1418201d3cfc050667ac..cc41828a25482f75574e57794ccbc777adddd5b9 100644 (file)
@@ -21,6 +21,7 @@
 #define VEPGLIST_ADVANCED_H
 
 #include <stack>
+#include <memory>
 
 #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<ChannelList> 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<ChannelList> chanList;
     ULONG channelNumber;
     MessageReceiver* videolive;
 
index 2dcd8b3c855445dd97bb997942f514d2dd88eadb..cde08e4cb72484bfcb1065fe107a7f94baf59da3 100644 (file)
@@ -52,7 +52,8 @@
 static const char* TAG = "VVideoLiveTV";
 
 
-VVideoLiveTV::VVideoLiveTV(ChannelList* tchanList, ULONG initialChannelNumber, VChannelList* tvchannelList)
+VVideoLiveTV::VVideoLiveTV(std::shared_ptr<ChannelList> 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;
     }
     
index baa4d76a9268c7f78624af0b1fb2acaf1c544bb4..fb7c96a6b08eb3a10096e38a96c6dc77d530cfc8 100644 (file)
@@ -24,6 +24,7 @@
 #include <stdio.h>
 #include <vector>
 #include <math.h>
+#include <memory>
 
 #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<ChannelList> 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<ChannelList> chanList;
     VChannelList* vchannelList;
     EventList* eventList;
     int numberWidth;
index e9468c15e20d4cf0fcc72d60debe07455d949467..8a94fdfce6441343dddf0feb5b641bf194e9e159 100644 (file)
@@ -303,7 +303,7 @@ int VWelcome::handleCommand(int command)
 
 void VWelcome::doChannelsList()
 {
-  ChannelList* chanList = VDR::getInstance()->getChannelsList(VDR::VIDEO);
+  std::shared_ptr<ChannelList> 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<ChannelList> chanList = VDR::getInstance()->getChannelsList(VDR::RADIO);
 
   if (chanList)
   {