]> git.vomp.tv Git - vompclient-marten.git/blob - audiovpe.cc
Last shader saves
[vompclient-marten.git] / audiovpe.cc
1 /*
2     Copyright 2004-2005 Chris Tallon, 2009 Marten Richter
3
4     This file is part of VOMP.
5
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.
10
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.
15
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.
19 */
20
21 #include "audiovpe.h"
22 #include "videovpeogl.h"
23 #include "log.h"
24
25 AudioVPE::AudioVPE()
26 {
27   initted = 0;
28   lastpacketnum=-1;
29   currentpacketnum=-1;
30   streamType = 0;
31   volume = 20;
32   muted = 0;
33   lastAType = MPTYPE_MPEG_AUDIO;
34 }
35
36 AudioVPE::~AudioVPE()
37 {
38 }
39
40 int AudioVPE::init(UCHAR tstreamType)
41 {
42   if (initted) return 0;
43   initted = 1;
44
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;
47
48   streamType = tstreamType;
49
50   if (!initAllParams())
51   {
52     shutdown();
53     return 0;
54   }
55
56   unMute();
57
58   // Set the volume variable to what the hardware is set at now
59   int hwvol = -1;
60 /*  int hwvolFail = ioctl(fdAudio, AV_GET_AUD_VOLUME, &hwvol);
61   if (!hwvolFail)
62   {
63     volume = 20 - ((hwvol >> 16) & 0xFF);
64     if ((volume < 0) || (volume > 20)) volume = 20;
65   }*/
66
67   return 1;
68 }
69
70 int AudioVPE::initAllParams()
71 {
72   return (setStreamType(streamType) && setChannel() && setSource());
73 }
74
75 int AudioVPE::shutdown()
76 {
77   if (!initted) return 0;
78   initted = 0;
79   //close(fdAudio);
80   return 1;
81 }
82
83 int AudioVPE::setStreamType(UCHAR type)
84 {
85   if (!initted) return 0;
86
87  // if (ioctl(fdAudio, AV_SET_AUD_STREAMTYPE, type) != 0) return 0;
88   return 1;
89 }
90
91 int AudioVPE::setChannel()
92 {
93   if (!initted) return 0;
94
95  // if (ioctl(fdAudio, AV_SET_AUD_CHANNEL, 0) != 0) return 0;
96   return 1;
97 }
98
99 int AudioVPE::setSource()
100 {
101   if (!initted) return 0;
102
103  // if (ioctl(fdAudio, AV_SET_AUD_SRC, 1) != 0) return 0;
104   return 1;
105 }
106
107 int AudioVPE::sync()
108 {
109   if (!initted) return 0;
110
111  // if (ioctl(fdAudio, AV_SET_AUD_SYNC, 2) != 0) return 0;
112   return 1;
113 }
114
115 int AudioVPE::play()
116 {
117   if (!initted) return 0;
118   lastpacketnum=-1;
119   currentpacketnum=-1;
120
121
122   //if (ioctl(fdAudio, AV_SET_AUD_PLAY, 0) != 0) return 0;
123   return 1;
124 }
125
126 int AudioVPE::stop()
127 {
128   if (!initted) return 0;
129
130   //if (ioctl(fdAudio, AV_SET_AUD_RESET, 0x11) != 0) return 0;
131   return 1;
132 }
133
134 int AudioVPE::mute()
135 {
136   if (!initted) return 0;
137
138 //  if (ioctl(fdAudio, AV_SET_AUD_MUTE, 1) != 0) return 0;
139   Log::getInstance()->log("Audio", Log::DEBUG, "MUTE MUTE MUTE");
140
141   muted = 1;
142   return 1;
143 }
144
145 int AudioVPE::unMute()
146 {
147   if (!initted) return 0;
148
149 //  if (ioctl(fdAudio, AV_SET_AUD_MUTE, 0) != 0) return 0;
150   Log::getInstance()->log("Audio", Log::DEBUG, "MUTE OFF OFF OFF");
151
152   muted = 0;
153   return 1;
154 }
155
156 int AudioVPE::pause()
157 {
158   if (!initted) return 0;
159
160  // if (ioctl(fdAudio, AV_SET_AUD_PAUSE, 1) != 0) return 0;
161   return 1;
162 }
163
164 int AudioVPE::unPause()
165 {
166   if (!initted) return 0;
167
168  // if (ioctl(fdAudio, AV_SET_AUD_UNPAUSE, 1) != 0) return 0;
169   return 1;
170 }
171
172 int AudioVPE::reset()
173 {
174   if (!initted) return 0;
175 //test();
176   Log::getInstance()->log("Audio", Log::DEBUG, "reset called");
177
178
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;
182
183   doMuting();
184   return 1;
185 }
186
187 int AudioVPE::setVolume(int tvolume)
188 {
189   // parameter: 0 for silence, 20 for full
190   if ((tvolume < 0) || (tvolume > 20)) return 0;
191
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
196
197   tvolume = 20 - tvolume;
198
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;
206
207 //  if (ioctl(fdAudio, AV_SET_AUD_VOLUME, &Avolume) != 0) return 0;
208
209 //  unsigned long vol = (tvolume << 24) | (tvolume << 16);
210 //
211 //  Log::getInstance()->log("Audio", Log::DEBUG, "%lx", vol);
212 //  Log::getInstance()->log("Audio", Log::DEBUG, "%i", tvolume);
213
214 //  if (ioctl(fdAudio, AV_SET_AUD_VOLUME, &vol) != 0) return 0;
215   return 1;
216 }
217
218 #ifdef DEV
219 int AudioVPE::test()
220 {
221 //  ULLONG stc = 0;
222 //  return ioctl(fdAudio, AV_SET_AUD_STC, &stc);
223
224 /*  aud_sync_parms_t a;
225   a.parm1 = 0;
226   a.parm2 = 0;
227 */
228 //  int b = ioctl(fdAudio, AV_SET_AUD_DISABLE_SYNC, &a);
229
230
231   /*OK*/ //printf("Audio sync disable = %i\n", b);
232
233   return 1;
234
235
236 }
237 #endif
238
239 void AudioVPE::PrepareMediaSample(const MediaPacketList& mplist,UINT samplepos)
240 {
241   packet = mplist.front();
242 }
243
244 UINT AudioVPE::DeliverMediaSample(UCHAR* buffer, UINT* samplepos)
245 {/*
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
250
251   //format pes
252   switch (packet.type) {
253           case MPTYPE_MPEG_AUDIO:
254                  buffer[packet.pos_buffer + 3]=0xc0; break;
255           case MPTYPE_AC3:
256                   buffer[packet.pos_buffer +buffer[packet.pos_buffer+8]+9]=0x80;
257                   buffer[packet.pos_buffer + 3]=0xbd; break;
258                   break;
259           default:
260           case MPTYPE_AC3_PRE13://Not tested no recording availiable
261                   buffer[packet.pos_buffer + 3]=0xbd; break;
262                   break;
263   };
264
265    if (packet.type!=lastAType && lastpacketnum!=-1){//Format Change //Push data out !
266       video->deinitMuxer();
267           lastAType=packet.type;
268           video->initMuxer();
269   }
270   lastAType=packet.type;
271
272
273  /* Mutex *mutex=video->getMuxMutex();
274   mutex->Lock();
275   FILE *muxout=video->getMuxFile();
276   if (!muxout) {mutex->Unlock(); return 0;}*
277   int written=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;
281   
282   //mutex->Unlock();
283
284    //Log::getInstance()->log("Audio", Log::DEBUG, "wrote %d bytes to mux",written);
285   
286   if (written == (int)packet.length) { *samplepos = 0; return 1;}
287   if (written <= 0) {
288           return 0;
289   }
290   *samplepos = written;*/
291   // Handle a partial write. Is this possible? Should we bother? No!
292  
293   *samplepos=packet.length;
294   return 1;
295 }
296
297 void AudioVPE::ResetTimeOffsets()
298 {
299 }