]> git.sesse.net Git - vlc/blobdiff - modules/access/dshow/filter.cpp
Removes trailing spaces. Removes tabs.
[vlc] / modules / access / dshow / filter.cpp
index d048ada371a6f843ced9b899f486c1ecf77cafbe..88d8f2b78d100af48c07894bdd0a46c3e9394669 100644 (file)
@@ -1,7 +1,7 @@
 /*****************************************************************************
  * filter.c : DirectShow access module for vlc
  *****************************************************************************
- * Copyright (C) 2002 VideoLAN
+ * Copyright (C) 2002 the VideoLAN team
  * $Id$
  *
  * Author: Gildas Bazin <gbazin@videolan.org>
  *
  * 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 */
@@ -47,7 +43,7 @@
 
 /*****************************************************************************
  * DirectShow GUIDs.
- * Easier to define them hear as mingw doesn't provide them all.
+ * Easier to define them here as mingw doesn't provide them all.
  *****************************************************************************/
 const GUID CLSID_SystemDeviceEnum = {0x62be5d10, 0x60eb, 0x11d0, {0xbd, 0x3b, 0x00, 0xa0, 0xc9, 0x11, 0xce, 0x86}};
 const GUID CLSID_VideoInputDeviceCategory = {0x860BB310,0x5D01,0x11d0,{0xBD,0x3B,0x00,0xA0,0xC9,0x11,0xCE,0x86}};
@@ -144,6 +140,12 @@ const GUID MEDIASUBTYPE_MPEG2_PROGRAM = {0xe06d8022, 0xdb46, 0x11cf, {0xb4, 0xd1
 const GUID MEDIASUBTYPE_MPEG2_TRANSPORT = {0xe06d8023, 0xdb46, 0x11cf, {0xb4, 0xd1, 0x00, 0x80, 0x5f, 0x6c, 0xbb, 0xea}};
 const GUID FORMAT_MPEG2Video = {0xe06d80e3, 0xdb46, 0x11cf, {0xb4, 0xd1, 0x00, 0x80, 0x5f, 0x6c, 0xbb, 0xea}};
 
+/* MJPG format */
+const GUID MEDIASUBTYPE_MJPG = {0x47504A4D, 0x0000, 0x0010, {0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71}};
+
+/* DivX formats */
+const GUID MEDIASUBTYPE_DIVX = {0x58564944, 0x0000, 0x0010, {0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71}};
+
 /* Analog Video */
 const GUID FORMAT_AnalogVideo = {0x482dde0, 0x7817, 0x11cf, {0x8a, 0x3, 0x0, 0xaa, 0x0, 0x6e, 0xcb, 0x65}};
 
@@ -275,6 +277,10 @@ int GetFourCCFromMediaType( const AM_MEDIA_TYPE &media_type )
             else if( media_type.subtype == MEDIASUBTYPE_MPEG2_VIDEO )
                i_fourcc = VLC_FOURCC( 'm', 'p', '2', 'v' );
 
+        /* DivX video */
+            else if( media_type.subtype == MEDIASUBTYPE_DIVX )
+               i_fourcc = VLC_FOURCC( 'D', 'I', 'V', 'X' );
+
             /* DV formats */
             else if( media_type.subtype == MEDIASUBTYPE_dvsl )
                i_fourcc = VLC_FOURCC( 'd', 'v', 's', 'l' );
@@ -282,6 +288,11 @@ int GetFourCCFromMediaType( const AM_MEDIA_TYPE &media_type )
                i_fourcc = VLC_FOURCC( 'd', 'v', 's', 'd' );
             else if( media_type.subtype == MEDIASUBTYPE_dvhd )
                i_fourcc = VLC_FOURCC( 'd', 'v', 'h', 'd' );
+
+            /* MJPEG format */
+            else if( media_type.subtype == MEDIASUBTYPE_MJPG )
+                i_fourcc = VLC_FOURCC( 'M', 'J', 'P', 'G' );
+
         }
     }
     else if( media_type.majortype == MEDIATYPE_Audio )
@@ -431,7 +442,7 @@ STDMETHODIMP CapturePin::Connect( IPin * pReceivePin,
     }
 
     if( !pmt ) return S_OK;
-                
     if( GUID_NULL != pmt->majortype &&
         media_types[0].majortype != pmt->majortype )
     {
@@ -506,18 +517,7 @@ STDMETHODIMP CapturePin::Disconnect()
 
     msg_Dbg( p_input, "CapturePin::Disconnect [OK]" );
 
-#if 1 // This used to create crashes sometimes. Is the problem fixed ?
-    VLCMediaSample vlc_sample;
-
-    vlc_mutex_lock( &p_sys->lock );
-    while( samples_queue.size() )
-    {
-        vlc_sample = samples_queue.back();
-        samples_queue.pop_back();
-        vlc_sample.p_sample->Release();
-    }
-    vlc_mutex_unlock( &p_sys->lock );
-#endif
+    /* samples_queue was already flushed in EndFlush() */
 
     p_connected_pin->Release();
     p_connected_pin = NULL;
@@ -600,7 +600,7 @@ STDMETHODIMP CapturePin::QueryAccept( const AM_MEDIA_TYPE *pmt )
 
     int i_fourcc = GetFourCCFromMediaType(*pmt);
     if( !i_fourcc )
-    {   
+    {
         msg_Dbg( p_input, "CapturePin::QueryAccept "
                  "[media type not supported]" );
         return S_FALSE;
@@ -617,10 +617,11 @@ STDMETHODIMP CapturePin::QueryAccept( const AM_MEDIA_TYPE *pmt )
         }
 
         msg_Dbg( p_input, "CapturePin::QueryAccept [OK] "
-                 "(width=%ld, height=%ld, chroma=%4.4s)",
+                 "(width=%ld, height=%ld, chroma=%4.4s, fps=%f)",
                  ((VIDEOINFOHEADER *)pmt->pbFormat)->bmiHeader.biWidth,
                  ((VIDEOINFOHEADER *)pmt->pbFormat)->bmiHeader.biHeight,
-                 (char *)&i_fourcc );
+                 (char *)&i_fourcc,
+         10000000.0f/((float)((VIDEOINFOHEADER *)pmt->pbFormat)->AvgTimePerFrame) );
     }
     else if( pmt->majortype == MEDIATYPE_Audio )
     {
@@ -630,7 +631,7 @@ STDMETHODIMP CapturePin::QueryAccept( const AM_MEDIA_TYPE *pmt )
                  ((WAVEFORMATEX *)pmt->pbFormat)->nSamplesPerSec,
                  ((WAVEFORMATEX *)pmt->pbFormat)->wBitsPerSample,
                  (char *)&i_fourcc );
-    }   
+    }
     else
     {
         msg_Dbg( p_input, "CapturePin::QueryAccept [OK] (stream format=%4.4s)",
@@ -683,6 +684,18 @@ STDMETHODIMP CapturePin::EndFlush( void )
 #ifdef DEBUG_DSHOW
     msg_Dbg( p_input, "CapturePin::EndFlush" );
 #endif
+
+    VLCMediaSample vlc_sample;
+
+    vlc_mutex_lock( &p_sys->lock );
+    while( samples_queue.size() )
+    {
+        vlc_sample = samples_queue.back();
+        samples_queue.pop_back();
+        vlc_sample.p_sample->Release();
+    }
+    vlc_mutex_unlock( &p_sys->lock );
+
     return S_OK;
 }
 STDMETHODIMP CapturePin::NewSegment( REFERENCE_TIME tStart,
@@ -779,7 +792,7 @@ CaptureFilter::CaptureFilter( vlc_object_t *_p_input, access_sys_t *p_sys,
                               AM_MEDIA_TYPE *mt, size_t mt_count )
   : p_input( _p_input ),
     p_pin( new CapturePin( _p_input, p_sys, this, mt, mt_count ) ),
-    state( State_Stopped ), i_ref( 1 ) 
+    state( State_Stopped ), i_ref( 1 )
 {
 }
 
@@ -898,6 +911,8 @@ STDMETHODIMP CaptureFilter::Stop()
     msg_Dbg( p_input, "CaptureFilter::Stop" );
 #endif
 
+    p_pin->EndFlush();
+
     state = State_Stopped;
     return S_OK;
 };
@@ -1119,12 +1134,12 @@ CaptureEnumMediaTypes::CaptureEnumMediaTypes( vlc_object_t *_p_input,
     /* Are we creating a new enumerator */
     if( pEnumMediaTypes == NULL )
     {
-        CopyMediaType(&cx_media_type, &p_pin->cx_media_type); 
+        CopyMediaType(&cx_media_type, &p_pin->cx_media_type);
         i_position = 0;
     }
     else
     {
-        CopyMediaType(&cx_media_type, &pEnumMediaTypes->cx_media_type); 
+        CopyMediaType(&cx_media_type, &pEnumMediaTypes->cx_media_type);
         i_position = pEnumMediaTypes->i_position;
     }
 }
@@ -1189,7 +1204,7 @@ STDMETHODIMP CaptureEnumMediaTypes::Next( ULONG cMediaTypes,
     ULONG offset = 0;
     ULONG max = p_pin->media_type_count;
 
-    if( ! ppMediaTypes ) 
+    if( ! ppMediaTypes )
         return E_POINTER;
 
     if( (! pcFetched)  && (cMediaTypes > 1) )
@@ -1208,7 +1223,7 @@ STDMETHODIMP CaptureEnumMediaTypes::Next( ULONG cMediaTypes,
                 (AM_MEDIA_TYPE *)CoTaskMemAlloc(sizeof(AM_MEDIA_TYPE));
             if( CopyMediaType(ppMediaTypes[copied], &cx_media_type) != S_OK )
                 return E_OUTOFMEMORY;
-            ++i_position; 
+            ++i_position;
             ++copied;
         }
     }
@@ -1222,7 +1237,7 @@ STDMETHODIMP CaptureEnumMediaTypes::Next( ULONG cMediaTypes,
             return E_OUTOFMEMORY;
 
         ++copied;
-        ++i_position; 
+        ++i_position;
     }
 
     if( pcFetched )  *pcFetched = copied;
@@ -1250,7 +1265,7 @@ STDMETHODIMP CaptureEnumMediaTypes::Reset()
 #endif
 
     FreeMediaType(cx_media_type);
-    CopyMediaType(&cx_media_type, &p_pin->cx_media_type); 
+    CopyMediaType(&cx_media_type, &p_pin->cx_media_type);
     i_position = 0;
     return S_OK;
 };