]> git.vomp.tv Git - vompclient.git/blob - audiowin.cc
New options screen system, new remote control handling, and all other
[vompclient.git] / audiowin.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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19 */
20
21 #include "audiowin.h"
22 #include "videowin.h"
23
24
25
26
27 AudioWin::AudioWin()
28 {
29   initted = 0;
30   firstsynched=false;
31   winvolume=0;
32   volume=20;
33
34
35
36 }
37
38 AudioWin::~AudioWin()
39 {
40
41 }
42
43 int AudioWin::init(UCHAR tstreamType)
44 {
45   if (initted) return 0;
46   initted = 1;
47   return 1;
48 }
49
50 int AudioWin::shutdown()
51 {
52   if (!initted) return 0;
53   initted = 0;
54   return 1;
55 }
56
57 int AudioWin::write(char *buf, int len)
58 {
59   return 0; //write(fdAudio, buf, len);
60 }
61
62 int AudioWin::setStreamType(UCHAR type)
63 {
64   if (!initted) return 0;
65   return 1;
66 }
67
68 int AudioWin::setChannel()
69 {
70   if (!initted) return 0;
71   return 1;
72 }
73
74 int AudioWin::setSource()
75 {
76   if (!initted) return 0;
77   return 1;
78 }
79
80 int AudioWin::sync()
81 {
82   if (!initted) return 0;
83   return 1;
84 }
85
86 int AudioWin::play()
87 {
88   if (!initted) return 0;
89   firstsynched=false;
90   return ((VideoWin*)Video::getInstance())->dsplay();
91
92 }
93
94 int AudioWin::stop()
95 {
96   if (!initted) return 0;
97   return ((VideoWin*)Video::getInstance())->dsstop();
98 }
99
100 int AudioWin::pause()
101 {
102   if (!initted) return 0;
103   return ((VideoWin*)Video::getInstance())->dspause();
104 }
105
106 int AudioWin::unPause()
107 {
108   if (!initted) return 0;
109   return ((VideoWin*)Video::getInstance())->dsunPause();
110 }
111
112 int AudioWin::reset()
113 {
114   
115   if (!initted){return 0;}
116   return ((VideoWin*)Video::getInstance())->dsreset();
117 }
118
119 int AudioWin::setVolume(int tvolume)
120 {
121   // parameter: 0 for silence, 20 for full
122   if ((tvolume < 0) || (tvolume > 20)) return 0;
123   winvolume=((tvolume-20)*100*30)/20;
124   if (tvolume==0) winvolume=-10000;
125   ((VideoWin*)Video::getInstance())->SetAudioVolume(winvolume);
126
127
128   return 1;
129 }
130
131 int AudioWin::mute()
132 {
133   if (!initted) return 0;
134   ((VideoWin*)Video::getInstance())->SetAudioState(false);
135   ((VideoWin*)Video::getInstance())->SetAudioVolume(-10000);
136   return 1;
137 }
138
139 int AudioWin::unMute()
140 {
141   if (!initted) return 0;
142   ((VideoWin*)Video::getInstance())->SetAudioState(true);
143   ((VideoWin*)Video::getInstance())->SetAudioVolume(winvolume);
144   return 1;
145 }
146
147 void AudioWin::PrepareMediaSample(const MediaPacketList& mplist,UINT samplepos)
148 {
149   mediapacket = mplist.front();
150 }
151
152 UINT AudioWin::DeliverMediaSample(const UCHAR* buffer, UINT *samplepos)
153 {
154   DeliverMediaPacket(mediapacket, buffer, samplepos);
155   if (*samplepos == mediapacket.length) {
156     *samplepos = 0;
157     return 1;
158   }
159   else return 0;
160 }
161
162 UINT AudioWin::DeliverMediaPacket(MediaPacket packet,
163      const UCHAR* buffer,
164      UINT *samplepos)
165 {
166
167   /*First Check, if we have an audio sample*/
168   VideoWin *vw=(VideoWin*)Video::getInstance();
169  if (!vw->isdsinited()) return 0;
170   if (vw->InIframemode()) {
171                 samplepos=0;
172                 MILLISLEEP(10);
173                 return 0; //Not in iframe mode!
174   }
175   IMediaSample* ms=NULL;
176   REFERENCE_TIME reftime1=0;
177   REFERENCE_TIME reftime2=0;
178
179   UINT headerstrip=0;
180   if (packet.disconti) {
181     firstsynched=false;
182     vw->DeliverAudioMediaSample();
183   }
184
185   if (packet.type!=vw->lastAType()){//Format Change //Push data out !
186       firstsynched=false;
187       vw->DeliverAudioMediaSample();
188   }
189
190
191
192   /*Inspect PES-Header */
193 /*  UINT header_length=buffer[(packet.pos_buffer+8)%bufferlength]+8/*is this right*;
194 */
195   if (*samplepos==0) {//stripheader
196     headerstrip=buffer[packet.pos_buffer+8]+9/*is this right*/;
197     if (packet.type == MPTYPE_AC3) headerstrip+=4; //skip ac3 bytes
198     *samplepos+=headerstrip;
199     if ( packet.synched ) {
200       vw->DeliverAudioMediaSample();//write out old data
201    /*   if (packet.presentation_time<0) { //Preroll?
202         *samplepos=packet.length;//if we have not processed at least one
203         return packet.length;//synched packet ignore it!
204       }*/
205
206       reftime1=packet.presentation_time;
207       reftime2=reftime1+1;
208       firstsynched=true;
209     } else {
210       if (!firstsynched) {//
211         *samplepos=packet.length;//if we have not processed at least one
212         
213         return packet.length;//synched packet ignore it!
214       }
215     }
216   }
217   BYTE *ms_buf;
218   UINT ms_length;
219   UINT ms_pos;
220   UINT haveToCopy;
221   if (!vw->getCurrentAudioMediaSample(&ms) || ms==NULL) {// get the current sample
222     //samplepos=0;
223     MILLISLEEP(10);
224     return *samplepos;
225   }
226   ms_pos=ms->GetActualDataLength();
227   ms_length=ms->GetSize();
228   haveToCopy=min(ms_length-ms_pos,packet.length-*samplepos);
229   if ((ms_length-ms_pos)<1) {
230     vw->DeliverAudioMediaSample(); //we are full!
231     if (!vw->getCurrentAudioMediaSample(&ms) || ms==NULL) {// get the current sample
232       //samplepos=0;
233       MILLISLEEP(10);
234       return *samplepos;
235     }
236     ms_pos=ms->GetActualDataLength();
237     ms_length=ms->GetSize();
238     haveToCopy=min(ms_length-ms_pos,packet.length-*samplepos);
239   }
240   ms->GetPointer(&ms_buf);
241
242
243   if (ms_pos==0) {//will only be changed on first packet
244     if (packet.disconti) {
245       ms->SetDiscontinuity(TRUE);
246     } else {
247       ms->SetDiscontinuity(FALSE);
248     }
249     if (packet.synched) {
250       ms->SetSyncPoint(TRUE);
251       ms->SetTime(&reftime1,&reftime2);
252
253       //ms->SetTime(NULL,NULL);
254       ms->SetMediaTime(NULL, NULL);
255     if (reftime1<0) ms->SetPreroll(TRUE);
256     else ms->SetPreroll(FALSE);
257     }else {
258       ms->SetSyncPoint(FALSE);
259       ms->SetTime(NULL,NULL);
260       ms->SetMediaTime(NULL, NULL);
261     ms->SetPreroll(FALSE);
262     //  ms->SetSyncPoint(TRUE);
263     }
264   }
265   if (packet.type!=vw->lastAType()) {
266       vw->changeAType(packet.type,ms);
267       ms->SetDiscontinuity(TRUE);
268   }
269
270
271   memcpy(ms_buf+ms_pos,buffer+packet.pos_buffer+*samplepos,haveToCopy);
272
273     ms->SetActualDataLength(haveToCopy+ms_pos);
274
275   *samplepos+=haveToCopy;
276
277   return haveToCopy+headerstrip;
278
279 }
280
281 long long AudioWin::SetStartOffset(long long curreftime, bool *rsync){
282   VideoWin *vw=(VideoWin*)Video::getInstance();
283   return vw->SetStartAudioOffset(curreftime,rsync);
284 }
285
286 void AudioWin::ResetTimeOffsets() {
287   VideoWin *vw=(VideoWin*)Video::getInstance();
288   return vw->ResetTimeOffsets();
289 }
290
291 bool AudioWin::supportsAc3(){
292     VideoWin *vw=(VideoWin*)Video::getInstance();
293     return vw->supportsAc3();
294 }
295
296 #ifdef DEV
297 int AudioWin::test()
298 {
299   return 0;
300 }
301 #endif
302
303
304