#ifndef DE265_DPB_H
#define DE265_DPB_H
#include "libde265/image.h"
#include "libde265/sps.h"
#include <deque>
#include <vector>
class decoder_context;
class decoded_picture_buffer {
public:
decoded_picture_buffer();
~decoded_picture_buffer();
void set_max_size_of_DPB(int n) { max_images_in_DPB=n; }
void set_norm_size_of_DPB(int n) { norm_images_in_DPB=n; }
int new_image(std::shared_ptr<const seq_parameter_set> sps, decoder_context* decctx,
de265_PTS pts, void* user_data, bool isOutputImage);
bool has_free_dpb_picture(bool high_priority) const;
void clear();
int size() const { return dpb.size(); }
de265_image* get_image(int index) {
if (index>=dpb.size()) return NULL;
return dpb[index];
}
const de265_image* get_image(int index) const {
if (index>=dpb.size()) return NULL;
return dpb[index];
}
int DPB_index_of_picture_with_POC(int poc, int currentID, bool preferLongTerm=false) const;
int DPB_index_of_picture_with_LSB(int lsb, int currentID, bool preferLongTerm=false) const;
int DPB_index_of_picture_with_ID (int id) const;
void insert_image_into_reorder_buffer(struct de265_image* img) {
reorder_output_queue.push_back(img);
}
int num_pictures_in_reorder_buffer() const { return reorder_output_queue.size(); }
void output_next_picture_in_reorder_buffer();
bool flush_reorder_buffer();
int num_pictures_in_output_queue() const { return image_output_queue.size(); }
struct de265_image* get_next_picture_in_output_queue() const { return image_output_queue.front(); }
void pop_next_picture_in_output_queue();
void log_dpb_content() const;
void log_dpb_queues() const;
private:
int max_images_in_DPB;
int norm_images_in_DPB;
std::vector<struct de265_image*> dpb;
std::vector<struct de265_image*> reorder_output_queue;
std::deque<struct de265_image*> image_output_queue;
private:
decoded_picture_buffer(const decoded_picture_buffer&);
decoded_picture_buffer& operator=(const decoded_picture_buffer&);
};
#endif