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

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