2 Copyright 2004-2005 Chris Tallon
4 This file is part of VOMP.
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.
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.
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
45 int AudioWin::init(UCHAR tstreamType)
47 if (initted) return 0;
52 int AudioWin::shutdown()
54 if (!initted) return 0;
59 int AudioWin::write(char *buf, int len)
61 return 0; //write(fdAudio, buf, len);
64 int AudioWin::setStreamType(UCHAR type)
66 if (!initted) return 0;
70 int AudioWin::setChannel()
72 if (!initted) return 0;
76 int AudioWin::setSource()
78 if (!initted) return 0;
84 if (!initted) return 0;
90 if (!initted) return 0;
92 return ((VideoWin*)Video::getInstance())->dsplay();
98 if (!initted) return 0;
99 return ((VideoWin*)Video::getInstance())->dsstop();
102 int AudioWin::pause()
104 if (!initted) return 0;
105 return ((VideoWin*)Video::getInstance())->dspause();
108 int AudioWin::unPause()
110 if (!initted) return 0;
111 return ((VideoWin*)Video::getInstance())->dsunPause();
114 int AudioWin::reset()
117 if (!initted){return 0;}
118 return ((VideoWin*)Video::getInstance())->dsreset();
121 int AudioWin::setVolume(int tvolume)
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);
135 if (!initted) return 0;
136 ((VideoWin*)Video::getInstance())->SetAudioState(false);
137 ((VideoWin*)Video::getInstance())->SetAudioVolume(-10000);
141 int AudioWin::unMute()
143 if (!initted) return 0;
144 ((VideoWin*)Video::getInstance())->SetAudioState(true);
145 ((VideoWin*)Video::getInstance())->SetAudioVolume(winvolume);
149 void AudioWin::PrepareMediaSample(const MediaPacketList& mplist,UINT samplepos)
151 mediapacket = mplist.front();
154 UINT AudioWin::DeliverMediaSample(const UCHAR* buffer, UINT *samplepos)
156 DeliverMediaPacket(mediapacket, buffer, samplepos);
157 if (*samplepos == mediapacket.length) {
164 UINT AudioWin::DeliverMediaPacket(MediaPacket packet,
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()) {
175 return 0; //Not in iframe mode!
177 IMediaSample* ms=NULL;
178 REFERENCE_TIME reftime1=0;
179 REFERENCE_TIME reftime2=0;
182 if (packet.disconti) {
184 vw->DeliverVideoMediaSample();
189 /*Inspect PES-Header */
190 /* UINT header_length=buffer[(packet.pos_buffer+8)%bufferlength]+8/*is this right*;
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!
202 reftime1=packet.presentation_time;
206 if (!firstsynched) {//
207 *samplepos=packet.length;//if we have not processed at least one
209 return packet.length;//synched packet ignore it!
217 if (!vw->getCurrentAudioMediaSample(&ms) || ms==NULL) {// get the current sample
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
232 ms_pos=ms->GetActualDataLength();
233 ms_length=ms->GetSize();
234 haveToCopy=min(ms_length-ms_pos,packet.length-*samplepos);
236 ms->GetPointer(&ms_buf);
238 if (ms_pos==0) {//will only be changed on first packet
239 if (packet.disconti) {
240 ms->SetDiscontinuity(TRUE);
242 ms->SetDiscontinuity(FALSE);
244 if (packet.synched) {
245 ms->SetSyncPoint(TRUE);
246 ms->SetTime(&reftime1,&reftime2);
248 //ms->SetTime(NULL,NULL);
249 ms->SetMediaTime(NULL, NULL);
250 if (reftime1<0) ms->SetPreroll(TRUE);
251 else ms->SetPreroll(FALSE);
253 ms->SetSyncPoint(FALSE);
254 ms->SetTime(NULL,NULL);
255 ms->SetMediaTime(NULL, NULL);
256 ms->SetPreroll(FALSE);
257 // ms->SetSyncPoint(TRUE);
262 memcpy(ms_buf+ms_pos,buffer+packet.pos_buffer+*samplepos,haveToCopy);
263 ms->SetActualDataLength(haveToCopy+ms_pos);
265 *samplepos+=haveToCopy;
267 return haveToCopy+headerstrip;
271 long long AudioWin::SetStartOffset(long long curreftime, bool *rsync){
272 VideoWin *vw=(VideoWin*)Video::getInstance();
273 return vw->SetStartAudioOffset(curreftime,rsync);
276 void AudioWin::ResetTimeOffsets() {
277 VideoWin *vw=(VideoWin*)Video::getInstance();
278 return vw->ResetTimeOffsets();