From f87c56805e2d4745b42f02f87c0eb4f991e47a82 Mon Sep 17 00:00:00 2001 From: Chris Tallon Date: Tue, 21 Nov 2006 21:45:24 +0000 Subject: [PATCH] Audio channel selection code *unfinished* --- demuxer.cc | 21 ++++- demuxer.h | 8 ++ objects.mk | 2 +- player.cc | 15 ++++ player.h | 3 + vaudioselector.cc | 221 ++++++++++++++++++++++++++++++++++++++++++++++ vaudioselector.h | 67 ++++++++++++++ vrecordinglist.cc | 22 ++--- vvideorec.cc | 35 +++++--- vvideorec.h | 3 + 10 files changed, 372 insertions(+), 25 deletions(-) create mode 100644 vaudioselector.cc create mode 100644 vaudioselector.h diff --git a/demuxer.cc b/demuxer.cc index aff0f7f..686f847 100644 --- a/demuxer.cc +++ b/demuxer.cc @@ -91,6 +91,11 @@ void Demuxer::reset() horizontal_size = vertical_size = 0; aspect_ratio = (enum AspectRatio) 0; frame_rate = bit_rate = 0; + + for (int i = 0; i < PESTYPE_AUDMAX - PESTYPE_AUD0; i++) + { + avail_mpaudchan[i] = false; + } } int Demuxer::shutdown() @@ -205,6 +210,9 @@ int Demuxer::PESPacket::submit() else if (packetType >= PESTYPE_AUD0 && packetType <= PESTYPE_AUDMAX) { if (dx->audio_current == -1) dx->audio_current = packetType; + + dx->avail_mpaudchan[packetType-PESTYPE_AUD0]=true; + if (dx->audio_current == packetType && !dx->aud_seeking) sent = dx->audiostream.put(data+submitted, size-submitted); else @@ -345,6 +353,17 @@ UINT Demuxer::stripAudio(UCHAR* buf, UINT len) return write_pos; } +bool* Demuxer::getmpAudioChannels() +{ + return avail_mpaudchan; +} +int Demuxer::getselAudioChannel() +{ + return audio_current; +} - +void Demuxer::setmpAudioChannel(int aud_channel) +{ + audio_current = aud_channel; +} diff --git a/demuxer.h b/demuxer.h index ca32c1e..465d1cf 100644 --- a/demuxer.h +++ b/demuxer.h @@ -37,6 +37,9 @@ however, no code was copied verbatim. #include "callback.h" #include "draintarget.h" +#define PES_AUDIO_START 0xc0 +#define PES_AUDIO_END 0xcf + class Demuxer { protected: @@ -82,6 +85,10 @@ protected: virtual void setFrameNum(ULONG frame) {} virtual ULONG getFrameNumFromPTS(ULLONG pts) {return 0;} + bool* getmpAudioChannels(); //Maybe virtual ? + int getselAudioChannel(); + void setmpAudioChannel(int aud_channel); + int getHorizontalSize() { return horizontal_size; } int getVerticalSize() { return vertical_size; } int getAspectRatio() { return aspect_ratio; } @@ -153,6 +160,7 @@ protected: PESTYPE_VIDMAX = PESTYPE_VID15 }; + bool avail_mpaudchan[PESTYPE_AUDMAX-PESTYPE_AUD0]; }; #endif diff --git a/objects.mk b/objects.mk index 50b10d4..001562e 100644 --- a/objects.mk +++ b/objects.mk @@ -10,7 +10,7 @@ OBJECTS1 = command.o log.o tcp.o dsock.o thread.o timers.o i18n.o mutex.o \ vtimerlist.o vtimeredit.o voptionsmenu.o vrecordingmenu.o \ vchannellist.o vwelcome.o vvideolive.o vvideorec.o vepgsettimer.o \ vchannelselect.o vserverselect.o vconnect.o vepg.o vrecmove.o \ - vradiorec.o \ + vradiorec.o vaudioselector.o \ widget.o wselectlist.o wjpeg.o wsymbol.o wbutton.o \ woptionbox.o wtextbox.o wwss.o \ fonts/helvB24.o fonts/helvB18.o \ diff --git a/player.cc b/player.cc index d9ddd51..7f4f593 100644 --- a/player.cc +++ b/player.cc @@ -151,6 +151,21 @@ ULONG Player::getCurrentFrameNum() } } +bool* Player::getDemuxerAudioChannels() +{ + return demuxer->getmpAudioChannels(); +} + +int Player::getCurrentAudioChannel() +{ + return demuxer->getselAudioChannel(); +} + +void Player::setAudioChannel(int newChannel) +{ + demuxer->setmpAudioChannel(newChannel); +} + // ----------------------------------- Externally called events void Player::play() diff --git a/player.h b/player.h index 2e920fd..2b5578d 100644 --- a/player.h +++ b/player.h @@ -56,6 +56,7 @@ class Player : public Thread_TYPE, public Callback void setStartFrame(ULONG frameNum); void setLengthBytes(ULLONG length); void setLengthFrames(ULONG length); + void setAudioChannel(int newChannel); void play(); void stop(); @@ -70,6 +71,8 @@ class Player : public Thread_TYPE, public Callback ULONG getCurrentFrameNum(); ULONG getLengthFrames(); UCHAR getIScanRate() { return ifactor; } + bool* getDemuxerAudioChannels(); + int getCurrentAudioChannel(); void call(void*); // for callback interface diff --git a/vaudioselector.cc b/vaudioselector.cc new file mode 100644 index 0000000..01b8c29 --- /dev/null +++ b/vaudioselector.cc @@ -0,0 +1,221 @@ +/* + Copyright 2004-2005 Chris Tallon + + This file is part of VOMP. + + VOMP is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + VOMP is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with VOMP; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ + +#include "vaudioselector.h" + +VAudioSelector::VAudioSelector(View* tparent, bool* availableAudioChannels, int currentAudioChannel, RecInfo* recInfo) +{ + 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); + + sl.setSurface(surface); + sl.setSurfaceOffset(0, 30); + sl.setDimensions(area.w, 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++) + { + if (availableAudioChannels[i]) + { + AudioChannel* ac = new AudioChannel(); + ac->type = 0; + ac->name = NULL; + ac->pestype = PES_AUDIO_START + i; + if (i == currentAudioChannel) selected = i; + acl.push_back(ac); + } + } + + unsigned char numchan_recinfo = recInfo->numComponents; + unsigned char numchan_siz = acl.size(); + int mp_audcounter = 0; + int ac3_counter = 0; + int ac3_offset = 0; + + for (i = 0; i < numchan_siz; i++) + { + AudioChannel* ac = acl[i]; + if (ac) + { + if (ac->type==0) + { + ac3_offset++; + } + } + } + + unsigned char type; + char* lang; + char* description; + int type_int; + + for (i = 0; i < numchan_recinfo; i++) + { + if (recInfo->streams[i] != 2) continue; //not an audio component + type = recInfo->types[i]; + lang = recInfo->languages[i]; + description = recInfo->descriptions[i]; + AudioChannel* ac = NULL; + type_int = 0; + + switch (type) + { + case 1: //mpaudio mono + case 3: //mpaudio stereo + if (mp_audcounter < numchan_siz) ac = acl[mp_audcounter]; + type_int = 0; + break; + case 5: //ac3 + if (ac3_counter + ac3_offset < numchan_siz) ac = acl[ac3_counter + ac3_offset]; + type_int = 1; + break; + } + + if (ac) + { + if (ac->type == type_int) + { + if (description && (strlen(description) > 0)) + { + ac->name = new char[strlen(description)+1]; + strcpy(ac->name, description); + } + else if (lang && (strlen(lang) > 0)) + { + ac->name = new char[strlen(lang)+1]; + strcpy(ac->name, lang); + } + } + } + + switch (type_int) + { + case 0: //mpaudio + mp_audcounter++; + break; + case 1: //ac3 + ac3_counter++; + break; + } + } + + // Now do display + + char tempString[300]; + int slSelected; + int audioChannelListSize = acl.size(); + + if (audioChannelListSize) + { + 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); + } + else + { + SNPRINTF(tempString, 299, "%lu", (ULONG)(ac->pestype - PES_AUDIO_START)); + sl.addOption(tempString, (ULONG)ac, slSelected); + } + } + } + else + { + sl.addOption(tr("No audio channel data available"), 0, 1); + } +} + +VAudioSelector::~VAudioSelector() +{ + int audioChannelListSize = acl.size(); + for(int i = 0; i < audioChannelListSize; i++) + { + delete acl[i]; + } + acl.clear(); + + sl.clear(); +} + +void VAudioSelector::draw() +{ + View::draw(); + sl.draw(); +} + +int VAudioSelector::handleCommand(int command) +{ + switch (command) + { + case Remote::BACK: + case Remote::OK: + { + return 4; + } + case Remote::DF_UP: + { + sl.up(); + sl.draw(); + + ViewMan::getInstance()->updateView(this); + //player->setAudioChannel((AudioChannel*)sl.getCurrentOptionData()); + + return 2; + } + case Remote::DF_DOWN: + { + sl.down(); + sl.draw(); + + ViewMan::getInstance()->updateView(this); + //player->setAudioChannel((AudioChannel*)sl.getCurrentOptionData()); + + return 2; + } + } + + return 0; +} diff --git a/vaudioselector.h b/vaudioselector.h new file mode 100644 index 0000000..6f4754b --- /dev/null +++ b/vaudioselector.h @@ -0,0 +1,67 @@ +/* + Copyright 2004-2005 Chris Tallon + + This file is part of VOMP. + + VOMP is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + VOMP is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with VOMP; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ + +#ifndef VAUDIOSELECTOR_H +#define VAUDIOSELECTOR_H + +#include +#include +#include +#include + +#include "view.h" +#include "remote.h" +#include "wselectlist.h" +#include "colour.h" +#include "video.h" +#include "viewman.h" +#include "i18n.h" + +#define PES_AUDIO_START 0xc0 +#define PES_AUDIO_END 0xcf + +class AudioChannel +{ + public: + int type; + char* name; + int pestype; +}; + +typedef vector AudioChannelList; + +class VAudioSelector : public View +{ + public: + VAudioSelector(View* parent, bool* availableAudioChannels, int currentAudioChannel, RecInfo* recInfo); + ~VAudioSelector(); + + int handleCommand(int command); + void draw(); + + private: + View* parent; + WSelectList sl; + + AudioChannelList acl; +}; + +#endif + \ No newline at end of file diff --git a/vrecordinglist.cc b/vrecordinglist.cc index c3edd7b..5be3e47 100644 --- a/vrecordinglist.cc +++ b/vrecordinglist.cc @@ -297,22 +297,22 @@ int VRecordingList::doPlay(bool resume) if (toPlay) { toPlay->loadRecInfo(); - if (toPlay->recInfo->hasVideo()) - { +// if (toPlay->recInfo->hasVideo()) +// { VVideoRec* vidrec = new VVideoRec(toPlay); vidrec->draw(); viewman->add(vidrec); viewman->updateView(vidrec); vidrec->go(resume); - } - else - { - VRadioRec* radrec = new VRadioRec(toPlay); - radrec->draw(); - viewman->add(radrec); - viewman->updateView(radrec); - radrec->go(); - } +// } +// else +// { +// VRadioRec* radrec = new VRadioRec(toPlay); +// radrec->draw(); +// viewman->add(radrec); +// viewman->updateView(radrec); +// radrec->go(); +// } return 1; } // should not get to here diff --git a/vvideorec.cc b/vvideorec.cc index d9c4425..e11d950 100644 --- a/vvideorec.cc +++ b/vvideorec.cc @@ -22,6 +22,7 @@ VVideoRec::VVideoRec(Recording* rec) { + viewman = ViewMan::getInstance(); vdr = VDR::getInstance(); video = Video::getInstance(); timers = Timers::getInstance(); @@ -158,8 +159,6 @@ void VVideoRec::go(bool resume) return; } - ViewMan* viewman = ViewMan::getInstance(); - Message* m = new Message(); m->message = Message::CLOSE_ME; m->from = this; @@ -248,6 +247,11 @@ int VVideoRec::handleCommand(int command) player->skipForward(10); return 2; } + case Remote::GREEN: + { + doAudioSelector(); + return 2; + } case Remote::FULL: case Remote::TV: { @@ -292,11 +296,7 @@ int VVideoRec::handleCommand(int command) return 2; } - case Remote::GREEN: - { - //player->test2(); - return 2; - } + #endif } @@ -338,7 +338,7 @@ void VVideoRec::processMessage(Message* m) Log::getInstance()->log("VVideoRec", Log::DEBUG, "Received do WSS 43"); wss.setWide(false); wss.draw(); - ViewMan::getInstance()->updateView(this, &wssRegion); + viewman->updateView(this, &wssRegion); } break; } @@ -349,7 +349,7 @@ void VVideoRec::processMessage(Message* m) Log::getInstance()->log("VVideoRec", Log::DEBUG, "Received do WSS 169"); wss.setWide(true); wss.draw(); - ViewMan::getInstance()->updateView(this, &wssRegion); + viewman->updateView(this, &wssRegion); } break; } @@ -395,6 +395,17 @@ void VVideoRec::toggleChopSides() } } +void VVideoRec::doAudioSelector() +{ + bool* availableAudioChannels = player->getDemuxerAudioChannels(); + int currentAudioChannel = player->getCurrentAudioChannel(); + VAudioSelector* vas = new VAudioSelector(this, availableAudioChannels, currentAudioChannel, myRec->recInfo); + + vas->draw(); + viewman->add(vas); + viewman->updateView(vas); +} + void VVideoRec::doBar(int action) { barShowing = true; @@ -457,7 +468,7 @@ void VVideoRec::doBar(int action) drawBarClocks(); - ViewMan::getInstance()->updateView(this, &barRegion); + viewman->updateView(this, &barRegion); if ((playerState == Player::S_FFWD) || (playerState == Player::S_FBWD)) { @@ -487,7 +498,7 @@ void VVideoRec::timercall(int clientReference) // Update clock if (!barShowing) break; drawBarClocks(); - ViewMan::getInstance()->updateView(this, &barRegion); + viewman->updateView(this, &barRegion); timers->setTimerD(this, 2, 0, 200000000); break; } @@ -608,5 +619,5 @@ void VVideoRec::removeBar() barShowing = false; stickyBar = false; rectangle(barRegion, transparent); - ViewMan::getInstance()->updateView(this, &barRegion); + viewman->updateView(this, &barRegion); } diff --git a/vvideorec.h b/vvideorec.h index 0259dee..0a24aa6 100644 --- a/vvideorec.h +++ b/vvideorec.h @@ -35,6 +35,7 @@ #include "timerreceiver.h" #include "message.h" #include "wwss.h" +#include "vaudioselector.h" //#include "vepg.h" // for testing EPG in NTSC with a NTSC test video @@ -53,6 +54,7 @@ class VVideoRec : public View, public TimerReceiver void processMessage(Message* m); private: + ViewMan* viewman; VDR* vdr; Video* video; Timers* timers; @@ -70,6 +72,7 @@ class VVideoRec : public View, public TimerReceiver bool stickyBar; bool isRadio; + void doAudioSelector(); void doBar(int action); void drawBarClocks(); void stopPlay(); -- 2.39.5