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.
5 // This file contains an implementation of an H.264 Decoded Picture Buffer
6 // used in H264 decoders.
8 #ifndef CONTENT_COMMON_GPU_MEDIA_H264_DPB_H_
9 #define CONTENT_COMMON_GPU_MEDIA_H264_DPB_H_
13 #include "base/basictypes.h"
14 #include "base/memory/ref_counted.h"
15 #include "media/filters/h264_parser.h"
19 class V4L2H264Picture
;
20 class VaapiH264Picture
;
22 // A picture (a frame or a field) in the H.264 spec sense.
23 // See spec at http://www.itu.int/rec/T-REC-H.264
24 class H264Picture
: public base::RefCounted
<H264Picture
> {
26 using Vector
= std::vector
<scoped_refptr
<H264Picture
>>;
36 virtual V4L2H264Picture
* AsV4L2H264Picture();
37 virtual VaapiH264Picture
* AsVaapiH264Picture();
39 // Values calculated per H.264 specification or taken from slice header.
40 // See spec for more details on each (some names have been converted from
41 // CamelCase in spec to Chromium-style names).
42 int top_field_order_cnt
;
43 int bottom_field_order_cnt
;
45 int pic_order_cnt_msb
;
46 int pic_order_cnt_lsb
;
49 int long_term_pic_num
;
50 int frame_num
; // from slice header
53 int long_term_frame_idx
;
55 media::H264SliceHeader::Type type
;
56 bool idr
; // IDR picture?
57 bool ref
; // reference picture?
58 bool long_term
; // long term reference picture?
60 // Does memory management op 5 needs to be executed after this
61 // picture has finished decoding?
66 // Values from slice_hdr to be used during reference marking and
67 // memory management after finishing this picture.
68 bool long_term_reference_flag
;
69 bool adaptive_ref_pic_marking_mode_flag
;
70 media::H264DecRefPicMarking
71 ref_pic_marking
[media::H264SliceHeader::kRefListSize
];
73 // Position in DPB (i.e. index in DPB).
77 friend class base::RefCounted
<H264Picture
>;
78 virtual ~H264Picture();
81 DISALLOW_COPY_AND_ASSIGN(H264Picture
);
84 // DPB - Decoded Picture Buffer.
85 // Stores decoded pictures that will be used for future display
92 void set_max_num_pics(size_t max_num_pics
);
93 size_t max_num_pics() const { return max_num_pics_
; }
95 // Remove unused (not reference and already outputted) pictures from DPB
99 // Remove a picture by its pic_order_cnt and free it.
100 void DeleteByPOC(int poc
);
105 // Store picture in DPB. DPB takes ownership of its resources.
106 void StorePic(const scoped_refptr
<H264Picture
>& pic
);
108 // Return the number of reference pictures in DPB.
111 // Mark all pictures in DPB as unused for reference.
112 void MarkAllUnusedForRef();
114 // Return a short-term reference picture by its pic_num.
115 scoped_refptr
<H264Picture
> GetShortRefPicByPicNum(int pic_num
);
117 // Return a long-term reference picture by its long_term_pic_num.
118 scoped_refptr
<H264Picture
> GetLongRefPicByLongTermPicNum(int pic_num
);
120 // Return the short reference picture with lowest frame_num. Used for sliding
121 // window memory management.
122 scoped_refptr
<H264Picture
> GetLowestFrameNumWrapShortRefPic();
124 // Append all pictures that have not been outputted yet to the passed |out|
125 // vector, sorted by lowest pic_order_cnt (in output order).
126 void GetNotOutputtedPicsAppending(H264Picture::Vector
* out
);
128 // Append all short term reference pictures to the passed |out| vector.
129 void GetShortTermRefPicsAppending(H264Picture::Vector
* out
);
131 // Append all long term reference pictures to the passed |out| vector.
132 void GetLongTermRefPicsAppending(H264Picture::Vector
* out
);
134 // Iterators for direct access to DPB contents.
135 // Will be invalidated after any of Remove* calls.
136 H264Picture::Vector::iterator
begin() { return pics_
.begin(); }
137 H264Picture::Vector::iterator
end() { return pics_
.end(); }
138 H264Picture::Vector::const_iterator
begin() const { return pics_
.begin(); }
139 H264Picture::Vector::const_iterator
end() const { return pics_
.end(); }
140 H264Picture::Vector::const_reverse_iterator
rbegin() const {
141 return pics_
.rbegin();
143 H264Picture::Vector::const_reverse_iterator
rend() const {
147 size_t size() const { return pics_
.size(); }
148 bool IsFull() const { return pics_
.size() == max_num_pics_
; }
150 // Per H264 spec, increase to 32 if interlaced video is supported.
151 enum { kDPBMaxSize
= 16, };
154 void UpdatePicPositions();
156 H264Picture::Vector pics_
;
157 size_t max_num_pics_
;
159 DISALLOW_COPY_AND_ASSIGN(H264DPB
);
162 } // namespace content
164 #endif // CONTENT_COMMON_GPU_MEDIA_H264_DPB_H_