| 
									
										
										
										
											2011-12-28 12:35:58 +00:00
										 |  |  | /*
 | 
					
						
							|  |  |  |  * This program is free software; you can redistribute it and/or | 
					
						
							|  |  |  |  * modify it under the terms of the GNU General Public License | 
					
						
							|  |  |  |  * as published by the Free Software Foundation; either version 2 | 
					
						
							|  |  |  |  * of the License, or (at your option) any later version. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * This program is distributed in the hope that it will be useful, | 
					
						
							|  |  |  |  * but WITHOUT ANY WARRANTY; without even the implied warranty of | 
					
						
							|  |  |  |  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | 
					
						
							|  |  |  |  * GNU General Public License for more details. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-02-18 08:08:12 +11:00
										 |  |  | /** \file
 | 
					
						
							|  |  |  |  * \ingroup pythonintern | 
					
						
							| 
									
										
										
										
											2011-12-28 12:35:58 +00:00
										 |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include "BLI_utildefines.h"
 | 
					
						
							| 
									
										
										
										
											2020-03-19 09:33:03 +01:00
										 |  |  | #include <Python.h>
 | 
					
						
							| 
									
										
										
										
											2011-12-28 12:35:58 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-09-15 01:52:28 +00:00
										 |  |  | #include "bpy_app_ffmpeg.h"
 | 
					
						
							| 
									
										
										
										
											2011-12-28 12:35:58 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-08-22 18:02:58 +10:00
										 |  |  | #include "../generic/py_capi_utils.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-12-28 12:35:58 +00:00
										 |  |  | #ifdef WITH_FFMPEG
 | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | #  include <libavcodec/avcodec.h>
 | 
					
						
							|  |  |  | #  include <libavdevice/avdevice.h>
 | 
					
						
							|  |  |  | #  include <libavformat/avformat.h>
 | 
					
						
							|  |  |  | #  include <libavutil/avutil.h>
 | 
					
						
							|  |  |  | #  include <libswscale/swscale.h>
 | 
					
						
							| 
									
										
										
										
											2011-12-28 12:35:58 +00:00
										 |  |  | #endif
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static PyTypeObject BlenderAppFFmpegType; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #define DEF_FFMPEG_LIB_VERSION(lib) \
 | 
					
						
							| 
									
										
										
										
											2019-12-20 10:42:57 +11:00
										 |  |  |   {(#lib "_version"), ("The " #lib " version  as a tuple of 3 numbers")}, \ | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |   { \ | 
					
						
							| 
									
										
										
										
											2019-12-20 10:42:57 +11:00
										 |  |  |     (#lib "_version_string"), ("The " #lib " version formatted as a string") \ | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2011-12-28 12:35:58 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | static PyStructSequence_Field app_ffmpeg_info_fields[] = { | 
					
						
							| 
									
										
										
										
											2019-12-20 10:42:57 +11:00
										 |  |  |     {"supported", "Boolean, True when Blender is built with FFmpeg support"}, | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     DEF_FFMPEG_LIB_VERSION(avcodec), | 
					
						
							|  |  |  |     DEF_FFMPEG_LIB_VERSION(avdevice), | 
					
						
							|  |  |  |     DEF_FFMPEG_LIB_VERSION(avformat), | 
					
						
							|  |  |  |     DEF_FFMPEG_LIB_VERSION(avutil), | 
					
						
							|  |  |  |     DEF_FFMPEG_LIB_VERSION(swscale), | 
					
						
							|  |  |  |     {NULL}, | 
					
						
							| 
									
										
										
										
											2011-12-28 12:35:58 +00:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #undef DEF_FFMPEG_LIB_VERSION
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static PyStructSequence_Desc app_ffmpeg_info_desc = { | 
					
						
							| 
									
										
										
										
											2019-12-20 10:42:57 +11:00
										 |  |  |     "bpy.app.ffmpeg",                                                          /* name */ | 
					
						
							|  |  |  |     "This module contains information about FFmpeg blender is linked against", /* doc */ | 
					
						
							|  |  |  |     app_ffmpeg_info_fields,                                                    /* fields */ | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |     ARRAY_SIZE(app_ffmpeg_info_fields) - 1, | 
					
						
							| 
									
										
										
										
											2011-12-28 12:35:58 +00:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static PyObject *make_ffmpeg_info(void) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |   PyObject *ffmpeg_info; | 
					
						
							|  |  |  |   int pos = 0; | 
					
						
							| 
									
										
										
										
											2011-12-28 13:50:33 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | #ifdef WITH_FFMPEG
 | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |   int curversion; | 
					
						
							| 
									
										
										
										
											2011-12-28 13:50:33 +00:00
										 |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2011-12-28 12:35:58 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |   ffmpeg_info = PyStructSequence_New(&BlenderAppFFmpegType); | 
					
						
							|  |  |  |   if (ffmpeg_info == NULL) { | 
					
						
							|  |  |  |     return NULL; | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2011-12-28 12:35:58 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | #if 0  // UNUSED
 | 
					
						
							|  |  |  | #  define SetIntItem(flag) PyStructSequence_SET_ITEM(ffmpeg_info, pos++, PyLong_FromLong(flag))
 | 
					
						
							| 
									
										
										
										
											2012-09-20 01:02:39 +00:00
										 |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2013-03-25 02:41:30 +00:00
										 |  |  | #ifndef WITH_FFMPEG
 | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | #  define SetStrItem(str) PyStructSequence_SET_ITEM(ffmpeg_info, pos++, PyUnicode_FromString(str))
 | 
					
						
							| 
									
										
										
										
											2013-03-25 02:41:30 +00:00
										 |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | #define SetObjItem(obj) PyStructSequence_SET_ITEM(ffmpeg_info, pos++, obj)
 | 
					
						
							| 
									
										
										
										
											2011-12-28 12:35:58 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | #ifdef WITH_FFMPEG
 | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | #  define FFMPEG_LIB_VERSION(lib) \
 | 
					
						
							|  |  |  |     { \ | 
					
						
							|  |  |  |       curversion = lib##_version(); \ | 
					
						
							|  |  |  |       SetObjItem( \ | 
					
						
							|  |  |  |           PyC_Tuple_Pack_I32(curversion >> 16, (curversion >> 8) % 256, curversion % 256)); \ | 
					
						
							|  |  |  |       SetObjItem(PyUnicode_FromFormat( \ | 
					
						
							|  |  |  |           "%2d, %2d, %2d", curversion >> 16, (curversion >> 8) % 256, curversion % 256)); \ | 
					
						
							|  |  |  |     } \ | 
					
						
							|  |  |  |     (void)0 | 
					
						
							| 
									
										
										
										
											2011-12-28 12:35:58 +00:00
										 |  |  | #else
 | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | #  define FFMPEG_LIB_VERSION(lib) \
 | 
					
						
							|  |  |  |     { \ | 
					
						
							|  |  |  |       SetStrItem("Unknown"); \ | 
					
						
							|  |  |  |       SetStrItem("Unknown"); \ | 
					
						
							|  |  |  |     } \ | 
					
						
							|  |  |  |     (void)0 | 
					
						
							| 
									
										
										
										
											2011-12-28 12:35:58 +00:00
										 |  |  | #endif
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #ifdef WITH_FFMPEG
 | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |   SetObjItem(PyBool_FromLong(1)); | 
					
						
							| 
									
										
										
										
											2011-12-28 12:35:58 +00:00
										 |  |  | #else
 | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |   SetObjItem(PyBool_FromLong(0)); | 
					
						
							| 
									
										
										
										
											2011-12-28 12:35:58 +00:00
										 |  |  | #endif
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |   FFMPEG_LIB_VERSION(avcodec); | 
					
						
							|  |  |  |   FFMPEG_LIB_VERSION(avdevice); | 
					
						
							|  |  |  |   FFMPEG_LIB_VERSION(avformat); | 
					
						
							|  |  |  |   FFMPEG_LIB_VERSION(avutil); | 
					
						
							|  |  |  |   FFMPEG_LIB_VERSION(swscale); | 
					
						
							| 
									
										
										
										
											2011-12-28 12:35:58 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | #undef FFMPEG_LIB_VERSION
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |   if (PyErr_Occurred()) { | 
					
						
							|  |  |  |     Py_CLEAR(ffmpeg_info); | 
					
						
							|  |  |  |     return NULL; | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2011-12-28 12:35:58 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-09-20 01:02:39 +00:00
										 |  |  | // #undef SetIntItem
 | 
					
						
							| 
									
										
										
										
											2011-12-28 12:35:58 +00:00
										 |  |  | #undef SetStrItem
 | 
					
						
							|  |  |  | #undef SetObjItem
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |   return ffmpeg_info; | 
					
						
							| 
									
										
										
										
											2011-12-28 12:35:58 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | PyObject *BPY_app_ffmpeg_struct(void) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |   PyObject *ret; | 
					
						
							| 
									
										
										
										
											2011-12-28 12:35:58 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |   PyStructSequence_InitType(&BlenderAppFFmpegType, &app_ffmpeg_info_desc); | 
					
						
							| 
									
										
										
										
											2011-12-28 12:35:58 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |   ret = make_ffmpeg_info(); | 
					
						
							| 
									
										
										
										
											2011-12-28 12:35:58 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |   /* prevent user from creating new instances */ | 
					
						
							|  |  |  |   BlenderAppFFmpegType.tp_init = NULL; | 
					
						
							|  |  |  |   BlenderAppFFmpegType.tp_new = NULL; | 
					
						
							|  |  |  |   BlenderAppFFmpegType.tp_hash = (hashfunc) | 
					
						
							| 
									
										
										
										
											2020-09-30 20:09:02 +10:00
										 |  |  |       _Py_HashPointer; /* without this we can't do set(sys.modules) T29635. */ | 
					
						
							| 
									
										
										
										
											2011-12-28 12:35:58 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |   return ret; | 
					
						
							| 
									
										
										
										
											2011-12-28 12:35:58 +00:00
										 |  |  | } |