Blender  V2.93
bpy_app_ffmpeg.c
Go to the documentation of this file.
1 /*
2  * This program is free software; you can redistribute it and/or
3  * modify it under the terms of the GNU General Public License
4  * as published by the Free Software Foundation; either version 2
5  * of the License, or (at your option) any later version.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program; if not, write to the Free Software Foundation,
14  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
15  */
16 
21 #include "BLI_utildefines.h"
22 #include <Python.h>
23 
24 #include "bpy_app_ffmpeg.h"
25 
26 #include "../generic/py_capi_utils.h"
27 
28 #ifdef WITH_FFMPEG
29 # include <libavcodec/avcodec.h>
30 # include <libavdevice/avdevice.h>
31 # include <libavformat/avformat.h>
32 # include <libavutil/avutil.h>
33 # include <libswscale/swscale.h>
34 #endif
35 
36 static PyTypeObject BlenderAppFFmpegType;
37 
38 #define DEF_FFMPEG_LIB_VERSION(lib) \
39  {(#lib "_version"), ("The " #lib " version as a tuple of 3 numbers")}, \
40  { \
41  (#lib "_version_string"), ("The " #lib " version formatted as a string") \
42  }
43 
44 static PyStructSequence_Field app_ffmpeg_info_fields[] = {
45  {"supported", "Boolean, True when Blender is built with FFmpeg support"},
46 
47  DEF_FFMPEG_LIB_VERSION(avcodec),
48  DEF_FFMPEG_LIB_VERSION(avdevice),
49  DEF_FFMPEG_LIB_VERSION(avformat),
50  DEF_FFMPEG_LIB_VERSION(avutil),
51  DEF_FFMPEG_LIB_VERSION(swscale),
52  {NULL},
53 };
54 
55 #undef DEF_FFMPEG_LIB_VERSION
56 
57 static PyStructSequence_Desc app_ffmpeg_info_desc = {
58  "bpy.app.ffmpeg", /* name */
59  "This module contains information about FFmpeg blender is linked against", /* doc */
60  app_ffmpeg_info_fields, /* fields */
62 };
63 
64 static PyObject *make_ffmpeg_info(void)
65 {
66  PyObject *ffmpeg_info;
67  int pos = 0;
68 
69 #ifdef WITH_FFMPEG
70  int curversion;
71 #endif
72 
73  ffmpeg_info = PyStructSequence_New(&BlenderAppFFmpegType);
74  if (ffmpeg_info == NULL) {
75  return NULL;
76  }
77 
78 #if 0 /* UNUSED */
79 # define SetIntItem(flag) PyStructSequence_SET_ITEM(ffmpeg_info, pos++, PyLong_FromLong(flag))
80 #endif
81 #ifndef WITH_FFMPEG
82 # define SetStrItem(str) PyStructSequence_SET_ITEM(ffmpeg_info, pos++, PyUnicode_FromString(str))
83 #endif
84 #define SetObjItem(obj) PyStructSequence_SET_ITEM(ffmpeg_info, pos++, obj)
85 
86 #ifdef WITH_FFMPEG
87 # define FFMPEG_LIB_VERSION(lib) \
88  { \
89  curversion = lib##_version(); \
90  SetObjItem( \
91  PyC_Tuple_Pack_I32(curversion >> 16, (curversion >> 8) % 256, curversion % 256)); \
92  SetObjItem(PyUnicode_FromFormat( \
93  "%2d, %2d, %2d", curversion >> 16, (curversion >> 8) % 256, curversion % 256)); \
94  } \
95  (void)0
96 #else
97 # define FFMPEG_LIB_VERSION(lib) \
98  { \
99  SetStrItem("Unknown"); \
100  SetStrItem("Unknown"); \
101  } \
102  (void)0
103 #endif
104 
105 #ifdef WITH_FFMPEG
106  SetObjItem(PyBool_FromLong(1));
107 #else
108  SetObjItem(PyBool_FromLong(0));
109 #endif
110 
111  FFMPEG_LIB_VERSION(avcodec);
112  FFMPEG_LIB_VERSION(avdevice);
113  FFMPEG_LIB_VERSION(avformat);
114  FFMPEG_LIB_VERSION(avutil);
115  FFMPEG_LIB_VERSION(swscale);
116 
117 #undef FFMPEG_LIB_VERSION
118 
119  if (UNLIKELY(PyErr_Occurred())) {
120  Py_DECREF(ffmpeg_info);
121  return NULL;
122  }
123 
124 // #undef SetIntItem
125 #undef SetStrItem
126 #undef SetObjItem
127 
128  return ffmpeg_info;
129 }
130 
131 PyObject *BPY_app_ffmpeg_struct(void)
132 {
133  PyObject *ret;
134 
135  PyStructSequence_InitType(&BlenderAppFFmpegType, &app_ffmpeg_info_desc);
136 
137  ret = make_ffmpeg_info();
138 
139  /* prevent user from creating new instances */
140  BlenderAppFFmpegType.tp_init = NULL;
141  BlenderAppFFmpegType.tp_new = NULL;
142  BlenderAppFFmpegType.tp_hash = (hashfunc)
143  _Py_HashPointer; /* without this we can't do set(sys.modules) T29635. */
144 
145  return ret;
146 }
#define ARRAY_SIZE(arr)
#define UNLIKELY(x)
#define DEF_FFMPEG_LIB_VERSION(lib)
static PyObject * make_ffmpeg_info(void)
static PyTypeObject BlenderAppFFmpegType
PyObject * BPY_app_ffmpeg_struct(void)
static PyStructSequence_Desc app_ffmpeg_info_desc
static PyStructSequence_Field app_ffmpeg_info_fields[]
#define FFMPEG_LIB_VERSION(lib)
#define SetObjItem(obj)
uint pos
return ret