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