]> git.vomp.tv Git - vompclient.git/blob - playerradio.h
Fix black background for 16:9 live TV on 4:3 screen
[vompclient.git] / playerradio.h
1 /*
2     Copyright 2004-2006 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, write to the Free Software
18     Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
19 */
20
21 #ifndef PLAYERRADIO_H
22 #define PLAYERRADIO_H
23
24 #include <stdio.h>
25 #include <stdlib.h>
26 #ifndef WIN32
27 #include <sys/time.h>
28 #endif
29 #include <time.h>
30
31 #include <mutex>
32
33 #include "threadsystem.h"
34
35 #include "callback.h"
36 #include "defines.h"
37 #include "afeed.h"
38
39 class Log;
40 class Audio;
41 class Video;
42 class Demuxer;
43 class VDR;
44 class MessageQueue;
45
46 /*
47  * Frames...
48  *
49  * VDR tells me there are around 8.3 "frames" per second in radio recordings.
50  * I don't know where this comes from but things seem to work.
51  */
52
53 class PlayerRadio : public Thread_TYPE, public Callback
54 {
55   public:
56     PlayerRadio(MessageQueue* messageQueue, void* messageReceiver);
57     virtual ~PlayerRadio();
58
59     bool init(ULLONG lengthBytes, ULONG lengthFrames, bool IsPesRecording);
60     int shutdown();
61     void setCurrentFrameNumber(ULONG num);
62
63     void play();
64     void stop();
65     void pause();
66     void playpause();
67     void jumpToPercent(double percent);
68     void skipForward(UINT seconds);
69     void skipBackward(UINT seconds);
70
71     UCHAR getState() { return state; }
72     ULONG getCurrentSeconds();
73     ULONG getLengthSeconds();
74
75     void call(void*); // for callback interface
76
77     const static UCHAR S_PLAY = 1;
78     const static UCHAR S_PAUSE_P = 2;
79     const static UCHAR S_PAUSE_I = 3;
80     const static UCHAR S_STOP = 6;
81     const static UCHAR S_JUMP = 7;
82
83     // Player events
84
85     const static UCHAR CONNECTION_LOST = 1;
86     const static UCHAR STOP_PLAYBACK = 2;
87     const static UCHAR STREAM_END = 3;
88
89   protected:
90     void threadMethod();
91     void threadPostStopCleanup();
92
93   private:
94     void switchState(UCHAR newState, ULONG jumpToFrame=0);
95
96     void threadFeedPlay();
97     void threadFeedScan();
98
99     void doConnectionLost();
100     void restartAtFrame(ULONG newFrame);
101     bool setLengthSeconds();
102
103     MessageQueue* messageQueue;
104     void* messageReceiver;
105     Log* logger;
106     Audio* audio;
107     Demuxer* demuxer;
108     VDR* vdr;
109     AFeed afeed;
110
111     bool initted{};
112     bool startup;
113
114     ULLONG startPTS{};
115     ULONG lengthSeconds{};
116
117     std::mutex stateLock;
118
119     ULLONG lengthBytes{};
120     ULONG lengthFrames{};
121     ULONG currentFrameNumber{};
122     static const UINT blockSize{10000};
123     static const UINT startupBlockSize{20000};
124     UCHAR* threadBuffer{};
125     UCHAR state{S_STOP};
126 };
127
128 #endif
129
130
131 /*
132
133 Possible states:
134
135 Play, Pause, FFwd, FBwd, (Stop), [Jump]
136
137                     Possible  Working
138
139 Play   -> PauseP       *         *
140        -> Stop         *         *
141        -> Jump         *         *
142
143 PauseP -> Play         *         *
144        -> Stop         *         *
145        -> Jump         *         *
146
147 PauseI -> Play         *         *
148        -> PauseP
149        -> Stop         *         *
150        -> Jump         *         *
151
152 Stop   -> Play         *         *
153        -> PauseP
154        -> Jump
155
156 Jump   -> Play
157        -> PauseP
158        -> Stop
159
160 */