| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 // | |
| 5 // This file contains an implementation of an H.264 Decoded Picture Buffer | |
| 6 // used in H264 decoders. | |
| 7 | |
| 8 #ifndef CONTENT_COMMON_GPU_MEDIA_H264_DPB_H_ | |
| 9 #define CONTENT_COMMON_GPU_MEDIA_H264_DPB_H_ | |
| 10 | |
| 11 #include <stddef.h> | |
| 12 | |
| 13 #include <vector> | |
| 14 | |
| 15 #include "base/macros.h" | |
| 16 #include "base/memory/ref_counted.h" | |
| 17 #include "media/filters/h264_parser.h" | |
| 18 | |
| 19 namespace content { | |
| 20 | |
| 21 class V4L2H264Picture; | |
| 22 class VaapiH264Picture; | |
| 23 | |
| 24 // A picture (a frame or a field) in the H.264 spec sense. | |
| 25 // See spec at http://www.itu.int/rec/T-REC-H.264 | |
| 26 class H264Picture : public base::RefCounted<H264Picture> { | |
| 27 public: | |
| 28 using Vector = std::vector<scoped_refptr<H264Picture>>; | |
| 29 | |
| 30 enum Field { | |
| 31 FIELD_NONE, | |
| 32 FIELD_TOP, | |
| 33 FIELD_BOTTOM, | |
| 34 }; | |
| 35 | |
| 36 H264Picture(); | |
| 37 | |
| 38 virtual V4L2H264Picture* AsV4L2H264Picture(); | |
| 39 virtual VaapiH264Picture* AsVaapiH264Picture(); | |
| 40 | |
| 41 // Values calculated per H.264 specification or taken from slice header. | |
| 42 // See spec for more details on each (some names have been converted from | |
| 43 // CamelCase in spec to Chromium-style names). | |
| 44 int pic_order_cnt_type; | |
| 45 int top_field_order_cnt; | |
| 46 int bottom_field_order_cnt; | |
| 47 int pic_order_cnt; | |
| 48 int pic_order_cnt_msb; | |
| 49 int pic_order_cnt_lsb; | |
| 50 int delta_pic_order_cnt_bottom; | |
| 51 int delta_pic_order_cnt0; | |
| 52 int delta_pic_order_cnt1; | |
| 53 | |
| 54 int pic_num; | |
| 55 int long_term_pic_num; | |
| 56 int frame_num; // from slice header | |
| 57 int frame_num_offset; | |
| 58 int frame_num_wrap; | |
| 59 int long_term_frame_idx; | |
| 60 | |
| 61 media::H264SliceHeader::Type type; | |
| 62 int nal_ref_idc; | |
| 63 bool idr; // IDR picture? | |
| 64 int idr_pic_id; // Valid only if idr == true. | |
| 65 bool ref; // reference picture? | |
| 66 bool long_term; // long term reference picture? | |
| 67 bool outputted; | |
| 68 // Does memory management op 5 needs to be executed after this | |
| 69 // picture has finished decoding? | |
| 70 bool mem_mgmt_5; | |
| 71 | |
| 72 // Created by the decoding process for gaps in frame_num. | |
| 73 // Not for decode or output. | |
| 74 bool nonexisting; | |
| 75 | |
| 76 Field field; | |
| 77 | |
| 78 // Values from slice_hdr to be used during reference marking and | |
| 79 // memory management after finishing this picture. | |
| 80 bool long_term_reference_flag; | |
| 81 bool adaptive_ref_pic_marking_mode_flag; | |
| 82 media::H264DecRefPicMarking | |
| 83 ref_pic_marking[media::H264SliceHeader::kRefListSize]; | |
| 84 | |
| 85 // Position in DPB (i.e. index in DPB). | |
| 86 int dpb_position; | |
| 87 | |
| 88 protected: | |
| 89 friend class base::RefCounted<H264Picture>; | |
| 90 virtual ~H264Picture(); | |
| 91 | |
| 92 private: | |
| 93 DISALLOW_COPY_AND_ASSIGN(H264Picture); | |
| 94 }; | |
| 95 | |
| 96 // DPB - Decoded Picture Buffer. | |
| 97 // Stores decoded pictures that will be used for future display | |
| 98 // and/or reference. | |
| 99 class H264DPB { | |
| 100 public: | |
| 101 H264DPB(); | |
| 102 ~H264DPB(); | |
| 103 | |
| 104 void set_max_num_pics(size_t max_num_pics); | |
| 105 size_t max_num_pics() const { return max_num_pics_; } | |
| 106 | |
| 107 // Remove unused (not reference and already outputted) pictures from DPB | |
| 108 // and free it. | |
| 109 void DeleteUnused(); | |
| 110 | |
| 111 // Remove a picture by its pic_order_cnt and free it. | |
| 112 void DeleteByPOC(int poc); | |
| 113 | |
| 114 // Clear DPB. | |
| 115 void Clear(); | |
| 116 | |
| 117 // Store picture in DPB. DPB takes ownership of its resources. | |
| 118 void StorePic(const scoped_refptr<H264Picture>& pic); | |
| 119 | |
| 120 // Return the number of reference pictures in DPB. | |
| 121 int CountRefPics(); | |
| 122 | |
| 123 // Mark all pictures in DPB as unused for reference. | |
| 124 void MarkAllUnusedForRef(); | |
| 125 | |
| 126 // Return a short-term reference picture by its pic_num. | |
| 127 scoped_refptr<H264Picture> GetShortRefPicByPicNum(int pic_num); | |
| 128 | |
| 129 // Return a long-term reference picture by its long_term_pic_num. | |
| 130 scoped_refptr<H264Picture> GetLongRefPicByLongTermPicNum(int pic_num); | |
| 131 | |
| 132 // Return the short reference picture with lowest frame_num. Used for sliding | |
| 133 // window memory management. | |
| 134 scoped_refptr<H264Picture> GetLowestFrameNumWrapShortRefPic(); | |
| 135 | |
| 136 // Append all pictures that have not been outputted yet to the passed |out| | |
| 137 // vector, sorted by lowest pic_order_cnt (in output order). | |
| 138 void GetNotOutputtedPicsAppending(H264Picture::Vector* out); | |
| 139 | |
| 140 // Append all short term reference pictures to the passed |out| vector. | |
| 141 void GetShortTermRefPicsAppending(H264Picture::Vector* out); | |
| 142 | |
| 143 // Append all long term reference pictures to the passed |out| vector. | |
| 144 void GetLongTermRefPicsAppending(H264Picture::Vector* out); | |
| 145 | |
| 146 // Iterators for direct access to DPB contents. | |
| 147 // Will be invalidated after any of Remove* calls. | |
| 148 H264Picture::Vector::iterator begin() { return pics_.begin(); } | |
| 149 H264Picture::Vector::iterator end() { return pics_.end(); } | |
| 150 H264Picture::Vector::const_iterator begin() const { return pics_.begin(); } | |
| 151 H264Picture::Vector::const_iterator end() const { return pics_.end(); } | |
| 152 H264Picture::Vector::const_reverse_iterator rbegin() const { | |
| 153 return pics_.rbegin(); | |
| 154 } | |
| 155 H264Picture::Vector::const_reverse_iterator rend() const { | |
| 156 return pics_.rend(); | |
| 157 } | |
| 158 | |
| 159 size_t size() const { return pics_.size(); } | |
| 160 bool IsFull() const { return pics_.size() == max_num_pics_; } | |
| 161 | |
| 162 // Per H264 spec, increase to 32 if interlaced video is supported. | |
| 163 enum { kDPBMaxSize = 16, }; | |
| 164 | |
| 165 private: | |
| 166 void UpdatePicPositions(); | |
| 167 | |
| 168 H264Picture::Vector pics_; | |
| 169 size_t max_num_pics_; | |
| 170 | |
| 171 DISALLOW_COPY_AND_ASSIGN(H264DPB); | |
| 172 }; | |
| 173 | |
| 174 } // namespace content | |
| 175 | |
| 176 #endif // CONTENT_COMMON_GPU_MEDIA_H264_DPB_H_ | |
| OLD | NEW |