Blender V2.61 - r43446

bpy_app_ffmpeg.c

Go to the documentation of this file.
00001 /*
00002  * ***** BEGIN GPL LICENSE BLOCK *****
00003  *
00004  * This program is free software; you can redistribute it and/or
00005  * modify it under the terms of the GNU General Public License
00006  * as published by the Free Software Foundation; either version 2
00007  * of the License, or (at your option) any later version.
00008  *
00009  * This program is distributed in the hope that it will be useful,
00010  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012  * GNU General Public License for more details.
00013  *
00014  * You should have received a copy of the GNU General Public License
00015  * along with this program; if not, write to the Free Software Foundation,
00016  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00017  *
00018  * Contributor(s): Sergey Sharybin
00019  *
00020  * ***** END GPL LICENSE BLOCK *****
00021  */
00022 
00027 #include <Python.h>
00028 #include "BLI_utildefines.h"
00029 #include "BLI_callbacks.h"
00030 
00031 #include "RNA_types.h"
00032 #include "RNA_access.h"
00033 #include "bpy_rna.h"
00034 
00035 #ifdef WITH_FFMPEG
00036 #include <libavcodec/avcodec.h>
00037 #include <libavdevice/avdevice.h>
00038 #include <libavformat/avformat.h>
00039 #include <libavutil/avutil.h>
00040 #include <libswscale/swscale.h>
00041 #endif
00042 
00043 static PyTypeObject BlenderAppFFmpegType;
00044 
00045 #define DEF_FFMPEG_LIB_VERSION(lib) \
00046     {(char *)(#lib "_version"), (char *)("The " #lib " version  as a tuple of 3 numbers")}, \
00047     {(char *)(#lib "_version_string"), (char *)("The " #lib " version formatted as a string")},
00048 
00049 static PyStructSequence_Field app_ffmpeg_info_fields[] = {
00050     {(char *)"supported", (char *)("Boolean, True when Blender is built with FFmpeg support")},
00051 
00052     DEF_FFMPEG_LIB_VERSION(avcodec)
00053     DEF_FFMPEG_LIB_VERSION(avdevice)
00054     DEF_FFMPEG_LIB_VERSION(avformat)
00055     DEF_FFMPEG_LIB_VERSION(avutil)
00056     DEF_FFMPEG_LIB_VERSION(swscale)
00057     {NULL}
00058 };
00059 
00060 #undef DEF_FFMPEG_LIB_VERSION
00061 
00062 static PyStructSequence_Desc app_ffmpeg_info_desc = {
00063     (char *)"bpy.app.ffmpeg",     /* name */
00064     (char *)"This module contains information about FFmpeg blender is linked against",    /* doc */
00065     app_ffmpeg_info_fields,    /* fields */
00066     (sizeof(app_ffmpeg_info_fields) / sizeof(PyStructSequence_Field)) - 1
00067 };
00068 
00069 static PyObject *make_ffmpeg_info(void)
00070 {
00071     PyObject *ffmpeg_info;
00072     int pos = 0;
00073 
00074 #ifdef WITH_FFMPEG
00075     int curversion;
00076 #endif
00077 
00078     ffmpeg_info = PyStructSequence_New(&BlenderAppFFmpegType);
00079     if (ffmpeg_info == NULL) {
00080         return NULL;
00081     }
00082 
00083 #define SetIntItem(flag) \
00084     PyStructSequence_SET_ITEM(ffmpeg_info, pos++, PyLong_FromLong(flag))
00085 #define SetStrItem(str) \
00086     PyStructSequence_SET_ITEM(ffmpeg_info, pos++, PyUnicode_FromString(str))
00087 #define SetObjItem(obj) \
00088     PyStructSequence_SET_ITEM(ffmpeg_info, pos++, obj)
00089 
00090 #ifdef WITH_FFMPEG
00091     #define FFMPEG_LIB_VERSION(lib) \
00092         curversion = lib ## _version(); \
00093         SetObjItem(Py_BuildValue("(iii)", \
00094                 curversion >> 16, (curversion >> 8) % 256, curversion % 256)); \
00095         SetObjItem(PyUnicode_FromFormat("%2d, %2d, %2d", \
00096                 curversion >> 16, (curversion >> 8) % 256, curversion % 256));
00097 #else
00098     #define FFMPEG_LIB_VERSION(lib) \
00099         SetStrItem("Unknown"); \
00100         SetStrItem("Unknown");
00101 #endif
00102 
00103 #ifdef WITH_FFMPEG
00104     SetObjItem(PyBool_FromLong(1));
00105 #else
00106     SetObjItem(PyBool_FromLong(0));
00107 #endif
00108 
00109     FFMPEG_LIB_VERSION(avcodec);
00110     FFMPEG_LIB_VERSION(avdevice);
00111     FFMPEG_LIB_VERSION(avformat);
00112     FFMPEG_LIB_VERSION(avutil);
00113     FFMPEG_LIB_VERSION(swscale);
00114 
00115 #undef FFMPEG_LIB_VERSION
00116 
00117     if (PyErr_Occurred()) {
00118         Py_CLEAR(ffmpeg_info);
00119         return NULL;
00120     }
00121 
00122 #undef SetIntItem
00123 #undef SetStrItem
00124 #undef SetObjItem
00125 
00126     return ffmpeg_info;
00127 }
00128 
00129 PyObject *BPY_app_ffmpeg_struct(void)
00130 {
00131     PyObject *ret;
00132 
00133     PyStructSequence_InitType(&BlenderAppFFmpegType, &app_ffmpeg_info_desc);
00134 
00135     ret = make_ffmpeg_info();
00136 
00137     /* prevent user from creating new instances */
00138     BlenderAppFFmpegType.tp_init = NULL;
00139     BlenderAppFFmpegType.tp_new = NULL;
00140     BlenderAppFFmpegType.tp_hash = (hashfunc)_Py_HashPointer; /* without this we can't do set(sys.modules) [#29635] */
00141 
00142     return ret;
00143 }