xref: /aosp_15_r20/external/libvpx/vp9/simple_encode.h (revision fb1b10ab9aebc7c7068eedab379b749d7e3900be)
1 /*
2  *  Copyright (c) 2019 The WebM project authors. All Rights Reserved.
3  *
4  *  Use of this source code is governed by a BSD-style license
5  *  that can be found in the LICENSE file in the root of the source
6  *  tree. An additional intellectual property rights grant can be found
7  *  in the file PATENTS.  All contributing project authors may
8  *  be found in the AUTHORS file in the root of the source tree.
9  */
10 
11 #ifndef VPX_VP9_SIMPLE_ENCODE_H_
12 #define VPX_VP9_SIMPLE_ENCODE_H_
13 
14 #include <cstddef>
15 #include <cstdint>
16 #include <cstdio>
17 #include <memory>
18 #include <vector>
19 
20 namespace vp9 {
21 
22 enum StatusCode {
23   StatusOk = 0,
24   StatusError,
25 };
26 
27 // TODO(angiebird): Add description for each frame type.
28 enum FrameType {
29   kFrameTypeKey = 0,
30   kFrameTypeInter = 1,
31   kFrameTypeAltRef = 2,
32   kFrameTypeOverlay = 3,
33   kFrameTypeGolden = 4,
34 };
35 
36 // TODO(angiebird): Add description for each reference frame type.
37 // This enum numbers have to be contiguous and start from zero except
38 // kNoneRefFrame.
39 enum RefFrameType {
40   kRefFrameTypeLast = 0,
41   kRefFrameTypePast = 1,
42   kRefFrameTypeFuture = 2,
43   kRefFrameTypeMax = 3,
44   kRefFrameTypeNone = -1,
45 };
46 
47 enum VP9_LEVEL {
48   LEVEL_UNKNOWN = 0,
49   LEVEL_AUTO = 1,
50   LEVEL_1 = 10,
51   LEVEL_1_1 = 11,
52   LEVEL_2 = 20,
53   LEVEL_2_1 = 21,
54   LEVEL_3 = 30,
55   LEVEL_3_1 = 31,
56   LEVEL_4 = 40,
57   LEVEL_4_1 = 41,
58   LEVEL_5 = 50,
59   LEVEL_5_1 = 51,
60   LEVEL_5_2 = 52,
61   LEVEL_6 = 60,
62   LEVEL_6_1 = 61,
63   LEVEL_6_2 = 62,
64   LEVEL_MAX = 255
65 };
66 
67 enum GopMapFlag {
68   kGopMapFlagStart =
69       1 << 0,  // Indicate this location is the start of a group of pictures.
70   kGopMapFlagUseAltRef =
71       1 << 1,  // Indicate this group of pictures will use an alt ref. Only set
72                // this flag when kGopMapFlagStart is set.
73 };
74 
75 // The frame is split to 4x4 blocks.
76 // This structure contains the information of each 4x4 block.
77 struct PartitionInfo {
78   int row;           // row pixel offset of current 4x4 block
79   int column;        // column pixel offset of current 4x4 block
80   int row_start;     // row pixel offset of the start of the prediction block
81   int column_start;  // column pixel offset of the start of the prediction block
82   int width;         // prediction block width
83   int height;        // prediction block height
84 };
85 
86 constexpr int kMotionVectorSubPixelPrecision = 8;
87 constexpr int kMotionVectorFullPixelPrecision = 1;
88 
89 // In the first pass. The frame is split to 16x16 blocks.
90 // This structure contains the information of each 16x16 block.
91 // In the second pass. The frame is split to 4x4 blocks.
92 // This structure contains the information of each 4x4 block.
93 struct MotionVectorInfo {
94   // Number of valid motion vectors, always 0 if this block is in the key frame.
95   // For inter frames, it could be 1 or 2.
96   int mv_count;
97   // The reference frame for motion vectors. If the second motion vector does
98   // not exist (mv_count = 1), the reference frame is kNoneRefFrame.
99   // Otherwise, the reference frame is either kRefFrameTypeLast, or
100   // kRefFrameTypePast, or kRefFrameTypeFuture.
101   RefFrameType ref_frame[2];
102   // The row offset of motion vectors in the unit of pixel.
103   // If the second motion vector does not exist, the value is 0.
104   double mv_row[2];
105   // The column offset of motion vectors in the unit of pixel.
106   // If the second motion vector does not exist, the value is 0.
107   double mv_column[2];
108 };
109 
110 // Accumulated tpl stats of all blocks in one frame.
111 // For each frame, the tpl stats are computed per 32x32 block.
112 struct TplStatsInfo {
113   // Intra complexity: the sum of absolute transform difference (SATD) of
114   // intra predicted residuals.
115   int64_t intra_cost;
116   // Inter complexity: the SATD of inter predicted residuals.
117   int64_t inter_cost;
118   // Motion compensated information flow. It measures how much information
119   // is propagated from the current frame to other frames.
120   int64_t mc_flow;
121   // Motion compensated dependency cost. It equals to its own intra_cost
122   // plus the mc_flow.
123   int64_t mc_dep_cost;
124   // Motion compensated reference cost.
125   int64_t mc_ref_cost;
126 };
127 
128 struct RefFrameInfo {
129   int coding_indexes[kRefFrameTypeMax];
130 
131   // Indicate whether the reference frames are available or not.
132   // When the reference frame type is not valid, it means either the to-be-coded
133   // frame is a key frame or the reference frame already appears in other
134   // reference frame type. vp9 always keeps three types of reference frame
135   // available.  However, the duplicated reference frames will not be
136   // chosen by the encoder. The priorities of choosing reference frames are
137   // kRefFrameTypeLast > kRefFrameTypePast > kRefFrameTypeFuture.
138   // For example, if kRefFrameTypeLast and kRefFrameTypePast both point to the
139   // same frame, kRefFrameTypePast will be set to invalid.
140   // 1: the ref frame type is available 0: the ref frame type is not available
141   int valid_list[kRefFrameTypeMax];
142 };
143 
144 bool operator==(const RefFrameInfo &a, const RefFrameInfo &b);
145 
146 struct EncodeFrameInfo {
147   int show_idx;
148 
149   // Each show or no show frame is assigned with a coding index based on its
150   // coding order (starting from zero) in the coding process of the entire
151   // video. The coding index for each frame is unique.
152   int coding_index;
153   RefFrameInfo ref_frame_info;
154   FrameType frame_type;
155 };
156 
157 // This structure is a copy of vp9 |nmv_component_counts|.
158 struct NewMotionvectorComponentCounts {
159   std::vector<unsigned int> sign;
160   std::vector<unsigned int> classes;
161   std::vector<unsigned int> class0;
162   std::vector<std::vector<unsigned int>> bits;
163   std::vector<std::vector<unsigned int>> class0_fp;
164   std::vector<unsigned int> fp;
165   std::vector<unsigned int> class0_hp;
166   std::vector<unsigned int> hp;
167 };
168 
169 // This structure is a copy of vp9 |nmv_context_counts|.
170 struct NewMotionVectorContextCounts {
171   std::vector<unsigned int> joints;
172   std::vector<NewMotionvectorComponentCounts> comps;
173 };
174 
175 using UintArray2D = std::vector<std::vector<unsigned int>>;
176 using UintArray3D = std::vector<std::vector<std::vector<unsigned int>>>;
177 using UintArray5D = std::vector<
178     std::vector<std::vector<std::vector<std::vector<unsigned int>>>>>;
179 using UintArray6D = std::vector<std::vector<
180     std::vector<std::vector<std::vector<std::vector<unsigned int>>>>>>;
181 
182 // This structure is a copy of vp9 |tx_counts|.
183 struct TransformSizeCounts {
184   // Transform size found in blocks of partition size 32x32.
185   // First dimension: transform size contexts (2).
186   // Second dimension: transform size type (3: 32x32, 16x16, 8x8)
187   UintArray2D p32x32;
188   // Transform size found in blocks of partition size 16x16.
189   // First dimension: transform size contexts (2).
190   // Second dimension: transform size type (2: 16x16, 8x8)
191   UintArray2D p16x16;
192   // Transform size found in blocks of partition size 8x8.
193   // First dimension: transform size contexts (2).
194   // Second dimension: transform size type (1: 8x8)
195   UintArray2D p8x8;
196   // Overall transform size count.
197   std::vector<unsigned int> tx_totals;
198 };
199 
200 // This structure is a copy of vp9 |FRAME_COUNTS|.
201 struct FrameCounts {
202   // Intra prediction mode for luma plane. First dimension: block size (4).
203   // Second dimension: intra prediction mode (10).
204   UintArray2D y_mode;
205   // Intra prediction mode for chroma plane. First and second dimension:
206   // intra prediction mode (10).
207   UintArray2D uv_mode;
208   // Partition type. First dimension: partition contexts (16).
209   // Second dimension: partition type (4).
210   UintArray2D partition;
211   // Transform coefficient.
212   UintArray6D coef;
213   // End of block (the position of the last non-zero transform coefficient)
214   UintArray5D eob_branch;
215   // Interpolation filter type. First dimension: switchable filter contexts (4).
216   // Second dimension: filter types (3).
217   UintArray2D switchable_interp;
218   // Inter prediction mode (the motion vector type).
219   // First dimension: inter mode contexts (7).
220   // Second dimension: mode type (4).
221   UintArray2D inter_mode;
222   // Block is intra or inter predicted. First dimension: contexts (4).
223   // Second dimension: type (0 for intra, 1 for inter).
224   UintArray2D intra_inter;
225   // Block is compound predicted (predicted from average of two blocks).
226   // First dimension: contexts (5).
227   // Second dimension: type (0 for single, 1 for compound prediction).
228   UintArray2D comp_inter;
229   // Type of the reference frame. Only one reference frame.
230   // First dimension: context (5). Second dimension: context (2).
231   // Third dimension: count (2).
232   UintArray3D single_ref;
233   // Type of the two reference frames.
234   // First dimension: context (5). Second dimension: count (2).
235   UintArray2D comp_ref;
236   // Block skips transform and quantization, uses prediction as reconstruction.
237   // First dimension: contexts (3). Second dimension: type (0 not skip, 1 skip).
238   UintArray2D skip;
239   // Transform size.
240   TransformSizeCounts tx;
241   // New motion vector.
242   NewMotionVectorContextCounts mv;
243 };
244 
245 struct ImageBuffer {
246   // The image data is stored in raster order,
247   // i.e. image[plane][r][c] =
248   // plane_buffer[plane][r * plane_width[plane] + plane_height[plane]].
249   std::unique_ptr<unsigned char[]> plane_buffer[3];
250   int plane_width[3];
251   int plane_height[3];
252 };
253 
254 void output_image_buffer(const ImageBuffer &image_buffer, std::FILE *out_file);
255 
256 struct EncodeFrameResult {
257   int show_idx;
258   FrameType frame_type;
259   int coding_idx;
260   RefFrameInfo ref_frame_info;
261   size_t coding_data_bit_size;
262   size_t coding_data_byte_size;
263   // The EncodeFrame will allocate a buffer, write the coding data into the
264   // buffer and give the ownership of the buffer to coding_data.
265   std::unique_ptr<unsigned char[]> coding_data;
266   size_t max_coding_data_byte_size;
267   double psnr;
268   uint64_t sse;
269   int quantize_index;
270   FrameCounts frame_counts;
271   int num_rows_4x4;  // number of row units, in size of 4.
272   int num_cols_4x4;  // number of column units, in size of 4.
273   // A vector of the partition information of the frame.
274   // The number of elements is |num_rows_4x4| * |num_cols_4x4|.
275   // The frame is divided 4x4 blocks of |num_rows_4x4| rows and
276   // |num_cols_4x4| columns.
277   // Each 4x4 block contains the current pixel position (|row|, |column|),
278   // the start pixel position of the partition (|row_start|, |column_start|),
279   // and the |width|, |height| of the partition.
280   // The current pixel position can be the same as the start pixel position
281   // if the 4x4 block is the top-left block in the partition. Otherwise, they
282   // are different.
283   // Within the same partition, all 4x4 blocks have the same |row_start|,
284   // |column_start|, |width| and |height|.
285   // For example, if the frame is partitioned to a 32x32 block,
286   // starting at (0, 0). Then, there're 64 4x4 blocks within this partition.
287   // They all have the same |row_start|, |column_start|, |width|, |height|,
288   // which can be used to figure out the start of the current partition and
289   // the start of the next partition block.
290   // Horizontal next: |column_start| + |width|,
291   // Vertical next: |row_start| + |height|.
292   std::vector<PartitionInfo> partition_info;
293   // A vector of the motion vector information of the frame.
294   // The number of elements is |num_rows_4x4| * |num_cols_4x4|.
295   // The frame is divided into 4x4 blocks of |num_rows_4x4| rows and
296   // |num_cols_4x4| columns.
297   // Each 4x4 block contains 0 motion vector if this is an intra predicted
298   // frame (for example, the key frame). If the frame is inter predicted,
299   // each 4x4 block contains either 1 or 2 motion vectors.
300   // Similar to partition info, all 4x4 blocks inside the same partition block
301   // share the same motion vector information.
302   std::vector<MotionVectorInfo> motion_vector_info;
303   // A vector of the tpl stats information.
304   // The tpl stats measure the complexity of a frame, as well as the
305   // information propagated along the motion trajectory between frames, in
306   // the reference frame structure.
307   // The tpl stats could be used as a more accurate spatial and temporal
308   // complexity measure in addition to the first pass stats.
309   // The vector contains tpl stats for all show frames in a GOP.
310   // The tpl stats stored in the vector is according to the encoding order.
311   // For example, suppose there are N show frames for the current GOP.
312   // Then tpl_stats_info[0] stores the information of the first frame to be
313   // encoded for this GOP, i.e., the AltRef frame.
314   std::vector<TplStatsInfo> tpl_stats_info;
315   ImageBuffer coded_frame;
316 
317   // recode_count, q_index_history and rate_history are only available when
318   // EncodeFrameWithTargetFrameBits() is used.
319   int recode_count;
320   std::vector<int> q_index_history;
321   std::vector<int> rate_history;
322 };
323 
324 struct GroupOfPicture {
325   // This list will be updated internally in StartEncode() and
326   // EncodeFrame()/EncodeFrameWithQuantizeIndex().
327   // In EncodeFrame()/EncodeFrameWithQuantizeIndex(), the update will only be
328   // triggered when the coded frame is the last one in the previous group of
329   // pictures.
330   std::vector<EncodeFrameInfo> encode_frame_list;
331 
332   // Indicates the index of the next coding frame in encode_frame_list.
333   // In other words, EncodeFrameInfo of the next coding frame can be
334   // obtained with encode_frame_list[next_encode_frame_index].
335   // Internally, next_encode_frame_index will be set to zero after the last
336   // frame of the group of pictures is coded. Otherwise, next_encode_frame_index
337   // will be increased after each EncodeFrame()/EncodeFrameWithQuantizeIndex()
338   // call.
339   int next_encode_frame_index;
340 
341   // Number of show frames in this group of pictures.
342   int show_frame_count;
343 
344   // The show index/timestamp of the earliest show frame in the group of
345   // pictures.
346   int start_show_index;
347 
348   // The coding index of the first coding frame in the group of pictures.
349   int start_coding_index;
350 
351   // Indicates whether this group of pictures starts with a key frame.
352   int first_is_key_frame;
353 
354   // Indicates whether this group of pictures uses an alt ref.
355   int use_alt_ref;
356 
357   // Indicates whether previous group of pictures used an alt ref.
358   int last_gop_use_alt_ref;
359 };
360 
361 class SimpleEncode {
362  public:
363   // When outfile_path is set, the encoder will output the bitstream in ivf
364   // format.
365   SimpleEncode(int frame_width, int frame_height, int frame_rate_num,
366                int frame_rate_den, int target_bitrate, int num_frames,
367                int target_level, const char *infile_path,
368                const char *outfile_path = nullptr);
369   ~SimpleEncode();
370   SimpleEncode(SimpleEncode &) = delete;
371   SimpleEncode &operator=(const SimpleEncode &) = delete;
372 
373   // Adjusts the encoder's coding speed.
374   // If this function is not called, the encoder will use default encode_speed
375   // 0. Call this function before ComputeFirstPassStats() if needed.
376   // The encode_speed is equivalent to --cpu-used of the vpxenc command.
377   // The encode_speed's range should be [0, 9].
378   // Setting the encode_speed to a higher level will yield faster coding
379   // at the cost of lower compression efficiency.
380   void SetEncodeSpeed(int encode_speed);
381 
382   // Set encoder config
383   // The following configs in VP9EncoderConfig are allowed to change in this
384   // function. See https://ffmpeg.org/ffmpeg-codecs.html#libvpx for each
385   // config's meaning.
386   // Configs in VP9EncoderConfig:          Equivalent configs in ffmpeg:
387   // 1  key_freq                           -g
388   // 2  two_pass_vbrmin_section            -minrate * 100LL / bit_rate
389   // 3  two_pass_vbrmax_section            -maxrate * 100LL / bit_rate
390   // 4  under_shoot_pct                    -undershoot-pct
391   // 5  over_shoot_pct                     -overshoot-pct
392   // 6  max_threads                        -threads
393   // 7  frame_parallel_decoding_mode       -frame-parallel
394   // 8  tile_column                        -tile-columns
395   // 9  arnr_max_frames                    -arnr-maxframes
396   // 10 arnr_strength                      -arnr-strength
397   // 11 lag_in_frames                      -rc_lookahead
398   // 12 encode_breakout                    -static-thresh
399   // 13 enable_tpl_model                   -enable-tpl
400   // 14 enable_auto_arf                    -auto-alt-ref
401   // 15 rc_mode
402   //    Possible Settings:
403   //      0 - Variable Bit Rate (VPX_VBR)  -b:v <bit_rate>
404   //      1 - Constant Bit Rate (VPX_CBR)  -b:v <bit_rate> -minrate <bit_rate>
405   //                                        -maxrate <bit_rate>
406   //        two_pass_vbrmin_section == 100   i.e. bit_rate == minrate == maxrate
407   //        two_pass_vbrmax_section == 100
408   //      2 - Constrained Quality (VPX_CQ) -crf <cq_level> -b:v bit_rate
409   //      3 - Constant Quality (VPX_Q)     -crf <cq_level> -b:v 0
410   //    See https://trac.ffmpeg.org/wiki/Encode/VP9 for more details.
411   // 16 cq_level                          see rc_mode for details.
412   StatusCode SetEncodeConfig(const char *name, const char *value);
413 
414   // A debug function that dumps configs from VP9EncoderConfig
415   // pass = 1: first pass, pass = 2: second pass
416   // fp: file pointer for dumping config
417   StatusCode DumpEncodeConfigs(int pass, FILE *fp);
418 
419   // Makes encoder compute the first pass stats and store it at
420   // impl_ptr_->first_pass_stats. key_frame_map_ is also computed based on the
421   // first pass stats.
422   void ComputeFirstPassStats();
423 
424   // Outputs the first pass stats represented by a 2-D vector.
425   // One can use the frame index at first dimension to retrieve the stats for
426   // each video frame. The stats of each video frame is a vector of 25 double
427   // values. For details, please check FIRSTPASS_STATS in vp9_firstpass.h
428   std::vector<std::vector<double>> ObserveFirstPassStats();
429 
430   // Outputs the first pass motion vectors represented by a 2-D vector.
431   // One can use the frame index at first dimension to retrieve the mvs for
432   // each video frame. The frame is divided into 16x16 blocks. The number of
433   // elements is round_up(|num_rows_4x4| / 4) * round_up(|num_cols_4x4| / 4).
434   std::vector<std::vector<MotionVectorInfo>> ObserveFirstPassMotionVectors();
435 
436   // Ouputs a copy of key_frame_map_, a binary vector with size equal to the
437   // number of show frames in the video. For each entry in the vector, 1
438   // indicates the position is a key frame and 0 indicates it's not a key frame.
439   // This function should be called after ComputeFirstPassStats()
440   std::vector<int> ObserveKeyFrameMap() const;
441 
442   // Sets group of pictures map for coding the entire video.
443   // Each entry in the gop_map corresponds to a show frame in the video.
444   // Therefore, the size of gop_map should equal to the number of show frames in
445   // the entire video.
446   // If a given entry's kGopMapFlagStart is set, it means this is the start of a
447   // gop. Once kGopMapFlagStart is set, one can set kGopMapFlagUseAltRef to
448   // indicate whether this gop use altref.
449   // If a given entry is zero, it means it's in the middle of a gop.
450   // This function should be called only once after ComputeFirstPassStats(),
451   // before StartEncode().
452   // This API will check and modify the gop_map to satisfy the following
453   // constraints.
454   // 1) Each key frame position should be at the start of a gop.
455   // 2) The last gop should not use an alt ref.
456   void SetExternalGroupOfPicturesMap(int *gop_map, int gop_map_size);
457 
458   // Observe the group of pictures map set through
459   // SetExternalGroupOfPicturesMap(). This function should be called after
460   // SetExternalGroupOfPicturesMap().
461   std::vector<int> ObserveExternalGroupOfPicturesMap();
462 
463   // Initializes the encoder for actual encoding.
464   // This function should be called after ComputeFirstPassStats().
465   void StartEncode();
466 
467   // Frees the encoder.
468   // This function should be called after StartEncode() or EncodeFrame().
469   void EndEncode();
470 
471   // The key frame group size includes one key frame plus the number of
472   // following inter frames. Note that the key frame group size only counts the
473   // show frames. The number of no show frames like alternate refereces are not
474   // counted.
475   int GetKeyFrameGroupSize() const;
476 
477   // Provides the group of pictures that the next coding frame is in.
478   // Only call this function between StartEncode() and EndEncode()
479   GroupOfPicture ObserveGroupOfPicture() const;
480 
481   // Gets encode_frame_info for the next coding frame.
482   // Only call this function between StartEncode() and EndEncode()
483   EncodeFrameInfo GetNextEncodeFrameInfo() const;
484 
485   // Encodes a frame
486   // This function should be called after StartEncode() and before EndEncode().
487   void EncodeFrame(EncodeFrameResult *encode_frame_result);
488 
489   // Encodes a frame with a specific quantize index.
490   // This function should be called after StartEncode() and before EndEncode().
491   void EncodeFrameWithQuantizeIndex(EncodeFrameResult *encode_frame_result,
492                                     int quantize_index);
493 
494   // Encode a frame with target frame bits usage.
495   // The encoder will find a quantize index to make the actual frame bits usage
496   // match the target. EncodeFrameWithTargetFrameBits() will recode the frame
497   // up to 7 times to find a q_index to make the actual_frame_bits satisfy the
498   // following inequality. |actual_frame_bits - target_frame_bits| * 100 /
499   // target_frame_bits
500   // <= percent_diff.
501   void EncodeFrameWithTargetFrameBits(EncodeFrameResult *encode_frame_result,
502                                       int target_frame_bits,
503                                       double percent_diff);
504 
505   // Gets the number of coding frames for the video. The coding frames include
506   // show frame and no show frame.
507   // This function should be called after ComputeFirstPassStats().
508   int GetCodingFrameNum() const;
509 
510   // Gets the total number of pixels of YUV planes per frame.
511   uint64_t GetFramePixelCount() const;
512 
513  private:
514   // Compute the key frame locations of the video based on first pass stats.
515   // The results are returned as a binary vector with 1s indicating keyframes
516   // and 0s indicating non keyframes.
517   // It has to be called after impl_ptr_->first_pass_stats is computed.
518   std::vector<int> ComputeKeyFrameMap() const;
519 
520   // Updates key_frame_group_size_, reset key_frame_group_index_ and init
521   // ref_frame_info_.
522   void UpdateKeyFrameGroup(int key_frame_show_index);
523 
524   // Update key_frame_group_index_.
525   void PostUpdateKeyFrameGroupIndex(FrameType frame_type);
526 
527   void PostUpdateState(const EncodeFrameResult &encode_frame_result);
528 
529   class EncodeImpl;
530 
531   int frame_width_;   // frame width in pixels.
532   int frame_height_;  // frame height in pixels.
533   int frame_rate_num_;
534   int frame_rate_den_;
535   int target_bitrate_;
536   int num_frames_;
537   int encode_speed_;
538   int target_level_;
539 
540   std::FILE *in_file_;
541   std::FILE *out_file_;
542   std::unique_ptr<EncodeImpl> impl_ptr_;
543 
544   std::vector<int> key_frame_map_;
545   std::vector<int> gop_map_;
546   GroupOfPicture group_of_picture_;
547 
548   // The key frame group size includes one key frame plus the number of
549   // following inter frames. Note that the key frame group size only counts the
550   // show frames. The number of no show frames like alternate references are not
551   // counted.
552   int key_frame_group_size_;
553 
554   // The index for the to-be-coded show frame in the key frame group.
555   int key_frame_group_index_;
556 
557   // Each show or no show frame is assigned with a coding index based on its
558   // coding order (starting from zero) in the coding process of the entire
559   // video. The coding index of the to-be-coded frame.
560   int frame_coding_index_;
561 
562   // Number of show frames we have coded so far.
563   int show_frame_count_;
564 
565   // TODO(angiebird): Do we need to reset ref_frames_info_ when the next key
566   // frame appears?
567   // Reference frames info of the to-be-coded frame.
568   RefFrameInfo ref_frame_info_;
569 
570   // A 2-D vector of motion vector information of the frame collected
571   // from the first pass. The first dimension is the frame index.
572   // Each frame is divided into 16x16 blocks. The number of elements is
573   // round_up(|num_rows_4x4| / 4) * round_up(|num_cols_4x4| / 4).
574   // Each 16x16 block contains 0 motion vector if this is an intra predicted
575   // frame (for example, the key frame). If the frame is inter predicted,
576   // each 16x16 block contains either 1 or 2 motion vectors.
577   // The first motion vector is always from the LAST_FRAME.
578   // The second motion vector is always from the GOLDEN_FRAME.
579   std::vector<std::vector<MotionVectorInfo>> fp_motion_vector_info_;
580 };
581 
582 }  // namespace vp9
583 
584 #endif  // VPX_VP9_SIMPLE_ENCODE_H_
585