]> 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 bdcac09ffcdb03a4d368772849da4274fb769602..56abcf0b36a2fe9ed5285e8dd4f710454094dba6 100644 (file)
@@ -59,7 +59,9 @@ static int ConfigDevicesCallback( vlc_object_t *, char const *,
 
 static void ShowPropertyPage( IUnknown * );
 static void ShowDeviceProperties( vlc_object_t *, ICaptureGraphBuilder2 *, 
-                                  IBaseFilter *, vlc_bool_t b_audio );
+                                  IBaseFilter *, vlc_bool_t );
+static void ShowTunerProperties( vlc_object_t *, ICaptureGraphBuilder2 *, 
+                                 IBaseFilter *, vlc_bool_t );
 
 /*****************************************************************************
  * Module descriptor
@@ -96,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 * );
@@ -130,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 );
@@ -223,7 +231,6 @@ static void DeleteDirectShowGraph( access_sys_t *p_sys )
     }
 }
 
-
 /*****************************************************************************
  * CommonOpen: open direct show device
  *****************************************************************************/
@@ -238,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 );
@@ -372,19 +380,20 @@ 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.i_int )
+    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;
-            HRESULT hr = pXbar->QueryInterface( IID_IBaseFilter, (void **)&p_XF );
-            if( SUCCEEDED(hr) )
+
+            if( SUCCEEDED( pXbar->QueryInterface( IID_IBaseFilter,
+                                                  (void **)&p_XF ) ) )
             {
                 ShowPropertyPage( p_XF );
                 p_XF->Release();
             }
-        }        
+        }
     }
 
     /* Initialize some data */
@@ -749,7 +758,7 @@ static int OpenDevice( vlc_object_t *p_this, access_sys_t *p_sys,
 
     if( !b_audio )
     {
-        // insert prefered video media type
+        // Insert prefered video media type
         AM_MEDIA_TYPE mtr;
         VIDEOINFOHEADER vh;
 
@@ -757,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);
@@ -766,12 +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;
+        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 );
@@ -779,7 +789,7 @@ static int OpenDevice( vlc_object_t *p_this, access_sys_t *p_sys,
     }
     else
     {
-        // insert prefered audio media type
+        // Insert prefered audio media type
         AM_MEDIA_TYPE mtr;
         WAVEFORMATEX wf;
 
@@ -808,16 +818,17 @@ static int OpenDevice( vlc_object_t *p_this, access_sys_t *p_sys,
         CopyMediaType(mt, &mtr);
     }
 
-    // retreive acceptable media types supported by device
-    
+    // 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 );
+    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) );
+        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
@@ -871,15 +882,23 @@ static int OpenDevice( vlc_object_t *p_this, access_sys_t *p_sys,
         dshow_stream.mt =
             p_capture_filter->CustomGetPin()->CustomGetMediaType();
 
-        /* Show Device 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 );
+            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 )
+        {
+            ShowTunerProperties( p_this, p_sys->p_capture_graph_builder2,
+                                 p_device_filter, b_audio );
+        }
+
         dshow_stream.mt =
             p_capture_filter->CustomGetPin()->CustomGetMediaType();
 
@@ -1096,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 ?
@@ -1169,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 )
                 {
@@ -1180,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 );
@@ -1544,39 +1572,37 @@ static int ConfigDevicesCallback( vlc_object_t *p_this, char const *psz_name,
 }
 
 /*****************************************************************************
- * properties
+ * Properties
  *****************************************************************************/
-
 static void ShowPropertyPage( IUnknown *obj )
 {
     ISpecifyPropertyPages *p_spec;
+    CAUUID cauuid;
 
     HRESULT hr = obj->QueryInterface( IID_ISpecifyPropertyPages,
-                                                  (void **)&p_spec );
-    if( SUCCEEDED(hr) )
-    {
-        CAUUID cauuid;
+                                      (void **)&p_spec );
+    if( FAILED(hr) ) return;
 
-        if( SUCCEEDED(p_spec->GetPages( &cauuid )) )
+    if( SUCCEEDED(p_spec->GetPages( &cauuid )) )
+    {
+        if( cauuid.cElems > 0 )
         {
-            if( cauuid.cElems > 0 )
-            {
-                HWND hwnd_desktop = ::GetDesktopWindow();
+            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 );
-            }
-            p_spec->Release();
+            CoTaskMemFree( cauuid.pElems );
         }
+        p_spec->Release();
     }
 }
 
 static void ShowDeviceProperties( vlc_object_t *p_this,
                                   ICaptureGraphBuilder2 *p_capture_graph,
-                                  IBaseFilter *p_device_filter, vlc_bool_t b_audio)
-{                    
+                                  IBaseFilter *p_device_filter,
+                                  vlc_bool_t b_audio )
+{
     HRESULT hr;
     msg_Dbg( p_this, "Configuring Device Properties" );
 
@@ -1595,7 +1621,8 @@ static void ShowDeviceProperties( vlc_object_t *p_this,
         msg_Dbg( p_this, "Showing WDM Audio Configuration Pages" );
 
         hr = p_capture_graph->FindInterface( &PIN_CATEGORY_CAPTURE,
-                                             &MEDIATYPE_Audio, p_device_filter,                                             IID_IAMStreamConfig,
+                                             &MEDIATYPE_Audio, p_device_filter,
+                                             IID_IAMStreamConfig,
                                              (void **)&p_SC );
         if( SUCCEEDED(hr) )
         {
@@ -1603,19 +1630,18 @@ static void ShowDeviceProperties( vlc_object_t *p_this,
             p_SC->Release();
         }
 
-     
         /*
          * TV Audio filter
          */
         IAMTVAudio *p_TVA;
-        HRESULT 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) )
         {
             ShowPropertyPage(p_TVA);
             p_TVA->Release();
-        }                
+        }
     }
 
     /*
@@ -1646,11 +1672,19 @@ static void ShowDeviceProperties( vlc_object_t *p_this,
             ShowPropertyPage(p_SC);
             p_SC->Release();
         }
-        
-        /*
-         * TV Tuner
-         */
+    }
+}
+
+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" );
+
+    if( p_capture_graph && !b_audio )
+    {
         IAMTVTuner *p_TV;
         hr = p_capture_graph->FindInterface( &PIN_CATEGORY_CAPTURE,
                                              &MEDIATYPE_Interleaved,
@@ -1669,6 +1703,6 @@ static void ShowDeviceProperties( vlc_object_t *p_this,
         {
             ShowPropertyPage(p_TV);
             p_TV->Release();
-        }        
+        }
     }
 }