From 12ae44c4a8cec832402c1764a592e86bddb7e231 Mon Sep 17 00:00:00 2001 From: Chris Tallon Date: Tue, 13 Dec 2005 18:13:48 +0000 Subject: [PATCH] EPG tweaks, EPG made NTSC compatible PAL/NTSC overridable from config file --- command.cc | 88 ++++++++++++++++++++++++++++++++++++-------- command.h | 1 + main.cc | 2 +- vepg.cc | 100 +++++++++++++++++++++++++++++++++----------------- vepg.h | 4 ++ vvideolive.cc | 43 +++++++--------------- vvideolive.h | 4 +- vvideorec.cc | 13 ++++++- vvideorec.h | 2 + 9 files changed, 175 insertions(+), 82 deletions(-) diff --git a/command.cc b/command.cc index 5c77313..a21a097 100644 --- a/command.cc +++ b/command.cc @@ -74,23 +74,10 @@ void Command::stop() irun = 0; } -void Command::run() +void Command::doWallpaper() { - if (!initted) return; - irun = 1; - - mainPid = getpid(); - Video* video = Video::getInstance(); - UCHAR screenSize = video->getFormat(); - - // moved from startup because surface delete doesn't work - - // just in case - video->signalOn(); - Led::getInstance()->on(); - // Blue background View* v = new View(); v->create(video->getScreenWidth(), video->getScreenHeight()); @@ -102,7 +89,7 @@ void Command::run() // Wallpaper wallpaper = new VWallpaper(); - if (screenSize == Video::PAL) + if (video->getFormat() == Video::PAL) { logger->log("Command", Log::DEBUG, "PAL wallpaper selected"); wallpaper->init("/wallpaperPAL.jpg"); @@ -115,6 +102,20 @@ void Command::run() wallpaper->draw(); viewman->add(wallpaper); viewman->updateView(wallpaper); +} + +void Command::run() +{ + if (!initted) return; + irun = 1; + + mainPid = getpid(); + + // just in case + Video::getInstance()->signalOn(); + Led::getInstance()->on(); + + doWallpaper(); // End of startup. Lock the mutex and put the first view up @@ -330,6 +331,63 @@ void Command::doJustConnected(VConnect* vconnect) VDR* vdr = VDR::getInstance(); char* config; + // See if config says to override video format (PAL/NTSC) + config = vdr->configLoad("General", "Override Video Format"); + if (config) + { + logger->log("Command", Log::DEBUG, "Override Video Format is present"); + + if ( (!strcmp(config, "PAL") && (video->getFormat() == Video::NTSC)) + || (!strcmp(config, "NTSC") && (video->getFormat() == Video::PAL)) ) + { + // Oh sheesh, need to switch format. Bye bye TV... + + // Take everything down + viewman->removeAll(); + viewman->removeView(wallpaper); + Osd* osd = Osd::getInstance(); + osd->shutdown(); + video->shutdown(); + + // Get video and osd back up with the new mode + if (!strcmp(config, "PAL")) + { + logger->log("Command", Log::DEBUG, "Switching to PAL"); + video->init(Video::PAL); + } + else if (!strcmp(config, "NTSC")) + { + logger->log("Command", Log::DEBUG, "Switching to NTSC"); + video->init(Video::NTSC); + } + osd->init("/dev/stbgfx"); + + // Put the wallpaper back + doWallpaper(); + + // Re add the vinfo + vi = new VInfo(); + vi->create(400, 200); + if (video->getFormat() == Video::PAL) + vi->setScreenPos(170, 200); + else + vi->setScreenPos(160, 150); + + vi->setOneLiner(tr("Connected, loading config")); + vi->draw(); + viewman->add(vi); + viewman->updateView(vi); + } + else + { + logger->log("Command", Log::DEBUG, "Already in requested mode, or request was not 'PAL' or 'NTSC'"); + } + } + else + { + logger->log("Command", Log::DEBUG, "Phew, no dangerous on-the-fly mode switching to do!"); + } + // Power off if first boot and config says so if (firstBoot) { diff --git a/command.h b/command.h index 3fe958e..2da9f78 100644 --- a/command.h +++ b/command.h @@ -75,6 +75,7 @@ class Command : public MessageQueue void handleCommand(int); void doStandby(); void doJustConnected(VConnect* vconnect); + void doWallpaper(); static Command* instance; pid_t mainPid; diff --git a/main.cc b/main.cc index 723ea6b..2f9a576 100644 --- a/main.cc +++ b/main.cc @@ -209,7 +209,7 @@ int main(int argc, char** argv) else if (videoFormat == Video::NTSC) logger->log("Core", Log::INFO, "Read from MTD: NTSC 720x480"); else logger->log("Core", Log::INFO, "No help from MTD. Assuming NTSC 720x480"); -// videoFormat = Video::NTSC; // enable this line to test NTSC in PAL land + //videoFormat = Video::NTSC; // enable this line to test NTSC in PAL land success = video->init(videoFormat); if (success) diff --git a/vepg.cc b/vepg.cc index af6d2da..50c9d47 100644 --- a/vepg.cc +++ b/vepg.cc @@ -32,9 +32,44 @@ */ #include "vepg.h" + +VEpg* VEpg::instance = NULL; VEpg::VEpg(VVideoLive* v, UINT currentChannel) { + instance = this; + + // PAL / NTSC sizes ----------------------- + + int xsize, ysize; + int xpos, ypos; + int summaryLines, summaryLowerPadding; + int chanNameYpos; + //UINT gridRows; // is a class member + + if (Video::getInstance()->getFormat() == Video::PAL) + { + xsize = 632; + ysize = 541; + xpos = 60; + ypos = 16; + summaryLines = 8; + summaryLowerPadding = 12; + chanNameYpos = 244; + gridRows = 7; + } + else + { + xsize = 632; + ysize = 452; + xpos = 50; + ypos = 10; + summaryLines = 6; + summaryLowerPadding = 26; + chanNameYpos = 206; + gridRows = 5; + } + // initialise variables and pointers viewman = ViewMan::getInstance(); videoLive = v; @@ -42,7 +77,7 @@ VEpg::VEpg(VVideoLive* v, UINT currentChannel) chanList = VDR::getInstance()->getChannelsList(VDR::VIDEO); //TODO want to be able to display video and radio together e = 0; - for(UINT listIndex = 0; listIndex < 7; listIndex++) + for(UINT listIndex = 0; listIndex < gridRows; listIndex++) { // initialise array of pointers to eventlist structures eventLista[listIndex] = NULL; @@ -51,46 +86,38 @@ VEpg::VEpg(VVideoLive* v, UINT currentChannel) // Create pallet on which to paint our epg view and position it in centre of screen. // Need to reduce size to deal with overscanning TVs. - // FIXME have size for ntsc - if (Video::getInstance()->getFormat() == Video::PAL) - { - create(632, 541); - setScreenPos(60, 16); - } - else - { - create(632, 440); - setScreenPos(50, 10); - } + create(xsize, ysize); + setScreenPos(xpos, ypos); -// beautify + // beautify Colour transparent = Colour(0, 0, 0, 0); setBackgroundColour(transparent); progTitle.setSurface(surface); progTitle.setSurfaceOffset(0,0); - progTitle.setDimensions(300,(Surface::getFontHeight() + 6) * 2 + 16); //paragraph line seperation is 6 pixels + progTitle.setDimensions(300,(Surface::getFontHeight() + 4) * 2 + 16); //paragraph line seperation is 4 pixels progTitle.setBackgroundColour(Colour::TITLEBARBACKGROUND); progTitle.setTextPos(5, 16); + progTitle.setGap(4); progInfo.setSurface(surface); progInfo.setSurfaceOffset(0, progTitle.getOffsetY() + progTitle.getHeight()); - progInfo.setDimensions(300,(Surface::getFontHeight() + 4) * 8 + 12); + progInfo.setDimensions(300,((Surface::getFontHeight() + 4) * summaryLines) + summaryLowerPadding); progInfo.setGap(4); chanName.setSurface(surface); chanName.setDimensions(510, (Surface::getFontHeight() + 4)); - chanName.setSurfaceOffset(305,244); + chanName.setSurfaceOffset(305, chanNameYpos); chanName.setBackgroundColour(Colour(0, 0, 0, 90)); // create area to display list of channels chanListbox.setSurface(surface); // add channel list chanListbox.setSurfaceOffset(0, progInfo.getOffsetY() + progInfo.getHeight() + Surface::getFontHeight() + 8); // position channel list - chanListbox.setDimensions(150, (Surface::getFontHeight() + 2) * 7 + 5); //listbox line seperation is 1 pixel + chanListbox.setDimensions(150, ((Surface::getFontHeight() + 2) * gridRows) + 5); //listbox line seperation is 2 pixels chanListbox.setGap(2); -// populate channel list + // populate channel list Channel* chan; int first = 1; for (UINT i = 0; i < chanList->size(); i++) @@ -112,18 +139,25 @@ VEpg::VEpg(VVideoLive* v, UINT currentChannel) VEpg::~VEpg() { - for(int listIndex = 0; listIndex < 7; listIndex++) - { - if (eventLista[listIndex]) - { - (eventLista)[listIndex]->clear(); - delete eventLista[listIndex]; - } - } -// delete [] eventLista; + instance = NULL; + + for(UINT listIndex = 0; listIndex < gridRows; listIndex++) + { + if (eventLista[listIndex]) + { + (eventLista)[listIndex]->clear(); + delete eventLista[listIndex]; + } + } + // delete [] eventLista; -// destroy dynamically allocated memory + // destroy dynamically allocated memory } + +VEpg* VEpg::getInstance() +{ + return instance; +} void VEpg::setInfo(Event* event) { @@ -328,7 +362,7 @@ int VEpg::handleCommand(int command) case Remote::GUIDE: { // return to normal TV mode - videoLive->setEpgMode(FALSE); + if (videoLive) videoLive->resetPictureSize(); // ptr check done in case being tested from videorec return 4; } case Remote::CHANNELUP: @@ -413,11 +447,11 @@ void VEpg::drawgrid() // redraws grid and select programme int y = chanListbox.getOffsetY() + 5; // vertical position of cell Colour bg, fg; // background colour of cells in grid // for each displayed channel, find programmes that fall in 2.5 hour time window - for(int listIndex = 0; listIndex < 7; listIndex++) + for(UINT listIndex = 0; listIndex < gridRows; listIndex++) { - if (listTop + listIndex >= chanListbox.getBottomOption()) + if (listTop + (int)listIndex >= chanListbox.getBottomOption()) continue; // ensure nothing populates grid below last channel - currentRow = (listTop + listIndex == chanListbox.getCurrentOption()); + currentRow = (listTop + (int)listIndex == chanListbox.getCurrentOption()); noevent.time = ltime; noevent.duration = WINDOW_WIDTH * 60; noevent.settitle(""); @@ -499,7 +533,7 @@ void VEpg::drawgrid() // redraws grid and select programme void VEpg::updateEventList() { Channel* chan; - for(UINT listIndex = 0; listIndex < 7; listIndex++) + for(UINT listIndex = 0; listIndex < gridRows; listIndex++) { if (eventLista[listIndex]) { diff --git a/vepg.h b/vepg.h index d9c786f..4d48c50 100644 --- a/vepg.h +++ b/vepg.h @@ -47,12 +47,15 @@ class VEpg : public View public: VEpg(VVideoLive* v, UINT currentChannel = 0); ~VEpg(); + static VEpg* getInstance(); int handleCommand(int command); // deal with commands (from remote control) void draw(); // draw epg view void setCurrentChannel(char* chname); private: + static VEpg* instance; + void setInfo(Event* event); // display details of selected programme void drawgrid(); // redraws grid and select programme void drawData(); @@ -79,6 +82,7 @@ class VEpg : public View time_t prevHour(time_t* t); VVideoLive* videoLive; ViewMan* viewman; + UINT gridRows; }; #endif diff --git a/vvideolive.cc b/vvideolive.cc index 6a39630..5321c51 100644 --- a/vvideolive.cc +++ b/vvideolive.cc @@ -33,7 +33,6 @@ VVideoLive::VVideoLive(ChannelList* tchanList, ULONG tstreamType) unavailable = 0; unavailableView = NULL; streamType = tstreamType; - epgmode=false; videoMode = Video::getInstance()->getMode(); if (streamType == VDR::RADIO) player = new PlayerVideo(Command::getInstance(), 0, 1); else player = new PlayerVideo(Command::getInstance(), 0, 0); @@ -124,11 +123,7 @@ int VVideoLive::handleCommand(int command) case Remote::GUIDE: case Remote::RED: { - if (!epgmode) - { - showEPG(); - } - epgmode=!epgmode; + showEPG(); return 2; } @@ -189,9 +184,9 @@ void VVideoLive::channelChange(UCHAR changeType, UINT newData) if (unavailable) showUnavailable(0); else stop(1); - if(epgmode) - if(vepg) - vepg->setCurrentChannel((*chanList)[currentChannel]->name); + + VEpg* vepg = VEpg::getInstance(); + if(vepg) vepg->setCurrentChannel((*chanList)[currentChannel]->name); play(); } @@ -205,7 +200,7 @@ void VVideoLive::processMessage(Message* m) { // this message is from vlivebanner channelChange(OFFSET, UP); - if(!epgmode) + if(!VEpg::getInstance()) { VLiveBanner* vlb = VLiveBanner::getInstance(); // guaranteed to be one vlb->setChannel((*chanList)[currentChannel]); @@ -217,7 +212,7 @@ void VVideoLive::processMessage(Message* m) { // this message is from vlivebanner channelChange(OFFSET, DOWN); - if(!epgmode) + if(!VEpg::getInstance()) { VLiveBanner* vlb = VLiveBanner::getInstance(); // guaranteed to be one vlb->setChannel((*chanList)[currentChannel]); @@ -234,19 +229,13 @@ void VVideoLive::processMessage(Message* m) else if (m->message == Message::EPG) { Log::getInstance()->log("VVideoLive", Log::DEBUG, "EPG requested from live banner"); - - if (!epgmode) - { - showEPG(); - epgmode=!epgmode; // shouldn't this be within the braces? // same for above in handleCommand, ask Brian FIXME - } + showEPG(); } } void VVideoLive::doBanner(bool bannerTakesCommands) { - if(epgmode) - return; + if (VEpg::getInstance()) return; if (VLiveBanner::getInstance()) return; // there already is one @@ -354,24 +343,20 @@ void VVideoLive::showEPG() { if (unavailable) showUnavailable(0); + if (VEpg::getInstance()) return; // already showing! + Video::getInstance()->setMode(Video::QUARTER); Video::getInstance()->setPosition(170, 5); //TODO need to deal with 4:3 switching - vepg = new VEpg(this, currentChannel); + VEpg* vepg = new VEpg(this, currentChannel); vepg->draw(); viewman->add(vepg); viewman->updateView(vepg); } -void VVideoLive::setEpgMode(bool mode) +void VVideoLive::resetPictureSize() { - epgmode = mode; - - // Ok so we do need this function - // but FIXME improve this, integrate with live mode switching from remote - if (mode == FALSE) - { - Video::getInstance()->setMode(videoMode); - } + // called by VEpg when it closes + Video::getInstance()->setMode(videoMode); } diff --git a/vvideolive.h b/vvideolive.h index a6eca71..2f1e722 100644 --- a/vvideolive.h +++ b/vvideolive.h @@ -61,7 +61,7 @@ class VVideoLive : public View void play(int noShowVLB = 0); void stop(int noRemoveVLB = 0); - void setEpgMode(bool mode); + void resetPictureSize(); const static UCHAR INDEX = 1; const static UCHAR NUMBER = 2; @@ -86,9 +86,7 @@ class VVideoLive : public View UINT downChannel(); void doBanner(bool takesCommands); void showUnavailable(int active); - VEpg* vepg; int xpos; - bool epgmode; void showEPG(); void doNoSuchChannel(); int videoMode; diff --git a/vvideorec.cc b/vvideorec.cc index 5622e18..18e0c8a 100644 --- a/vvideorec.cc +++ b/vvideorec.cc @@ -116,7 +116,18 @@ int VVideoRec::handleCommand(int command) #ifdef DEV case Remote::RED: { - player->test1(); + //player->test1(); + + /* + // for testing EPG in NTSC with a NTSC test video + Video::getInstance()->setMode(Video::QUARTER); + Video::getInstance()->setPosition(170, 5); + VEpg* vepg = new VEpg(NULL, 0); + vepg->draw(); + ViewMan::getInstance()->add(vepg); + ViewMan::getInstance()->updateView(vepg); + */ + return 2; } case Remote::GREEN: diff --git a/vvideorec.h b/vvideorec.h index f33c1c7..cfaf2f5 100644 --- a/vvideorec.h +++ b/vvideorec.h @@ -31,6 +31,8 @@ #include "colour.h" #include "osd.h" +//#include "vepg.h" // for testing EPG in NTSC with a NTSC test video + class VVideoRec : public View { public: -- 2.39.2