]> git.sesse.net Git - vlc/blobdiff - modules/access/dshow/crossbar.cpp
Removes trailing spaces. Removes tabs.
[vlc] / modules / access / dshow / crossbar.cpp
index bdff328ceaa6915abb8a59cbf8304b5cf6f28ea5..6fb5908174736cb55bb00c1a8e3df3b25f2b2399 100644 (file)
@@ -1,7 +1,7 @@
 /*****************************************************************************
  * crossbar.c : DirectShow access module for vlc
  *****************************************************************************
- * Copyright (C) 2002 VideoLAN
+ * Copyright (C) 2002 the VideoLAN team
  * $Id$
  *
  * Author: Damien Fouilleul <damien dot fouilleul at laposte dot net>
  *
  * You should have received a copy of the GNU General Public License
  * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
  *****************************************************************************/
 
 /*****************************************************************************
  * Preamble
  *****************************************************************************/
-#include <stdlib.h>
-#include <stdio.h>
-#include <string.h>
 
 #include <vlc/vlc.h>
-#include <vlc/input.h>
-#include <vlc/vout.h>
+#include <vlc_vout.h>
 
 #ifndef _MSC_VER
     /* Work-around a bug in w32api-2.5 */
@@ -74,13 +70,13 @@ static HRESULT GetCrossbarIPinAtIndex( IAMCrossbar *pXbar, LONG PinIndex,
 
     if( pXbar->QueryInterface(IID_IBaseFilter, (void **)&pFilter) == S_OK )
     {
-        if( SUCCEEDED(pFilter->EnumPins(&pins)) ) 
+        if( SUCCEEDED(pFilter->EnumPins(&pins)) )
         {
             LONG i = 0;
-            while( pins->Next(1, &pP, &n) == S_OK ) 
+            while( pins->Next(1, &pP, &n) == S_OK )
             {
                 pP->Release();
-                if( i == TrueIndex ) 
+                if( i == TrueIndex )
                 {
                     *ppPin = pP;
                     break;
@@ -92,7 +88,7 @@ static HRESULT GetCrossbarIPinAtIndex( IAMCrossbar *pXbar, LONG PinIndex,
         pFilter->Release();
     }
 
-    return *ppPin ? S_OK : E_FAIL; 
+    return *ppPin ? S_OK : E_FAIL;
 }
 
 /*****************************************************************************
@@ -136,7 +132,7 @@ static HRESULT GetCrossbarIndexFromIPin( IAMCrossbar * pXbar, LONG * PinIndex,
         pFilter->Release();
     }
 
-    return fOK ? S_OK : E_FAIL; 
+    return fOK ? S_OK : E_FAIL;
 }
 
 /*****************************************************************************
@@ -178,8 +174,8 @@ HRESULT FindCrossbarRoutes( vlc_object_t *p_this, access_sys_t *p_sys,
     }
 
     LONG inputPinIndexRelated, outputPinIndexRelated;
-    LONG inputPinPhysicalType, outputPinPhysicalType;
-    LONG inputPinIndex, outputPinIndex;
+    LONG inputPinPhysicalType = 0, outputPinPhysicalType;
+    LONG inputPinIndex = 0, outputPinIndex;
     if( FAILED(GetCrossbarIndexFromIPin( pXbar, &outputPinIndex,
                                          FALSE, p_output_pin )) ||
         FAILED(pXbar->get_CrossbarPinInfo( FALSE, outputPinIndex,
@@ -192,21 +188,52 @@ HRESULT FindCrossbarRoutes( vlc_object_t *p_this, access_sys_t *p_sys,
         return S_FALSE;
     }
 
+    /*
+    ** if physical type is 0, then use default/existing route to physical connector
+    */
+    if( physicalType == 0 )
+    {
+        /* use following as default connector type if we fail to find an existing route */
+        physicalType = PhysConn_Video_Tuner;
+        if( SUCCEEDED(pXbar->get_IsRoutedTo(outputPinIndex, &inputPinIndex)) )
+        {
+
+            if( SUCCEEDED( pXbar->get_CrossbarPinInfo( TRUE,  inputPinIndex,
+                           &inputPinIndexRelated, &inputPinPhysicalType )) )
+            {
+                // remember connector type
+                physicalType = inputPinPhysicalType;
+                msg_Dbg( p_this, "found existing route for output %ld (type %ld) to input %ld (type %ld)",
+                         outputPinIndex, outputPinPhysicalType, inputPinIndex,
+                         inputPinPhysicalType );
+                // fall through to for loop, note 'inputPinIndex' is set to the pin we are looking for
+                // hence, loop iteration should not wind back
+
+            }
+        }
+        else {
+            // reset to first pin for complete loop iteration
+            inputPinIndex = 0;
+        }
+    }
     //
     // for all input pins
     //
-    for( inputPinIndex = 0; S_OK != result && inputPinIndex < inputPinCount;
-         inputPinIndex++ ) 
+    for( /* inputPinIndex has been set */ ; (S_OK != result) && (inputPinIndex < inputPinCount); ++inputPinIndex )
     {
         if( FAILED(pXbar->get_CrossbarPinInfo( TRUE,  inputPinIndex,
-                &inputPinIndexRelated, &inputPinPhysicalType )) ) continue;
-   
-        // Is the pin a video pin?
+            &inputPinIndexRelated, &inputPinPhysicalType )) ) continue;
+
+        // Is this pin matching required connector physical type?
         if( inputPinPhysicalType != physicalType ) continue;
 
         // Can we route it?
         if( FAILED(pXbar->CanRoute(outputPinIndex, inputPinIndex)) ) continue;
-
         IPin *pPin;
         if( FAILED(GetCrossbarIPinAtIndex( pXbar, inputPinIndex,
                                            TRUE, &pPin)) ) continue;
@@ -218,7 +245,7 @@ HRESULT FindCrossbarRoutes( vlc_object_t *p_this, access_sys_t *p_sys,
             physicalType == inputPinPhysicalType &&
             (p_sys->i_crossbar_route_depth = depth+1) < MAX_CROSSBAR_DEPTH) )
         {
-            // hold on crossbar
+            // hold on crossbar, will be released when graph is destroyed
             pXbar->AddRef();
 
             // remember crossbar route
@@ -228,8 +255,8 @@ HRESULT FindCrossbarRoutes( vlc_object_t *p_this, access_sys_t *p_sys,
             p_sys->crossbar_routes[depth].AudioInputIndex = inputPinIndexRelated;
             p_sys->crossbar_routes[depth].AudioOutputIndex = outputPinIndexRelated;
 
-            msg_Dbg( p_this, "Crossbar at depth %d, Found Route For "
-                     "ouput %ld (type %ld) to input %ld (type %ld)", depth,
+            msg_Dbg( p_this, "crossbar at depth %d, found route for "
+                     "output %ld (type %ld) to input %ld (type %ld)", depth,
                      outputPinIndex, outputPinPhysicalType, inputPinIndex,
                      inputPinPhysicalType );