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
43 int AudioWin::init(UCHAR tstreamType)
45 if (initted) return 0;
50 int AudioWin::shutdown()
52 if (!initted) return 0;
57 int AudioWin::write(char *buf, int len)
59 return 0; //write(fdAudio, buf, len);
62 int AudioWin::setStreamType(UCHAR type)
64 if (!initted) return 0;
68 int AudioWin::setChannel()
70 if (!initted) return 0;
74 int AudioWin::setSource()
76 if (!initted) return 0;
82 if (!initted) return 0;
88 if (!initted) return 0;
90 return ((VideoWin*)Video::getInstance())->dsplay();
96 if (!initted) return 0;
97 return ((VideoWin*)Video::getInstance())->dsstop();
100 int AudioWin::pause()
102 if (!initted) return 0;
103 return ((VideoWin*)Video::getInstance())->dspause();
106 int AudioWin::unPause()
108 if (!initted) return 0;
109 return ((VideoWin*)Video::getInstance())->dsunPause();
112 int AudioWin::reset()
115 if (!initted){return 0;}
116 return ((VideoWin*)Video::getInstance())->dsreset();
119 int AudioWin::setVolume(int tvolume)
121 // parameter: 0 for silence, 20 for full
122 if ((tvolume < 0) || (tvolume > 20)) return 0;
123 winvolume=((tvolume-20)*100*30)/20;
124 if (tvolume==0) winvolume=-10000;
125 ((VideoWin*)Video::getInstance())->SetAudioVolume(winvolume);
133 if (!initted) return 0;
134 ((VideoWin*)Video::getInstance())->SetAudioState(false);
135 ((VideoWin*)Video::getInstance())->SetAudioVolume(-10000);
139 int AudioWin::unMute()
141 if (!initted) return 0;
142 ((VideoWin*)Video::getInstance())->SetAudioState(true);
143 ((VideoWin*)Video::getInstance())->SetAudioVolume(winvolume);
147 void AudioWin::PrepareMediaSample(const MediaPacketList& mplist,UINT samplepos)
149 mediapacket = mplist.front();
152 UINT AudioWin::DeliverMediaSample(const UCHAR* buffer, UINT *samplepos)
154 DeliverMediaPacket(mediapacket, buffer, samplepos);
155 if (*samplepos == mediapacket.length) {
162 UINT AudioWin::DeliverMediaPacket(MediaPacket packet,
167 /*First Check, if we have an audio sample*/
168 VideoWin *vw=(VideoWin*)Video::getInstance();
169 if (!vw->isdsinited()) return 0;
170 if (vw->InIframemode()) {
173 return 0; //Not in iframe mode!
175 IMediaSample* ms=NULL;
176 REFERENCE_TIME reftime1=0;
177 REFERENCE_TIME reftime2=0;
180 if (packet.disconti) {
182 vw->DeliverAudioMediaSample();
185 if (packet.type!=vw->lastAType()){//Format Change //Push data out !
187 vw->DeliverAudioMediaSample();
192 /*Inspect PES-Header */
193 /* UINT header_length=buffer[(packet.pos_buffer+8)%bufferlength]+8/*is this right*;
195 if (*samplepos==0) {//stripheader
196 headerstrip=buffer[packet.pos_buffer+8]+9/*is this right*/;
197 if (packet.type == MPTYPE_AC3) headerstrip+=4; //skip ac3 bytes
198 *samplepos+=headerstrip;
199 if ( packet.synched ) {
200 vw->DeliverAudioMediaSample();//write out old data
201 /* if (packet.presentation_time<0) { //Preroll?
202 *samplepos=packet.length;//if we have not processed at least one
203 return packet.length;//synched packet ignore it!
206 reftime1=packet.presentation_time;
210 if (!firstsynched) {//
211 *samplepos=packet.length;//if we have not processed at least one
213 return packet.length;//synched packet ignore it!
221 if (!vw->getCurrentAudioMediaSample(&ms) || ms==NULL) {// get the current sample
226 ms_pos=ms->GetActualDataLength();
227 ms_length=ms->GetSize();
228 haveToCopy=min(ms_length-ms_pos,packet.length-*samplepos);
229 if ((ms_length-ms_pos)<1) {
230 vw->DeliverAudioMediaSample(); //we are full!
231 if (!vw->getCurrentAudioMediaSample(&ms) || ms==NULL) {// get the current sample
236 ms_pos=ms->GetActualDataLength();
237 ms_length=ms->GetSize();
238 haveToCopy=min(ms_length-ms_pos,packet.length-*samplepos);
240 ms->GetPointer(&ms_buf);
243 if (ms_pos==0) {//will only be changed on first packet
244 if (packet.disconti) {
245 ms->SetDiscontinuity(TRUE);
247 ms->SetDiscontinuity(FALSE);
249 if (packet.synched) {
250 ms->SetSyncPoint(TRUE);
251 ms->SetTime(&reftime1,&reftime2);
253 //ms->SetTime(NULL,NULL);
254 ms->SetMediaTime(NULL, NULL);
255 if (reftime1<0) ms->SetPreroll(TRUE);
256 else ms->SetPreroll(FALSE);
258 ms->SetSyncPoint(FALSE);
259 ms->SetTime(NULL,NULL);
260 ms->SetMediaTime(NULL, NULL);
261 ms->SetPreroll(FALSE);
262 // ms->SetSyncPoint(TRUE);
265 if (packet.type!=vw->lastAType()) {
266 vw->changeAType(packet.type,ms);
267 ms->SetDiscontinuity(TRUE);
271 memcpy(ms_buf+ms_pos,buffer+packet.pos_buffer+*samplepos,haveToCopy);
273 ms->SetActualDataLength(haveToCopy+ms_pos);
275 *samplepos+=haveToCopy;
277 return haveToCopy+headerstrip;
281 long long AudioWin::SetStartOffset(long long curreftime, bool *rsync){
282 VideoWin *vw=(VideoWin*)Video::getInstance();
283 return vw->SetStartAudioOffset(curreftime,rsync);
286 void AudioWin::ResetTimeOffsets() {
287 VideoWin *vw=(VideoWin*)Video::getInstance();
288 return vw->ResetTimeOffsets();
291 bool AudioWin::supportsAc3(){
292 VideoWin *vw=(VideoWin*)Video::getInstance();
293 return vw->supportsAc3();