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

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

Issue 2061823003: media: Drop "media::" in media/gpu (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: work around clang format by adding an empty line Created 4 years, 6 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
« no previous file with comments | « media/gpu/gpu_video_decode_accelerator_factory_impl.cc ('k') | media/gpu/h264_decoder.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 #ifndef MEDIA_GPU_H264_DECODER_H_ 5 #ifndef MEDIA_GPU_H264_DECODER_H_
6 #define MEDIA_GPU_H264_DECODER_H_ 6 #define MEDIA_GPU_H264_DECODER_H_
7 7
8 #include <stddef.h> 8 #include <stddef.h>
9 #include <stdint.h> 9 #include <stdint.h>
10 10
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
46 46
47 // Submit metadata for the current frame, providing the current |sps| and 47 // Submit metadata for the current frame, providing the current |sps| and
48 // |pps| for it, |dpb| has to contain all the pictures in DPB for current 48 // |pps| for it, |dpb| has to contain all the pictures in DPB for current
49 // frame, and |ref_pic_p0/b0/b1| as specified in the H264 spec. Note that 49 // frame, and |ref_pic_p0/b0/b1| as specified in the H264 spec. Note that
50 // depending on the frame type, either p0, or b0 and b1 are used. |pic| 50 // depending on the frame type, either p0, or b0 and b1 are used. |pic|
51 // contains information about the picture for the current frame. 51 // contains information about the picture for the current frame.
52 // Note that this does not run decode in the accelerator and the decoder 52 // Note that this does not run decode in the accelerator and the decoder
53 // is expected to follow this call with one or more SubmitSlice() calls 53 // is expected to follow this call with one or more SubmitSlice() calls
54 // before calling SubmitDecode(). 54 // before calling SubmitDecode().
55 // Return true if successful. 55 // Return true if successful.
56 virtual bool SubmitFrameMetadata(const media::H264SPS* sps, 56 virtual bool SubmitFrameMetadata(const H264SPS* sps,
57 const media::H264PPS* pps, 57 const H264PPS* pps,
58 const H264DPB& dpb, 58 const H264DPB& dpb,
59 const H264Picture::Vector& ref_pic_listp0, 59 const H264Picture::Vector& ref_pic_listp0,
60 const H264Picture::Vector& ref_pic_listb0, 60 const H264Picture::Vector& ref_pic_listb0,
61 const H264Picture::Vector& ref_pic_listb1, 61 const H264Picture::Vector& ref_pic_listb1,
62 const scoped_refptr<H264Picture>& pic) = 0; 62 const scoped_refptr<H264Picture>& pic) = 0;
63 63
64 // Submit one slice for the current frame, passing the current |pps| and 64 // Submit one slice for the current frame, passing the current |pps| and
65 // |pic| (same as in SubmitFrameMetadata()), the parsed header for the 65 // |pic| (same as in SubmitFrameMetadata()), the parsed header for the
66 // current slice in |slice_hdr|, and the reordered |ref_pic_listX|, 66 // current slice in |slice_hdr|, and the reordered |ref_pic_listX|,
67 // as per H264 spec. 67 // as per H264 spec.
68 // |data| pointing to the full slice (including the unparsed header| of 68 // |data| pointing to the full slice (including the unparsed header| of
69 // |size| in bytes. 69 // |size| in bytes.
70 // This must be called one or more times per frame, before SubmitDecode(). 70 // This must be called one or more times per frame, before SubmitDecode().
71 // Note that |data| does not have to remain valid after this call returns. 71 // Note that |data| does not have to remain valid after this call returns.
72 // Return true if successful. 72 // Return true if successful.
73 virtual bool SubmitSlice(const media::H264PPS* pps, 73 virtual bool SubmitSlice(const H264PPS* pps,
74 const media::H264SliceHeader* slice_hdr, 74 const H264SliceHeader* slice_hdr,
75 const H264Picture::Vector& ref_pic_list0, 75 const H264Picture::Vector& ref_pic_list0,
76 const H264Picture::Vector& ref_pic_list1, 76 const H264Picture::Vector& ref_pic_list1,
77 const scoped_refptr<H264Picture>& pic, 77 const scoped_refptr<H264Picture>& pic,
78 const uint8_t* data, 78 const uint8_t* data,
79 size_t size) = 0; 79 size_t size) = 0;
80 80
81 // Execute the decode in hardware for |pic|, using all the slices and 81 // Execute the decode in hardware for |pic|, using all the slices and
82 // metadata submitted via SubmitFrameMetadata() and SubmitSlice() since 82 // metadata submitted via SubmitFrameMetadata() and SubmitSlice() since
83 // the previous call to SubmitDecode(). 83 // the previous call to SubmitDecode().
84 // Return true if successful. 84 // Return true if successful.
(...skipping 11 matching lines...) Expand all
96 // any cached parameters/slices that have not been committed yet. 96 // any cached parameters/slices that have not been committed yet.
97 virtual void Reset() = 0; 97 virtual void Reset() = 0;
98 98
99 private: 99 private:
100 DISALLOW_COPY_AND_ASSIGN(H264Accelerator); 100 DISALLOW_COPY_AND_ASSIGN(H264Accelerator);
101 }; 101 };
102 102
103 H264Decoder(H264Accelerator* accelerator); 103 H264Decoder(H264Accelerator* accelerator);
104 ~H264Decoder() override; 104 ~H264Decoder() override;
105 105
106 // media::AcceleratedVideoDecoder implementation. 106 // AcceleratedVideoDecoder implementation.
107 bool Flush() override WARN_UNUSED_RESULT; 107 bool Flush() override WARN_UNUSED_RESULT;
108 void Reset() override; 108 void Reset() override;
109 void SetStream(const uint8_t* ptr, size_t size) override; 109 void SetStream(const uint8_t* ptr, size_t size) override;
110 DecodeResult Decode() override WARN_UNUSED_RESULT; 110 DecodeResult Decode() override WARN_UNUSED_RESULT;
111 gfx::Size GetPicSize() const override; 111 gfx::Size GetPicSize() const override;
112 size_t GetRequiredNumOfPictures() const override; 112 size_t GetRequiredNumOfPictures() const override;
113 113
114 private: 114 private:
115 // We need to keep at most kDPBMaxSize pictures in DPB for 115 // We need to keep at most kDPBMaxSize pictures in DPB for
116 // reference/to display later and an additional one for the one currently 116 // reference/to display later and an additional one for the one currently
117 // being decoded. We also ask for some additional ones since VDA needs 117 // being decoded. We also ask for some additional ones since VDA needs
118 // to accumulate a few ready-to-output pictures before it actually starts 118 // to accumulate a few ready-to-output pictures before it actually starts
119 // displaying and giving them back. +2 instead of +1 because of subjective 119 // displaying and giving them back. +2 instead of +1 because of subjective
120 // smoothness improvement during testing. 120 // smoothness improvement during testing.
121 enum { 121 enum {
122 kPicsInPipeline = media::limits::kMaxVideoFrames + 2, 122 kPicsInPipeline = limits::kMaxVideoFrames + 2,
123 kMaxNumReqPictures = H264DPB::kDPBMaxSize + kPicsInPipeline, 123 kMaxNumReqPictures = H264DPB::kDPBMaxSize + kPicsInPipeline,
124 }; 124 };
125 125
126 // Internal state of the decoder. 126 // Internal state of the decoder.
127 enum State { 127 enum State {
128 kNeedStreamMetadata, // After initialization, need an SPS. 128 kNeedStreamMetadata, // After initialization, need an SPS.
129 kDecoding, // Ready to decode from any point. 129 kDecoding, // Ready to decode from any point.
130 kAfterReset, // After Reset(), need a resume point. 130 kAfterReset, // After Reset(), need a resume point.
131 kError, // Error in decode, can't continue. 131 kError, // Error in decode, can't continue.
132 }; 132 };
133 133
134 // Process H264 stream structures. 134 // Process H264 stream structures.
135 bool ProcessSPS(int sps_id, bool* need_new_buffers); 135 bool ProcessSPS(int sps_id, bool* need_new_buffers);
136 // Process current slice header to discover if we need to start a new picture, 136 // Process current slice header to discover if we need to start a new picture,
137 // finishing up the current one. 137 // finishing up the current one.
138 bool PreprocessCurrentSlice(); 138 bool PreprocessCurrentSlice();
139 // Process current slice as a slice of the current picture. 139 // Process current slice as a slice of the current picture.
140 bool ProcessCurrentSlice(); 140 bool ProcessCurrentSlice();
141 141
142 // Return true if we need to start a new picture. 142 // Return true if we need to start a new picture.
143 bool IsNewPrimaryCodedPicture(const media::H264SliceHeader* slice_hdr) const; 143 bool IsNewPrimaryCodedPicture(const H264SliceHeader* slice_hdr) const;
144 144
145 // Initialize the current picture according to data in |slice_hdr|. 145 // Initialize the current picture according to data in |slice_hdr|.
146 bool InitCurrPicture(const media::H264SliceHeader* slice_hdr); 146 bool InitCurrPicture(const H264SliceHeader* slice_hdr);
147 147
148 // Initialize |pic| as a "non-existing" picture (see spec) with |frame_num|, 148 // Initialize |pic| as a "non-existing" picture (see spec) with |frame_num|,
149 // to be used for frame gap concealment. 149 // to be used for frame gap concealment.
150 bool InitNonexistingPicture(scoped_refptr<H264Picture> pic, int frame_num); 150 bool InitNonexistingPicture(scoped_refptr<H264Picture> pic, int frame_num);
151 151
152 // Calculate picture order counts for |pic| on initialization 152 // Calculate picture order counts for |pic| on initialization
153 // of a new frame (see spec). 153 // of a new frame (see spec).
154 bool CalculatePicOrderCounts(scoped_refptr<H264Picture> pic); 154 bool CalculatePicOrderCounts(scoped_refptr<H264Picture> pic);
155 155
156 // Update PicNum values in pictures stored in DPB on creation of 156 // Update PicNum values in pictures stored in DPB on creation of
157 // a picture with |frame_num|. 157 // a picture with |frame_num|.
158 void UpdatePicNums(int frame_num); 158 void UpdatePicNums(int frame_num);
159 159
160 bool UpdateMaxNumReorderFrames(const media::H264SPS* sps); 160 bool UpdateMaxNumReorderFrames(const H264SPS* sps);
161 161
162 // Prepare reference picture lists for the current frame. 162 // Prepare reference picture lists for the current frame.
163 void PrepareRefPicLists(const media::H264SliceHeader* slice_hdr); 163 void PrepareRefPicLists(const H264SliceHeader* slice_hdr);
164 // Prepare reference picture lists for the given slice. 164 // Prepare reference picture lists for the given slice.
165 bool ModifyReferencePicLists(const media::H264SliceHeader* slice_hdr, 165 bool ModifyReferencePicLists(const H264SliceHeader* slice_hdr,
166 H264Picture::Vector* ref_pic_list0, 166 H264Picture::Vector* ref_pic_list0,
167 H264Picture::Vector* ref_pic_list1); 167 H264Picture::Vector* ref_pic_list1);
168 168
169 // Construct initial reference picture lists for use in decoding of 169 // Construct initial reference picture lists for use in decoding of
170 // P and B pictures (see 8.2.4 in spec). 170 // P and B pictures (see 8.2.4 in spec).
171 void ConstructReferencePicListsP(const media::H264SliceHeader* slice_hdr); 171 void ConstructReferencePicListsP(const H264SliceHeader* slice_hdr);
172 void ConstructReferencePicListsB(const media::H264SliceHeader* slice_hdr); 172 void ConstructReferencePicListsB(const H264SliceHeader* slice_hdr);
173 173
174 // Helper functions for reference list construction, per spec. 174 // Helper functions for reference list construction, per spec.
175 int PicNumF(const scoped_refptr<H264Picture>& pic); 175 int PicNumF(const scoped_refptr<H264Picture>& pic);
176 int LongTermPicNumF(const scoped_refptr<H264Picture>& pic); 176 int LongTermPicNumF(const scoped_refptr<H264Picture>& pic);
177 177
178 // Perform the reference picture lists' modification (reordering), as 178 // Perform the reference picture lists' modification (reordering), as
179 // specified in spec (8.2.4). 179 // specified in spec (8.2.4).
180 // 180 //
181 // |list| indicates list number and should be either 0 or 1. 181 // |list| indicates list number and should be either 0 or 1.
182 bool ModifyReferencePicList(const media::H264SliceHeader* slice_hdr, 182 bool ModifyReferencePicList(const H264SliceHeader* slice_hdr,
183 int list, 183 int list,
184 H264Picture::Vector* ref_pic_listx); 184 H264Picture::Vector* ref_pic_listx);
185 185
186 // Perform reference picture memory management operations (marking/unmarking 186 // Perform reference picture memory management operations (marking/unmarking
187 // of reference pictures, long term picture management, discarding, etc.). 187 // of reference pictures, long term picture management, discarding, etc.).
188 // See 8.2.5 in spec. 188 // See 8.2.5 in spec.
189 bool HandleMemoryManagementOps(scoped_refptr<H264Picture> pic); 189 bool HandleMemoryManagementOps(scoped_refptr<H264Picture> pic);
190 bool ReferencePictureMarking(scoped_refptr<H264Picture> pic); 190 bool ReferencePictureMarking(scoped_refptr<H264Picture> pic);
191 bool SlidingWindowPictureMarking(); 191 bool SlidingWindowPictureMarking();
192 192
193 // Handle a gap in frame_num in the stream up to |frame_num|, by creating 193 // Handle a gap in frame_num in the stream up to |frame_num|, by creating
194 // "non-existing" pictures (see spec). 194 // "non-existing" pictures (see spec).
195 bool HandleFrameNumGap(int frame_num); 195 bool HandleFrameNumGap(int frame_num);
196 196
197 // Start processing a new frame. 197 // Start processing a new frame.
198 bool StartNewFrame(const media::H264SliceHeader* slice_hdr); 198 bool StartNewFrame(const H264SliceHeader* slice_hdr);
199 199
200 // All data for a frame received, process it and decode. 200 // All data for a frame received, process it and decode.
201 bool FinishPrevFrameIfPresent(); 201 bool FinishPrevFrameIfPresent();
202 202
203 // Called after we are done processing |pic|. Performs all operations to be 203 // Called after we are done processing |pic|. Performs all operations to be
204 // done after decoding, including DPB management, reference picture marking 204 // done after decoding, including DPB management, reference picture marking
205 // and memory management operations. 205 // and memory management operations.
206 // This will also output pictures if any have become ready to be outputted 206 // This will also output pictures if any have become ready to be outputted
207 // after processing |pic|. 207 // after processing |pic|.
208 bool FinishPicture(scoped_refptr<H264Picture> pic); 208 bool FinishPicture(scoped_refptr<H264Picture> pic);
209 209
210 // Clear DPB contents and remove all surfaces in DPB from *in_use_ list. 210 // Clear DPB contents and remove all surfaces in DPB from *in_use_ list.
211 // Cleared pictures will be made available for decode, unless they are 211 // Cleared pictures will be made available for decode, unless they are
212 // at client waiting to be displayed. 212 // at client waiting to be displayed.
213 void ClearDPB(); 213 void ClearDPB();
214 214
215 // Commits all pending data for HW decoder and starts HW decoder. 215 // Commits all pending data for HW decoder and starts HW decoder.
216 bool DecodePicture(); 216 bool DecodePicture();
217 217
218 // Notifies client that a picture is ready for output. 218 // Notifies client that a picture is ready for output.
219 void OutputPic(scoped_refptr<H264Picture> pic); 219 void OutputPic(scoped_refptr<H264Picture> pic);
220 220
221 // Output all pictures in DPB that have not been outputted yet. 221 // Output all pictures in DPB that have not been outputted yet.
222 bool OutputAllRemainingPics(); 222 bool OutputAllRemainingPics();
223 223
224 // Decoder state. 224 // Decoder state.
225 State state_; 225 State state_;
226 226
227 // Parser in use. 227 // Parser in use.
228 media::H264Parser parser_; 228 H264Parser parser_;
229 229
230 // DPB in use. 230 // DPB in use.
231 H264DPB dpb_; 231 H264DPB dpb_;
232 232
233 // Picture currently being processed/decoded. 233 // Picture currently being processed/decoded.
234 scoped_refptr<H264Picture> curr_pic_; 234 scoped_refptr<H264Picture> curr_pic_;
235 235
236 // Reference picture lists, constructed for each frame. 236 // Reference picture lists, constructed for each frame.
237 H264Picture::Vector ref_pic_list_p0_; 237 H264Picture::Vector ref_pic_list_p0_;
238 H264Picture::Vector ref_pic_list_b0_; 238 H264Picture::Vector ref_pic_list_b0_;
(...skipping 15 matching lines...) Expand all
254 int prev_ref_top_field_order_cnt_; 254 int prev_ref_top_field_order_cnt_;
255 int prev_ref_pic_order_cnt_msb_; 255 int prev_ref_pic_order_cnt_msb_;
256 int prev_ref_pic_order_cnt_lsb_; 256 int prev_ref_pic_order_cnt_lsb_;
257 H264Picture::Field prev_ref_field_; 257 H264Picture::Field prev_ref_field_;
258 258
259 // Currently active SPS and PPS. 259 // Currently active SPS and PPS.
260 int curr_sps_id_; 260 int curr_sps_id_;
261 int curr_pps_id_; 261 int curr_pps_id_;
262 262
263 // Current NALU and slice header being processed. 263 // Current NALU and slice header being processed.
264 std::unique_ptr<media::H264NALU> curr_nalu_; 264 std::unique_ptr<H264NALU> curr_nalu_;
265 std::unique_ptr<media::H264SliceHeader> curr_slice_hdr_; 265 std::unique_ptr<H264SliceHeader> curr_slice_hdr_;
266 266
267 // Output picture size. 267 // Output picture size.
268 gfx::Size pic_size_; 268 gfx::Size pic_size_;
269 269
270 // PicOrderCount of the previously outputted frame. 270 // PicOrderCount of the previously outputted frame.
271 int last_output_poc_; 271 int last_output_poc_;
272 272
273 H264Accelerator* accelerator_; 273 H264Accelerator* accelerator_;
274 274
275 DISALLOW_COPY_AND_ASSIGN(H264Decoder); 275 DISALLOW_COPY_AND_ASSIGN(H264Decoder);
276 }; 276 };
277 277
278 } // namespace media 278 } // namespace media
279 279
280 #endif // MEDIA_GPU_H264_DECODER_H_ 280 #endif // MEDIA_GPU_H264_DECODER_H_
OLDNEW
« no previous file with comments | « media/gpu/gpu_video_decode_accelerator_factory_impl.cc ('k') | media/gpu/h264_decoder.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698