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

Side by Side Diff: media/gpu/mojo/client/gpu_jpeg_decode_accelerator_host.cc

Issue 2923933004: [NotForReview] Move GJDAH and GJDA to media/gpu/mojo
Patch Set: . Created 3 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
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "media/gpu/mojo/client/gpu_jpeg_decode_accelerator_host.h"
6
7 #include <stddef.h>
8
9 #include "base/bind.h"
10 #include "base/logging.h"
11 #include "base/macros.h"
12 #include "base/memory/shared_memory_handle.h"
13 #include "build/build_config.h"
14 #include "mojo/public/cpp/system/platform_handle.h"
15
16 namespace media {
17
18 GpuJpegDecodeAcceleratorHost::GpuJpegDecodeAcceleratorHost(
19 scoped_refptr<base::SingleThreadTaskRunner> io_task_runner,
20 mojom::GpuJpegDecodeAcceleratorPtrInfo jpeg_decoder_info)
21 : io_task_runner_(io_task_runner) {
22 jpeg_decoder_.Bind(std::move(jpeg_decoder_info));
23 }
24
25 GpuJpegDecodeAcceleratorHost::~GpuJpegDecodeAcceleratorHost() {
26 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
27 }
28
29 bool GpuJpegDecodeAcceleratorHost::Initialize(
30 JpegDecodeAccelerator::Client* client) {
31 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
32
33 bool succeeded = false;
34 jpeg_decoder_->Initialize(&succeeded);
35
36 if (succeeded)
37 client_ = client;
38
39 return succeeded;
40 }
41
42 void GpuJpegDecodeAcceleratorHost::OnDecodeAckOnIOThread(
43 int32_t bitstream_buffer_id,
44 mojom::Error error) {
45 DCHECK(io_task_runner_->BelongsToCurrentThread());
46
47 if (!client_)
48 return;
49
50 if (error == mojom::Error::NO_ERRORS) {
51 client_->VideoFrameReady(bitstream_buffer_id);
52 } else {
53 // Only NotifyError once.
54 // Client::NotifyError() may trigger deletion of |this| (on another
55 // thread), so calling it needs to be the last thing done on this stack!
56 JpegDecodeAccelerator::Client* client = nullptr;
57 std::swap(client, client_);
58 client->NotifyError(bitstream_buffer_id,
59 static_cast<JpegDecodeAccelerator::Error>(error));
60 }
61 }
62
63 void GpuJpegDecodeAcceleratorHost::OnDecodeAck(int32_t bitstream_buffer_id,
64 mojom::Error error) {
65 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
66
67 io_task_runner_->PostTask(
68 FROM_HERE,
69 base::Bind(&GpuJpegDecodeAcceleratorHost::OnDecodeAckOnIOThread,
70 base::Unretained(this), bitstream_buffer_id, error));
71 }
72
73 void GpuJpegDecodeAcceleratorHost::Decode(
74 const BitstreamBuffer& bitstream_buffer,
75 const scoped_refptr<VideoFrame>& video_frame) {
76 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
77
78 DCHECK(
79 base::SharedMemory::IsHandleValid(video_frame->shared_memory_handle()));
80
81 base::SharedMemoryHandle input_handle =
82 base::SharedMemory::DuplicateHandle(bitstream_buffer.handle());
83 if (!base::SharedMemory::IsHandleValid(input_handle)) {
84 DLOG(ERROR) << "Failed to duplicate handle of BitstreamBuffer";
85 return;
86 }
87
88 base::SharedMemoryHandle output_handle =
89 base::SharedMemory::DuplicateHandle(video_frame->shared_memory_handle());
90 if (!base::SharedMemory::IsHandleValid(output_handle)) {
91 DLOG(ERROR) << "Failed to duplicate handle of VideoFrame";
92 #if defined(OS_POSIX) && !defined(OS_MACOSX)
93 if (input_handle.OwnershipPassesToIPC()) {
94 input_handle.Close();
95 }
96 #else
97 // TODO(kcwu) fix the handle leak after crbug.com/493414 resolved.
98 #endif
99 return;
100 }
101
102 mojo::ScopedSharedBufferHandle input_buffer_handle =
103 mojo::WrapSharedMemoryHandle(input_handle, bitstream_buffer.size(),
104 true /* read_only */);
105 mojom::BitstreamBufferPtr buffer = mojom::BitstreamBuffer::New();
106 buffer->id = bitstream_buffer.id();
107 buffer->memory_handle = std::move(input_buffer_handle);
108 buffer->size = bitstream_buffer.size();
109 buffer->offset = bitstream_buffer.offset();
110 buffer->timestamp = bitstream_buffer.presentation_timestamp();
111 buffer->key_id = bitstream_buffer.key_id();
112 buffer->iv = bitstream_buffer.iv();
113 buffer->subsamples = bitstream_buffer.subsamples();
114
115 size_t output_buffer_size = VideoFrame::AllocationSize(
116 video_frame->format(), video_frame->coded_size());
117 mojo::ScopedSharedBufferHandle output_frame_handle =
118 mojo::WrapSharedMemoryHandle(output_handle, output_buffer_size,
119 false /* read_only */);
120
121 jpeg_decoder_->Decode(std::move(buffer), video_frame->coded_size(),
122 std::move(output_frame_handle),
123 base::checked_cast<uint32_t>(output_buffer_size),
124 base::Bind(&GpuJpegDecodeAcceleratorHost::OnDecodeAck,
125 base::Unretained(this)));
126 }
127
128 bool GpuJpegDecodeAcceleratorHost::IsSupported() {
129 return true;
130 }
131
132 } // namespace media
OLDNEW
« no previous file with comments | « media/gpu/mojo/client/gpu_jpeg_decode_accelerator_host.h ('k') | media/gpu/mojo/common/BUILD.gn » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698