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

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

Issue 2735083002: [Mojo Video Capture] Add test coverage for accelerated jpeg decoding (Closed)
Patch Set: Removed OnStoppedUsingGpuDecode() event. Created 3 years, 9 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 2017 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.
4
5 #include "media/gpu/fake_jpeg_decode_accelerator.h"
6
7 #include "base/bind.h"
8 #include "base/single_thread_task_runner.h"
9 #include "base/threading/thread_task_runner_handle.h"
10 #include "media/filters/jpeg_parser.h"
11 #include "media/gpu/shared_memory_region.h"
12 #include "third_party/libyuv/include/libyuv.h"
13
14 namespace media {
15
16 FakeJpegDecodeAccelerator::FakeJpegDecodeAccelerator(
17 const scoped_refptr<base::SingleThreadTaskRunner>& io_task_runner)
18 : task_runner_(base::ThreadTaskRunnerHandle::Get()),
19 io_task_runner_(std::move(io_task_runner)),
20 weak_factory_(this) {}
21
22 FakeJpegDecodeAccelerator::~FakeJpegDecodeAccelerator() = default;
23
24 bool FakeJpegDecodeAccelerator::Initialize(
25 JpegDecodeAccelerator::Client* client) {
26 client_ = client;
mcasas 2017/03/08 01:33:17 I guess here is DCHECK(io_task_runner_->BelongsTo
chfremer 2017/03/08 18:58:08 In this case it is |task_runner_|, not |io_task_ru
27 return true;
28 }
29
30 void FakeJpegDecodeAccelerator::Decode(
31 const BitstreamBuffer& bitstream_buffer,
32 const scoped_refptr<VideoFrame>& video_frame) {
33 DCHECK(io_task_runner_->BelongsToCurrentThread());
34 // SharedMemoryRegion will take over the |bitstream_buffer.handle()|.
35 std::unique_ptr<SharedMemoryRegion> src_shm_(
36 new SharedMemoryRegion(bitstream_buffer, true));
37 if (!src_shm_->Map()) {
38 DLOG(ERROR) << "Unable to map shared memory in FakeJpegDecodeAccelerator";
39 NotifyError(bitstream_buffer.id(), JpegDecodeAccelerator::UNREADABLE_INPUT);
40 return;
41 }
42
43 JpegParseResult parse_result;
44 if (!ParseJpegPicture(static_cast<uint8_t*>(src_shm_->memory()),
45 src_shm_->size(), &parse_result)) {
46 DLOG(ERROR) << "ParseJpegPicture failed in FakeJpegDecodeAccelerator";
47 NotifyError(bitstream_buffer.id(),
48 JpegDecodeAccelerator::PARSE_JPEG_FAILED);
49 return;
50 }
51 const gfx::Size src_coded_size(parse_result.frame_header.coded_width,
52 parse_result.frame_header.coded_height);
53 DCHECK_GE(src_coded_size.width(), video_frame->coded_size().width());
54 DCHECK_GE(src_coded_size.height(), video_frame->coded_size().height());
55
56 uint8_t* dst_y = video_frame->data(VideoFrame::kYPlane);
57 uint8_t* dst_u = video_frame->data(VideoFrame::kUPlane);
58 uint8_t* dst_v = video_frame->data(VideoFrame::kVPlane);
59 size_t dst_y_stride = video_frame->stride(VideoFrame::kYPlane);
60 size_t dst_u_stride = video_frame->stride(VideoFrame::kUPlane);
61 size_t dst_v_stride = video_frame->stride(VideoFrame::kVPlane);
62
63 if (libyuv::ConvertToI420(
64 static_cast<uint8_t*>(src_shm_->memory()), src_shm_->size(), dst_y,
65 dst_y_stride, dst_u, dst_u_stride, dst_v, dst_v_stride, 0, 0,
66 src_coded_size.width(), src_coded_size.height(),
67 video_frame->coded_size().width(), video_frame->coded_size().height(),
68 libyuv::kRotate0, libyuv::FOURCC_MJPG) != 0) {
69 DLOG(ERROR) << "Software decode failed.";
70 NotifyError(bitstream_buffer.id(), JpegDecodeAccelerator::PLATFORM_FAILURE);
71 return;
72 }
73 task_runner_->PostTask(
74 FROM_HERE,
75 base::Bind(&FakeJpegDecodeAccelerator::OnDecodeDoneOnClientThread,
76 weak_factory_.GetWeakPtr(), bitstream_buffer.id()));
77 }
78
79 bool FakeJpegDecodeAccelerator::IsSupported() {
80 return true;
81 }
82
83 void FakeJpegDecodeAccelerator::NotifyError(int32_t bitstream_buffer_id,
84 Error error) {
85 DCHECK(io_task_runner_->BelongsToCurrentThread());
86 task_runner_->PostTask(
87 FROM_HERE,
88 base::Bind(&FakeJpegDecodeAccelerator::NotifyErrorOnClientThread,
89 weak_factory_.GetWeakPtr(), bitstream_buffer_id, error));
90 }
91
92 void FakeJpegDecodeAccelerator::NotifyErrorOnClientThread(
93 int32_t bitstream_buffer_id,
94 Error error) {
95 DCHECK(task_runner_->BelongsToCurrentThread());
96 client_->NotifyError(bitstream_buffer_id, error);
97 }
98
99 void FakeJpegDecodeAccelerator::OnDecodeDoneOnClientThread(
100 int32_t input_buffer_id) {
101 DCHECK(task_runner_->BelongsToCurrentThread());
102 client_->VideoFrameReady(input_buffer_id);
103 }
104
105 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698