digiKam
encoder-context.h
Go to the documentation of this file.
1 /*
2  * H.265 video codec.
3  * Copyright (c) 2013-2014 struktur AG, Dirk Farin <farin@struktur.de>
4  *
5  * Authors: Dirk Farin <farin@struktur.de>
6  *
7  * This file is part of libde265.
8  *
9  * libde265 is free software: you can redistribute it and/or modify
10  * it under the terms of the GNU Lesser General Public License as
11  * published by the Free Software Foundation, either version 3 of
12  * the License, or (at your option) any later version.
13  *
14  * libde265 is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  * GNU Lesser General Public License for more details.
18  *
19  * You should have received a copy of the GNU Lesser General Public License
20  * along with libde265. If not, see <http://www.gnu.org/licenses/>.
21  */
22 
23 #ifndef ENCODER_CONTEXT_H
24 #define ENCODER_CONTEXT_H
25 
26 #include "libde265/image.h"
27 #include "libde265/decctx.h"
28 #include "libde265/image-io.h"
31 #include "libde265/encoder/sop.h"
32 #include "libde265/en265.h"
33 #include "libde265/util.h"
34 
35 #include <memory>
36 
37 
39 {
40  public:
43 
44  virtual const de265_image* get_image(int frame_id) const {
45  return picbuf.get_picture(frame_id)->reconstruction;
46  }
47 
48  virtual bool has_image(int frame_id) const {
49  return picbuf.has_picture(frame_id);
50  }
51 
53 
56 
58 
60  bool image_spec_is_defined; // whether we know the input image size
61 
63  /*
64  void (*release_func)(en265_encoder_context*,
65  de265_image*,
66  void* userdata);
67  */
68 
69  //error_queue errqueue;
70  //acceleration_functions accel;
71 
72  // quick links
73  de265_image* img; // reconstruction
74  //de265_image* prediction;
75  image_data* imgdata; // input image
77 
79 
80  // temporary memory for motion compensated pixels (when CB-algo passes this down to TB-algo)
81  //uint8_t prediction[3][64*64]; // stride: 1<<(cb->log2Size)
82  //int prediction_x0,prediction_y0;
83 
84 
85  int active_qp; // currently active QP
86  /*int target_qp;*/ /* QP we want to code at.
87  (Not actually the real QP. Check image.get_QPY() for that.) */
88 
89  const seq_parameter_set& get_sps() const { return *sps; }
90  const pic_parameter_set& get_pps() const { return *pps; }
91 
92  seq_parameter_set& get_sps() { return *sps; }
93  pic_parameter_set& get_pps() { return *pps; }
94 
95  std::shared_ptr<video_parameter_set>& get_shared_vps() { return vps; }
96  std::shared_ptr<seq_parameter_set>& get_shared_sps() { return sps; }
97  std::shared_ptr<pic_parameter_set>& get_shared_pps() { return pps; }
98 
99  private:
100  std::shared_ptr<video_parameter_set> vps;
101  std::shared_ptr<seq_parameter_set> sps;
102  std::shared_ptr<pic_parameter_set> pps;
103  //slice_segment_header shdr;
104 
105  public:
108 
110  std::shared_ptr<sop_creator> sop;
111 
112  std::deque<en265_packet*> output_packets;
113 
114 
115  // --- rate-control ---
116 
117  float lambda;
118 
119 
120  // --- CABAC output and rate estimation ---
121 
122  //CABAC_encoder* cabac; // currently active CABAC output (estim or bitstream)
123  //context_model_table2* ctx_model; // currently active ctx models (estim or bitstream)
124 
125  // CABAC bitstream writer
128 
129  //std::shared_ptr<CABAC_encoder> cabac_estim;
130 
132 
133 
134  /*** TODO: CABAC_encoder direkt an encode-Funktion übergeben, anstatt hier
135  aussenrum zwischenzuspeichern (mit undefinierter Lifetime).
136  Das Context-Model kann dann gleich mit in den Encoder rein cabac_encoder(ctxtable).
137  write_bits() wird dann mit dem context-index aufgerufen, nicht mit dem model direkt.
138  ***/
139 
140 
141  /*
142  void switch_CABAC(context_model_table2* model) {
143  cabac = cabac_estim.get();
144  ctx_model = model;
145  }
146 
147  void switch_CABAC_to_bitstream() {
148  cabac = &cabac_bitstream;
149  ctx_model = &ctx_model_bitstream;
150  }
151  */
152 
154 
155 
156  // --- encoding control ---
157 
161 
162 
163  // Input images can be released after encoding and when the output packet is released.
164  // This is important to do as soon as possible, as the image might actually wrap
165  // scarce resources like camera picture buffers.
166  // This function does release (only) the raw input data.
167  void release_input_image(int frame_number) { picbuf.release_input_image(frame_number); }
168 
169  void mark_image_is_outputted(int frame_number) { picbuf.mark_image_is_outputted(frame_number); }
170 };
171 
172 
173 #endif
Definition: cabac.h:103
Definition: encoder-types.h:341
Definition: encoder-core.h:83
Definition: decctx.h:274
Definition: configparam.h:366
Definition: contextmodel.h:100
Definition: encoder-context.h:39
int image_height
Definition: encoder-context.h:59
de265_image * img
Definition: encoder-context.h:73
encoder_picture_buffer picbuf
Definition: encoder-context.h:109
std::shared_ptr< seq_parameter_set > & get_shared_sps()
Definition: encoder-context.h:96
CABAC_encoder_bitstream cabac_encoder
Definition: encoder-context.h:126
bool headers_have_been_sent
Definition: encoder-context.h:107
bool encoder_started
Definition: encoder-context.h:52
int active_qp
Definition: encoder-context.h:85
void start_encoder()
std::shared_ptr< pic_parameter_set > & get_shared_pps()
Definition: encoder-context.h:97
void mark_image_is_outputted(int frame_number)
Definition: encoder-context.h:169
void * param_image_allocation_userdata
Definition: encoder-context.h:62
void release_input_image(int frame_number)
Definition: encoder-context.h:167
const pic_parameter_set & get_pps() const
Definition: encoder-context.h:90
de265_error encode_headers()
bool parameters_have_been_set
Definition: encoder-context.h:106
context_model_table cabac_ctx_models
Definition: encoder-context.h:127
std::deque< en265_packet * > output_packets
Definition: encoder-context.h:112
config_parameters params_config
Definition: encoder-context.h:55
seq_parameter_set & get_sps()
Definition: encoder-context.h:92
image_data * imgdata
Definition: encoder-context.h:75
virtual bool has_image(int frame_id) const
Definition: encoder-context.h:48
CTBTreeMatrix ctbs
Definition: encoder-context.h:78
int image_width
Definition: encoder-context.h:59
virtual const de265_image * get_image(int frame_id) const
Definition: encoder-context.h:44
encoder_params params
Definition: encoder-context.h:54
std::shared_ptr< video_parameter_set > & get_shared_vps()
Definition: encoder-context.h:95
float lambda
Definition: encoder-context.h:117
pic_parameter_set & get_pps()
Definition: encoder-context.h:93
const seq_parameter_set & get_sps() const
Definition: encoder-context.h:89
EncoderCore_Custom algo
Definition: encoder-context.h:57
de265_error encode_picture_from_input_buffer()
bool use_adaptive_context
Definition: encoder-context.h:131
slice_segment_header * shdr
Definition: encoder-context.h:76
std::shared_ptr< sop_creator > sop
Definition: encoder-context.h:110
en265_packet * create_packet(en265_packet_content_type t)
bool image_spec_is_defined
Definition: encoder-context.h:60
Definition: encpicbuf.h:92
const image_data * get_picture(int frame_number) const
void release_input_image(int frame_number)
bool has_picture(int frame_number) const
void mark_image_is_outputted(int frame_number)
Definition: pps.h:59
Definition: sps.h:86
Definition: slice.h:130
de265_error
Definition: de265.h:82
en265_packet_content_type
Definition: en265.h:144
Definition: image.h:222
Definition: en265.h:184
Definition: encoder-params.h:76
Definition: encpicbuf.h:35
de265_image * reconstruction
Definition: encpicbuf.h:43