Coverage Report

Created: 2026-05-16 06:41

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_CANNOT_START_THREADPOOL: return "cannot start decoding threads";
86
0
  case DE265_ERROR_LIBRARY_INITIALIZATION_FAILED: return "global library initialization failed";
87
0
  case DE265_ERROR_LIBRARY_NOT_INITIALIZED: return "cannot free library data (not initialized";
88
89
  //case DE265_ERROR_MAX_THREAD_CONTEXTS_EXCEEDED:
90
  //  return "internal error: maximum number of thread contexts exceeded";
91
  //case DE265_ERROR_MAX_NUMBER_OF_SLICES_EXCEEDED:
92
  //  return "internal error: maximum number of slices exceeded";
93
0
  case DE265_ERROR_NOT_IMPLEMENTED_YET:
94
0
    return "unimplemented decoder feature";
95
    //case DE265_ERROR_SCALING_LIST_NOT_IMPLEMENTED:
96
    //return "scaling list not implemented";
97
98
0
  case DE265_ERROR_WAITING_FOR_INPUT_DATA:
99
0
    return "no more input data, decoder stalled";
100
0
  case DE265_ERROR_CANNOT_PROCESS_SEI:
101
0
    return "SEI data cannot be processed";
102
0
  case DE265_ERROR_PARAMETER_PARSING:
103
0
    return "command-line parameter error";
104
0
  case DE265_ERROR_NO_INITIAL_SLICE_HEADER:
105
0
    return "first slice missing, cannot decode dependent slice";
106
0
  case DE265_ERROR_PREMATURE_END_OF_SLICE:
107
0
    return "premature end of slice data";
108
0
  case DE265_ERROR_UNSPECIFIED_DECODING_ERROR:
109
0
    return "unspecified decoding error";
110
111
0
  case DE265_WARNING_NO_WPP_CANNOT_USE_MULTITHREADING:
112
0
    return "Cannot run decoder multi-threaded because stream does not support WPP";
113
0
  case DE265_WARNING_WARNING_BUFFER_FULL:
114
0
    return "Too many warnings queued";
115
0
  case DE265_WARNING_PREMATURE_END_OF_SLICE_SEGMENT:
116
0
    return "Premature end of slice segment";
117
0
  case DE265_WARNING_INCORRECT_ENTRY_POINT_OFFSET:
118
0
    return "Incorrect entry-point offsets";
119
0
  case DE265_WARNING_CTB_OUTSIDE_IMAGE_AREA:
120
0
    return "CTB outside of image area (concealing stream error...)";
121
0
  case DE265_WARNING_SPS_HEADER_INVALID:
122
0
    return "sps header invalid";
123
0
  case DE265_WARNING_PPS_HEADER_INVALID:
124
0
    return "pps header invalid";
125
0
  case DE265_WARNING_SLICEHEADER_INVALID:
126
0
    return "slice header invalid";
127
0
  case DE265_WARNING_INCORRECT_MOTION_VECTOR_SCALING:
128
0
    return "impossible motion vector scaling";
129
0
  case DE265_WARNING_NONEXISTING_PPS_REFERENCED:
130
0
    return "non-existing PPS referenced";
131
0
  case DE265_WARNING_NONEXISTING_SPS_REFERENCED:
132
0
    return "non-existing SPS referenced";
133
0
  case DE265_WARNING_BOTH_PREDFLAGS_ZERO:
134
0
    return "both predFlags[] are zero in MC";
135
0
  case DE265_WARNING_NONEXISTING_REFERENCE_PICTURE_ACCESSED:
136
0
    return "non-existing reference picture accessed";
137
0
  case DE265_WARNING_NUMMVP_NOT_EQUAL_TO_NUMMVQ:
138
0
    return "numMV_P != numMV_Q in deblocking";
139
0
  case DE265_WARNING_NUMBER_OF_SHORT_TERM_REF_PIC_SETS_OUT_OF_RANGE:
140
0
    return "number of short-term ref-pic-sets out of range";
141
0
  case DE265_WARNING_SHORT_TERM_REF_PIC_SET_OUT_OF_RANGE:
142
0
    return "short-term ref-pic-set index out of range";
143
0
  case DE265_WARNING_FAULTY_REFERENCE_PICTURE_LIST:
144
0
    return "faulty reference picture list";
145
0
  case DE265_WARNING_EOSS_BIT_NOT_SET:
146
0
    return "end_of_sub_stream_one_bit not set to 1 when it should be";
147
0
  case DE265_WARNING_MAX_NUM_REF_PICS_EXCEEDED:
148
0
    return "maximum number of reference pictures exceeded";
149
0
  case DE265_WARNING_INVALID_CHROMA_FORMAT:
150
0
    return "invalid chroma format in SPS header";
151
0
  case DE265_WARNING_SLICE_SEGMENT_ADDRESS_INVALID:
152
0
    return "slice segment address invalid";
153
0
  case DE265_WARNING_DEPENDENT_SLICE_WITH_ADDRESS_ZERO:
154
0
    return "dependent slice with address 0";
155
0
  case DE265_WARNING_NUMBER_OF_THREADS_LIMITED_TO_MAXIMUM:
156
0
    return "number of threads limited to maximum amount";
157
0
  case DE265_NON_EXISTING_LT_REFERENCE_CANDIDATE_IN_SLICE_HEADER:
158
0
    return "non-existing long-term reference candidate specified in slice header";
159
0
  case DE265_WARNING_CANNOT_APPLY_SAO_OUT_OF_MEMORY:
160
0
    return "cannot apply SAO because we ran out of memory";
161
0
  case DE265_WARNING_SPS_MISSING_CANNOT_DECODE_SEI:
162
0
    return "SPS header missing, cannot decode SEI";
163
0
  case DE265_WARNING_COLLOCATED_MOTION_VECTOR_OUTSIDE_IMAGE_AREA:
164
0
    return "collocated motion-vector is outside image area";
165
0
  case DE265_WARNING_PCM_BITDEPTH_TOO_LARGE:
166
0
    return "PCM bit-depth too large";
167
0
  case DE265_WARNING_REFERENCE_IMAGE_BIT_DEPTH_DOES_NOT_MATCH:
168
0
    return "Bit-depth of reference image does not match current image";
169
0
  case DE265_WARNING_REFERENCE_IMAGE_SIZE_DOES_NOT_MATCH_SPS:
170
0
    return "Size of reference image does not match current size in SPS";
171
0
  case DE265_WARNING_CHROMA_OF_CURRENT_IMAGE_DOES_NOT_MATCH_SPS:
172
0
    return "Chroma format of current image does not match chroma in SPS";
173
0
  case DE265_WARNING_BIT_DEPTH_OF_CURRENT_IMAGE_DOES_NOT_MATCH_SPS:
174
0
    return "Bit-depth of current image does not match SPS";
175
0
  case DE265_WARNING_REFERENCE_IMAGE_CHROMA_FORMAT_DOES_NOT_MATCH:
176
0
    return "Chroma format of reference image does not match current image";
177
0
  case DE265_WARNING_INVALID_SLICE_HEADER_INDEX_ACCESS:
178
0
    return "Access with invalid slice header index";
179
0
  case DE265_WARNING_INVALID_TU_BLOCK_SPLIT:
180
0
    return "Transform block split below minimum transform size";
181
0
  case DE265_WARNING_RICE_PARAMETER_OUT_OF_RANGE:
182
0
    return "Rice parameter or StatCoeff out of range, clamped";
183
184
0
  default: return "unknown error";
185
0
  }
186
0
}
187
188
LIBDE265_API int de265_isOK(de265_error err)
189
33
{
190
33
  return err == DE265_OK || err >= 1000;
191
33
}
192
193
194
195
static int de265_init_count;
196
197
static std::mutex& de265_init_mutex()
198
75
{
199
75
  static std::mutex de265_init_mutex;
200
75
  return de265_init_mutex;
201
75
}
202
203
204
LIBDE265_API de265_error de265_init()
205
42
{
206
42
  std::lock_guard<std::mutex> lock(de265_init_mutex());
207
208
42
  de265_init_count++;
209
210
42
  if (de265_init_count > 1) {
211
    // we are not the first -> already initialized
212
213
33
    return DE265_OK;
214
33
  }
215
216
217
  // do initializations
218
219
9
  init_scan_orders();
220
221
9
  if (!alloc_and_init_significant_coeff_ctxIdx_lookupTable()) {
222
0
    de265_init_count--;
223
0
    return DE265_ERROR_LIBRARY_INITIALIZATION_FAILED;
224
0
  }
225
226
9
  return DE265_OK;
227
9
}
228
229
LIBDE265_API de265_error de265_free()
230
33
{
231
33
  std::lock_guard<std::mutex> lock(de265_init_mutex());
232
233
33
  if (de265_init_count<=0) {
234
0
    return DE265_ERROR_LIBRARY_NOT_INITIALIZED;
235
0
  }
236
237
33
  de265_init_count--;
238
239
33
  if (de265_init_count==0) {
240
0
    free_significant_coeff_ctxIdx_lookupTable();
241
0
  }
242
243
33
  return DE265_OK;
244
33
}
245
246
247
LIBDE265_API de265_decoder_context* de265_new_decoder()
248
33
{
249
33
  de265_error init_err = de265_init();
250
33
  if (init_err != DE265_OK) {
251
0
    return nullptr;
252
0
  }
253
254
33
  decoder_context* ctx = new decoder_context;
255
33
  if (!ctx) {
256
0
    de265_free();
257
0
    return nullptr;
258
0
  }
259
260
33
  return reinterpret_cast<de265_decoder_context*>(ctx);
261
33
}
262
263
264
LIBDE265_API de265_error de265_free_decoder(de265_decoder_context* de265ctx)
265
33
{
266
33
  decoder_context* ctx = reinterpret_cast<decoder_context*>(de265ctx);
267
268
33
  ctx->stop_thread_pool();
269
270
33
  delete ctx;
271
272
33
  return de265_free();
273
33
}
274
275
276
LIBDE265_API de265_error de265_start_worker_threads(de265_decoder_context* de265ctx, int number_of_threads)
277
33
{
278
33
  decoder_context* ctx = reinterpret_cast<decoder_context*>(de265ctx);
279
280
33
  if (number_of_threads > MAX_THREADS) {
281
0
    number_of_threads = MAX_THREADS;
282
0
  }
283
284
33
  if (number_of_threads>0) {
285
33
    de265_error err = ctx->start_thread_pool(number_of_threads);
286
33
    if (de265_isOK(err)) {
287
33
      err = DE265_OK;
288
33
    }
289
33
    return err;
290
33
  }
291
0
  else {
292
0
    return DE265_OK;
293
0
  }
294
33
}
295
296
297
#ifndef LIBDE265_DISABLE_DEPRECATED
298
LIBDE265_API de265_error de265_decode_data(de265_decoder_context* de265ctx,
299
                                           const void* data8, int len)
300
0
{
301
  //decoder_context* ctx = reinterpret_cast<decoder_context*>(de265ctx);
302
0
  de265_error err;
303
0
  if (len > 0) {
304
0
    err = de265_push_data(de265ctx, data8, len, 0, nullptr);
305
0
  } else {
306
0
    err = de265_flush_data(de265ctx);
307
0
  }
308
0
  if (err != DE265_OK) {
309
0
    return err;
310
0
  }
311
312
0
  int more = 0;
313
0
  do {
314
0
    err = de265_decode(de265ctx, &more);
315
0
    if (err != DE265_OK) {
316
0
        more = 0;
317
0
    }
318
319
0
    switch (err) {
320
0
    case DE265_ERROR_WAITING_FOR_INPUT_DATA:
321
      // ignore error (didn't exist in 0.4 and before)
322
0
      err = DE265_OK;
323
0
      break;
324
0
    default:
325
0
      break;
326
0
    }
327
0
  } while (more);
328
0
  return err;
329
0
}
330
#endif
331
332
#if 0
333
static void dumpdata(const void* data, int len)
334
{
335
  for (int i=0;i<len;i++) {
336
    printf("%02x ", ((uint8_t*)data)[i]);
337
  }
338
  printf("\n");
339
}
340
#endif
341
342
343
LIBDE265_API de265_error de265_push_data(de265_decoder_context* de265ctx,
344
                                         const void* data8, int len,
345
                                         de265_PTS pts, void* user_data)
346
0
{
347
0
  decoder_context* ctx = reinterpret_cast<decoder_context*>(de265ctx);
348
0
  const uint8_t* data = reinterpret_cast<const uint8_t*>(data8);
349
350
  //printf("push data (size %d)\n",len);
351
  //dumpdata(data8,16);
352
353
0
  return ctx->nal_parser.push_data(data,len,pts,user_data);
354
0
}
355
356
357
LIBDE265_API de265_error de265_push_NAL(de265_decoder_context* de265ctx,
358
                                        const void* data8, int len,
359
                                        de265_PTS pts, void* user_data)
360
46.2k
{
361
46.2k
  decoder_context* ctx = reinterpret_cast<decoder_context*>(de265ctx);
362
46.2k
  const uint8_t* data = reinterpret_cast<const uint8_t*>(data8);
363
364
  //printf("push NAL (size %d)\n",len);
365
  //dumpdata(data8,16);
366
367
46.2k
  return ctx->nal_parser.push_NAL(data,len,pts,user_data);
368
46.2k
}
369
370
371
LIBDE265_API de265_error de265_decode(de265_decoder_context* de265ctx, int* more)
372
0
{
373
0
  decoder_context* ctx = reinterpret_cast<decoder_context*>(de265ctx);
374
375
0
  return ctx->decode(more);
376
0
}
377
378
379
LIBDE265_API void        de265_push_end_of_NAL(de265_decoder_context* de265ctx)
380
0
{
381
0
  decoder_context* ctx = reinterpret_cast<decoder_context*>(de265ctx);
382
383
0
  ctx->nal_parser.flush_data();
384
0
}
385
386
387
LIBDE265_API void        de265_push_end_of_frame(de265_decoder_context* de265ctx)
388
0
{
389
0
  de265_push_end_of_NAL(de265ctx);
390
391
0
  decoder_context* ctx = reinterpret_cast<decoder_context*>(de265ctx);
392
0
  ctx->nal_parser.mark_end_of_frame();
393
0
}
394
395
396
LIBDE265_API de265_error de265_flush_data(de265_decoder_context* de265ctx)
397
0
{
398
0
  de265_push_end_of_NAL(de265ctx);
399
400
0
  decoder_context* ctx = reinterpret_cast<decoder_context*>(de265ctx);
401
402
0
  ctx->nal_parser.flush_data();
403
0
  ctx->nal_parser.mark_end_of_stream();
404
405
0
  return DE265_OK;
406
0
}
407
408
409
LIBDE265_API void de265_reset(de265_decoder_context* de265ctx)
410
0
{
411
0
  decoder_context* ctx = reinterpret_cast<decoder_context*>(de265ctx);
412
413
  //printf("--- reset ---\n");
414
415
0
  ctx->reset();
416
0
}
417
418
419
LIBDE265_API const struct de265_image* de265_get_next_picture(de265_decoder_context* de265ctx)
420
0
{
421
0
  const struct de265_image* img = de265_peek_next_picture(de265ctx);
422
0
  if (img) {
423
0
    de265_release_next_picture(de265ctx);
424
0
  }
425
426
0
  return img;
427
0
}
428
429
430
LIBDE265_API const struct de265_image* de265_peek_next_picture(de265_decoder_context* de265ctx)
431
0
{
432
0
  decoder_context* ctx = reinterpret_cast<decoder_context*>(de265ctx);
433
434
0
  if (ctx->num_pictures_in_output_queue()>0) {
435
0
    de265_image* img = ctx->get_next_picture_in_output_queue();
436
0
    return img;
437
0
  }
438
0
  else {
439
0
    return nullptr;
440
0
  }
441
0
}
442
443
444
LIBDE265_API void de265_release_next_picture(de265_decoder_context* de265ctx)
445
0
{
446
0
  decoder_context* ctx = reinterpret_cast<decoder_context*>(de265ctx);
447
448
  // no active output picture -> ignore release request
449
450
0
  if (ctx->num_pictures_in_output_queue()==0) { return; }
451
452
0
  de265_image* next_image = ctx->get_next_picture_in_output_queue();
453
454
0
  loginfo(LogDPB, "release DPB with POC=%d\n",next_image->PicOrderCntVal);
455
456
0
  next_image->PicOutputFlag = false;
457
458
  // TODO: actually, we want to release it here, but we cannot without breaking API
459
  // compatibility, because get_next_picture calls this immediately. Hence, we release
460
  // images while scanning for available slots in the DPB.
461
  // if (next_image->can_be_released()) { next_image->release(); }
462
463
  // pop output queue
464
465
0
  ctx->pop_next_picture_in_output_queue();
466
0
}
467
468
469
470
LIBDE265_API int  de265_get_highest_TID(de265_decoder_context* de265ctx)
471
0
{
472
0
  decoder_context* ctx = reinterpret_cast<decoder_context*>(de265ctx);
473
0
  return ctx->get_highest_TID();
474
0
}
475
476
LIBDE265_API int  de265_get_current_TID(de265_decoder_context* de265ctx)
477
0
{
478
0
  decoder_context* ctx = reinterpret_cast<decoder_context*>(de265ctx);
479
0
  return ctx->get_current_TID();
480
0
}
481
482
LIBDE265_API void de265_set_limit_TID(de265_decoder_context* de265ctx,int max_tid)
483
0
{
484
0
  decoder_context* ctx = reinterpret_cast<decoder_context*>(de265ctx);
485
0
  ctx->set_limit_TID(max_tid);
486
0
}
487
488
LIBDE265_API void de265_set_framerate_ratio(de265_decoder_context* de265ctx,int percent)
489
0
{
490
0
  decoder_context* ctx = reinterpret_cast<decoder_context*>(de265ctx);
491
0
  ctx->set_framerate_ratio(percent);
492
0
}
493
494
LIBDE265_API int  de265_change_framerate(de265_decoder_context* de265ctx,int more)
495
0
{
496
0
  decoder_context* ctx = reinterpret_cast<decoder_context*>(de265ctx);
497
0
  return ctx->change_framerate(more);
498
0
}
499
500
501
LIBDE265_API de265_error de265_get_warning(de265_decoder_context* de265ctx)
502
0
{
503
0
  decoder_context* ctx = reinterpret_cast<decoder_context*>(de265ctx);
504
505
0
  return ctx->get_warning();
506
0
}
507
508
LIBDE265_API void de265_set_parameter_bool(de265_decoder_context* de265ctx, enum de265_param param, int value)
509
0
{
510
0
  decoder_context* ctx = reinterpret_cast<decoder_context*>(de265ctx);
511
512
0
  switch (param)
513
0
    {
514
0
    case DE265_DECODER_PARAM_BOOL_SEI_CHECK_HASH:
515
0
      ctx->param_sei_check_hash = !!value;
516
0
      break;
517
518
0
    case DE265_DECODER_PARAM_SUPPRESS_FAULTY_PICTURES:
519
0
      ctx->param_suppress_faulty_pictures = !!value;
520
0
      break;
521
522
0
    case DE265_DECODER_PARAM_DISABLE_DEBLOCKING:
523
0
      ctx->param_disable_deblocking = !!value;
524
0
      break;
525
526
0
    case DE265_DECODER_PARAM_DISABLE_SAO:
527
0
      ctx->param_disable_sao = !!value;
528
0
      break;
529
530
      /*
531
    case DE265_DECODER_PARAM_DISABLE_MC_RESIDUAL_IDCT:
532
      ctx->param_disable_mc_residual_idct = !!value;
533
      break;
534
535
    case DE265_DECODER_PARAM_DISABLE_INTRA_RESIDUAL_IDCT:
536
      ctx->param_disable_intra_residual_idct = !!value;
537
      break;
538
      */
539
540
0
    default:
541
0
      assert(false);
542
0
      break;
543
0
    }
544
0
}
545
546
547
LIBDE265_API void de265_set_parameter_int(de265_decoder_context* de265ctx, enum de265_param param, int value)
548
0
{
549
0
  decoder_context* ctx = reinterpret_cast<decoder_context*>(de265ctx);
550
551
0
  switch (param)
552
0
    {
553
0
    case DE265_DECODER_PARAM_DUMP_SPS_HEADERS:
554
0
      ctx->param_sps_headers_fd = value;
555
0
      break;
556
557
0
    case DE265_DECODER_PARAM_DUMP_VPS_HEADERS:
558
0
      ctx->param_vps_headers_fd = value;
559
0
      break;
560
561
0
    case DE265_DECODER_PARAM_DUMP_PPS_HEADERS:
562
0
      ctx->param_pps_headers_fd = value;
563
0
      break;
564
565
0
    case DE265_DECODER_PARAM_DUMP_SLICE_HEADERS:
566
0
      ctx->param_slice_headers_fd = value;
567
0
      break;
568
569
0
    case DE265_DECODER_PARAM_ACCELERATION_CODE:
570
0
      ctx->set_acceleration_functions(static_cast<enum de265_acceleration>(value));
571
0
      break;
572
573
0
    default:
574
0
      assert(false);
575
0
      break;
576
0
    }
577
0
}
578
579
580
581
582
LIBDE265_API int de265_get_parameter_bool(de265_decoder_context* de265ctx, enum de265_param param)
583
0
{
584
0
  decoder_context* ctx = reinterpret_cast<decoder_context*>(de265ctx);
585
586
0
  switch (param)
587
0
    {
588
0
    case DE265_DECODER_PARAM_BOOL_SEI_CHECK_HASH:
589
0
      return ctx->param_sei_check_hash;
590
591
0
    case DE265_DECODER_PARAM_SUPPRESS_FAULTY_PICTURES:
592
0
      return ctx->param_suppress_faulty_pictures;
593
594
0
    case DE265_DECODER_PARAM_DISABLE_DEBLOCKING:
595
0
      return ctx->param_disable_deblocking;
596
597
0
    case DE265_DECODER_PARAM_DISABLE_SAO:
598
0
      return ctx->param_disable_sao;
599
600
      /*
601
    case DE265_DECODER_PARAM_DISABLE_MC_RESIDUAL_IDCT:
602
      return ctx->param_disable_mc_residual_idct;
603
604
    case DE265_DECODER_PARAM_DISABLE_INTRA_RESIDUAL_IDCT:
605
      return ctx->param_disable_intra_residual_idct;
606
      */
607
608
0
    default:
609
0
      assert(false);
610
0
      return false;
611
0
    }
612
0
}
613
614
615
LIBDE265_API int de265_get_number_of_input_bytes_pending(de265_decoder_context* de265ctx)
616
0
{
617
0
  decoder_context* ctx = reinterpret_cast<decoder_context*>(de265ctx);
618
619
0
  return ctx->nal_parser.bytes_in_input_queue();
620
0
}
621
622
623
LIBDE265_API int de265_get_number_of_NAL_units_pending(de265_decoder_context* de265ctx)
624
0
{
625
0
  decoder_context* ctx = reinterpret_cast<decoder_context*>(de265ctx);
626
627
0
  return ctx->nal_parser.number_of_NAL_units_pending();
628
0
}
629
630
631
LIBDE265_API int de265_get_image_width(const struct de265_image* img,int channel)
632
0
{
633
0
  switch (channel) {
634
0
  case 0:
635
0
    return img->width_confwin;
636
0
  case 1:
637
0
  case 2:
638
0
    return img->chroma_width_confwin;
639
0
  default:
640
0
    return 0;
641
0
  }
642
0
}
643
644
LIBDE265_API int de265_get_image_height(const struct de265_image* img,int channel)
645
0
{
646
0
  switch (channel) {
647
0
  case 0:
648
0
    return img->height_confwin;
649
0
  case 1:
650
0
  case 2:
651
0
    return img->chroma_height_confwin;
652
0
  default:
653
0
    return 0;
654
0
  }
655
0
}
656
657
LIBDE265_API int de265_get_bits_per_pixel(const struct de265_image* img,int channel)
658
0
{
659
0
  switch (channel) {
660
0
  case 0:
661
0
    return img->get_sps().BitDepth_Y;
662
0
  case 1:
663
0
  case 2:
664
0
    return img->get_sps().BitDepth_C;
665
0
  default:
666
0
    return 0;
667
0
  }
668
0
}
669
670
LIBDE265_API enum de265_chroma de265_get_chroma_format(const struct de265_image* img)
671
0
{
672
0
  return img->get_chroma_format();
673
0
}
674
675
LIBDE265_API const uint8_t* de265_get_image_plane(const de265_image* img, int channel, int* stride)
676
0
{
677
0
  assert(channel>=0 && channel <= 2);
678
679
0
  uint8_t* data = img->pixels_confwin[channel];
680
681
0
  if (stride) *stride = img->get_image_stride(channel) * ((de265_get_bits_per_pixel(img, channel)+7) / 8);
682
683
0
  return data;
684
0
}
685
686
LIBDE265_API void *de265_get_image_plane_user_data(const struct de265_image* img, int channel)
687
0
{
688
0
  assert(channel>=0 && channel <= 2);
689
690
0
  return img->plane_user_data[channel];
691
0
}
692
693
LIBDE265_API void de265_set_image_plane(de265_image* img, int cIdx, void* mem, int stride, void *userdata)
694
0
{
695
  // The internal "stride" is the number of pixels per line.
696
0
  stride = stride / ((de265_get_bits_per_pixel(img, cIdx)+7) / 8);
697
0
  img->set_image_plane(cIdx, static_cast<uint8_t*>(mem), stride, userdata);
698
0
}
699
700
LIBDE265_API void de265_set_image_allocation_functions(de265_decoder_context* de265ctx,
701
                                                       de265_image_allocation* allocfunc,
702
                                                       void* userdata)
703
0
{
704
0
  decoder_context* ctx = reinterpret_cast<decoder_context*>(de265ctx);
705
706
0
  ctx->set_image_allocation_functions(allocfunc, userdata);
707
0
}
708
709
LIBDE265_API const struct de265_image_allocation *de265_get_default_image_allocation_functions(void)
710
0
{
711
0
  return &de265_image::default_image_allocation;
712
0
}
713
714
LIBDE265_API de265_PTS de265_get_image_PTS(const struct de265_image* img)
715
0
{
716
0
  return img->pts;
717
0
}
718
719
LIBDE265_API void* de265_get_image_user_data(const struct de265_image* img)
720
0
{
721
0
  return img->user_data;
722
0
}
723
724
LIBDE265_API void de265_set_image_user_data(struct de265_image* img, void *user_data)
725
0
{
726
0
  img->user_data = user_data;
727
0
}
728
729
LIBDE265_API void de265_get_image_NAL_header(const struct de265_image* img,
730
                                             int* nal_unit_type,
731
                                             const char** nal_unit_name,
732
                                             int* nuh_layer_id,
733
                                             int* nuh_temporal_id)
734
0
{
735
0
  if (nal_unit_type)   *nal_unit_type   = img->nal_hdr.nal_unit_type;
736
0
  if (nal_unit_name)   *nal_unit_name   = get_NAL_name(img->nal_hdr.nal_unit_type);
737
0
  if (nuh_layer_id)    *nuh_layer_id    = img->nal_hdr.nuh_layer_id;
738
0
  if (nuh_temporal_id) *nuh_temporal_id = img->nal_hdr.nuh_temporal_id;
739
0
}
740
741
LIBDE265_API int de265_get_image_full_range_flag(const struct de265_image* img)
742
0
{
743
0
  return img->get_sps().vui.video_full_range_flag;
744
0
}
745
746
LIBDE265_API int de265_get_image_colour_primaries(const struct de265_image* img)
747
0
{
748
0
  return img->get_sps().vui.colour_primaries;
749
0
}
750
751
LIBDE265_API int de265_get_image_transfer_characteristics(const struct de265_image* img)
752
0
{
753
0
  return img->get_sps().vui.transfer_characteristics;
754
0
}
755
756
LIBDE265_API int de265_get_image_matrix_coefficients(const struct de265_image* img)
757
0
{
758
0
  return img->get_sps().vui.matrix_coeffs;
759
0
}
760
761
}