/work/libde265/libde265/de265.cc
Line | Count | Source |
1 | | /* |
2 | | * H.265 video codec. |
3 | | * Copyright (c) 2013-2014 struktur AG, Dirk Farin <farin@struktur.de> |
4 | | * |
5 | | * This file is part of libde265. |
6 | | * |
7 | | * libde265 is free software: you can redistribute it and/or modify |
8 | | * it under the terms of the GNU Lesser General Public License as |
9 | | * published by the Free Software Foundation, either version 3 of |
10 | | * the License, or (at your option) any later version. |
11 | | * |
12 | | * libde265 is distributed in the hope that it will be useful, |
13 | | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
14 | | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
15 | | * GNU Lesser General Public License for more details. |
16 | | * |
17 | | * You should have received a copy of the GNU Lesser General Public License |
18 | | * along with libde265. If not, see <http://www.gnu.org/licenses/>. |
19 | | */ |
20 | | |
21 | | #define DEBUG_INSERT_STREAM_ERRORS 0 |
22 | | |
23 | | |
24 | | #include "de265.h" |
25 | | #include "decctx.h" |
26 | | #include "util.h" |
27 | | #include "scan.h" |
28 | | #include "image.h" |
29 | | #include "sei.h" |
30 | | |
31 | | #include <assert.h> |
32 | | #include <string.h> |
33 | | #include <stdlib.h> |
34 | | #include <mutex> |
35 | | |
36 | | |
37 | | // TODO: should be in some vps.c related header |
38 | | de265_error read_vps(decoder_context* ctx, bitreader* reader, video_parameter_set* vps); |
39 | | |
40 | | extern "C" { |
41 | | LIBDE265_API const char *de265_get_version(void) |
42 | 0 | { |
43 | 0 | return (LIBDE265_VERSION); |
44 | 0 | } |
45 | | |
46 | | LIBDE265_API uint32_t de265_get_version_number(void) |
47 | 0 | { |
48 | 0 | return (LIBDE265_NUMERIC_VERSION); |
49 | 0 | } |
50 | | |
51 | | static uint8_t bcd2dec(uint8_t v) |
52 | 0 | { |
53 | 0 | return (v>>4) * 10 + (v & 0x0F); |
54 | 0 | } |
55 | | |
56 | | LIBDE265_API int de265_get_version_number_major(void) |
57 | 0 | { |
58 | 0 | return bcd2dec(((LIBDE265_NUMERIC_VERSION)>>24) & 0xFF); |
59 | 0 | } |
60 | | |
61 | | LIBDE265_API int de265_get_version_number_minor(void) |
62 | 0 | { |
63 | 0 | return bcd2dec(((LIBDE265_NUMERIC_VERSION)>>16) & 0xFF); |
64 | 0 | } |
65 | | |
66 | | LIBDE265_API int de265_get_version_number_maintenance(void) |
67 | 0 | { |
68 | 0 | return bcd2dec(((LIBDE265_NUMERIC_VERSION)>>8) & 0xFF); |
69 | 0 | } |
70 | | |
71 | | |
72 | | LIBDE265_API const char* de265_get_error_text(de265_error err) |
73 | 0 | { |
74 | 0 | switch (err) { |
75 | 0 | case DE265_OK: return "no error"; |
76 | 0 | case DE265_ERROR_NO_SUCH_FILE: return "no such file"; |
77 | | //case DE265_ERROR_NO_STARTCODE: return "no startcode found"; |
78 | | //case DE265_ERROR_EOF: return "end of file"; |
79 | 0 | case DE265_ERROR_COEFFICIENT_OUT_OF_IMAGE_BOUNDS: return "coefficient out of image bounds"; |
80 | 0 | case DE265_ERROR_CHECKSUM_MISMATCH: return "image checksum mismatch"; |
81 | 0 | case DE265_ERROR_CTB_OUTSIDE_IMAGE_AREA: return "CTB outside of image area"; |
82 | 0 | case DE265_ERROR_OUT_OF_MEMORY: return "out of memory"; |
83 | 0 | case DE265_ERROR_CODED_PARAMETER_OUT_OF_RANGE: return "coded parameter out of range"; |
84 | 0 | case DE265_ERROR_IMAGE_BUFFER_FULL: return "DPB/output queue full"; |
85 | 0 | case DE265_ERROR_IMAGE_SIZE_EXCEEDS_SECURITY_LIMIT: return "image size exceeds security limit"; |
86 | 0 | case DE265_ERROR_NAL_SIZE_EXCEEDS_SECURITY_LIMIT: return "NAL unit size exceeds security limit"; |
87 | 0 | case DE265_ERROR_CANNOT_START_THREADPOOL: return "cannot start decoding threads"; |
88 | 0 | case DE265_ERROR_LIBRARY_INITIALIZATION_FAILED: return "global library initialization failed"; |
89 | 0 | case DE265_ERROR_LIBRARY_NOT_INITIALIZED: return "cannot free library data (not initialized"; |
90 | | |
91 | | //case DE265_ERROR_MAX_THREAD_CONTEXTS_EXCEEDED: |
92 | | // return "internal error: maximum number of thread contexts exceeded"; |
93 | | //case DE265_ERROR_MAX_NUMBER_OF_SLICES_EXCEEDED: |
94 | | // return "internal error: maximum number of slices exceeded"; |
95 | 0 | case DE265_ERROR_NOT_IMPLEMENTED_YET: |
96 | 0 | return "unimplemented decoder feature"; |
97 | | //case DE265_ERROR_SCALING_LIST_NOT_IMPLEMENTED: |
98 | | //return "scaling list not implemented"; |
99 | | |
100 | 0 | case DE265_ERROR_WAITING_FOR_INPUT_DATA: |
101 | 0 | return "no more input data, decoder stalled"; |
102 | 0 | case DE265_ERROR_CANNOT_PROCESS_SEI: |
103 | 0 | return "SEI data cannot be processed"; |
104 | 0 | case DE265_ERROR_PARAMETER_PARSING: |
105 | 0 | return "command-line parameter error"; |
106 | 0 | case DE265_ERROR_NO_INITIAL_SLICE_HEADER: |
107 | 0 | return "first slice missing, cannot decode dependent slice"; |
108 | 0 | case DE265_ERROR_PREMATURE_END_OF_SLICE: |
109 | 0 | return "premature end of slice data"; |
110 | 0 | case DE265_ERROR_UNSPECIFIED_DECODING_ERROR: |
111 | 0 | return "unspecified decoding error"; |
112 | | |
113 | 0 | case DE265_WARNING_NO_WPP_CANNOT_USE_MULTITHREADING: |
114 | 0 | return "Cannot run decoder multi-threaded because stream does not support WPP"; |
115 | 0 | case DE265_WARNING_WARNING_BUFFER_FULL: |
116 | 0 | return "Too many warnings queued"; |
117 | 0 | case DE265_WARNING_PREMATURE_END_OF_SLICE_SEGMENT: |
118 | 0 | return "Premature end of slice segment"; |
119 | 0 | case DE265_WARNING_INCORRECT_ENTRY_POINT_OFFSET: |
120 | 0 | return "Incorrect entry-point offsets"; |
121 | 0 | case DE265_WARNING_CTB_OUTSIDE_IMAGE_AREA: |
122 | 0 | return "CTB outside of image area (concealing stream error...)"; |
123 | 0 | case DE265_WARNING_SPS_HEADER_INVALID: |
124 | 0 | return "sps header invalid"; |
125 | 0 | case DE265_WARNING_PPS_HEADER_INVALID: |
126 | 0 | return "pps header invalid"; |
127 | 0 | case DE265_WARNING_SLICEHEADER_INVALID: |
128 | 0 | return "slice header invalid"; |
129 | 0 | case DE265_WARNING_INCORRECT_MOTION_VECTOR_SCALING: |
130 | 0 | return "impossible motion vector scaling"; |
131 | 0 | case DE265_WARNING_NONEXISTING_PPS_REFERENCED: |
132 | 0 | return "non-existing PPS referenced"; |
133 | 0 | case DE265_WARNING_NONEXISTING_SPS_REFERENCED: |
134 | 0 | return "non-existing SPS referenced"; |
135 | 0 | case DE265_WARNING_BOTH_PREDFLAGS_ZERO: |
136 | 0 | return "both predFlags[] are zero in MC"; |
137 | 0 | case DE265_WARNING_NONEXISTING_REFERENCE_PICTURE_ACCESSED: |
138 | 0 | return "non-existing reference picture accessed"; |
139 | 0 | case DE265_WARNING_NUMMVP_NOT_EQUAL_TO_NUMMVQ: |
140 | 0 | return "numMV_P != numMV_Q in deblocking"; |
141 | 0 | case DE265_WARNING_NUMBER_OF_SHORT_TERM_REF_PIC_SETS_OUT_OF_RANGE: |
142 | 0 | return "number of short-term ref-pic-sets out of range"; |
143 | 0 | case DE265_WARNING_SHORT_TERM_REF_PIC_SET_OUT_OF_RANGE: |
144 | 0 | return "short-term ref-pic-set index out of range"; |
145 | 0 | case DE265_WARNING_FAULTY_REFERENCE_PICTURE_LIST: |
146 | 0 | return "faulty reference picture list"; |
147 | 0 | case DE265_WARNING_EOSS_BIT_NOT_SET: |
148 | 0 | return "end_of_sub_stream_one_bit not set to 1 when it should be"; |
149 | 0 | case DE265_WARNING_MAX_NUM_REF_PICS_EXCEEDED: |
150 | 0 | return "maximum number of reference pictures exceeded"; |
151 | 0 | case DE265_WARNING_INVALID_CHROMA_FORMAT: |
152 | 0 | return "invalid chroma format in SPS header"; |
153 | 0 | case DE265_WARNING_SLICE_SEGMENT_ADDRESS_INVALID: |
154 | 0 | return "slice segment address invalid"; |
155 | 0 | case DE265_WARNING_DEPENDENT_SLICE_WITH_ADDRESS_ZERO: |
156 | 0 | return "dependent slice with address 0"; |
157 | 0 | case DE265_WARNING_NUMBER_OF_THREADS_LIMITED_TO_MAXIMUM: |
158 | 0 | return "number of threads limited to maximum amount"; |
159 | 0 | case DE265_NON_EXISTING_LT_REFERENCE_CANDIDATE_IN_SLICE_HEADER: |
160 | 0 | return "non-existing long-term reference candidate specified in slice header"; |
161 | 0 | case DE265_WARNING_CANNOT_APPLY_SAO_OUT_OF_MEMORY: |
162 | 0 | return "cannot apply SAO because we ran out of memory"; |
163 | 0 | case DE265_WARNING_SPS_MISSING_CANNOT_DECODE_SEI: |
164 | 0 | return "SPS header missing, cannot decode SEI"; |
165 | 0 | case DE265_WARNING_COLLOCATED_MOTION_VECTOR_OUTSIDE_IMAGE_AREA: |
166 | 0 | return "collocated motion-vector is outside image area"; |
167 | 0 | case DE265_WARNING_PCM_BITDEPTH_TOO_LARGE: |
168 | 0 | return "PCM bit-depth too large"; |
169 | 0 | case DE265_WARNING_REFERENCE_IMAGE_BIT_DEPTH_DOES_NOT_MATCH: |
170 | 0 | return "Bit-depth of reference image does not match current image"; |
171 | 0 | case DE265_WARNING_REFERENCE_IMAGE_SIZE_DOES_NOT_MATCH_SPS: |
172 | 0 | return "Size of reference image does not match current size in SPS"; |
173 | 0 | case DE265_WARNING_CHROMA_OF_CURRENT_IMAGE_DOES_NOT_MATCH_SPS: |
174 | 0 | return "Chroma format of current image does not match chroma in SPS"; |
175 | 0 | case DE265_WARNING_BIT_DEPTH_OF_CURRENT_IMAGE_DOES_NOT_MATCH_SPS: |
176 | 0 | return "Bit-depth of current image does not match SPS"; |
177 | 0 | case DE265_WARNING_REFERENCE_IMAGE_CHROMA_FORMAT_DOES_NOT_MATCH: |
178 | 0 | return "Chroma format of reference image does not match current image"; |
179 | 0 | case DE265_WARNING_INVALID_SLICE_HEADER_INDEX_ACCESS: |
180 | 0 | return "Access with invalid slice header index"; |
181 | 0 | case DE265_WARNING_INVALID_TU_BLOCK_SPLIT: |
182 | 0 | return "Transform block split below minimum transform size"; |
183 | 0 | case DE265_WARNING_RICE_PARAMETER_OUT_OF_RANGE: |
184 | 0 | return "Rice parameter or StatCoeff out of range, clamped"; |
185 | 0 | case DE265_WARNING_MAX_NUMBER_OF_SEI_MESSAGES_EXCEEDED: |
186 | 0 | return "number of SEI messages exceeds security limit, dropped"; |
187 | | |
188 | 0 | default: return "unknown error"; |
189 | 0 | } |
190 | 0 | } |
191 | | |
192 | | LIBDE265_API int de265_isOK(de265_error err) |
193 | 1.68k | { |
194 | 1.68k | return err == DE265_OK || err >= 1000; |
195 | 1.68k | } |
196 | | |
197 | | |
198 | | |
199 | | static int de265_init_count; |
200 | | |
201 | | static std::mutex& de265_init_mutex() |
202 | 3.38k | { |
203 | 3.38k | static std::mutex de265_init_mutex; |
204 | 3.38k | return de265_init_mutex; |
205 | 3.38k | } |
206 | | |
207 | | |
208 | | LIBDE265_API de265_error de265_init() |
209 | 1.69k | { |
210 | 1.69k | std::lock_guard<std::mutex> lock(de265_init_mutex()); |
211 | | |
212 | 1.69k | de265_init_count++; |
213 | | |
214 | 1.69k | if (de265_init_count > 1) { |
215 | | // we are not the first -> already initialized |
216 | | |
217 | 1.68k | return DE265_OK; |
218 | 1.68k | } |
219 | | |
220 | | |
221 | | // do initializations |
222 | | |
223 | 13 | init_scan_orders(); |
224 | | |
225 | 13 | if (!alloc_and_init_significant_coeff_ctxIdx_lookupTable()) { |
226 | 0 | de265_init_count--; |
227 | 0 | return DE265_ERROR_LIBRARY_INITIALIZATION_FAILED; |
228 | 0 | } |
229 | | |
230 | 13 | return DE265_OK; |
231 | 13 | } |
232 | | |
233 | | LIBDE265_API de265_error de265_free() |
234 | 1.68k | { |
235 | 1.68k | std::lock_guard<std::mutex> lock(de265_init_mutex()); |
236 | | |
237 | 1.68k | if (de265_init_count<=0) { |
238 | 0 | return DE265_ERROR_LIBRARY_NOT_INITIALIZED; |
239 | 0 | } |
240 | | |
241 | 1.68k | de265_init_count--; |
242 | | |
243 | 1.68k | if (de265_init_count==0) { |
244 | 1 | free_significant_coeff_ctxIdx_lookupTable(); |
245 | 1 | } |
246 | | |
247 | 1.68k | return DE265_OK; |
248 | 1.68k | } |
249 | | |
250 | | |
251 | | LIBDE265_API de265_decoder_context* de265_new_decoder() |
252 | 1.68k | { |
253 | 1.68k | de265_error init_err = de265_init(); |
254 | 1.68k | if (init_err != DE265_OK) { |
255 | 0 | return nullptr; |
256 | 0 | } |
257 | | |
258 | 1.68k | decoder_context* ctx = new decoder_context; |
259 | 1.68k | if (!ctx) { |
260 | 0 | de265_free(); |
261 | 0 | return nullptr; |
262 | 0 | } |
263 | | |
264 | 1.68k | return reinterpret_cast<de265_decoder_context*>(ctx); |
265 | 1.68k | } |
266 | | |
267 | | |
268 | | LIBDE265_API de265_error de265_free_decoder(de265_decoder_context* de265ctx) |
269 | 1.68k | { |
270 | 1.68k | decoder_context* ctx = reinterpret_cast<decoder_context*>(de265ctx); |
271 | | |
272 | 1.68k | ctx->stop_thread_pool(); |
273 | | |
274 | 1.68k | delete ctx; |
275 | | |
276 | 1.68k | return de265_free(); |
277 | 1.68k | } |
278 | | |
279 | | |
280 | | LIBDE265_API de265_error de265_start_worker_threads(de265_decoder_context* de265ctx, int number_of_threads) |
281 | 1.68k | { |
282 | 1.68k | decoder_context* ctx = reinterpret_cast<decoder_context*>(de265ctx); |
283 | | |
284 | 1.68k | if (number_of_threads > MAX_THREADS) { |
285 | 0 | number_of_threads = MAX_THREADS; |
286 | 0 | } |
287 | | |
288 | 1.68k | if (number_of_threads>0) { |
289 | 1.68k | de265_error err = ctx->start_thread_pool(number_of_threads); |
290 | 1.68k | if (de265_isOK(err)) { |
291 | 1.68k | err = DE265_OK; |
292 | 1.68k | } |
293 | 1.68k | return err; |
294 | 1.68k | } |
295 | 0 | else { |
296 | 0 | return DE265_OK; |
297 | 0 | } |
298 | 1.68k | } |
299 | | |
300 | | |
301 | | #ifndef LIBDE265_DISABLE_DEPRECATED |
302 | | LIBDE265_API de265_error de265_decode_data(de265_decoder_context* de265ctx, |
303 | | const void* data8, int len) |
304 | 0 | { |
305 | | //decoder_context* ctx = reinterpret_cast<decoder_context*>(de265ctx); |
306 | 0 | de265_error err; |
307 | 0 | if (len > 0) { |
308 | 0 | err = de265_push_data(de265ctx, data8, len, 0, nullptr); |
309 | 0 | } else { |
310 | 0 | err = de265_flush_data(de265ctx); |
311 | 0 | } |
312 | 0 | if (err != DE265_OK) { |
313 | 0 | return err; |
314 | 0 | } |
315 | | |
316 | 0 | int more = 0; |
317 | 0 | do { |
318 | 0 | err = de265_decode(de265ctx, &more); |
319 | 0 | if (err != DE265_OK) { |
320 | 0 | more = 0; |
321 | 0 | } |
322 | |
|
323 | 0 | switch (err) { |
324 | 0 | case DE265_ERROR_WAITING_FOR_INPUT_DATA: |
325 | | // ignore error (didn't exist in 0.4 and before) |
326 | 0 | err = DE265_OK; |
327 | 0 | break; |
328 | 0 | default: |
329 | 0 | break; |
330 | 0 | } |
331 | 0 | } while (more); |
332 | 0 | return err; |
333 | 0 | } |
334 | | #endif |
335 | | |
336 | | #if 0 |
337 | | static void dumpdata(const void* data, int len) |
338 | | { |
339 | | for (int i=0;i<len;i++) { |
340 | | printf("%02x ", ((uint8_t*)data)[i]); |
341 | | } |
342 | | printf("\n"); |
343 | | } |
344 | | #endif |
345 | | |
346 | | |
347 | | LIBDE265_API de265_error de265_push_data(de265_decoder_context* de265ctx, |
348 | | const void* data8, int len, |
349 | | de265_PTS pts, void* user_data) |
350 | 0 | { |
351 | 0 | decoder_context* ctx = reinterpret_cast<decoder_context*>(de265ctx); |
352 | 0 | const uint8_t* data = reinterpret_cast<const uint8_t*>(data8); |
353 | | |
354 | | //printf("push data (size %d)\n",len); |
355 | | //dumpdata(data8,16); |
356 | |
|
357 | 0 | return ctx->nal_parser.push_data(data,len,pts,user_data); |
358 | 0 | } |
359 | | |
360 | | |
361 | | LIBDE265_API de265_error de265_push_NAL(de265_decoder_context* de265ctx, |
362 | | const void* data8, int len, |
363 | | de265_PTS pts, void* user_data) |
364 | 57.8k | { |
365 | 57.8k | decoder_context* ctx = reinterpret_cast<decoder_context*>(de265ctx); |
366 | 57.8k | const uint8_t* data = reinterpret_cast<const uint8_t*>(data8); |
367 | | |
368 | | //printf("push NAL (size %d)\n",len); |
369 | | //dumpdata(data8,16); |
370 | | |
371 | 57.8k | return ctx->nal_parser.push_NAL(data,len,pts,user_data); |
372 | 57.8k | } |
373 | | |
374 | | |
375 | | LIBDE265_API de265_error de265_decode(de265_decoder_context* de265ctx, int* more) |
376 | 51.4k | { |
377 | 51.4k | decoder_context* ctx = reinterpret_cast<decoder_context*>(de265ctx); |
378 | | |
379 | 51.4k | return ctx->decode(more); |
380 | 51.4k | } |
381 | | |
382 | | |
383 | | LIBDE265_API void de265_push_end_of_NAL(de265_decoder_context* de265ctx) |
384 | 1.01k | { |
385 | 1.01k | decoder_context* ctx = reinterpret_cast<decoder_context*>(de265ctx); |
386 | | |
387 | 1.01k | ctx->nal_parser.flush_data(); |
388 | 1.01k | } |
389 | | |
390 | | |
391 | | LIBDE265_API void de265_push_end_of_frame(de265_decoder_context* de265ctx) |
392 | 0 | { |
393 | 0 | de265_push_end_of_NAL(de265ctx); |
394 | |
|
395 | 0 | decoder_context* ctx = reinterpret_cast<decoder_context*>(de265ctx); |
396 | 0 | ctx->nal_parser.mark_end_of_frame(); |
397 | 0 | } |
398 | | |
399 | | |
400 | | LIBDE265_API de265_error de265_flush_data(de265_decoder_context* de265ctx) |
401 | 1.01k | { |
402 | 1.01k | de265_push_end_of_NAL(de265ctx); |
403 | | |
404 | 1.01k | decoder_context* ctx = reinterpret_cast<decoder_context*>(de265ctx); |
405 | | |
406 | 1.01k | ctx->nal_parser.flush_data(); |
407 | 1.01k | ctx->nal_parser.mark_end_of_stream(); |
408 | | |
409 | 1.01k | return DE265_OK; |
410 | 1.01k | } |
411 | | |
412 | | |
413 | | LIBDE265_API void de265_reset(de265_decoder_context* de265ctx) |
414 | 0 | { |
415 | 0 | decoder_context* ctx = reinterpret_cast<decoder_context*>(de265ctx); |
416 | | |
417 | | //printf("--- reset ---\n"); |
418 | |
|
419 | 0 | ctx->reset(); |
420 | 0 | } |
421 | | |
422 | | |
423 | | LIBDE265_API const struct de265_image* de265_get_next_picture(de265_decoder_context* de265ctx) |
424 | 48.0k | { |
425 | 48.0k | const struct de265_image* img = de265_peek_next_picture(de265ctx); |
426 | 48.0k | if (img) { |
427 | 0 | de265_release_next_picture(de265ctx); |
428 | 0 | } |
429 | | |
430 | 48.0k | return img; |
431 | 48.0k | } |
432 | | |
433 | | |
434 | | LIBDE265_API const struct de265_image* de265_peek_next_picture(de265_decoder_context* de265ctx) |
435 | 48.0k | { |
436 | 48.0k | decoder_context* ctx = reinterpret_cast<decoder_context*>(de265ctx); |
437 | | |
438 | 48.0k | if (ctx->num_pictures_in_output_queue()>0) { |
439 | 0 | de265_image* img = ctx->get_next_picture_in_output_queue(); |
440 | 0 | return img; |
441 | 0 | } |
442 | 48.0k | else { |
443 | 48.0k | return nullptr; |
444 | 48.0k | } |
445 | 48.0k | } |
446 | | |
447 | | |
448 | | LIBDE265_API void de265_release_next_picture(de265_decoder_context* de265ctx) |
449 | 0 | { |
450 | 0 | decoder_context* ctx = reinterpret_cast<decoder_context*>(de265ctx); |
451 | | |
452 | | // no active output picture -> ignore release request |
453 | |
|
454 | 0 | if (ctx->num_pictures_in_output_queue()==0) { return; } |
455 | | |
456 | 0 | de265_image* next_image = ctx->get_next_picture_in_output_queue(); |
457 | |
|
458 | 0 | loginfo(LogDPB, "release DPB with POC=%d\n",next_image->PicOrderCntVal); |
459 | |
|
460 | 0 | next_image->PicOutputFlag = false; |
461 | | |
462 | | // TODO: actually, we want to release it here, but we cannot without breaking API |
463 | | // compatibility, because get_next_picture calls this immediately. Hence, we release |
464 | | // images while scanning for available slots in the DPB. |
465 | | // if (next_image->can_be_released()) { next_image->release(); } |
466 | | |
467 | | // pop output queue |
468 | |
|
469 | 0 | ctx->pop_next_picture_in_output_queue(); |
470 | 0 | } |
471 | | |
472 | | |
473 | | |
474 | | LIBDE265_API int de265_get_highest_TID(de265_decoder_context* de265ctx) |
475 | 0 | { |
476 | 0 | decoder_context* ctx = reinterpret_cast<decoder_context*>(de265ctx); |
477 | 0 | return ctx->get_highest_TID(); |
478 | 0 | } |
479 | | |
480 | | LIBDE265_API int de265_get_current_TID(de265_decoder_context* de265ctx) |
481 | 0 | { |
482 | 0 | decoder_context* ctx = reinterpret_cast<decoder_context*>(de265ctx); |
483 | 0 | return ctx->get_current_TID(); |
484 | 0 | } |
485 | | |
486 | | LIBDE265_API void de265_set_limit_TID(de265_decoder_context* de265ctx,int max_tid) |
487 | 0 | { |
488 | 0 | decoder_context* ctx = reinterpret_cast<decoder_context*>(de265ctx); |
489 | 0 | ctx->set_limit_TID(max_tid); |
490 | 0 | } |
491 | | |
492 | | LIBDE265_API void de265_set_framerate_ratio(de265_decoder_context* de265ctx,int percent) |
493 | 0 | { |
494 | 0 | decoder_context* ctx = reinterpret_cast<decoder_context*>(de265ctx); |
495 | 0 | ctx->set_framerate_ratio(percent); |
496 | 0 | } |
497 | | |
498 | | LIBDE265_API int de265_change_framerate(de265_decoder_context* de265ctx,int more) |
499 | 0 | { |
500 | 0 | decoder_context* ctx = reinterpret_cast<decoder_context*>(de265ctx); |
501 | 0 | return ctx->change_framerate(more); |
502 | 0 | } |
503 | | |
504 | | |
505 | | LIBDE265_API de265_error de265_get_warning(de265_decoder_context* de265ctx) |
506 | 0 | { |
507 | 0 | decoder_context* ctx = reinterpret_cast<decoder_context*>(de265ctx); |
508 | |
|
509 | 0 | return ctx->get_warning(); |
510 | 0 | } |
511 | | |
512 | | LIBDE265_API void de265_set_parameter_bool(de265_decoder_context* de265ctx, enum de265_param param, int value) |
513 | 0 | { |
514 | 0 | decoder_context* ctx = reinterpret_cast<decoder_context*>(de265ctx); |
515 | |
|
516 | 0 | switch (param) |
517 | 0 | { |
518 | 0 | case DE265_DECODER_PARAM_BOOL_SEI_CHECK_HASH: |
519 | 0 | ctx->param_sei_check_hash = !!value; |
520 | 0 | break; |
521 | | |
522 | 0 | case DE265_DECODER_PARAM_SUPPRESS_FAULTY_PICTURES: |
523 | 0 | ctx->param_suppress_faulty_pictures = !!value; |
524 | 0 | break; |
525 | | |
526 | 0 | case DE265_DECODER_PARAM_DISABLE_DEBLOCKING: |
527 | 0 | ctx->param_disable_deblocking = !!value; |
528 | 0 | break; |
529 | | |
530 | 0 | case DE265_DECODER_PARAM_DISABLE_SAO: |
531 | 0 | ctx->param_disable_sao = !!value; |
532 | 0 | break; |
533 | | |
534 | | /* |
535 | | case DE265_DECODER_PARAM_DISABLE_MC_RESIDUAL_IDCT: |
536 | | ctx->param_disable_mc_residual_idct = !!value; |
537 | | break; |
538 | | |
539 | | case DE265_DECODER_PARAM_DISABLE_INTRA_RESIDUAL_IDCT: |
540 | | ctx->param_disable_intra_residual_idct = !!value; |
541 | | break; |
542 | | */ |
543 | | |
544 | 0 | default: |
545 | 0 | assert(false); |
546 | 0 | break; |
547 | 0 | } |
548 | 0 | } |
549 | | |
550 | | |
551 | | LIBDE265_API void de265_set_parameter_int(de265_decoder_context* de265ctx, enum de265_param param, int value) |
552 | 0 | { |
553 | 0 | decoder_context* ctx = reinterpret_cast<decoder_context*>(de265ctx); |
554 | |
|
555 | 0 | switch (param) |
556 | 0 | { |
557 | 0 | case DE265_DECODER_PARAM_DUMP_SPS_HEADERS: |
558 | 0 | ctx->param_sps_headers_fd = value; |
559 | 0 | break; |
560 | | |
561 | 0 | case DE265_DECODER_PARAM_DUMP_VPS_HEADERS: |
562 | 0 | ctx->param_vps_headers_fd = value; |
563 | 0 | break; |
564 | | |
565 | 0 | case DE265_DECODER_PARAM_DUMP_PPS_HEADERS: |
566 | 0 | ctx->param_pps_headers_fd = value; |
567 | 0 | break; |
568 | | |
569 | 0 | case DE265_DECODER_PARAM_DUMP_SLICE_HEADERS: |
570 | 0 | ctx->param_slice_headers_fd = value; |
571 | 0 | break; |
572 | | |
573 | 0 | case DE265_DECODER_PARAM_ACCELERATION_CODE: |
574 | 0 | ctx->set_acceleration_functions(static_cast<enum de265_acceleration>(value)); |
575 | 0 | break; |
576 | | |
577 | 0 | default: |
578 | 0 | assert(false); |
579 | 0 | break; |
580 | 0 | } |
581 | 0 | } |
582 | | |
583 | | |
584 | | |
585 | | |
586 | | LIBDE265_API int de265_get_parameter_bool(de265_decoder_context* de265ctx, enum de265_param param) |
587 | 0 | { |
588 | 0 | decoder_context* ctx = reinterpret_cast<decoder_context*>(de265ctx); |
589 | |
|
590 | 0 | switch (param) |
591 | 0 | { |
592 | 0 | case DE265_DECODER_PARAM_BOOL_SEI_CHECK_HASH: |
593 | 0 | return ctx->param_sei_check_hash; |
594 | | |
595 | 0 | case DE265_DECODER_PARAM_SUPPRESS_FAULTY_PICTURES: |
596 | 0 | return ctx->param_suppress_faulty_pictures; |
597 | | |
598 | 0 | case DE265_DECODER_PARAM_DISABLE_DEBLOCKING: |
599 | 0 | return ctx->param_disable_deblocking; |
600 | | |
601 | 0 | case DE265_DECODER_PARAM_DISABLE_SAO: |
602 | 0 | return ctx->param_disable_sao; |
603 | | |
604 | | /* |
605 | | case DE265_DECODER_PARAM_DISABLE_MC_RESIDUAL_IDCT: |
606 | | return ctx->param_disable_mc_residual_idct; |
607 | | |
608 | | case DE265_DECODER_PARAM_DISABLE_INTRA_RESIDUAL_IDCT: |
609 | | return ctx->param_disable_intra_residual_idct; |
610 | | */ |
611 | | |
612 | 0 | default: |
613 | 0 | assert(false); |
614 | 0 | return false; |
615 | 0 | } |
616 | 0 | } |
617 | | |
618 | | |
619 | | static const de265_security_limits disabled_security_limits = { |
620 | | 1, // version |
621 | | 0, // max_image_size_pixels |
622 | | 0, // max_NAL_size_bytes |
623 | | 0 // max_SEI_messages |
624 | | }; |
625 | | |
626 | | |
627 | | LIBDE265_API de265_security_limits* de265_get_security_limits(de265_decoder_context* de265ctx) |
628 | 1.68k | { |
629 | 1.68k | decoder_context* ctx = reinterpret_cast<decoder_context*>(de265ctx); |
630 | 1.68k | return &ctx->param_security_limits; |
631 | 1.68k | } |
632 | | |
633 | | |
634 | | // Copy security limits field by field, but only those fields that exist in both |
635 | | // structs, i.e. up to min(dst->version, src->version). This keeps copying safe |
636 | | // when 'src' was compiled against a different (older or newer) header version |
637 | | // than 'dst'. Fields not covered by the common version keep their value in 'dst'. |
638 | | static void copy_security_limits(de265_security_limits* dst, const de265_security_limits* src) |
639 | 0 | { |
640 | 0 | uint8_t version = (dst->version < src->version) ? dst->version : src->version; |
641 | |
|
642 | 0 | if (version >= 1) { |
643 | 0 | dst->max_image_size_pixels = src->max_image_size_pixels; |
644 | 0 | dst->max_NAL_size_bytes = src->max_NAL_size_bytes; |
645 | 0 | dst->max_SEI_messages = src->max_SEI_messages; |
646 | 0 | } |
647 | 0 | } |
648 | | |
649 | | |
650 | | LIBDE265_API void de265_set_security_limits(de265_decoder_context* de265ctx, |
651 | | const de265_security_limits* limits) |
652 | 0 | { |
653 | 0 | decoder_context* ctx = reinterpret_cast<decoder_context*>(de265ctx); |
654 | 0 | if (limits) { |
655 | 0 | copy_security_limits(&ctx->param_security_limits, limits); |
656 | 0 | } |
657 | 0 | } |
658 | | |
659 | | |
660 | | LIBDE265_API const de265_security_limits* de265_get_disabled_security_limits() |
661 | 0 | { |
662 | 0 | return &disabled_security_limits; |
663 | 0 | } |
664 | | |
665 | | |
666 | | LIBDE265_API int de265_get_number_of_input_bytes_pending(de265_decoder_context* de265ctx) |
667 | 0 | { |
668 | 0 | decoder_context* ctx = reinterpret_cast<decoder_context*>(de265ctx); |
669 | |
|
670 | 0 | return ctx->nal_parser.bytes_in_input_queue(); |
671 | 0 | } |
672 | | |
673 | | |
674 | | LIBDE265_API int de265_get_number_of_NAL_units_pending(de265_decoder_context* de265ctx) |
675 | 0 | { |
676 | 0 | decoder_context* ctx = reinterpret_cast<decoder_context*>(de265ctx); |
677 | |
|
678 | 0 | return ctx->nal_parser.number_of_NAL_units_pending(); |
679 | 0 | } |
680 | | |
681 | | |
682 | | LIBDE265_API int de265_get_image_width(const struct de265_image* img,int channel) |
683 | 0 | { |
684 | 0 | switch (channel) { |
685 | 0 | case 0: |
686 | 0 | return img->width_confwin; |
687 | 0 | case 1: |
688 | 0 | case 2: |
689 | 0 | return img->chroma_width_confwin; |
690 | 0 | default: |
691 | 0 | return 0; |
692 | 0 | } |
693 | 0 | } |
694 | | |
695 | | LIBDE265_API int de265_get_image_height(const struct de265_image* img,int channel) |
696 | 0 | { |
697 | 0 | switch (channel) { |
698 | 0 | case 0: |
699 | 0 | return img->height_confwin; |
700 | 0 | case 1: |
701 | 0 | case 2: |
702 | 0 | return img->chroma_height_confwin; |
703 | 0 | default: |
704 | 0 | return 0; |
705 | 0 | } |
706 | 0 | } |
707 | | |
708 | | LIBDE265_API int de265_get_bits_per_pixel(const struct de265_image* img,int channel) |
709 | 0 | { |
710 | 0 | switch (channel) { |
711 | 0 | case 0: |
712 | 0 | return img->get_sps().BitDepth_Y; |
713 | 0 | case 1: |
714 | 0 | case 2: |
715 | 0 | return img->get_sps().BitDepth_C; |
716 | 0 | default: |
717 | 0 | return 0; |
718 | 0 | } |
719 | 0 | } |
720 | | |
721 | | LIBDE265_API enum de265_chroma de265_get_chroma_format(const struct de265_image* img) |
722 | 0 | { |
723 | 0 | return img->get_chroma_format(); |
724 | 0 | } |
725 | | |
726 | | LIBDE265_API const uint8_t* de265_get_image_plane(const de265_image* img, int channel, int* stride) |
727 | 0 | { |
728 | 0 | assert(channel>=0 && channel <= 2); |
729 | | |
730 | 0 | uint8_t* data = img->pixels_confwin[channel]; |
731 | |
|
732 | 0 | if (stride) *stride = img->get_image_stride(channel) * ((de265_get_bits_per_pixel(img, channel)+7) / 8); |
733 | |
|
734 | 0 | return data; |
735 | 0 | } |
736 | | |
737 | | LIBDE265_API void *de265_get_image_plane_user_data(const struct de265_image* img, int channel) |
738 | 0 | { |
739 | 0 | assert(channel>=0 && channel <= 2); |
740 | | |
741 | 0 | return img->plane_user_data[channel]; |
742 | 0 | } |
743 | | |
744 | | LIBDE265_API void de265_set_image_plane(de265_image* img, int cIdx, void* mem, int stride, void *userdata) |
745 | 0 | { |
746 | | // The internal "stride" is the number of pixels per line. |
747 | 0 | stride = stride / ((de265_get_bits_per_pixel(img, cIdx)+7) / 8); |
748 | 0 | img->set_image_plane(cIdx, static_cast<uint8_t*>(mem), stride, userdata); |
749 | 0 | } |
750 | | |
751 | | LIBDE265_API void de265_set_image_allocation_functions(de265_decoder_context* de265ctx, |
752 | | de265_image_allocation* allocfunc, |
753 | | void* userdata) |
754 | 0 | { |
755 | 0 | decoder_context* ctx = reinterpret_cast<decoder_context*>(de265ctx); |
756 | |
|
757 | 0 | ctx->set_image_allocation_functions(allocfunc, userdata); |
758 | 0 | } |
759 | | |
760 | | LIBDE265_API const struct de265_image_allocation *de265_get_default_image_allocation_functions(void) |
761 | 0 | { |
762 | 0 | return &de265_image::default_image_allocation; |
763 | 0 | } |
764 | | |
765 | | LIBDE265_API de265_PTS de265_get_image_PTS(const struct de265_image* img) |
766 | 0 | { |
767 | 0 | return img->pts; |
768 | 0 | } |
769 | | |
770 | | LIBDE265_API void* de265_get_image_user_data(const struct de265_image* img) |
771 | 0 | { |
772 | 0 | return img->user_data; |
773 | 0 | } |
774 | | |
775 | | LIBDE265_API void de265_set_image_user_data(struct de265_image* img, void *user_data) |
776 | 0 | { |
777 | 0 | img->user_data = user_data; |
778 | 0 | } |
779 | | |
780 | | LIBDE265_API void de265_get_image_NAL_header(const struct de265_image* img, |
781 | | int* nal_unit_type, |
782 | | const char** nal_unit_name, |
783 | | int* nuh_layer_id, |
784 | | int* nuh_temporal_id) |
785 | 0 | { |
786 | 0 | if (nal_unit_type) *nal_unit_type = img->nal_hdr.nal_unit_type; |
787 | 0 | if (nal_unit_name) *nal_unit_name = get_NAL_name(img->nal_hdr.nal_unit_type); |
788 | 0 | if (nuh_layer_id) *nuh_layer_id = img->nal_hdr.nuh_layer_id; |
789 | 0 | if (nuh_temporal_id) *nuh_temporal_id = img->nal_hdr.nuh_temporal_id; |
790 | 0 | } |
791 | | |
792 | | LIBDE265_API int de265_get_image_full_range_flag(const struct de265_image* img) |
793 | 0 | { |
794 | 0 | return img->get_sps().vui.video_full_range_flag; |
795 | 0 | } |
796 | | |
797 | | LIBDE265_API int de265_get_image_colour_primaries(const struct de265_image* img) |
798 | 0 | { |
799 | 0 | return img->get_sps().vui.colour_primaries; |
800 | 0 | } |
801 | | |
802 | | LIBDE265_API int de265_get_image_transfer_characteristics(const struct de265_image* img) |
803 | 0 | { |
804 | 0 | return img->get_sps().vui.transfer_characteristics; |
805 | 0 | } |
806 | | |
807 | | LIBDE265_API int de265_get_image_matrix_coefficients(const struct de265_image* img) |
808 | 0 | { |
809 | 0 | return img->get_sps().vui.matrix_coeffs; |
810 | 0 | } |
811 | | |
812 | | } |