]> git.vomp.tv Git - vompclient.git/blob - audiowin.cc
Update for windows
[vompclient.git] / audiowin.cc
1 /*\r
2     Copyright 2004-2005 Chris Tallon\r
3 \r
4     This file is part of VOMP.\r
5 \r
6     VOMP is free software; you can redistribute it and/or modify\r
7     it under the terms of the GNU General Public License as published by\r
8     the Free Software Foundation; either version 2 of the License, or\r
9     (at your option) any later version.\r
10 \r
11     VOMP is distributed in the hope that it will be useful,\r
12     but WITHOUT ANY WARRANTY; without even the implied warranty of\r
13     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
14     GNU General Public License for more details.\r
15 \r
16     You should have received a copy of the GNU General Public License\r
17     along with VOMP; if not, write to the Free Software\r
18     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA\r
19 */\r
20 \r
21 #include "audiowin.h"\r
22 #include "videowin.h"\r
23 \r
24 \r
25 \r
26 \r
27 \r
28 AudioWin::AudioWin()\r
29 {\r
30   initted = 0;\r
31   firstsynched=false;\r
32   winvolume=0;\r
33   volume=20;\r
34 \r
35 \r
36 \r
37 }\r
38 \r
39 AudioWin::~AudioWin()\r
40 {\r
41 \r
42 \r
43 }\r
44 \r
45 int AudioWin::init(UCHAR tstreamType)\r
46 {\r
47   if (initted) return 0;\r
48   initted = 1;\r
49   return 1;\r
50 }\r
51 \r
52 int AudioWin::shutdown()\r
53 {\r
54   if (!initted) return 0;\r
55   initted = 0;\r
56   return 1;\r
57 }\r
58 \r
59 int AudioWin::write(char *buf, int len)\r
60 {\r
61   return 0; //write(fdAudio, buf, len);\r
62 }\r
63 \r
64 int AudioWin::setStreamType(UCHAR type)\r
65 {\r
66   if (!initted) return 0;\r
67   return 1;\r
68 }\r
69 \r
70 int AudioWin::setChannel()\r
71 {\r
72   if (!initted) return 0;\r
73   return 1;\r
74 }\r
75 \r
76 int AudioWin::setSource()\r
77 {\r
78   if (!initted) return 0;\r
79   return 1;\r
80 }\r
81 \r
82 int AudioWin::sync()\r
83 {\r
84   if (!initted) return 0;\r
85   return 1;\r
86 }\r
87 \r
88 int AudioWin::play()\r
89 {\r
90   if (!initted) return 0;\r
91   firstsynched=false;\r
92   return ((VideoWin*)Video::getInstance())->dsplay();\r
93 \r
94 }\r
95 \r
96 int AudioWin::stop()\r
97 {\r
98   if (!initted) return 0;\r
99   return ((VideoWin*)Video::getInstance())->dsstop();\r
100 }\r
101 \r
102 int AudioWin::pause()\r
103 {\r
104   if (!initted) return 0;\r
105   return ((VideoWin*)Video::getInstance())->dspause();\r
106 }\r
107 \r
108 int AudioWin::unPause()\r
109 {\r
110   if (!initted) return 0;\r
111   return ((VideoWin*)Video::getInstance())->dsunPause();\r
112 }\r
113 \r
114 int AudioWin::reset()\r
115 {\r
116   \r
117   if (!initted){return 0;}\r
118   return ((VideoWin*)Video::getInstance())->dsreset();\r
119 }\r
120 \r
121 int AudioWin::setVolume(int tvolume)\r
122 {\r
123   // parameter: 0 for silence, 20 for full\r
124   if ((tvolume < 0) || (tvolume > 20)) return 0;\r
125   winvolume=((tvolume-20)*100*30)/20;\r
126   if (tvolume==0) winvolume=-10000;\r
127   ((VideoWin*)Video::getInstance())->SetAudioVolume(winvolume);\r
128 \r
129 \r
130   return 1;\r
131 }\r
132 \r
133 int AudioWin::mute()\r
134 {\r
135   if (!initted) return 0;\r
136   ((VideoWin*)Video::getInstance())->SetAudioState(false);\r
137   ((VideoWin*)Video::getInstance())->SetAudioVolume(-10000);\r
138   return 1;\r
139 }\r
140 \r
141 int AudioWin::unMute()\r
142 {\r
143   if (!initted) return 0;\r
144   ((VideoWin*)Video::getInstance())->SetAudioState(true);\r
145   ((VideoWin*)Video::getInstance())->SetAudioVolume(winvolume);\r
146   return 1;\r
147 }\r
148 \r
149 void AudioWin::PrepareMediaSample(const MediaPacketList& mplist,UINT samplepos)\r
150 {\r
151   mediapacket = mplist.front();\r
152 }\r
153 \r
154 UINT AudioWin::DeliverMediaSample(const UCHAR* buffer, UINT *samplepos)\r
155 {\r
156   DeliverMediaPacket(mediapacket, buffer, samplepos);\r
157   if (*samplepos == mediapacket.length) {\r
158     *samplepos = 0;\r
159     return 1;\r
160   }\r
161   else return 0;\r
162 }\r
163 \r
164 UINT AudioWin::DeliverMediaPacket(MediaPacket packet,\r
165      const UCHAR* buffer,\r
166      UINT *samplepos)\r
167 {\r
168 \r
169   /*First Check, if we have an audio sample*/\r
170   VideoWin *vw=(VideoWin*)Video::getInstance();\r
171   if (vw->InIframemode()) {\r
172                 samplepos=0;\r
173                 MILLISLEEP(10);\r
174                 return 0; //Not in iframe mode!\r
175   }\r
176   IMediaSample* ms=NULL;\r
177   REFERENCE_TIME reftime1=0;\r
178   REFERENCE_TIME reftime2=0;\r
179 \r
180   UINT headerstrip=0;\r
181   if (packet.disconti) {\r
182     firstsynched=false;\r
183     vw->DeliverVideoMediaSample();\r
184   }\r
185 \r
186 \r
187 \r
188   /*Inspect PES-Header */\r
189 /*  UINT header_length=buffer[(packet.pos_buffer+8)%bufferlength]+8/*is this right*;\r
190 */\r
191   if (*samplepos==0) {//stripheader\r
192     headerstrip=buffer[packet.pos_buffer+8]+9/*is this right*/;\r
193     *samplepos+=headerstrip;\r
194     if ( packet.synched ) {\r
195       vw->DeliverAudioMediaSample();//write out old data\r
196    /*   if (packet.presentation_time<0) { //Preroll?\r
197         *samplepos=packet.length;//if we have not processed at least one\r
198         return packet.length;//synched packet ignore it!\r
199       }*/\r
200 \r
201       reftime1=packet.presentation_time;\r
202       reftime2=reftime1+1;\r
203       firstsynched=true;\r
204     } else {\r
205       if (!firstsynched) {//\r
206         *samplepos=packet.length;//if we have not processed at least one\r
207         \r
208         return packet.length;//synched packet ignore it!\r
209       }\r
210     }\r
211   }\r
212   BYTE *ms_buf;\r
213   UINT ms_length;\r
214   UINT ms_pos;\r
215   UINT haveToCopy;\r
216   if (!vw->getCurrentAudioMediaSample(&ms) || ms==NULL) {// get the current sample\r
217     //samplepos=0;\r
218     MILLISLEEP(10);\r
219     return *samplepos;\r
220   }\r
221   ms_pos=ms->GetActualDataLength();\r
222   ms_length=ms->GetSize();\r
223   haveToCopy=min(ms_length-ms_pos,packet.length-*samplepos);\r
224   if ((ms_length-ms_pos)<1) {\r
225     vw->DeliverAudioMediaSample(); //we are full!\r
226     if (!vw->getCurrentAudioMediaSample(&ms) || ms==NULL) {// get the current sample\r
227       //samplepos=0;\r
228       MILLISLEEP(10);\r
229       return *samplepos;\r
230     }\r
231     ms_pos=ms->GetActualDataLength();\r
232     ms_length=ms->GetSize();\r
233     haveToCopy=min(ms_length-ms_pos,packet.length-*samplepos);\r
234   }\r
235   ms->GetPointer(&ms_buf);\r
236 \r
237   if (ms_pos==0) {//will only be changed on first packet\r
238     if (packet.disconti) {\r
239       ms->SetDiscontinuity(TRUE);\r
240     } else {\r
241       ms->SetDiscontinuity(FALSE);\r
242     }\r
243     if (packet.synched) {\r
244       ms->SetSyncPoint(TRUE);\r
245       ms->SetTime(&reftime1,&reftime2);\r
246 \r
247       //ms->SetTime(NULL,NULL);\r
248       ms->SetMediaTime(NULL, NULL);\r
249     if (reftime1<0) ms->SetPreroll(TRUE);\r
250     else ms->SetPreroll(FALSE);\r
251     }else {\r
252       ms->SetSyncPoint(FALSE);\r
253       ms->SetTime(NULL,NULL);\r
254       ms->SetMediaTime(NULL, NULL);\r
255     ms->SetPreroll(FALSE);\r
256      MessageBox(0,"here I'm","Hallo",0);\r
257     //  ms->SetSyncPoint(TRUE);\r
258     }\r
259   }\r
260 \r
261 \r
262   memcpy(ms_buf+ms_pos,buffer+packet.pos_buffer+*samplepos,haveToCopy);\r
263     ms->SetActualDataLength(haveToCopy+ms_pos);\r
264 \r
265   *samplepos+=haveToCopy;\r
266 \r
267   return haveToCopy+headerstrip;\r
268 \r
269 }\r
270 \r
271 long long AudioWin::SetStartOffset(long long curreftime, bool *rsync){\r
272   VideoWin *vw=(VideoWin*)Video::getInstance();\r
273   return vw->SetStartAudioOffset(curreftime,rsync);\r
274 }\r
275 \r
276 void AudioWin::ResetTimeOffsets() {\r
277   VideoWin *vw=(VideoWin*)Video::getInstance();\r
278   return vw->ResetTimeOffsets();\r
279 }\r
280 \r
281 #ifdef DEV\r
282 int AudioWin::test()\r
283 {\r
284   return 0;\r
285 }\r
286 #endif\r
287 \r
288 \r