Coverage Report

Created: 2026-06-15 06:24

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/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
402
{
194
402
  return err == DE265_OK || err >= 1000;
195
402
}
196
197
198
199
static int de265_init_count;
200
201
static std::mutex& de265_init_mutex()
202
806
{
203
806
  static std::mutex de265_init_mutex;
204
806
  return de265_init_mutex;
205
806
}
206
207
208
LIBDE265_API de265_error de265_init()
209
404
{
210
404
  std::lock_guard<std::mutex> lock(de265_init_mutex());
211
212
404
  de265_init_count++;
213
214
404
  if (de265_init_count > 1) {
215
    // we are not the first -> already initialized
216
217
402
    return DE265_OK;
218
402
  }
219
220
221
  // do initializations
222
223
2
  init_scan_orders();
224
2
  pps_scan_cache_init();
225
226
2
  if (!alloc_and_init_significant_coeff_ctxIdx_lookupTable()) {
227
0
    pps_scan_cache_free();
228
0
    de265_init_count--;
229
0
    return DE265_ERROR_LIBRARY_INITIALIZATION_FAILED;
230
0
  }
231
232
2
  return DE265_OK;
233
2
}
234
235
LIBDE265_API de265_error de265_free()
236
402
{
237
402
  std::lock_guard<std::mutex> lock(de265_init_mutex());
238
239
402
  if (de265_init_count<=0) {
240
0
    return DE265_ERROR_LIBRARY_NOT_INITIALIZED;
241
0
  }
242
243
402
  de265_init_count--;
244
245
402
  if (de265_init_count==0) {
246
0
    free_significant_coeff_ctxIdx_lookupTable();
247
0
    pps_scan_cache_free();
248
0
  }
249
250
402
  return DE265_OK;
251
402
}
252
253
254
LIBDE265_API de265_decoder_context* de265_new_decoder()
255
402
{
256
402
  de265_error init_err = de265_init();
257
402
  if (init_err != DE265_OK) {
258
0
    return nullptr;
259
0
  }
260
261
402
  decoder_context* ctx = new decoder_context;
262
402
  if (!ctx) {
263
0
    de265_free();
264
0
    return nullptr;
265
0
  }
266
267
402
  return reinterpret_cast<de265_decoder_context*>(ctx);
268
402
}
269
270
271
LIBDE265_API de265_error de265_free_decoder(de265_decoder_context* de265ctx)
272
402
{
273
402
  decoder_context* ctx = reinterpret_cast<decoder_context*>(de265ctx);
274
275
402
  ctx->stop_thread_pool();
276
277
402
  delete ctx;
278
279
402
  return de265_free();
280
402
}
281
282
283
LIBDE265_API de265_error de265_start_worker_threads(de265_decoder_context* de265ctx, int number_of_threads)
284
402
{
285
402
  decoder_context* ctx = reinterpret_cast<decoder_context*>(de265ctx);
286
287
402
  if (number_of_threads > MAX_THREADS) {
288
0
    number_of_threads = MAX_THREADS;
289
0
  }
290
291
402
  if (number_of_threads>0) {
292
402
    de265_error err = ctx->start_thread_pool(number_of_threads);
293
402
    if (de265_isOK(err)) {
294
402
      err = DE265_OK;
295
402
    }
296
402
    return err;
297
402
  }
298
0
  else {
299
0
    return DE265_OK;
300
0
  }
301
402
}
302
303
304
#ifndef LIBDE265_DISABLE_DEPRECATED
305
LIBDE265_API de265_error de265_decode_data(de265_decoder_context* de265ctx,
306
                                           const void* data8, int len)
307
0
{
308
  //decoder_context* ctx = reinterpret_cast<decoder_context*>(de265ctx);
309
0
  de265_error err;
310
0
  if (len > 0) {
311
0
    err = de265_push_data(de265ctx, data8, len, 0, nullptr);
312
0
  } else {
313
0
    err = de265_flush_data(de265ctx);
314
0
  }
315
0
  if (err != DE265_OK) {
316
0
    return err;
317
0
  }
318
319
0
  int more = 0;
320
0
  do {
321
0
    err = de265_decode(de265ctx, &more);
322
0
    if (err != DE265_OK) {
323
0
        more = 0;
324
0
    }
325
326
0
    switch (err) {
327
0
    case DE265_ERROR_WAITING_FOR_INPUT_DATA:
328
      // ignore error (didn't exist in 0.4 and before)
329
0
      err = DE265_OK;
330
0
      break;
331
0
    default:
332
0
      break;
333
0
    }
334
0
  } while (more);
335
0
  return err;
336
0
}
337
#endif
338
339
#if 0
340
static void dumpdata(const void* data, int len)
341
{
342
  for (int i=0;i<len;i++) {
343
    printf("%02x ", ((uint8_t*)data)[i]);
344
  }
345
  printf("\n");
346
}
347
#endif
348
349
350
LIBDE265_API de265_error de265_push_data(de265_decoder_context* de265ctx,
351
                                         const void* data8, int len,
352
                                         de265_PTS pts, void* user_data)
353
0
{
354
0
  decoder_context* ctx = reinterpret_cast<decoder_context*>(de265ctx);
355
0
  const uint8_t* data = reinterpret_cast<const uint8_t*>(data8);
356
357
  //printf("push data (size %d)\n",len);
358
  //dumpdata(data8,16);
359
360
0
  return ctx->nal_parser.push_data(data,len,pts,user_data);
361
0
}
362
363
364
LIBDE265_API de265_error de265_push_NAL(de265_decoder_context* de265ctx,
365
                                        const void* data8, int len,
366
                                        de265_PTS pts, void* user_data)
367
690
{
368
690
  decoder_context* ctx = reinterpret_cast<decoder_context*>(de265ctx);
369
690
  const uint8_t* data = reinterpret_cast<const uint8_t*>(data8);
370
371
  //printf("push NAL (size %d)\n",len);
372
  //dumpdata(data8,16);
373
374
690
  return ctx->nal_parser.push_NAL(data,len,pts,user_data);
375
690
}
376
377
378
LIBDE265_API de265_error de265_decode(de265_decoder_context* de265ctx, int* more)
379
14.8k
{
380
14.8k
  decoder_context* ctx = reinterpret_cast<decoder_context*>(de265ctx);
381
382
14.8k
  return ctx->decode(more);
383
14.8k
}
384
385
386
LIBDE265_API void        de265_push_end_of_NAL(de265_decoder_context* de265ctx)
387
294
{
388
294
  decoder_context* ctx = reinterpret_cast<decoder_context*>(de265ctx);
389
390
294
  ctx->nal_parser.flush_data();
391
294
}
392
393
394
LIBDE265_API void        de265_push_end_of_frame(de265_decoder_context* de265ctx)
395
0
{
396
0
  de265_push_end_of_NAL(de265ctx);
397
398
0
  decoder_context* ctx = reinterpret_cast<decoder_context*>(de265ctx);
399
0
  ctx->nal_parser.mark_end_of_frame();
400
0
}
401
402
403
LIBDE265_API de265_error de265_flush_data(de265_decoder_context* de265ctx)
404
294
{
405
294
  de265_push_end_of_NAL(de265ctx);
406
407
294
  decoder_context* ctx = reinterpret_cast<decoder_context*>(de265ctx);
408
409
294
  ctx->nal_parser.flush_data();
410
294
  ctx->nal_parser.mark_end_of_stream();
411
412
294
  return DE265_OK;
413
294
}
414
415
416
LIBDE265_API void de265_reset(de265_decoder_context* de265ctx)
417
0
{
418
0
  decoder_context* ctx = reinterpret_cast<decoder_context*>(de265ctx);
419
420
  //printf("--- reset ---\n");
421
422
0
  ctx->reset();
423
0
}
424
425
426
LIBDE265_API const struct de265_image* de265_get_next_picture(de265_decoder_context* de265ctx)
427
14.4k
{
428
14.4k
  const struct de265_image* img = de265_peek_next_picture(de265ctx);
429
14.4k
  if (img) {
430
0
    de265_release_next_picture(de265ctx);
431
0
  }
432
433
14.4k
  return img;
434
14.4k
}
435
436
437
LIBDE265_API const struct de265_image* de265_peek_next_picture(de265_decoder_context* de265ctx)
438
14.4k
{
439
14.4k
  decoder_context* ctx = reinterpret_cast<decoder_context*>(de265ctx);
440
441
14.4k
  if (ctx->num_pictures_in_output_queue()>0) {
442
0
    de265_image* img = ctx->get_next_picture_in_output_queue();
443
0
    return img;
444
0
  }
445
14.4k
  else {
446
14.4k
    return nullptr;
447
14.4k
  }
448
14.4k
}
449
450
451
LIBDE265_API void de265_release_next_picture(de265_decoder_context* de265ctx)
452
0
{
453
0
  decoder_context* ctx = reinterpret_cast<decoder_context*>(de265ctx);
454
455
  // no active output picture -> ignore release request
456
457
0
  if (ctx->num_pictures_in_output_queue()==0) { return; }
458
459
0
  de265_image* next_image = ctx->get_next_picture_in_output_queue();
460
461
0
  loginfo(LogDPB, "release DPB with POC=%d\n",next_image->PicOrderCntVal);
462
463
0
  next_image->PicOutputFlag = false;
464
465
  // TODO: actually, we want to release it here, but we cannot without breaking API
466
  // compatibility, because get_next_picture calls this immediately. Hence, we release
467
  // images while scanning for available slots in the DPB.
468
  // if (next_image->can_be_released()) { next_image->release(); }
469
470
  // pop output queue
471
472
0
  ctx->pop_next_picture_in_output_queue();
473
0
}
474
475
476
477
LIBDE265_API int  de265_get_highest_TID(de265_decoder_context* de265ctx)
478
0
{
479
0
  decoder_context* ctx = reinterpret_cast<decoder_context*>(de265ctx);
480
0
  return ctx->get_highest_TID();
481
0
}
482
483
LIBDE265_API int  de265_get_current_TID(de265_decoder_context* de265ctx)
484
0
{
485
0
  decoder_context* ctx = reinterpret_cast<decoder_context*>(de265ctx);
486
0
  return ctx->get_current_TID();
487
0
}
488
489
LIBDE265_API void de265_set_limit_TID(de265_decoder_context* de265ctx,int max_tid)
490
0
{
491
0
  decoder_context* ctx = reinterpret_cast<decoder_context*>(de265ctx);
492
0
  ctx->set_limit_TID(max_tid);
493
0
}
494
495
LIBDE265_API void de265_set_framerate_ratio(de265_decoder_context* de265ctx,int percent)
496
0
{
497
0
  decoder_context* ctx = reinterpret_cast<decoder_context*>(de265ctx);
498
0
  ctx->set_framerate_ratio(percent);
499
0
}
500
501
LIBDE265_API int  de265_change_framerate(de265_decoder_context* de265ctx,int more)
502
0
{
503
0
  decoder_context* ctx = reinterpret_cast<decoder_context*>(de265ctx);
504
0
  return ctx->change_framerate(more);
505
0
}
506
507
508
LIBDE265_API de265_error de265_get_warning(de265_decoder_context* de265ctx)
509
0
{
510
0
  decoder_context* ctx = reinterpret_cast<decoder_context*>(de265ctx);
511
512
0
  return ctx->get_warning();
513
0
}
514
515
LIBDE265_API void de265_set_parameter_bool(de265_decoder_context* de265ctx, enum de265_param param, int value)
516
0
{
517
0
  decoder_context* ctx = reinterpret_cast<decoder_context*>(de265ctx);
518
519
0
  switch (param)
520
0
    {
521
0
    case DE265_DECODER_PARAM_BOOL_SEI_CHECK_HASH:
522
0
      ctx->param_sei_check_hash = !!value;
523
0
      break;
524
525
0
    case DE265_DECODER_PARAM_SUPPRESS_FAULTY_PICTURES:
526
0
      ctx->param_suppress_faulty_pictures = !!value;
527
0
      break;
528
529
0
    case DE265_DECODER_PARAM_DISABLE_DEBLOCKING:
530
0
      ctx->param_disable_deblocking = !!value;
531
0
      break;
532
533
0
    case DE265_DECODER_PARAM_DISABLE_SAO:
534
0
      ctx->param_disable_sao = !!value;
535
0
      break;
536
537
      /*
538
    case DE265_DECODER_PARAM_DISABLE_MC_RESIDUAL_IDCT:
539
      ctx->param_disable_mc_residual_idct = !!value;
540
      break;
541
542
    case DE265_DECODER_PARAM_DISABLE_INTRA_RESIDUAL_IDCT:
543
      ctx->param_disable_intra_residual_idct = !!value;
544
      break;
545
      */
546
547
0
    default:
548
0
      assert(false);
549
0
      break;
550
0
    }
551
0
}
552
553
554
LIBDE265_API void de265_set_parameter_int(de265_decoder_context* de265ctx, enum de265_param param, int value)
555
0
{
556
0
  decoder_context* ctx = reinterpret_cast<decoder_context*>(de265ctx);
557
558
0
  switch (param)
559
0
    {
560
0
    case DE265_DECODER_PARAM_DUMP_SPS_HEADERS:
561
0
      ctx->param_sps_headers_fd = value;
562
0
      break;
563
564
0
    case DE265_DECODER_PARAM_DUMP_VPS_HEADERS:
565
0
      ctx->param_vps_headers_fd = value;
566
0
      break;
567
568
0
    case DE265_DECODER_PARAM_DUMP_PPS_HEADERS:
569
0
      ctx->param_pps_headers_fd = value;
570
0
      break;
571
572
0
    case DE265_DECODER_PARAM_DUMP_SLICE_HEADERS:
573
0
      ctx->param_slice_headers_fd = value;
574
0
      break;
575
576
0
    case DE265_DECODER_PARAM_ACCELERATION_CODE:
577
0
      ctx->set_acceleration_functions(static_cast<enum de265_acceleration>(value));
578
0
      break;
579
580
0
    default:
581
0
      assert(false);
582
0
      break;
583
0
    }
584
0
}
585
586
587
588
589
LIBDE265_API int de265_get_parameter_bool(de265_decoder_context* de265ctx, enum de265_param param)
590
0
{
591
0
  decoder_context* ctx = reinterpret_cast<decoder_context*>(de265ctx);
592
593
0
  switch (param)
594
0
    {
595
0
    case DE265_DECODER_PARAM_BOOL_SEI_CHECK_HASH:
596
0
      return ctx->param_sei_check_hash;
597
598
0
    case DE265_DECODER_PARAM_SUPPRESS_FAULTY_PICTURES:
599
0
      return ctx->param_suppress_faulty_pictures;
600
601
0
    case DE265_DECODER_PARAM_DISABLE_DEBLOCKING:
602
0
      return ctx->param_disable_deblocking;
603
604
0
    case DE265_DECODER_PARAM_DISABLE_SAO:
605
0
      return ctx->param_disable_sao;
606
607
      /*
608
    case DE265_DECODER_PARAM_DISABLE_MC_RESIDUAL_IDCT:
609
      return ctx->param_disable_mc_residual_idct;
610
611
    case DE265_DECODER_PARAM_DISABLE_INTRA_RESIDUAL_IDCT:
612
      return ctx->param_disable_intra_residual_idct;
613
      */
614
615
0
    default:
616
0
      assert(false);
617
0
      return false;
618
0
    }
619
0
}
620
621
622
static const de265_security_limits disabled_security_limits = {
623
  1,    // version
624
  0,    // max_image_size_pixels
625
  0,    // max_NAL_size_bytes
626
  0     // max_SEI_messages
627
};
628
629
630
LIBDE265_API de265_security_limits* de265_get_security_limits(de265_decoder_context* de265ctx)
631
402
{
632
402
  decoder_context* ctx = reinterpret_cast<decoder_context*>(de265ctx);
633
402
  return &ctx->param_security_limits;
634
402
}
635
636
637
// Copy security limits field by field, but only those fields that exist in both
638
// structs, i.e. up to min(dst->version, src->version). This keeps copying safe
639
// when 'src' was compiled against a different (older or newer) header version
640
// than 'dst'. Fields not covered by the common version keep their value in 'dst'.
641
static void copy_security_limits(de265_security_limits* dst, const de265_security_limits* src)
642
0
{
643
0
  uint8_t version = (dst->version < src->version) ? dst->version : src->version;
644
645
0
  if (version >= 1) {
646
0
    dst->max_image_size_pixels = src->max_image_size_pixels;
647
0
    dst->max_NAL_size_bytes    = src->max_NAL_size_bytes;
648
0
    dst->max_SEI_messages      = src->max_SEI_messages;
649
0
  }
650
0
}
651
652
653
LIBDE265_API void de265_set_security_limits(de265_decoder_context* de265ctx,
654
                                            const de265_security_limits* limits)
655
0
{
656
0
  decoder_context* ctx = reinterpret_cast<decoder_context*>(de265ctx);
657
0
  if (limits) {
658
0
    copy_security_limits(&ctx->param_security_limits, limits);
659
0
  }
660
0
}
661
662
663
LIBDE265_API const de265_security_limits* de265_get_disabled_security_limits()
664
0
{
665
0
  return &disabled_security_limits;
666
0
}
667
668
669
LIBDE265_API int de265_get_number_of_input_bytes_pending(de265_decoder_context* de265ctx)
670
0
{
671
0
  decoder_context* ctx = reinterpret_cast<decoder_context*>(de265ctx);
672
673
0
  return ctx->nal_parser.bytes_in_input_queue();
674
0
}
675
676
677
LIBDE265_API int de265_get_number_of_NAL_units_pending(de265_decoder_context* de265ctx)
678
0
{
679
0
  decoder_context* ctx = reinterpret_cast<decoder_context*>(de265ctx);
680
681
0
  return ctx->nal_parser.number_of_NAL_units_pending();
682
0
}
683
684
685
LIBDE265_API int de265_get_image_width(const struct de265_image* img,int channel)
686
0
{
687
0
  switch (channel) {
688
0
  case 0:
689
0
    return img->width_confwin;
690
0
  case 1:
691
0
  case 2:
692
0
    return img->chroma_width_confwin;
693
0
  default:
694
0
    return 0;
695
0
  }
696
0
}
697
698
LIBDE265_API int de265_get_image_height(const struct de265_image* img,int channel)
699
0
{
700
0
  switch (channel) {
701
0
  case 0:
702
0
    return img->height_confwin;
703
0
  case 1:
704
0
  case 2:
705
0
    return img->chroma_height_confwin;
706
0
  default:
707
0
    return 0;
708
0
  }
709
0
}
710
711
LIBDE265_API int de265_get_bits_per_pixel(const struct de265_image* img,int channel)
712
0
{
713
0
  switch (channel) {
714
0
  case 0:
715
0
    return img->get_sps().BitDepth_Y;
716
0
  case 1:
717
0
  case 2:
718
0
    return img->get_sps().BitDepth_C;
719
0
  default:
720
0
    return 0;
721
0
  }
722
0
}
723
724
LIBDE265_API enum de265_chroma de265_get_chroma_format(const struct de265_image* img)
725
0
{
726
0
  return img->get_chroma_format();
727
0
}
728
729
LIBDE265_API const uint8_t* de265_get_image_plane(const de265_image* img, int channel, int* stride)
730
0
{
731
0
  assert(channel>=0 && channel <= 2);
732
733
0
  uint8_t* data = img->pixels_confwin[channel];
734
735
0
  if (stride) *stride = static_cast<int>(img->get_image_stride(channel) * ((de265_get_bits_per_pixel(img, channel)+7) / 8));
736
737
0
  return data;
738
0
}
739
740
LIBDE265_API void *de265_get_image_plane_user_data(const struct de265_image* img, int channel)
741
0
{
742
0
  assert(channel>=0 && channel <= 2);
743
744
0
  return img->plane_user_data[channel];
745
0
}
746
747
LIBDE265_API void de265_set_image_plane(de265_image* img, int cIdx, void* mem, int stride, void *userdata)
748
0
{
749
  // The internal "stride" is the number of pixels per line.
750
0
  stride = stride / ((de265_get_bits_per_pixel(img, cIdx)+7) / 8);
751
0
  img->set_image_plane(cIdx, static_cast<uint8_t*>(mem), stride, userdata);
752
0
}
753
754
LIBDE265_API void de265_set_image_allocation_functions(de265_decoder_context* de265ctx,
755
                                                       de265_image_allocation* allocfunc,
756
                                                       void* userdata)
757
0
{
758
0
  decoder_context* ctx = reinterpret_cast<decoder_context*>(de265ctx);
759
760
0
  ctx->set_image_allocation_functions(allocfunc, userdata);
761
0
}
762
763
LIBDE265_API const struct de265_image_allocation *de265_get_default_image_allocation_functions(void)
764
0
{
765
0
  return &de265_image::default_image_allocation;
766
0
}
767
768
LIBDE265_API de265_PTS de265_get_image_PTS(const struct de265_image* img)
769
0
{
770
0
  return img->pts;
771
0
}
772
773
LIBDE265_API void* de265_get_image_user_data(const struct de265_image* img)
774
0
{
775
0
  return img->user_data;
776
0
}
777
778
LIBDE265_API void de265_set_image_user_data(struct de265_image* img, void *user_data)
779
0
{
780
0
  img->user_data = user_data;
781
0
}
782
783
LIBDE265_API void de265_get_image_NAL_header(const struct de265_image* img,
784
                                             int* nal_unit_type,
785
                                             const char** nal_unit_name,
786
                                             int* nuh_layer_id,
787
                                             int* nuh_temporal_id)
788
0
{
789
0
  if (nal_unit_type)   *nal_unit_type   = img->nal_hdr.nal_unit_type;
790
0
  if (nal_unit_name)   *nal_unit_name   = get_NAL_name(img->nal_hdr.nal_unit_type);
791
0
  if (nuh_layer_id)    *nuh_layer_id    = img->nal_hdr.nuh_layer_id;
792
0
  if (nuh_temporal_id) *nuh_temporal_id = img->nal_hdr.nuh_temporal_id;
793
0
}
794
795
LIBDE265_API int de265_get_image_full_range_flag(const struct de265_image* img)
796
0
{
797
0
  return img->get_sps().vui.video_full_range_flag;
798
0
}
799
800
LIBDE265_API int de265_get_image_colour_primaries(const struct de265_image* img)
801
0
{
802
0
  return img->get_sps().vui.colour_primaries;
803
0
}
804
805
LIBDE265_API int de265_get_image_transfer_characteristics(const struct de265_image* img)
806
0
{
807
0
  return img->get_sps().vui.transfer_characteristics;
808
0
}
809
810
LIBDE265_API int de265_get_image_matrix_coefficients(const struct de265_image* img)
811
0
{
812
0
  return img->get_sps().vui.matrix_coeffs;
813
0
}
814
815
}