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

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: Rebase to March 15th, Remove #include jpeg_parser 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/gpu/shared_memory_region.h"
11
12 namespace media {
13
14 FakeJpegDecodeAccelerator::FakeJpegDecodeAccelerator(
15 const scoped_refptr<base::SingleThreadTaskRunner>& io_task_runner)
16 : client_task_runner_(base::ThreadTaskRunnerHandle::Get()),
17 io_task_runner_(std::move(io_task_runner)),
18 decoder_thread_("FakeJpegDecoderThread"),
19 weak_factory_(this) {}
20
21 FakeJpegDecodeAccelerator::~FakeJpegDecodeAccelerator() {
22 DCHECK(client_task_runner_->BelongsToCurrentThread());
23 }
24
25 bool FakeJpegDecodeAccelerator::Initialize(
26 JpegDecodeAccelerator::Client* client) {
27 DCHECK(client_task_runner_->BelongsToCurrentThread());
28 client_ = client;
29
30 if (!decoder_thread_.Start()) {
31 DLOG(ERROR) << "Failed to start decoding thread.";
32 return false;
33 }
34 decoder_task_runner_ = decoder_thread_.task_runner();
35
36 return true;
37 }
38
39 void FakeJpegDecodeAccelerator::Decode(
40 const BitstreamBuffer& bitstream_buffer,
41 const scoped_refptr<VideoFrame>& video_frame) {
42 DCHECK(io_task_runner_->BelongsToCurrentThread());
43
44 // SharedMemoryRegion will take over the |bitstream_buffer.handle()|.
45 std::unique_ptr<SharedMemoryRegion> src_shm(
46 new SharedMemoryRegion(bitstream_buffer, true));
47 if (!src_shm->Map()) {
48 DLOG(ERROR) << "Unable to map shared memory in FakeJpegDecodeAccelerator";
49 NotifyError(bitstream_buffer.id(), JpegDecodeAccelerator::UNREADABLE_INPUT);
50 return;
51 }
52
53 // Unretained |this| is safe because |this| owns |decoder_thread_|.
54 decoder_task_runner_->PostTask(
55 FROM_HERE, base::Bind(&FakeJpegDecodeAccelerator::DecodeOnDecoderThread,
56 base::Unretained(this), bitstream_buffer,
57 video_frame, base::Passed(&src_shm)));
58 }
59
60 void FakeJpegDecodeAccelerator::DecodeOnDecoderThread(
61 const BitstreamBuffer& bitstream_buffer,
62 const scoped_refptr<VideoFrame>& video_frame,
63 std::unique_ptr<SharedMemoryRegion> src_shm) {
64 DCHECK(decoder_task_runner_->BelongsToCurrentThread());
65
66 // Do not actually decode the Jpeg data.
67 // Instead, just fill the output buffer with zeros.
68 size_t allocation_size =
69 VideoFrame::AllocationSize(PIXEL_FORMAT_I420, video_frame->coded_size());
70 memset(video_frame->data(0), 0, allocation_size);
71
72 client_task_runner_->PostTask(
73 FROM_HERE,
74 base::Bind(&FakeJpegDecodeAccelerator::OnDecodeDoneOnClientThread,
75 weak_factory_.GetWeakPtr(), bitstream_buffer.id()));
76 }
77
78 bool FakeJpegDecodeAccelerator::IsSupported() {
79 return true;
80 }
81
82 void FakeJpegDecodeAccelerator::NotifyError(int32_t bitstream_buffer_id,
83 Error error) {
84 client_task_runner_->PostTask(
85 FROM_HERE,
86 base::Bind(&FakeJpegDecodeAccelerator::NotifyErrorOnClientThread,
87 weak_factory_.GetWeakPtr(), bitstream_buffer_id, error));
88 }
89
90 void FakeJpegDecodeAccelerator::NotifyErrorOnClientThread(
91 int32_t bitstream_buffer_id,
92 Error error) {
93 DCHECK(client_task_runner_->BelongsToCurrentThread());
94 client_->NotifyError(bitstream_buffer_id, error);
95 }
96
97 void FakeJpegDecodeAccelerator::OnDecodeDoneOnClientThread(
98 int32_t input_buffer_id) {
99 DCHECK(client_task_runner_->BelongsToCurrentThread());
100 client_->VideoFrameReady(input_buffer_id);
101 }
102
103 } // namespace media
OLDNEW
« no previous file with comments | « media/gpu/fake_jpeg_decode_accelerator.h ('k') | media/gpu/ipc/service/gpu_jpeg_decode_accelerator.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698