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