OBJECTS = main.o command.o log.o remote.o led.o mtd.o video.o audio.o tcp.o directory.o thread.o \
player.o demuxer.o stream.o vfeed.o afeed.o afeedr.o osd.o surface.o viewman.o vdr.o dsock.o box.o \
- list.o queue.o node.o recording.o channel.o message.o playerradio.o messagequeue.o \
+ list.o queue.o node.o recording.o channel.o message.o playervideo.o playerradio.o messagequeue.o \
view.o vinfo.o vwallpaper.o vvolume.o vrecordinglist.o vlivebanner.o vmute.o \
vrecordingmenu.o vquestion.o vchannellist.o vwelcome.o vvideolive.o vvideorec.o vradiolive.o \
vchannelselect.o vserverselect.o colour.o vconnect.o voptions.o \
int Audio::test()
{
- ULLONG stc = 0;
- return ioctl(fdAudio, AV_SET_AUD_STC, &stc);
+// ULLONG stc = 0;
+// return ioctl(fdAudio, AV_SET_AUD_STC, &stc);
+
+ aud_sync_parms_t a;
+ a.parm1 = 0;
+ a.parm2 = 0;
+
+ int b = ioctl(fdAudio, AV_SET_AUD_DISABLE_SYNC, &a);
+
+
+ printf("Audio sync disable = %i\n", b);
+
+ return 1;
+
+
}
int Audio::volumeUp()
#include "player.h"
-Player::Player(MessageQueue* messageQueue)
-: vfeed(this), afeed(this)
+Player::Player()
{
initted = 0;
- commandMessageQueue = messageQueue;
-
- paused = 0;
- playing = 0;
- ffwd = 0;
- fbwd = 0;
- feedPosition = 0;
- feedMode = MODE_NORMAL;
streamLength = 0;
// FIXME - this might need settings back to zero for new live play depending on what is done with it
-}
-
-Player::~Player()
-{
- if (initted) shutdown();
-}
-int Player::init()
-{
- if (initted) return 0;
-
- video = Video::getInstance();
audio = Audio::getInstance();
-
- if (demuxer.init()) // inverted
- {
- Log::getInstance()->log("Player", Log::ERR, "Demuxer failed to init");
- shutdown();
- return 0;
- }
-
- vfeed.init(video->getFD());
- afeed.init(audio->getFD());
-
- video->stop();
- video->blank();
- audio->stop();
-
- startup = 0;
- initted = 1;
- return 1;
-}
-
-int Player::shutdown()
-{
- if (!initted) return 0;
- initted = 0;
-
- Log::getInstance()->log("Player", Log::DEBUG, "Player shutdown...");
-
- // copy of stop
- if (playing)
- {
- playing = 0;
- threadStop();
- video->stop();
- video->blank();
- audio->stop();
- vfeed.stop();
- afeed.stop();
- video->reset();
- demuxer.reset();
- feedPosition = 0;
- }
-
- return 1;
-}
-
-int Player::play()
-{
- if (!initted) return 0;
-
- // If we are just paused, unpause!
- if (paused)
- {
- togglePause();
- return 1;
- }
-
- // If we are fast forwarding, set to normal
- if (ffwd)
- {
- toggleFastForward();
- return 1;
- }
-
- // If we are fast backwarding, set to normal
- if (fbwd)
- {
- toggleFastBackward();
- return 1;
- }
-
- // If we are already playing, bail // FIXME - resync?
- if (playing)
- {
- Log::getInstance()->log("Player", Log::DEBUG, "DOING RESYNC");
-
-/*
- vfeed.stop();
- afeed.stop();
- video->reset();
- audio->reset();
- demuxer.flush();
- demuxer.seek();
- vfeed.start();
- afeed.start();
-
-
- video->play();
- audio->play();
- video->sync();
- audio->sync();
- call();
-*/
-
- // resync method 2..
-
- video->pause();
- usleep(500000);
- video->play();
- video->sync();
-
-
- return 1;
- }
-
- // Standard play start
-
- audio->reset();
- video->reset();
- demuxer.reset();
- startup = 1;
-
-// ------------------------ This one works, but doesn't allow any pre-buffering.
- threadStart();
- vfeed.start();
- afeed.start();
- audio->play();
- video->play();
- video->sync();
- audio->sync();
-
- video->pause();
- usleep(500000); // SYNC
- video->sync();
- video->unPause();
- video->sync();
-
-// ------------------------ This one doesn't work, but it should, and would allow for prebuffering.
-
-/*
-
- threadStart();
- sleep(2);
-
-// struct timespec delay;
-// delay.tv_sec = 1;
-// delay.tv_nsec = 500000000;
-// nanosleep(&delay, NULL);
-
- vfeed.start();
- afeed.start();
- video->play();
- audio->play();
- video->sync();
- audio->sync();
-*/
-// ------------------------------------------------------------------------------------------------
-
- playing = 1;
- return 1;
-}
-
-void Player::stop()
-{
- if (!initted) return;
- if (!playing) return;
-
- if (ffwd || fbwd)
- {
- ffwd = 0;
- fbwd = 0;
- afeed.enable();
- video->unFastForward();
- audio->systemMuteOff();
- feedMode = MODE_NORMAL;
- }
-
- playing = 0;
- paused = 0;
-
- threadStop();
- video->stop();
- video->blank();
- audio->stop();
- audio->unPause();
- vfeed.stop();
- afeed.stop();
- video->reset();
- demuxer.reset();
-
- feedPosition = 0;
}
-void Player::togglePause()
-{
- if (!initted) return;
- if (!playing) return;
-
- if (ffwd) toggleFastForward();
- if (fbwd) toggleFastBackward();
-
- if (paused)
- {
- video->unPause();
- audio->unPause();
- paused = 0;
- }
- else
- {
- video->pause();
- audio->pause();
- paused = 1;
- }
-}
-
-void Player::test()
-{
- Log::getInstance()->log("Player", Log::DEBUG, "PLAYER TEST");
-
-/*
-
-// video->test();
-
- static int flipflop = 0;
-
- int a;
- if (flipflop) a = video->setAspectRatio(Video::ASPECT16X9);
- else a = video->setAspectRatio(Video::ASPECT4X3);
-
- flipflop = !flipflop;
-
- printf("A = %i\n", a);
-*/
-}
-
-void Player::test2()
-{
- Log::getInstance()->log("Player", Log::DEBUG, "PLAYER TEST");
-
- video->test2();
-}
-
-void Player::setPosition(ULLONG position)
-{
- feedPosition = position;
-}
-
-void Player::setLength(ULLONG length)
-{
- streamLength = length;
- Log::getInstance()->log("Player", Log::DEBUG, "Player has received length of %llu", streamLength);
-}
-
-void Player::skipForward(int seconds)
-{
- // skip forward 1 minute
- Log::getInstance()->log("Player", Log::DEBUG, "SKIP FORWARD %i SECONDS", seconds);
-
- if (paused) togglePause();
-
- ULLONG moveBy = seconds * 500000;
-
- threadStop();
- vfeed.stop();
- afeed.stop();
- video->stop();
- video->reset();
- audio->reset();
- audio->doMuting(); // ???
- demuxer.flush();
- feedPosition += moveBy;
-
- printf("Audio test %i\n", audio->test());
-
- vfeed.start();
- afeed.start();
- threadStart();
- audio->play();
- video->play();
- video->sync();
- audio->sync();
-
- video->pause();
- usleep(500000); // SYNC
- video->sync();
- video->unPause();
- video->sync();
-
-}
-
-void Player::skipBackward(int seconds)
-{
- // skip forward 1 minute
- Log::getInstance()->log("Player", Log::DEBUG, "SKIP BACKWARD %i SECONDS", seconds);
-
- if (paused) togglePause();
-
- ULLONG moveBy = seconds * 500000;
-
- threadStop();
- vfeed.stop();
- afeed.stop();
- video->stop();
- audio->stop();
- video->reset();
- audio->reset();
- audio->doMuting(); // ???
- demuxer.flush();
- if (feedPosition > moveBy) feedPosition -= moveBy;
- vfeed.start();
- afeed.start();
- threadStart();
- audio->play();
- video->play();
- video->sync();
- audio->sync();
-
- video->pause();
- usleep(500000); // SYNC
- video->sync();
- video->unPause();
- video->sync();
-
-}
-
-void Player::toggleFastForward()
-{
- if (!initted) return;
- if (!playing) return;
-
- if (paused) togglePause();
- if (fbwd) toggleFastBackward();
-
- if (ffwd)
- {
- ffwd = 0;
-// video->unFastForward();
-
-
- threadStop();
- vfeed.stop();
- afeed.stop();
- video->stop();
- audio->stop();
- video->reset();
- audio->reset();
- demuxer.flush();
-// demuxer.seek();
- vfeed.start();
- afeed.enable();
- afeed.start();
- threadStart();
- video->play();
- audio->play();
- video->sync();
- audio->sync();
-
- audio->systemMuteOff();
-
- video->pause();
- usleep(500000); // SYNC
- video->sync();
- video->unPause();
- video->sync();
-
-/*
- demuxer.flushAudio();
- audio->reset();
- afeed.enable();
- //video->reset();
- audio->play();
- video->play();
- video->sync();
- audio->sync();
- audio->systemMuteOff();
-*/
- }
- else
- {
- ffwd = 1;
- afeed.disable();
- audio->systemMuteOn();
- video->fastForward();
- }
-}
-
-void Player::toggleFastBackward()
-{
- if (!initted) return;
- if (!playing) return;
-
- if (paused) togglePause();
- if (ffwd) toggleFastForward();
-
- if (fbwd)
- {
- fbwd = 0;
- afeed.enable();
- audio->systemMuteOff();
-
-// threadStop();
- feedMode = MODE_NORMAL;
-// threadStart();
- }
- else
- {
- fbwd = 1;
- afeed.disable();
- audio->systemMuteOn();
-
- threadStop();
- feedMode = MODE_BACKWARDS;
- video->reset();
- video->play();
- demuxer.flush();
- threadStart();
- }
-}
-
-void Player::jumpToPercent(int percent)
-{
- threadStop();
- vfeed.stop();
- afeed.stop();
- video->stop();
- audio->stop();
- video->reset();
- audio->reset();
- demuxer.flush();
- demuxer.seek();
- feedPosition = streamLength * percent / 100;
- vfeed.start();
- afeed.start();
- threadStart();
- audio->play();
- video->play();
- video->sync();
- audio->sync();
-
- video->pause();
- usleep(500000); // SYNC
- video->sync();
- video->unPause();
- video->sync();
-}
-
-
-void Player::call()
-{
- threadSignalNoLock();
-}
-
-// Feed thread
-
-void Player::threadMethod()
-{
- UCHAR buf[blockSize];
- int thisRead;
- int writeLength;
- int thisWrite;
-
- VDR* vdr = VDR::getInstance();
-
- int askFor;
- while(1)
- {
- thisRead = 0;
- writeLength = 0;
- thisWrite = 0;
-
- threadCheckExit();
-
- // a bit hackey. this needs to be split to live and rec players
- if (streamLength && (feedPosition >= streamLength)) break;
- askFor = blockSize;
- if (streamLength && ((feedPosition + blockSize) > streamLength))
- {
- askFor = streamLength - feedPosition;
- }
- thisRead = vdr->getBlock(buf, feedPosition, askFor);
- if (startup)
- {
- int a_stream = demuxer.scan(buf, thisRead);
- demuxer.setAudioStream(a_stream);
- Log::getInstance()->log("Player", Log::DEBUG, "Startup Audio stream chosen %x", a_stream);
- startup = 0;
- }
-
- if (feedMode == MODE_NORMAL)
- {
- feedPosition += thisRead;
- }
- else if (feedMode == MODE_BACKWARDS)
- {
- if (feedPosition >= 100000)
- {
- feedPosition -= 100000;
- demuxer.seek();
- }
- else
- {
- // got to the start of the recording.. revert to play mode? how?
- feedPosition += thisRead;
- }
- }
-
- threadCheckExit();
-
- while(writeLength < thisRead)
- {
- thisWrite = demuxer.put(buf + writeLength, thisRead - writeLength);
- writeLength += thisWrite;
-
- if (!thisWrite)
- {
- Log::getInstance()->log("Player", Log::DEBUG, "DEMUXER FULL!!!");
- // demuxer is full and cant take anymore
- threadWaitForSignal();
- Log::getInstance()->log("Player", Log::DEBUG, "BACK FROM WAIT");
- }
-
- threadCheckExit();
- }
- }
-
- // end of recording
- Log::getInstance()->log("Player", Log::DEBUG, "Recording playback ends");
- Message* m = new Message();
- m->message = Message::STOP_PLAYBACK;
- Log::getInstance()->log("Player", Log::DEBUG, "Posting message...");
- commandMessageQueue->postMessage(m);
- Log::getInstance()->log("Player", Log::DEBUG, "Message posted...");
-
-
-}
+Player::~Player() {}
#ifndef PLAYER_H
#define PLAYER_H
-#include <stdio.h>
-
-#include "audio.h"
-#include "video.h"
-#include "demuxer.h"
-#include "vfeed.h"
-#include "afeed.h"
-#include "remote.h"
#include "thread.h"
-#include "vdr.h"
#include "callback.h"
-#include "message.h"
-#include "messagequeue.h"
+#include "defines.h"
+#include "log.h"
+#include "audio.h"
class Player : public Thread, public Callback
{
public:
- Player(MessageQueue* messageQueue);
+ Player();
virtual ~Player();
-
- int init();
- int shutdown();
-
- int play();
- void stop();
- void togglePause();
- void toggleFastForward();
- void toggleFastBackward();
- void jumpToPercent(int percent);
- void skipForward(int seconds);
- void skipBackward(int seconds);
- void test();
- void test2();
- void call(); // for callback interface
- void setPosition(ULLONG position);
- void setLength(ULLONG length);
-
- void threadMethod();
-
- private:
+ virtual int init()=0;
+ virtual int shutdown()=0;
+ virtual int play()=0;
+ virtual void stop()=0;
+ virtual void togglePause()=0;
+ virtual void toggleFastForward()=0;
+ virtual void toggleFastBackward()=0;
+ virtual void jumpToPercent(int percent)=0;
+ virtual void skipForward(int seconds)=0;
+ virtual void skipBackward(int seconds)=0;
+ virtual void test()=0;
+ virtual void test2()=0;
+ virtual void setPosition(ULLONG position)=0;
+ virtual void setLength(ULLONG length)=0;
+
+ virtual void call()=0; // for callback interface
+ virtual void threadMethod()=0; // for thread interface
+
+ protected:
int initted;
- MessageQueue* commandMessageQueue;
- Video* video;
- Audio* audio;
- Demuxer demuxer;
- int startup;
- VFeed vfeed;
- AFeed afeed;
ULLONG streamLength;
- ULLONG feedPosition;
- UCHAR feedMode;
- const static UCHAR MODE_NORMAL = 1;
- const static UCHAR MODE_BACKWARDS = 2;
- const static int blockSize = 100000;
+ Audio* audio;
- UCHAR playing; // As in not stopped, (playing && paused) can == TRUE
- UCHAR paused; // Must be in playing state as well
- UCHAR ffwd; // Must be in playing state as well
- UCHAR fbwd; // Must be in playing state as well
};
#endif
PlayerRadio::PlayerRadio()
: afeedr(this, &stream)
{
- initted = 0;
-
paused = 0;
playing = 0;
ffwd = 0;
fbwd = 0;
feedPosition = 0;
feedMode = MODE_NORMAL;
-
- streamLength = 0;
- // FIXME - this might need settings back to zero for new live play depending on what is done with it
}
PlayerRadio::~PlayerRadio()
{
if (initted) return 0;
- audio = Audio::getInstance();
stream.init(120000);
afeedr.init(audio->getFD());
audio->stop();
+
initted = 1;
return 1;
}
audio->reset();
afeedr.start();
+
audio->play();
call();
// Standard play start
audio->reset();
+ audio->stop();
/*
// ------------------------ This one works, but doesn't allow any pre-buffering.
// ------------------------ This one doesn't work, but it should, and would allow for prebuffering.
*/
+ audio->test();
threadStart();
sleep(6);
// delay.tv_nsec = 500000000;
// nanosleep(&delay, NULL);
+
afeedr.start();
audio->play();
// audio->sync();
void PlayerRadio::setLength(ULLONG length)
{
streamLength = length;
- Log::getInstance()->log("PlayerRadio", Log::DEBUG, "PlayerRadio has received length of %llu", streamLength);
+ Log::getInstance()->log("PlayerRadio", Log::DEBUG, "Player has received length of %llu", streamLength);
}
void PlayerRadio::skipForward()
void PlayerRadio::call()
{
- threadSignalNoLock();
+ Log::getInstance()->log("PlayerRadio", Log::DEBUG, "playerradio called\n");
+// threadSignalNoLock();
}
// Feed thread
}
thisRead = vdr->getBlock(buf, feedPosition, askFor);
+ // temp
+ printf("Written direct: %i\n", write(audio->getFD(), buf, thisRead));
+
+
+
if (feedMode == MODE_NORMAL)
{
feedPosition += thisRead;
threadCheckExit();
- while(writeLength < thisRead)
+/* while(writeLength < thisRead)
{
thisWrite = stream.put(buf + writeLength, thisRead - writeLength);
+ Log::getInstance()->log("PlayerRadio", Log::DEBUG, "Just put %i to stream", thisWrite);
+
writeLength += thisWrite;
if (!thisWrite)
{
- Log::getInstance()->log("Player", Log::DEBUG, "RADIO OUTPUT STREAM FULL!!!");
+ Log::getInstance()->log("PlayerRadio", Log::DEBUG, "RADIO OUTPUT STREAM FULL!!!");
// stream is full and cant take anymore
threadWaitForSignal();
- Log::getInstance()->log("Player", Log::DEBUG, "BACK FROM WAIT");
+ Log::getInstance()->log("PlayerRadio", Log::DEBUG, "BACK FROM WAIT");
}
threadCheckExit();
}
Log::getInstance()->log("PlayerRadio", Log::DEBUG, "Written audio");
-
+*/
}
}
#include <stdio.h>
+#include "player.h"
#include "audio.h"
#include "afeedr.h"
#include "remote.h"
#include "callback.h"
#include "stream.h"
-class PlayerRadio : public Thread, public Callback
+class PlayerRadio : public Player
{
public:
PlayerRadio();
void threadMethod();
+ void skipForward(int) {};
+ void skipBackward(int) {};
+ void test() {};
+ void test2() {};
+
private:
- int initted;
- Audio* audio;
- int startup;
Stream stream;
AFeedR afeedr;
- ULLONG streamLength;
ULLONG feedPosition;
UCHAR feedMode;
const static UCHAR MODE_NORMAL = 1;
const static UCHAR MODE_BACKWARDS = 2;
- const static int blockSize = 30000;
+ const static int blockSize = 2000;
UCHAR playing; // As in not stopped, (playing && paused) can == TRUE
UCHAR paused; // Must be in playing state as well
if (chan == NULL) return 2;
- View* v = NULL;
-
- // stop radio
- // if (chan->type == VDR::RADIO) return 2;
-
- if (chan->type == VDR::VIDEO)
- {
- v = new VVideoLive(chanList);
- ((VVideoLive*)v)->setChannel(chan->number);
- }
- else if (chan->type == VDR::RADIO)
- {
- v = new VRadioLive(chanList);
- ((VRadioLive*)v)->setChannel(chan->number);
- }
+ VVideoLive* v = new VVideoLive(chanList, chan->type);
+ v->setChannel(chan->number);
ViewMan::getInstance()->addNoLock(v);
v->draw();
return recordingLength;
}
+ULLONG VDR::rescanRecording()
+{
+ unsigned long totalLength = 8;
+ UCHAR buffer[totalLength];
+
+ *(unsigned long*)&buffer[0] = htonl(totalLength - 4);
+ *(unsigned long*)&buffer[4] = htonl(VDR_RESCANRECORDING);
+
+ pthread_mutex_lock(&mutex);
+ unsigned int a = tcp->sendPacket(buffer, totalLength);
+ if (a != totalLength)
+ {
+ pthread_mutex_unlock(&mutex);
+ return 0;
+ }
+
+ unsigned char* p = (unsigned char*)tcp->receivePacket();
+ pthread_mutex_unlock(&mutex);
+ if (!p) return 0;
+
+ if (tcp->getDataLength() != 8)
+ {
+ free(p);
+ return 0;
+ }
+
+ ULLONG recordingLength = ntohll(*(ULLONG*)p);
+
+ Log::getInstance()->log("VDR", Log::DEBUG, "VDR said length is: %llu", recordingLength);
+ free(p);
+
+ return recordingLength;
+}
+
int VDR::getChannelSchedule(ULONG number)
{
UCHAR buffer[12];
char* getRecordingSummary(char* fileName);
int deleteRecording(char* fileName);
ULLONG streamRecording(Recording* rec);
+ ULLONG rescanRecording();
List* getChannelsList(ULONG type);
int streamChannel(ULONG number);
const static ULONG VDR_GETCHANNELSCHEDULE = 10;
const static ULONG VDR_CONFIGSAVE = 11;
const static ULONG VDR_CONFIGLOAD = 12;
+ const static ULONG VDR_RESCANRECORDING = 13;
long getSimpleReply();
char* getStringReply();
void VLiveBanner::draw()
{
- int success = VDR::getInstance()->getChannelSchedule(1);
+//int success = VDR::getInstance()->getChannelSchedule(1);
+int success = 0;
if (!success)
{
#include "vvideolive.h"
-VVideoLive::VVideoLive(List* tchanList)
+VVideoLive::VVideoLive(List* tchanList, ULONG tstreamType)
{
- player = new Player(NULL);
- player->init();
vdr = VDR::getInstance();
viewman = ViewMan::getInstance();
chanList = tchanList;
currentChannel = NULL;
unavailable = 0;
unavailableView = NULL;
+ streamType = tstreamType;
+ if (streamType == VDR::VIDEO)
+ {
+ player = new PlayerVideo(NULL, 0);
+ }
+ else
+ {
+ player = new PlayerRadio();
+ }
+ player->init();
Video* video = Video::getInstance();
setDimensions(video->getScreenHeight(), video->getScreenWidth());
#include <stdio.h>
#include "view.h"
-#include "player.h"
+#include "playervideo.h"
+#include "playerradio.h"
#include "vdr.h"
#include "list.h"
#include "channel.h"
class VVideoLive : public View
{
public:
- VVideoLive(List* chanList);
+ VVideoLive(List* chanList, ULONG streamType);
~VVideoLive();
void draw();
int handleCommand(int command);
Channel* currentChannel;
int unavailable;
VInfo* unavailableView;
+ ULONG streamType;
void upChannel();
void downChannel();
VVideoRec::VVideoRec(Recording* rec)
{
- player = new Player(Command::getInstance());
+ player = new PlayerVideo(Command::getInstance(), 1);
player->init();
vdr = VDR::getInstance();
#include <stdio.h>
#include "view.h"
-#include "player.h"
+#include "playervideo.h"
#include "vdr.h"
#include "recording.h"
#include "command.h"