| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 // The bulk of this file is support code; sorry about that. Here's an overview | 5 // The bulk of this file is support code; sorry about that. Here's an overview |
| 6 // to hopefully help readers of this code: | 6 // to hopefully help readers of this code: |
| 7 // - RenderingHelper is charged with interacting with X11/{EGL/GLES2,GLX/GL} or | 7 // - RenderingHelper is charged with interacting with X11/{EGL/GLES2,GLX/GL} or |
| 8 // Win/EGL. | 8 // Win/EGL. |
| 9 // - ClientState is an enum for the state of the decode client used by the test. | 9 // - ClientState is an enum for the state of the decode client used by the test. |
| 10 // - ClientStateNotification is a barrier abstraction that allows the test code | 10 // - ClientStateNotification is a barrier abstraction that allows the test code |
| (...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 196 CS_RESETTING = 5, | 196 CS_RESETTING = 5, |
| 197 CS_RESET = 6, | 197 CS_RESET = 6, |
| 198 CS_ERROR = 7, | 198 CS_ERROR = 7, |
| 199 CS_DESTROYED = 8, | 199 CS_DESTROYED = 8, |
| 200 CS_MAX, // Must be last entry. | 200 CS_MAX, // Must be last entry. |
| 201 }; | 201 }; |
| 202 | 202 |
| 203 // A helper class used to manage the lifetime of a Texture. | 203 // A helper class used to manage the lifetime of a Texture. |
| 204 class TextureRef : public base::RefCounted<TextureRef> { | 204 class TextureRef : public base::RefCounted<TextureRef> { |
| 205 public: | 205 public: |
| 206 TextureRef(uint32 texture_id, const base::Closure& no_longer_needed_cb) | 206 TextureRef(const base::Closure& no_longer_needed_cb) |
| 207 : texture_id_(texture_id), no_longer_needed_cb_(no_longer_needed_cb) {} | 207 : no_longer_needed_cb_(no_longer_needed_cb) {} |
| 208 | |
| 209 int32 texture_id() const { return texture_id_; } | |
| 210 | 208 |
| 211 private: | 209 private: |
| 212 friend class base::RefCounted<TextureRef>; | 210 friend class base::RefCounted<TextureRef>; |
| 213 ~TextureRef(); | 211 ~TextureRef(); |
| 214 | |
| 215 uint32 texture_id_; | |
| 216 base::Closure no_longer_needed_cb_; | 212 base::Closure no_longer_needed_cb_; |
| 217 }; | 213 }; |
| 218 | 214 |
| 219 TextureRef::~TextureRef() { | 215 TextureRef::~TextureRef() { |
| 220 base::ResetAndReturn(&no_longer_needed_cb_).Run(); | 216 base::ResetAndReturn(&no_longer_needed_cb_).Run(); |
| 221 } | 217 } |
| 222 | 218 |
| 223 // Client that can accept callbacks from a VideoDecodeAccelerator and is used by | 219 // Client that can accept callbacks from a VideoDecodeAccelerator and is used by |
| 224 // the TESTs below. | 220 // the TESTs below. |
| 225 class GLRenderingVDAClient | 221 class GLRenderingVDAClient |
| (...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 355 // DismissPictureBuffer(). The keys in the map are the IDs of the | 351 // DismissPictureBuffer(). The keys in the map are the IDs of the |
| 356 // corresponding picture buffers, and the values are TextureRefs to the | 352 // corresponding picture buffers, and the values are TextureRefs to the |
| 357 // textures. | 353 // textures. |
| 358 TextureRefMap active_textures_; | 354 TextureRefMap active_textures_; |
| 359 | 355 |
| 360 // A map of the textures that are still pending in the renderer. | 356 // A map of the textures that are still pending in the renderer. |
| 361 // We check this to ensure all frames are rendered before entering the | 357 // We check this to ensure all frames are rendered before entering the |
| 362 // CS_RESET_State. | 358 // CS_RESET_State. |
| 363 TextureRefMap pending_textures_; | 359 TextureRefMap pending_textures_; |
| 364 | 360 |
| 365 int32 next_picture_buffer_id_; | |
| 366 | |
| 367 DISALLOW_IMPLICIT_CONSTRUCTORS(GLRenderingVDAClient); | 361 DISALLOW_IMPLICIT_CONSTRUCTORS(GLRenderingVDAClient); |
| 368 }; | 362 }; |
| 369 | 363 |
| 370 GLRenderingVDAClient::GLRenderingVDAClient( | 364 GLRenderingVDAClient::GLRenderingVDAClient( |
| 371 size_t window_id, | 365 size_t window_id, |
| 372 RenderingHelper* rendering_helper, | 366 RenderingHelper* rendering_helper, |
| 373 ClientStateNotification<ClientState>* note, | 367 ClientStateNotification<ClientState>* note, |
| 374 const std::string& encoded_data, | 368 const std::string& encoded_data, |
| 375 int num_in_flight_decodes, | 369 int num_in_flight_decodes, |
| 376 int num_play_throughs, | 370 int num_play_throughs, |
| (...skipping 20 matching lines...) Expand all Loading... |
| 397 delete_decoder_state_(delete_decoder_state), | 391 delete_decoder_state_(delete_decoder_state), |
| 398 state_(CS_CREATED), | 392 state_(CS_CREATED), |
| 399 num_skipped_fragments_(0), | 393 num_skipped_fragments_(0), |
| 400 num_queued_fragments_(0), | 394 num_queued_fragments_(0), |
| 401 num_decoded_frames_(0), | 395 num_decoded_frames_(0), |
| 402 num_done_bitstream_buffers_(0), | 396 num_done_bitstream_buffers_(0), |
| 403 texture_target_(0), | 397 texture_target_(0), |
| 404 suppress_rendering_(suppress_rendering), | 398 suppress_rendering_(suppress_rendering), |
| 405 delay_reuse_after_frame_num_(delay_reuse_after_frame_num), | 399 delay_reuse_after_frame_num_(delay_reuse_after_frame_num), |
| 406 decode_calls_per_second_(decode_calls_per_second), | 400 decode_calls_per_second_(decode_calls_per_second), |
| 407 render_as_thumbnails_(render_as_thumbnails), | 401 render_as_thumbnails_(render_as_thumbnails) { |
| 408 next_picture_buffer_id_(1) { | |
| 409 CHECK_GT(num_in_flight_decodes, 0); | 402 CHECK_GT(num_in_flight_decodes, 0); |
| 410 CHECK_GT(num_play_throughs, 0); | 403 CHECK_GT(num_play_throughs, 0); |
| 411 // |num_in_flight_decodes_| is unsupported if |decode_calls_per_second_| > 0. | 404 // |num_in_flight_decodes_| is unsupported if |decode_calls_per_second_| > 0. |
| 412 if (decode_calls_per_second_ > 0) | 405 if (decode_calls_per_second_ > 0) |
| 413 CHECK_EQ(1, num_in_flight_decodes_); | 406 CHECK_EQ(1, num_in_flight_decodes_); |
| 414 | 407 |
| 415 // Default to H264 baseline if no profile provided. | 408 // Default to H264 baseline if no profile provided. |
| 416 profile_ = (profile != media::VIDEO_CODEC_PROFILE_UNKNOWN | 409 profile_ = (profile != media::VIDEO_CODEC_PROFILE_UNKNOWN |
| 417 ? profile | 410 ? profile |
| 418 : media::H264PROFILE_BASELINE); | 411 : media::H264PROFILE_BASELINE); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 435 new DXVAVideoDecodeAccelerator(base::Bind(&DoNothingReturnTrue))); | 428 new DXVAVideoDecodeAccelerator(base::Bind(&DoNothingReturnTrue))); |
| 436 #endif | 429 #endif |
| 437 return decoder.Pass(); | 430 return decoder.Pass(); |
| 438 } | 431 } |
| 439 | 432 |
| 440 scoped_ptr<media::VideoDecodeAccelerator> | 433 scoped_ptr<media::VideoDecodeAccelerator> |
| 441 GLRenderingVDAClient::CreateV4L2VDA() { | 434 GLRenderingVDAClient::CreateV4L2VDA() { |
| 442 scoped_ptr<media::VideoDecodeAccelerator> decoder; | 435 scoped_ptr<media::VideoDecodeAccelerator> decoder; |
| 443 #if defined(OS_CHROMEOS) && (defined(ARCH_CPU_ARMEL) || \ | 436 #if defined(OS_CHROMEOS) && (defined(ARCH_CPU_ARMEL) || \ |
| 444 (defined(USE_OZONE) && defined(USE_V4L2_CODEC))) | 437 (defined(USE_OZONE) && defined(USE_V4L2_CODEC))) |
| 445 scoped_refptr<V4L2Device> device = V4L2Device::Create(V4L2Device::kDecoder); | 438 scoped_ptr<V4L2Device> device = V4L2Device::Create(V4L2Device::kDecoder); |
| 446 if (device.get()) { | 439 if (device.get()) { |
| 447 base::WeakPtr<VideoDecodeAccelerator::Client> weak_client = AsWeakPtr(); | 440 base::WeakPtr<VideoDecodeAccelerator::Client> weak_client = AsWeakPtr(); |
| 448 decoder.reset(new V4L2VideoDecodeAccelerator( | 441 decoder.reset(new V4L2VideoDecodeAccelerator( |
| 449 static_cast<EGLDisplay>(rendering_helper_->GetGLDisplay()), | 442 static_cast<EGLDisplay>(rendering_helper_->GetGLDisplay()), |
| 450 static_cast<EGLContext>(rendering_helper_->GetGLContextHandle()), | 443 static_cast<EGLContext>(rendering_helper_->GetGLContextHandle()), |
| 451 weak_client, | 444 weak_client, |
| 452 base::Bind(&DoNothingReturnTrue), | 445 base::Bind(&DoNothingReturnTrue), |
| 453 device, | 446 device.Pass(), |
| 454 base::MessageLoopProxy::current())); | 447 base::MessageLoopProxy::current())); |
| 455 } | 448 } |
| 456 #endif | 449 #endif |
| 457 return decoder.Pass(); | 450 return decoder.Pass(); |
| 458 } | 451 } |
| 459 | 452 |
| 460 scoped_ptr<media::VideoDecodeAccelerator> | 453 scoped_ptr<media::VideoDecodeAccelerator> |
| 461 GLRenderingVDAClient::CreateVaapiVDA() { | 454 GLRenderingVDAClient::CreateVaapiVDA() { |
| 462 scoped_ptr<media::VideoDecodeAccelerator> decoder; | 455 scoped_ptr<media::VideoDecodeAccelerator> decoder; |
| 463 #if defined(OS_CHROMEOS) && defined(ARCH_CPU_X86_FAMILY) | 456 #if defined(OS_CHROMEOS) && defined(ARCH_CPU_X86_FAMILY) |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 505 std::vector<media::PictureBuffer> buffers; | 498 std::vector<media::PictureBuffer> buffers; |
| 506 | 499 |
| 507 texture_target_ = texture_target; | 500 texture_target_ = texture_target; |
| 508 for (uint32 i = 0; i < requested_num_of_buffers; ++i) { | 501 for (uint32 i = 0; i < requested_num_of_buffers; ++i) { |
| 509 uint32 texture_id; | 502 uint32 texture_id; |
| 510 base::WaitableEvent done(false, false); | 503 base::WaitableEvent done(false, false); |
| 511 rendering_helper_->CreateTexture( | 504 rendering_helper_->CreateTexture( |
| 512 texture_target_, &texture_id, dimensions, &done); | 505 texture_target_, &texture_id, dimensions, &done); |
| 513 done.Wait(); | 506 done.Wait(); |
| 514 | 507 |
| 515 int32 picture_buffer_id = next_picture_buffer_id_++; | 508 // Use the texture_id as the picture's id. |
| 516 CHECK(active_textures_ | 509 int32 id = static_cast<int32>(texture_id); |
| 517 .insert(std::make_pair( | 510 CHECK( |
| 518 picture_buffer_id, | 511 active_textures_.insert(std::make_pair( |
| 519 new TextureRef(texture_id, | 512 id, new TextureRef(base::Bind( |
| 520 base::Bind(&RenderingHelper::DeleteTexture, | 513 &RenderingHelper::DeleteTexture, |
| 521 base::Unretained(rendering_helper_), | 514 base::Unretained(rendering_helper_), |
| 522 texture_id)))) | 515 texture_id)))).second); |
| 523 .second); | |
| 524 | 516 |
| 525 buffers.push_back( | 517 buffers.push_back(media::PictureBuffer(id, dimensions, texture_id)); |
| 526 media::PictureBuffer(picture_buffer_id, dimensions, texture_id)); | |
| 527 } | 518 } |
| 528 decoder_->AssignPictureBuffers(buffers); | 519 decoder_->AssignPictureBuffers(buffers); |
| 529 } | 520 } |
| 530 | 521 |
| 531 void GLRenderingVDAClient::DismissPictureBuffer(int32 picture_buffer_id) { | 522 void GLRenderingVDAClient::DismissPictureBuffer(int32 picture_buffer_id) { |
| 532 CHECK_EQ(1U, active_textures_.erase(picture_buffer_id)); | 523 CHECK_EQ(1U, active_textures_.erase(picture_buffer_id)); |
| 533 } | 524 } |
| 534 | 525 |
| 535 void GLRenderingVDAClient::PictureReady(const media::Picture& picture) { | 526 void GLRenderingVDAClient::PictureReady(const media::Picture& picture) { |
| 536 // We shouldn't be getting pictures delivered after Reset has completed. | 527 // We shouldn't be getting pictures delivered after Reset has completed. |
| (...skipping 25 matching lines...) Expand all Loading... |
| 562 // Re-start decoding from the beginning of the stream to avoid needing to | 553 // Re-start decoding from the beginning of the stream to avoid needing to |
| 563 // know how to find I-frames and so on in this test. | 554 // know how to find I-frames and so on in this test. |
| 564 encoded_data_next_pos_to_decode_ = 0; | 555 encoded_data_next_pos_to_decode_ = 0; |
| 565 } | 556 } |
| 566 | 557 |
| 567 TextureRefMap::iterator texture_it = | 558 TextureRefMap::iterator texture_it = |
| 568 active_textures_.find(picture.picture_buffer_id()); | 559 active_textures_.find(picture.picture_buffer_id()); |
| 569 ASSERT_NE(active_textures_.end(), texture_it); | 560 ASSERT_NE(active_textures_.end(), texture_it); |
| 570 | 561 |
| 571 scoped_refptr<VideoFrameTexture> video_frame = new VideoFrameTexture( | 562 scoped_refptr<VideoFrameTexture> video_frame = new VideoFrameTexture( |
| 572 texture_target_, texture_it->second->texture_id(), | 563 texture_target_, |
| 564 static_cast<uint32>(texture_it->first), // the texture id |
| 573 base::Bind(&GLRenderingVDAClient::ReturnPicture, AsWeakPtr(), | 565 base::Bind(&GLRenderingVDAClient::ReturnPicture, AsWeakPtr(), |
| 574 picture.picture_buffer_id())); | 566 picture.picture_buffer_id())); |
| 575 ASSERT_TRUE(pending_textures_.insert(*texture_it).second); | 567 ASSERT_TRUE(pending_textures_.insert(*texture_it).second); |
| 576 | 568 |
| 577 if (render_as_thumbnails_) { | 569 if (render_as_thumbnails_) { |
| 578 rendering_helper_->RenderThumbnail(video_frame->texture_target(), | 570 rendering_helper_->RenderThumbnail(video_frame->texture_target(), |
| 579 video_frame->texture_id()); | 571 video_frame->texture_id()); |
| 580 } else if (!suppress_rendering_) { | 572 } else if (!suppress_rendering_) { |
| 581 rendering_helper_->QueueVideoFrame(window_id_, video_frame); | 573 rendering_helper_->QueueVideoFrame(window_id_, video_frame); |
| 582 } | 574 } |
| (...skipping 939 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1522 if (it->first == "ozone-platform" || it->first == "ozone-use-surfaceless") | 1514 if (it->first == "ozone-platform" || it->first == "ozone-use-surfaceless") |
| 1523 continue; | 1515 continue; |
| 1524 LOG(FATAL) << "Unexpected switch: " << it->first << ":" << it->second; | 1516 LOG(FATAL) << "Unexpected switch: " << it->first << ":" << it->second; |
| 1525 } | 1517 } |
| 1526 | 1518 |
| 1527 base::ShadowingAtExitManager at_exit_manager; | 1519 base::ShadowingAtExitManager at_exit_manager; |
| 1528 content::RenderingHelper::InitializeOneOff(); | 1520 content::RenderingHelper::InitializeOneOff(); |
| 1529 | 1521 |
| 1530 return RUN_ALL_TESTS(); | 1522 return RUN_ALL_TESTS(); |
| 1531 } | 1523 } |
| OLD | NEW |