From 24ffd44f2fe033cee37fba6600e1dc4c164053c3 Mon Sep 17 00:00:00 2001 From: Chris Tallon Date: Fri, 24 Nov 2006 16:57:45 +0000 Subject: [PATCH] Audio channel selection code finished --- CREDITS | 1 + demuxer.cc | 2 +- demuxer.h | 2 +- message.h | 2 + recinfo.cc | 9 ++- recinfo.h | 2 +- vaudioselector.cc | 68 +++++++++++-------- vaudioselector.h | 10 +-- view.h | 2 +- vvideorec.cc | 165 ++++++++++++++++++++++++++++++---------------- vvideorec.h | 10 ++- widget.cc | 6 ++ widget.h | 2 + wselectlist.cc | 2 +- 14 files changed, 182 insertions(+), 101 deletions(-) diff --git a/CREDITS b/CREDITS index 9cff30a..433092e 100644 --- a/CREDITS +++ b/CREDITS @@ -38,6 +38,7 @@ Marten Richter Debian packages for the e-TOBI VDR repository Information about index.vdr and code to navigate recordings Windows port of vompclient + Audio channel selection Thanks to the following people for their work with the MVP: diff --git a/demuxer.cc b/demuxer.cc index 686f847..aea868c 100644 --- a/demuxer.cc +++ b/demuxer.cc @@ -92,7 +92,7 @@ void Demuxer::reset() aspect_ratio = (enum AspectRatio) 0; frame_rate = bit_rate = 0; - for (int i = 0; i < PESTYPE_AUDMAX - PESTYPE_AUD0; i++) + for (int i = 0; i <= (PESTYPE_AUDMAX - PESTYPE_AUD0); i++) { avail_mpaudchan[i] = false; } diff --git a/demuxer.h b/demuxer.h index ea1d37e..eb5881c 100644 --- a/demuxer.h +++ b/demuxer.h @@ -161,7 +161,7 @@ protected: PESTYPE_VIDMAX = PESTYPE_VID15 }; - bool avail_mpaudchan[PESTYPE_AUDMAX-PESTYPE_AUD0]; + bool avail_mpaudchan[PESTYPE_AUDMAX-PESTYPE_AUD0+1]; }; #endif diff --git a/message.h b/message.h index 8a9b293..4c98b99 100644 --- a/message.h +++ b/message.h @@ -65,6 +65,8 @@ class Message const static ULONG MOVE_RECORDING = 20; const static ULONG UDP_BUTTON = 21; const static ULONG PLAYER_EVENT = 22; + const static ULONG AUDIO_CHANGE_CHANNEL = 23; + const static ULONG CHILD_CLOSE = 24; }; #endif diff --git a/recinfo.cc b/recinfo.cc index 3a22c35..faa370a 100644 --- a/recinfo.cc +++ b/recinfo.cc @@ -106,12 +106,15 @@ void RecInfo::print() } } -bool RecInfo::hasVideo() +bool RecInfo::hasNoVideo() { + // If no info (numComponents == 0) assume there is video + if (!numComponents) return false; + // video = 1, audio = 2 for (ULONG i = 0; i < numComponents; i++) - if (streams[i] == 1) return true; + if (streams[i] == 1) return false; - return false; + return true; } diff --git a/recinfo.h b/recinfo.h index 9442f32..031fcc5 100644 --- a/recinfo.h +++ b/recinfo.h @@ -49,7 +49,7 @@ class RecInfo void print(); - bool hasVideo(); + bool hasNoVideo(); private: diff --git a/vaudioselector.cc b/vaudioselector.cc index 01b8c29..a310df0 100644 --- a/vaudioselector.cc +++ b/vaudioselector.cc @@ -1,5 +1,5 @@ /* - Copyright 2004-2005 Chris Tallon + Copyright 2006 Chris Tallon, Marten Richter This file is part of VOMP. @@ -20,36 +20,27 @@ #include "vaudioselector.h" -VAudioSelector::VAudioSelector(View* tparent, bool* availableAudioChannels, int currentAudioChannel, RecInfo* recInfo) +VAudioSelector::VAudioSelector(void* tparent, bool* availableAudioChannels, int currentAudioChannel, RecInfo* recInfo) { + Log::getInstance()->log("VAS", Log::DEBUG, "%i", currentAudioChannel); + parent = tparent; create(200, 120); - if (Video::getInstance()->getFormat() == Video::PAL) - { - setScreenPos(62, 410); - } - else - { - setScreenPos(57, 320); - } - - setTitleText(tr("Audio")); - setBackgroundColour(Colour::VIEWBACKGROUND); - setTitleBarOn(1); - setTitleBarColour(Colour::TITLEBARBACKGROUND); +// setTitleText(tr("Audio")); +// setTitleBarOn(1); +// setTitleBarColour(Colour::TITLEBARBACKGROUND); sl.setSurface(surface); - sl.setSurfaceOffset(0, 30); - sl.setDimensions(area.w, area.h - 30); + sl.setSurfaceOffset(40, 30); + sl.setDimensions(area.w - 45, area.h - 30); // Load data from availableAudioChannels, currentAudioChannel and recInfo int i; - int selected = 0; - for (i = 0; i < PES_AUDIO_END - PES_AUDIO_START; i++) + for (i = 0; i < PES_AUDIO_MAXCHANNELS; i++) { if (availableAudioChannels[i]) { @@ -57,7 +48,6 @@ VAudioSelector::VAudioSelector(View* tparent, bool* availableAudioChannels, int ac->type = 0; ac->name = NULL; ac->pestype = PES_AUDIO_START + i; - if (i == currentAudioChannel) selected = i; acl.push_back(ac); } } @@ -138,7 +128,6 @@ VAudioSelector::VAudioSelector(View* tparent, bool* availableAudioChannels, int // Now do display char tempString[300]; - int slSelected; int audioChannelListSize = acl.size(); if (audioChannelListSize) @@ -146,19 +135,15 @@ VAudioSelector::VAudioSelector(View* tparent, bool* availableAudioChannels, int for(i = 0; i < audioChannelListSize; i++) { AudioChannel* ac = acl[i]; - if (i == currentAudioChannel) - slSelected = 1; - else - slSelected = 0; if (ac->name) { - sl.addOption(ac->name, (ULONG)ac, slSelected); + sl.addOption(ac->name, (ULONG)ac, (ac->pestype == currentAudioChannel)); } else { SNPRINTF(tempString, 299, "%lu", (ULONG)(ac->pestype - PES_AUDIO_START)); - sl.addOption(tempString, (ULONG)ac, slSelected); + sl.addOption(tempString, (ULONG)ac, (ac->pestype == currentAudioChannel)); } } } @@ -178,11 +163,21 @@ VAudioSelector::~VAudioSelector() acl.clear(); sl.clear(); + + Message* m = new Message(); + m->from = this; + m->to = parent; + m->message = Message::CHILD_CLOSE; + Command::getInstance()->postMessageNoLock(m); } void VAudioSelector::draw() { View::draw(); + rectangle(0, 0, area.w, 30, Colour::TITLEBARBACKGROUND); + drawText(tr("Audio"), 45, 5, Colour::LIGHTTEXT); + + sl.setBackgroundColour(backgroundColour); sl.draw(); } @@ -192,26 +187,41 @@ int VAudioSelector::handleCommand(int command) { case Remote::BACK: case Remote::OK: + case Remote::GREEN: { return 4; } case Remote::DF_UP: + case Remote::UP: { sl.up(); sl.draw(); ViewMan::getInstance()->updateView(this); - //player->setAudioChannel((AudioChannel*)sl.getCurrentOptionData()); + + Message* m = new Message(); + m->from = this; + m->to = parent; + m->message = Message::AUDIO_CHANGE_CHANNEL; + m->parameter = ((AudioChannel*)sl.getCurrentOptionData())->pestype; + Command::getInstance()->postMessageNoLock(m); return 2; } case Remote::DF_DOWN: + case Remote::DOWN: { sl.down(); sl.draw(); ViewMan::getInstance()->updateView(this); - //player->setAudioChannel((AudioChannel*)sl.getCurrentOptionData()); + + Message* m = new Message(); + m->from = this; + m->to = parent; + m->message = Message::AUDIO_CHANGE_CHANNEL; + m->parameter = ((AudioChannel*)sl.getCurrentOptionData())->pestype; + Command::getInstance()->postMessageNoLock(m); return 2; } diff --git a/vaudioselector.h b/vaudioselector.h index 6f4754b..5a5c9ea 100644 --- a/vaudioselector.h +++ b/vaudioselector.h @@ -1,5 +1,5 @@ /* - Copyright 2004-2005 Chris Tallon + Copyright 2006 Chris Tallon, Marten Richter This file is part of VOMP. @@ -33,9 +33,11 @@ #include "video.h" #include "viewman.h" #include "i18n.h" +#include "message.h" +#include "command.h" #define PES_AUDIO_START 0xc0 -#define PES_AUDIO_END 0xcf +#define PES_AUDIO_MAXCHANNELS 0x20 class AudioChannel { @@ -50,14 +52,14 @@ typedef vector AudioChannelList; class VAudioSelector : public View { public: - VAudioSelector(View* parent, bool* availableAudioChannels, int currentAudioChannel, RecInfo* recInfo); + VAudioSelector(void* parent, bool* availableAudioChannels, int currentAudioChannel, RecInfo* recInfo); ~VAudioSelector(); int handleCommand(int command); void draw(); private: - View* parent; + void* parent; WSelectList sl; AudioChannelList acl; diff --git a/view.h b/view.h index 5cc6009..739a397 100644 --- a/view.h +++ b/view.h @@ -49,12 +49,12 @@ class View : public Box private: static char numViews; - Colour backgroundColour; char* titleText; UCHAR borderOn; protected: + Colour backgroundColour; Colour titleBarColour; UCHAR titleBarOn; }; diff --git a/vvideorec.cc b/vvideorec.cc index e11d950..9fde5dc 100644 --- a/vvideorec.cc +++ b/vvideorec.cc @@ -26,10 +26,11 @@ VVideoRec::VVideoRec(Recording* rec) vdr = VDR::getInstance(); video = Video::getInstance(); timers = Timers::getInstance(); + vas = NULL; - isRadio = !(rec->recInfo->hasVideo()); + isRadio = rec->recInfo->hasNoVideo(); - Log::getInstance()->log("VVideoRec", Log::DEBUG, "hasVideo = %i", isRadio); + Log::getInstance()->log("VVideoRec", Log::DEBUG, "Radio = %i", isRadio); player = new Player(Command::getInstance(), this, true, isRadio); player->init(); @@ -83,7 +84,9 @@ VVideoRec::VVideoRec(Recording* rec) barBlue.set(0, 0, 150, 150); barShowing = false; - stickyBar = false; + barGenHold = false; + barScanHold = false; + barVasHold = false; dowss = false; char* optionWSS = vdr->configLoad("General", "WSS"); @@ -112,6 +115,12 @@ VVideoRec::VVideoRec(Recording* rec) VVideoRec::~VVideoRec() { + if (vas) + { + viewman->removeView(vas); + vas = NULL; + } + if (playing) stopPlay(); video->setDefaultAspect(); @@ -142,12 +151,20 @@ void VVideoRec::go(bool resume) ULLONG lengthBytes = vdr->streamRecording(myRec->getFileName(), &lengthFrames); if (lengthBytes) { - doBar(0); player->setLengthBytes(lengthBytes); - if (!isRadio) player->setLengthFrames(lengthFrames); + if (!isRadio) + { + Log::getInstance()->log("VVideoRec", Log::DEBUG, "GO is setting length frames = %lu", lengthFrames); + player->setLengthFrames(lengthFrames); + } + else + { + Log::getInstance()->log("VVideoRec", Log::DEBUG, "GO is NOT setting length frames"); + } player->setStartFrame(startFrameNum); // means bytes if radio (FIXME not done yet!) player->play(); playing = true; + doBar(0); } else { @@ -281,6 +298,8 @@ int VVideoRec::handleCommand(int command) #ifdef DEV case Remote::RED: { + //Don't use RED for anything. It will eventually be recording summary + //player->test1(); @@ -306,52 +325,67 @@ int VVideoRec::handleCommand(int command) void VVideoRec::processMessage(Message* m) { - if (m->from != player) return; - if (m->message != Message::PLAYER_EVENT) return; - Log::getInstance()->log("VVideoRec", Log::DEBUG, "Message received"); - switch(m->parameter) + if (m->from == player) { - case Player::CONNECTION_LOST: // connection lost detected + if (m->message != Message::PLAYER_EVENT) return; + switch(m->parameter) { - // I can't handle this, send it to command - Message* m = new Message(); - m->to = Command::getInstance(); - m->message = Message::CONNECTION_LOST; - Command::getInstance()->postMessageNoLock(m); - break; - } - case Player::STOP_PLAYBACK: - { - // FIXME Obselete ish - improve this - Message* m = new Message(); // Must be done after this thread finishes, and must break into master mutex - m->to = Command::getInstance(); - m->message = Message::STOP_PLAYBACK; - Command::getInstance()->postMessageNoLock(m); - break; - } - case Player::ASPECT43: - { - if (dowss) + case Player::CONNECTION_LOST: // connection lost detected { - Log::getInstance()->log("VVideoRec", Log::DEBUG, "Received do WSS 43"); - wss.setWide(false); - wss.draw(); - viewman->updateView(this, &wssRegion); + // I can't handle this, send it to command + Message* m = new Message(); + m->to = Command::getInstance(); + m->message = Message::CONNECTION_LOST; + Command::getInstance()->postMessageNoLock(m); + break; } - break; - } - case Player::ASPECT169: - { - if (dowss) + case Player::STOP_PLAYBACK: { - Log::getInstance()->log("VVideoRec", Log::DEBUG, "Received do WSS 169"); - wss.setWide(true); - wss.draw(); - viewman->updateView(this, &wssRegion); + // FIXME Obselete ish - improve this + Message* m = new Message(); // Must be done after this thread finishes, and must break into master mutex + m->to = Command::getInstance(); + m->message = Message::STOP_PLAYBACK; + Command::getInstance()->postMessageNoLock(m); + break; } - break; + case Player::ASPECT43: + { + if (dowss) + { + Log::getInstance()->log("VVideoRec", Log::DEBUG, "Received do WSS 43"); + wss.setWide(false); + wss.draw(); + viewman->updateView(this, &wssRegion); + } + break; + } + case Player::ASPECT169: + { + if (dowss) + { + Log::getInstance()->log("VVideoRec", Log::DEBUG, "Received do WSS 169"); + wss.setWide(true); + wss.draw(); + viewman->updateView(this, &wssRegion); + } + break; + } + } + } + else if (m->message == Message::AUDIO_CHANGE_CHANNEL) + { + Log::getInstance()->log("VVideoRec", Log::DEBUG, "Received change audio channel to %i", m->parameter); + player->setAudioChannel(m->parameter); + } + else if (m->message == Message::CHILD_CLOSE) + { + if (m->from == vas) + { + vas = NULL; + barVasHold = false; + if (!barGenHold && !barScanHold && !barVasHold) removeBar(); } } } @@ -399,7 +433,22 @@ void VVideoRec::doAudioSelector() { bool* availableAudioChannels = player->getDemuxerAudioChannels(); int currentAudioChannel = player->getCurrentAudioChannel(); - VAudioSelector* vas = new VAudioSelector(this, availableAudioChannels, currentAudioChannel, myRec->recInfo); + + vas = new VAudioSelector(this, availableAudioChannels, currentAudioChannel, myRec->recInfo); + vas->setBackgroundColour(barBlue); + if (video->getFormat() == Video::PAL) + { +// vas->setScreenPos(62, barRegion.y - 120); + vas->setScreenPos(0, barRegion.y - 120); + } + else + { +// vas->setScreenPos(57, barRegion.y - 120); + vas->setScreenPos(0, barRegion.y - 120); + } + + barVasHold = true; + doBar(0); vas->draw(); viewman->add(vas); @@ -470,16 +519,14 @@ void VVideoRec::doBar(int action) viewman->updateView(this, &barRegion); - if ((playerState == Player::S_FFWD) || (playerState == Player::S_FBWD)) - { - timers->cancelTimer(this, 1); - stickyBar = true; - } - else - { - timers->setTimerD(this, 1, 4); // only set the getridofbar timer if not ffwd/fbwd - stickyBar = false; - } + timers->cancelTimer(this, 1); + + + if ((playerState == Player::S_FFWD) || (playerState == Player::S_FBWD)) barScanHold = true; + else barScanHold = false; + + if (!barGenHold && !barScanHold && !barVasHold) timers->setTimerD(this, 1, 4); + timers->setTimerD(this, 2, 0, 200000000); } @@ -507,17 +554,17 @@ void VVideoRec::timercall(int clientReference) void VVideoRec::drawBarClocks() { - if (stickyBar) + if (barScanHold) { UCHAR playerState = player->getState(); // sticky bar is set if we are in ffwd/fbwd mode // if player has gone to S_PLAY then kill stickyBar, and run doBar(0) which // will repaint all the bar (it will call this function again, but - // this section won't run because stickyBar will then == false) + // this section won't run because stickyBarF will then == false) if ((playerState != Player::S_FFWD) && (playerState != Player::S_FBWD)) { - stickyBar = false; + barScanHold = false; doBar(0); return; // doBar will call this function and do the rest } @@ -617,7 +664,9 @@ void VVideoRec::removeBar() if (!barShowing) return; timers->cancelTimer(this, 2); barShowing = false; - stickyBar = false; + barGenHold = false; + barScanHold = false; + barVasHold = false; rectangle(barRegion, transparent); viewman->updateView(this, &barRegion); } diff --git a/vvideorec.h b/vvideorec.h index 0a24aa6..b03a40f 100644 --- a/vvideorec.h +++ b/vvideorec.h @@ -40,6 +40,7 @@ //#include "vepg.h" // for testing EPG in NTSC with a NTSC test video class Timers; +class VAudioSelector; class VVideoRec : public View, public TimerReceiver { @@ -61,6 +62,8 @@ class VVideoRec : public View, public TimerReceiver Player* player; Recording* myRec; + VAudioSelector* vas; + Colour transparent; Colour barBlue; @@ -68,10 +71,13 @@ class VVideoRec : public View, public TimerReceiver void toggleChopSides(); bool playing; - bool barShowing; - bool stickyBar; bool isRadio; + bool barShowing; + bool barGenHold; + bool barScanHold; + bool barVasHold; + void doAudioSelector(); void doBar(int action); void drawBarClocks(); diff --git a/widget.cc b/widget.cc index a525519..dc332c3 100644 --- a/widget.cc +++ b/widget.cc @@ -22,6 +22,7 @@ Widget::Widget() { + backgroundColour = Colour::VIEWBACKGROUND; } Widget::~Widget() @@ -39,6 +40,11 @@ void Widget::setDimensions(int twidth, int theight) area.h = theight; } +void Widget::setBackgroundColour(Colour& Tcolour) +{ + backgroundColour = Tcolour; +} + int Widget::getOffsetY() { return offsetY; diff --git a/widget.h b/widget.h index fee77dd..c572009 100644 --- a/widget.h +++ b/widget.h @@ -34,6 +34,7 @@ class Widget : public Box virtual void draw()=0; void setSurface(Surface* tsurface); void setDimensions(int width, int height); + void setBackgroundColour(Colour& colour); int getOffsetY(); int getOffsetX(); @@ -41,6 +42,7 @@ class Widget : public Box private: protected: + Colour backgroundColour; }; #endif diff --git a/wselectlist.cc b/wselectlist.cc index e27593c..21b6d98 100644 --- a/wselectlist.cc +++ b/wselectlist.cc @@ -98,7 +98,7 @@ void WSelectList::draw() - fillColour(Colour::VIEWBACKGROUND); + fillColour(backgroundColour); UINT ypos = 5; for (UINT i = topOption; i < (topOption + numOptionsDisplayable); i++) -- 2.39.2