Coverage Report

Created: 2026-05-16 06:41

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/work/libde265/libde265/dpb.h
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
#ifndef DE265_DPB_H
22
#define DE265_DPB_H
23
24
#include "libde265/image.h"
25
#include "libde265/sps.h"
26
27
#include <deque>
28
#include <vector>
29
30
class decoder_context;
31
32
class decoded_picture_buffer {
33
public:
34
33
  decoded_picture_buffer() = default;
35
  ~decoded_picture_buffer();
36
37
0
  void set_max_size_of_DPB(uint8_t n)  { max_images_in_DPB=n; }
38
0
  void set_norm_size_of_DPB(uint8_t n) { norm_images_in_DPB=n; }
39
40
  /* Alloc a new image in the DPB and return its index.
41
     If there is no space for a new image, returns the negative value of an de265_error.
42
     I.e. you can check for error by return_value<0, which is error (-return_value);
43
     */
44
  int new_image(std::shared_ptr<const seq_parameter_set> sps, decoder_context* decctx,
45
                de265_PTS pts, void* user_data, bool isOutputImage);
46
47
  /* Check for a free slot in the DPB. There are some slots reserved for
48
     unavailable reference frames. If high_priority==true, these reserved slots
49
     are included in the check. */
50
  bool has_free_dpb_picture(bool high_priority) const;
51
52
  /* Remove all pictures from DPB and queues. Decoding should be stopped while calling this. */
53
  void clear();
54
55
0
  size_t size() const { return dpb.size(); }
56
57
  /* Raw access to the images. */
58
59
0
  /* */ de265_image* get_image(uint16_t index)       {
60
0
    if (index>=dpb.size()) return nullptr;
61
0
    return dpb[index];
62
0
  }
63
64
0
  const de265_image* get_image(uint16_t index) const {
65
0
    if (index>=dpb.size()) return nullptr;
66
0
    return dpb[index];
67
0
  }
68
69
  /* Search DPB for the slot index of a specific picture. */
70
  int DPB_index_of_picture_with_POC(int poc, uint32_t currentID, bool preferLongTerm=false) const;
71
  int DPB_index_of_picture_with_LSB(int lsb, uint32_t currentID, bool preferLongTerm=false) const;
72
  int DPB_index_of_picture_with_ID (uint32_t id) const;
73
74
75
  // --- reorder buffer ---
76
77
0
  void insert_image_into_reorder_buffer(struct de265_image* img) {
78
0
    reorder_output_queue.push_back(img);
79
0
  }
80
81
0
  int num_pictures_in_reorder_buffer() const { return reorder_output_queue.size(); }
82
83
  // move next picture in reorder buffer to output queue
84
  void output_next_picture_in_reorder_buffer();
85
86
  // Move all pictures in reorder buffer to output buffer. Return true if there were any pictures.
87
  bool flush_reorder_buffer();
88
89
90
  // --- output buffer ---
91
92
0
  int num_pictures_in_output_queue() const { return image_output_queue.size(); }
93
94
  /* Get the next picture in the output queue, but do not remove it from the queue. */
95
0
  struct de265_image* get_next_picture_in_output_queue() const { return image_output_queue.front(); }
96
97
  /* Remove the next picture in the output queue. */
98
  void pop_next_picture_in_output_queue();
99
100
101
  // --- debug ---
102
103
  void log_dpb_content() const;
104
  void log_dpb_queues() const;
105
106
private:
107
  static const int DPB_DEFAULT_MAX_IMAGES = 30;
108
109
  uint8_t max_images_in_DPB = DPB_DEFAULT_MAX_IMAGES;
110
  uint8_t norm_images_in_DPB = DPB_DEFAULT_MAX_IMAGES;
111
112
  std::vector<struct de265_image*> dpb; // decoded picture buffer
113
114
  std::vector<struct de265_image*> reorder_output_queue;
115
  std::deque<struct de265_image*>  image_output_queue;
116
117
  decoded_picture_buffer(const decoded_picture_buffer&) = delete;
118
  decoded_picture_buffer& operator=(const decoded_picture_buffer&) = delete;
119
};
120
121
#endif