2 Copyright 2004-2005 Chris Tallon
\r
4 This file is part of VOMP.
\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
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
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
21 #include "audiowin.h"
\r
22 #include "videowin.h"
\r
28 AudioWin::AudioWin()
\r
39 AudioWin::~AudioWin()
\r
45 int AudioWin::init(UCHAR tstreamType)
\r
47 if (initted) return 0;
\r
52 int AudioWin::shutdown()
\r
54 if (!initted) return 0;
\r
59 int AudioWin::write(char *buf, int len)
\r
61 return 0; //write(fdAudio, buf, len);
\r
64 int AudioWin::setStreamType(UCHAR type)
\r
66 if (!initted) return 0;
\r
70 int AudioWin::setChannel()
\r
72 if (!initted) return 0;
\r
76 int AudioWin::setSource()
\r
78 if (!initted) return 0;
\r
82 int AudioWin::sync()
\r
84 if (!initted) return 0;
\r
88 int AudioWin::play()
\r
90 if (!initted) return 0;
\r
92 return ((VideoWin*)Video::getInstance())->dsplay();
\r
96 int AudioWin::stop()
\r
98 if (!initted) return 0;
\r
99 return ((VideoWin*)Video::getInstance())->dsstop();
\r
102 int AudioWin::pause()
\r
104 if (!initted) return 0;
\r
105 return ((VideoWin*)Video::getInstance())->dspause();
\r
108 int AudioWin::unPause()
\r
110 if (!initted) return 0;
\r
111 return ((VideoWin*)Video::getInstance())->dsunPause();
\r
114 int AudioWin::reset()
\r
116 if (!initted) return 0;
\r
117 return ((VideoWin*)Video::getInstance())->dsreset();
\r
120 int AudioWin::setVolume(int tvolume)
\r
122 // parameter: 0 for silence, 20 for full
\r
123 if ((tvolume < 0) || (tvolume > 20)) return 0;
\r
124 winvolume=((tvolume-20)*100*30)/20;
\r
125 if (tvolume==0) winvolume=-10000;
\r
126 ((VideoWin*)Video::getInstance())->SetAudioVolume(winvolume);
\r
132 int AudioWin::mute()
\r
134 if (!initted) return 0;
\r
135 ((VideoWin*)Video::getInstance())->SetAudioState(false);
\r
136 ((VideoWin*)Video::getInstance())->SetAudioVolume(-10000);
\r
140 int AudioWin::unMute()
\r
142 if (!initted) return 0;
\r
143 ((VideoWin*)Video::getInstance())->SetAudioState(true);
\r
144 ((VideoWin*)Video::getInstance())->SetAudioVolume(winvolume);
\r
148 void AudioWin::PrepareMediaSample(const MediaPacketList& mplist,UINT samplepos)
\r
150 mediapacket = mplist.front();
\r
153 UINT AudioWin::DeliverMediaSample(const UCHAR* buffer, UINT *samplepos)
\r
155 DeliverMediaPacket(mediapacket, buffer, samplepos);
\r
156 if (*samplepos == mediapacket.length) {
\r
163 UINT AudioWin::DeliverMediaPacket(MediaPacket packet,
\r
164 const UCHAR* buffer,
\r
167 /*First Check, if we have an audio sample*/
\r
168 VideoWin *vw=(VideoWin*)Video::getInstance();
\r
169 IMediaSample* ms=NULL;
\r
170 REFERENCE_TIME reftime1=0;
\r
171 REFERENCE_TIME reftime2=0;
\r
173 UINT headerstrip=0;
\r
174 if (packet.disconti) {
\r
175 firstsynched=false;
\r
176 vw->DeliverVideoMediaSample();
\r
181 /*Inspect PES-Header */
\r
182 /* UINT header_length=buffer[(packet.pos_buffer+8)%bufferlength]+8/*is this right*;
\r
184 if (*samplepos==0) {//stripheader
\r
185 headerstrip=buffer[packet.pos_buffer+8]+9/*is this right*/;
\r
186 *samplepos+=headerstrip;
\r
187 if ( packet.synched ) {
\r
188 vw->DeliverAudioMediaSample();//write out old data
\r
189 /* if (packet.presentation_time<0) { //Preroll?
\r
190 *samplepos=packet.length;//if we have not processed at least one
\r
191 return packet.length;//synched packet ignore it!
\r
194 reftime1=packet.presentation_time;
\r
195 reftime2=reftime1+1;
\r
198 if (!firstsynched) {//
\r
199 *samplepos=packet.length;//if we have not processed at least one
\r
200 return packet.length;//synched packet ignore it!
\r
208 if (!vw->getCurrentAudioMediaSample(&ms) || ms==NULL) {// get the current sample
\r
213 ms_pos=ms->GetActualDataLength();
\r
214 ms_length=ms->GetSize();
\r
215 haveToCopy=min(ms_length-ms_pos,packet.length-*samplepos);
\r
216 if ((ms_length-ms_pos)<1) {
\r
217 vw->DeliverAudioMediaSample(); //we are full!
\r
218 if (!vw->getCurrentAudioMediaSample(&ms) || ms==NULL) {// get the current sample
\r
223 ms_pos=ms->GetActualDataLength();
\r
224 ms_length=ms->GetSize();
\r
225 haveToCopy=min(ms_length-ms_pos,packet.length-*samplepos);
\r
227 ms->GetPointer(&ms_buf);
\r
229 if (ms_pos==0) {//will only be changed on first packet
\r
230 if (packet.disconti) {
\r
231 ms->SetDiscontinuity(TRUE);
\r
233 ms->SetDiscontinuity(FALSE);
\r
235 if (packet.synched) {
\r
236 ms->SetSyncPoint(TRUE);
\r
237 ms->SetTime(&reftime1,&reftime2);
\r
239 //ms->SetTime(NULL,NULL);
\r
240 ms->SetMediaTime(NULL, NULL);
\r
241 if (reftime1<0) ms->SetPreroll(TRUE);
\r
242 else ms->SetPreroll(FALSE);
\r
244 ms->SetSyncPoint(FALSE);
\r
245 ms->SetTime(NULL,NULL);
\r
246 ms->SetMediaTime(NULL, NULL);
\r
247 ms->SetPreroll(FALSE);
\r
248 MessageBox(0,"here I'm","Hallo",0);
\r
249 // ms->SetSyncPoint(TRUE);
\r
254 memcpy(ms_buf+ms_pos,buffer+packet.pos_buffer+*samplepos,haveToCopy);
\r
255 ms->SetActualDataLength(haveToCopy+ms_pos);
\r
257 *samplepos+=haveToCopy;
\r
259 return haveToCopy+headerstrip;
\r
263 long long AudioWin::SetStartOffset(long long curreftime, bool *rsync){
\r
264 VideoWin *vw=(VideoWin*)Video::getInstance();
\r
265 return vw->SetStartAudioOffset(curreftime,rsync);
\r
268 void AudioWin::ResetTimeOffsets() {
\r
269 VideoWin *vw=(VideoWin*)Video::getInstance();
\r
270 return vw->ResetTimeOffsets();
\r
274 int AudioWin::test()
\r