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"
33 lastAType = MPTYPE_MPEG_AUDIO;
40 int AudioVPE::init(UCHAR tstreamType)
42 if (initted) return 0;
45 // // if ((fdAudio = open("/dev/adec_mpg", O_RDWR | O_NONBLOCK)) < 0) return 0;
46 // if ((fdAudio = open("/dev/adec_mpg", O_WRONLY)) < 0) return 0;
48 streamType = tstreamType;
58 // Set the volume variable to what the hardware is set at now
60 /* int hwvolFail = ioctl(fdAudio, AV_GET_AUD_VOLUME, &hwvol);
63 volume = 20 - ((hwvol >> 16) & 0xFF);
64 if ((volume < 0) || (volume > 20)) volume = 20;
70 int AudioVPE::initAllParams()
72 return (setStreamType(streamType) && setChannel() && setSource());
75 int AudioVPE::shutdown()
77 if (!initted) return 0;
83 int AudioVPE::setStreamType(UCHAR type)
85 if (!initted) return 0;
87 // if (ioctl(fdAudio, AV_SET_AUD_STREAMTYPE, type) != 0) return 0;
91 int AudioVPE::setChannel()
93 if (!initted) return 0;
95 // if (ioctl(fdAudio, AV_SET_AUD_CHANNEL, 0) != 0) return 0;
99 int AudioVPE::setSource()
101 if (!initted) return 0;
103 // if (ioctl(fdAudio, AV_SET_AUD_SRC, 1) != 0) return 0;
109 if (!initted) return 0;
111 // if (ioctl(fdAudio, AV_SET_AUD_SYNC, 2) != 0) return 0;
117 if (!initted) return 0;
122 //if (ioctl(fdAudio, AV_SET_AUD_PLAY, 0) != 0) return 0;
128 if (!initted) return 0;
130 //if (ioctl(fdAudio, AV_SET_AUD_RESET, 0x11) != 0) return 0;
136 if (!initted) return 0;
138 // if (ioctl(fdAudio, AV_SET_AUD_MUTE, 1) != 0) return 0;
139 Log::getInstance()->log("Audio", Log::DEBUG, "MUTE MUTE MUTE");
145 int AudioVPE::unMute()
147 if (!initted) return 0;
149 // if (ioctl(fdAudio, AV_SET_AUD_MUTE, 0) != 0) return 0;
150 Log::getInstance()->log("Audio", Log::DEBUG, "MUTE OFF OFF OFF");
156 int AudioVPE::pause()
158 if (!initted) return 0;
160 // if (ioctl(fdAudio, AV_SET_AUD_PAUSE, 1) != 0) return 0;
164 int AudioVPE::unPause()
166 if (!initted) return 0;
168 // if (ioctl(fdAudio, AV_SET_AUD_UNPAUSE, 1) != 0) return 0;
172 int AudioVPE::reset()
174 if (!initted) return 0;
176 Log::getInstance()->log("Audio", Log::DEBUG, "reset called");
179 // if (ioctl(fdAudio, AV_SET_AUD_RESET, 0x11) != 0) return 0;
180 // Log::getInstance()->log("Audio", Log::DEBUG, "reset back");
181 // if (ioctl(fdAudio, AV_SET_AUD_PLAY, 0) != 0) return 0;
187 int AudioVPE::setVolume(int tvolume)
189 // parameter: 0 for silence, 20 for full
190 if ((tvolume < 0) || (tvolume > 20)) return 0;
192 // volume = 2 * (20 - volume);
193 // Right, that one was rubbish... 0-10 were almost
194 // inaudible, 11-20 did what should have been done
195 // over the whole 0-20 range
197 tvolume = 20 - tvolume;
199 audio_volume Avolume;
200 Avolume.frontleft = tvolume + Aoffset.frontleft;
201 Avolume.frontright = tvolume + Aoffset.frontright;
202 Avolume.rearleft = tvolume + Aoffset.rearleft;
203 Avolume.rearright = tvolume + Aoffset.rearright;
204 Avolume.center = tvolume + Aoffset.center;
205 Avolume.lfe = tvolume + Aoffset.lfe;
207 // if (ioctl(fdAudio, AV_SET_AUD_VOLUME, &Avolume) != 0) return 0;
209 // unsigned long vol = (tvolume << 24) | (tvolume << 16);
211 // Log::getInstance()->log("Audio", Log::DEBUG, "%lx", vol);
212 // Log::getInstance()->log("Audio", Log::DEBUG, "%i", tvolume);
214 // if (ioctl(fdAudio, AV_SET_AUD_VOLUME, &vol) != 0) return 0;
222 // return ioctl(fdAudio, AV_SET_AUD_STC, &stc);
224 /* aud_sync_parms_t a;
228 // int b = ioctl(fdAudio, AV_SET_AUD_DISABLE_SYNC, &a);
231 /*OK*/ //printf("Audio sync disable = %i\n", b);
239 void AudioVPE::PrepareMediaSample(const MediaPacketList& mplist,UINT samplepos)
241 packet = mplist.front();
244 UINT AudioVPE::DeliverMediaSample(UCHAR* buffer, UINT* samplepos)
246 VideoVPEOGL *video=(VideoVPEOGL*)Video::getInstance();
247 //Log::getInstance()->log("Audio", Log::DEBUG, "lastpacket %d lastbuddypacket %d currentpacket %d",lastpacketnum,video->getLastPacketNum(),packet.index);
248 currentpacketnum=packet.index;
249 if (lastpacketnum!=-1 && packet.index-1!=lastpacketnum && packet.index-1>video->getLastPacketNum()) return 0; //Not in order
252 switch (packet.type) {
253 case MPTYPE_MPEG_AUDIO:
254 buffer[packet.pos_buffer + 3]=0xc0; break;
256 buffer[packet.pos_buffer +buffer[packet.pos_buffer+8]+9]=0x80;
257 buffer[packet.pos_buffer + 3]=0xbd; break;
260 case MPTYPE_AC3_PRE13://Not tested no recording availiable
261 buffer[packet.pos_buffer + 3]=0xbd; break;
265 if (packet.type!=lastAType && lastpacketnum!=-1){//Format Change //Push data out !
266 video->deinitMuxer();
267 lastAType=packet.type;
270 lastAType=packet.type;
273 /* Mutex *mutex=video->getMuxMutex();
275 FILE *muxout=video->getMuxFile();
276 if (!muxout) {mutex->Unlock(); return 0;}*
278 //written=fwrite(buffer + packet.pos_buffer,1,packet.length,muxout);
279 written=video->WriteOutTS(buffer + packet.pos_buffer,packet.length,packet.type);
280 lastpacketnum=packet.index;
284 //Log::getInstance()->log("Audio", Log::DEBUG, "wrote %d bytes to mux",written);
286 if (written == (int)packet.length) { *samplepos = 0; return 1;}
290 *samplepos = written;*/
291 // Handle a partial write. Is this possible? Should we bother? No!
293 *samplepos=packet.length;
297 void AudioVPE::ResetTimeOffsets()