2 Copyright 2004-2005 Chris Tallon
4 This file is part of VOMP.
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.
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.
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 // this is a total copy from player but with video stuff taken out
22 // most of this isn't used because it's designed for recording playback
25 #include "playerradio.h"
27 PlayerRadio::PlayerRadio()
28 : afeedr(this, &stream)
37 feedMode = MODE_NORMAL;
40 // FIXME - this might need settings back to zero for new live play depending on what is done with it
43 PlayerRadio::~PlayerRadio()
45 if (initted) shutdown();
48 int PlayerRadio::init()
50 if (initted) return 0;
52 audio = Audio::getInstance();
54 afeedr.init(audio->getFD());
62 int PlayerRadio::shutdown()
64 if (!initted) return 0;
67 Log::getInstance()->log("PlayerRadio", Log::DEBUG, "PlayerRadio shutdown...");
82 int PlayerRadio::play()
84 if (!initted) return 0;
86 // If we are just paused, unpause!
93 // If we are fast forwarding, set to normal
100 // If we are fast backwarding, set to normal
103 toggleFastBackward();
107 // If we are already playing, bail // FIXME - resync?
110 Log::getInstance()->log("PlayerRadio", Log::DEBUG, "DOING RESYNC");
122 // Standard play start
127 // ------------------------ This one works, but doesn't allow any pre-buffering.
133 // ------------------------ This one doesn't work, but it should, and would allow for prebuffering.
139 // struct timespec delay;
141 // delay.tv_nsec = 500000000;
142 // nanosleep(&delay, NULL);
147 // ------------------------------------------------------------------------------------------------
153 void PlayerRadio::stop()
155 if (!initted) return;
156 if (!playing) return;
166 void PlayerRadio::togglePause()
168 if (!initted) return;
169 if (!playing) return;
171 if (ffwd) toggleFastForward();
172 if (fbwd) toggleFastBackward();
186 void PlayerRadio::setPosition(ULLONG position)
188 feedPosition = position;
191 void PlayerRadio::setLength(ULLONG length)
193 streamLength = length;
194 Log::getInstance()->log("PlayerRadio", Log::DEBUG, "PlayerRadio has received length of %llu", streamLength);
197 void PlayerRadio::skipForward()
199 // skip forward 1 minute
200 Log::getInstance()->log("PlayerRadio", Log::DEBUG, "SKIP FORWARD 1 MINUTE");
202 if (paused) togglePause();
208 audio->doMuting(); // ???
209 feedPosition += 30000000;
215 void PlayerRadio::skipBackward()
217 // skip forward 1 minute
218 Log::getInstance()->log("PlayerRadio", Log::DEBUG, "SKIP BACKWARD 1 MINUTE");
220 if (paused) togglePause();
226 audio->doMuting(); // ???
227 if (feedPosition > 30000000) feedPosition -= 30000000;
233 void PlayerRadio::toggleFastForward()
235 if (!initted) return;
236 if (!playing) return;
238 if (paused) togglePause();
239 if (fbwd) toggleFastBackward();
246 audio->systemMuteOff();
252 audio->systemMuteOn();
256 void PlayerRadio::toggleFastBackward()
258 if (!initted) return;
259 if (!playing) return;
261 if (paused) togglePause();
262 if (ffwd) toggleFastForward();
268 audio->systemMuteOff();
271 feedMode = MODE_NORMAL;
278 audio->systemMuteOn();
281 feedMode = MODE_BACKWARDS;
286 void PlayerRadio::jumpToPercent(int percent)
292 feedPosition = streamLength * percent / 100;
300 void PlayerRadio::call()
302 threadSignalNoLock();
307 void PlayerRadio::threadMethod()
309 UCHAR buf[blockSize];
314 VDR* vdr = VDR::getInstance();
325 // a bit hackey. this needs to be split to live and rec players
326 if (streamLength && (feedPosition >= streamLength)) break;
328 if (streamLength && ((feedPosition + blockSize) > streamLength))
330 askFor = streamLength - feedPosition;
332 thisRead = vdr->getBlock(buf, feedPosition, askFor);
334 if (feedMode == MODE_NORMAL)
336 feedPosition += thisRead;
338 else if (feedMode == MODE_BACKWARDS)
340 if (feedPosition >= 100000)
342 feedPosition -= 100000;
346 // got to the start of the recording.. revert to play mode? how?
347 feedPosition += thisRead;
353 while(writeLength < thisRead)
355 thisWrite = stream.put(buf + writeLength, thisRead - writeLength);
356 writeLength += thisWrite;
360 Log::getInstance()->log("Player", Log::DEBUG, "RADIO OUTPUT STREAM FULL!!!");
361 // stream is full and cant take anymore
362 threadWaitForSignal();
363 Log::getInstance()->log("Player", Log::DEBUG, "BACK FROM WAIT");
369 Log::getInstance()->log("PlayerRadio", Log::DEBUG, "Written audio");