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

Side by Side Diff: media/gpu/v4l2_slice_video_decode_accelerator.cc

Issue 2229353002: V4L2SVDA: Add a VP9Accelerator implementation utilizing the V4L2 VP9 frame API. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: compilation fixes Created 4 years, 3 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
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 #include "media/gpu/v4l2_slice_video_decode_accelerator.h" 5 #include "media/gpu/v4l2_slice_video_decode_accelerator.h"
6 6
7 #include <errno.h> 7 #include <errno.h>
8 #include <fcntl.h> 8 #include <fcntl.h>
9 #include <linux/videodev2.h> 9 #include <linux/videodev2.h>
10 #include <poll.h> 10 #include <poll.h>
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
59 #define IOCTL_OR_LOG_ERROR(type, arg) \ 59 #define IOCTL_OR_LOG_ERROR(type, arg) \
60 do { \ 60 do { \
61 if (device_->Ioctl(type, arg) != 0) \ 61 if (device_->Ioctl(type, arg) != 0) \
62 PLOGF(ERROR) << "ioctl() failed: " << #type; \ 62 PLOGF(ERROR) << "ioctl() failed: " << #type; \
63 } while (0) 63 } while (0)
64 64
65 namespace media { 65 namespace media {
66 66
67 // static 67 // static
68 const uint32_t V4L2SliceVideoDecodeAccelerator::supported_input_fourccs_[] = { 68 const uint32_t V4L2SliceVideoDecodeAccelerator::supported_input_fourccs_[] = {
69 V4L2_PIX_FMT_H264_SLICE, V4L2_PIX_FMT_VP8_FRAME, 69 V4L2_PIX_FMT_H264_SLICE, V4L2_PIX_FMT_VP8_FRAME, V4L2_PIX_FMT_VP9_FRAME,
70 }; 70 };
71 71
72 class V4L2SliceVideoDecodeAccelerator::V4L2DecodeSurface 72 class V4L2SliceVideoDecodeAccelerator::V4L2DecodeSurface
73 : public base::RefCounted<V4L2DecodeSurface> { 73 : public base::RefCounted<V4L2DecodeSurface> {
74 public: 74 public:
75 using ReleaseCB = base::Callback<void(int)>; 75 using ReleaseCB = base::Callback<void(int)>;
76 76
77 V4L2DecodeSurface(int32_t bitstream_id, 77 V4L2DecodeSurface(int32_t bitstream_id,
78 int input_record, 78 int input_record,
79 int output_record, 79 int output_record,
80 const ReleaseCB& release_cb); 80 const ReleaseCB& release_cb);
81 81
82 // Mark the surface as decoded. This will also release all references, as 82 // Mark the surface as decoded. This will also release all references, as
83 // they are not needed anymore. 83 // they are not needed anymore and execute the done callback, if not null.
84 void SetDecoded(); 84 void SetDecoded();
85 bool decoded() const { return decoded_; } 85 bool decoded() const { return decoded_; }
86 86
87 int32_t bitstream_id() const { return bitstream_id_; } 87 int32_t bitstream_id() const { return bitstream_id_; }
88 int input_record() const { return input_record_; } 88 int input_record() const { return input_record_; }
89 int output_record() const { return output_record_; } 89 int output_record() const { return output_record_; }
90 uint32_t config_store() const { return config_store_; } 90 uint32_t config_store() const { return config_store_; }
91 91
92 // Take references to each reference surface and keep them until the 92 // Take references to each reference surface and keep them until the
93 // target surface is decoded. 93 // target surface is decoded.
94 void SetReferenceSurfaces( 94 void SetReferenceSurfaces(
95 const std::vector<scoped_refptr<V4L2DecodeSurface>>& ref_surfaces); 95 const std::vector<scoped_refptr<V4L2DecodeSurface>>& ref_surfaces);
96 96
97 // If provided via this method, |done_cb| callback will be executed after
98 // decoding into this surface is finished. The callback is reset afterwards,
99 // so it needs to be set again before each decode operation.
100 void SetDecodeDoneCallback(const base::Closure& done_cb) {
101 DCHECK(done_cb_.is_null());
102 done_cb_ = done_cb;
103 }
104
97 std::string ToString() const; 105 std::string ToString() const;
98 106
99 private: 107 private:
100 friend class base::RefCounted<V4L2DecodeSurface>; 108 friend class base::RefCounted<V4L2DecodeSurface>;
101 ~V4L2DecodeSurface(); 109 ~V4L2DecodeSurface();
102 110
103 int32_t bitstream_id_; 111 int32_t bitstream_id_;
104 int input_record_; 112 int input_record_;
105 int output_record_; 113 int output_record_;
106 uint32_t config_store_; 114 uint32_t config_store_;
107 115
108 bool decoded_; 116 bool decoded_;
109 ReleaseCB release_cb_; 117 ReleaseCB release_cb_;
118 base::Closure done_cb_;
110 119
111 std::vector<scoped_refptr<V4L2DecodeSurface>> reference_surfaces_; 120 std::vector<scoped_refptr<V4L2DecodeSurface>> reference_surfaces_;
112 121
113 DISALLOW_COPY_AND_ASSIGN(V4L2DecodeSurface); 122 DISALLOW_COPY_AND_ASSIGN(V4L2DecodeSurface);
114 }; 123 };
115 124
116 V4L2SliceVideoDecodeAccelerator::V4L2DecodeSurface::V4L2DecodeSurface( 125 V4L2SliceVideoDecodeAccelerator::V4L2DecodeSurface::V4L2DecodeSurface(
117 int32_t bitstream_id, 126 int32_t bitstream_id,
118 int input_record, 127 int input_record,
119 int output_record, 128 int output_record,
(...skipping 16 matching lines...) Expand all
136 reference_surfaces_ = ref_surfaces; 145 reference_surfaces_ = ref_surfaces;
137 } 146 }
138 147
139 void V4L2SliceVideoDecodeAccelerator::V4L2DecodeSurface::SetDecoded() { 148 void V4L2SliceVideoDecodeAccelerator::V4L2DecodeSurface::SetDecoded() {
140 DCHECK(!decoded_); 149 DCHECK(!decoded_);
141 decoded_ = true; 150 decoded_ = true;
142 151
143 // We can now drop references to all reference surfaces for this surface 152 // We can now drop references to all reference surfaces for this surface
144 // as we are done with decoding. 153 // as we are done with decoding.
145 reference_surfaces_.clear(); 154 reference_surfaces_.clear();
155
156 // And finally execute and drop the decode done callback, if set.
157 if (!done_cb_.is_null())
158 base::ResetAndReturn(&done_cb_).Run();
146 } 159 }
147 160
148 std::string V4L2SliceVideoDecodeAccelerator::V4L2DecodeSurface::ToString() 161 std::string V4L2SliceVideoDecodeAccelerator::V4L2DecodeSurface::ToString()
149 const { 162 const {
150 std::string out; 163 std::string out;
151 base::StringAppendF(&out, "Buffer %d -> %d. ", input_record_, output_record_); 164 base::StringAppendF(&out, "Buffer %d -> %d. ", input_record_, output_record_);
152 base::StringAppendF(&out, "Reference surfaces:"); 165 base::StringAppendF(&out, "Reference surfaces:");
153 for (const auto& ref : reference_surfaces_) { 166 for (const auto& ref : reference_surfaces_) {
154 DCHECK_NE(ref->output_record(), output_record_); 167 DCHECK_NE(ref->output_record(), output_record_);
155 base::StringAppendF(&out, " %d", ref->output_record()); 168 base::StringAppendF(&out, " %d", ref->output_record());
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
238 V4L2SliceVideoDecodeAccelerator::PictureRecord::PictureRecord( 251 V4L2SliceVideoDecodeAccelerator::PictureRecord::PictureRecord(
239 bool cleared, 252 bool cleared,
240 const Picture& picture) 253 const Picture& picture)
241 : cleared(cleared), picture(picture) {} 254 : cleared(cleared), picture(picture) {}
242 255
243 V4L2SliceVideoDecodeAccelerator::PictureRecord::~PictureRecord() {} 256 V4L2SliceVideoDecodeAccelerator::PictureRecord::~PictureRecord() {}
244 257
245 class V4L2SliceVideoDecodeAccelerator::V4L2H264Accelerator 258 class V4L2SliceVideoDecodeAccelerator::V4L2H264Accelerator
246 : public H264Decoder::H264Accelerator { 259 : public H264Decoder::H264Accelerator {
247 public: 260 public:
248 V4L2H264Accelerator(V4L2SliceVideoDecodeAccelerator* v4l2_dec); 261 explicit V4L2H264Accelerator(V4L2SliceVideoDecodeAccelerator* v4l2_dec);
249 ~V4L2H264Accelerator() override; 262 ~V4L2H264Accelerator() override;
250 263
251 // H264Decoder::H264Accelerator implementation. 264 // H264Decoder::H264Accelerator implementation.
252 scoped_refptr<H264Picture> CreateH264Picture() override; 265 scoped_refptr<H264Picture> CreateH264Picture() override;
253 266
254 bool SubmitFrameMetadata(const H264SPS* sps, 267 bool SubmitFrameMetadata(const H264SPS* sps,
255 const H264PPS* pps, 268 const H264PPS* pps,
256 const H264DPB& dpb, 269 const H264DPB& dpb,
257 const H264Picture::Vector& ref_pic_listp0, 270 const H264Picture::Vector& ref_pic_listp0,
258 const H264Picture::Vector& ref_pic_listb0, 271 const H264Picture::Vector& ref_pic_listb0,
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
292 static const size_t kMaxSlices = 16; 305 static const size_t kMaxSlices = 16;
293 struct v4l2_ctrl_h264_slice_param v4l2_slice_params_[kMaxSlices]; 306 struct v4l2_ctrl_h264_slice_param v4l2_slice_params_[kMaxSlices];
294 struct v4l2_ctrl_h264_decode_param v4l2_decode_param_; 307 struct v4l2_ctrl_h264_decode_param v4l2_decode_param_;
295 308
296 DISALLOW_COPY_AND_ASSIGN(V4L2H264Accelerator); 309 DISALLOW_COPY_AND_ASSIGN(V4L2H264Accelerator);
297 }; 310 };
298 311
299 class V4L2SliceVideoDecodeAccelerator::V4L2VP8Accelerator 312 class V4L2SliceVideoDecodeAccelerator::V4L2VP8Accelerator
300 : public VP8Decoder::VP8Accelerator { 313 : public VP8Decoder::VP8Accelerator {
301 public: 314 public:
302 V4L2VP8Accelerator(V4L2SliceVideoDecodeAccelerator* v4l2_dec); 315 explicit V4L2VP8Accelerator(V4L2SliceVideoDecodeAccelerator* v4l2_dec);
303 ~V4L2VP8Accelerator() override; 316 ~V4L2VP8Accelerator() override;
304 317
305 // VP8Decoder::VP8Accelerator implementation. 318 // VP8Decoder::VP8Accelerator implementation.
306 scoped_refptr<VP8Picture> CreateVP8Picture() override; 319 scoped_refptr<VP8Picture> CreateVP8Picture() override;
307 320
308 bool SubmitDecode(const scoped_refptr<VP8Picture>& pic, 321 bool SubmitDecode(const scoped_refptr<VP8Picture>& pic,
309 const Vp8FrameHeader* frame_hdr, 322 const Vp8FrameHeader* frame_hdr,
310 const scoped_refptr<VP8Picture>& last_frame, 323 const scoped_refptr<VP8Picture>& last_frame,
311 const scoped_refptr<VP8Picture>& golden_frame, 324 const scoped_refptr<VP8Picture>& golden_frame,
312 const scoped_refptr<VP8Picture>& alt_frame) override; 325 const scoped_refptr<VP8Picture>& alt_frame) override;
313 326
314 bool OutputPicture(const scoped_refptr<VP8Picture>& pic) override; 327 bool OutputPicture(const scoped_refptr<VP8Picture>& pic) override;
315 328
316 private: 329 private:
317 scoped_refptr<V4L2DecodeSurface> VP8PictureToV4L2DecodeSurface( 330 scoped_refptr<V4L2DecodeSurface> VP8PictureToV4L2DecodeSurface(
318 const scoped_refptr<VP8Picture>& pic); 331 const scoped_refptr<VP8Picture>& pic);
319 332
320 V4L2SliceVideoDecodeAccelerator* v4l2_dec_; 333 V4L2SliceVideoDecodeAccelerator* v4l2_dec_;
321 334
322 DISALLOW_COPY_AND_ASSIGN(V4L2VP8Accelerator); 335 DISALLOW_COPY_AND_ASSIGN(V4L2VP8Accelerator);
323 }; 336 };
324 337
338 class V4L2SliceVideoDecodeAccelerator::V4L2VP9Accelerator
339 : public VP9Decoder::VP9Accelerator {
340 public:
341 explicit V4L2VP9Accelerator(V4L2SliceVideoDecodeAccelerator* v4l2_dec);
342 ~V4L2VP9Accelerator() override;
343
344 // VP9Decoder::VP9Accelerator implementation.
345 scoped_refptr<VP9Picture> CreateVP9Picture() override;
346
347 bool SubmitDecode(const scoped_refptr<VP9Picture>& pic,
348 const Vp9SegmentationParams& segm_params,
349 const Vp9LoopFilterParams& lf_params,
350 const std::vector<scoped_refptr<VP9Picture>>& ref_pictures,
351 const base::Closure& done_cb) override;
352
353 bool OutputPicture(const scoped_refptr<VP9Picture>& pic) override;
354
355 bool GetFrameContext(const scoped_refptr<VP9Picture>& pic,
356 Vp9FrameContext* frame_ctx) override;
357
358 bool IsFrameContextRequired() const override {
359 return device_needs_frame_context_;
360 }
361
362 private:
363 scoped_refptr<V4L2DecodeSurface> VP9PictureToV4L2DecodeSurface(
364 const scoped_refptr<VP9Picture>& pic);
365
366 bool device_needs_frame_context_;
367
368 V4L2SliceVideoDecodeAccelerator* v4l2_dec_;
369
370 DISALLOW_COPY_AND_ASSIGN(V4L2VP9Accelerator);
371 };
372
325 // Codec-specific subclasses of software decoder picture classes. 373 // Codec-specific subclasses of software decoder picture classes.
326 // This allows us to keep decoders oblivious of our implementation details. 374 // This allows us to keep decoders oblivious of our implementation details.
327 class V4L2H264Picture : public H264Picture { 375 class V4L2H264Picture : public H264Picture {
328 public: 376 public:
329 V4L2H264Picture( 377 explicit V4L2H264Picture(
330 const scoped_refptr<V4L2SliceVideoDecodeAccelerator::V4L2DecodeSurface>& 378 const scoped_refptr<V4L2SliceVideoDecodeAccelerator::V4L2DecodeSurface>&
331 dec_surface); 379 dec_surface);
332 380
333 V4L2H264Picture* AsV4L2H264Picture() override { return this; } 381 V4L2H264Picture* AsV4L2H264Picture() override { return this; }
334 scoped_refptr<V4L2SliceVideoDecodeAccelerator::V4L2DecodeSurface> 382 scoped_refptr<V4L2SliceVideoDecodeAccelerator::V4L2DecodeSurface>
335 dec_surface() { 383 dec_surface() {
336 return dec_surface_; 384 return dec_surface_;
337 } 385 }
338 386
339 private: 387 private:
340 ~V4L2H264Picture() override; 388 ~V4L2H264Picture() override;
341 389
342 scoped_refptr<V4L2SliceVideoDecodeAccelerator::V4L2DecodeSurface> 390 scoped_refptr<V4L2SliceVideoDecodeAccelerator::V4L2DecodeSurface>
343 dec_surface_; 391 dec_surface_;
344 392
345 DISALLOW_COPY_AND_ASSIGN(V4L2H264Picture); 393 DISALLOW_COPY_AND_ASSIGN(V4L2H264Picture);
346 }; 394 };
347 395
348 V4L2H264Picture::V4L2H264Picture( 396 V4L2H264Picture::V4L2H264Picture(
349 const scoped_refptr<V4L2SliceVideoDecodeAccelerator::V4L2DecodeSurface>& 397 const scoped_refptr<V4L2SliceVideoDecodeAccelerator::V4L2DecodeSurface>&
350 dec_surface) 398 dec_surface)
351 : dec_surface_(dec_surface) {} 399 : dec_surface_(dec_surface) {}
352 400
353 V4L2H264Picture::~V4L2H264Picture() {} 401 V4L2H264Picture::~V4L2H264Picture() {}
354 402
355 class V4L2VP8Picture : public VP8Picture { 403 class V4L2VP8Picture : public VP8Picture {
356 public: 404 public:
357 V4L2VP8Picture( 405 explicit V4L2VP8Picture(
358 const scoped_refptr<V4L2SliceVideoDecodeAccelerator::V4L2DecodeSurface>& 406 const scoped_refptr<V4L2SliceVideoDecodeAccelerator::V4L2DecodeSurface>&
359 dec_surface); 407 dec_surface);
360 408
361 V4L2VP8Picture* AsV4L2VP8Picture() override { return this; } 409 V4L2VP8Picture* AsV4L2VP8Picture() override { return this; }
362 scoped_refptr<V4L2SliceVideoDecodeAccelerator::V4L2DecodeSurface> 410 scoped_refptr<V4L2SliceVideoDecodeAccelerator::V4L2DecodeSurface>
363 dec_surface() { 411 dec_surface() {
364 return dec_surface_; 412 return dec_surface_;
365 } 413 }
366 414
367 private: 415 private:
368 ~V4L2VP8Picture() override; 416 ~V4L2VP8Picture() override;
369 417
370 scoped_refptr<V4L2SliceVideoDecodeAccelerator::V4L2DecodeSurface> 418 scoped_refptr<V4L2SliceVideoDecodeAccelerator::V4L2DecodeSurface>
371 dec_surface_; 419 dec_surface_;
372 420
373 DISALLOW_COPY_AND_ASSIGN(V4L2VP8Picture); 421 DISALLOW_COPY_AND_ASSIGN(V4L2VP8Picture);
374 }; 422 };
375 423
376 V4L2VP8Picture::V4L2VP8Picture( 424 V4L2VP8Picture::V4L2VP8Picture(
377 const scoped_refptr<V4L2SliceVideoDecodeAccelerator::V4L2DecodeSurface>& 425 const scoped_refptr<V4L2SliceVideoDecodeAccelerator::V4L2DecodeSurface>&
378 dec_surface) 426 dec_surface)
379 : dec_surface_(dec_surface) {} 427 : dec_surface_(dec_surface) {}
380 428
381 V4L2VP8Picture::~V4L2VP8Picture() {} 429 V4L2VP8Picture::~V4L2VP8Picture() {}
382 430
431 class V4L2VP9Picture : public VP9Picture {
432 public:
433 explicit V4L2VP9Picture(
434 const scoped_refptr<V4L2SliceVideoDecodeAccelerator::V4L2DecodeSurface>&
435 dec_surface);
436
437 V4L2VP9Picture* AsV4L2VP9Picture() override { return this; }
438 scoped_refptr<V4L2SliceVideoDecodeAccelerator::V4L2DecodeSurface>
439 dec_surface() {
440 return dec_surface_;
441 }
442
443 private:
444 ~V4L2VP9Picture() override;
445
446 scoped_refptr<V4L2SliceVideoDecodeAccelerator::V4L2DecodeSurface>
447 dec_surface_;
448
449 DISALLOW_COPY_AND_ASSIGN(V4L2VP9Picture);
450 };
451
452 V4L2VP9Picture::V4L2VP9Picture(
453 const scoped_refptr<V4L2SliceVideoDecodeAccelerator::V4L2DecodeSurface>&
454 dec_surface)
455 : dec_surface_(dec_surface) {}
456
457 V4L2VP9Picture::~V4L2VP9Picture() {}
458
383 V4L2SliceVideoDecodeAccelerator::V4L2SliceVideoDecodeAccelerator( 459 V4L2SliceVideoDecodeAccelerator::V4L2SliceVideoDecodeAccelerator(
384 const scoped_refptr<V4L2Device>& device, 460 const scoped_refptr<V4L2Device>& device,
385 EGLDisplay egl_display, 461 EGLDisplay egl_display,
386 const GetGLContextCallback& get_gl_context_cb, 462 const GetGLContextCallback& get_gl_context_cb,
387 const MakeGLContextCurrentCallback& make_context_current_cb) 463 const MakeGLContextCurrentCallback& make_context_current_cb)
388 : input_planes_count_(0), 464 : input_planes_count_(0),
389 output_planes_count_(0), 465 output_planes_count_(0),
390 child_task_runner_(base::ThreadTaskRunnerHandle::Get()), 466 child_task_runner_(base::ThreadTaskRunnerHandle::Get()),
391 device_(device), 467 device_(device),
392 decoder_thread_("V4L2SliceVideoDecodeAcceleratorThread"), 468 decoder_thread_("V4L2SliceVideoDecodeAcceleratorThread"),
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
473 549
474 video_profile_ = config.profile; 550 video_profile_ = config.profile;
475 551
476 if (video_profile_ >= H264PROFILE_MIN && video_profile_ <= H264PROFILE_MAX) { 552 if (video_profile_ >= H264PROFILE_MIN && video_profile_ <= H264PROFILE_MAX) {
477 h264_accelerator_.reset(new V4L2H264Accelerator(this)); 553 h264_accelerator_.reset(new V4L2H264Accelerator(this));
478 decoder_.reset(new H264Decoder(h264_accelerator_.get())); 554 decoder_.reset(new H264Decoder(h264_accelerator_.get()));
479 } else if (video_profile_ >= VP8PROFILE_MIN && 555 } else if (video_profile_ >= VP8PROFILE_MIN &&
480 video_profile_ <= VP8PROFILE_MAX) { 556 video_profile_ <= VP8PROFILE_MAX) {
481 vp8_accelerator_.reset(new V4L2VP8Accelerator(this)); 557 vp8_accelerator_.reset(new V4L2VP8Accelerator(this));
482 decoder_.reset(new VP8Decoder(vp8_accelerator_.get())); 558 decoder_.reset(new VP8Decoder(vp8_accelerator_.get()));
559 } else if (video_profile_ >= VP9PROFILE_MIN &&
560 video_profile_ <= VP9PROFILE_MAX) {
561 vp9_accelerator_.reset(new V4L2VP9Accelerator(this));
562 decoder_.reset(new VP9Decoder(vp9_accelerator_.get()));
483 } else { 563 } else {
484 NOTREACHED() << "Unsupported profile " << video_profile_; 564 NOTREACHED() << "Unsupported profile " << video_profile_;
485 return false; 565 return false;
486 } 566 }
487 567
488 // TODO(posciak): This needs to be queried once supported. 568 // TODO(posciak): This needs to be queried once supported.
489 input_planes_count_ = 1; 569 input_planes_count_ = 1;
490 output_planes_count_ = 1; 570 output_planes_count_ = 1;
491 571
492 if (egl_display_ == EGL_NO_DISPLAY) { 572 if (egl_display_ == EGL_NO_DISPLAY) {
(...skipping 483 matching lines...) Expand 10 before | Expand all | Expand 10 after
976 } 1056 }
977 1057
978 it->second->SetDecoded(); 1058 it->second->SetDecoded();
979 surfaces_at_device_.erase(it); 1059 surfaces_at_device_.erase(it);
980 } 1060 }
981 1061
982 // A frame was decoded, see if we can output it. 1062 // A frame was decoded, see if we can output it.
983 TryOutputSurfaces(); 1063 TryOutputSurfaces();
984 1064
985 ProcessPendingEventsIfNeeded(); 1065 ProcessPendingEventsIfNeeded();
1066 ScheduleDecodeBufferTaskIfNeeded();
986 } 1067 }
987 1068
988 void V4L2SliceVideoDecodeAccelerator::NewEventPending() { 1069 void V4L2SliceVideoDecodeAccelerator::NewEventPending() {
989 // Switch to event processing mode if we are decoding. Otherwise we are either 1070 // Switch to event processing mode if we are decoding. Otherwise we are either
990 // already in it, or we will potentially switch to it later, after finishing 1071 // already in it, or we will potentially switch to it later, after finishing
991 // other tasks. 1072 // other tasks.
992 if (state_ == kDecoding) 1073 if (state_ == kDecoding)
993 state_ = kIdle; 1074 state_ = kIdle;
994 1075
995 ProcessPendingEventsIfNeeded(); 1076 ProcessPendingEventsIfNeeded();
(...skipping 351 matching lines...) Expand 10 before | Expand all | Expand 10 after
1347 if (!TrySetNewBistreamBuffer()) 1428 if (!TrySetNewBistreamBuffer())
1348 return; 1429 return;
1349 1430
1350 break; 1431 break;
1351 1432
1352 case AcceleratedVideoDecoder::kRanOutOfSurfaces: 1433 case AcceleratedVideoDecoder::kRanOutOfSurfaces:
1353 // No more surfaces for the decoder, we'll come back once we have more. 1434 // No more surfaces for the decoder, we'll come back once we have more.
1354 DVLOGF(4) << "Ran out of surfaces"; 1435 DVLOGF(4) << "Ran out of surfaces";
1355 return; 1436 return;
1356 1437
1438 case AcceleratedVideoDecoder::kNeedContextUpdate:
1439 DVLOGF(4) << "Awaiting context update";
1440 return;
1441
1357 case AcceleratedVideoDecoder::kDecodeError: 1442 case AcceleratedVideoDecoder::kDecodeError:
1358 DVLOGF(1) << "Error decoding stream"; 1443 DVLOGF(1) << "Error decoding stream";
1359 NOTIFY_ERROR(PLATFORM_FAILURE); 1444 NOTIFY_ERROR(PLATFORM_FAILURE);
1360 return; 1445 return;
1361 } 1446 }
1362 } 1447 }
1363 } 1448 }
1364 1449
1365 void V4L2SliceVideoDecodeAccelerator::InitiateSurfaceSetChange() { 1450 void V4L2SliceVideoDecodeAccelerator::InitiateSurfaceSetChange() {
1366 DVLOGF(2); 1451 DVLOGF(2);
(...skipping 741 matching lines...) Expand 10 before | Expand all | Expand 10 after
2108 V4L2_H264_SPS_FLAG_QPPRIME_Y_ZERO_TRANSFORM_BYPASS); 2193 V4L2_H264_SPS_FLAG_QPPRIME_Y_ZERO_TRANSFORM_BYPASS);
2109 SET_V4L2_SPS_FLAG_IF(delta_pic_order_always_zero_flag, 2194 SET_V4L2_SPS_FLAG_IF(delta_pic_order_always_zero_flag,
2110 V4L2_H264_SPS_FLAG_DELTA_PIC_ORDER_ALWAYS_ZERO); 2195 V4L2_H264_SPS_FLAG_DELTA_PIC_ORDER_ALWAYS_ZERO);
2111 SET_V4L2_SPS_FLAG_IF(gaps_in_frame_num_value_allowed_flag, 2196 SET_V4L2_SPS_FLAG_IF(gaps_in_frame_num_value_allowed_flag,
2112 V4L2_H264_SPS_FLAG_GAPS_IN_FRAME_NUM_VALUE_ALLOWED); 2197 V4L2_H264_SPS_FLAG_GAPS_IN_FRAME_NUM_VALUE_ALLOWED);
2113 SET_V4L2_SPS_FLAG_IF(frame_mbs_only_flag, V4L2_H264_SPS_FLAG_FRAME_MBS_ONLY); 2198 SET_V4L2_SPS_FLAG_IF(frame_mbs_only_flag, V4L2_H264_SPS_FLAG_FRAME_MBS_ONLY);
2114 SET_V4L2_SPS_FLAG_IF(mb_adaptive_frame_field_flag, 2199 SET_V4L2_SPS_FLAG_IF(mb_adaptive_frame_field_flag,
2115 V4L2_H264_SPS_FLAG_MB_ADAPTIVE_FRAME_FIELD); 2200 V4L2_H264_SPS_FLAG_MB_ADAPTIVE_FRAME_FIELD);
2116 SET_V4L2_SPS_FLAG_IF(direct_8x8_inference_flag, 2201 SET_V4L2_SPS_FLAG_IF(direct_8x8_inference_flag,
2117 V4L2_H264_SPS_FLAG_DIRECT_8X8_INFERENCE); 2202 V4L2_H264_SPS_FLAG_DIRECT_8X8_INFERENCE);
2118 #undef SET_FLAG 2203 #undef SET_V4L2_SPS_FLAG_IF
2119 memset(&ctrl, 0, sizeof(ctrl)); 2204 memset(&ctrl, 0, sizeof(ctrl));
2120 ctrl.id = V4L2_CID_MPEG_VIDEO_H264_SPS; 2205 ctrl.id = V4L2_CID_MPEG_VIDEO_H264_SPS;
2121 ctrl.size = sizeof(v4l2_sps); 2206 ctrl.size = sizeof(v4l2_sps);
2122 ctrl.p_h264_sps = &v4l2_sps; 2207 ctrl.p_h264_sps = &v4l2_sps;
2123 ctrls.push_back(ctrl); 2208 ctrls.push_back(ctrl);
2124 2209
2125 struct v4l2_ctrl_h264_pps v4l2_pps; 2210 struct v4l2_ctrl_h264_pps v4l2_pps;
2126 memset(&v4l2_pps, 0, sizeof(v4l2_pps)); 2211 memset(&v4l2_pps, 0, sizeof(v4l2_pps));
2127 #define PPS_TO_V4L2PPS(a) v4l2_pps.a = pps->a 2212 #define PPS_TO_V4L2PPS(a) v4l2_pps.a = pps->a
2128 PPS_TO_V4L2PPS(pic_parameter_set_id); 2213 PPS_TO_V4L2PPS(pic_parameter_set_id);
(...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after
2350 2435
2351 memcpy(static_cast<uint8_t*>(input_record.address) + input_record.bytes_used, 2436 memcpy(static_cast<uint8_t*>(input_record.address) + input_record.bytes_used,
2352 data, size); 2437 data, size);
2353 input_record.bytes_used += size; 2438 input_record.bytes_used += size;
2354 2439
2355 return true; 2440 return true;
2356 } 2441 }
2357 2442
2358 bool V4L2SliceVideoDecodeAccelerator::SubmitExtControls( 2443 bool V4L2SliceVideoDecodeAccelerator::SubmitExtControls(
2359 struct v4l2_ext_controls* ext_ctrls) { 2444 struct v4l2_ext_controls* ext_ctrls) {
2445 DCHECK(decoder_thread_task_runner_->BelongsToCurrentThread());
2360 DCHECK_GT(ext_ctrls->config_store, 0u); 2446 DCHECK_GT(ext_ctrls->config_store, 0u);
2361 IOCTL_OR_ERROR_RETURN_FALSE(VIDIOC_S_EXT_CTRLS, ext_ctrls); 2447 IOCTL_OR_ERROR_RETURN_FALSE(VIDIOC_S_EXT_CTRLS, ext_ctrls);
2362 return true; 2448 return true;
2363 } 2449 }
2364 2450
2451 bool V4L2SliceVideoDecodeAccelerator::GetExtControls(
2452 struct v4l2_ext_controls* ext_ctrls) {
2453 DCHECK(decoder_thread_task_runner_->BelongsToCurrentThread());
2454 DCHECK_GT(ext_ctrls->config_store, 0u);
2455 IOCTL_OR_ERROR_RETURN_FALSE(VIDIOC_G_EXT_CTRLS, ext_ctrls);
2456 return true;
2457 }
2458
2459 bool V4L2SliceVideoDecodeAccelerator::IsCtrlExposed(uint32_t ctrl_id) {
2460 struct v4l2_queryctrl query_ctrl;
2461 memset(&query_ctrl, 0, sizeof(query_ctrl));
2462 query_ctrl.id = ctrl_id;
2463
2464 return (device_->Ioctl(VIDIOC_QUERYCTRL, &query_ctrl) == 0);
2465 }
2466
2365 bool V4L2SliceVideoDecodeAccelerator::V4L2H264Accelerator::SubmitDecode( 2467 bool V4L2SliceVideoDecodeAccelerator::V4L2H264Accelerator::SubmitDecode(
2366 const scoped_refptr<H264Picture>& pic) { 2468 const scoped_refptr<H264Picture>& pic) {
2367 scoped_refptr<V4L2DecodeSurface> dec_surface = 2469 scoped_refptr<V4L2DecodeSurface> dec_surface =
2368 H264PictureToV4L2DecodeSurface(pic); 2470 H264PictureToV4L2DecodeSurface(pic);
2369 2471
2370 v4l2_decode_param_.num_slices = num_slices_; 2472 v4l2_decode_param_.num_slices = num_slices_;
2371 v4l2_decode_param_.idr_pic_flag = pic->idr; 2473 v4l2_decode_param_.idr_pic_flag = pic->idr;
2372 v4l2_decode_param_.top_field_order_cnt = pic->top_field_order_cnt; 2474 v4l2_decode_param_.top_field_order_cnt = pic->top_field_order_cnt;
2373 v4l2_decode_param_.bottom_field_order_cnt = pic->bottom_field_order_cnt; 2475 v4l2_decode_param_.bottom_field_order_cnt = pic->bottom_field_order_cnt;
2374 2476
(...skipping 10 matching lines...) Expand all
2385 ctrl.id = V4L2_CID_MPEG_VIDEO_H264_DECODE_PARAM; 2487 ctrl.id = V4L2_CID_MPEG_VIDEO_H264_DECODE_PARAM;
2386 ctrl.size = sizeof(v4l2_decode_param_); 2488 ctrl.size = sizeof(v4l2_decode_param_);
2387 ctrl.p_h264_decode_param = &v4l2_decode_param_; 2489 ctrl.p_h264_decode_param = &v4l2_decode_param_;
2388 ctrls.push_back(ctrl); 2490 ctrls.push_back(ctrl);
2389 2491
2390 struct v4l2_ext_controls ext_ctrls; 2492 struct v4l2_ext_controls ext_ctrls;
2391 memset(&ext_ctrls, 0, sizeof(ext_ctrls)); 2493 memset(&ext_ctrls, 0, sizeof(ext_ctrls));
2392 ext_ctrls.count = ctrls.size(); 2494 ext_ctrls.count = ctrls.size();
2393 ext_ctrls.controls = &ctrls[0]; 2495 ext_ctrls.controls = &ctrls[0];
2394 ext_ctrls.config_store = dec_surface->config_store(); 2496 ext_ctrls.config_store = dec_surface->config_store();
2395 v4l2_dec_->SubmitExtControls(&ext_ctrls); 2497 if (!v4l2_dec_->SubmitExtControls(&ext_ctrls))
2498 return false;
2396 2499
2397 Reset(); 2500 Reset();
2398 2501
2399 v4l2_dec_->DecodeSurface(dec_surface); 2502 v4l2_dec_->DecodeSurface(dec_surface);
2400 return true; 2503 return true;
2401 } 2504 }
2402 2505
2403 bool V4L2SliceVideoDecodeAccelerator::V4L2H264Accelerator::OutputPicture( 2506 bool V4L2SliceVideoDecodeAccelerator::V4L2H264Accelerator::OutputPicture(
2404 const scoped_refptr<H264Picture>& pic) { 2507 const scoped_refptr<H264Picture>& pic) {
2405 scoped_refptr<V4L2DecodeSurface> dec_surface = 2508 scoped_refptr<V4L2DecodeSurface> dec_surface =
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
2494 const Vp8QuantizationHeader& vp8_quant_hdr, 2597 const Vp8QuantizationHeader& vp8_quant_hdr,
2495 struct v4l2_vp8_quantization_hdr* v4l2_quant_hdr) { 2598 struct v4l2_vp8_quantization_hdr* v4l2_quant_hdr) {
2496 v4l2_quant_hdr->y_ac_qi = vp8_quant_hdr.y_ac_qi; 2599 v4l2_quant_hdr->y_ac_qi = vp8_quant_hdr.y_ac_qi;
2497 v4l2_quant_hdr->y_dc_delta = vp8_quant_hdr.y_dc_delta; 2600 v4l2_quant_hdr->y_dc_delta = vp8_quant_hdr.y_dc_delta;
2498 v4l2_quant_hdr->y2_dc_delta = vp8_quant_hdr.y2_dc_delta; 2601 v4l2_quant_hdr->y2_dc_delta = vp8_quant_hdr.y2_dc_delta;
2499 v4l2_quant_hdr->y2_ac_delta = vp8_quant_hdr.y2_ac_delta; 2602 v4l2_quant_hdr->y2_ac_delta = vp8_quant_hdr.y2_ac_delta;
2500 v4l2_quant_hdr->uv_dc_delta = vp8_quant_hdr.uv_dc_delta; 2603 v4l2_quant_hdr->uv_dc_delta = vp8_quant_hdr.uv_dc_delta;
2501 v4l2_quant_hdr->uv_ac_delta = vp8_quant_hdr.uv_ac_delta; 2604 v4l2_quant_hdr->uv_ac_delta = vp8_quant_hdr.uv_ac_delta;
2502 } 2605 }
2503 2606
2504 static void FillV4L2EntropyHeader( 2607 static void FillV4L2Vp8EntropyHeader(
2505 const Vp8EntropyHeader& vp8_entropy_hdr, 2608 const Vp8EntropyHeader& vp8_entropy_hdr,
2506 struct v4l2_vp8_entropy_hdr* v4l2_entropy_hdr) { 2609 struct v4l2_vp8_entropy_hdr* v4l2_entropy_hdr) {
2507 ARRAY_MEMCPY_CHECKED(v4l2_entropy_hdr->coeff_probs, 2610 ARRAY_MEMCPY_CHECKED(v4l2_entropy_hdr->coeff_probs,
2508 vp8_entropy_hdr.coeff_probs); 2611 vp8_entropy_hdr.coeff_probs);
2509 ARRAY_MEMCPY_CHECKED(v4l2_entropy_hdr->y_mode_probs, 2612 ARRAY_MEMCPY_CHECKED(v4l2_entropy_hdr->y_mode_probs,
2510 vp8_entropy_hdr.y_mode_probs); 2613 vp8_entropy_hdr.y_mode_probs);
2511 ARRAY_MEMCPY_CHECKED(v4l2_entropy_hdr->uv_mode_probs, 2614 ARRAY_MEMCPY_CHECKED(v4l2_entropy_hdr->uv_mode_probs,
2512 vp8_entropy_hdr.uv_mode_probs); 2615 vp8_entropy_hdr.uv_mode_probs);
2513 ARRAY_MEMCPY_CHECKED(v4l2_entropy_hdr->mv_probs, vp8_entropy_hdr.mv_probs); 2616 ARRAY_MEMCPY_CHECKED(v4l2_entropy_hdr->mv_probs, vp8_entropy_hdr.mv_probs);
2514 } 2617 }
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
2550 #undef SET_V4L2_FRM_HDR_FLAG_IF 2653 #undef SET_V4L2_FRM_HDR_FLAG_IF
2551 2654
2552 FillV4L2SegmentationHeader(frame_hdr->segmentation_hdr, 2655 FillV4L2SegmentationHeader(frame_hdr->segmentation_hdr,
2553 &v4l2_frame_hdr.sgmnt_hdr); 2656 &v4l2_frame_hdr.sgmnt_hdr);
2554 2657
2555 FillV4L2LoopfilterHeader(frame_hdr->loopfilter_hdr, &v4l2_frame_hdr.lf_hdr); 2658 FillV4L2LoopfilterHeader(frame_hdr->loopfilter_hdr, &v4l2_frame_hdr.lf_hdr);
2556 2659
2557 FillV4L2QuantizationHeader(frame_hdr->quantization_hdr, 2660 FillV4L2QuantizationHeader(frame_hdr->quantization_hdr,
2558 &v4l2_frame_hdr.quant_hdr); 2661 &v4l2_frame_hdr.quant_hdr);
2559 2662
2560 FillV4L2EntropyHeader(frame_hdr->entropy_hdr, &v4l2_frame_hdr.entropy_hdr); 2663 FillV4L2Vp8EntropyHeader(frame_hdr->entropy_hdr, &v4l2_frame_hdr.entropy_hdr);
2561 2664
2562 v4l2_frame_hdr.first_part_size = 2665 v4l2_frame_hdr.first_part_size =
2563 base::checked_cast<__u32>(frame_hdr->first_part_size); 2666 base::checked_cast<__u32>(frame_hdr->first_part_size);
2564 v4l2_frame_hdr.first_part_offset = 2667 v4l2_frame_hdr.first_part_offset =
2565 base::checked_cast<__u32>(frame_hdr->first_part_offset); 2668 base::checked_cast<__u32>(frame_hdr->first_part_offset);
2566 v4l2_frame_hdr.macroblock_bit_offset = 2669 v4l2_frame_hdr.macroblock_bit_offset =
2567 base::checked_cast<__u32>(frame_hdr->macroblock_bit_offset); 2670 base::checked_cast<__u32>(frame_hdr->macroblock_bit_offset);
2568 v4l2_frame_hdr.num_dct_parts = frame_hdr->num_of_dct_partitions; 2671 v4l2_frame_hdr.num_dct_parts = frame_hdr->num_of_dct_partitions;
2569 2672
2570 static_assert(arraysize(v4l2_frame_hdr.dct_part_sizes) == 2673 static_assert(arraysize(v4l2_frame_hdr.dct_part_sizes) ==
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
2641 } 2744 }
2642 2745
2643 scoped_refptr<V4L2SliceVideoDecodeAccelerator::V4L2DecodeSurface> 2746 scoped_refptr<V4L2SliceVideoDecodeAccelerator::V4L2DecodeSurface>
2644 V4L2SliceVideoDecodeAccelerator::V4L2VP8Accelerator:: 2747 V4L2SliceVideoDecodeAccelerator::V4L2VP8Accelerator::
2645 VP8PictureToV4L2DecodeSurface(const scoped_refptr<VP8Picture>& pic) { 2748 VP8PictureToV4L2DecodeSurface(const scoped_refptr<VP8Picture>& pic) {
2646 V4L2VP8Picture* v4l2_pic = pic->AsV4L2VP8Picture(); 2749 V4L2VP8Picture* v4l2_pic = pic->AsV4L2VP8Picture();
2647 CHECK(v4l2_pic); 2750 CHECK(v4l2_pic);
2648 return v4l2_pic->dec_surface(); 2751 return v4l2_pic->dec_surface();
2649 } 2752 }
2650 2753
2754 V4L2SliceVideoDecodeAccelerator::V4L2VP9Accelerator::V4L2VP9Accelerator(
2755 V4L2SliceVideoDecodeAccelerator* v4l2_dec)
2756 : v4l2_dec_(v4l2_dec) {
2757 DCHECK(v4l2_dec_);
2758
2759 device_needs_frame_context_ =
2760 v4l2_dec_->IsCtrlExposed(V4L2_CID_MPEG_VIDEO_VP9_ENTROPY);
2761 DVLOG_IF(1, device_needs_frame_context_)
2762 << "Device requires frame context parsing";
2763 }
2764
2765 V4L2SliceVideoDecodeAccelerator::V4L2VP9Accelerator::~V4L2VP9Accelerator() {}
2766
2767 scoped_refptr<VP9Picture>
2768 V4L2SliceVideoDecodeAccelerator::V4L2VP9Accelerator::CreateVP9Picture() {
2769 scoped_refptr<V4L2DecodeSurface> dec_surface = v4l2_dec_->CreateSurface();
2770 if (!dec_surface)
2771 return nullptr;
2772
2773 return new V4L2VP9Picture(dec_surface);
2774 }
2775
2776 static void FillV4L2VP9LoopFilterParams(
2777 const Vp9LoopFilterParams& vp9_lf_params,
2778 struct v4l2_vp9_loop_filter_params* v4l2_lf_params) {
2779 #define SET_LF_PARAMS_FLAG_IF(cond, flag) \
2780 v4l2_lf_params->flags |= ((vp9_lf_params.cond) ? (flag) : 0)
2781 SET_LF_PARAMS_FLAG_IF(delta_enabled, V4L2_VP9_LOOP_FLTR_FLAG_DELTA_ENABLED);
2782 SET_LF_PARAMS_FLAG_IF(delta_update, V4L2_VP9_LOOP_FLTR_FLAG_DELTA_UPDATE);
2783 #undef SET_LF_PARAMS_FLAG_IF
2784
2785 v4l2_lf_params->level = vp9_lf_params.level;
2786 v4l2_lf_params->sharpness = vp9_lf_params.sharpness;
2787
2788 ARRAY_MEMCPY_CHECKED(v4l2_lf_params->deltas, vp9_lf_params.ref_deltas);
2789 ARRAY_MEMCPY_CHECKED(v4l2_lf_params->mode_deltas, vp9_lf_params.mode_deltas);
2790 ARRAY_MEMCPY_CHECKED(v4l2_lf_params->lvl_lookup, vp9_lf_params.lvl);
2791 }
2792
2793 static void FillV4L2VP9QuantizationParams(
2794 const Vp9QuantizationParams& vp9_quant_params,
2795 struct v4l2_vp9_quantization_params* v4l2_q_params) {
2796 #define SET_Q_PARAMS_FLAG_IF(cond, flag) \
2797 v4l2_q_params->flags |= ((vp9_quant_params.cond) ? (flag) : 0)
2798 SET_Q_PARAMS_FLAG_IF(IsLossless(), V4L2_VP9_QUANT_PARAMS_FLAG_LOSSLESS);
2799 #undef SET_Q_PARAMS_FLAG_IF
2800
2801 #define Q_PARAMS_TO_V4L2_Q_PARAMS(a) v4l2_q_params->a = vp9_quant_params.a
2802 Q_PARAMS_TO_V4L2_Q_PARAMS(base_q_idx);
2803 Q_PARAMS_TO_V4L2_Q_PARAMS(delta_q_y_dc);
2804 Q_PARAMS_TO_V4L2_Q_PARAMS(delta_q_uv_dc);
2805 Q_PARAMS_TO_V4L2_Q_PARAMS(delta_q_uv_ac);
2806 #undef Q_PARAMS_TO_V4L2_Q_PARAMS
2807 }
2808
2809 static void FillV4L2VP9SegmentationParams(
2810 const Vp9SegmentationParams& vp9_segm_params,
2811 struct v4l2_vp9_segmentation_params* v4l2_segm_params) {
2812 #define SET_SEG_PARAMS_FLAG_IF(cond, flag) \
2813 v4l2_segm_params->flags |= ((vp9_segm_params.cond) ? (flag) : 0)
2814 SET_SEG_PARAMS_FLAG_IF(enabled, V4L2_VP9_SGMNT_PARAM_FLAG_ENABLED);
2815 SET_SEG_PARAMS_FLAG_IF(update_map, V4L2_VP9_SGMNT_PARAM_FLAG_UPDATE_MAP);
2816 SET_SEG_PARAMS_FLAG_IF(temporal_update,
2817 V4L2_VP9_SGMNT_PARAM_FLAG_TEMPORAL_UPDATE);
2818 SET_SEG_PARAMS_FLAG_IF(update_data, V4L2_VP9_SGMNT_PARAM_FLAG_UPDATE_DATA);
2819 SET_SEG_PARAMS_FLAG_IF(abs_or_delta_update,
2820 V4L2_VP9_SGMNT_PARAM_FLAG_ABS_OR_DELTA_UPDATE);
2821 #undef SET_SEG_PARAMS_FLAG_IF
2822
2823 ARRAY_MEMCPY_CHECKED(v4l2_segm_params->tree_probs,
2824 vp9_segm_params.tree_probs);
2825 ARRAY_MEMCPY_CHECKED(v4l2_segm_params->pred_probs,
2826 vp9_segm_params.pred_probs);
2827 ARRAY_MEMCPY_CHECKED(v4l2_segm_params->feature_data,
2828 vp9_segm_params.feature_data);
2829
2830 static_assert(arraysize(v4l2_segm_params->feature_enabled) ==
2831 arraysize(vp9_segm_params.feature_enabled) &&
2832 arraysize(v4l2_segm_params->feature_enabled[0]) ==
2833 arraysize(vp9_segm_params.feature_enabled[0]),
2834 "feature_enabled arrays must be of same size");
2835 for (size_t i = 0; i < arraysize(v4l2_segm_params->feature_enabled); ++i) {
2836 for (size_t j = 0; j < arraysize(v4l2_segm_params->feature_enabled[i]);
2837 ++j) {
2838 v4l2_segm_params->feature_enabled[i][j] =
2839 vp9_segm_params.feature_enabled[i][j];
2840 }
2841 }
2842 }
2843
2844 static void FillV4L2Vp9EntropyContext(
2845 const Vp9FrameContext& vp9_frame_ctx,
2846 struct v4l2_vp9_entropy_ctx* v4l2_entropy_ctx) {
2847 #define ARRAY_MEMCPY_CHECKED_FRM_CTX_TO_V4L2_ENTR(a) \
2848 ARRAY_MEMCPY_CHECKED(v4l2_entropy_ctx->a, vp9_frame_ctx.a)
2849 ARRAY_MEMCPY_CHECKED_FRM_CTX_TO_V4L2_ENTR(tx_probs_8x8);
2850 ARRAY_MEMCPY_CHECKED_FRM_CTX_TO_V4L2_ENTR(tx_probs_16x16);
2851 ARRAY_MEMCPY_CHECKED_FRM_CTX_TO_V4L2_ENTR(tx_probs_32x32);
2852
2853 ARRAY_MEMCPY_CHECKED_FRM_CTX_TO_V4L2_ENTR(coef_probs);
2854 ARRAY_MEMCPY_CHECKED_FRM_CTX_TO_V4L2_ENTR(skip_prob);
2855 ARRAY_MEMCPY_CHECKED_FRM_CTX_TO_V4L2_ENTR(inter_mode_probs);
2856 ARRAY_MEMCPY_CHECKED_FRM_CTX_TO_V4L2_ENTR(interp_filter_probs);
2857 ARRAY_MEMCPY_CHECKED_FRM_CTX_TO_V4L2_ENTR(is_inter_prob);
2858
2859 ARRAY_MEMCPY_CHECKED_FRM_CTX_TO_V4L2_ENTR(comp_mode_prob);
2860 ARRAY_MEMCPY_CHECKED_FRM_CTX_TO_V4L2_ENTR(single_ref_prob);
2861 ARRAY_MEMCPY_CHECKED_FRM_CTX_TO_V4L2_ENTR(comp_ref_prob);
2862
2863 ARRAY_MEMCPY_CHECKED_FRM_CTX_TO_V4L2_ENTR(y_mode_probs);
2864 ARRAY_MEMCPY_CHECKED_FRM_CTX_TO_V4L2_ENTR(uv_mode_probs);
2865
2866 ARRAY_MEMCPY_CHECKED_FRM_CTX_TO_V4L2_ENTR(partition_probs);
2867
2868 ARRAY_MEMCPY_CHECKED_FRM_CTX_TO_V4L2_ENTR(mv_joint_probs);
2869 ARRAY_MEMCPY_CHECKED_FRM_CTX_TO_V4L2_ENTR(mv_sign_prob);
2870 ARRAY_MEMCPY_CHECKED_FRM_CTX_TO_V4L2_ENTR(mv_class_probs);
2871 ARRAY_MEMCPY_CHECKED_FRM_CTX_TO_V4L2_ENTR(mv_class0_bit_prob);
2872 ARRAY_MEMCPY_CHECKED_FRM_CTX_TO_V4L2_ENTR(mv_bits_prob);
2873 ARRAY_MEMCPY_CHECKED_FRM_CTX_TO_V4L2_ENTR(mv_class0_fr_probs);
2874 ARRAY_MEMCPY_CHECKED_FRM_CTX_TO_V4L2_ENTR(mv_fr_probs);
2875 ARRAY_MEMCPY_CHECKED_FRM_CTX_TO_V4L2_ENTR(mv_class0_hp_prob);
2876 ARRAY_MEMCPY_CHECKED_FRM_CTX_TO_V4L2_ENTR(mv_hp_prob);
2877 #undef ARRAY_MEMCPY_CHECKED_FRM_CTX_TO_V4L2_ENTR
2878 }
2879
2880 bool V4L2SliceVideoDecodeAccelerator::V4L2VP9Accelerator::SubmitDecode(
2881 const scoped_refptr<VP9Picture>& pic,
2882 const Vp9SegmentationParams& segm_params,
2883 const Vp9LoopFilterParams& lf_params,
2884 const std::vector<scoped_refptr<VP9Picture>>& ref_pictures,
2885 const base::Closure& done_cb) {
2886 const Vp9FrameHeader* frame_hdr = pic->frame_hdr.get();
2887 DCHECK(frame_hdr);
2888
2889 struct v4l2_ctrl_vp9_frame_hdr v4l2_frame_hdr;
2890 memset(&v4l2_frame_hdr, 0, sizeof(v4l2_frame_hdr));
2891
2892 #define FHDR_TO_V4L2_FHDR(a) v4l2_frame_hdr.a = frame_hdr->a
2893 FHDR_TO_V4L2_FHDR(profile);
2894 FHDR_TO_V4L2_FHDR(frame_type);
2895
2896 FHDR_TO_V4L2_FHDR(bit_depth);
2897 FHDR_TO_V4L2_FHDR(color_range);
2898 FHDR_TO_V4L2_FHDR(subsampling_x);
2899 FHDR_TO_V4L2_FHDR(subsampling_y);
2900
2901 FHDR_TO_V4L2_FHDR(frame_width);
2902 FHDR_TO_V4L2_FHDR(frame_height);
2903 FHDR_TO_V4L2_FHDR(render_width);
2904 FHDR_TO_V4L2_FHDR(render_height);
2905
2906 FHDR_TO_V4L2_FHDR(reset_frame_context);
2907
2908 FHDR_TO_V4L2_FHDR(interpolation_filter);
2909 FHDR_TO_V4L2_FHDR(frame_context_idx);
2910
2911 FHDR_TO_V4L2_FHDR(tile_cols_log2);
2912 FHDR_TO_V4L2_FHDR(tile_rows_log2);
2913
2914 FHDR_TO_V4L2_FHDR(header_size_in_bytes);
2915 #undef FHDR_TO_V4L2_FHDR
2916 v4l2_frame_hdr.color_space = static_cast<uint8_t>(frame_hdr->color_space);
2917
2918 FillV4L2VP9QuantizationParams(frame_hdr->quant_params,
2919 &v4l2_frame_hdr.quant_params);
2920
2921 #define SET_V4L2_FRM_HDR_FLAG_IF(cond, flag) \
2922 v4l2_frame_hdr.flags |= ((frame_hdr->cond) ? (flag) : 0)
2923 SET_V4L2_FRM_HDR_FLAG_IF(show_frame, V4L2_VP9_FRAME_HDR_FLAG_SHOW_FRAME);
2924 SET_V4L2_FRM_HDR_FLAG_IF(error_resilient_mode,
2925 V4L2_VP9_FRAME_HDR_FLAG_ERR_RES);
2926 SET_V4L2_FRM_HDR_FLAG_IF(intra_only, V4L2_VP9_FRAME_HDR_FLAG_FRAME_INTRA);
2927 SET_V4L2_FRM_HDR_FLAG_IF(allow_high_precision_mv,
2928 V4L2_VP9_FRAME_HDR_ALLOW_HIGH_PREC_MV);
2929 SET_V4L2_FRM_HDR_FLAG_IF(refresh_frame_context,
2930 V4L2_VP9_FRAME_HDR_REFRESH_FRAME_CTX);
2931 SET_V4L2_FRM_HDR_FLAG_IF(frame_parallel_decoding_mode,
2932 V4L2_VP9_FRAME_HDR_PARALLEL_DEC_MODE);
2933 #undef SET_V4L2_FRM_HDR_FLAG_IF
2934
2935 FillV4L2VP9LoopFilterParams(lf_params, &v4l2_frame_hdr.lf_params);
2936 FillV4L2VP9SegmentationParams(segm_params, &v4l2_frame_hdr.sgmnt_params);
2937
2938 std::vector<struct v4l2_ext_control> ctrls;
2939
2940 struct v4l2_ext_control ctrl;
2941 memset(&ctrl, 0, sizeof(ctrl));
2942 ctrl.id = V4L2_CID_MPEG_VIDEO_VP9_FRAME_HDR;
2943 ctrl.size = sizeof(v4l2_frame_hdr);
2944 ctrl.p_vp9_frame_hdr = &v4l2_frame_hdr;
2945 ctrls.push_back(ctrl);
2946
2947 struct v4l2_ctrl_vp9_decode_param v4l2_decode_param;
2948 memset(&v4l2_decode_param, 0, sizeof(v4l2_decode_param));
2949 DCHECK_EQ(ref_pictures.size(), arraysize(v4l2_decode_param.ref_frames));
2950
2951 std::vector<scoped_refptr<V4L2DecodeSurface>> ref_surfaces;
2952 for (size_t i = 0; i < ref_pictures.size(); ++i) {
2953 if (ref_pictures[i]) {
2954 scoped_refptr<V4L2DecodeSurface> ref_surface =
2955 VP9PictureToV4L2DecodeSurface(ref_pictures[i]);
2956
2957 v4l2_decode_param.ref_frames[i] = ref_surface->output_record();
2958 ref_surfaces.push_back(ref_surface);
2959 } else {
2960 v4l2_decode_param.ref_frames[i] = VIDEO_MAX_FRAME;
2961 }
2962 }
2963
2964 static_assert(arraysize(v4l2_decode_param.active_ref_frames) ==
2965 arraysize(frame_hdr->ref_frame_idx),
2966 "active reference frame array sizes mismatch");
2967
2968 for (size_t i = 0; i < arraysize(frame_hdr->ref_frame_idx); ++i) {
2969 uint8_t idx = frame_hdr->ref_frame_idx[i];
2970 if (idx >= ref_pictures.size())
2971 return false;
2972
2973 struct v4l2_vp9_reference_frame* v4l2_ref_frame =
2974 &v4l2_decode_param.active_ref_frames[i];
2975
2976 scoped_refptr<VP9Picture> ref_pic = ref_pictures[idx];
2977 if (ref_pic) {
2978 scoped_refptr<V4L2DecodeSurface> ref_surface =
2979 VP9PictureToV4L2DecodeSurface(ref_pic);
2980 v4l2_ref_frame->buf_index = ref_surface->output_record();
2981 #define REF_TO_V4L2_REF(a) v4l2_ref_frame->a = ref_pic->frame_hdr->a
2982 REF_TO_V4L2_REF(frame_width);
2983 REF_TO_V4L2_REF(frame_height);
2984 REF_TO_V4L2_REF(bit_depth);
2985 REF_TO_V4L2_REF(subsampling_x);
2986 REF_TO_V4L2_REF(subsampling_y);
2987 #undef REF_TO_V4L2_REF
2988 } else {
2989 v4l2_ref_frame->buf_index = VIDEO_MAX_FRAME;
2990 }
2991 }
2992
2993 memset(&ctrl, 0, sizeof(ctrl));
2994 ctrl.id = V4L2_CID_MPEG_VIDEO_VP9_DECODE_PARAM;
2995 ctrl.size = sizeof(v4l2_decode_param);
2996 ctrl.p_vp9_decode_param = &v4l2_decode_param;
2997 ctrls.push_back(ctrl);
2998
2999 // Defined outside of the if() clause below as it must remain valid until
3000 // the call to SubmitExtControls().
3001 struct v4l2_ctrl_vp9_entropy v4l2_entropy;
3002 if (device_needs_frame_context_) {
3003 memset(&v4l2_entropy, 0, sizeof(v4l2_entropy));
3004 FillV4L2Vp9EntropyContext(frame_hdr->initial_frame_context,
3005 &v4l2_entropy.initial_entropy_ctx);
3006 FillV4L2Vp9EntropyContext(frame_hdr->frame_context,
3007 &v4l2_entropy.current_entropy_ctx);
3008 v4l2_entropy.tx_mode = frame_hdr->compressed_header.tx_mode;
3009 v4l2_entropy.reference_mode = frame_hdr->compressed_header.reference_mode;
3010
3011 memset(&ctrl, 0, sizeof(ctrl));
3012 ctrl.id = V4L2_CID_MPEG_VIDEO_VP9_ENTROPY;
3013 ctrl.size = sizeof(v4l2_entropy);
3014 ctrl.p_vp9_entropy = &v4l2_entropy;
3015 ctrls.push_back(ctrl);
3016 }
3017
3018 scoped_refptr<V4L2DecodeSurface> dec_surface =
3019 VP9PictureToV4L2DecodeSurface(pic);
3020
3021 struct v4l2_ext_controls ext_ctrls;
3022 memset(&ext_ctrls, 0, sizeof(ext_ctrls));
3023 ext_ctrls.count = ctrls.size();
3024 ext_ctrls.controls = &ctrls[0];
3025 ext_ctrls.config_store = dec_surface->config_store();
3026 if (!v4l2_dec_->SubmitExtControls(&ext_ctrls))
3027 return false;
3028
3029 dec_surface->SetReferenceSurfaces(ref_surfaces);
3030 dec_surface->SetDecodeDoneCallback(done_cb);
3031
3032 if (!v4l2_dec_->SubmitSlice(dec_surface->input_record(), frame_hdr->data,
3033 frame_hdr->frame_size))
3034 return false;
3035
3036 v4l2_dec_->DecodeSurface(dec_surface);
3037 return true;
3038 }
3039
3040 bool V4L2SliceVideoDecodeAccelerator::V4L2VP9Accelerator::OutputPicture(
3041 const scoped_refptr<VP9Picture>& pic) {
3042 scoped_refptr<V4L2DecodeSurface> dec_surface =
3043 VP9PictureToV4L2DecodeSurface(pic);
3044
3045 v4l2_dec_->SurfaceReady(dec_surface);
3046 return true;
3047 }
3048
3049 static void FillVp9FrameContext(struct v4l2_vp9_entropy_ctx& v4l2_entropy_ctx,
3050 Vp9FrameContext* vp9_frame_ctx) {
3051 #define ARRAY_MEMCPY_CHECKED_V4L2_ENTR_TO_FRM_CTX(a) \
3052 ARRAY_MEMCPY_CHECKED(vp9_frame_ctx->a, v4l2_entropy_ctx.a)
3053 ARRAY_MEMCPY_CHECKED_V4L2_ENTR_TO_FRM_CTX(tx_probs_8x8);
3054 ARRAY_MEMCPY_CHECKED_V4L2_ENTR_TO_FRM_CTX(tx_probs_16x16);
3055 ARRAY_MEMCPY_CHECKED_V4L2_ENTR_TO_FRM_CTX(tx_probs_32x32);
3056
3057 ARRAY_MEMCPY_CHECKED_V4L2_ENTR_TO_FRM_CTX(coef_probs);
3058 ARRAY_MEMCPY_CHECKED_V4L2_ENTR_TO_FRM_CTX(skip_prob);
3059 ARRAY_MEMCPY_CHECKED_V4L2_ENTR_TO_FRM_CTX(inter_mode_probs);
3060 ARRAY_MEMCPY_CHECKED_V4L2_ENTR_TO_FRM_CTX(interp_filter_probs);
3061 ARRAY_MEMCPY_CHECKED_V4L2_ENTR_TO_FRM_CTX(is_inter_prob);
3062
3063 ARRAY_MEMCPY_CHECKED_V4L2_ENTR_TO_FRM_CTX(comp_mode_prob);
3064 ARRAY_MEMCPY_CHECKED_V4L2_ENTR_TO_FRM_CTX(single_ref_prob);
3065 ARRAY_MEMCPY_CHECKED_V4L2_ENTR_TO_FRM_CTX(comp_ref_prob);
3066
3067 ARRAY_MEMCPY_CHECKED_V4L2_ENTR_TO_FRM_CTX(y_mode_probs);
3068 ARRAY_MEMCPY_CHECKED_V4L2_ENTR_TO_FRM_CTX(uv_mode_probs);
3069
3070 ARRAY_MEMCPY_CHECKED_V4L2_ENTR_TO_FRM_CTX(partition_probs);
3071
3072 ARRAY_MEMCPY_CHECKED_V4L2_ENTR_TO_FRM_CTX(mv_joint_probs);
3073 ARRAY_MEMCPY_CHECKED_V4L2_ENTR_TO_FRM_CTX(mv_sign_prob);
3074 ARRAY_MEMCPY_CHECKED_V4L2_ENTR_TO_FRM_CTX(mv_class_probs);
3075 ARRAY_MEMCPY_CHECKED_V4L2_ENTR_TO_FRM_CTX(mv_class0_bit_prob);
3076 ARRAY_MEMCPY_CHECKED_V4L2_ENTR_TO_FRM_CTX(mv_bits_prob);
3077 ARRAY_MEMCPY_CHECKED_V4L2_ENTR_TO_FRM_CTX(mv_class0_fr_probs);
3078 ARRAY_MEMCPY_CHECKED_V4L2_ENTR_TO_FRM_CTX(mv_fr_probs);
3079 ARRAY_MEMCPY_CHECKED_V4L2_ENTR_TO_FRM_CTX(mv_class0_hp_prob);
3080 ARRAY_MEMCPY_CHECKED_V4L2_ENTR_TO_FRM_CTX(mv_hp_prob);
3081 #undef ARRAY_MEMCPY_CHECKED_V4L2_ENTR_TO_FRM_CTX
3082 }
3083
3084 bool V4L2SliceVideoDecodeAccelerator::V4L2VP9Accelerator::GetFrameContext(
3085 const scoped_refptr<VP9Picture>& pic,
3086 Vp9FrameContext* frame_ctx) {
3087 struct v4l2_ctrl_vp9_entropy v4l2_entropy;
3088 memset(&v4l2_entropy, 0, sizeof(v4l2_entropy));
3089
3090 struct v4l2_ext_control ctrl;
3091 memset(&ctrl, 0, sizeof(ctrl));
3092 ctrl.id = V4L2_CID_MPEG_VIDEO_VP9_ENTROPY;
3093 ctrl.size = sizeof(v4l2_entropy);
3094 ctrl.p_vp9_entropy = &v4l2_entropy;
3095
3096 scoped_refptr<V4L2DecodeSurface> dec_surface =
3097 VP9PictureToV4L2DecodeSurface(pic);
3098
3099 struct v4l2_ext_controls ext_ctrls;
3100 memset(&ext_ctrls, 0, sizeof(ext_ctrls));
3101 ext_ctrls.count = 1;
3102 ext_ctrls.controls = &ctrl;
3103 ext_ctrls.config_store = dec_surface->config_store();
3104
3105 if (!v4l2_dec_->GetExtControls(&ext_ctrls))
3106 return false;
3107
3108 FillVp9FrameContext(v4l2_entropy.current_entropy_ctx, frame_ctx);
3109 return true;
3110 }
3111
3112 scoped_refptr<V4L2SliceVideoDecodeAccelerator::V4L2DecodeSurface>
3113 V4L2SliceVideoDecodeAccelerator::V4L2VP9Accelerator::
3114 VP9PictureToV4L2DecodeSurface(const scoped_refptr<VP9Picture>& pic) {
3115 V4L2VP9Picture* v4l2_pic = pic->AsV4L2VP9Picture();
3116 CHECK(v4l2_pic);
3117 return v4l2_pic->dec_surface();
3118 }
3119
2651 void V4L2SliceVideoDecodeAccelerator::DecodeSurface( 3120 void V4L2SliceVideoDecodeAccelerator::DecodeSurface(
2652 const scoped_refptr<V4L2DecodeSurface>& dec_surface) { 3121 const scoped_refptr<V4L2DecodeSurface>& dec_surface) {
2653 DCHECK(decoder_thread_task_runner_->BelongsToCurrentThread()); 3122 DCHECK(decoder_thread_task_runner_->BelongsToCurrentThread());
2654 3123
2655 DVLOGF(3) << "Submitting decode for surface: " << dec_surface->ToString(); 3124 DVLOGF(3) << "Submitting decode for surface: " << dec_surface->ToString();
2656 Enqueue(dec_surface); 3125 Enqueue(dec_surface);
2657 } 3126 }
2658 3127
2659 void V4L2SliceVideoDecodeAccelerator::SurfaceReady( 3128 void V4L2SliceVideoDecodeAccelerator::SurfaceReady(
2660 const scoped_refptr<V4L2DecodeSurface>& dec_surface) { 3129 const scoped_refptr<V4L2DecodeSurface>& dec_surface) {
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after
2803 V4L2SliceVideoDecodeAccelerator::GetSupportedProfiles() { 3272 V4L2SliceVideoDecodeAccelerator::GetSupportedProfiles() {
2804 scoped_refptr<V4L2Device> device = V4L2Device::Create(V4L2Device::kDecoder); 3273 scoped_refptr<V4L2Device> device = V4L2Device::Create(V4L2Device::kDecoder);
2805 if (!device) 3274 if (!device)
2806 return SupportedProfiles(); 3275 return SupportedProfiles();
2807 3276
2808 return device->GetSupportedDecodeProfiles(arraysize(supported_input_fourccs_), 3277 return device->GetSupportedDecodeProfiles(arraysize(supported_input_fourccs_),
2809 supported_input_fourccs_); 3278 supported_input_fourccs_);
2810 } 3279 }
2811 3280
2812 } // namespace media 3281 } // namespace media
OLDNEW
« no previous file with comments | « media/gpu/v4l2_slice_video_decode_accelerator.h ('k') | media/gpu/vaapi_video_decode_accelerator.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698