]> git.vomp.tv Git - vompclient.git/blob - playerradio.h
Code cleaning
[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 #ifdef WIN32
32 #include "threadwin.h"
33 #else
34 #include "threadp.h"
35 #endif
36 #include "callback.h"
37 #include "defines.h"
38 #include "afeed.h"
39
40 class Log;
41 class Audio;
42 class Video;
43 class Demuxer;
44 class VDR;
45 class MessageQueue;
46
47 class PlayerRadio : public Thread_TYPE, public Callback
48 {
49   public:
50     PlayerRadio(MessageQueue* messageQueue, void* messageReceiver);
51     virtual ~PlayerRadio();
52
53     int init(ULLONG lengthBytes, ULONG lengthPackets);
54     int shutdown();
55     void setStartBytes(ULLONG startBytes);
56
57     void play();
58     void stop();
59     void pause();
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_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   protected:
82     void threadMethod();
83     void threadPostStopCleanup();
84
85   private:
86     void switchState(UCHAR newState, ULONG jumpPacket=0);
87
88     void threadFeedPlay();
89     void threadFeedScan();
90
91     void doConnectionLost();
92     void restartAtPacket(ULONG newPacket);
93     bool setLengthSeconds();
94
95     MessageQueue* messageQueue;
96     void* messageReceiver;
97     Log* logger;
98     Audio* audio;
99     Demuxer* demuxer;
100     VDR* vdr;
101     AFeed afeed;
102
103     bool initted;
104     bool startup;
105
106     ULLONG startPTS;
107     ULONG lengthSeconds;
108
109 #ifndef WIN32
110     pthread_mutex_t mutex;
111 #else
112     HANDLE mutex;
113 #endif
114     void lock();
115     void unLock();
116
117     ULLONG lengthBytes;
118     ULLONG streamPos;
119     ULONG lengthPackets;
120     ULONG currentPacketNumber;
121     UINT blockSize;
122     UINT startupBlockSize;
123     UCHAR* threadBuffer;
124     UCHAR state;
125 };
126
127 #endif
128
129
130 /*
131
132 Possible states:
133
134 Play, Pause, FFwd, FBwd, (Stop), [Jump]
135
136                     Possible  Working
137
138 Play   -> PauseP       *         *
139        -> Stop         *         *
140        -> Jump         *         *
141
142 PauseP -> Play         *         *
143        -> Stop         *         *
144        -> Jump         *         *
145
146 PauseI -> Play         *         *
147        -> PauseP
148        -> Stop         *         *
149        -> Jump         *         *
150
151 Stop   -> Play         *         *
152        -> PauseP
153        -> Jump
154
155 Jump   -> Play
156        -> PauseP
157        -> Stop
158
159 */