2 Copyright 2004-2005 Chris Tallon, 2009 Marten Richter
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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
22 #include "videovpeogl.h"
34 lastAType = MPTYPE_MPEG_AUDIO;
41 int AudioVPE::init(UCHAR tstreamType)
43 if (initted) return 0;
46 // // if ((fdAudio = open("/dev/adec_mpg", O_RDWR | O_NONBLOCK)) < 0) return 0;
47 // if ((fdAudio = open("/dev/adec_mpg", O_WRONLY)) < 0) return 0;
49 streamType = tstreamType;
59 // Set the volume variable to what the hardware is set at now
61 /* int hwvolFail = ioctl(fdAudio, AV_GET_AUD_VOLUME, &hwvol);
64 volume = 20 - ((hwvol >> 16) & 0xFF);
65 if ((volume < 0) || (volume > 20)) volume = 20;
71 int AudioVPE::initAllParams()
73 return (setStreamType(streamType) && setChannel() && setSource());
76 int AudioVPE::shutdown()
78 if (!initted) return 0;
84 int AudioVPE::setStreamType(UCHAR type)
86 if (!initted) return 0;
88 // if (ioctl(fdAudio, AV_SET_AUD_STREAMTYPE, type) != 0) return 0;
92 int AudioVPE::setChannel()
94 if (!initted) return 0;
96 // if (ioctl(fdAudio, AV_SET_AUD_CHANNEL, 0) != 0) return 0;
100 int AudioVPE::setSource()
102 if (!initted) return 0;
104 // if (ioctl(fdAudio, AV_SET_AUD_SRC, 1) != 0) return 0;
110 if (!initted) return 0;
112 // if (ioctl(fdAudio, AV_SET_AUD_SYNC, 2) != 0) return 0;
118 if (!initted) return 0;
121 ((VideoVPEOGL*) Video::getInstance())->initMuxer();
123 //if (ioctl(fdAudio, AV_SET_AUD_PLAY, 0) != 0) return 0;
129 if (!initted) return 0;
130 ((VideoVPEOGL*) Video::getInstance())->deinitMuxer();
132 //if (ioctl(fdAudio, AV_SET_AUD_RESET, 0x11) != 0) return 0;
138 if (!initted) return 0;
140 // if (ioctl(fdAudio, AV_SET_AUD_MUTE, 1) != 0) return 0;
141 Log::getInstance()->log("Audio", Log::DEBUG, "MUTE MUTE MUTE");
147 int AudioVPE::unMute()
149 if (!initted) return 0;
151 // if (ioctl(fdAudio, AV_SET_AUD_MUTE, 0) != 0) return 0;
152 Log::getInstance()->log("Audio", Log::DEBUG, "MUTE OFF OFF OFF");
158 int AudioVPE::pause()
160 if (!initted) return 0;
162 // if (ioctl(fdAudio, AV_SET_AUD_PAUSE, 1) != 0) return 0;
166 int AudioVPE::unPause()
168 if (!initted) return 0;
170 // if (ioctl(fdAudio, AV_SET_AUD_UNPAUSE, 1) != 0) return 0;
174 int AudioVPE::reset()
176 if (!initted) return 0;
178 Log::getInstance()->log("Audio", Log::DEBUG, "reset called");
179 ((VideoVPEOGL*) Video::getInstance())->deinitMuxer();
181 // if (ioctl(fdAudio, AV_SET_AUD_RESET, 0x11) != 0) return 0;
182 // Log::getInstance()->log("Audio", Log::DEBUG, "reset back");
183 // if (ioctl(fdAudio, AV_SET_AUD_PLAY, 0) != 0) return 0;
189 int AudioVPE::setVolume(int tvolume)
191 // parameter: 0 for silence, 20 for full
192 if ((tvolume < 0) || (tvolume > 20)) return 0;
194 // volume = 2 * (20 - volume);
195 // Right, that one was rubbish... 0-10 were almost
196 // inaudible, 11-20 did what should have been done
197 // over the whole 0-20 range
199 tvolume = 20 - tvolume;
201 audio_volume Avolume;
202 Avolume.frontleft = tvolume + Aoffset.frontleft;
203 Avolume.frontright = tvolume + Aoffset.frontright;
204 Avolume.rearleft = tvolume + Aoffset.rearleft;
205 Avolume.rearright = tvolume + Aoffset.rearright;
206 Avolume.center = tvolume + Aoffset.center;
207 Avolume.lfe = tvolume + Aoffset.lfe;
209 // if (ioctl(fdAudio, AV_SET_AUD_VOLUME, &Avolume) != 0) return 0;
211 // unsigned long vol = (tvolume << 24) | (tvolume << 16);
213 // Log::getInstance()->log("Audio", Log::DEBUG, "%lx", vol);
214 // Log::getInstance()->log("Audio", Log::DEBUG, "%i", tvolume);
216 // if (ioctl(fdAudio, AV_SET_AUD_VOLUME, &vol) != 0) return 0;
224 // return ioctl(fdAudio, AV_SET_AUD_STC, &stc);
226 /* aud_sync_parms_t a;
230 // int b = ioctl(fdAudio, AV_SET_AUD_DISABLE_SYNC, &a);
233 /*OK*/ //printf("Audio sync disable = %i\n", b);
241 void AudioVPE::PrepareMediaSample(const MediaPacketList& mplist,UINT samplepos)
243 packet = mplist.front();
246 UINT AudioVPE::DeliverMediaSample(UCHAR* buffer, UINT* samplepos)
248 VideoVPEOGL *video=(VideoVPEOGL*)Video::getInstance();
249 //Log::getInstance()->log("Audio", Log::DEBUG, "lastpacket %d lastbuddypacket %d currentpacket %d",lastpacketnum,video->getLastPacketNum(),packet.index);
250 currentpacketnum=packet.index;
251 if (lastpacketnum!=-1 && packet.index-1!=lastpacketnum && packet.index-1>video->getLastPacketNum()) return 0; //Not in order
254 switch (packet.type) {
255 case MPTYPE_MPEG_AUDIO:
256 buffer[packet.pos_buffer + 3]=0xc0; break;
258 buffer[packet.pos_buffer +buffer[packet.pos_buffer+8]+9]=0x80;
259 buffer[packet.pos_buffer + 3]=0xbd; break;
262 case MPTYPE_AC3_PRE13://Not tested no recording availiable
263 buffer[packet.pos_buffer + 3]=0xbd; break;
267 if (packet.type!=lastAType && lastpacketnum!=-1){//Format Change //Push data out !
268 video->deinitMuxer();
269 lastAType=packet.type;
272 lastAType=packet.type;
275 /* Mutex *mutex=video->getMuxMutex();
277 FILE *muxout=video->getMuxFile();
278 if (!muxout) {mutex->Unlock(); return 0;}*
280 //written=fwrite(buffer + packet.pos_buffer,1,packet.length,muxout);
281 written=video->WriteOutTS(buffer + packet.pos_buffer,packet.length,packet.type);
282 lastpacketnum=packet.index;
286 //Log::getInstance()->log("Audio", Log::DEBUG, "wrote %d bytes to mux",written);
288 if (written == (int)packet.length) { *samplepos = 0; return 1;}
292 *samplepos = written;*/
293 // Handle a partial write. Is this possible? Should we bother? No!
298 void AudioVPE::ResetTimeOffsets()