]> git.vomp.tv Git - vompclient.git/blob - playerradiorec.h
Message queue fix for VVideoRec
[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 LogNT;
32 class Audio;
33 class Video;
34 class Demuxer;
35 class VDR;
36 class MessageQueue;
37 class MessageReceiver;
38
39 /*
40  * Frames...
41  *
42  * VDR tells me there are around 8.3 "frames" per second in radio recordings.
43  * I don't know where this comes from but things seem to work.
44  */
45
46 class PlayerRadioRec : public Callback
47 {
48   public:
49     PlayerRadioRec(MessageQueue* messageQueue, MessageReceiver* messageReceiver);
50     virtual ~PlayerRadioRec();
51
52     bool init(ULLONG lengthBytes, ULONG lengthFrames, bool IsPesRecording);
53     int shutdown();
54     void setCurrentFrameNumber(ULONG num);
55
56     void play();
57     void stop();
58     void pause();
59     void playpause();
60     void jumpToPercent(double percent);
61     void skipForward(UINT seconds);
62     void skipBackward(UINT seconds);
63
64     UCHAR getState() { return state; }
65     ULONG getCurrentSeconds();
66     ULONG getLengthSeconds();
67
68     void call(void*); // for callback interface
69
70     const static UCHAR S_PLAY = 1;
71     const static UCHAR S_PAUSE_P = 2;
72     const static UCHAR S_PAUSE_I = 3;
73     const static UCHAR S_STOP = 6;
74     const static UCHAR S_JUMP = 7;
75
76     // Player events
77
78     const static UCHAR CONNECTION_LOST = 1;
79     const static UCHAR STOP_PLAYBACK = 2;
80     const static UCHAR STREAM_END = 3;
81
82   private:
83     void switchState(UCHAR newState, ULONG jumpToFrame=0);
84     void threadMethod();
85
86     void doConnectionLost();
87     void restartAtFrame(ULONG newFrame);
88     bool setLengthSeconds();
89
90     MessageQueue* messageQueue;
91     MessageReceiver* messageReceiver;
92     LogNT* logger;
93     Audio* audio;
94     Demuxer* demuxer;
95     VDR* vdr;
96     AFeed afeed;
97
98     bool initted{};
99     bool startup;
100
101     ULLONG startPTS{};
102     ULONG lengthSeconds{};
103
104     std::mutex stateLock;
105
106     std::thread playerThread;
107     std::mutex playerThreadMutex;
108     std::condition_variable playerThreadCond;
109     bool threadReqQuit;
110     void threadStop();
111
112     ULLONG lengthBytes{};
113     ULONG lengthFrames{};
114     ULONG currentFrameNumber{};
115     static const UINT blockSize{10000};
116     static const UINT startupBlockSize{20000};
117     UCHAR state{S_STOP};
118 };
119
120 #endif
121
122
123 /*
124
125 Possible states:
126
127 Play, Pause, FFwd, FBwd, (Stop), [Jump]
128
129                     Possible  Working
130
131 Play   -> PauseP       *         *
132        -> Stop         *         *
133        -> Jump         *         *
134
135 PauseP -> Play         *         *
136        -> Stop         *         *
137        -> Jump         *         *
138
139 PauseI -> Play         *         *
140        -> PauseP
141        -> Stop         *         *
142        -> Jump         *         *
143
144 Stop   -> Play         *         *
145        -> PauseP
146        -> Jump
147
148 Jump   -> Play
149        -> PauseP
150        -> Stop
151
152 */