1 /*
2  * copyright (c) 2003 Fabrice Bellard
3  *
4  * This file is part of FFmpeg.
5  *
6  * FFmpeg is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * FFmpeg is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with FFmpeg; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19  */
20 module ffmpeg.libavutil.avutil;
21 
22 import std.stdint;
23 import std.format;
24 import std.array;
25 import core.vararg;
26 
27 public import ffmpeg.libavutil.common;
28 public import ffmpeg.libavutil.rational;
29 public import ffmpeg.libavutil.samplefmt;
30 public import ffmpeg.libavutil.frame;
31 public import ffmpeg.libavutil.pixfmt;
32 public import ffmpeg.libavutil.log;
33 public import ffmpeg.libavutil.dict;
34 public import ffmpeg.libavutil.error;
35 public import ffmpeg.libavutil.mathematics;
36 public import ffmpeg.libavutil.channel_layout;
37 public import ffmpeg.libavutil.avutil_version;
38 
39 extern(C): 
40 /*
41  * @mainpage
42  *
43  * @section libav_intro Introduction
44  *
45  * This document describes the usage of the different libraries
46  * provided by FFmpeg.
47  *
48  * @li @ref libavc "libavcodec" encoding/decoding library
49  * @li @subpage libavfilter graph based frame editing library
50  * @li @ref libavf "libavformat" I/O and muxing/demuxing library
51  * @li @ref lavd "libavdevice" special devices muxing/demuxing library
52  * @li @ref lavu "libavutil" common utility library
53  * @li @subpage libpostproc post processing library
54  * @li @subpage libswscale  color conversion and scaling library
55  */
56 
57 /**
58  * @defgroup lavu Common utility functions
59  *
60  * @brief
61  * libavutil contains the code shared across all the other FFmpeg
62  * libraries
63  *
64  * @note In order to use the functions provided by avutil you must include
65  * the specific header.
66  *
67  * @{
68  *
69  * @defgroup lavu_crypto Crypto and Hashing
70  *
71  * @{
72  * @}
73  *
74  * @defgroup lavu_math Maths
75  * @{
76  *
77  * @}
78  *
79  * @defgroup lavu_string String Manipulation
80  *
81  * @{
82  *
83  * @}
84  *
85  * @defgroup lavu_mem Memory Management
86  *
87  * @{
88  *
89  * @}
90  *
91  * @defgroup lavu_data Data Structures
92  * @{
93  *
94  * @}
95  *
96  * @defgroup lavu_audio Audio related
97  *
98  * @{
99  *
100  * @}
101  *
102  * @defgroup lavu_error Error Codes
103  *
104  * @{
105  *
106  * @}
107  *
108  * @defgroup lavu_misc Other
109  *
110  * @{
111  *
112  * @defgroup lavu_internal Internal
113  *
114  * Not exported functions, for internal usage only
115  *
116  * @{
117  *
118  * @}
119  */
120 
121 /**
122  * @addtogroup lavu_ver
123  * @{
124  */
125 
126 /**
127  * Return the LIBAVUTIL_VERSION_INT constant.
128  */
129 uint avutil_version();
130 
131 /**
132  * Return the libavutil build-time configuration.
133  */
134 char *avutil_configuration();
135 
136 /**
137  * Return the libavutil license.
138  */
139 char *avutil_license();
140 
141 /**
142  * @}
143  */
144 
145 /**
146  * @addtogroup lavu_media Media Type
147  * @brief Media Type
148  */
149 
150 enum AVMediaType {
151     AVMEDIA_TYPE_UNKNOWN = -1,  ///< Usually treated as AVMEDIA_TYPE_DATA
152     AVMEDIA_TYPE_VIDEO,
153     AVMEDIA_TYPE_AUDIO,
154     AVMEDIA_TYPE_DATA,          ///< Opaque data information usually continuous
155     AVMEDIA_TYPE_SUBTITLE,
156     AVMEDIA_TYPE_ATTACHMENT,    ///< Opaque data information usually sparse
157     AVMEDIA_TYPE_NB
158 } 
159 
160 /**
161  * Return a string describing the media_type enum, NULL if media_type
162  * is unknown.
163  */
164 char* av_get_media_type_string(AVMediaType media_type);
165 
166 /**
167  * @defgroup lavu_const Constants
168  * @{
169  *
170  * @defgroup lavu_enc Encoding specific
171  *
172  * @note those definition should move to avcodec
173  * @{
174  */
175 
176 enum FF_LAMBDA_SHIFT = 7;
177 enum FF_LAMBDA_SCALE = (1<<FF_LAMBDA_SHIFT);
178 enum FF_QP2LAMBDA = 118; ///< factor to convert from H.263 QP to lambda
179 enum FF_LAMBDA_MAX = (256*128-1);
180 
181 enum FF_QUALITY_SCALE = FF_LAMBDA_SCALE; //FIXME maybe remove
182 
183 /**
184  * @}
185  * @defgroup lavu_time Timestamp specific
186  *
187  * FFmpeg internal timebase and timestamp definitions
188  *
189  * @{
190  */
191 
192 /**
193  * @brief Undefined timestamp value
194  *
195  * Usually reported by demuxer that work on containers that do not provide
196  * either pts or dts.
197  */
198 
199 enum AV_NOPTS_VALUE = 0x8000000000000000;
200 
201 
202 /**
203  * Internal time base represented as integer
204  */
205 
206 enum AV_TIME_BASE = 1000000;
207 
208 /**
209  * Internal time base represented as fractional value
210  */
211 
212 AVRational AV_TIME_BASE_Q = {num:1, den:AV_TIME_BASE};
213 
214 /**
215  * @}
216  * @}
217  * @defgroup lavu_picture Image related
218  *
219  * AVPicture types, pixel formats and basic image planes manipulation.
220  *
221  * @{
222  */
223 enum AVPictureType {
224       AV_PICTURE_TYPE_NONE = 0,
225       AV_PICTURE_TYPE_I,
226       AV_PICTURE_TYPE_P,
227       AV_PICTURE_TYPE_B,
228       AV_PICTURE_TYPE_S,
229       AV_PICTURE_TYPE_SI,
230       AV_PICTURE_TYPE_SP,
231       AV_PICTURE_TYPE_BI
232 }
233 
234 /**
235  * Return a single letter to describe the given picture type
236  * pict_type.
237  *
238  * @param[in] pict_type the picture type @return a single character
239  * representing the picture type, '?' if pict_type is unknown
240  */
241 char av_get_picture_type_char(AVPictureType pict_type);
242 // end avutil.h
243   
244 /**
245  * Fill the provided buffer with a string containing a timestamp time
246  * representation.
247  *
248  * @param buf a buffer with size in bytes of at least AV_TS_MAX_STRING_SIZE
249  * @param ts the timestamp to represent
250  * @param tb the timebase of the timestamp
251  * @return the buffer in input
252  */
253 string av_ts_make_time_string(int64_t ts, AVRational tb)
254 {
255   import std.format; 
256   import std.array;
257   if (ts == AV_NOPTS_VALUE) {
258     return "No Value";
259   } else {
260     auto toTs = av_q2d(tb) * ts;
261     auto writer = appender!string(); 
262     formattedWrite(writer, "%.6g", toTs);
263     return writer.data;
264   }
265 }
266 
267 /**
268  * Return x default pointer in case p is NULL.
269  */
270 //static inline void *av_x_if_null(const void *p, const void *x)
271 //{
272 //    return (void *)(intptr_t)(p ? p : x);
273 //}
274 
275 /**
276  * Compute the length of an integer list.
277  *
278  * @param elsize  size in bytes of each list element (only 1, 2, 4 or 8)
279  * @param term    list terminator (usually 0 or -1)
280  * @param list    pointer to the list
281  * @return  length of the list, in elements, not counting the terminator
282  */
283 //unsigned av_int_list_length_for_size(unsigned elsize,
284 //                                    const void *list, uint64_t term) av_pure;
285 
286 /**
287  * Compute the length of an integer list.
288  *
289  * @param term  list terminator (usually 0 or -1)
290  * @param list  pointer to the list
291  * @return  length of the list, in elements, not counting the terminator
292  */
293 //#define av_int_list_length(list, term) \
294 //av_int_list_length_for_size(sizeof(*(list)), list, term)
295 
296 /**
297  * Open a file using a UTF-8 filename.
298  * The API of this function matches POSIX fopen(), errors are returned through
299  * errno.
300  */
301 //FILE *av_fopen_utf8(const char *path, const char *mode);
302 
303 /**
304  * Return the fractional representation of the internal time base.
305  */
306 //AVRational av_get_time_base_q(void);
307 
308 /**
309  * @}
310  * @}
311  */