CPPMyth
Library to interoperate with MythTV server
mythlivetvplayback.h
1 /*
2  * Copyright (C) 2014 Jean-Luc Barriere
3  *
4  * This Program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; either version 2, or (at your option)
7  * any later version.
8  *
9  * This Program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; see the file COPYING. If not, write to
16  * the Free Software Foundation, 51 Franklin Street, Fifth Floor, Boston,
17  * MA 02110-1301 USA
18  * http://www.gnu.org/copyleft/gpl.html
19  *
20  */
21 
22 #ifndef MYTHLIVETVPLAYBACK_H
23 #define MYTHLIVETVPLAYBACK_H
24 
25 #include "proto/mythprotorecorder.h"
26 #include "proto/mythprototransfer.h"
27 #include "proto/mythprotomonitor.h"
28 #include "mythstream.h"
29 #include "mytheventhandler.h"
30 #include "mythtypes.h"
31 
32 #include <vector>
33 
34 #define MYTH_LIVETV_CHUNK_SIZE 64000
35 #define MYTH_LIVETV_CHUNK_MIN 8000
36 #define MYTH_LIVETV_CHUNK_MAX 128000
37 
38 namespace Myth
39 {
40 
41  class LiveTVPlayback : private ProtoMonitor, public Stream, private EventSubscriber
42  {
43  public:
44  LiveTVPlayback(EventHandler& handler);
45  LiveTVPlayback(const std::string& server, unsigned port);
46  ~LiveTVPlayback();
47 
48  bool Open();
49  void Close();
50  bool IsOpen() { return ProtoMonitor::IsOpen(); }
51  void SetTuneDelay(unsigned delay);
52  void SetLimitTuneAttempts(bool limit);
53  bool SpawnLiveTV(const std::string& chanNum, const ChannelList& channels);
54  bool SpawnLiveTV(const ChannelPtr& thisChannel);
55  void StopLiveTV();
56 
57  void SetChunk(unsigned size); // to change the size of read chunk
58 
59  // Implement Stream
60  int64_t GetSize() const;
61  int Read(void *buffer, unsigned n);
62  int64_t Seek(int64_t offset, WHENCE_t whence);
63  int64_t GetPosition() const;
64 
65  bool IsPlaying() const;
66  bool IsLiveRecording() const;
67  bool KeepLiveRecording(bool keep);
68  ProgramPtr GetPlayedProgram() const;
69  time_t GetLiveTimeStart() const;
70  unsigned GetChainedCount() const;
71  ProgramPtr GetChainedProgram(unsigned sequence) const;
72  uint32_t GetCardId() const;
73  SignalStatusPtr GetSignal() const;
74 
75  // Implement EventSubscriber
76  void HandleBackendMessage(EventMessagePtr msg);
77 
78  private:
79  EventHandler m_eventHandler;
80  unsigned m_eventSubscriberId;
81 
82  unsigned m_tuneDelay;
83  bool m_limitTuneAttempts;
84  ProtoRecorderPtr m_recorder;
85  SignalStatusPtr m_signal;
86 
87  typedef std::vector<std::pair<ProtoTransferPtr, ProgramPtr> > chained_t;
88  struct {
89  std::string UID;
90  chained_t chained;
91  ProtoTransferPtr currentTransfer;
92  volatile unsigned currentSequence;
93  volatile unsigned lastSequence;
94  volatile bool watch;
95  volatile bool switchOnCreate;
96  } m_chain;
97 
98  void InitChain();
99  void ClearChain();
100  bool IsChained(const Program& program);
101  void HandleChainUpdate();
102  bool SwitchChain(unsigned sequence);
103  bool SwitchChainLast();
104 
105  typedef std::multimap<unsigned, std::pair<CardInputPtr, ChannelPtr> > preferredCards_t;
106  preferredCards_t FindTunableCardIds(const std::string& chanNum, const ChannelList& channels);
107 
108  int _read(void *buffer, unsigned n);
109  int64_t _seek(int64_t offset, WHENCE_t whence);
110  // data buffer
111  unsigned m_chunk; // the size of block to read
112  struct { unsigned pos; unsigned len; unsigned char * data; } m_buffer;
113  };
114 
115 }
116 
117 #endif /* MYTHLIVETVPLAYBACK_H */
118 
This is the main namespace that encloses all public classes.
Definition: mythcontrol.h:29