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;
123 //if (ioctl(fdAudio, AV_SET_AUD_PLAY, 0) != 0) return 0;
129 if (!initted) return 0;
131 //if (ioctl(fdAudio, AV_SET_AUD_RESET, 0x11) != 0) return 0;
137 if (!initted) return 0;
139 // if (ioctl(fdAudio, AV_SET_AUD_MUTE, 1) != 0) return 0;
140 Log::getInstance()->log("Audio", Log::DEBUG, "MUTE MUTE MUTE");
146 int AudioVPE::unMute()
148 if (!initted) return 0;
150 // if (ioctl(fdAudio, AV_SET_AUD_MUTE, 0) != 0) return 0;
151 Log::getInstance()->log("Audio", Log::DEBUG, "MUTE OFF OFF OFF");
157 int AudioVPE::pause()
159 if (!initted) return 0;
161 // if (ioctl(fdAudio, AV_SET_AUD_PAUSE, 1) != 0) return 0;
165 int AudioVPE::unPause()
167 if (!initted) return 0;
169 // if (ioctl(fdAudio, AV_SET_AUD_UNPAUSE, 1) != 0) return 0;
173 int AudioVPE::reset()
175 if (!initted) return 0;
177 Log::getInstance()->log("Audio", Log::DEBUG, "reset called");
180 // if (ioctl(fdAudio, AV_SET_AUD_RESET, 0x11) != 0) return 0;
181 // Log::getInstance()->log("Audio", Log::DEBUG, "reset back");
182 // if (ioctl(fdAudio, AV_SET_AUD_PLAY, 0) != 0) return 0;
188 int AudioVPE::setVolume(int tvolume)
190 // parameter: 0 for silence, 20 for full
191 if ((tvolume < 0) || (tvolume > 20)) return 0;
193 // volume = 2 * (20 - volume);
194 // Right, that one was rubbish... 0-10 were almost
195 // inaudible, 11-20 did what should have been done
196 // over the whole 0-20 range
198 tvolume = 20 - tvolume;
200 audio_volume Avolume;
201 Avolume.frontleft = tvolume + Aoffset.frontleft;
202 Avolume.frontright = tvolume + Aoffset.frontright;
203 Avolume.rearleft = tvolume + Aoffset.rearleft;
204 Avolume.rearright = tvolume + Aoffset.rearright;
205 Avolume.center = tvolume + Aoffset.center;
206 Avolume.lfe = tvolume + Aoffset.lfe;
208 // if (ioctl(fdAudio, AV_SET_AUD_VOLUME, &Avolume) != 0) return 0;
210 // unsigned long vol = (tvolume << 24) | (tvolume << 16);
212 // Log::getInstance()->log("Audio", Log::DEBUG, "%lx", vol);
213 // Log::getInstance()->log("Audio", Log::DEBUG, "%i", tvolume);
215 // if (ioctl(fdAudio, AV_SET_AUD_VOLUME, &vol) != 0) return 0;
223 // return ioctl(fdAudio, AV_SET_AUD_STC, &stc);
225 /* aud_sync_parms_t a;
229 // int b = ioctl(fdAudio, AV_SET_AUD_DISABLE_SYNC, &a);
232 /*OK*/ //printf("Audio sync disable = %i\n", b);
240 void AudioVPE::PrepareMediaSample(const MediaPacketList& mplist,UINT samplepos)
242 packet = mplist.front();
245 UINT AudioVPE::DeliverMediaSample(UCHAR* buffer, UINT* samplepos)
247 VideoVPEOGL *video=(VideoVPEOGL*)Video::getInstance();
248 //Log::getInstance()->log("Audio", Log::DEBUG, "lastpacket %d lastbuddypacket %d currentpacket %d",lastpacketnum,video->getLastPacketNum(),packet.index);
249 currentpacketnum=packet.index;
250 if (lastpacketnum!=-1 && packet.index-1!=lastpacketnum && packet.index-1>video->getLastPacketNum()) return 0; //Not in order
253 switch (packet.type) {
254 case MPTYPE_MPEG_AUDIO:
255 buffer[packet.pos_buffer + 3]=0xc0; break;
257 buffer[packet.pos_buffer +buffer[packet.pos_buffer+8]+9]=0x80;
258 buffer[packet.pos_buffer + 3]=0xbd; break;
261 case MPTYPE_AC3_PRE13://Not tested no recording availiable
262 buffer[packet.pos_buffer + 3]=0xbd; break;
266 if (packet.type!=lastAType && lastpacketnum!=-1){//Format Change //Push data out !
267 video->deinitMuxer();
268 lastAType=packet.type;
271 lastAType=packet.type;
274 /* Mutex *mutex=video->getMuxMutex();
276 FILE *muxout=video->getMuxFile();
277 if (!muxout) {mutex->Unlock(); return 0;}*
279 //written=fwrite(buffer + packet.pos_buffer,1,packet.length,muxout);
280 written=video->WriteOutTS(buffer + packet.pos_buffer,packet.length,packet.type);
281 lastpacketnum=packet.index;
285 //Log::getInstance()->log("Audio", Log::DEBUG, "wrote %d bytes to mux",written);
287 if (written == (int)packet.length) { *samplepos = 0; return 1;}
291 *samplepos = written;*/
292 // Handle a partial write. Is this possible? Should we bother? No!
294 *samplepos=packet.length;
298 void AudioVPE::ResetTimeOffsets()