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