Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(223)

Side by Side Diff: content/common/gpu/media/h264_decoder.h

Issue 833063003: Add accelerated video decoder interface, VP8 and H.264 implementations and hook up to V4L2SVDA. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
kcwu 2015/01/09 15:36:46 2015
Pawel Osciak 2015/01/12 07:18:20 This is a modified file from 2012.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #ifndef CONTENT_COMMON_GPU_MEDIA_H264_DECODER_H_
6 #define CONTENT_COMMON_GPU_MEDIA_H264_DECODER_H_
7
8 #include <vector>
9
10 #include "base/callback_forward.h"
11 #include "base/memory/linked_ptr.h"
12 #include "base/memory/ref_counted.h"
13 #include "base/memory/scoped_ptr.h"
14 #include "base/message_loop/message_loop_proxy.h"
15 #include "content/common/content_export.h"
16 #include "content/common/gpu/media/accelerated_video_decoder.h"
17 #include "content/common/gpu/media/h264_dpb.h"
18 #include "media/base/limits.h"
19 #include "media/filters/h264_parser.h"
20 #include "ui/gfx/geometry/size.h"
21
22 namespace content {
23
24 // Clients of this class are expected to pass H264 Annex-B byte stream
25 // and are expected to provide an implementation of H264Accelerator for
26 // offloading final steps of the decoding process.
27 //
28 // This class must be created, called and destroyed on a single thread, and
29 // does nothing internally on any other thread.
30 class CONTENT_EXPORT H264Decoder : public AcceleratedVideoDecoder {
31 public:
32 class CONTENT_EXPORT H264Accelerator {
33 public:
34 H264Accelerator() {}
35 virtual ~H264Accelerator() {}
36
37 virtual scoped_refptr<H264Picture> CreateH264Picture() = 0;
38
39 virtual bool SubmitFrameMetadata(const media::H264SPS* sps,
40 const media::H264PPS* pps,
41 const H264DPB& dpb,
42 const H264Picture::Vector& ref_pic_listp0,
43 const H264Picture::Vector& ref_pic_listb0,
44 const H264Picture::Vector& ref_pic_listb1,
45 const scoped_refptr<H264Picture>& pic) = 0;
46
47 virtual bool SubmitSlice(const media::H264PPS* pps,
48 const media::H264SliceHeader* slice_hdr,
49 const H264Picture::Vector& ref_pic_list0,
50 const H264Picture::Vector& ref_pic_list1,
51 const scoped_refptr<H264Picture>& pic,
52 const uint8_t* data,
53 size_t size) = 0;
54
55 virtual bool SubmitDecode(const scoped_refptr<H264Picture>& pic) = 0;
56 virtual bool OutputPicture(const scoped_refptr<H264Picture>& pic) = 0;
57
58 DISALLOW_COPY_AND_ASSIGN(H264Accelerator);
59 };
60
61 H264Decoder(H264Accelerator* accelerator);
62 virtual ~H264Decoder();
63
64 // content::AcceleratedVideoDecoder implementation.
65 bool Flush() override WARN_UNUSED_RESULT;
66 void Reset() override;
67 void SetStream(const uint8* ptr, size_t size) override;
68 DecResult Decode() override WARN_UNUSED_RESULT;
69 gfx::Size GetPicSize() override { return pic_size_; }
70 size_t GetRequiredNumOfPictures() override;
71
72 private:
73 // We need to keep at most kDPBMaxSize pictures in DPB for
74 // reference/to display later and an additional one for the one currently
75 // being decoded. We also ask for some additional ones since VDA needs
76 // to accumulate a few ready-to-output pictures before it actually starts
77 // displaying and giving them back. +2 instead of +1 because of subjective
78 // smoothness improvement during testing.
79 enum {
80 kPicsInPipeline = media::limits::kMaxVideoFrames + 2,
81 kMaxNumReqPictures = H264DPB::kDPBMaxSize + kPicsInPipeline,
82 };
83
84 // Internal state of the decoder.
85 enum State {
86 kNeedStreamMetadata, // After initialization, need an SPS.
87 kDecoding, // Ready to decode from any point.
88 kAfterReset, // After Reset(), need a resume point.
89 kError, // Error in decode, can't continue.
90 };
91
92 // Process H264 stream structures.
93 bool ProcessSPS(int sps_id, bool* need_new_buffers);
94 bool ProcessPPS(int pps_id);
95 bool PreprocessSlice(media::H264SliceHeader* slice_hdr);
96 bool ProcessSlice(media::H264SliceHeader* slice_hdr);
97
98 // Initialize the current picture according to data in |slice_hdr|.
99 bool InitCurrPicture(media::H264SliceHeader* slice_hdr);
100
101 // Calculate picture order counts for the new picture
102 // on initialization of a new frame (see spec).
103 bool CalculatePicOrderCounts(media::H264SliceHeader* slice_hdr);
104
105 // Update PicNum values in pictures stored in DPB on creation of new
106 // frame (see spec).
107 void UpdatePicNums();
108
109 bool UpdateMaxNumReorderFrames(const media::H264SPS* sps);
110
111 // Prepare reference picture lists for the current frame.
112 void PrepareRefPicLists(media::H264SliceHeader* slice_hdr);
113 // Prepare reference picture lists for the given slice.
114 bool ModifyReferencePicLists(media::H264SliceHeader* slice_hdr,
115 H264Picture::Vector* ref_pic_list0,
116 H264Picture::Vector* ref_pic_list1);
117
118 // Construct initial reference picture lists for use in decoding of
119 // P and B pictures (see 8.2.4 in spec).
120 void ConstructReferencePicListsP(media::H264SliceHeader* slice_hdr);
121 void ConstructReferencePicListsB(media::H264SliceHeader* slice_hdr);
122
123 // Helper functions for reference list construction, per spec.
124 int PicNumF(const scoped_refptr<H264Picture>& pic);
125 int LongTermPicNumF(const scoped_refptr<H264Picture>& pic);
126
127 // Perform the reference picture lists' modification (reordering), as
128 // specified in spec (8.2.4).
129 //
130 // |list| indicates list number and should be either 0 or 1.
131 bool ModifyReferencePicList(media::H264SliceHeader* slice_hdr,
132 int list,
133 H264Picture::Vector* ref_pic_listx);
134
135 // Perform reference picture memory management operations (marking/unmarking
136 // of reference pictures, long term picture management, discarding, etc.).
137 // See 8.2.5 in spec.
138 bool HandleMemoryManagementOps();
139 void ReferencePictureMarking();
140
141 // Start processing a new frame.
142 bool StartNewFrame(media::H264SliceHeader* slice_hdr);
143
144 // All data for a frame received, process it and decode.
145 bool FinishPrevFrameIfPresent();
146
147 // Called after decoding, performs all operations to be done after decoding,
148 // including DPB management, reference picture marking and memory management
149 // operations.
150 // This will also output a picture if one is ready for output.
151 bool FinishPicture();
152
153 // Clear DPB contents and remove all surfaces in DPB from *in_use_ list.
154 // Cleared pictures will be made available for decode, unless they are
155 // at client waiting to be displayed.
156 void ClearDPB();
157
158 // Commits all pending data for HW decoder and starts HW decoder.
159 bool DecodePicture();
160
161 // Notifies client that a picture is ready for output.
162 void OutputPic(scoped_refptr<H264Picture> pic);
163
164 // Output all pictures in DPB that have not been outputted yet.
165 bool OutputAllRemainingPics();
166
167 // Decoder state.
168 State state_;
169
170 // Parser in use.
171 media::H264Parser parser_;
172
173 // DPB in use.
174 H264DPB dpb_;
175
176 // Picture currently being processed/decoded.
177 scoped_refptr<H264Picture> curr_pic_;
178
179 // Reference picture lists, constructed for each frame.
180 H264Picture::Vector ref_pic_list_p0_;
181 H264Picture::Vector ref_pic_list_b0_;
182 H264Picture::Vector ref_pic_list_b1_;
183
184 // Global state values, needed in decoding. See spec.
185 int max_pic_order_cnt_lsb_;
186 int max_frame_num_;
187 int max_pic_num_;
188 int max_long_term_frame_idx_;
189 size_t max_num_reorder_frames_;
190
191 int frame_num_;
192 int prev_frame_num_;
193 int prev_frame_num_offset_;
194 bool prev_has_memmgmnt5_;
195
196 // Values related to previously decoded reference picture.
197 bool prev_ref_has_memmgmnt5_;
198 int prev_ref_top_field_order_cnt_;
199 int prev_ref_pic_order_cnt_msb_;
200 int prev_ref_pic_order_cnt_lsb_;
201 H264Picture::Field prev_ref_field_;
202
203 // Currently active SPS and PPS.
204 int curr_sps_id_;
205 int curr_pps_id_;
206
207 // Current NALU and slice header being processed.
208 scoped_ptr<media::H264NALU> curr_nalu_;
209 scoped_ptr<media::H264SliceHeader> curr_slice_hdr_;
210
211 // Output picture size.
212 gfx::Size pic_size_;
213
214 // PicOrderCount of the previously outputted frame.
215 int last_output_poc_;
216
217 H264Accelerator* accelerator_;
218
219 DISALLOW_COPY_AND_ASSIGN(H264Decoder);
220 };
221
222 } // namespace content
223
224 #endif // CONTENT_COMMON_GPU_MEDIA_H264_DECODER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698