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