]> git.sesse.net Git - vlc/blobdiff - modules/access/bda/bdagraph.cpp
broken avi dialog: don't confuse user by asking a binary answer
[vlc] / modules / access / bda / bdagraph.cpp
index c14a1b291c959a9dfc5645668add431f5a02d859..4864d226d283ed3e5d2acc8062d47efb2f5d1d27 100644 (file)
@@ -41,6 +41,13 @@ extern "C" {
         delete p_access->p_sys->p_bda_module;
     };
 
+    int dvb_SubmitCQAMTuneRequest( access_t* p_access )
+    {
+        if( p_access->p_sys->p_bda_module )
+            return p_access->p_sys->p_bda_module->SubmitCQAMTuneRequest();
+        return VLC_EGENERIC;
+    };
+
     int dvb_SubmitATSCTuneRequest( access_t* p_access )
     {
         if( p_access->p_sys->p_bda_module )
@@ -157,6 +164,99 @@ BDAGraph::~BDAGraph()
     CoUninitialize();
 }
 
+/*****************************************************************************
+* Submit an Clear QAM Tune Request (US Cable Shit)
+*****************************************************************************/
+int BDAGraph::SubmitCQAMTuneRequest()
+{
+    HRESULT hr = S_OK;
+    class localComPtr
+    {
+        public:
+        IDigitalCableTuneRequest* p_cqam_tune_request;
+        IDigitalCableLocator* p_cqam_locator;
+        localComPtr(): p_cqam_tune_request(NULL), p_cqam_locator(NULL) {};
+        ~localComPtr()
+        {
+            if( p_cqam_tune_request )
+                p_cqam_tune_request->Release();
+            if( p_cqam_locator )
+                p_cqam_locator->Release();
+        }
+    } l;
+    long l_minor_channel, l_physical_channel, l_frequency;
+
+    l_physical_channel = var_GetInteger( p_access, "dvb-physical-channel" );
+    l_minor_channel    = var_GetInteger( p_access, "dvb-minor-channel" );
+    l_frequency        = var_GetInteger( p_access, "dvb-frequency" );
+
+    guid_network_type = CLSID_DigitalCableNetworkType;
+    hr = CreateTuneRequest();
+    if( FAILED( hr ) )
+    {
+        msg_Warn( p_access, "SubmitCQAMTuneRequest: "\
+            "Cannot create Tuning Space: hr=0x%8lx", hr );
+        return VLC_EGENERIC;
+    }
+
+    hr = p_tune_request->QueryInterface( IID_IDigitalCableTuneRequest,
+        (void**)&l.p_cqam_tune_request );
+    if( FAILED( hr ) )
+    {
+        msg_Warn( p_access, "SubmitCQAMTuneRequest: "\
+            "Cannot QI for IDigitalCableTuneRequest: hr=0x%8lx", hr );
+        return VLC_EGENERIC;
+    }
+    hr = ::CoCreateInstance( CLSID_DigitalCableLocator, 0, CLSCTX_INPROC,
+                             IID_IDigitalCableLocator, (void**)&l.p_cqam_locator );
+    if( FAILED( hr ) )
+    {
+        msg_Warn( p_access, "SubmitCQAMTuneRequest: "\
+            "Cannot create the CQAM locator: hr=0x%8lx", hr );
+        return VLC_EGENERIC;
+    }
+
+    hr = S_OK;
+    if( SUCCEEDED( hr ) && l_physical_channel > 0 )
+        hr = l.p_cqam_locator->put_PhysicalChannel( l_physical_channel );
+    if( SUCCEEDED( hr ) && l_frequency > 0 )
+        hr = l.p_cqam_locator->put_CarrierFrequency( l_frequency );
+    if( SUCCEEDED( hr ) && l_minor_channel > 0 )
+        hr = l.p_cqam_tune_request->put_MinorChannel( l_minor_channel );
+    if( FAILED( hr ) )
+    {
+        msg_Warn( p_access, "SubmitCQAMTuneRequest: "\
+            "Cannot set tuning parameters: hr=0x%8lx", hr );
+        return VLC_EGENERIC;
+    }
+
+    hr = p_tune_request->put_Locator( l.p_cqam_locator );
+    if( FAILED( hr ) )
+    {
+        msg_Warn( p_access, "SubmitCQAMTuneRequest: "\
+            "Cannot put the locator: hr=0x%8lx", hr );
+        return VLC_EGENERIC;
+    }
+
+    /* Build and Run the Graph. If a Tuner device is in use the graph will
+     * fail to run. Repeated calls to build will check successive tuner
+     * devices */
+    do
+    {
+        hr = Build();
+        if( FAILED( hr ) )
+        {
+            msg_Warn( p_access, "SubmitCQAMTuneRequest: "\
+                "Cannot Build the Graph: hr=0x%8lx", hr );
+            return VLC_EGENERIC;
+        }
+        hr = Start();
+    }
+    while( hr != S_OK );
+
+    return VLC_SUCCESS;
+}
+
 /*****************************************************************************
 * Submit an ATSC Tune Request
 *****************************************************************************/
@@ -911,7 +1011,7 @@ HRESULT BDAGraph::CreateTuneRequest()
 
             /* Test for a specific Tuning space name supplied on the command
              * line as dvb-networkname=xxx */
-            if( strlen( l.psz_network_name ) == 0 ||
+            if( *l.psz_network_name == '\0' ||
                 strcmp( l.psz_network_name, l.psz_bstr_name ) == 0 )
             {
                 msg_Dbg( p_access, "CreateTuneRequest: Using Tuning Space: %s",
@@ -1001,7 +1101,7 @@ HRESULT BDAGraph::CreateTuneRequest()
             l.psz_bstr_name = new char[ l.i_name_len ];
             l.i_name_len = WideCharToMultiByte( CP_ACP, 0, l.bstr_name, -1,
                 l.psz_bstr_name, l.i_name_len, NULL, NULL );
-            if( strlen( l.psz_network_name ) == 0 ||
+            if( *l.psz_network_name == '\0' ||
                 strcmp( l.psz_network_name, l.psz_bstr_name ) == 0 )
             {
                 msg_Dbg( p_access, "CreateTuneRequest: Using Tuning Space: %s",
@@ -1188,8 +1288,7 @@ HRESULT BDAGraph::Build()
     if( FAILED( hr ) )
     {
         msg_Warn( p_access, "Build: "\
-            "Cannot save Tuning Space: hr=0x%8lx", hr );
-        return hr;
+            "Cannot save Tuning Space: hr=0x%8lx (ignored)", hr );
     }
 
     /* If we have already have a filter graph, rebuild it*/
@@ -1205,14 +1304,22 @@ HRESULT BDAGraph::Build()
     }
 
     /* First filter in the graph is the Network Provider and
-     * its Scanning Tuner which takes the Tune Request*/
-    hr = ::CoCreateInstance( guid_network_type, NULL, CLSCTX_INPROC_SERVER,
+     * its Scanning Tuner which takes the Tune Request
+     * Try to build the Win 7 Universal Network Provider first*/
+    hr = ::CoCreateInstance( CLSID_NetworkProvider, NULL, CLSCTX_INPROC_SERVER,
         IID_IBaseFilter, (void**)&p_network_provider);
     if( FAILED( hr ) )
     {
         msg_Warn( p_access, "Build: "\
-            "Cannot CoCreate Network Provider: hr=0x%8lx", hr );
-        return hr;
+            "Cannot CoCreate the Universal Network Provider, trying the old way...");
+        hr = ::CoCreateInstance( guid_network_type, NULL, CLSCTX_INPROC_SERVER,
+            IID_IBaseFilter, (void**)&p_network_provider);
+        if( FAILED( hr ) )
+        {
+            msg_Warn( p_access, "Build: "\
+                "Cannot CoCreate Network Provider: hr=0x%8lx", hr );
+            return hr;
+        }
     }
     hr = p_filter_graph->AddFilter( p_network_provider, L"Network Provider" );
     if( FAILED( hr ) )
@@ -1222,30 +1329,6 @@ HRESULT BDAGraph::Build()
         return hr;
     }
 
-    hr = p_network_provider->QueryInterface( IID_IScanningTuner,
-        (void**)&p_scanning_tuner );
-    if( FAILED( hr ) )
-    {
-        msg_Warn( p_access, "Build: "\
-            "Cannot QI Network Provider for Scanning Tuner: hr=0x%8lx", hr );
-        return hr;
-    }
-
-    hr = p_scanning_tuner->Validate( p_tune_request );
-    if( FAILED( hr ) )
-    {
-        msg_Warn( p_access, "Build: "\
-            "Tune Request is invalid: hr=0x%8lx", hr );
-        return hr;
-    }
-    hr = p_scanning_tuner->put_TuneRequest( p_tune_request );
-    if( FAILED( hr ) )
-    {
-        msg_Warn( p_access, "Build: "\
-            "Cannot submit the tune request: hr=0x%8lx", hr );
-        return hr;
-    }
-
     /* Add the Network Tuner to the Network Provider. On subsequent calls,
      * l_tuner_used will cause a different tuner to be selected
      * To select a specific device first get the parameter that nominates the
@@ -1291,6 +1374,31 @@ HRESULT BDAGraph::Build()
         msg_Warn( p_access, "Build: "\
             "Cannot find Capture device. Connecting to tuner: hr=0x%8lx", hr );
     }
+
+    hr = p_network_provider->QueryInterface( IID_IScanningTuner,
+        (void**)&p_scanning_tuner );
+    if( FAILED( hr ) )
+    {
+        msg_Warn( p_access, "Build: "\
+            "Cannot QI Network Provider for Scanning Tuner: hr=0x%8lx", hr );
+        return hr;
+    }
+
+    hr = p_scanning_tuner->Validate( p_tune_request );
+    if( FAILED( hr ) )
+    {
+        msg_Warn( p_access, "Build: "\
+            "Tune Request is invalid: hr=0x%8lx", hr );
+        //return hr; it is not mandatory to validate. Validate fails, but the request is successfully accepted
+    }
+    hr = p_scanning_tuner->put_TuneRequest( p_tune_request );
+    if( FAILED( hr ) )
+    {
+        msg_Warn( p_access, "Build: "\
+            "Cannot submit the tune request: hr=0x%8lx", hr );
+        return hr;
+    }
+
     if( p_sample_grabber )
          p_sample_grabber->Release();
     p_sample_grabber = NULL;