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

Side by Side Diff: media/gpu/ipc/service/gpu_video_encode_accelerator.cc

Issue 2427053002: Move video encode accelerator IPC messages to GPU IO thread (Closed)
Patch Set: Created 4 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 "media/gpu/ipc/service/gpu_video_encode_accelerator.h" 5 #include "media/gpu/ipc/service/gpu_video_encode_accelerator.h"
6 6
7 #include <memory> 7 #include <memory>
8 8
9 #include "base/callback.h" 9 #include "base/callback.h"
10 #include "base/command_line.h" 10 #include "base/command_line.h"
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
92 92
93 #if defined(OS_WIN) 93 #if defined(OS_WIN)
94 std::unique_ptr<VideoEncodeAccelerator> CreateMediaFoundationVEA() { 94 std::unique_ptr<VideoEncodeAccelerator> CreateMediaFoundationVEA() {
95 return base::WrapUnique<media::VideoEncodeAccelerator>( 95 return base::WrapUnique<media::VideoEncodeAccelerator>(
96 new MediaFoundationVideoEncodeAccelerator()); 96 new MediaFoundationVideoEncodeAccelerator());
97 } 97 }
98 #endif 98 #endif
99 99
100 } // anonymous namespace 100 } // anonymous namespace
101 101
102 class GpuVideoEncodeAccelerator::MessageFilter : public IPC::MessageFilter {
103 public:
104 MessageFilter(GpuVideoEncodeAccelerator* owner, int32_t host_route_id)
105 : owner_(owner), host_route_id_(host_route_id) {}
106
107 void OnChannelError() override { sender_ = NULL; }
108
109 void OnChannelClosing() override { sender_ = NULL; }
110
111 void OnFilterAdded(IPC::Channel* channel) override { sender_ = channel; }
112
113 void OnFilterRemoved() override {
114 // This will delete |owner_| and |this|.
sandersd (OOO until July 31) 2016/10/21 18:41:03 Misleading comment, since it makes the (cross-clas
emircan 2016/10/24 19:44:52 I agree that it sounds like it is coming from dtor
115 owner_->OnFilterRemoved();
116 }
117
118 bool OnMessageReceived(const IPC::Message& msg) override {
119 if (msg.routing_id() != host_route_id_)
120 return false;
121
122 IPC_BEGIN_MESSAGE_MAP(MessageFilter, msg)
123 IPC_MESSAGE_FORWARD(AcceleratedVideoEncoderMsg_Encode, owner_,
124 GpuVideoEncodeAccelerator::OnEncode)
125 IPC_MESSAGE_FORWARD(AcceleratedVideoEncoderMsg_UseOutputBitstreamBuffer,
126 owner_,
127 GpuVideoEncodeAccelerator::OnUseOutputBitstreamBuffer)
128 IPC_MESSAGE_FORWARD(
129 AcceleratedVideoEncoderMsg_RequestEncodingParametersChange, owner_,
130 GpuVideoEncodeAccelerator::OnRequestEncodingParametersChange)
131 IPC_MESSAGE_UNHANDLED(return false)
132 IPC_END_MESSAGE_MAP()
133 return true;
134 }
135
136 bool SendOnIOThread(IPC::Message* message) {
137 CHECK(!message->is_sync());
138 if (!sender_) {
139 delete message;
140 return false;
141 }
142 const bool rv = sender_->Send(message);
143 CHECK(rv);
sandersd (OOO until July 31) 2016/10/21 18:41:03 ?
emircan 2016/10/24 19:44:52 It was paranioa check. Removing it.
144 return rv;
145 }
146
147 protected:
148 ~MessageFilter() override {}
149
150 private:
151 GpuVideoEncodeAccelerator* const owner_;
152 const int32_t host_route_id_;
153 // The sender to which this filter was added.
154 IPC::Sender* sender_;
155 };
156
102 GpuVideoEncodeAccelerator::GpuVideoEncodeAccelerator( 157 GpuVideoEncodeAccelerator::GpuVideoEncodeAccelerator(
103 int32_t host_route_id, 158 int32_t host_route_id,
104 gpu::GpuCommandBufferStub* stub) 159 gpu::GpuCommandBufferStub* stub,
160 const scoped_refptr<base::SingleThreadTaskRunner>& io_task_runner)
105 : host_route_id_(host_route_id), 161 : host_route_id_(host_route_id),
106 stub_(stub), 162 stub_(stub),
107 input_format_(PIXEL_FORMAT_UNKNOWN), 163 input_format_(PIXEL_FORMAT_UNKNOWN),
108 output_buffer_size_(0), 164 output_buffer_size_(0),
165 filter_removed_(base::WaitableEvent::ResetPolicy::MANUAL,
166 base::WaitableEvent::InitialState::NOT_SIGNALED),
167 main_task_runner_(base::ThreadTaskRunnerHandle::Get()),
168 io_task_runner_(io_task_runner),
109 weak_this_factory_(this) { 169 weak_this_factory_(this) {
110 stub_->AddDestructionObserver(this); 170 stub_->AddDestructionObserver(this);
111 make_context_current_ = 171 make_context_current_ =
112 base::Bind(&MakeDecoderContextCurrent, stub_->AsWeakPtr()); 172 base::Bind(&MakeDecoderContextCurrent, stub_->AsWeakPtr());
113 } 173 }
114 174
115 GpuVideoEncodeAccelerator::~GpuVideoEncodeAccelerator() { 175 GpuVideoEncodeAccelerator::~GpuVideoEncodeAccelerator() {
116 // This class can only be self-deleted from OnWillDestroyStub(), which means 176 // This class can only be self-deleted from OnWillDestroyStub(), which means
117 // the VEA has already been destroyed in there. 177 // the VEA has already been destroyed in there.
118 DCHECK(!encoder_); 178 DCHECK(!encoder_);
119 } 179 }
120 180
121 bool GpuVideoEncodeAccelerator::Initialize(VideoPixelFormat input_format, 181 bool GpuVideoEncodeAccelerator::Initialize(VideoPixelFormat input_format,
122 const gfx::Size& input_visible_size, 182 const gfx::Size& input_visible_size,
123 VideoCodecProfile output_profile, 183 VideoCodecProfile output_profile,
124 uint32_t initial_bitrate) { 184 uint32_t initial_bitrate) {
185 DCHECK(main_task_runner_->BelongsToCurrentThread());
125 DVLOG(1) << __FUNCTION__ 186 DVLOG(1) << __FUNCTION__
126 << " input_format=" << VideoPixelFormatToString(input_format) 187 << " input_format=" << VideoPixelFormatToString(input_format)
127 << ", input_visible_size=" << input_visible_size.ToString() 188 << ", input_visible_size=" << input_visible_size.ToString()
128 << ", output_profile=" << GetProfileName(output_profile) 189 << ", output_profile=" << GetProfileName(output_profile)
129 << ", initial_bitrate=" << initial_bitrate; 190 << ", initial_bitrate=" << initial_bitrate;
130 DCHECK(!encoder_); 191 DCHECK(!encoder_);
131 192
132 if (!stub_->channel()->AddRoute(host_route_id_, stub_->stream_id(), this)) { 193 if (!stub_->channel()->AddRoute(host_route_id_, stub_->stream_id(), this)) {
133 DLOG(ERROR) << __FUNCTION__ << " failed to add route"; 194 DLOG(ERROR) << __FUNCTION__ << " failed to add route";
134 return false; 195 return false;
(...skipping 11 matching lines...) Expand all
146 stub_->channel()->gpu_channel_manager()->gpu_preferences(); 207 stub_->channel()->gpu_channel_manager()->gpu_preferences();
147 208
148 // Try all possible encoders and use the first successful encoder. 209 // Try all possible encoders and use the first successful encoder.
149 for (const auto& factory_function : GetVEAFactoryFunctions(gpu_preferences)) { 210 for (const auto& factory_function : GetVEAFactoryFunctions(gpu_preferences)) {
150 encoder_ = factory_function.Run(); 211 encoder_ = factory_function.Run();
151 if (encoder_ && 212 if (encoder_ &&
152 encoder_->Initialize(input_format, input_visible_size, output_profile, 213 encoder_->Initialize(input_format, input_visible_size, output_profile,
153 initial_bitrate, this)) { 214 initial_bitrate, this)) {
154 input_format_ = input_format; 215 input_format_ = input_format;
155 input_visible_size_ = input_visible_size; 216 input_visible_size_ = input_visible_size;
217 // Attempt to set up performing encoding tasks on IO thread, if supported
218 // by the VEA.
219 if (encoder_->TryToSetupEncodeOnSeparateThread(
220 weak_this_factory_.GetWeakPtr(), io_task_runner_)) {
221 filter_ = new MessageFilter(this, host_route_id_);
222 stub_->channel()->AddFilter(filter_.get());
223 }
156 return true; 224 return true;
157 } 225 }
158 } 226 }
159 encoder_.reset(); 227 encoder_.reset();
160 DLOG(ERROR) << __FUNCTION__ << " VEA initialization failed"; 228 DLOG(ERROR) << __FUNCTION__ << " VEA initialization failed";
161 return false; 229 return false;
162 } 230 }
163 231
164 bool GpuVideoEncodeAccelerator::OnMessageReceived(const IPC::Message& message) { 232 bool GpuVideoEncodeAccelerator::OnMessageReceived(const IPC::Message& message) {
165 bool handled = true; 233 bool handled = true;
166 IPC_BEGIN_MESSAGE_MAP(GpuVideoEncodeAccelerator, message) 234 IPC_BEGIN_MESSAGE_MAP(GpuVideoEncodeAccelerator, message)
167 IPC_MESSAGE_HANDLER(AcceleratedVideoEncoderMsg_Encode, OnEncode) 235 IPC_MESSAGE_HANDLER(AcceleratedVideoEncoderMsg_Encode, OnEncode)
168 IPC_MESSAGE_HANDLER(AcceleratedVideoEncoderMsg_UseOutputBitstreamBuffer, 236 IPC_MESSAGE_HANDLER(AcceleratedVideoEncoderMsg_UseOutputBitstreamBuffer,
169 OnUseOutputBitstreamBuffer) 237 OnUseOutputBitstreamBuffer)
170 IPC_MESSAGE_HANDLER( 238 IPC_MESSAGE_HANDLER(
171 AcceleratedVideoEncoderMsg_RequestEncodingParametersChange, 239 AcceleratedVideoEncoderMsg_RequestEncodingParametersChange,
172 OnRequestEncodingParametersChange) 240 OnRequestEncodingParametersChange)
173 IPC_MESSAGE_HANDLER(AcceleratedVideoEncoderMsg_Destroy, OnDestroy) 241 IPC_MESSAGE_HANDLER(AcceleratedVideoEncoderMsg_Destroy, OnDestroy)
174 IPC_MESSAGE_UNHANDLED(handled = false) 242 IPC_MESSAGE_UNHANDLED(handled = false)
175 IPC_END_MESSAGE_MAP() 243 IPC_END_MESSAGE_MAP()
176 return handled; 244 return handled;
177 } 245 }
178 246
179 void GpuVideoEncodeAccelerator::RequireBitstreamBuffers( 247 void GpuVideoEncodeAccelerator::RequireBitstreamBuffers(
180 unsigned int input_count, 248 unsigned int input_count,
181 const gfx::Size& input_coded_size, 249 const gfx::Size& input_coded_size,
182 size_t output_buffer_size) { 250 size_t output_buffer_size) {
183 Send(new AcceleratedVideoEncoderHostMsg_RequireBitstreamBuffers( 251 if (!Send(new AcceleratedVideoEncoderHostMsg_RequireBitstreamBuffers(
184 host_route_id_, input_count, input_coded_size, output_buffer_size)); 252 host_route_id_, input_count, input_coded_size, output_buffer_size))) {
253 DLOG(ERROR) << __func__ << " failed.";
sandersd (OOO until July 31) 2016/10/21 18:41:03 Should GVEA be entering some sort of error state o
emircan 2016/10/24 19:44:52 I added these to have logs if any error occurs but
254 }
185 input_coded_size_ = input_coded_size; 255 input_coded_size_ = input_coded_size;
186 output_buffer_size_ = output_buffer_size; 256 output_buffer_size_ = output_buffer_size;
187 } 257 }
188 258
189 void GpuVideoEncodeAccelerator::BitstreamBufferReady( 259 void GpuVideoEncodeAccelerator::BitstreamBufferReady(
190 int32_t bitstream_buffer_id, 260 int32_t bitstream_buffer_id,
191 size_t payload_size, 261 size_t payload_size,
192 bool key_frame, 262 bool key_frame,
193 base::TimeDelta timestamp) { 263 base::TimeDelta timestamp) {
194 Send(new AcceleratedVideoEncoderHostMsg_BitstreamBufferReady( 264 DCHECK(CheckCalledOnMessageFilterThread());
195 host_route_id_, bitstream_buffer_id, payload_size, key_frame, timestamp)); 265 if (!Send(new AcceleratedVideoEncoderHostMsg_BitstreamBufferReady(
266 host_route_id_, bitstream_buffer_id, payload_size, key_frame,
267 timestamp))) {
268 DLOG(ERROR) << __func__ << " failed.";
269 }
196 } 270 }
197 271
198 void GpuVideoEncodeAccelerator::NotifyError( 272 void GpuVideoEncodeAccelerator::NotifyError(
199 VideoEncodeAccelerator::Error error) { 273 VideoEncodeAccelerator::Error error) {
200 Send(new AcceleratedVideoEncoderHostMsg_NotifyError(host_route_id_, error)); 274 DCHECK(CheckCalledOnMessageFilterThread());
275 if (!Send(new AcceleratedVideoEncoderHostMsg_NotifyError(host_route_id_,
276 error))) {
277 DLOG(ERROR) << __func__ << " failed.";
278 }
201 } 279 }
202 280
203 void GpuVideoEncodeAccelerator::OnWillDestroyStub() { 281 void GpuVideoEncodeAccelerator::OnWillDestroyStub() {
282 DCHECK(main_task_runner_->BelongsToCurrentThread());
204 DCHECK(stub_); 283 DCHECK(stub_);
284
285 if (filter_) {
286 stub_->channel()->RemoveFilter(filter_.get());
287 filter_removed_.Wait();
288 }
289
205 stub_->channel()->RemoveRoute(host_route_id_); 290 stub_->channel()->RemoveRoute(host_route_id_);
206 stub_->RemoveDestructionObserver(this); 291 stub_->RemoveDestructionObserver(this);
207 encoder_.reset(); 292 encoder_.reset();
208 delete this; 293 delete this;
209 } 294 }
210 295
211 // static 296 // static
212 gpu::VideoEncodeAcceleratorSupportedProfiles 297 gpu::VideoEncodeAcceleratorSupportedProfiles
213 GpuVideoEncodeAccelerator::GetSupportedProfiles( 298 GpuVideoEncodeAccelerator::GetSupportedProfiles(
214 const gpu::GpuPreferences& gpu_preferences) { 299 const gpu::GpuPreferences& gpu_preferences) {
215 VideoEncodeAccelerator::SupportedProfiles profiles; 300 VideoEncodeAccelerator::SupportedProfiles profiles;
216 301
217 for (const auto& factory_function : GetVEAFactoryFunctions(gpu_preferences)) { 302 for (const auto& factory_function : GetVEAFactoryFunctions(gpu_preferences)) {
218 std::unique_ptr<VideoEncodeAccelerator> encoder = factory_function.Run(); 303 std::unique_ptr<VideoEncodeAccelerator> encoder = factory_function.Run();
219 if (!encoder) 304 if (!encoder)
220 continue; 305 continue;
221 VideoEncodeAccelerator::SupportedProfiles vea_profiles = 306 VideoEncodeAccelerator::SupportedProfiles vea_profiles =
222 encoder->GetSupportedProfiles(); 307 encoder->GetSupportedProfiles();
223 GpuVideoAcceleratorUtil::InsertUniqueEncodeProfiles(vea_profiles, 308 GpuVideoAcceleratorUtil::InsertUniqueEncodeProfiles(vea_profiles,
224 &profiles); 309 &profiles);
225 } 310 }
226 return GpuVideoAcceleratorUtil::ConvertMediaToGpuEncodeProfiles(profiles); 311 return GpuVideoAcceleratorUtil::ConvertMediaToGpuEncodeProfiles(profiles);
227 } 312 }
228 313
314 void GpuVideoEncodeAccelerator::OnFilterRemoved() {
315 // We're destroying; cancel all callbacks.
sandersd (OOO until July 31) 2016/10/21 18:41:03 Are there no GPU shutdown paths where the channel
emircan 2016/10/24 19:44:52 Filter is actually removed before GVEA is destruct
316 weak_this_factory_.InvalidateWeakPtrs();
317 filter_removed_.Signal();
318 }
319
229 // static 320 // static
230 std::vector<GpuVideoEncodeAccelerator::VEAFactoryFunction> 321 std::vector<GpuVideoEncodeAccelerator::VEAFactoryFunction>
231 GpuVideoEncodeAccelerator::GetVEAFactoryFunctions( 322 GpuVideoEncodeAccelerator::GetVEAFactoryFunctions(
232 const gpu::GpuPreferences& gpu_preferences) { 323 const gpu::GpuPreferences& gpu_preferences) {
233 std::vector<VEAFactoryFunction> vea_factory_functions; 324 std::vector<VEAFactoryFunction> vea_factory_functions;
234 #if defined(OS_CHROMEOS) && defined(USE_V4L2_CODEC) 325 #if defined(OS_CHROMEOS) && defined(USE_V4L2_CODEC)
235 vea_factory_functions.push_back(base::Bind(&CreateV4L2VEA)); 326 vea_factory_functions.push_back(base::Bind(&CreateV4L2VEA));
236 #endif 327 #endif
237 #if defined(OS_CHROMEOS) && defined(ARCH_CPU_X86_FAMILY) 328 #if defined(OS_CHROMEOS) && defined(ARCH_CPU_X86_FAMILY)
238 if (!gpu_preferences.disable_vaapi_accelerated_video_encode) 329 if (!gpu_preferences.disable_vaapi_accelerated_video_encode)
239 vea_factory_functions.push_back(base::Bind(&CreateVaapiVEA)); 330 vea_factory_functions.push_back(base::Bind(&CreateVaapiVEA));
240 #endif 331 #endif
241 #if defined(OS_ANDROID) && defined(ENABLE_WEBRTC) 332 #if defined(OS_ANDROID) && defined(ENABLE_WEBRTC)
242 if (!gpu_preferences.disable_web_rtc_hw_encoding) 333 if (!gpu_preferences.disable_web_rtc_hw_encoding)
243 vea_factory_functions.push_back(base::Bind(&CreateAndroidVEA)); 334 vea_factory_functions.push_back(base::Bind(&CreateAndroidVEA));
244 #endif 335 #endif
245 #if defined(OS_MACOSX) 336 #if defined(OS_MACOSX)
246 vea_factory_functions.push_back(base::Bind(&CreateVTVEA)); 337 vea_factory_functions.push_back(base::Bind(&CreateVTVEA));
247 #endif 338 #endif
248 #if defined(OS_WIN) 339 #if defined(OS_WIN)
249 if (base::FeatureList::IsEnabled(kMediaFoundationH264Encoding)) 340 if (base::FeatureList::IsEnabled(kMediaFoundationH264Encoding))
250 vea_factory_functions.push_back(base::Bind(&CreateMediaFoundationVEA)); 341 vea_factory_functions.push_back(base::Bind(&CreateMediaFoundationVEA));
251 #endif 342 #endif
252 return vea_factory_functions; 343 return vea_factory_functions;
253 } 344 }
254 345
255 void GpuVideoEncodeAccelerator::OnEncode( 346 void GpuVideoEncodeAccelerator::OnEncode(
256 const AcceleratedVideoEncoderMsg_Encode_Params& params) { 347 const AcceleratedVideoEncoderMsg_Encode_Params& params) {
348 DCHECK(CheckCalledOnMessageFilterThread());
257 DVLOG(3) << __FUNCTION__ << " frame_id = " << params.frame_id 349 DVLOG(3) << __FUNCTION__ << " frame_id = " << params.frame_id
258 << ", buffer_size=" << params.buffer_size 350 << ", buffer_size=" << params.buffer_size
259 << ", force_keyframe=" << params.force_keyframe; 351 << ", force_keyframe=" << params.force_keyframe;
260 DCHECK_EQ(PIXEL_FORMAT_I420, input_format_); 352 DCHECK_EQ(PIXEL_FORMAT_I420, input_format_);
261 353
262 // Wrap into a SharedMemory in the beginning, so that |params.buffer_handle| 354 // Wrap into a SharedMemory in the beginning, so that |params.buffer_handle|
263 // is cleaned properly in case of an early return. 355 // is cleaned properly in case of an early return.
264 std::unique_ptr<base::SharedMemory> shm( 356 std::unique_ptr<base::SharedMemory> shm(
265 new base::SharedMemory(params.buffer_handle, true)); 357 new base::SharedMemory(params.buffer_handle, true));
266 358
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
307 frame->AddDestructionObserver(BindToCurrentLoop(base::Bind( 399 frame->AddDestructionObserver(BindToCurrentLoop(base::Bind(
308 &GpuVideoEncodeAccelerator::EncodeFrameFinished, 400 &GpuVideoEncodeAccelerator::EncodeFrameFinished,
309 weak_this_factory_.GetWeakPtr(), params.frame_id, base::Passed(&shm)))); 401 weak_this_factory_.GetWeakPtr(), params.frame_id, base::Passed(&shm))));
310 encoder_->Encode(frame, params.force_keyframe); 402 encoder_->Encode(frame, params.force_keyframe);
311 } 403 }
312 404
313 void GpuVideoEncodeAccelerator::OnUseOutputBitstreamBuffer( 405 void GpuVideoEncodeAccelerator::OnUseOutputBitstreamBuffer(
314 int32_t buffer_id, 406 int32_t buffer_id,
315 base::SharedMemoryHandle buffer_handle, 407 base::SharedMemoryHandle buffer_handle,
316 uint32_t buffer_size) { 408 uint32_t buffer_size) {
409 DCHECK(CheckCalledOnMessageFilterThread());
317 DVLOG(3) << __FUNCTION__ << " buffer_id=" << buffer_id 410 DVLOG(3) << __FUNCTION__ << " buffer_id=" << buffer_id
318 << ", buffer_size=" << buffer_size; 411 << ", buffer_size=" << buffer_size;
319 if (!encoder_) 412 if (!encoder_)
320 return; 413 return;
321 if (buffer_id < 0) { 414 if (buffer_id < 0) {
322 DLOG(ERROR) << __FUNCTION__ << " invalid buffer_id=" << buffer_id; 415 DLOG(ERROR) << __FUNCTION__ << " invalid buffer_id=" << buffer_id;
323 NotifyError(VideoEncodeAccelerator::kPlatformFailureError); 416 NotifyError(VideoEncodeAccelerator::kPlatformFailureError);
324 return; 417 return;
325 } 418 }
326 if (buffer_size < output_buffer_size_) { 419 if (buffer_size < output_buffer_size_) {
327 DLOG(ERROR) << __FUNCTION__ 420 DLOG(ERROR) << __FUNCTION__
328 << " buffer too small for buffer_id=" << buffer_id; 421 << " buffer too small for buffer_id=" << buffer_id;
329 NotifyError(VideoEncodeAccelerator::kPlatformFailureError); 422 NotifyError(VideoEncodeAccelerator::kPlatformFailureError);
330 return; 423 return;
331 } 424 }
332 encoder_->UseOutputBitstreamBuffer( 425 encoder_->UseOutputBitstreamBuffer(
333 BitstreamBuffer(buffer_id, buffer_handle, buffer_size)); 426 BitstreamBuffer(buffer_id, buffer_handle, buffer_size));
334 } 427 }
335 428
336 void GpuVideoEncodeAccelerator::OnDestroy() { 429 void GpuVideoEncodeAccelerator::OnDestroy() {
430 DCHECK(main_task_runner_->BelongsToCurrentThread());
337 DVLOG(2) << __FUNCTION__; 431 DVLOG(2) << __FUNCTION__;
338 OnWillDestroyStub(); 432 OnWillDestroyStub();
339 } 433 }
340 434
341 void GpuVideoEncodeAccelerator::OnRequestEncodingParametersChange( 435 void GpuVideoEncodeAccelerator::OnRequestEncodingParametersChange(
342 uint32_t bitrate, 436 uint32_t bitrate,
343 uint32_t framerate) { 437 uint32_t framerate) {
438 DCHECK(CheckCalledOnMessageFilterThread());
344 DVLOG(2) << __FUNCTION__ << " bitrate=" << bitrate 439 DVLOG(2) << __FUNCTION__ << " bitrate=" << bitrate
345 << ", framerate=" << framerate; 440 << ", framerate=" << framerate;
346 if (!encoder_) 441 if (!encoder_)
347 return; 442 return;
348 encoder_->RequestEncodingParametersChange(bitrate, framerate); 443 encoder_->RequestEncodingParametersChange(bitrate, framerate);
349 } 444 }
350 445
351 void GpuVideoEncodeAccelerator::EncodeFrameFinished( 446 void GpuVideoEncodeAccelerator::EncodeFrameFinished(
352 int32_t frame_id, 447 int32_t frame_id,
353 std::unique_ptr<base::SharedMemory> shm) { 448 std::unique_ptr<base::SharedMemory> shm) {
354 Send(new AcceleratedVideoEncoderHostMsg_NotifyInputDone(host_route_id_, 449 DCHECK(CheckCalledOnMessageFilterThread());
355 frame_id)); 450 if (!Send(new AcceleratedVideoEncoderHostMsg_NotifyInputDone(host_route_id_,
451 frame_id))) {
452 DLOG(ERROR) << __func__ << " failed.";
453 }
356 // Just let |shm| fall out of scope. 454 // Just let |shm| fall out of scope.
357 } 455 }
358 456
359 void GpuVideoEncodeAccelerator::Send(IPC::Message* message) { 457 bool GpuVideoEncodeAccelerator::Send(IPC::Message* message) {
360 stub_->channel()->Send(message); 458 if (filter_ && io_task_runner_->BelongsToCurrentThread()) {
459 DCHECK(io_task_runner_->BelongsToCurrentThread());
sandersd (OOO until July 31) 2016/10/21 18:41:03 DCHECK() is redundant.
emircan 2016/10/24 19:44:52 Done.
460 return filter_->SendOnIOThread(message);
461 }
462 DCHECK(main_task_runner_->BelongsToCurrentThread());
463 return stub_->channel()->Send(message);
464 }
465
466 bool GpuVideoEncodeAccelerator::CheckCalledOnMessageFilterThread() {
467 return (io_task_runner_->BelongsToCurrentThread() && filter_) ||
468 (main_task_runner_->BelongsToCurrentThread() && !filter_);
sandersd (OOO until July 31) 2016/10/21 18:41:03 Nit: Putting |filter_| condition first makes more
emircan 2016/10/24 19:44:52 Done.
361 } 469 }
362 470
363 } // namespace media 471 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698