]> git.vomp.tv Git - vompclient.git/blob - audiomvp.cc
Display channel name, duration, resume point and size on recording info screen
[vompclient.git] / audiomvp.cc
1 /*
2     Copyright 2004-2005 Chris Tallon
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 "audiomvp.h"
22
23 #include "log.h"
24
25 AudioMVP::AudioMVP()
26 {
27   if (instance) return;
28   initted = 0;
29   fdAudio = 0;
30   streamType = 0;
31   volume = 20;
32   muted = 0;
33 }
34
35 AudioMVP::~AudioMVP()
36 {
37 }
38
39 int AudioMVP::init(UCHAR tstreamType)
40 {
41   if (initted) return 0;
42   initted = 1;
43
44 //  if ((fdAudio = open("/dev/adec_mpg", O_RDWR | O_NONBLOCK)) < 0) return 0;
45   if ((fdAudio = open("/dev/adec_mpg", O_WRONLY)) < 0) return 0;
46
47   streamType = tstreamType;
48
49   if (!initAllParams())
50   {
51     shutdown();
52     return 0;
53   }
54
55   unMute();
56
57   // Set the volume variable to what the hardware is set at now
58   int hwvol = -1;
59   int hwvolFail = ioctl(fdAudio, AV_GET_AUD_VOLUME, &hwvol);
60   if (!hwvolFail)
61   {
62     volume = 20 - ((hwvol >> 16) & 0xFF);
63     if ((volume < 0) || (volume > 20)) volume = 20;
64   }
65
66   return 1;
67 }
68
69 int AudioMVP::initAllParams()
70 {
71   return (setStreamType(streamType) && setChannel() && setSource());
72 }
73
74 int AudioMVP::shutdown()
75 {
76   if (!initted) return 0;
77   initted = 0;
78   close(fdAudio);
79   return 1;
80 }
81
82 int AudioMVP::setStreamType(UCHAR type)
83 {
84   if (!initted) return 0;
85
86   if (ioctl(fdAudio, AV_SET_AUD_STREAMTYPE, type) != 0) return 0;
87   return 1;
88 }
89
90 int AudioMVP::setChannel()
91 {
92   if (!initted) return 0;
93
94   if (ioctl(fdAudio, AV_SET_AUD_CHANNEL, 0) != 0) return 0;
95   return 1;
96 }
97
98 int AudioMVP::setSource()
99 {
100   if (!initted) return 0;
101
102   if (ioctl(fdAudio, AV_SET_AUD_SRC, 1) != 0) return 0;
103   return 1;
104 }
105
106 int AudioMVP::sync()
107 {
108   if (!initted) return 0;
109
110   if (ioctl(fdAudio, AV_SET_AUD_SYNC, 2) != 0) return 0;
111   return 1;
112 }
113
114 int AudioMVP::play()
115 {
116   if (!initted) return 0;
117
118   if (ioctl(fdAudio, AV_SET_AUD_PLAY, 0) != 0) return 0;
119   return 1;
120 }
121
122 int AudioMVP::stop()
123 {
124   if (!initted) return 0;
125
126   if (ioctl(fdAudio, AV_SET_AUD_RESET, 0x11) != 0) return 0;
127   return 1;
128 }
129
130 int AudioMVP::mute()
131 {
132   if (!initted) return 0;
133
134   if (ioctl(fdAudio, AV_SET_AUD_MUTE, 1) != 0) return 0;
135   Log::getInstance()->log("Audio", Log::DEBUG, "MUTE MUTE MUTE");
136
137   muted = 1;
138   return 1;
139 }
140
141 int AudioMVP::unMute()
142 {
143   if (!initted) return 0;
144
145   if (ioctl(fdAudio, AV_SET_AUD_MUTE, 0) != 0) return 0;
146   Log::getInstance()->log("Audio", Log::DEBUG, "MUTE OFF OFF OFF");
147
148   muted = 0;
149   return 1;
150 }
151
152 int AudioMVP::pause()
153 {
154   if (!initted) return 0;
155
156   if (ioctl(fdAudio, AV_SET_AUD_PAUSE, 1) != 0) return 0;
157   return 1;
158 }
159
160 int AudioMVP::unPause()
161 {
162   if (!initted) return 0;
163
164   if (ioctl(fdAudio, AV_SET_AUD_UNPAUSE, 1) != 0) return 0;
165   return 1;
166 }
167
168 int AudioMVP::reset()
169 {
170   if (!initted) return 0;
171 //test();
172   Log::getInstance()->log("Audio", Log::DEBUG, "reset called");
173   if (ioctl(fdAudio, AV_SET_AUD_RESET, 0x11) != 0) return 0;
174   Log::getInstance()->log("Audio", Log::DEBUG, "reset back");
175   if (ioctl(fdAudio, AV_SET_AUD_PLAY, 0) != 0) return 0;
176
177   doMuting();
178   return 1;
179 }
180
181 int AudioMVP::setVolume(int tvolume)
182 {
183   // parameter: 0 for silence, 20 for full
184   if ((tvolume < 0) || (tvolume > 20)) return 0;
185
186 // volume = 2 * (20 - volume);
187 // Right, that one was rubbish... 0-10 were almost
188 // inaudible, 11-20 did what should have been done
189 // over the whole 0-20 range
190
191   tvolume = 20 - tvolume;
192
193   audio_volume Avolume;
194   Avolume.frontleft = tvolume + Aoffset.frontleft;
195   Avolume.frontright = tvolume + Aoffset.frontright;
196   Avolume.rearleft = tvolume + Aoffset.rearleft;
197   Avolume.rearright = tvolume + Aoffset.rearright;
198   Avolume.center = tvolume + Aoffset.center;
199   Avolume.lfe = tvolume + Aoffset.lfe;
200
201   if (ioctl(fdAudio, AV_SET_AUD_VOLUME, &Avolume) != 0) return 0;
202
203 //  unsigned long vol = (tvolume << 24) | (tvolume << 16);
204 //
205 //  Log::getInstance()->log("Audio", Log::DEBUG, "%lx", vol);
206 //  Log::getInstance()->log("Audio", Log::DEBUG, "%i", tvolume);
207
208 //  if (ioctl(fdAudio, AV_SET_AUD_VOLUME, &vol) != 0) return 0;
209   return 1;
210 }
211
212 #ifdef DEV
213 int AudioMVP::test()
214 {
215 //  ULLONG stc = 0;
216 //  return ioctl(fdAudio, AV_SET_AUD_STC, &stc);
217
218   aud_sync_parms_t a;
219   a.parm1 = 0;
220   a.parm2 = 0;
221
222   int b = ioctl(fdAudio, AV_SET_AUD_DISABLE_SYNC, &a);
223
224
225   /*OK*/ printf("Audio sync disable = %i\n", b);
226
227   return 1;
228
229
230 }
231 #endif
232
233 void AudioMVP::PrepareMediaSample(const MediaPacketList& mplist,UINT samplepos)
234 {
235   packet = mplist.front();
236 }
237
238 UINT AudioMVP::DeliverMediaSample(UCHAR* buffer, UINT* samplepos)
239 {
240   int written = ::write(fdAudio, buffer + packet.pos_buffer + *samplepos,
241                                  packet.length - *samplepos);
242   if (written == (int)(packet.length - *samplepos)) {*samplepos = 0; return 1;}
243   if (written > 0) *samplepos += written;
244   return 0;
245 }
246
247 void AudioMVP::ResetTimeOffsets()
248 {
249 }