]> git.vomp.tv Git - vompclient-marten.git/commitdiff
Ac3 for Windows
authorChris Tallon <chris@vomp.tv>
Sat, 10 Feb 2007 15:27:02 +0000 (15:27 +0000)
committerChris Tallon <chris@vomp.tv>
Sat, 10 Feb 2007 15:27:02 +0000 (15:27 +0000)
videowin.cc
videowin.h

index 4307b6229d499b593779270daa833fb1a26520d3..f940a270c427d9d398b8db08a1c636d5c99c84f4 100644 (file)
@@ -58,6 +58,7 @@ VideoWin::VideoWin()
   cur_video_media_sample=NULL;
   videoon=true;
   audioon=true;
+  audiovolume=0;
   pseudotvsize=0;
   videoposx=0;
   videoposy=0;
@@ -218,7 +219,7 @@ int VideoWin::dsplay()
    WaitForSingleObject(filtermutex,INFINITE);
   if (hres=CoCreateInstance(CLSID_FilterGraph,NULL,CLSCTX_INPROC_SERVER,
     IID_IGraphBuilder,(void**)&dsgraphbuilder)!=S_OK) {
-    ReleaseMutex(filtermutex);
+         ReleaseMutex(filtermutex);
       return 0;
    }
    #ifdef DS_DEBUG
@@ -226,7 +227,7 @@ int VideoWin::dsplay()
    #endif
    //This is just a try to see if building the graph works
 //   dsgraphbuilder->RenderFile(L"D:\\Projekte\\VTP Client\\test.mpa" ,NULL);
-
+   
    firstsynched=false;
    lastaudiomode=MPTYPE_MPEG_AUDIO;
    //lastaudiomode=MPTYPE_AC3;
@@ -234,14 +235,14 @@ int VideoWin::dsplay()
    // to DirectShow
    if (hres=dsgraphbuilder->AddFilter(sourcefilter,L"Vomp Win Source Filter")!=S_OK) {
    Log::getInstance()->log("VideoWin", Log::WARN , "Failed adding Vomp Source Filter!");
-   ReleaseMutex(filtermutex);
+        ReleaseMutex(filtermutex);
      CleanupDS();
      return 0;
    }
    //if (audioon) {
      if (hres=dsgraphbuilder->Render((IPin*)sourcefilter->GetAudioPin()/*audio*/)!=S_OK) {
      Log::getInstance()->log("VideoWin", Log::WARN , "Failed rendering audio!");
-     ReleaseMutex(filtermutex);
+          ReleaseMutex(filtermutex);
        CleanupDS();
        return 0;
      }
@@ -252,22 +253,22 @@ int VideoWin::dsplay()
     if (hres=CoCreateInstance(CLSID_VideoMixingRenderer9,0,
       CLSCTX_INPROC_SERVER,IID_IBaseFilter,(void**) &dsvmrrenderer)!=S_OK) {
       Log::getInstance()->log("VideoWin", Log::WARN ,"Failed creating VMR9 renderer!");
-    ReleaseMutex(filtermutex);
+         ReleaseMutex(filtermutex);
       CleanupDS();
-
+      
     }
       /*VMR 9 stuff**/
     if (hres=dsgraphbuilder->AddFilter(dsvmrrenderer,L"VMR9")!=S_OK) {
-    ReleaseMutex(filtermutex);
+         ReleaseMutex(filtermutex);
       CleanupDS();
       Log::getInstance()->log("VideoWin", Log::WARN ,"Failed adding VMR9 renderer!");
-
+      
       return 0;
     }
     IVMRFilterConfig9* vmrfilconfig;
     if (dsvmrrenderer->QueryInterface(IID_IVMRFilterConfig9,(void**)&vmrfilconfig)!=S_OK) {
       ReleaseMutex(filtermutex);
-    CleanupDS();
+         CleanupDS();
       Log::getInstance()->log("VideoWin", Log::WARN ,"Failed getting VMR9 Filterconfig interface!");
       return 0;
     }
@@ -276,15 +277,15 @@ int VideoWin::dsplay()
 
     if (dsvmrrenderer->QueryInterface(IID_IVMRSurfaceAllocatorNotify9,(void**)& dsvmrsurfnotify)!=S_OK) {
       ReleaseMutex(filtermutex);
-    CleanupDS();
+         CleanupDS();
       Log::getInstance()->log("VideoWin", Log::WARN ,"Failed getting VMR9 Surface Allocator interface!");
-
+      
       return 0;
     }
     allocatorvmr=new DsAllocator();
     dsvmrsurfnotify->AdviseSurfaceAllocator(NULL,allocatorvmr);
     allocatorvmr->AdviseNotify(dsvmrsurfnotify);
-
+       
 
 
 
@@ -293,18 +294,18 @@ int VideoWin::dsplay()
     if (dsgraphbuilder->QueryInterface(IID_IFilterGraph2,(void**)&fg2)!=S_OK) {
       Log::getInstance()->log("VideoWin", Log::WARN , "Failed querying for FilterGraph2 Interface!");
       ReleaseMutex(filtermutex);
-    CleanupDS();
+         CleanupDS();
       return 0;
     }
     if (hres=fg2->RenderEx((IPin*)sourcefilter->GetVideoPin()/*video*/,
         AM_RENDEREX_RENDERTOEXISTINGRENDERERS,NULL)!=S_OK) {
       Log::getInstance()->log("VideoWin", Log::WARN , "Failed rendering Video!");
-    fg2->Release();
-    ReleaseMutex(filtermutex);
-    CleanupDS();
+         fg2->Release();
+         ReleaseMutex(filtermutex);
+         CleanupDS();
       return 0;
     }
-  fg2->Release();
+       fg2->Release();
    }
 #endif
    if (hres=CoCreateInstance(CLSID_SystemClock,NULL,CLSCTX_INPROC_SERVER,
@@ -316,7 +317,8 @@ int VideoWin::dsplay()
    HRESULT hresdeb=dsmediafilter->SetSyncSource(dsrefclock);
 
    dsgraphbuilder->QueryInterface(IID_IMediaControl,(void **) &dsmediacontrol);
-   dsgraphbuilder->QueryInterface(IID_IBasicAudio,(void **) &dsbasicaudio);
+   dsgraphbuilder->QueryInterface(IID_IBasicAudio,(void **) &dsbasicaudio);    
+   if (dsbasicaudio) dsbasicaudio->put_Volume(audiovolume);
    dsinited=true;
    //MILLISLEEP(100);
 
@@ -328,28 +330,28 @@ int VideoWin::dsplay()
 
 int VideoWin::EnterIframePlayback()
 {
-  if (!initted) return 0;
-  CleanupDS();
-  //So this is the real code, this prevents the feeder from calling noexisting objects!
+       if (!initted) return 0;
+       CleanupDS();
+       //So this is the real code, this prevents the feeder from calling noexisting objects!
    WaitForSingleObject(filtermutex,INFINITE);
-  iframemode=true;//enter iframe mode
-  //Build filter graph
-  HRESULT hres;
-  if (hres=CoCreateInstance(CLSID_FilterGraph,NULL,CLSCTX_INPROC_SERVER,
-     IID_IGraphBuilder,(void**)&dsgraphbuilder)!=S_OK) {
-       ReleaseMutex(filtermutex);
-       return 0;
-  }
+       iframemode=true;//enter iframe mode
+       //Build filter graph
+       HRESULT hres;
+       if (hres=CoCreateInstance(CLSID_FilterGraph,NULL,CLSCTX_INPROC_SERVER,
+                IID_IGraphBuilder,(void**)&dsgraphbuilder)!=S_OK) {
+                        ReleaseMutex(filtermutex);
+                        return 0;
+       }
 #ifdef DS_DEBUG
-  AddToRot(dsgraphbuilder,&graphidentifier);
+       AddToRot(dsgraphbuilder,&graphidentifier);
 #endif
-
+   
    //firstsynched=false;
    sourcefilter=new DsSourceFilter(); //Creating our Source filter for pushing Data
    // to DirectShow
    if (hres=dsgraphbuilder->AddFilter(sourcefilter,L"Vomp Win Source Filter")!=S_OK) {
    Log::getInstance()->log("VideoWin", Log::WARN , "Failed adding Vomp Source Filter!");
-     ReleaseMutex(filtermutex);
+     ReleaseMutex(filtermutex);  
      CleanupDS();
      return 0;
    }
@@ -360,54 +362,54 @@ int VideoWin::EnterIframePlayback()
       CLSCTX_INPROC_SERVER,IID_IBaseFilter,(void**) &dsvmrrenderer)!=S_OK) {
       Log::getInstance()->log("VideoWin", Log::WARN ,"Failed creating VMR9 renderer!");
       ReleaseMutex(filtermutex);
-    CleanupDS();
-    return 0;
+         CleanupDS();
+         return 0;
     }
       /*VMR 9 stuff**/
     if (hres=dsgraphbuilder->AddFilter(dsvmrrenderer,L"VMR9")!=S_OK) {
       Log::getInstance()->log("VideoWin", Log::WARN ,"Failed adding VMR9 renderer!");
       ReleaseMutex(filtermutex);
-    CleanupDS();
+         CleanupDS();
       return 0;
     }
     IVMRFilterConfig9* vmrfilconfig;
     if (dsvmrrenderer->QueryInterface(IID_IVMRFilterConfig9,(void**)&vmrfilconfig)!=S_OK) {
       ReleaseMutex(filtermutex);
-    CleanupDS();
+         CleanupDS();
       Log::getInstance()->log("VideoWin", Log::WARN ,"Failed getting VMR9 Filterconfig interface!");
-
+      
       return 0;
     }
     vmrfilconfig->SetRenderingMode(VMR9Mode_Renderless);
     vmrfilconfig->Release();
 
-    if (dsvmrrenderer->QueryInterface(IID_IVMRSurfaceAllocatorNotify9,(void**)& dsvmrsurfnotify)!=S_OK) {
+    if (dsvmrrenderer->QueryInterface(IID_IVMRSurfaceAllocatorNotify9,(void**)& dsvmrsurfnotify)!=S_OK) { 
       Log::getInstance()->log("VideoWin", Log::WARN ,"Failed getting VMR9 Surface Allocator interface!");
       ReleaseMutex(filtermutex);
-    CleanupDS();
+         CleanupDS();
       return 0;
     }
     allocatorvmr=new DsAllocator();
     dsvmrsurfnotify->AdviseSurfaceAllocator(NULL,allocatorvmr);
     allocatorvmr->AdviseNotify(dsvmrsurfnotify);
-
+       
     /*VMR 9 stuff end */
     IFilterGraph2*fg2=NULL;
     if (dsgraphbuilder->QueryInterface(IID_IFilterGraph2,(void**)&fg2)!=S_OK) {
       Log::getInstance()->log("VideoWin", Log::WARN , "Failed querying for FilterGraph2 Interface!");
       ReleaseMutex(filtermutex);
-    CleanupDS();
+         CleanupDS();
       return 0;
     }
     if (hres=fg2->RenderEx((IPin*)sourcefilter->GetVideoPin()/*video*/,
         AM_RENDEREX_RENDERTOEXISTINGRENDERERS,NULL)!=S_OK) {
       Log::getInstance()->log("VideoWin", Log::WARN , "Failed rendering Video!");
-    fg2->Release();
-    ReleaseMutex(filtermutex);
+         fg2->Release();
+         ReleaseMutex(filtermutex);
       CleanupDS();
       return 0;
     }
-  fg2->Release();
+       fg2->Release();
    }
 #endif
 /*   if (hres=CoCreateInstance(CLSID_SystemClock,NULL,CLSCTX_INPROC_SERVER,
@@ -419,9 +421,9 @@ int VideoWin::EnterIframePlayback()
    dsmediafilter->SetSyncSource(/*dsrefclock*/NULL); //Run as fast as you can!
 
    dsgraphbuilder->QueryInterface(IID_IMediaControl,(void **) &dsmediacontrol);
-   dsgraphbuilder->QueryInterface(IID_IBasicAudio,(void **) &dsbasicaudio);
+   dsgraphbuilder->QueryInterface(IID_IBasicAudio,(void **) &dsbasicaudio);    
   dsinited=true;
-
+  
 
    dsmediacontrol->Run();
    ReleaseMutex(filtermutex);
@@ -450,7 +452,7 @@ int VideoWin::stop()
 int VideoWin::reset()
 {
   if (!initted) return 0;
-
+  
 
   return 1;
 }
@@ -478,7 +480,7 @@ int VideoWin::dspause()
 int VideoWin::pause()
 {
   if (!initted) return 0;
-
+  
   return 1;
 }
 
@@ -508,7 +510,7 @@ int VideoWin::fastForward()
 int VideoWin::unFastForward()
 {
   if (!initted) return 0;
-
+  
   return 1;
 }
 
@@ -526,22 +528,22 @@ int VideoWin::blank(void)
 
 ULLONG VideoWin::getCurrentTimestamp()
 {
-  REFERENCE_TIME startoffset;
-  REFERENCE_TIME ncr_time;
+       REFERENCE_TIME startoffset;
+       REFERENCE_TIME ncr_time;
   if (iframemode) return 0; //Not in iframe mode!
   if (!dsrefclock || !sourcefilter) return 0;
-  FILTER_STATE state;
-  sourcefilter->GetState(10,&state);
+       FILTER_STATE state;
+       sourcefilter->GetState(10,&state);
 
-  if (state==State_Running) dsrefclock->GetTime(&cr_time);
-  ncr_time=cr_time;
+       if (state==State_Running) dsrefclock->GetTime(&cr_time);
+       ncr_time=cr_time;
   startoffset=sourcefilter->getStartOffset();
-  ncr_time-=startoffset;
-  ncr_time-=lastreftimeRT;
+       ncr_time-=startoffset;
+       ncr_time-=lastreftimeRT;
  /* ULLONG result=frameNumberToTimecode(
     VDR::getInstance()->frameNumberFromPosition(lastreftimeBYTE));*/
-  ULLONG result=lastreftimePTS;
-  result+=(ULLONG)(ncr_time/10000LL*90LL);
+       ULLONG result=lastreftimePTS;
+       result+=(ULLONG)(ncr_time/10000LL*90LL);
   return result;
 
 }
@@ -572,8 +574,8 @@ void VideoWin::CleanupDS()
     cur_video_media_sample=NULL;
   }
   if (dsbasicaudio) {
-    dsbasicaudio->Release();
-    dsbasicaudio=NULL;
+         dsbasicaudio->Release();
+         dsbasicaudio=NULL;
   }
   if (dsvmrsurfnotify) {
     dsvmrsurfnotify->Release();
@@ -609,9 +611,9 @@ void VideoWin::CleanupDS()
 #ifdef DS_DEBUG
     RemoveFromRot(graphidentifier);
 #endif
-  dsgraphbuilder->Release();
+       dsgraphbuilder->Release();
     dsgraphbuilder=NULL;
-
+       
     sourcefilter=NULL; //The Graph Builder destroys our SourceFilter
   }
   ReleaseMutex(filtermutex);
@@ -639,18 +641,18 @@ UINT VideoWin::DeliverMediaPacket(MediaPacket packet,
      UINT *samplepos)
 {
   /*First Check, if we have an audio sample*/
-  if (!isdsinited()) return 0;
+       if (!isdsinited()) return 0;
 #ifdef DO_VIDEO
-  if (!videoon) {
-    *samplepos+=packet.length;
+       if (!videoon) {
+         *samplepos+=packet.length;
        MILLISLEEP(0); //yet not implemented//bad idea
        return packet.length;
-  }
+       }
   /*First Check, if we have an audio sample*/
   if (iframemode) {
-    samplepos=0;
-    MILLISLEEP(10);
-    return 0; //Not in iframe mode!
+               samplepos=0;
+               MILLISLEEP(10);
+               return 0; //Not in iframe mode!
   }
   IMediaSample* ms=NULL;
   REFERENCE_TIME reftime1=0;
@@ -688,7 +690,7 @@ UINT VideoWin::DeliverMediaPacket(MediaPacket packet,
   UINT ms_length;
   UINT ms_pos;
   UINT haveToCopy;
-
+  
   if (!getCurrentVideoMediaSample(&ms) || ms==NULL) {// get the current sample
     samplepos=0;
     MILLISLEEP(10);
@@ -726,7 +728,7 @@ UINT VideoWin::DeliverMediaPacket(MediaPacket packet,
     else ms->SetPreroll(FALSE);
     /*Timecode handling*/
     lastreftimeRT=reftime1;
-  lastreftimePTS=packet.pts;
+       lastreftimePTS=packet.pts;
 
     }else {
       ms->SetSyncPoint(FALSE);
@@ -840,7 +842,7 @@ long long VideoWin::SetStartOffset(long long curreftime, bool *rsync)
   }
 
   lastrefvideotime=curreftime;
-
+  
   return startoffset;
 
 }
@@ -887,14 +889,15 @@ void VideoWin::ResetTimeOffsets() {
 
 void VideoWin::SetAudioVolume(long volume)
 {
-  if (dsbasicaudio) dsbasicaudio->put_Volume(volume);
+    audiovolume=volume;
+       if (dsbasicaudio) dsbasicaudio->put_Volume(volume);
 }
 
 void VideoWin::displayIFrame(const UCHAR* buffer, UINT length)
 {
-  if (!iframemode) EnterIframePlayback();
+       if (!iframemode) EnterIframePlayback();
 
-  if (!isdsinited()) return ;
+       if (!isdsinited()) return ;
 #ifdef DO_VIDEO
   IMediaSample* ms=NULL;
   REFERENCE_TIME reftime1=0;
@@ -909,7 +912,7 @@ void VideoWin::displayIFrame(const UCHAR* buffer, UINT length)
   DWORD ms_length;
   ms->GetPointer(&ms_buf);
   ms_length=ms->GetSize();
-
+  
   /*First Check, if we have an video sample*/
   DWORD read_pos = 0, write_pos = 0;
   DWORD pattern, packet_length;
@@ -925,44 +928,44 @@ void VideoWin::displayIFrame(const UCHAR* buffer, UINT length)
       read_pos++;
     else
     {
-    headerstrip=buffer[read_pos+8]+9/*is this right*/;
+         headerstrip=buffer[read_pos+8]+9/*is this right*/;
       packet_length = ((buffer[read_pos+4] << 8) | (buffer[read_pos+5])) + 6;
       if (read_pos + packet_length > length)
         read_pos = length;
       else
       {
-      if ((write_pos+packet_length-headerstrip)>ms_length) {
-        if (first) {
+                 if ((write_pos+packet_length-headerstrip)>ms_length) {
+                         if (first) {
                   ms->SetSyncPoint(TRUE);
                   ms->SetDiscontinuity(TRUE);
                   first=false;
               } else ms->SetSyncPoint(FALSE);
-        ms->SetTime(NULL,NULL);
-        ms->SetMediaTime(NULL, NULL);
-        ms->SetActualDataLength(write_pos);
-        DeliverVideoMediaSample();
-
-        if (!getCurrentVideoMediaSample(&ms) || ms==NULL) {// get the current sample
-        MILLISLEEP(10);
-        return ;
-        }
-        write_pos=0;
-        ms_length=ms->GetSize();
-        ms->GetPointer(&ms_buf);
-      }
-      if (packet_length-headerstrip>0) {
-      memcpy(ms_buf+write_pos, buffer+read_pos+headerstrip, packet_length-headerstrip);
-      write_pos += packet_length-headerstrip;
-      }
-      read_pos += packet_length;
-
-      pattern = (buffer[read_pos] << 16) | (buffer[read_pos+1] << 8)
+                         ms->SetTime(NULL,NULL);
+                         ms->SetMediaTime(NULL, NULL);
+                         ms->SetActualDataLength(write_pos);
+                         DeliverVideoMediaSample();
+
+                         if (!getCurrentVideoMediaSample(&ms) || ms==NULL) {// get the current sample
+                               MILLISLEEP(10);
+                               return ;
+                         }
+                         write_pos=0;
+                         ms_length=ms->GetSize();
+                         ms->GetPointer(&ms_buf);
+                 }
+                 if (packet_length-headerstrip>0) {
+                       memcpy(ms_buf+write_pos, buffer+read_pos+headerstrip, packet_length-headerstrip);
+                       write_pos += packet_length-headerstrip;
+                 }
+                 read_pos += packet_length;
+                 
+                 pattern = (buffer[read_pos] << 16) | (buffer[read_pos+1] << 8)
                                         | (buffer[read_pos+2]);
       }
     }
   }
 
-  if (first) {ms->SetSyncPoint(TRUE);first=false;}
+  if (first) {ms->SetSyncPoint(TRUE);first=false;} 
   else ms->SetSyncPoint(FALSE);
   ms->SetTime(NULL,NULL);
   ms->SetMediaTime(NULL, NULL);
@@ -990,7 +993,7 @@ bool VideoWin::changeAType(int type,IMediaSample* ms){
         lastaudiomode=type;
         return sourcefilter->changeAType(type,ms);
     }
-    else
+    else 
     {
         return false;
     }
@@ -1011,3 +1014,4 @@ int VideoWin::test2()
 
 
 
+
index 2a64edfd279924f74944786f130e14b707f74316..d8ec9ea8f9d8dc623af050f7cfdfce2c9d309840 100644 (file)
@@ -58,18 +58,18 @@ class VideoWin : public Video
     int setPosition(int x, int y);
     int sync();
     int play();
-  int dsplay();
-  bool InIframemode() {return iframemode;};
+       int dsplay();
+       bool InIframemode() {return iframemode;};
     int stop();
-  int dsstop();
+       int dsstop();
     int pause();
-  int dspause();
+       int dspause();
     int unPause();
-  int dsunPause();
+       int dsunPause();
     int fastForward();
     int unFastForward();
     int reset();
-  int dsreset();
+       int dsreset();
     int blank();
     int signalOn();
     int signalOff();
@@ -99,11 +99,11 @@ class VideoWin : public Video
   virtual void ResetTimeOffsets();
 
     void SetAudioState(bool state){audioon=state;};
-  void SetAudioVolume(long volume);
+       void SetAudioVolume(long volume);
 
     void turnVideoOn(){videoon=true;};
     void turnVideoOff(){videoon=false;};
-
+       
     virtual void displayIFrame(const UCHAR* buffer, UINT length);
 
   unsigned int getPosx() {return videoposx;};
@@ -152,6 +152,7 @@ private:
   unsigned int videoposx;
   unsigned int videoposy;
   int lastaudiomode;
+  int audiovolume;
 #ifdef DS_DEBUG
   DWORD graphidentifier;
 #endif
@@ -160,3 +161,4 @@ private:
 #endif
 
 
+