]> git.vomp.tv Git - vompclient.git/blob - playerradiorec.h
Windows fixes
[vompclient.git] / playerradiorec.h
1 /*
2     Copyright 2004-2020 Chris Tallon
3
4     This file is part of VOMP.
5
6     VOMP is free software; you can redistribute it and/or modify
7     it under the terms of the GNU General Public License as published by
8     the Free Software Foundation; either version 2 of the License, or
9     (at your option) any later version.
10
11     VOMP is distributed in the hope that it will be useful,
12     but WITHOUT ANY WARRANTY; without even the implied warranty of
13     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14     GNU General Public License for more details.
15
16     You should have received a copy of the GNU General Public License
17     along with VOMP.  If not, see <https://www.gnu.org/licenses/>.
18 */
19
20 #ifndef PLAYERRADIOREC_H
21 #define PLAYERRADIOREC_H
22
23 #include <thread>
24 #include <mutex>
25 #include <condition_variable>
26
27 #include "defines.h"
28 #include "callback.h"
29 #include "afeed.h"
30
31 class Log;
32 class Audio;
33 class Video;
34 class Demuxer;
35 class VDR;
36 class MessageQueue;
37
38 /*
39  * Frames...
40  *
41  * VDR tells me there are around 8.3 "frames" per second in radio recordings.
42  * I don't know where this comes from but things seem to work.
43  */
44
45 class PlayerRadioRec : public Callback
46 {
47   public:
48     PlayerRadioRec(MessageQueue* messageQueue, void* messageReceiver);
49     virtual ~PlayerRadioRec();
50
51     bool init(ULLONG lengthBytes, ULONG lengthFrames, bool IsPesRecording);
52     int shutdown();
53     void setCurrentFrameNumber(ULONG num);
54
55     void play();
56     void stop();
57     void pause();
58     void playpause();
59     void jumpToPercent(double percent);
60     void skipForward(UINT seconds);
61     void skipBackward(UINT seconds);
62
63     UCHAR getState() { return state; }
64     ULONG getCurrentSeconds();
65     ULONG getLengthSeconds();
66
67     void call(void*); // for callback interface
68
69     const static UCHAR S_PLAY = 1;
70     const static UCHAR S_PAUSE_P = 2;
71     const static UCHAR S_PAUSE_I = 3;
72     const static UCHAR S_STOP = 6;
73     const static UCHAR S_JUMP = 7;
74
75     // Player events
76
77     const static UCHAR CONNECTION_LOST = 1;
78     const static UCHAR STOP_PLAYBACK = 2;
79     const static UCHAR STREAM_END = 3;
80
81   private:
82     void switchState(UCHAR newState, ULONG jumpToFrame=0);
83     void threadMethod();
84
85     void doConnectionLost();
86     void restartAtFrame(ULONG newFrame);
87     bool setLengthSeconds();
88
89     MessageQueue* messageQueue;
90     void* messageReceiver;
91     Log* logger;
92     Audio* audio;
93     Demuxer* demuxer;
94     VDR* vdr;
95     AFeed afeed;
96
97     bool initted{};
98     bool startup;
99
100     ULLONG startPTS{};
101     ULONG lengthSeconds{};
102
103     std::mutex stateLock;
104
105     std::thread playerThread;
106     std::mutex playerThreadMutex;
107     std::condition_variable playerThreadCond;
108     bool threadReqQuit;
109     void threadStop();
110
111     ULLONG lengthBytes{};
112     ULONG lengthFrames{};
113     ULONG currentFrameNumber{};
114     static const UINT blockSize{10000};
115     static const UINT startupBlockSize{20000};
116     UCHAR state{S_STOP};
117 };
118
119 #endif
120
121
122 /*
123
124 Possible states:
125
126 Play, Pause, FFwd, FBwd, (Stop), [Jump]
127
128                     Possible  Working
129
130 Play   -> PauseP       *         *
131        -> Stop         *         *
132        -> Jump         *         *
133
134 PauseP -> Play         *         *
135        -> Stop         *         *
136        -> Jump         *         *
137
138 PauseI -> Play         *         *
139        -> PauseP
140        -> Stop         *         *
141        -> Jump         *         *
142
143 Stop   -> Play         *         *
144        -> PauseP
145        -> Jump
146
147 Jump   -> Play
148        -> PauseP
149        -> Stop
150
151 */