Panda3D
|
00001 // Filename: ffmpegVirtualFile.h 00002 // Created by: jyelon (01Aug2007) 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 FFMPEGVIRTUALFILE_H 00016 #define FFMPEGVIRTUALFILE_H 00017 00018 #include "pandabase.h" 00019 00020 #ifdef HAVE_FFMPEG 00021 00022 #include "config_movies.h" 00023 #include "filename.h" 00024 #include "subfileInfo.h" 00025 00026 #include <stdarg.h> 00027 extern "C" { 00028 #include "libavformat/avio.h" 00029 } 00030 00031 struct URLContext; 00032 struct AVFormatContext; 00033 00034 //////////////////////////////////////////////////////////////////// 00035 // Class : FfmpegVirtualFile 00036 // Description : Enables ffmpeg to access panda's VFS. Create an 00037 // instance of the FfmpegVirtualFile for each ffmpeg 00038 // stream you wish to open. 00039 //////////////////////////////////////////////////////////////////// 00040 class EXPCL_PANDA_MOVIES FfmpegVirtualFile { 00041 public: 00042 FfmpegVirtualFile(); 00043 ~FfmpegVirtualFile(); 00044 private: 00045 FfmpegVirtualFile(const FfmpegVirtualFile ©); 00046 void operator = (const FfmpegVirtualFile ©); 00047 00048 public: 00049 bool open_vfs(const Filename &filename); 00050 bool open_subfile(const SubfileInfo &info); 00051 void close(); 00052 00053 INLINE bool is_open() const; 00054 INLINE AVFormatContext *get_format_context() const; 00055 00056 static void register_protocol(); 00057 00058 private: 00059 static int pandavfs_open(URLContext *h, const char *filename, int flags); 00060 static int pandavfs_read(URLContext *h, unsigned char *buf, int size); 00061 static int pandavfs_write(URLContext *h, const unsigned char *buf, int size); 00062 static int64_t pandavfs_seek(URLContext *h, int64_t pos, int whence); 00063 static int pandavfs_close(URLContext *h); 00064 00065 static void log_callback(void *ptr, int level, const char *fmt, va_list v1); 00066 00067 private: 00068 AVFormatContext *_format_context; 00069 streampos _start; 00070 streamsize _size; 00071 istream *_in; 00072 pifstream _file_in; 00073 bool _owns_in; 00074 }; 00075 00076 #include "ffmpegVirtualFile.I" 00077 00078 #endif // HAVE_FFMPEG 00079 #endif // FFMPEGVIRTUALFILE_H 00080