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