]> git.sesse.net Git - vlc/blobdiff - modules/access/bda/bdagraph.cpp
Removes trailing spaces. Removes tabs.
[vlc] / modules / access / bda / bdagraph.cpp
index f536923cd49fb845bf5c42f778b3e2fe99c1bfa6..e208fb4e5eae89150221421b609dc7a8faa2e1b7 100644 (file)
 /*****************************************************************************
  * Preamble
  *****************************************************************************/
-#include <stdlib.h>
-#include <stdio.h>
-#include <string.h>
-
-#include <vlc/vlc.h>
-#include <vlc_input.h>
-#include <vlc_access.h>
-
-/* Needed to call CoInitializeEx */
-#define _WIN32_DCOM
-
-/* Work-around a bug in w32api-2.5 */
-/*#ifndef _MSC_VER
-#   define QACONTAINERFLAGS QACONTAINERFLAGS_SOMETHINGELSE
-#endif */
-
 #include "bdagraph.h"
 
-const GUID CLSID_ATSCLocator           =
-    {0x8872FF1B,0x98FA,0x4D7A,{0x8D,0x93,0xC9,0xF1,0x05,0x5F,0x85,0xBB}};
-const GUID CLSID_ATSCNetworkProvider   =
-    {0x0dad2fdd,0x5fd7,0x11d3,{0x8f,0x50,0x00,0xc0,0x4f,0x79,0x71,0xe2}};
-const GUID CLSID_DVBCLocator           =
-    {0xc531d9fd,0x9685,0x4028,{0x8b,0x68,0x6e,0x12,0x32,0x07,0x9f,0x1e}};
-const GUID CLSID_DVBCNetworkProvider   =
-    {0xdc0c0fe7,0x0485,0x4266,{0xb9,0x3f,0x68,0xfb,0xf8,0xe,0xd8,0x34}};
-const GUID CLSID_DVBSLocator           =
-    {0x1df7d126,0x4050,0x47f0,{0xa7,0xcf,0x4c,0x4c,0xa9,0x24,0x13,0x33}};
-const GUID CLSID_DVBSNetworkProvider   =
-    {0xfa4b375a,0x45b4,0x4d45,{0x84,0x40,0x26,0x39,0x57,0xb1,0x16,0x23}};
-const GUID CLSID_DVBSTuningSpace       =
-    {0xb64016f3,0xc9a2,0x4066,{0x96,0xf0,0xbd,0x95,0x63,0x31,0x47,0x26}};
-const GUID CLSID_DVBTLocator           =
-    {0x9cd64701,0xbdf3,0x4d14,{0x8e,0x03,0xf1,0x29,0x83,0xd8,0x66,0x64}};
-const GUID CLSID_DVBTNetworkProvider   =
-    {0x216c62df,0x6d7f,0x4e9a,{0x85,0x71,0x05,0xf1,0x4e,0xdb,0x76,0x6a}};
-const GUID CLSID_FilterGraph           =
-    {0xe436ebb3,0x524f,0x11ce,{0x9f,0x53,0x00,0x20,0xaf,0x0b,0xa7,0x70}};
-const GUID CLSID_InfTee                =
-    {0xf8388a40,0xd5bb,0x11d0,{0xbe,0x5a,0x00,0x80,0xc7,0x06,0x56,0x8e}};
-const GUID CLSID_MPEG2Demultiplexer    =
-    {0xafb6c280,0x2c41,0x11d3,{0x8a,0x60,0x00,0x00,0xf8,0x1e,0x0e,0x4a}};
-const GUID CLSID_NullRenderer          =
-    {0xc1f400a4,0x3f08,0x11d3,{0x9f,0x0b,0x00,0x60,0x08,0x03,0x9e,0x37}};
-const GUID CLSID_SampleGrabber         =
-    {0xc1f400a0,0x3f08,0x11d3,{0x9f,0x0b,0x00,0x60,0x08,0x03,0x9e,0x37}};
-const GUID CLSID_SystemDeviceEnum      =
-    {0x62be5d10,0x60eb,0x11d0,{0xbd,0x3b,0x00,0xa0,0xc9,0x11,0xce,0x86}};
-const GUID CLSID_SystemTuningSpaces    =
-    {0xd02aac50,0x027e,0x11d3,{0x9d,0x8e,0x00,0xc0,0x4f,0x72,0xd9,0x80}};
-
-const GUID IID_IATSCChannelTuneRequest =
-    {0x0369B4E1,0x45B6,0x11d3,{0xB6,0x50,0x00,0xC0,0x4F,0x79,0x49,0x8E}};
-const GUID IID_IATSCLocator            =
-    {0xbf8d986f,0x8c2b,0x4131,{0x94,0xd7,0x4d,0x3d,0x9f,0xcc,0x21,0xef}};
-const GUID IID_IBaseFilter             =
-    {0x56a86895,0x0ad4,0x11ce,{0xb0,0x3a,0x00,0x20,0xaf,0x0b,0xa7,0x70}};
-const GUID IID_ICreateDevEnum          =
-    {0x29840822,0x5b84,0x11d0,{0xbd,0x3b,0x00,0xa0,0xc9,0x11,0xce,0x86}};
-const GUID IID_IDVBTLocator            =
-    {0x8664da16,0xdda2,0x42ac,{0x92,0x6a,0xc1,0x8f,0x91,0x27,0xc3,0x02}};
-const GUID IID_IDVBCLocator            =
-    {0x6e42f36e,0x1dd2,0x43c4,{0x9f,0x78,0x69,0xd2,0x5a,0xe3,0x90,0x34}};
-const GUID IID_IDVBSLocator            =
-    {0x3d7c353c,0x0d04,0x45f1,{0xa7,0x42,0xf9,0x7c,0xc1,0x18,0x8d,0xc8}};
-const GUID IID_IDVBSTuningSpace        =
-    {0xcdf7be60,0xd954,0x42fd,{0xa9,0x72,0x78,0x97,0x19,0x58,0xe4,0x70}};
-const GUID IID_IDVBTuneRequest         =
-    {0x0D6F567E,0xA636,0x42bb,{0x83,0xBA,0xCE,0x4C,0x17,0x04,0xAF,0xA2}};
-const GUID IID_IGraphBuilder           =
-    {0x56a868a9,0x0ad4,0x11ce,{0xb0,0x3a,0x00,0x20,0xaf,0x0b,0xa7,0x70}};
-const GUID IID_IMediaControl           =
-    {0x56a868b1,0x0ad4,0x11ce,{0xb0,0x3a,0x00,0x20,0xaf,0x0b,0xa7,0x70}};
-const GUID IID_IMpeg2Demultiplexer     =
-    {0x436eee9c,0x264f,0x4242,{0x90,0xe1,0x4e,0x33,0x0c,0x10,0x75,0x12}};
-const GUID IID_ISampleGrabber          =
-    {0x6b652fff,0x11fe,0x4fce,{0x92,0xad,0x02,0x66,0xb5,0xd7,0xc7,0x8f}};
-const GUID IID_IScanningTuner          =
-    {0x1dfd0a5c,0x0284,0x11d3,{0x9d,0x8e,0x00,0xc0,0x4f,0x72,0xd9,0x80}};
-const GUID IID_ITuner                  =
-    {0x28C52640,0x018A,0x11d3,{0x9D,0x8E,0x00,0xC0,0x4F,0x72,0xD9,0x80}};
-const GUID IID_ITuningSpace            =
-    {0x061c6e30,0xe622,0x11d2,{0x94,0x93,0x00,0xc0,0x4f,0x72,0xd9,0x80}};
-const GUID IID_ITuningSpaceContainer   =
-    {0x5B692E84,0xE2F1,0x11d2,{0x94,0x93,0x00,0xC0,0x4F,0x72,0xD9,0x80}};
-
-const GUID KSCATEGORY_BDA_TRANSPORT_INFORMATION =
-    {0xa2e3074f,0x6c3d,0x11d3,{0xb6,0x53,0x00,0xc0,0x4f,0x79,0x49,0x8e}};
-const GUID KSCATEGORY_BDA_RECEIVER_COMPONENT    =
-    {0xFD0A5AF4,0xB41D,0x11d2,{0x9c,0x95,0x00,0xc0,0x4f,0x79,0x71,0xe0}};
-const GUID KSCATEGORY_BDA_NETWORK_TUNER         =
-    {0x71985f48,0x1ca1,0x11d3,{0x9c,0xc8,0x00,0xc0,0x4f,0x79,0x71,0xe0}};
-const GUID MEDIATYPE_MPEG2_SECTIONS             =
-    {0x455f176c,0x4b06,0x47ce,{0x9a,0xef,0x8c,0xae,0xf7,0x3d,0xf7,0xb5}};
-const GUID MEDIASUBTYPE_None                    =
-    {0xe436eb8e,0x524f,0x11ce,{0x9f,0x53,0x00,0x20,0xaf,0x0b,0xa7,0x70}};
-const GUID FORMAT_None                          =
-    {0x0f6417d6,0xc318,0x11d0,{0xa4,0x3f,0x00,0xa0,0xc9,0x22,0x31,0x96}};
-
 /****************************************************************************
  * Interfaces for calls from C
  ****************************************************************************/
@@ -134,40 +37,52 @@ extern "C" {
 
     void dvb_deleteBDAGraph( access_t* p_access )
     {
-        delete p_access->p_sys->p_bda_module;
+        if( p_access->p_sys->p_bda_module )
+            delete p_access->p_sys->p_bda_module;
     };
 
     int dvb_SubmitATSCTuneRequest( access_t* p_access )
     {
-        return p_access->p_sys->p_bda_module->SubmitATSCTuneRequest();
+        if( p_access->p_sys->p_bda_module )
+            return p_access->p_sys->p_bda_module->SubmitATSCTuneRequest();
+        return VLC_EGENERIC;
     };
 
     int dvb_SubmitDVBTTuneRequest( access_t* p_access )
     {
-        return p_access->p_sys->p_bda_module->SubmitDVBTTuneRequest();
+        if( p_access->p_sys->p_bda_module )
+            return p_access->p_sys->p_bda_module->SubmitDVBTTuneRequest();
+        return VLC_EGENERIC;
     };
 
     int dvb_SubmitDVBCTuneRequest( access_t* p_access )
     {
-        return p_access->p_sys->p_bda_module->SubmitDVBCTuneRequest();
-    };    
+        if( p_access->p_sys->p_bda_module )
+            return p_access->p_sys->p_bda_module->SubmitDVBCTuneRequest();
+        return VLC_EGENERIC;
+    };
 
     int dvb_SubmitDVBSTuneRequest( access_t* p_access )
     {
-        return p_access->p_sys->p_bda_module->SubmitDVBSTuneRequest();
+        if( p_access->p_sys->p_bda_module )
+            return p_access->p_sys->p_bda_module->SubmitDVBSTuneRequest();
+        return VLC_EGENERIC;
     };
 
     long dvb_GetBufferSize( access_t* p_access )
     {
-        return p_access->p_sys->p_bda_module->GetBufferSize();
+        if( p_access->p_sys->p_bda_module )
+            return p_access->p_sys->p_bda_module->GetBufferSize();
+        return -1;
     };
 
     long dvb_ReadBuffer( access_t* p_access, long* l_buffer_len, BYTE* p_buff )
     {
-        return p_access->p_sys->p_bda_module->ReadBuffer( l_buffer_len, 
-            p_buff );
+        if( p_access->p_sys->p_bda_module )
+            return p_access->p_sys->p_bda_module->ReadBuffer( l_buffer_len,
+                p_buff );
+        return -1;
     };
-
 };
 
 /*****************************************************************************
@@ -179,6 +94,7 @@ BDAGraph::BDAGraph( access_t* p_this ):
     l_tuner_used(-1),
     d_graph_register( 0 )
 {
+    b_ready = FALSE;
     p_tuning_space = NULL;
     p_tune_request = NULL;
     p_media_control = NULL;
@@ -319,11 +235,70 @@ int BDAGraph::SubmitDVBTTuneRequest()
                 p_dvbt_locator->Release();
         }
     } l;
-    long l_frequency, l_bandwidth;
-
-    l_frequency = l_bandwidth = -1;
+    long l_frequency, l_bandwidth, l_hp_fec, l_lp_fec, l_guard;
+    long l_transmission, l_hierarchy;
+    BinaryConvolutionCodeRate i_hp_fec, i_lp_fec;
+    GuardInterval             i_guard;
+    TransmissionMode          i_transmission;
+    HierarchyAlpha            i_hierarchy;
+
+    l_frequency = l_bandwidth = l_hp_fec = l_lp_fec = l_guard = -1;
+    l_transmission = l_hierarchy = -1;
     l_frequency = var_GetInteger( p_access, "dvb-frequency" );
     l_bandwidth = var_GetInteger( p_access, "dvb-bandwidth" );
+    l_hp_fec = var_GetInteger( p_access, "dvb-code-rate-hp" );
+    l_lp_fec = var_GetInteger( p_access, "dvb-code-rate-lp" );
+    l_guard = var_GetInteger( p_access, "dvb-guard" );
+    l_transmission = var_GetInteger( p_access, "dvb-transmission" );
+    l_hierarchy = var_GetInteger( p_access, "dvb-hierarchy" );
+
+    i_hp_fec = BDA_BCC_RATE_NOT_SET;
+    if( l_hp_fec == 1 )
+        i_hp_fec = BDA_BCC_RATE_1_2;
+    if( l_hp_fec == 2 )
+        i_hp_fec = BDA_BCC_RATE_2_3;
+    if( l_hp_fec == 3 )
+        i_hp_fec = BDA_BCC_RATE_3_4;
+    if( l_hp_fec == 4 )
+        i_hp_fec = BDA_BCC_RATE_5_6;
+    if( l_hp_fec == 5 )
+        i_hp_fec = BDA_BCC_RATE_7_8;
+
+    i_lp_fec = BDA_BCC_RATE_NOT_SET;
+    if( l_lp_fec == 1 )
+        i_lp_fec = BDA_BCC_RATE_1_2;
+    if( l_lp_fec == 2 )
+        i_lp_fec = BDA_BCC_RATE_2_3;
+    if( l_lp_fec == 3 )
+        i_lp_fec = BDA_BCC_RATE_3_4;
+    if( l_lp_fec == 4 )
+        i_lp_fec = BDA_BCC_RATE_5_6;
+    if( l_lp_fec == 5 )
+        i_lp_fec = BDA_BCC_RATE_7_8;
+
+    i_guard = BDA_GUARD_NOT_SET;
+    if( l_guard == 32 )
+        i_guard = BDA_GUARD_1_32;
+    if( l_guard == 16 )
+        i_guard = BDA_GUARD_1_16;
+    if( l_guard == 8 )
+        i_guard = BDA_GUARD_1_8;
+    if( l_guard == 4 )
+        i_guard = BDA_GUARD_1_4;
+
+    i_transmission = BDA_XMIT_MODE_NOT_SET;
+    if( l_transmission == 2 )
+        i_transmission = BDA_XMIT_MODE_2K;
+    if( l_transmission == 8 )
+        i_transmission = BDA_XMIT_MODE_8K;
+
+    i_hierarchy = BDA_HALPHA_NOT_SET;
+    if( l_hierarchy == 1 )
+        i_hierarchy = BDA_HALPHA_1;
+    if( l_hierarchy == 2 )
+        i_hierarchy = BDA_HALPHA_2;
+    if( l_hierarchy == 4 )
+        i_hierarchy = BDA_HALPHA_4;
 
     guid_network_type = CLSID_DVBTNetworkProvider;
     hr = CreateTuneRequest();
@@ -360,6 +335,16 @@ int BDAGraph::SubmitDVBTTuneRequest()
         hr = l.p_dvbt_locator->put_CarrierFrequency( l_frequency );
     if( SUCCEEDED( hr ) && l_bandwidth > 0 )
         hr = l.p_dvbt_locator->put_Bandwidth( l_bandwidth );
+    if( SUCCEEDED( hr ) && i_hp_fec != BDA_BCC_RATE_NOT_SET )
+        hr = l.p_dvbt_locator->put_InnerFECRate( i_hp_fec );
+    if( SUCCEEDED( hr ) && i_lp_fec != BDA_BCC_RATE_NOT_SET )
+        hr = l.p_dvbt_locator->put_LPInnerFECRate( i_lp_fec );
+    if( SUCCEEDED( hr ) && i_guard != BDA_GUARD_NOT_SET )
+        hr = l.p_dvbt_locator->put_Guard( i_guard );
+    if( SUCCEEDED( hr ) && i_transmission != BDA_XMIT_MODE_NOT_SET )
+        hr = l.p_dvbt_locator->put_Mode( i_transmission );
+    if( SUCCEEDED( hr ) && i_hierarchy != BDA_HALPHA_NOT_SET )
+        hr = l.p_dvbt_locator->put_HAlpha( i_hierarchy );
     if( FAILED( hr ) )
     {
         msg_Warn( p_access, "SubmitDVBTTuneRequest: "\
@@ -519,9 +504,13 @@ int BDAGraph::SubmitDVBSTuneRequest()
         public:
         IDVBTuneRequest* p_dvbs_tune_request;
         IDVBSLocator* p_dvbs_locator;
-        localComPtr(): p_dvbs_tune_request(NULL), p_dvbs_locator(NULL) {};
+        IDVBSTuningSpace* p_dvbs_tuning_space;
+        localComPtr(): p_dvbs_tune_request(NULL), p_dvbs_locator(NULL),
+            p_dvbs_tuning_space(NULL) {};
         ~localComPtr()
         {
+            if( p_dvbs_tuning_space )
+                p_dvbs_tuning_space->Release();
             if( p_dvbs_tune_request )
                 p_dvbs_tune_request->Release();
             if( p_dvbs_locator )
@@ -529,17 +518,25 @@ int BDAGraph::SubmitDVBSTuneRequest()
         }
     } l;
     long l_frequency, l_symbolrate, l_azimuth, l_elevation, l_longitude;
+    long l_lnb_lof1, l_lnb_lof2, l_lnb_slof, l_inversion, l_network_id;
     char* psz_polarisation;
     Polarisation i_polar;
+    SpectralInversion i_inversion;
     VARIANT_BOOL b_west;
 
     l_frequency = l_symbolrate = l_azimuth = l_elevation = l_longitude = -1;
+    l_lnb_lof1 = l_lnb_lof2 = l_lnb_slof = l_inversion = l_network_id = -1;
     l_frequency = var_GetInteger( p_access, "dvb-frequency" );
     l_symbolrate = var_GetInteger( p_access, "dvb-srate" );
     l_azimuth = var_GetInteger( p_access, "dvb-azimuth" );
     l_elevation = var_GetInteger( p_access, "dvb-elevation" );
     l_longitude = var_GetInteger( p_access, "dvb-longitude" );
+    l_lnb_lof1 = var_GetInteger( p_access, "dvb-lnb-lof1" );
+    l_lnb_lof2 = var_GetInteger( p_access, "dvb-lnb-lof2" );
+    l_lnb_slof = var_GetInteger( p_access, "dvb-lnb-slof" );
     psz_polarisation = var_GetString( p_access, "dvb-polarisation" );
+    l_inversion = var_GetInteger( p_access, "dvb-inversion" );
+    l_network_id = var_GetInteger( p_access, "dvb-network_id" );
 
     b_west = ( l_longitude < 0 ) ? TRUE : FALSE;
 
@@ -553,11 +550,19 @@ int BDAGraph::SubmitDVBSTuneRequest()
     if( *psz_polarisation == 'R' || *psz_polarisation == 'r' )
         i_polar = BDA_POLARISATION_CIRCULAR_R;
 
+    i_inversion = BDA_SPECTRAL_INVERSION_NOT_SET;
+    if( l_inversion == 0 )
+        i_inversion = BDA_SPECTRAL_INVERSION_NORMAL;
+    if( l_inversion == 1 )
+        i_inversion = BDA_SPECTRAL_INVERSION_INVERTED;
+    if( l_inversion == 2 )
+        i_inversion = BDA_SPECTRAL_INVERSION_AUTOMATIC;
+
     guid_network_type = CLSID_DVBSNetworkProvider;
     hr = CreateTuneRequest();
     if( FAILED( hr ) )
     {
-        msg_Warn( p_access, "SubmitDVBCTuneRequest: "\
+        msg_Warn( p_access, "SubmitDVBSTuneRequest: "\
             "Cannot create Tune Request: hr=0x%8lx", hr );
         return VLC_EGENERIC;
     }
@@ -566,7 +571,7 @@ int BDAGraph::SubmitDVBSTuneRequest()
         (void**)&l.p_dvbs_tune_request );
     if( FAILED( hr ) )
     {
-        msg_Warn( p_access, "SubmitDVBCTuneRequest: "\
+        msg_Warn( p_access, "SubmitDVBSTuneRequest: "\
             "Cannot QI for IDVBTuneRequest: hr=0x%8lx", hr );
         return VLC_EGENERIC;
     }
@@ -578,11 +583,20 @@ int BDAGraph::SubmitDVBSTuneRequest()
         IID_IDVBSLocator, (void**)&l.p_dvbs_locator );
     if( FAILED( hr ) )
     {
-        msg_Warn( p_access, "SubmitDVBCTuneRequest: "\
+        msg_Warn( p_access, "SubmitDVBSTuneRequest: "\
             "Cannot create the DVBS Locator: hr=0x%8lx", hr );
         return VLC_EGENERIC;
     }
 
+    hr = p_tuning_space->QueryInterface( IID_IDVBSTuningSpace,
+        (void**)&l.p_dvbs_tuning_space );
+    if( FAILED( hr ) )
+    {
+        msg_Warn( p_access, "SubmitDVBSTuneRequest: "\
+            "Cannot QI for IDVBSTuningSpace: hr=0x%8lx", hr );
+        return VLC_EGENERIC;
+    }
+
     hr = S_OK;
     if( l_frequency > 0 )
         hr = l.p_dvbs_locator->put_CarrierFrequency( l_frequency );
@@ -598,9 +612,19 @@ int BDAGraph::SubmitDVBSTuneRequest()
         hr = l.p_dvbs_locator->put_WestPosition( b_west );
     if( SUCCEEDED( hr ) && i_polar != BDA_POLARISATION_NOT_SET )
         hr = l.p_dvbs_locator->put_SignalPolarisation( i_polar );
+    if( SUCCEEDED( hr ) && l_lnb_lof1 > 0 )
+        hr = l.p_dvbs_tuning_space->put_LowOscillator( l_lnb_lof1 );
+    if( SUCCEEDED( hr ) && l_lnb_lof2 > 0 )
+        hr = l.p_dvbs_tuning_space->put_HighOscillator( l_lnb_lof2 );
+    if( SUCCEEDED( hr ) && l_lnb_slof > 0 )
+        hr = l.p_dvbs_tuning_space->put_LNBSwitch( l_lnb_slof );
+    if( SUCCEEDED( hr ) && i_inversion != BDA_SPECTRAL_INVERSION_NOT_SET )
+        hr = l.p_dvbs_tuning_space->put_SpectralInversion( i_inversion );
+    if( SUCCEEDED( hr ) && l_network_id > 0 )
+        hr = l.p_dvbs_tuning_space->put_NetworkID( l_network_id );
     if( FAILED( hr ) )
     {
-        msg_Warn( p_access, "SubmitDVBCTuneRequest: "\
+        msg_Warn( p_access, "SubmitDVBSTuneRequest: "\
             "Cannot set tuning parameters on Locator: hr=0x%8lx", hr );
         return VLC_EGENERIC;
     }
@@ -608,7 +632,7 @@ int BDAGraph::SubmitDVBSTuneRequest()
     hr = p_tune_request->put_Locator( l.p_dvbs_locator );
     if( FAILED( hr ) )
     {
-        msg_Warn( p_access, "SubmitDVBCTuneRequest: "\
+        msg_Warn( p_access, "SubmitDVBSTuneRequest: "\
             "Cannot put the locator: hr=0x%8lx", hr );
         return VLC_EGENERIC;
     }
@@ -981,7 +1005,7 @@ HRESULT BDAGraph::FindFilter( REFCLSID clsid, long* i_moniker_used,
             p_moniker_enum(NULL),
             p_filter(NULL),
             p_property_bag(NULL)
-                { ::VariantInit(&var_bstr); };
+            { ::VariantInit(&var_bstr); };
         ~localComPtr()
         {
             if( p_moniker )
@@ -1000,16 +1024,16 @@ HRESULT BDAGraph::FindFilter( REFCLSID clsid, long* i_moniker_used,
     {
         hr = ::CoCreateInstance( CLSID_SystemDeviceEnum, 0, CLSCTX_INPROC,
             IID_ICreateDevEnum, (void**)&p_system_dev_enum );
-         if( FAILED( hr ) )
-         {
-             msg_Warn( p_access, "FindFilter: "\
-                 "Cannot CoCreate SystemDeviceEnum: hr=0x%8lx", hr );
-             return hr;
+        if( FAILED( hr ) )
+        {
+            msg_Warn( p_access, "FindFilter: "\
+                "Cannot CoCreate SystemDeviceEnum: hr=0x%8lx", hr );
+            return hr;
         }
     }
 
     hr = p_system_dev_enum->CreateClassEnumerator( clsid,
-                                                   &l.p_moniker_enum, 0 );
+        &l.p_moniker_enum, 0 );
     if( hr != S_OK )
     {
         msg_Warn( p_access, "FindFilter: "\
@@ -1246,6 +1270,7 @@ HRESULT BDAGraph::Start()
         return hr;
 
     /* The Graph is not running so stop it and return an error */
+    msg_Warn( p_access, "Start: Graph not started: %d", i_state );
     hr = p_media_control->Stop();
     if( FAILED( hr ) )
     {
@@ -1261,15 +1286,23 @@ HRESULT BDAGraph::Start()
 *****************************************************************************/
 long BDAGraph::GetBufferSize()
 {
-    while( queue_sample.empty() )
-        Sleep( 50 );
-
     long l_buffer_size = 0;
     long l_queue_size;
 
+    b_ready = true;
+
+    for( int i_timer = 0; queue_sample.empty() && i_timer < 200; i_timer++ )
+        Sleep( 10 );
+
+    l_queue_size = queue_sample.size();
+    if( l_queue_size <= 0 )
+    {
+        msg_Warn( p_access, "BDA GetBufferSize: Timed Out waiting for sample" );
+        return -1;
+    }
+
     /* Establish the length of the queue as it grows quickly. If the queue
      * size is checked dynamically there is a risk of not exiting the loop */
-    l_queue_size = queue_sample.size();
     for( long l_queue_count=0; l_queue_count < l_queue_size; l_queue_count++ )
     {
         l_buffer_size += queue_sample.front()->GetActualDataLength();
@@ -1311,8 +1344,15 @@ long BDAGraph::ReadBuffer( long* pl_buffer_len, BYTE* p_buffer )
 ******************************************************************************/
 STDMETHODIMP BDAGraph::SampleCB( double d_time, IMediaSample *p_sample )
 {
-    p_sample->AddRef();
-    queue_sample.push( p_sample );
+    if( b_ready )
+    {
+        p_sample->AddRef();
+        queue_sample.push( p_sample );
+    }
+    else
+    {
+        msg_Warn( p_access, "BDA SampleCB: Not ready - dropped sample" );
+    }
     return S_OK;
 }
 
@@ -1379,7 +1419,7 @@ HRESULT BDAGraph::Destroy()
         p_media_control->Release();
         p_media_control = NULL;
     }
-    if( p_scanning_tuner )
+    if( p_filter_graph )
     {
         p_filter_graph->Release();
         p_filter_graph = NULL;
@@ -1426,17 +1466,28 @@ HRESULT BDAGraph::Register()
     wsprintfW( psz_w_graph_name, L"VLC BDA Graph %08x Pid %08x",
         (DWORD_PTR) p_filter_graph, ::GetCurrentProcessId() );
     hr = CreateItemMoniker( L"!", psz_w_graph_name, &l.p_moniker );
-    if( SUCCEEDED( hr ) )
-        hr = l.p_ro_table->Register( ROTFLAGS_REGISTRATIONKEEPSALIVE,
-            p_filter_graph, l.p_moniker, &d_graph_register );
-
+    if( FAILED( hr ) )
+    {
+        msg_Warn( p_access, "Register: Cannot Create Moniker: hr=0x%8lx", hr );
+        return hr;
+    }
+    hr = l.p_ro_table->Register( ROTFLAGS_REGISTRATIONKEEPSALIVE,
+        p_filter_graph, l.p_moniker, &d_graph_register );
+    if( FAILED( hr ) )
+    {
+        msg_Warn( p_access, "Register: Cannot Register Graph: hr=0x%8lx", hr );
+        return hr;
+    }
+    msg_Dbg( p_access, "Register: registered Graph: %S", psz_w_graph_name );
     return hr;
 }
 
 void BDAGraph::Deregister()
 {
+    HRESULT   hr;
     IRunningObjectTable* p_ro_table;
-    if( SUCCEEDED( ::GetRunningObjectTable( 0, &p_ro_table ) ) )
+    hr = ::GetRunningObjectTable( 0, &p_ro_table );
+    if( SUCCEEDED( hr ) )
         p_ro_table->Revoke( d_graph_register );
     d_graph_register = 0;
     p_ro_table->Release();