OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/renderer/pepper/video_decoder_shim.h" | 5 #include "content/renderer/pepper/video_decoder_shim.h" |
6 | 6 |
7 #include <GLES2/gl2.h> | 7 #include <GLES2/gl2.h> |
8 #include <GLES2/gl2ext.h> | 8 #include <GLES2/gl2ext.h> |
9 #include <GLES2/gl2extchromium.h> | 9 #include <GLES2/gl2extchromium.h> |
10 | 10 |
11 #include "base/bind.h" | 11 #include "base/bind.h" |
12 #include "base/numerics/safe_conversions.h" | 12 #include "base/numerics/safe_conversions.h" |
| 13 #include "base/single_thread_task_runner.h" |
13 #include "content/public/renderer/render_thread.h" | 14 #include "content/public/renderer/render_thread.h" |
14 #include "content/renderer/pepper/pepper_video_decoder_host.h" | 15 #include "content/renderer/pepper/pepper_video_decoder_host.h" |
15 #include "content/renderer/render_thread_impl.h" | 16 #include "content/renderer/render_thread_impl.h" |
16 #include "gpu/command_buffer/client/gles2_implementation.h" | 17 #include "gpu/command_buffer/client/gles2_implementation.h" |
17 #include "media/base/decoder_buffer.h" | 18 #include "media/base/decoder_buffer.h" |
18 #include "media/base/limits.h" | 19 #include "media/base/limits.h" |
19 #include "media/base/video_decoder.h" | 20 #include "media/base/video_decoder.h" |
20 #include "media/filters/ffmpeg_video_decoder.h" | 21 #include "media/filters/ffmpeg_video_decoder.h" |
21 #include "media/filters/vpx_video_decoder.h" | 22 #include "media/filters/vpx_video_decoder.h" |
22 #include "media/video/picture.h" | 23 #include "media/video/picture.h" |
(...skipping 264 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
287 } | 288 } |
288 | 289 |
289 void VideoDecoderShim::DecoderImpl::OnResetComplete() { | 290 void VideoDecoderShim::DecoderImpl::OnResetComplete() { |
290 main_message_loop_->PostTask( | 291 main_message_loop_->PostTask( |
291 FROM_HERE, base::Bind(&VideoDecoderShim::OnResetComplete, shim_)); | 292 FROM_HERE, base::Bind(&VideoDecoderShim::OnResetComplete, shim_)); |
292 } | 293 } |
293 | 294 |
294 VideoDecoderShim::VideoDecoderShim(PepperVideoDecoderHost* host) | 295 VideoDecoderShim::VideoDecoderShim(PepperVideoDecoderHost* host) |
295 : state_(UNINITIALIZED), | 296 : state_(UNINITIALIZED), |
296 host_(host), | 297 host_(host), |
297 media_message_loop_( | 298 media_task_runner_( |
298 RenderThreadImpl::current()->GetMediaThreadMessageLoopProxy()), | 299 RenderThreadImpl::current()->GetMediaThreadTaskRunner()), |
299 context_provider_( | 300 context_provider_( |
300 RenderThreadImpl::current()->SharedMainThreadContextProvider()), | 301 RenderThreadImpl::current()->SharedMainThreadContextProvider()), |
301 texture_pool_size_(0), | 302 texture_pool_size_(0), |
302 num_pending_decodes_(0), | 303 num_pending_decodes_(0), |
303 weak_ptr_factory_(this) { | 304 weak_ptr_factory_(this) { |
304 DCHECK(host_); | 305 DCHECK(host_); |
305 DCHECK(media_message_loop_.get()); | 306 DCHECK(media_task_runner_.get()); |
306 DCHECK(context_provider_.get()); | 307 DCHECK(context_provider_.get()); |
307 decoder_impl_.reset(new DecoderImpl(weak_ptr_factory_.GetWeakPtr())); | 308 decoder_impl_.reset(new DecoderImpl(weak_ptr_factory_.GetWeakPtr())); |
308 } | 309 } |
309 | 310 |
310 VideoDecoderShim::~VideoDecoderShim() { | 311 VideoDecoderShim::~VideoDecoderShim() { |
311 DCHECK(RenderThreadImpl::current()); | 312 DCHECK(RenderThreadImpl::current()); |
312 // Delete any remaining textures. | 313 // Delete any remaining textures. |
313 TextureIdMap::iterator it = texture_id_map_.begin(); | 314 TextureIdMap::iterator it = texture_id_map_.begin(); |
314 for (; it != texture_id_map_.end(); ++it) | 315 for (; it != texture_id_map_.end(); ++it) |
315 DeleteTexture(it->second); | 316 DeleteTexture(it->second); |
316 texture_id_map_.clear(); | 317 texture_id_map_.clear(); |
317 | 318 |
318 FlushCommandBuffer(); | 319 FlushCommandBuffer(); |
319 | 320 |
320 weak_ptr_factory_.InvalidateWeakPtrs(); | 321 weak_ptr_factory_.InvalidateWeakPtrs(); |
321 // No more callbacks from the delegate will be received now. | 322 // No more callbacks from the delegate will be received now. |
322 | 323 |
323 // The callback now holds the only reference to the DecoderImpl, which will be | 324 // The callback now holds the only reference to the DecoderImpl, which will be |
324 // deleted when Stop completes. | 325 // deleted when Stop completes. |
325 media_message_loop_->PostTask( | 326 media_task_runner_->PostTask( |
326 FROM_HERE, | 327 FROM_HERE, |
327 base::Bind(&VideoDecoderShim::DecoderImpl::Stop, | 328 base::Bind(&VideoDecoderShim::DecoderImpl::Stop, |
328 base::Owned(decoder_impl_.release()))); | 329 base::Owned(decoder_impl_.release()))); |
329 } | 330 } |
330 | 331 |
331 bool VideoDecoderShim::Initialize( | 332 bool VideoDecoderShim::Initialize( |
332 media::VideoCodecProfile profile, | 333 media::VideoCodecProfile profile, |
333 media::VideoDecodeAccelerator::Client* client) { | 334 media::VideoDecodeAccelerator::Client* client) { |
334 DCHECK_EQ(client, host_); | 335 DCHECK_EQ(client, host_); |
335 DCHECK(RenderThreadImpl::current()); | 336 DCHECK(RenderThreadImpl::current()); |
(...skipping 11 matching lines...) Expand all Loading... |
347 codec, | 348 codec, |
348 profile, | 349 profile, |
349 media::VideoFrame::YV12, | 350 media::VideoFrame::YV12, |
350 gfx::Size(32, 24), // Small sizes that won't fail. | 351 gfx::Size(32, 24), // Small sizes that won't fail. |
351 gfx::Rect(32, 24), | 352 gfx::Rect(32, 24), |
352 gfx::Size(32, 24), | 353 gfx::Size(32, 24), |
353 NULL /* extra_data */, // TODO(bbudge) Verify this isn't needed. | 354 NULL /* extra_data */, // TODO(bbudge) Verify this isn't needed. |
354 0 /* extra_data_size */, | 355 0 /* extra_data_size */, |
355 false /* decryption */); | 356 false /* decryption */); |
356 | 357 |
357 media_message_loop_->PostTask( | 358 media_task_runner_->PostTask( |
358 FROM_HERE, | 359 FROM_HERE, |
359 base::Bind(&VideoDecoderShim::DecoderImpl::Initialize, | 360 base::Bind(&VideoDecoderShim::DecoderImpl::Initialize, |
360 base::Unretained(decoder_impl_.get()), | 361 base::Unretained(decoder_impl_.get()), |
361 config)); | 362 config)); |
362 // Return success, even though we are asynchronous, to mimic | 363 // Return success, even though we are asynchronous, to mimic |
363 // media::VideoDecodeAccelerator. | 364 // media::VideoDecodeAccelerator. |
364 return true; | 365 return true; |
365 } | 366 } |
366 | 367 |
367 void VideoDecoderShim::Decode(const media::BitstreamBuffer& bitstream_buffer) { | 368 void VideoDecoderShim::Decode(const media::BitstreamBuffer& bitstream_buffer) { |
368 DCHECK(RenderThreadImpl::current()); | 369 DCHECK(RenderThreadImpl::current()); |
369 DCHECK_EQ(state_, DECODING); | 370 DCHECK_EQ(state_, DECODING); |
370 | 371 |
371 // We need the address of the shared memory, so we can copy the buffer. | 372 // We need the address of the shared memory, so we can copy the buffer. |
372 const uint8_t* buffer = host_->DecodeIdToAddress(bitstream_buffer.id()); | 373 const uint8_t* buffer = host_->DecodeIdToAddress(bitstream_buffer.id()); |
373 DCHECK(buffer); | 374 DCHECK(buffer); |
374 | 375 |
375 media_message_loop_->PostTask( | 376 media_task_runner_->PostTask( |
376 FROM_HERE, | 377 FROM_HERE, |
377 base::Bind( | 378 base::Bind( |
378 &VideoDecoderShim::DecoderImpl::Decode, | 379 &VideoDecoderShim::DecoderImpl::Decode, |
379 base::Unretained(decoder_impl_.get()), | 380 base::Unretained(decoder_impl_.get()), |
380 bitstream_buffer.id(), | 381 bitstream_buffer.id(), |
381 media::DecoderBuffer::CopyFrom(buffer, bitstream_buffer.size()))); | 382 media::DecoderBuffer::CopyFrom(buffer, bitstream_buffer.size()))); |
382 num_pending_decodes_++; | 383 num_pending_decodes_++; |
383 } | 384 } |
384 | 385 |
385 void VideoDecoderShim::AssignPictureBuffers( | 386 void VideoDecoderShim::AssignPictureBuffers( |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
422 void VideoDecoderShim::Flush() { | 423 void VideoDecoderShim::Flush() { |
423 DCHECK(RenderThreadImpl::current()); | 424 DCHECK(RenderThreadImpl::current()); |
424 DCHECK_EQ(state_, DECODING); | 425 DCHECK_EQ(state_, DECODING); |
425 state_ = FLUSHING; | 426 state_ = FLUSHING; |
426 } | 427 } |
427 | 428 |
428 void VideoDecoderShim::Reset() { | 429 void VideoDecoderShim::Reset() { |
429 DCHECK(RenderThreadImpl::current()); | 430 DCHECK(RenderThreadImpl::current()); |
430 DCHECK_EQ(state_, DECODING); | 431 DCHECK_EQ(state_, DECODING); |
431 state_ = RESETTING; | 432 state_ = RESETTING; |
432 media_message_loop_->PostTask( | 433 media_task_runner_->PostTask( |
433 FROM_HERE, | 434 FROM_HERE, |
434 base::Bind(&VideoDecoderShim::DecoderImpl::Reset, | 435 base::Bind(&VideoDecoderShim::DecoderImpl::Reset, |
435 base::Unretained(decoder_impl_.get()))); | 436 base::Unretained(decoder_impl_.get()))); |
436 } | 437 } |
437 | 438 |
438 void VideoDecoderShim::Destroy() { | 439 void VideoDecoderShim::Destroy() { |
439 // This will be called, but our destructor does the actual work. | 440 // This will be called, but our destructor does the actual work. |
440 } | 441 } |
441 | 442 |
442 void VideoDecoderShim::OnInitializeComplete(int32_t result, | 443 void VideoDecoderShim::OnInitializeComplete(int32_t result, |
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
587 void VideoDecoderShim::DeleteTexture(uint32_t texture_id) { | 588 void VideoDecoderShim::DeleteTexture(uint32_t texture_id) { |
588 gpu::gles2::GLES2Interface* gles2 = context_provider_->ContextGL(); | 589 gpu::gles2::GLES2Interface* gles2 = context_provider_->ContextGL(); |
589 gles2->DeleteTextures(1, &texture_id); | 590 gles2->DeleteTextures(1, &texture_id); |
590 } | 591 } |
591 | 592 |
592 void VideoDecoderShim::FlushCommandBuffer() { | 593 void VideoDecoderShim::FlushCommandBuffer() { |
593 context_provider_->ContextGL()->Flush(); | 594 context_provider_->ContextGL()->Flush(); |
594 } | 595 } |
595 | 596 |
596 } // namespace content | 597 } // namespace content |
OLD | NEW |