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

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

Issue 649533003: C++11 declares a type safe null pointer (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixed Presubmit errors Created 6 years, 2 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
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 #define NOTIFY_ERROR(error) \ 16 #define NOTIFY_ERROR(error) \
17 PostNotifyError(error); \ 17 PostNotifyError(error); \
18 DLOG(ERROR) 18 DLOG(ERROR)
19 19
20 GpuVideoEncodeAcceleratorHost::GpuVideoEncodeAcceleratorHost( 20 GpuVideoEncodeAcceleratorHost::GpuVideoEncodeAcceleratorHost(
21 GpuChannelHost* channel, 21 GpuChannelHost* channel,
22 CommandBufferProxyImpl* impl) 22 CommandBufferProxyImpl* impl)
23 : channel_(channel), 23 : channel_(channel),
24 encoder_route_id_(MSG_ROUTING_NONE), 24 encoder_route_id_(MSG_ROUTING_NONE),
25 client_(NULL), 25 client_(nullptr),
26 impl_(impl), 26 impl_(impl),
27 next_frame_id_(0), 27 next_frame_id_(0),
28 weak_this_factory_(this) { 28 weak_this_factory_(this) {
29 DCHECK(channel_); 29 DCHECK(channel_);
30 DCHECK(impl_); 30 DCHECK(impl_);
31 impl_->AddDeletionObserver(this); 31 impl_->AddDeletionObserver(this);
32 } 32 }
33 33
34 GpuVideoEncodeAcceleratorHost::~GpuVideoEncodeAcceleratorHost() { 34 GpuVideoEncodeAcceleratorHost::~GpuVideoEncodeAcceleratorHost() {
35 DCHECK(CalledOnValidThread()); 35 DCHECK(CalledOnValidThread());
(...skipping 21 matching lines...) Expand all
57 // See OnNotifyError for why |this| mustn't be used after OnNotifyError might 57 // See OnNotifyError for why |this| mustn't be used after OnNotifyError might
58 // have been called above. 58 // have been called above.
59 return handled; 59 return handled;
60 } 60 }
61 61
62 void GpuVideoEncodeAcceleratorHost::OnChannelError() { 62 void GpuVideoEncodeAcceleratorHost::OnChannelError() {
63 DCHECK(CalledOnValidThread()); 63 DCHECK(CalledOnValidThread());
64 if (channel_) { 64 if (channel_) {
65 if (encoder_route_id_ != MSG_ROUTING_NONE) 65 if (encoder_route_id_ != MSG_ROUTING_NONE)
66 channel_->RemoveRoute(encoder_route_id_); 66 channel_->RemoveRoute(encoder_route_id_);
67 channel_ = NULL; 67 channel_ = nullptr;
68 } 68 }
69 NOTIFY_ERROR(kPlatformFailureError) << "OnChannelError()"; 69 NOTIFY_ERROR(kPlatformFailureError) << "OnChannelError()";
70 } 70 }
71 71
72 std::vector<media::VideoEncodeAccelerator::SupportedProfile> 72 std::vector<media::VideoEncodeAccelerator::SupportedProfile>
73 GpuVideoEncodeAcceleratorHost::GetSupportedProfiles() { 73 GpuVideoEncodeAcceleratorHost::GetSupportedProfiles() {
74 DCHECK(CalledOnValidThread()); 74 DCHECK(CalledOnValidThread());
75 if (!channel_) 75 if (!channel_)
76 return std::vector<media::VideoEncodeAccelerator::SupportedProfile>(); 76 return std::vector<media::VideoEncodeAccelerator::SupportedProfile>();
77 return channel_->gpu_info().video_encode_accelerator_supported_profiles; 77 return channel_->gpu_info().video_encode_accelerator_supported_profiles;
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
175 return; 175 return;
176 176
177 Send(new AcceleratedVideoEncoderMsg_RequestEncodingParametersChange( 177 Send(new AcceleratedVideoEncoderMsg_RequestEncodingParametersChange(
178 encoder_route_id_, bitrate, framerate)); 178 encoder_route_id_, bitrate, framerate));
179 } 179 }
180 180
181 void GpuVideoEncodeAcceleratorHost::Destroy() { 181 void GpuVideoEncodeAcceleratorHost::Destroy() {
182 DCHECK(CalledOnValidThread()); 182 DCHECK(CalledOnValidThread());
183 if (channel_) 183 if (channel_)
184 Send(new AcceleratedVideoEncoderMsg_Destroy(encoder_route_id_)); 184 Send(new AcceleratedVideoEncoderMsg_Destroy(encoder_route_id_));
185 client_ = NULL; 185 client_ = nullptr;
186 delete this; 186 delete this;
187 } 187 }
188 188
189 void GpuVideoEncodeAcceleratorHost::OnWillDeleteImpl() { 189 void GpuVideoEncodeAcceleratorHost::OnWillDeleteImpl() {
190 DCHECK(CalledOnValidThread()); 190 DCHECK(CalledOnValidThread());
191 impl_ = NULL; 191 impl_ = nullptr;
192 192
193 // The CommandBufferProxyImpl is going away; error out this VEA. 193 // The CommandBufferProxyImpl is going away; error out this VEA.
194 OnChannelError(); 194 OnChannelError();
195 } 195 }
196 196
197 void GpuVideoEncodeAcceleratorHost::PostNotifyError(Error error) { 197 void GpuVideoEncodeAcceleratorHost::PostNotifyError(Error error) {
198 DCHECK(CalledOnValidThread()); 198 DCHECK(CalledOnValidThread());
199 DVLOG(2) << "PostNotifyError(): error=" << error; 199 DVLOG(2) << "PostNotifyError(): error=" << error;
200 // Post the error notification back to this thread, to avoid re-entrancy. 200 // Post the error notification back to this thread, to avoid re-entrancy.
201 base::MessageLoopProxy::current()->PostTask( 201 base::MessageLoopProxy::current()->PostTask(
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
238 // theoretical" - Android's std::hash_map crashes if we don't do this. 238 // theoretical" - Android's std::hash_map crashes if we don't do this.
239 scoped_refptr<media::VideoFrame> frame = frame_map_[frame_id]; 239 scoped_refptr<media::VideoFrame> frame = frame_map_[frame_id];
240 if (!frame_map_.erase(frame_id)) { 240 if (!frame_map_.erase(frame_id)) {
241 DLOG(ERROR) << "OnNotifyInputDone(): " 241 DLOG(ERROR) << "OnNotifyInputDone(): "
242 "invalid frame_id=" << frame_id; 242 "invalid frame_id=" << frame_id;
243 // See OnNotifyError for why this needs to be the last thing in this 243 // See OnNotifyError for why this needs to be the last thing in this
244 // function. 244 // function.
245 OnNotifyError(kPlatformFailureError); 245 OnNotifyError(kPlatformFailureError);
246 return; 246 return;
247 } 247 }
248 frame = NULL; // Not necessary but nice to be explicit; see fun-fact above. 248 frame = nullptr; // Not necessary but nice to be explicit; see fun-fact above.
249 } 249 }
250 250
251 void GpuVideoEncodeAcceleratorHost::OnBitstreamBufferReady( 251 void GpuVideoEncodeAcceleratorHost::OnBitstreamBufferReady(
252 int32 bitstream_buffer_id, 252 int32 bitstream_buffer_id,
253 uint32 payload_size, 253 uint32 payload_size,
254 bool key_frame) { 254 bool key_frame) {
255 DCHECK(CalledOnValidThread()); 255 DCHECK(CalledOnValidThread());
256 DVLOG(3) << "OnBitstreamBufferReady(): " 256 DVLOG(3) << "OnBitstreamBufferReady(): "
257 "bitstream_buffer_id=" << bitstream_buffer_id 257 "bitstream_buffer_id=" << bitstream_buffer_id
258 << ", payload_size=" << payload_size 258 << ", payload_size=" << payload_size
259 << ", key_frame=" << key_frame; 259 << ", key_frame=" << key_frame;
260 if (client_) 260 if (client_)
261 client_->BitstreamBufferReady(bitstream_buffer_id, payload_size, key_frame); 261 client_->BitstreamBufferReady(bitstream_buffer_id, payload_size, key_frame);
262 } 262 }
263 263
264 void GpuVideoEncodeAcceleratorHost::OnNotifyError(Error error) { 264 void GpuVideoEncodeAcceleratorHost::OnNotifyError(Error error) {
265 DCHECK(CalledOnValidThread()); 265 DCHECK(CalledOnValidThread());
266 DVLOG(2) << "OnNotifyError(): error=" << error; 266 DVLOG(2) << "OnNotifyError(): error=" << error;
267 if (!client_) 267 if (!client_)
268 return; 268 return;
269 weak_this_factory_.InvalidateWeakPtrs(); 269 weak_this_factory_.InvalidateWeakPtrs();
270 270
271 // Client::NotifyError() may Destroy() |this|, so calling it needs to be the 271 // Client::NotifyError() may Destroy() |this|, so calling it needs to be the
272 // last thing done on this stack! 272 // last thing done on this stack!
273 media::VideoEncodeAccelerator::Client* client = NULL; 273 media::VideoEncodeAccelerator::Client* client = nullptr;
274 std::swap(client_, client); 274 std::swap(client_, client);
275 client->NotifyError(error); 275 client->NotifyError(error);
276 } 276 }
277 277
278 } // namespace content 278 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698