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 "videowin.h"
\r
23 #include "dssourcefilter.h"
\r
24 #include "dsallocator.h"
\r
28 void AdjustWindow();
\r
32 VideoWin::VideoWin()
\r
35 dsgraphbuilder=NULL;
\r
36 dsmediacontrol=NULL;
\r
44 dsvmrsurfnotify=NULL;
\r
45 filtermutex=CreateMutex(NULL,FALSE,NULL);
\r
47 offsetvideonotset=true;
\r
48 offsetaudionotset=true;
\r
55 cur_audio_media_sample=NULL;
\r
56 cur_video_media_sample=NULL;
\r
62 iframemode=false;//We are not in Iframe mode at begining
\r
68 VideoWin::~VideoWin()
\r
71 CloseHandle(filtermutex);
\r
78 int VideoWin::init(UCHAR tformat)
\r
80 if (initted) return 0;
\r
83 tvsize=Video::ASPECT16X9; //Internally Vomp should think we are a 16:9 TV
\r
87 if (!setFormat(tformat)){ shutdown(); return 0; }
\r
91 int VideoWin::setTVsize(UCHAR ttvsize)
\r
93 pseudotvsize=ttvsize;
\r
97 int VideoWin::setDefaultAspect()
\r
99 return setAspectRatio(Video::ASPECT4X3);
\r
102 int VideoWin::shutdown()
\r
104 if (!initted) return 0;
\r
109 int VideoWin::setFormat(UCHAR tformat)
\r
111 if (!initted) return 0;
\r
112 if ((tformat != PAL) && (tformat != NTSC)) return 0;
\r
114 if (format == NTSC)
\r
117 screenHeight = 480;
\r
122 screenHeight = 576;
\r
128 int VideoWin::setConnection(UCHAR tconnection)
\r
130 if (!initted) return 0;
\r
131 if ((tconnection != COMPOSITERGB) && (tconnection != SVIDEO)) return 0;
\r
132 connection = tconnection;
\r
137 int VideoWin::setAspectRatio(UCHAR taspectRatio)
\r
139 if (!initted) return 0;
\r
140 if ((taspectRatio != ASPECT4X3) && (taspectRatio != ASPECT16X9)) return 0;
\r
141 aspectRatio = taspectRatio;
\r
146 int VideoWin::setMode(UCHAR tmode)
\r
148 if (!initted) return 0;
\r
150 //if ((tmode == LETTERBOX) && (tvsize == ASPECT16X9)) return 0; // invalid mode
\r
152 if ((tmode != NORMAL) && (tmode != LETTERBOX) && (tmode != UNKNOWN2) && (tmode != QUARTER) && (tmode != EIGHTH)
\r
153 && (tmode != ZOOM) && (tmode != UNKNOWN6)) return 0;
\r
162 int VideoWin::signalOff()
\r
167 int VideoWin::signalOn()
\r
172 int VideoWin::setSource()
\r
174 if (!initted) return 0;
\r
179 int VideoWin::setPosition(int x, int y)
\r
181 if (!initted) return 0;
\r
182 if (mode==QUARTER || mode==EIGHTH) {
\r
189 int VideoWin::sync()
\r
191 if (!initted) return 0;
\r
196 #ifdef DS_DEBUG // This stuff would not included in vomp due to lincemse restrcitions
\r
197 #include "dshelper.h"
\r
202 int VideoWin::play()
\r
204 if (!initted) return 0;
\r
208 int VideoWin::dsplay()
\r
210 if (!initted) return 0;
\r
213 //Build filter graph
\r
215 //So this is the real code, this prevents the feeder from calling noexisting objects!
\r
216 WaitForSingleObject(filtermutex,INFINITE);
\r
217 if (hres=CoCreateInstance(CLSID_FilterGraph,NULL,CLSCTX_INPROC_SERVER,
\r
218 IID_IGraphBuilder,(void**)&dsgraphbuilder)!=S_OK) {
\r
219 ReleaseMutex(filtermutex);
\r
223 AddToRot(dsgraphbuilder,&graphidentifier);
\r
225 //This is just a try to see if building the graph works
\r
226 // dsgraphbuilder->RenderFile(L"D:\\Projekte\\VTP Client\\test.mpa" ,NULL);
\r
228 firstsynched=false;
\r
229 sourcefilter=new DsSourceFilter(); //Creating our Source filter for pushing Data
\r
231 if (hres=dsgraphbuilder->AddFilter(sourcefilter,L"Vomp Win Source Filter")!=S_OK) {
\r
232 Log::getInstance()->log("VideoWin", Log::WARN , "Failed adding Vomp Source Filter!");
\r
233 ReleaseMutex(filtermutex);
\r
238 if (hres=dsgraphbuilder->Render((IPin*)sourcefilter->GetAudioPin()/*audio*/)!=S_OK) {
\r
239 Log::getInstance()->log("VideoWin", Log::WARN , "Failed rendering audio!");
\r
240 ReleaseMutex(filtermutex);
\r
247 //We alloc the vmr9 as next step
\r
248 if (hres=CoCreateInstance(CLSID_VideoMixingRenderer9,0,
\r
249 CLSCTX_INPROC_SERVER,IID_IBaseFilter,(void**) &dsvmrrenderer)!=S_OK) {
\r
250 Log::getInstance()->log("VideoWin", Log::WARN ,"Failed creating VMR9 renderer!");
\r
251 ReleaseMutex(filtermutex);
\r
256 if (hres=dsgraphbuilder->AddFilter(dsvmrrenderer,L"VMR9")!=S_OK) {
\r
257 ReleaseMutex(filtermutex);
\r
259 Log::getInstance()->log("VideoWin", Log::WARN ,"Failed adding VMR9 renderer!");
\r
263 IVMRFilterConfig9* vmrfilconfig;
\r
264 if (dsvmrrenderer->QueryInterface(IID_IVMRFilterConfig9,(void**)&vmrfilconfig)!=S_OK) {
\r
265 ReleaseMutex(filtermutex);
\r
267 Log::getInstance()->log("VideoWin", Log::WARN ,"Failed getting VMR9 Filterconfig interface!");
\r
270 vmrfilconfig->SetRenderingMode(VMR9Mode_Renderless);
\r
271 vmrfilconfig->Release();
\r
273 if (dsvmrrenderer->QueryInterface(IID_IVMRSurfaceAllocatorNotify9,(void**)& dsvmrsurfnotify)!=S_OK) {
\r
274 ReleaseMutex(filtermutex);
\r
276 Log::getInstance()->log("VideoWin", Log::WARN ,"Failed getting VMR9 Surface Allocator interface!");
\r
280 allocatorvmr=new DsAllocator();
\r
281 dsvmrsurfnotify->AdviseSurfaceAllocator(NULL,allocatorvmr);
\r
282 allocatorvmr->AdviseNotify(dsvmrsurfnotify);
\r
287 /*VMR 9 stuff end */
\r
288 IFilterGraph2*fg2=NULL;
\r
289 if (dsgraphbuilder->QueryInterface(IID_IFilterGraph2,(void**)&fg2)!=S_OK) {
\r
290 Log::getInstance()->log("VideoWin", Log::WARN , "Failed querying for FilterGraph2 Interface!");
\r
291 ReleaseMutex(filtermutex);
\r
295 if (hres=fg2->RenderEx((IPin*)sourcefilter->GetVideoPin()/*video*/,
\r
296 AM_RENDEREX_RENDERTOEXISTINGRENDERERS,NULL)!=S_OK) {
\r
297 Log::getInstance()->log("VideoWin", Log::WARN , "Failed rendering Video!");
\r
299 ReleaseMutex(filtermutex);
\r
306 if (hres=CoCreateInstance(CLSID_SystemClock,NULL,CLSCTX_INPROC_SERVER,
\r
307 IID_IReferenceClock,(void**)&dsrefclock)!=S_OK) {
\r
311 dsgraphbuilder->QueryInterface(IID_IMediaFilter,(void **) &dsmediafilter);
\r
312 HRESULT hresdeb=dsmediafilter->SetSyncSource(dsrefclock);
\r
314 dsgraphbuilder->QueryInterface(IID_IMediaControl,(void **) &dsmediacontrol);
\r
315 dsgraphbuilder->QueryInterface(IID_IBasicAudio,(void **) &dsbasicaudio);
\r
319 hresdeb=dsmediacontrol->Run();
\r
320 iframemode=false;//exit iframe mode
\r
321 ReleaseMutex(filtermutex);
\r
325 int VideoWin::EnterIframePlayback()
\r
327 if (!initted) return 0;
\r
329 //So this is the real code, this prevents the feeder from calling noexisting objects!
\r
330 WaitForSingleObject(filtermutex,INFINITE);
\r
331 iframemode=true;//enter iframe mode
\r
332 //Build filter graph
\r
334 if (hres=CoCreateInstance(CLSID_FilterGraph,NULL,CLSCTX_INPROC_SERVER,
\r
335 IID_IGraphBuilder,(void**)&dsgraphbuilder)!=S_OK) {
\r
336 ReleaseMutex(filtermutex);
\r
340 AddToRot(dsgraphbuilder,&graphidentifier);
\r
343 //firstsynched=false;
\r
344 sourcefilter=new DsSourceFilter(); //Creating our Source filter for pushing Data
\r
346 if (hres=dsgraphbuilder->AddFilter(sourcefilter,L"Vomp Win Source Filter")!=S_OK) {
\r
347 Log::getInstance()->log("VideoWin", Log::WARN , "Failed adding Vomp Source Filter!");
\r
348 ReleaseMutex(filtermutex);
\r
354 //We alloc the vmr9 as next step
\r
355 if (hres=CoCreateInstance(CLSID_VideoMixingRenderer9,0,
\r
356 CLSCTX_INPROC_SERVER,IID_IBaseFilter,(void**) &dsvmrrenderer)!=S_OK) {
\r
357 Log::getInstance()->log("VideoWin", Log::WARN ,"Failed creating VMR9 renderer!");
\r
358 ReleaseMutex(filtermutex);
\r
363 if (hres=dsgraphbuilder->AddFilter(dsvmrrenderer,L"VMR9")!=S_OK) {
\r
364 Log::getInstance()->log("VideoWin", Log::WARN ,"Failed adding VMR9 renderer!");
\r
365 ReleaseMutex(filtermutex);
\r
369 IVMRFilterConfig9* vmrfilconfig;
\r
370 if (dsvmrrenderer->QueryInterface(IID_IVMRFilterConfig9,(void**)&vmrfilconfig)!=S_OK) {
\r
371 ReleaseMutex(filtermutex);
\r
373 Log::getInstance()->log("VideoWin", Log::WARN ,"Failed getting VMR9 Filterconfig interface!");
\r
377 vmrfilconfig->SetRenderingMode(VMR9Mode_Renderless);
\r
378 vmrfilconfig->Release();
\r
380 if (dsvmrrenderer->QueryInterface(IID_IVMRSurfaceAllocatorNotify9,(void**)& dsvmrsurfnotify)!=S_OK) {
\r
381 Log::getInstance()->log("VideoWin", Log::WARN ,"Failed getting VMR9 Surface Allocator interface!");
\r
382 ReleaseMutex(filtermutex);
\r
386 allocatorvmr=new DsAllocator();
\r
387 dsvmrsurfnotify->AdviseSurfaceAllocator(NULL,allocatorvmr);
\r
388 allocatorvmr->AdviseNotify(dsvmrsurfnotify);
\r
390 /*VMR 9 stuff end */
\r
391 IFilterGraph2*fg2=NULL;
\r
392 if (dsgraphbuilder->QueryInterface(IID_IFilterGraph2,(void**)&fg2)!=S_OK) {
\r
393 Log::getInstance()->log("VideoWin", Log::WARN , "Failed querying for FilterGraph2 Interface!");
\r
394 ReleaseMutex(filtermutex);
\r
398 if (hres=fg2->RenderEx((IPin*)sourcefilter->GetVideoPin()/*video*/,
\r
399 AM_RENDEREX_RENDERTOEXISTINGRENDERERS,NULL)!=S_OK) {
\r
400 Log::getInstance()->log("VideoWin", Log::WARN , "Failed rendering Video!");
\r
402 ReleaseMutex(filtermutex);
\r
409 /* if (hres=CoCreateInstance(CLSID_SystemClock,NULL,CLSCTX_INPROC_SERVER,
\r
410 IID_IReferenceClock,(void**)&dsrefclock)!=S_OK) {
\r
414 dsgraphbuilder->QueryInterface(IID_IMediaFilter,(void **) &dsmediafilter);
\r
415 dsmediafilter->SetSyncSource(/*dsrefclock*/NULL); //Run as fast as you can!
\r
417 dsgraphbuilder->QueryInterface(IID_IMediaControl,(void **) &dsmediacontrol);
\r
418 dsgraphbuilder->QueryInterface(IID_IBasicAudio,(void **) &dsbasicaudio);
\r
422 dsmediacontrol->Run();
\r
423 ReleaseMutex(filtermutex);
\r
428 int VideoWin::dsstop()
\r
430 if (!initted) return 0;
\r
438 int VideoWin::stop()
\r
440 if (!initted) return 0;
\r
446 int VideoWin::reset()
\r
448 if (!initted) return 0;
\r
454 int VideoWin::dsreset()
\r
456 if (!initted) return 0;
\r
459 iframemode=false;//exit iframe mode
\r
465 int VideoWin::dspause()
\r
467 if (!initted) return 0;
\r
468 WaitForSingleObject(filtermutex,INFINITE);
\r
469 if (dsmediacontrol) dsmediacontrol->Pause();
\r
470 ReleaseMutex(filtermutex);
\r
474 int VideoWin::pause()
\r
476 if (!initted) return 0;
\r
481 int VideoWin::unPause() // FIXME get rid - same as play!!
\r
482 {//No on windows this is not the same, I don't get rid of!
\r
483 if (!initted) return 0;
\r
487 int VideoWin::dsunPause() // FIXME get rid - same as play!!
\r
488 {//No on windows this is not the same, I don't get rid of!
\r
489 if (!initted) return 0;
\r
490 WaitForSingleObject(filtermutex,INFINITE);
\r
491 if (dsmediacontrol) dsmediacontrol->Run();
\r
492 ReleaseMutex(filtermutex);
\r
497 int VideoWin::fastForward()
\r
499 if (!initted) return 0;
\r
504 int VideoWin::unFastForward()
\r
506 if (!initted) return 0;
\r
511 int VideoWin::attachFrameBuffer()
\r
513 if (!initted) return 0;
\r
517 int VideoWin::blank(void)
\r
519 ((OsdWin*)Osd::getInstance())->Blank();
\r
523 ULLONG VideoWin::getCurrentTimestamp()
\r
525 REFERENCE_TIME startoffset;
\r
526 REFERENCE_TIME ncr_time;
\r
527 if (iframemode) return 0; //Not in iframe mode!
\r
528 if (!dsrefclock || !sourcefilter) return 0;
\r
529 FILTER_STATE state;
\r
530 sourcefilter->GetState(10,&state);
\r
532 if (state==State_Running) dsrefclock->GetTime(&cr_time);
\r
534 startoffset=sourcefilter->getStartOffset();
\r
535 ncr_time-=startoffset;
\r
536 ncr_time-=lastreftimeRT;
\r
537 /* ULLONG result=frameNumberToTimecode(
\r
538 VDR::getInstance()->frameNumberFromPosition(lastreftimeBYTE));*/
\r
539 ULLONG result=lastreftimePTS;
\r
540 result+=(ULLONG)(ncr_time/10000LL*90LL);
\r
545 ULONG VideoWin::timecodeToFrameNumber(ULLONG timecode)
\r
547 if (format == PAL) return (ULONG)(((double)timecode / (double)90000) * (double)25);
\r
548 else return (ULONG)(((double)timecode / (double)90000) * (double)30);
\r
551 ULLONG VideoWin::frameNumberToTimecode(ULONG framenumber)
\r
553 if (format == PAL) return (ULLONG)(((double)framenumber * (double)90000) / (double)25);
\r
554 else return (ULLONG)(((double)framenumber * (double)90000) / (double)30);
\r
557 void VideoWin::CleanupDS()
\r
559 WaitForSingleObject(filtermutex,INFINITE);
\r
561 if (dsmediacontrol)dsmediacontrol->Stop();
\r
562 if (cur_audio_media_sample) {
\r
563 cur_audio_media_sample->Release();
\r
564 cur_audio_media_sample=NULL;
\r
566 if (cur_video_media_sample) {
\r
567 cur_video_media_sample->Release();
\r
568 cur_video_media_sample=NULL;
\r
570 if (dsbasicaudio) {
\r
571 dsbasicaudio->Release();
\r
574 if (dsvmrsurfnotify) {
\r
575 dsvmrsurfnotify->Release();
\r
576 dsvmrsurfnotify=NULL;
\r
578 if (dsvmrrenderer) {
\r
579 dsvmrrenderer->Release();
\r
580 dsvmrrenderer=NULL;
\r
583 if (allocatorvmr) {
\r
584 allocatorvmr->Release();
\r
589 dsrefclock->Release();
\r
592 if (dsmediafilter) {
\r
593 dsmediafilter->Release();
\r
594 dsmediafilter=NULL;
\r
599 if (dsmediacontrol) {
\r
600 dsmediacontrol->Stop();
\r
601 dsmediacontrol->Release();
\r
602 dsmediacontrol=NULL;
\r
604 if (dsgraphbuilder){
\r
606 RemoveFromRot(graphidentifier);
\r
608 dsgraphbuilder->Release();
\r
609 dsgraphbuilder=NULL;
\r
611 sourcefilter=NULL; //The Graph Builder destroys our SourceFilter
\r
613 ReleaseMutex(filtermutex);
\r
617 void VideoWin::PrepareMediaSample(const MediaPacketList& mplist,
\r
620 mediapacket = mplist.front();
\r
623 UINT VideoWin::DeliverMediaSample(const UCHAR* buffer, UINT *samplepos)
\r
625 DeliverMediaPacket(mediapacket, buffer, samplepos);
\r
626 if (*samplepos == mediapacket.length) {
\r
633 UINT VideoWin::DeliverMediaPacket(MediaPacket packet,
\r
634 const UCHAR* buffer,
\r
637 /*First Check, if we have an audio sample*/
\r
638 if (!isdsinited()) return 0;
\r
641 *samplepos+=packet.length;
\r
642 MILLISLEEP(0); //yet not implemented//bad idea
\r
643 return packet.length;
\r
645 /*First Check, if we have an audio sample*/
\r
649 return 0; //Not in iframe mode!
\r
651 IMediaSample* ms=NULL;
\r
652 REFERENCE_TIME reftime1=0;
\r
653 REFERENCE_TIME reftime2=0;
\r
655 UINT headerstrip=0;
\r
656 if (packet.disconti) {
\r
657 firstsynched=false;
\r
658 DeliverVideoMediaSample();
\r
663 /*Inspect PES-Header */
\r
665 if (*samplepos==0) {//stripheader
\r
666 headerstrip=buffer[packet.pos_buffer+8]+9/*is this right*/;
\r
667 *samplepos+=headerstrip;
\r
668 if ( packet.synched ) {
\r
669 DeliverVideoMediaSample();//write out old data
\r
670 /* if (packet.presentation_time<0) { //Preroll?
\r
671 *samplepos=packet.length;//if we have not processed at least one
\r
672 return packet.length;//synched packet ignore it!
\r
675 reftime1=packet.presentation_time;
\r
676 reftime2=reftime1+1;
\r
679 if (!firstsynched) {//
\r
680 *samplepos=packet.length;//if we have not processed at least one
\r
681 return packet.length;//synched packet ignore it!
\r
690 if (!getCurrentVideoMediaSample(&ms) || ms==NULL) {// get the current sample
\r
695 ms_pos=ms->GetActualDataLength();
\r
696 ms_length=ms->GetSize();
\r
697 haveToCopy=min(ms_length-ms_pos,packet.length-*samplepos);
\r
698 if ((ms_length-ms_pos)<1) {
\r
699 DeliverVideoMediaSample(); //we are full!
\r
700 if (!getCurrentVideoMediaSample(&ms) || ms==NULL) {// get the current sample
\r
705 ms_pos=ms->GetActualDataLength();
\r
706 ms_length=ms->GetSize();
\r
707 haveToCopy=min(ms_length-ms_pos,packet.length-*samplepos);
\r
709 ms->GetPointer(&ms_buf);
\r
712 if (ms_pos==0) {//will only be changed on first packet
\r
713 if (packet.disconti) {
\r
714 ms->SetDiscontinuity(TRUE);
\r
716 ms->SetDiscontinuity(FALSE);
\r
718 if (packet.synched) {
\r
719 ms->SetSyncPoint(TRUE);
\r
720 ms->SetTime(&reftime1,&reftime2);
\r
721 //ms->SetTime(NULL,NULL);
\r
722 ms->SetMediaTime(NULL, NULL);
\r
723 if (reftime1<0) ms->SetPreroll(TRUE);
\r
724 else ms->SetPreroll(FALSE);
\r
725 /*Timecode handling*/
\r
726 lastreftimeRT=reftime1;
\r
727 lastreftimePTS=packet.pts;
\r
730 ms->SetSyncPoint(FALSE);
\r
731 ms->SetTime(NULL,NULL);
\r
732 ms->SetMediaTime(NULL, NULL);
\r
733 ms->SetPreroll(FALSE);
\r
735 // ms->SetSyncPoint(TRUE);
\r
740 memcpy(ms_buf+ms_pos,buffer+packet.pos_buffer+*samplepos,haveToCopy);
\r
741 ms->SetActualDataLength(haveToCopy+ms_pos);
\r
743 *samplepos+=haveToCopy;
\r
745 return haveToCopy+headerstrip;
\r
749 *samplepos+=packet.length;
\r
750 MILLISLEEP(0); //yet not implemented//bad idea
\r
751 return packet.length;
\r
755 int VideoWin::getCurrentAudioMediaSample(IMediaSample** ms)
\r
757 //WaitForSingleObject(filtermutex,INFINITE);
\r
758 if (!sourcefilter){
\r
759 // ReleaseMutex(filtermutex);
\r
762 if (cur_audio_media_sample) {
\r
763 *ms=cur_audio_media_sample;//already open
\r
766 if (!sourcefilter->getCurrentAudioMediaSample(ms)) {
\r
767 // ReleaseMutex(filtermutex);
\r
769 if (*ms) (*ms)->SetActualDataLength(0);
\r
770 cur_audio_media_sample=*ms;
\r
771 //Don't release the mutex before deliver
\r
775 int VideoWin::getCurrentVideoMediaSample(IMediaSample** ms)
\r
777 //WaitForSingleObject(filtermutex,INFINITE);
\r
778 if (!sourcefilter){
\r
779 // ReleaseMutex(filtermutex);
\r
782 if (cur_video_media_sample) {
\r
783 *ms=cur_video_media_sample;//already open
\r
786 if (!sourcefilter->getCurrentVideoMediaSample(ms)) {
\r
787 // ReleaseMutex(filtermutex);
\r
789 if (*ms) (*ms)->SetActualDataLength(0);
\r
791 cur_video_media_sample=*ms;
\r
792 //Don't release the mutex before deliver
\r
796 int VideoWin::DeliverAudioMediaSample(){
\r
797 if (cur_audio_media_sample) {
\r
798 sourcefilter->DeliverAudioMediaSample(cur_audio_media_sample);
\r
799 cur_audio_media_sample=NULL;
\r
801 //ReleaseMutex(filtermutex);
\r
805 int VideoWin::DeliverVideoMediaSample(){
\r
806 if (cur_video_media_sample) {
\r
807 sourcefilter->DeliverVideoMediaSample(cur_video_media_sample);
\r
808 cur_video_media_sample=NULL;
\r
810 //ReleaseMutex(filtermutex);
\r
814 long long VideoWin::SetStartOffset(long long curreftime, bool *rsync)
\r
817 if (offsetnotset) {
\r
818 startoffset=curreftime;//offset is set for audio
\r
819 offsetnotset=false;
\r
820 offsetvideonotset=false;
\r
824 if (offsetvideonotset) {
\r
825 offsetvideonotset=false;
\r
828 if ( (curreftime-lastrefvideotime)>10000000LL
\r
829 || (curreftime-lastrefvideotime)<-10000000LL) {//if pts jumps to big resync
\r
830 startoffset+=curreftime-lastrefvideotime;
\r
831 lastrefaudiotime+=curreftime-lastrefvideotime;
\r
833 offsetaudionotset=true;
\r
840 lastrefvideotime=curreftime;
\r
842 return startoffset;
\r
846 long long VideoWin::SetStartAudioOffset(long long curreftime, bool *rsync)
\r
849 if (offsetnotset) {
\r
850 startoffset=curreftime;
\r
851 offsetnotset=false;
\r
852 offsetaudionotset=false;
\r
854 if (offsetaudionotset) {
\r
855 offsetaudionotset=false;
\r
858 if ( (curreftime-lastrefaudiotime)>10000000LL
\r
859 || (curreftime-lastrefaudiotime)<-10000000LL) {//if pts jumps to big resync
\r
860 startoffset+=curreftime-lastrefaudiotime;
\r
861 lastrefvideotime+=curreftime-lastrefaudiotime;
\r
863 offsetvideonotset=true;
\r
869 lastrefaudiotime=curreftime;
\r
870 return startoffset;
\r
873 void VideoWin::ResetTimeOffsets() {
\r
874 offsetnotset=true; //called from demuxer
\r
875 offsetvideonotset=true;
\r
876 offsetaudionotset=true;
\r
878 lastrefaudiotime=0;
\r
879 lastrefvideotime=0;
\r
886 void VideoWin::SetAudioVolume(long volume)
\r
888 if (dsbasicaudio) dsbasicaudio->put_Volume(volume);
\r
891 void VideoWin::displayIFrame(const UCHAR* buffer, UINT length)
\r
893 if (!iframemode) EnterIframePlayback();
\r
895 if (!isdsinited()) return ;
\r
897 IMediaSample* ms=NULL;
\r
898 REFERENCE_TIME reftime1=0;
\r
899 REFERENCE_TIME reftime2=0;
\r
900 if (!videoon) return;
\r
902 if (!getCurrentVideoMediaSample(&ms) || ms==NULL) {// get the current sample
\r
908 ms->GetPointer(&ms_buf);
\r
909 ms_length=ms->GetSize();
\r
911 /*First Check, if we have an video sample*/
\r
912 DWORD read_pos = 0, write_pos = 0;
\r
913 DWORD pattern, packet_length;
\r
914 DWORD headerstrip=0;
\r
916 if (length < 4) return ;
\r
917 //Now we strip the pes header
\r
918 pattern = (buffer[0] << 16) | (buffer[1] << 8) | (buffer[2]);
\r
919 while (read_pos + 7 <= length)
\r
921 pattern = ((pattern << 8) & 0xFFFFFFFF) | buffer[read_pos+3];
\r
922 if (pattern < 0x000001E0 || pattern > 0x000001EF)
\r
926 headerstrip=buffer[read_pos+8]+9/*is this right*/;
\r
927 packet_length = ((buffer[read_pos+4] << 8) | (buffer[read_pos+5])) + 6;
\r
928 if (read_pos + packet_length > length)
\r
932 if ((write_pos+packet_length-headerstrip)>ms_length) {
\r
933 if (first) {ms->SetSyncPoint(TRUE);first=false;}
\r
934 else ms->SetSyncPoint(FALSE);
\r
935 ms->SetTime(NULL,NULL);
\r
936 ms->SetMediaTime(NULL, NULL);
\r
937 ms->SetActualDataLength(write_pos);
\r
938 DeliverVideoMediaSample();
\r
940 if (!getCurrentVideoMediaSample(&ms) || ms==NULL) {// get the current sample
\r
945 ms_length=ms->GetSize();
\r
946 ms->GetPointer(&ms_buf);
\r
948 if (packet_length-headerstrip>0) {
\r
949 memcpy(ms_buf+write_pos, buffer+read_pos+headerstrip, packet_length-headerstrip);
\r
950 write_pos += packet_length-headerstrip;
\r
952 read_pos += packet_length;
\r
954 pattern = (buffer[read_pos] << 16) | (buffer[read_pos+1] << 8)
\r
955 | (buffer[read_pos+2]);
\r
960 if (first) {ms->SetSyncPoint(TRUE);first=false;}
\r
961 else ms->SetSyncPoint(FALSE);
\r
962 ms->SetTime(NULL,NULL);
\r
963 ms->SetMediaTime(NULL, NULL);
\r
964 ms->SetActualDataLength(write_pos);
\r
965 DeliverVideoMediaSample();
\r
969 // *samplepos+=packet.length;
\r
970 MILLISLEEP(0); //yet not implemented//bad idea
\r
977 int VideoWin::test()
\r
982 int VideoWin::test2()
\r