]> git.sesse.net Git - vlc/blobdiff - modules/access/dshow/dshow.cpp
* modules/access/dshow: some more debug messages.
[vlc] / modules / access / dshow / dshow.cpp
index 5d9473d122e16c0dfcf45b9e3579aaf87a7edd16..56abcf0b36a2fe9ed5285e8dd4f710454094dba6 100644 (file)
@@ -57,8 +57,11 @@ static int FindDevicesCallback( vlc_object_t *, char const *,
 static int ConfigDevicesCallback( vlc_object_t *, char const *,
                                   vlc_value_t, vlc_value_t, void * );
 
-static void PropertiesPage( vlc_object_t *, IBaseFilter *,
-                            ICaptureGraphBuilder2 *, vlc_bool_t );
+static void ShowPropertyPage( IUnknown * );
+static void ShowDeviceProperties( vlc_object_t *, ICaptureGraphBuilder2 *, 
+                                  IBaseFilter *, vlc_bool_t );
+static void ShowTunerProperties( vlc_object_t *, ICaptureGraphBuilder2 *, 
+                                 IBaseFilter *, vlc_bool_t );
 
 /*****************************************************************************
  * Module descriptor
@@ -95,6 +98,9 @@ static char *ppsz_adev_text[] = { N_("Default"), N_("None") };
 #define CONFIG_LONGTEXT N_( \
     "Show the properties dialog of the selected device before starting the " \
     "stream.")
+#define TUNER_TEXT N_("Tuner properties")
+#define TUNER_LONGTEXT N_( \
+    "Show the tuner properties [channel selection] page." )
 
 static int  CommonOpen ( vlc_object_t *, access_sys_t *, vlc_bool_t );
 static void CommonClose( vlc_object_t *, access_sys_t * );
@@ -129,6 +135,9 @@ vlc_module_begin();
     add_bool( "dshow-config", VLC_FALSE, NULL, CONFIG_TEXT, CONFIG_LONGTEXT,
               VLC_FALSE );
 
+    add_bool( "dshow-tuner", VLC_FALSE, NULL, TUNER_TEXT, TUNER_LONGTEXT,
+              VLC_FALSE );
+
     add_shortcut( "dshow" );
     set_capability( "access_demux", 0 );
     set_callbacks( DemuxOpen, DemuxClose );
@@ -236,7 +245,8 @@ static int CommonOpen( vlc_object_t *p_this, access_sys_t *p_sys,
     int i_width = 0, i_height = 0, i_chroma = 0;
     vlc_bool_t b_audio = VLC_TRUE;
 
-    var_Create( p_this, "dshow-config", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
+    var_Create( p_this, "dshow-config", VLC_VAR_BOOL | VLC_VAR_DOINHERIT );
+    var_Create( p_this, "dshow-tuner", VLC_VAR_BOOL | VLC_VAR_DOINHERIT );
 
     var_Create( p_this, "dshow-vdev", VLC_VAR_STRING | VLC_VAR_DOINHERIT );
     var_Get( p_this, "dshow-vdev", &val );
@@ -339,7 +349,7 @@ static int CommonOpen( vlc_object_t *p_this, access_sys_t *p_sys,
         msg_Err( p_this, "can't open audio");
     }
 
-    for( i = 0; i < p_sys->i_crossbar_route_depth; i++ )
+    for( i = p_sys->i_crossbar_route_depth-1; i >= 0 ; --i )
     {
         IAMCrossbar *pXbar = p_sys->crossbar_routes[i].pXbar;
         LONG VideoInputIndex = p_sys->crossbar_routes[i].VideoInputIndex;
@@ -366,6 +376,26 @@ static int CommonOpen( vlc_object_t *p_this, access_sys_t *p_sys,
         }
     }
 
+    /*
+    ** Show properties pages from other filters in graph
+    */
+    var_Get( p_this, "dshow-config", &val );
+    if( val.b_bool )
+    {
+        for( i = p_sys->i_crossbar_route_depth-1; i >= 0 ; --i )
+        {
+            IAMCrossbar *pXbar = p_sys->crossbar_routes[i].pXbar;
+            IBaseFilter *p_XF;
+
+            if( SUCCEEDED( pXbar->QueryInterface( IID_IBaseFilter,
+                                                  (void **)&p_XF ) ) )
+            {
+                ShowPropertyPage( p_XF );
+                p_XF->Release();
+            }
+        }
+    }
+
     /* Initialize some data */
     p_sys->i_current_stream = 0;
     vlc_mutex_init( p_this, &p_sys->lock );
@@ -428,9 +458,9 @@ static int DemuxOpen( vlc_object_t *p_this )
             if( p_stream->i_fourcc == VLC_FOURCC('R','V','2','4') )
             {
                 /* This is in BGR format */
-              fmt.video.i_bmask = 0x00ff0000;
-              fmt.video.i_gmask = 0x0000ff00;
-              fmt.video.i_rmask = 0x000000ff;
+                fmt.video.i_bmask = 0x00ff0000;
+                fmt.video.i_gmask = 0x0000ff00;
+                fmt.video.i_rmask = 0x000000ff;
             }
         }
         else if( p_stream->mt.majortype == MEDIATYPE_Audio )
@@ -609,8 +639,7 @@ static bool ConnectFilters( vlc_object_t *p_this, access_sys_t *p_sys,
                             if( guid == PIN_CATEGORY_ANALOGVIDEOIN )
                             {
                                 // recursively search crossbar routes
-                                FindCrossbarRoutes( p_this, p_sys, pP,
-                                                    PhysConn_Video_Tuner );
+                                FindCrossbarRoutes( p_this, p_sys, pP, 0 );
                                 // found it
                                 Found = TRUE;
                             }
@@ -724,48 +753,12 @@ static int OpenDevice( vlc_object_t *p_this, access_sys_t *p_sys,
         return VLC_EGENERIC;
     }
 
-    AM_MEDIA_TYPE *mt;
-    AM_MEDIA_TYPE media_types[MAX_MEDIA_TYPES];
-
-    size_t mt_count = EnumDeviceCaps( p_this, p_device_filter, p_sys->i_chroma,
-                                      p_sys->i_width, p_sys->i_height,
-                                      0, 0, 0, media_types, MAX_MEDIA_TYPES );
-
-    if( mt_count > 0 )
-    {
-        mt = (AM_MEDIA_TYPE *)malloc( sizeof(AM_MEDIA_TYPE)*mt_count );
+    size_t mt_count = 0;
+    AM_MEDIA_TYPE *mt = NULL;
 
-        // Order and copy returned media types according to arbitrary
-        // fourcc priority
-        for( size_t c = 0; c < mt_count; c++ )
-        {
-            int slot_priority =
-                GetFourCCPriority(GetFourCCFromMediaType(media_types[c]));
-            size_t slot_copy = c;
-            for( size_t d = c+1; d < mt_count; d++ )
-            {
-                int priority =
-                    GetFourCCPriority(GetFourCCFromMediaType(media_types[d]));
-                if( priority > slot_priority )
-                {
-                    slot_priority = priority;
-                    slot_copy = d;
-                }
-            }
-            if( slot_copy != c )
-            {
-                mt[c] = media_types[slot_copy];
-                media_types[slot_copy] = media_types[c];
-            }
-            else
-            {
-                mt[c] = media_types[c];
-            }
-        }
-    }
-    else if( !b_audio )
+    if( !b_audio )
     {
-        // Use default video media type
+        // Insert prefered video media type
         AM_MEDIA_TYPE mtr;
         VIDEOINFOHEADER vh;
 
@@ -773,7 +766,6 @@ static int OpenDevice( vlc_object_t *p_this, access_sys_t *p_sys,
         mtr.subtype              = MEDIASUBTYPE_I420;
         mtr.bFixedSizeSamples    = TRUE;
         mtr.bTemporalCompression = FALSE;
-        mtr.lSampleSize          = 0;
         mtr.pUnk                 = NULL;
         mtr.formattype           = FORMAT_VideoInfo;
         mtr.cbFormat             = sizeof(vh);
@@ -782,15 +774,14 @@ static int OpenDevice( vlc_object_t *p_this, access_sys_t *p_sys,
         memset(&vh, 0, sizeof(vh));
 
         vh.bmiHeader.biSize   = sizeof(vh.bmiHeader);
-        vh.bmiHeader.biWidth  = p_sys->i_width > 0 ? p_sys->i_width: 320;
+        vh.bmiHeader.biWidth  = p_sys->i_width > 0 ? p_sys->i_width : 320;
         vh.bmiHeader.biHeight = p_sys->i_height > 0 ? p_sys->i_height : 240;
-        vh.bmiHeader.biPlanes      = 1;
+        vh.bmiHeader.biPlanes      = 3;
         vh.bmiHeader.biBitCount    = 12;
         vh.bmiHeader.biCompression = VLC_FOURCC('I','4','2','0');
-        vh.bmiHeader.biSizeImage   = p_sys->i_width * 12 * p_sys->i_height / 8;
-
-        msg_Warn( p_this, "device %s using built-in video media type",
-                  devicename.c_str() );
+        vh.bmiHeader.biSizeImage   = vh.bmiHeader.biWidth * 12 *
+            vh.bmiHeader.biHeight / 8;
+        mtr.lSampleSize            = vh.bmiHeader.biSizeImage;
 
         mt_count = 1;
         mt = (AM_MEDIA_TYPE *)malloc( sizeof(AM_MEDIA_TYPE)*mt_count );
@@ -798,7 +789,7 @@ static int OpenDevice( vlc_object_t *p_this, access_sys_t *p_sys,
     }
     else
     {
-        // Use default audio media type
+        // Insert prefered audio media type
         AM_MEDIA_TYPE mtr;
         WAVEFORMATEX wf;
 
@@ -822,14 +813,53 @@ static int OpenDevice( vlc_object_t *p_this, access_sys_t *p_sys,
         wf.nAvgBytesPerSec = wf.nSamplesPerSec * wf.nBlockAlign;
         wf.cbSize = 0;
 
-        msg_Warn( p_this, "device %s using built-in audio media type",
-                  devicename.c_str() );
-
         mt_count = 1;
         mt = (AM_MEDIA_TYPE *)malloc( sizeof(AM_MEDIA_TYPE)*mt_count );
         CopyMediaType(mt, &mtr);
     }
 
+    // Retreive acceptable media types supported by device
+    AM_MEDIA_TYPE media_types[MAX_MEDIA_TYPES];
+    size_t media_count =
+        EnumDeviceCaps( p_this, p_device_filter, p_sys->i_chroma,
+                        p_sys->i_width, p_sys->i_height,
+                        0, 0, 0, media_types, MAX_MEDIA_TYPES );
+
+    if( media_count > 0 )
+    {
+        mt = (AM_MEDIA_TYPE *)realloc( mt, sizeof(AM_MEDIA_TYPE) *
+                                       (mt_count + media_count) );
+
+        // Order and copy returned media types according to arbitrary
+        // fourcc priority
+        for( size_t c = 0; c < media_count; c++ )
+        {
+            int slot_priority =
+                GetFourCCPriority(GetFourCCFromMediaType(media_types[c]));
+            size_t slot_copy = c;
+            for( size_t d = c+1; d < media_count; d++ )
+            {
+                int priority =
+                    GetFourCCPriority(GetFourCCFromMediaType(media_types[d]));
+                if( priority > slot_priority )
+                {
+                    slot_priority = priority;
+                    slot_copy = d;
+                }
+            }
+            if( slot_copy != c )
+            {
+                mt[c+mt_count] = media_types[slot_copy];
+                media_types[slot_copy] = media_types[c];
+            }
+            else
+            {
+                mt[c+mt_count] = media_types[c];
+            }
+        }
+        mt_count += media_count;
+    }
+
     /* Create and add our capture filter */
     CaptureFilter *p_capture_filter =
         new CaptureFilter( p_this, p_sys, mt, mt_count );
@@ -852,15 +882,21 @@ static int OpenDevice( vlc_object_t *p_this, access_sys_t *p_sys,
         dshow_stream.mt =
             p_capture_filter->CustomGetPin()->CustomGetMediaType();
 
-        /* Show properties. Done here so the VLC stream is setup with the
-         * proper parameters. */
+        /* Show Device properties. Done here so the VLC stream is setup with
+         * the proper parameters. */
         vlc_value_t val;
         var_Get( p_this, "dshow-config", &val );
-        if( val.i_int )
+        if( val.b_bool )
+        {
+            ShowDeviceProperties( p_this, p_sys->p_capture_graph_builder2,
+                                  p_device_filter, b_audio );
+        }
+
+        var_Get( p_this, "dshow-tuner", &val );
+        if( val.b_bool )
         {
-            PropertiesPage( p_this, p_device_filter,
-                            p_sys->p_capture_graph_builder2,
-                            dshow_stream.mt.majortype == MEDIATYPE_Audio );
+            ShowTunerProperties( p_this, p_sys->p_capture_graph_builder2,
+                                 p_device_filter, b_audio );
         }
 
         dshow_stream.mt =
@@ -1079,7 +1115,7 @@ static size_t EnumDeviceCaps( vlc_object_t *p_this, IBaseFilter *p_filter,
         AM_MEDIA_TYPE *p_mt;
         while( p_enummt->Next( 1, &p_mt, NULL ) == S_OK )
         {
-            int i_current_fourcc = GetFourCCFromMediaType(*p_mt);
+            int i_current_fourcc = GetFourCCFromMediaType( *p_mt );
             if( i_current_fourcc && p_mt->majortype == MEDIATYPE_Video )
             {
                 int i_current_width = p_mt->pbFormat ?
@@ -1152,6 +1188,10 @@ static size_t EnumDeviceCaps( vlc_object_t *p_this, IBaseFilter *p_filter,
             }
             else if( i_current_fourcc && p_mt->majortype == MEDIATYPE_Stream )
             {
+                msg_Dbg( p_this, "EnumDeviceCaps: input pin "
+                         "accepts stream format: %4.4s",
+                         (char *)&i_current_fourcc );
+
                 if( ( !i_fourcc || i_fourcc == i_current_fourcc ) &&
                     mt_count < mt_max )
                 {
@@ -1163,7 +1203,12 @@ static size_t EnumDeviceCaps( vlc_object_t *p_this, IBaseFilter *p_filter,
             }
             else
             {
-                msg_Dbg( p_this, "EnumDeviceCaps: input pin: unknown format" );
+                char *psz_type = "unknown";
+                if( p_mt->majortype == MEDIATYPE_Video ) psz_type = "video";
+                if( p_mt->majortype == MEDIATYPE_Audio ) psz_type = "audio";
+                if( p_mt->majortype == MEDIATYPE_Stream ) psz_type = "stream";
+                msg_Dbg( p_this, "EnumDeviceCaps: input pin: unknown format "
+                         "(%s %4.4s)", psz_type, (char *)&p_mt->subtype );
                 FreeMediaType( *p_mt );
             }
             CoTaskMemFree( (PVOID)p_mt );
@@ -1509,7 +1554,7 @@ static int ConfigDevicesCallback( vlc_object_t *p_this, char const *psz_name,
         FindCaptureDevice( p_this, &devicename, NULL, b_audio );
     if( p_device_filter )
     {
-        PropertiesPage( p_this, p_device_filter, NULL, b_audio );
+        ShowPropertyPage( p_device_filter );
     }
     else
     {
@@ -1526,47 +1571,45 @@ static int ConfigDevicesCallback( vlc_object_t *p_this, char const *psz_name,
     return VLC_SUCCESS;
 }
 
-static void ShowPropertyPage( IUnknown *obj, CAUUID *cauuid )
+/*****************************************************************************
+ * Properties
+ *****************************************************************************/
+static void ShowPropertyPage( IUnknown *obj )
 {
-    if( cauuid->cElems > 0 )
+    ISpecifyPropertyPages *p_spec;
+    CAUUID cauuid;
+
+    HRESULT hr = obj->QueryInterface( IID_ISpecifyPropertyPages,
+                                      (void **)&p_spec );
+    if( FAILED(hr) ) return;
+
+    if( SUCCEEDED(p_spec->GetPages( &cauuid )) )
     {
-        HWND hwnd_desktop = ::GetDesktopWindow();
+        if( cauuid.cElems > 0 )
+        {
+            HWND hwnd_desktop = ::GetDesktopWindow();
 
-        OleCreatePropertyFrame( hwnd_desktop, 30, 30, NULL, 1, &obj,
-                                cauuid->cElems, cauuid->pElems, 0, 0, NULL );
+            OleCreatePropertyFrame( hwnd_desktop, 30, 30, NULL, 1, &obj,
+                                    cauuid.cElems, cauuid.pElems, 0, 0, NULL );
 
-        CoTaskMemFree( cauuid->pElems );
+            CoTaskMemFree( cauuid.pElems );
+        }
+        p_spec->Release();
     }
 }
 
-static void PropertiesPage( vlc_object_t *p_this, IBaseFilter *p_device_filter,
-                            ICaptureGraphBuilder2 *p_capture_graph,
-                            vlc_bool_t b_audio )
+static void ShowDeviceProperties( vlc_object_t *p_this,
+                                  ICaptureGraphBuilder2 *p_capture_graph,
+                                  IBaseFilter *p_device_filter,
+                                  vlc_bool_t b_audio )
 {
-    CAUUID cauuid;
-
+    HRESULT hr;
     msg_Dbg( p_this, "Configuring Device Properties" );
 
     /*
      * Video or audio capture filter page
      */
-    ISpecifyPropertyPages *p_spec;
-
-    HRESULT hr = p_device_filter->QueryInterface( IID_ISpecifyPropertyPages,
-                                                  (void **)&p_spec );
-    if( SUCCEEDED(hr) )
-    {
-        if( SUCCEEDED(p_spec->GetPages( &cauuid )) )
-        {
-            ShowPropertyPage( p_device_filter, &cauuid );
-        }
-        p_spec->Release();
-    }
-
-    msg_Dbg( p_this, "looking for WDM Configuration Pages" );
-
-    if( p_capture_graph )
-        msg_Dbg( p_this, "got capture graph for WDM Configuration Pages" );
+    ShowPropertyPage( p_device_filter );
 
     /*
      * Audio capture pin
@@ -1575,27 +1618,15 @@ static void PropertiesPage( vlc_object_t *p_this, IBaseFilter *p_device_filter,
     {
         IAMStreamConfig *p_SC;
 
+        msg_Dbg( p_this, "Showing WDM Audio Configuration Pages" );
+
         hr = p_capture_graph->FindInterface( &PIN_CATEGORY_CAPTURE,
                                              &MEDIATYPE_Audio, p_device_filter,
                                              IID_IAMStreamConfig,
                                              (void **)&p_SC );
         if( SUCCEEDED(hr) )
         {
-            hr = p_SC->QueryInterface( IID_ISpecifyPropertyPages,
-                                       (void **)&p_spec );
-            if( SUCCEEDED(hr) )
-            {
-                hr = p_spec->GetPages( &cauuid );
-                if( SUCCEEDED(hr) )
-                {
-                    for( unsigned int c = 0; c < cauuid.cElems; c++ )
-                    {
-                        ShowPropertyPage( p_SC, &cauuid );
-                    }
-                    CoTaskMemFree( cauuid.pElems );
-                }
-                p_spec->Release();
-            }
+            ShowPropertyPage(p_SC);
             p_SC->Release();
         }
 
@@ -1603,20 +1634,12 @@ static void PropertiesPage( vlc_object_t *p_this, IBaseFilter *p_device_filter,
          * TV Audio filter
          */
         IAMTVAudio *p_TVA;
-        hr = p_capture_graph->FindInterface( &PIN_CATEGORY_CAPTURE, 
+        HRESULT hr = p_capture_graph->FindInterface( &PIN_CATEGORY_CAPTURE,
                                              &MEDIATYPE_Audio, p_device_filter,
                                              IID_IAMTVAudio, (void **)&p_TVA );
         if( SUCCEEDED(hr) )
         {
-            hr = p_TVA->QueryInterface( IID_ISpecifyPropertyPages,
-                                        (void **)&p_spec );
-            if( SUCCEEDED(hr) )
-            {
-                if( SUCCEEDED( p_spec->GetPages( &cauuid ) ) )
-                    ShowPropertyPage(p_TVA, &cauuid);
-
-                p_spec->Release();
-            }
+            ShowPropertyPage(p_TVA);
             p_TVA->Release();
         }
     }
@@ -1628,6 +1651,8 @@ static void PropertiesPage( vlc_object_t *p_this, IBaseFilter *p_device_filter,
     {
         IAMStreamConfig *p_SC;
 
+        msg_Dbg( p_this, "Showing WDM Video Configuration Pages" );
+
         hr = p_capture_graph->FindInterface( &PIN_CATEGORY_CAPTURE,
                                              &MEDIATYPE_Interleaved,
                                              p_device_filter,
@@ -1644,83 +1669,22 @@ static void PropertiesPage( vlc_object_t *p_this, IBaseFilter *p_device_filter,
 
         if( SUCCEEDED(hr) )
         {
-            hr = p_SC->QueryInterface( IID_ISpecifyPropertyPages,
-                                       (void **)&p_spec );
-            if( SUCCEEDED(hr) )
-            {
-                if( SUCCEEDED( p_spec->GetPages(&cauuid) ) )
-                {
-                    ShowPropertyPage(p_SC, &cauuid);
-                }
-                p_spec->Release();
-            }
+            ShowPropertyPage(p_SC);
             p_SC->Release();
         }
+    }
+}
 
-        /*
-         * Video crossbar, and a possible second crossbar
-         */
-        IAMCrossbar *p_X, *p_X2;
-        IBaseFilter *p_XF;
-
-        hr = p_capture_graph->FindInterface( &PIN_CATEGORY_CAPTURE,
-                                             &MEDIATYPE_Interleaved,
-                                             p_device_filter,
-                                             IID_IAMCrossbar, (void **)&p_X );
-        if( FAILED(hr) )
-        {
-            hr = p_capture_graph->FindInterface( &PIN_CATEGORY_CAPTURE,
-                                                 &MEDIATYPE_Video,
-                                                 p_device_filter,
-                                                 IID_IAMCrossbar,
-                                                 (void **)&p_X );
-        }
-
-        if( SUCCEEDED(hr) )
-        {
-            hr = p_X->QueryInterface( IID_IBaseFilter, (void **)&p_XF );
-            if( SUCCEEDED(hr) )
-            {
-                hr = p_X->QueryInterface( IID_ISpecifyPropertyPages,
-                                          (void **)&p_spec );
-                if( SUCCEEDED(hr) )
-                {
-                    hr = p_spec->GetPages(&cauuid);
-                    if( hr == S_OK && cauuid.cElems > 0 )
-                    {
-                        ShowPropertyPage( p_X, &cauuid );
-                    }
-                    p_spec->Release();
-                }
-
-                hr = p_capture_graph->FindInterface( &LOOK_UPSTREAM_ONLY, NULL,
-                                                     p_XF, IID_IAMCrossbar,
-                                                     (void **)&p_X2 );
-                if( SUCCEEDED(hr) )
-                {
-                    hr = p_X2->QueryInterface( IID_ISpecifyPropertyPages,
-                                               (void **)&p_spec );
-                    if( SUCCEEDED(hr) )
-                    {
-                        hr = p_spec->GetPages( &cauuid );
-                        if( SUCCEEDED(hr) )
-                        {
-                            ShowPropertyPage( p_X2, &cauuid );
-                        }
-                        p_spec->Release();
-                    }
-                    p_X2->Release();
-                }
-
-                p_XF->Release();
-            }
-
-            p_X->Release();
-        }
+static void ShowTunerProperties( vlc_object_t *p_this,
+                                 ICaptureGraphBuilder2 *p_capture_graph,
+                                 IBaseFilter *p_device_filter,
+                                 vlc_bool_t b_audio )
+{
+    HRESULT hr;
+    msg_Dbg( p_this, "Configuring Tuner Properties" );
 
-        /*
-         * TV Tuner
-         */
+    if( p_capture_graph && !b_audio )
+    {
         IAMTVTuner *p_TV;
         hr = p_capture_graph->FindInterface( &PIN_CATEGORY_CAPTURE,
                                              &MEDIATYPE_Interleaved,
@@ -1737,17 +1701,7 @@ static void PropertiesPage( vlc_object_t *p_this, IBaseFilter *p_device_filter,
 
         if( SUCCEEDED(hr) )
         {
-            hr = p_TV->QueryInterface( IID_ISpecifyPropertyPages,
-                                       (void **)&p_spec );
-            if( SUCCEEDED(hr) )
-            {
-                hr = p_spec->GetPages(&cauuid);
-                if( SUCCEEDED(hr) )
-                {
-                    ShowPropertyPage(p_TV, &cauuid);
-                }
-                p_spec->Release();
-            }
+            ShowPropertyPage(p_TV);
             p_TV->Release();
         }
     }