Coverage Report

Created: 2025-06-16 07:00

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