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 <vector> |
| 12 |
| 13 #include "base/basictypes.h" |
| 14 #include "base/memory/scoped_vector.h" |
| 15 #include "content/common/gpu/media/h264_parser.h" |
| 16 |
| 17 namespace content { |
| 18 |
| 19 // A picture (a frame or a field) in the H.264 spec sense. |
| 20 // See spec at http://www.itu.int/rec/T-REC-H.264 |
| 21 struct H264Picture { |
| 22 enum Field { |
| 23 FIELD_NONE, |
| 24 FIELD_TOP, |
| 25 FIELD_BOTTOM, |
| 26 }; |
| 27 |
| 28 // Values calculated per H.264 specification or taken from slice header. |
| 29 // See spec for more details on each (some names have been converted from |
| 30 // CamelCase in spec to Chromium-style names). |
| 31 int top_field_order_cnt; |
| 32 int bottom_field_order_cnt; |
| 33 int pic_order_cnt; |
| 34 int pic_order_cnt_msb; |
| 35 int pic_order_cnt_lsb; |
| 36 |
| 37 int pic_num; |
| 38 int long_term_pic_num; |
| 39 int frame_num; // from slice header |
| 40 int frame_num_wrap; |
| 41 int long_term_frame_idx; |
| 42 |
| 43 bool idr; // IDR picture? |
| 44 bool ref; // reference picture? |
| 45 bool long_term; // long term reference picture? |
| 46 bool outputted; |
| 47 // Does memory management op 5 needs to be executed after this |
| 48 // picture has finished decoding? |
| 49 bool mem_mgmt_5; |
| 50 |
| 51 Field field; |
| 52 |
| 53 // Values from slice_hdr to be used during reference marking and |
| 54 // memory management after finishing this picture. |
| 55 bool long_term_reference_flag; |
| 56 bool adaptive_ref_pic_marking_mode_flag; |
| 57 H264DecRefPicMarking ref_pic_marking[H264SliceHeader::kRefListSize]; |
| 58 |
| 59 typedef std::vector<H264Picture*> PtrVector; |
| 60 }; |
| 61 |
| 62 // DPB - Decoded Picture Buffer. |
| 63 // Stores decoded pictures that will be used for future display |
| 64 // and/or reference. |
| 65 class H264DPB { |
| 66 public: |
| 67 H264DPB(); |
| 68 ~H264DPB(); |
| 69 |
| 70 // Remove unused (not reference and already outputted) pictures from DPB. |
| 71 void RemoveUnused(); |
| 72 |
| 73 // Remove a picture by its pic_order_cnt. |
| 74 void RemoveByPOC(int poc); |
| 75 |
| 76 // Clear DPB. |
| 77 void Clear(); |
| 78 |
| 79 // Store picture in DPB. DPB takes ownership of its resources. |
| 80 void StorePic(H264Picture* pic); |
| 81 |
| 82 // Return the number of reference pictures in DPB. |
| 83 int CountRefPics(); |
| 84 |
| 85 // Mark all pictures in DPB as unused for reference. |
| 86 void MarkAllUnusedForRef(); |
| 87 |
| 88 // Return a short-term reference picture by its pic_num. |
| 89 H264Picture* GetShortRefPicByPicNum(int pic_num); |
| 90 |
| 91 // Return a long-term reference picture by its long_term_pic_num. |
| 92 H264Picture* GetLongRefPicByLongTermPicNum(int pic_num); |
| 93 |
| 94 // Return the short reference picture with lowest frame_num. Used for sliding |
| 95 // window memory management. |
| 96 H264Picture* GetLowestFrameNumWrapShortRefPic(); |
| 97 |
| 98 // Append all pictures that have not been outputted yet to the passed |out| |
| 99 // vector, sorted by lowest pic_order_cnt (in output order). |
| 100 void GetNotOutputtedPicsAppending(H264Picture::PtrVector& out); |
| 101 |
| 102 // Append all short term reference pictures to the passed |out| vector. |
| 103 void GetShortTermRefPicsAppending(H264Picture::PtrVector& out); |
| 104 |
| 105 // Append all long term reference pictures to the passed |out| vector. |
| 106 void GetLongTermRefPicsAppending(H264Picture::PtrVector& out); |
| 107 |
| 108 // Iterators for direct access to DPB contents. |
| 109 // Will be invalidated after any of Remove* calls. |
| 110 typedef ScopedVector<H264Picture> Pictures; |
| 111 Pictures::iterator begin() { return pics_.begin(); } |
| 112 Pictures::iterator end() { return pics_.end(); } |
| 113 Pictures::reverse_iterator rbegin() { return pics_.rbegin(); } |
| 114 Pictures::reverse_iterator rend() { return pics_.rend(); } |
| 115 |
| 116 size_t size() const { return pics_.size(); } |
| 117 bool IsFull() const { return pics_.size() == kDPBMaxSize; } |
| 118 |
| 119 // Per H264 spec, increase to 32 if interlaced video is supported. |
| 120 enum { kDPBMaxSize = 16 }; |
| 121 |
| 122 private: |
| 123 // Remove a picture from DPB, freeing its resources. |
| 124 void RemovePic(const Pictures::iterator iter); |
| 125 |
| 126 Pictures pics_; |
| 127 |
| 128 DISALLOW_COPY_AND_ASSIGN(H264DPB); |
| 129 }; |
| 130 |
| 131 } // namespace content |
| 132 |
| 133 #endif // CONTENT_COMMON_GPU_MEDIA_H264_DPB_H_ |
| 134 |
OLD | NEW |