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

Side by Side Diff: content/common/gpu/client/gpu_video_encode_accelerator_host.cc

Issue 170843004: Pass Client pointer in Initialize() for VDA/VEA (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: 50e826de Rebase. Created 6 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 | Annotate | Revision Log
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 "content/common/gpu/client/gpu_video_encode_accelerator_host.h" 5 #include "content/common/gpu/client/gpu_video_encode_accelerator_host.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "base/message_loop/message_loop_proxy.h" 8 #include "base/message_loop/message_loop_proxy.h"
9 #include "content/common/gpu/client/gpu_channel_host.h" 9 #include "content/common/gpu/client/gpu_channel_host.h"
10 #include "content/common/gpu/gpu_messages.h" 10 #include "content/common/gpu/gpu_messages.h"
11 #include "content/common/gpu/media/gpu_video_encode_accelerator.h" 11 #include "content/common/gpu/media/gpu_video_encode_accelerator.h"
12 #include "media/base/video_frame.h" 12 #include "media/base/video_frame.h"
13 13
14 namespace content { 14 namespace content {
15 15
16 GpuVideoEncodeAcceleratorHost::GpuVideoEncodeAcceleratorHost( 16 GpuVideoEncodeAcceleratorHost::GpuVideoEncodeAcceleratorHost(
17 media::VideoEncodeAccelerator::Client* client,
18 const scoped_refptr<GpuChannelHost>& gpu_channel_host, 17 const scoped_refptr<GpuChannelHost>& gpu_channel_host,
19 int32 route_id) 18 int32 route_id)
20 : client_(client), 19 : client_(NULL),
21 client_ptr_factory_(client_),
22 channel_(gpu_channel_host), 20 channel_(gpu_channel_host),
23 route_id_(route_id), 21 route_id_(route_id),
24 next_frame_id_(0) { 22 next_frame_id_(0) {
25 channel_->AddRoute(route_id_, AsWeakPtr()); 23 channel_->AddRoute(route_id_, AsWeakPtr());
26 } 24 }
27 25
28 GpuVideoEncodeAcceleratorHost::~GpuVideoEncodeAcceleratorHost() { 26 GpuVideoEncodeAcceleratorHost::~GpuVideoEncodeAcceleratorHost() {
29 if (channel_) 27 if (channel_)
30 channel_->RemoveRoute(route_id_); 28 channel_->RemoveRoute(route_id_);
31 } 29 }
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
66 } 64 }
67 // See OnNotifyError for why this needs to be the last thing in this 65 // See OnNotifyError for why this needs to be the last thing in this
68 // function. 66 // function.
69 OnNotifyError(kPlatformFailureError); 67 OnNotifyError(kPlatformFailureError);
70 } 68 }
71 69
72 void GpuVideoEncodeAcceleratorHost::Initialize( 70 void GpuVideoEncodeAcceleratorHost::Initialize(
73 media::VideoFrame::Format input_format, 71 media::VideoFrame::Format input_format,
74 const gfx::Size& input_visible_size, 72 const gfx::Size& input_visible_size,
75 media::VideoCodecProfile output_profile, 73 media::VideoCodecProfile output_profile,
76 uint32 initial_bitrate) { 74 uint32 initial_bitrate,
75 Client* client) {
76 client_ = client;
77 client_ptr_factory_.reset(new base::WeakPtrFactory<Client>(client_));
77 Send(new AcceleratedVideoEncoderMsg_Initialize(route_id_, 78 Send(new AcceleratedVideoEncoderMsg_Initialize(route_id_,
78 input_format, 79 input_format,
79 input_visible_size, 80 input_visible_size,
80 output_profile, 81 output_profile,
81 initial_bitrate)); 82 initial_bitrate));
82 } 83 }
83 84
84 void GpuVideoEncodeAcceleratorHost::Encode( 85 void GpuVideoEncodeAcceleratorHost::Encode(
85 const scoped_refptr<media::VideoFrame>& frame, 86 const scoped_refptr<media::VideoFrame>& frame,
86 bool force_keyframe) { 87 bool force_keyframe) {
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
145 void GpuVideoEncodeAcceleratorHost::Destroy() { 146 void GpuVideoEncodeAcceleratorHost::Destroy() {
146 Send(new GpuChannelMsg_DestroyVideoEncoder(route_id_)); 147 Send(new GpuChannelMsg_DestroyVideoEncoder(route_id_));
147 delete this; 148 delete this;
148 } 149 }
149 150
150 void GpuVideoEncodeAcceleratorHost::NotifyError(Error error) { 151 void GpuVideoEncodeAcceleratorHost::NotifyError(Error error) {
151 DVLOG(2) << "NotifyError(): error=" << error; 152 DVLOG(2) << "NotifyError(): error=" << error;
152 base::MessageLoopProxy::current()->PostTask( 153 base::MessageLoopProxy::current()->PostTask(
153 FROM_HERE, 154 FROM_HERE,
154 base::Bind(&media::VideoEncodeAccelerator::Client::NotifyError, 155 base::Bind(&media::VideoEncodeAccelerator::Client::NotifyError,
155 client_ptr_factory_.GetWeakPtr(), 156 client_ptr_factory_->GetWeakPtr(),
156 error)); 157 error));
157 } 158 }
158 159
159 void GpuVideoEncodeAcceleratorHost::OnNotifyInitializeDone() { 160 void GpuVideoEncodeAcceleratorHost::OnNotifyInitializeDone() {
160 DVLOG(2) << "OnNotifyInitializeDone()"; 161 DVLOG(2) << "OnNotifyInitializeDone()";
161 if (client_) 162 if (client_)
162 client_->NotifyInitializeDone(); 163 client_->NotifyInitializeDone();
163 } 164 }
164 165
165 void GpuVideoEncodeAcceleratorHost::OnRequireBitstreamBuffers( 166 void GpuVideoEncodeAcceleratorHost::OnRequireBitstreamBuffers(
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
203 << ", payload_size=" << payload_size 204 << ", payload_size=" << payload_size
204 << ", key_frame=" << key_frame; 205 << ", key_frame=" << key_frame;
205 if (client_) 206 if (client_)
206 client_->BitstreamBufferReady(bitstream_buffer_id, payload_size, key_frame); 207 client_->BitstreamBufferReady(bitstream_buffer_id, payload_size, key_frame);
207 } 208 }
208 209
209 void GpuVideoEncodeAcceleratorHost::OnNotifyError(Error error) { 210 void GpuVideoEncodeAcceleratorHost::OnNotifyError(Error error) {
210 DVLOG(2) << "OnNotifyError(): error=" << error; 211 DVLOG(2) << "OnNotifyError(): error=" << error;
211 if (!client_) 212 if (!client_)
212 return; 213 return;
213 client_ptr_factory_.InvalidateWeakPtrs(); 214 client_ptr_factory_.reset();
214 215
215 // Client::NotifyError() may Destroy() |this|, so calling it needs to be the 216 // Client::NotifyError() may Destroy() |this|, so calling it needs to be the
216 // last thing done on this stack! 217 // last thing done on this stack!
217 media::VideoEncodeAccelerator::Client* client = NULL; 218 media::VideoEncodeAccelerator::Client* client = NULL;
218 std::swap(client_, client); 219 std::swap(client_, client);
219 client->NotifyError(error); 220 client->NotifyError(error);
220 } 221 }
221 222
222 void GpuVideoEncodeAcceleratorHost::Send(IPC::Message* message) { 223 void GpuVideoEncodeAcceleratorHost::Send(IPC::Message* message) {
223 if (!channel_) { 224 if (!channel_) {
224 DLOG(ERROR) << "Send(): no channel"; 225 DLOG(ERROR) << "Send(): no channel";
225 delete message; 226 delete message;
226 NotifyError(kPlatformFailureError); 227 NotifyError(kPlatformFailureError);
227 } else if (!channel_->Send(message)) { 228 } else if (!channel_->Send(message)) {
228 DLOG(ERROR) << "Send(): sending failed: message->type()=" 229 DLOG(ERROR) << "Send(): sending failed: message->type()="
229 << message->type(); 230 << message->type();
230 NotifyError(kPlatformFailureError); 231 NotifyError(kPlatformFailureError);
231 } 232 }
232 } 233 }
233 234
234 } // namespace content 235 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698