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