DirectShowDecoder.h

Go to the documentation of this file.
00001 
00002 //    Copyright 2004, SenseGraphics AB
00003 //
00004 //    This file is part of H3D API.
00005 //
00006 //    H3D API is free software; you can redistribute it and/or modify
00007 //    it under the terms of the GNU General Public License as published by
00008 //    the Free Software Foundation; either version 2 of the License, or
00009 //    (at your option) any later version.
00010 //
00011 //    H3D API is distributed in the hope that it will be useful,
00012 //    but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 //    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014 //    GNU General Public License for more details.
00015 //
00016 //    You should have received a copy of the GNU General Public License
00017 //    along with H3D API; if not, write to the Free Software
00018 //    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00019 //
00020 //    A commercial license is also available. Please contact us at 
00021 //    www.sensegraphics.com for more information.
00022 //
00023 //
00027 //
00029 
00030 #ifndef __DIRECTSHOWDECODER_H__
00031 #define __DIRECTSHOWDECODER_H__
00032 
00033 #include "FieldTemplates.h"
00034 #include "SFTime.h"
00035 
00036 #ifdef HAVE_DSHOW
00037 
00038 // Include from DirectShow BaseClasses
00039 // Remove the DEBUG defines when including DShow classes in order
00040 // to always use the release version. The debug version caused us
00041 // problems.
00042 #ifdef _DEBUG
00043 #define RESTORE__DEBUG
00044 #undef _DEBUG
00045 #endif
00046 
00047 #ifdef DEBUG
00048 #define RESTORE_DEBUG
00049 #undef DEBUG
00050 #endif
00051 #include <streams.h>
00052 
00053 #ifdef RESTORE__DEBUG
00054 #define _DEBUG
00055 #undef RESTORE__DEBUG
00056 #endif
00057 
00058 #ifdef RESTORE_DEBUG
00059 #define DEBUG
00060 #undef RESTORE_DEBUG
00061 #endif
00062 
00063 #ifdef _MSC_VER
00064 #pragma comment( lib, "strmbase.lib" )
00065 #endif
00066 
00067 #include "H3DVideoClipDecoderNode.h"
00068 
00069 namespace H3D {
00070 
00071 struct __declspec(uuid("{71771540-2017-11cf-ae26-0020afd79767}")) CLSID_TextureRenderer;
00072 
00077   class H3DAPI_API DirectShowDecoder : public H3DVideoClipDecoderNode {
00078 
00080     class DShowEventHandler: public AutoUpdate< SFTime > {
00081       virtual void update();
00082     };
00083 
00086     class CFrameGrabber: public CBaseVideoRenderer {
00087     public:
00089       CFrameGrabber(LPUNKNOWN pUnk, HRESULT *phr, DirectShowDecoder *d );
00090 
00091       // CBaseVideoRenderer functions
00092 
00094       HRESULT CheckMediaType(const CMediaType *pmt );
00095 
00097       HRESULT SetMediaType(const CMediaType *pmt );
00098     
00100       HRESULT DoRenderSample(IMediaSample *pMediaSample); 
00101 
00105       void OnReceiveFirstSample(IMediaSample *pSample) { 
00106         DoRenderSample( pSample ); 
00107       }
00108 
00109       DirectShowDecoder *decoder;
00110     };
00111 
00112     friend class CFrameGrabber;
00113 
00114   public:
00116     DirectShowDecoder();
00117 
00119     ~DirectShowDecoder();
00120 
00122     virtual bool loadClip( const string &url );
00123 
00125     virtual void startPlaying();
00126 
00129     virtual void stopPlaying();
00130 
00132     virtual void pausePlaying();
00133 
00136     virtual void setLooping( bool v ) {
00137       looping = v;
00138     }
00139 
00141     virtual H3DTime getPosition();
00142 
00144     virtual void setPosition( H3DTime pos );
00145 
00150     virtual bool setRate( double r ) {
00151       HRESULT hr;
00152       if( g_pMS ) 
00153         hr = g_pMS->SetRate( r ); 
00154       rate = r;
00155       return hr == S_OK;
00156     }
00157 
00160     virtual H3DTime getDuration() {
00161       return duration;
00162     }
00163 
00165     virtual bool haveNewFrame() { return have_new_frame; }
00166 
00168     virtual void getNewFrame( unsigned char *buffer );
00169 
00171     virtual unsigned int getFrameWidth() { return frame_width; }
00172 
00174     virtual unsigned int getFrameHeight() { return frame_height; }
00175 
00177     virtual unsigned int getFrameBitsPerPixel() { return 24; }
00178 
00180     virtual unsigned int getFrameSize() { 
00181       return frame_width * frame_height * 3; 
00182     }
00183 
00185     virtual Image::PixelType getFramePixelType() { return Image::RGB; }
00186     
00188     virtual Image::PixelComponentType getFramePixelComponentType() { 
00189       return Image::UNSIGNED;
00190     }
00191 
00193     static H3DNodeDatabase database;  
00194   
00196     static DecoderRegistration reader_registration;
00197 
00200     static bool supportsFileType( const string &url );
00201   protected:
00202     // DirectShow pointers
00203     CComPtr<IGraphBuilder>  g_pGB;          // GraphBuilder
00204     CComPtr<IMediaControl>  g_pMC;          // Media Control
00205     CComPtr<IMediaSeeking> g_pMS;          // Media Seeking
00206     CComPtr<IMediaEvent>    g_pME;          // Media Event
00207     CComPtr<IBaseFilter>    g_pRenderer;    // our custom renderer
00208   
00210     HRESULT initDShowTextureRenderer( const string &url );
00211 
00214     void cleanupDShow( void );
00215 
00217     unsigned int frame_width;
00218 
00220     unsigned int frame_height;
00221 
00223     unsigned int data_size;
00224 
00226     unsigned char *data;
00227 
00230     bool have_new_frame;
00231 
00233     double rate;
00234   
00236     CFrameGrabber *frame_grabber;
00237 
00239     bool looping;
00240 
00242     H3DTime duration;
00243 
00245     auto_ptr< DShowEventHandler > event_handler;
00246   };
00247 
00248 }
00249 #endif
00250 #endif

Generated on Thu Aug 24 12:38:32 2006 for H3D API by  doxygen 1.4.5