CPPMyth
Library to interoperate with MythTV server
mythrecordingplayback.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 MYTHRECORDINGPLAYBACK_H
23 #define MYTHRECORDINGPLAYBACK_H
24 
25 #include "proto/mythprotoplayback.h"
26 #include "proto/mythprototransfer.h"
27 #include "mythstream.h"
28 #include "mytheventhandler.h"
29 
30 #define MYTH_RECORDING_CHUNK_SIZE 64000
31 #define MYTH_RECORDING_CHUNK_MIN 8000
32 #define MYTH_RECORDING_CHUNK_MAX 128000
33 
34 namespace Myth
35 {
36 
37  class RecordingPlayback : private ProtoPlayback, public Stream, private EventSubscriber
38  {
39  public:
41  RecordingPlayback(const std::string& server, unsigned port);
43 
44  bool Open();
45  void Close();
46  bool IsOpen() { return ProtoPlayback::IsOpen(); }
47  bool OpenTransfer(ProgramPtr recording);
48  void CloseTransfer();
49  bool TransferIsOpen();
50 
51  void SetChunk(unsigned size); // to change the size of read chunk
52 
53  // Implement Stream
54  int64_t GetSize() const;
55  int Read(void *buffer, unsigned n);
56  int64_t Seek(int64_t offset, WHENCE_t whence);
57  int64_t GetPosition() const;
58 
59  // Implement EventSubscriber
60  void HandleBackendMessage(EventMessagePtr msg);
61 
62  private:
63  EventHandler m_eventHandler;
64  unsigned m_eventSubscriberId;
65  ProtoTransferPtr m_transfer;
66  ProgramPtr m_recording;
67  volatile bool m_readAhead;
68 
69  int _read(void *buffer, unsigned n);
70  int64_t _seek(int64_t offset, WHENCE_t whence);
71  // data buffer
72  unsigned m_chunk; // the size of block to read
73  struct { unsigned pos; unsigned len; unsigned char * data; } m_buffer;
74  };
75 
76 }
77 
78 #endif /* MYTHRECORDINGPLAYBACK_H */
This is the main namespace that encloses all public classes.
Definition: mythcontrol.h:29