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