Panda3D

ffmpegTexture.h

00001 // Filename: ffmpegTexture.h
00002 // Created by:  zacpavlov (19Aug05)
00003 //
00004 ////////////////////////////////////////////////////////////////////
00005 //
00006 // PANDA 3D SOFTWARE
00007 // Copyright (c) Carnegie Mellon University.  All rights reserved.
00008 //
00009 // All use of this software is subject to the terms of the revised BSD
00010 // license.  You should have received a copy of this license along
00011 // with this source code in a file named "LICENSE."
00012 //
00013 ////////////////////////////////////////////////////////////////////
00014 
00015 #ifndef FFMPEGTEXTURE_H
00016 #define FFMPEGTEXTURE_H
00017 
00018 #include "pandabase.h"
00019 #ifdef HAVE_FFMPEG
00020 
00021 #include "videoTexture.h"
00022 
00023 extern "C" {
00024   #include "libavcodec/avcodec.h"
00025   #include "libavformat/avformat.h"
00026 #ifdef HAVE_SWSCALE
00027   #include "libswscale/swscale.h"
00028 #endif
00029 }
00030 
00031 ////////////////////////////////////////////////////////////////////
00032 //       Class : FFMpegTexture
00033 // Description : 
00034 ////////////////////////////////////////////////////////////////////
00035 class EXPCL_PANDA_GRUTIL FFMpegTexture : public VideoTexture {
00036 PUBLISHED:
00037   FFMpegTexture(const string &name = string());
00038 protected:
00039   FFMpegTexture(const FFMpegTexture &copy);
00040 PUBLISHED:
00041   virtual ~FFMpegTexture();
00042 
00043 public:
00044   static PT(Texture) make_texture();
00045 
00046 protected:
00047   virtual PT(Texture) do_make_copy();
00048   void do_assign(const FFMpegTexture &copy);
00049 
00050   virtual void update_frame(int frame);
00051   virtual bool do_read_one(const Filename &fullpath, const Filename &alpha_fullpath,
00052                            int z, int n, int primary_file_num_channels, int alpha_file_channel,
00053                            const LoaderOptions &options,
00054                            bool header_only, BamCacheRecord *record);
00055   virtual bool do_load_one(const PNMImage &pnmimage, const string &name,
00056                            int z, int n, const LoaderOptions &options);
00057 
00058 private:    
00059   class VideoPage;
00060   class VideoStream;
00061 
00062   VideoPage &modify_page(int z);
00063   bool do_reconsider_video_properties(const VideoStream &stream, 
00064                                       int num_components, int z, 
00065                                       const LoaderOptions &options);
00066   void do_update();
00067     
00068   class VideoStream {
00069   public:
00070     VideoStream();
00071     VideoStream(const VideoStream &copy);
00072     ~VideoStream();
00073 
00074     bool read(const Filename &filename);
00075     void clear();
00076     INLINE bool is_valid() const;
00077     INLINE bool is_from_file() const;
00078     bool get_frame_data(int frame);
00079 
00080   private:
00081     int read_video_frame(AVPacket *packet);
00082 
00083   public:
00084     AVCodecContext *_codec_context; 
00085     AVFormatContext *_format_context; 
00086     
00087     int _stream_number;
00088     AVFrame *_frame;
00089     AVFrame *_frame_out;
00090 
00091     Filename _filename;
00092     int _next_frame_number;
00093     int _image_size_bytes;
00094 
00095   private:
00096     unsigned char * _raw_data;
00097     AVCodec *_codec;
00098   };
00099 
00100   class VideoPage {
00101   public:
00102     INLINE VideoPage();
00103     INLINE VideoPage(const VideoPage &copy);
00104     INLINE ~VideoPage();
00105 
00106     VideoStream _color, _alpha;
00107   };
00108 
00109   typedef pvector<VideoPage> Pages;
00110   Pages _pages;
00111 
00112 public:
00113   static void register_with_read_factory();
00114 
00115 public:
00116   static TypeHandle get_class_type() {
00117     return _type_handle;
00118   }
00119   static void init_type() {
00120     VideoTexture::init_type();
00121     register_type(_type_handle, "FFMpegTexture",
00122                   VideoTexture::get_class_type());
00123   }
00124   virtual TypeHandle get_type() const {
00125     return get_class_type();
00126   }
00127   virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
00128 
00129 private:
00130   static TypeHandle _type_handle;
00131 };
00132 
00133 #include "ffmpegTexture.I"
00134 
00135 
00136 
00137 #endif  // HAVE_OPENCV
00138 
00139 #endif
 All Classes Functions Variables Enumerations