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

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: b0ec4672 Build fixes. Created 6 years, 10 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(
Ami GONE FROM CHROMIUM 2014/02/24 23:12:40 NULL-init client_
sheu 2014/02/24 23:48:20 Done.
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 : channel_(gpu_channel_host), route_id_(route_id), next_frame_id_(0) {
21 client_ptr_factory_(client_),
22 channel_(gpu_channel_host),
23 route_id_(route_id),
24 next_frame_id_(0) {
25 channel_->AddRoute(route_id_, AsWeakPtr()); 20 channel_->AddRoute(route_id_, AsWeakPtr());
26 } 21 }
27 22
28 GpuVideoEncodeAcceleratorHost::~GpuVideoEncodeAcceleratorHost() { 23 GpuVideoEncodeAcceleratorHost::~GpuVideoEncodeAcceleratorHost() {
29 if (channel_) 24 if (channel_)
30 channel_->RemoveRoute(route_id_); 25 channel_->RemoveRoute(route_id_);
31 } 26 }
32 27
33 // static 28 // static
34 std::vector<media::VideoEncodeAccelerator::SupportedProfile> 29 std::vector<media::VideoEncodeAccelerator::SupportedProfile>
(...skipping 28 matching lines...) Expand all
63 if (channel_) { 58 if (channel_) {
64 channel_->RemoveRoute(route_id_); 59 channel_->RemoveRoute(route_id_);
65 channel_ = NULL; 60 channel_ = NULL;
66 } 61 }
67 // See OnNotifyError for why this needs to be the last thing in this 62 // See OnNotifyError for why this needs to be the last thing in this
68 // function. 63 // function.
69 OnNotifyError(kPlatformFailureError); 64 OnNotifyError(kPlatformFailureError);
70 } 65 }
71 66
72 void GpuVideoEncodeAcceleratorHost::Initialize( 67 void GpuVideoEncodeAcceleratorHost::Initialize(
68 Client* client,
73 media::VideoFrame::Format input_format, 69 media::VideoFrame::Format input_format,
74 const gfx::Size& input_visible_size, 70 const gfx::Size& input_visible_size,
75 media::VideoCodecProfile output_profile, 71 media::VideoCodecProfile output_profile,
76 uint32 initial_bitrate) { 72 uint32 initial_bitrate) {
73 client_ = client;
74 client_ptr_factory_.reset(new base::WeakPtrFactory<Client>(client_));
77 Send(new AcceleratedVideoEncoderMsg_Initialize(route_id_, 75 Send(new AcceleratedVideoEncoderMsg_Initialize(route_id_,
78 input_format, 76 input_format,
79 input_visible_size, 77 input_visible_size,
80 output_profile, 78 output_profile,
81 initial_bitrate)); 79 initial_bitrate));
82 } 80 }
83 81
84 void GpuVideoEncodeAcceleratorHost::Encode( 82 void GpuVideoEncodeAcceleratorHost::Encode(
85 const scoped_refptr<media::VideoFrame>& frame, 83 const scoped_refptr<media::VideoFrame>& frame,
86 bool force_keyframe) { 84 bool force_keyframe) {
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
145 void GpuVideoEncodeAcceleratorHost::Destroy() { 143 void GpuVideoEncodeAcceleratorHost::Destroy() {
146 Send(new GpuChannelMsg_DestroyVideoEncoder(route_id_)); 144 Send(new GpuChannelMsg_DestroyVideoEncoder(route_id_));
147 delete this; 145 delete this;
148 } 146 }
149 147
150 void GpuVideoEncodeAcceleratorHost::NotifyError(Error error) { 148 void GpuVideoEncodeAcceleratorHost::NotifyError(Error error) {
151 DVLOG(2) << "NotifyError(): error=" << error; 149 DVLOG(2) << "NotifyError(): error=" << error;
152 base::MessageLoopProxy::current()->PostTask( 150 base::MessageLoopProxy::current()->PostTask(
153 FROM_HERE, 151 FROM_HERE,
154 base::Bind(&media::VideoEncodeAccelerator::Client::NotifyError, 152 base::Bind(&media::VideoEncodeAccelerator::Client::NotifyError,
155 client_ptr_factory_.GetWeakPtr(), 153 client_ptr_factory_->GetWeakPtr(),
156 error)); 154 error));
157 } 155 }
158 156
159 void GpuVideoEncodeAcceleratorHost::OnNotifyInitializeDone() { 157 void GpuVideoEncodeAcceleratorHost::OnNotifyInitializeDone() {
160 DVLOG(2) << "OnNotifyInitializeDone()"; 158 DVLOG(2) << "OnNotifyInitializeDone()";
161 if (client_) 159 if (client_)
162 client_->NotifyInitializeDone(); 160 client_->NotifyInitializeDone();
163 } 161 }
164 162
165 void GpuVideoEncodeAcceleratorHost::OnRequireBitstreamBuffers( 163 void GpuVideoEncodeAcceleratorHost::OnRequireBitstreamBuffers(
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
203 << ", payload_size=" << payload_size 201 << ", payload_size=" << payload_size
204 << ", key_frame=" << key_frame; 202 << ", key_frame=" << key_frame;
205 if (client_) 203 if (client_)
206 client_->BitstreamBufferReady(bitstream_buffer_id, payload_size, key_frame); 204 client_->BitstreamBufferReady(bitstream_buffer_id, payload_size, key_frame);
207 } 205 }
208 206
209 void GpuVideoEncodeAcceleratorHost::OnNotifyError(Error error) { 207 void GpuVideoEncodeAcceleratorHost::OnNotifyError(Error error) {
210 DVLOG(2) << "OnNotifyError(): error=" << error; 208 DVLOG(2) << "OnNotifyError(): error=" << error;
211 if (!client_) 209 if (!client_)
212 return; 210 return;
213 client_ptr_factory_.InvalidateWeakPtrs(); 211 client_ptr_factory_.reset();
214 212
215 // Client::NotifyError() may Destroy() |this|, so calling it needs to be the 213 // Client::NotifyError() may Destroy() |this|, so calling it needs to be the
216 // last thing done on this stack! 214 // last thing done on this stack!
217 media::VideoEncodeAccelerator::Client* client = NULL; 215 media::VideoEncodeAccelerator::Client* client = NULL;
218 std::swap(client_, client); 216 std::swap(client_, client);
219 client->NotifyError(error); 217 client->NotifyError(error);
220 } 218 }
221 219
222 void GpuVideoEncodeAcceleratorHost::Send(IPC::Message* message) { 220 void GpuVideoEncodeAcceleratorHost::Send(IPC::Message* message) {
223 if (!channel_) { 221 if (!channel_) {
224 DLOG(ERROR) << "Send(): no channel"; 222 DLOG(ERROR) << "Send(): no channel";
225 delete message; 223 delete message;
226 NotifyError(kPlatformFailureError); 224 NotifyError(kPlatformFailureError);
227 } else if (!channel_->Send(message)) { 225 } else if (!channel_->Send(message)) {
228 DLOG(ERROR) << "Send(): sending failed: message->type()=" 226 DLOG(ERROR) << "Send(): sending failed: message->type()="
229 << message->type(); 227 << message->type();
230 NotifyError(kPlatformFailureError); 228 NotifyError(kPlatformFailureError);
231 } 229 }
232 } 230 }
233 231
234 } // namespace content 232 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698