diff options
author | hclam <hclam@chromium.org> | 2014-09-10 13:29:01 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2014-09-10 20:38:46 +0000 |
commit | 42d3637eb8a7a82ac5a3183272224b6c2b5f2249 (patch) | |
tree | 6e29ef15ca86a6cd09ea35e5ecbaff759dd76380 | |
parent | 660e22c9b046890cb64947d0942469ea3b5003e2 (diff) | |
download | chromium_src-42d3637eb8a7a82ac5a3183272224b6c2b5f2249.zip chromium_src-42d3637eb8a7a82ac5a3183272224b6c2b5f2249.tar.gz chromium_src-42d3637eb8a7a82ac5a3183272224b6c2b5f2249.tar.bz2 |
Cast: Flow hw encoder initialization error to extensions API
cast.streaming API will be notified if there is a hardware
initialization error. This way extension can decide whether to restart
with a different codec or just fail.
Also fixed a small issue that Framer is printing too many messages.
BUG=402182
Review URL: https://codereview.chromium.org/555563003
Cr-Commit-Position: refs/heads/master@{#294216}
-rw-r--r-- | chrome/renderer/media/cast_session_delegate.cc | 46 | ||||
-rw-r--r-- | chrome/renderer/media/cast_session_delegate.h | 1 | ||||
-rw-r--r-- | media/cast/cast_defines.h | 3 | ||||
-rw-r--r-- | media/cast/cast_sender_impl.cc | 31 | ||||
-rw-r--r-- | media/cast/cast_sender_impl.h | 5 | ||||
-rw-r--r-- | media/cast/net/rtp/framer.cc | 2 | ||||
-rw-r--r-- | media/cast/sender/external_video_encoder.cc | 20 | ||||
-rw-r--r-- | media/cast/sender/external_video_encoder.h | 7 | ||||
-rw-r--r-- | media/cast/sender/external_video_encoder_unittest.cc | 4 | ||||
-rw-r--r-- | media/cast/sender/video_sender.cc | 29 | ||||
-rw-r--r-- | media/cast/sender/video_sender.h | 10 | ||||
-rw-r--r-- | media/cast/sender/video_sender_unittest.cc | 56 | ||||
-rw-r--r-- | media/cast/test/end2end_unittest.cc | 1 | ||||
-rw-r--r-- | media/cast/test/fake_video_encode_accelerator.cc | 3 | ||||
-rw-r--r-- | media/cast/test/fake_video_encode_accelerator.h | 4 | ||||
-rw-r--r-- | media/cast/test/simulator.cc | 1 |
16 files changed, 164 insertions, 59 deletions
diff --git a/chrome/renderer/media/cast_session_delegate.cc b/chrome/renderer/media/cast_session_delegate.cc index 9e0e10e..c90982c 100644 --- a/chrome/renderer/media/cast_session_delegate.cc +++ b/chrome/renderer/media/cast_session_delegate.cc @@ -55,7 +55,7 @@ void CastSessionDelegate::StartAudio( cast_sender_->InitializeAudio( config, base::Bind(&CastSessionDelegate::InitializationResultCB, - weak_factory_.GetWeakPtr())); + weak_factory_.GetWeakPtr(), error_callback)); } void CastSessionDelegate::StartVideo( @@ -77,7 +77,7 @@ void CastSessionDelegate::StartVideo( cast_sender_->InitializeVideo( config, base::Bind(&CastSessionDelegate::InitializationResultCB, - weak_factory_.GetWeakPtr()), + weak_factory_.GetWeakPtr(), error_callback), create_vea_cb, create_video_encode_mem_cb); } @@ -205,16 +205,44 @@ void CastSessionDelegate::StatusNotificationCB( } void CastSessionDelegate::InitializationResultCB( + const ErrorCallback& error_callback, media::cast::CastInitializationStatus result) const { DCHECK(cast_sender_); - // TODO(pwestin): handle the error codes. - if (result == media::cast::STATUS_AUDIO_INITIALIZED) { - audio_frame_input_available_callback_.Run( - cast_sender_->audio_frame_input()); - } else if (result == media::cast::STATUS_VIDEO_INITIALIZED) { - video_frame_input_available_callback_.Run( - cast_sender_->video_frame_input()); + switch (result) { + case media::cast::STATUS_AUDIO_INITIALIZED: + audio_frame_input_available_callback_.Run( + cast_sender_->audio_frame_input()); + break; + case media::cast::STATUS_VIDEO_INITIALIZED: + video_frame_input_available_callback_.Run( + cast_sender_->video_frame_input()); + break; + case media::cast::STATUS_INVALID_CAST_ENVIRONMENT: + error_callback.Run("Invalid cast environment."); + break; + case media::cast::STATUS_INVALID_CRYPTO_CONFIGURATION: + error_callback.Run("Invalid encryption keys."); + break; + case media::cast::STATUS_UNSUPPORTED_AUDIO_CODEC: + error_callback.Run("Audio codec not supported."); + break; + case media::cast::STATUS_UNSUPPORTED_VIDEO_CODEC: + error_callback.Run("Video codec not supported."); + break; + case media::cast::STATUS_INVALID_AUDIO_CONFIGURATION: + error_callback.Run("Invalid audio configuration."); + break; + case media::cast::STATUS_INVALID_VIDEO_CONFIGURATION: + error_callback.Run("Invalid video configuration."); + break; + case media::cast::STATUS_HW_VIDEO_ENCODER_NOT_SUPPORTED: + error_callback.Run("Hardware video encoder not supported."); + break; + case media::cast::STATUS_AUDIO_UNINITIALIZED: + case media::cast::STATUS_VIDEO_UNINITIALIZED: + NOTREACHED() << "Not an error."; + break; } } diff --git a/chrome/renderer/media/cast_session_delegate.h b/chrome/renderer/media/cast_session_delegate.h index c027dff..a89892c 100644 --- a/chrome/renderer/media/cast_session_delegate.h +++ b/chrome/renderer/media/cast_session_delegate.h @@ -90,6 +90,7 @@ class CastSessionDelegate { // If this callback is called with STATUS_INITIALIZED it will report back // to the sinks that it's ready to accept incoming audio / video frames. void InitializationResultCB( + const ErrorCallback& error_callback, media::cast::CastInitializationStatus result) const; private: diff --git a/media/cast/cast_defines.h b/media/cast/cast_defines.h index c2016f7..76e2527 100644 --- a/media/cast/cast_defines.h +++ b/media/cast/cast_defines.h @@ -46,8 +46,7 @@ enum CastInitializationStatus { STATUS_UNSUPPORTED_VIDEO_CODEC, STATUS_INVALID_AUDIO_CONFIGURATION, STATUS_INVALID_VIDEO_CONFIGURATION, - STATUS_GPU_ACCELERATION_NOT_SUPPORTED, - STATUS_GPU_ACCELERATION_ERROR, + STATUS_HW_VIDEO_ENCODER_NOT_SUPPORTED, }; enum DefaultSettings { diff --git a/media/cast/cast_sender_impl.cc b/media/cast/cast_sender_impl.cc index f617ef4..a8d63fe 100644 --- a/media/cast/cast_sender_impl.cc +++ b/media/cast/cast_sender_impl.cc @@ -105,7 +105,6 @@ void CastSenderImpl::InitializeAudio( const CastInitializationStatus status = audio_sender_->InitializationResult(); if (status == STATUS_AUDIO_INITIALIZED) { - ssrc_of_audio_sender_ = audio_config.incoming_feedback_ssrc; audio_frame_input_ = new LocalAudioFrameInput(cast_environment_, audio_sender_->AsWeakPtr()); } @@ -127,19 +126,14 @@ void CastSenderImpl::InitializeVideo( VLOG(1) << "CastSenderImpl@" << this << "::InitializeVideo()"; - video_sender_.reset(new VideoSender(cast_environment_, - video_config, - create_vea_cb, - create_video_encode_mem_cb, - transport_sender_)); - - const CastInitializationStatus status = video_sender_->InitializationResult(); - if (status == STATUS_VIDEO_INITIALIZED) { - ssrc_of_video_sender_ = video_config.incoming_feedback_ssrc; - video_frame_input_ = - new LocalVideoFrameInput(cast_environment_, video_sender_->AsWeakPtr()); - } - cast_initialization_cb.Run(status); + video_sender_.reset(new VideoSender( + cast_environment_, + video_config, + base::Bind(&CastSenderImpl::OnVideoInitialized, + weak_factory_.GetWeakPtr(), cast_initialization_cb), + create_vea_cb, + create_video_encode_mem_cb, + transport_sender_)); if (audio_sender_) { DCHECK(audio_sender_->GetTargetPlayoutDelay() == video_sender_->GetTargetPlayoutDelay()); @@ -170,5 +164,14 @@ void CastSenderImpl::SetTargetPlayoutDelay( } } +void CastSenderImpl::OnVideoInitialized( + const CastInitializationCallback& initialization_cb, + media::cast::CastInitializationStatus result) { + DCHECK(cast_environment_->CurrentlyOn(CastEnvironment::MAIN)); + video_frame_input_ = + new LocalVideoFrameInput(cast_environment_, video_sender_->AsWeakPtr()); + initialization_cb.Run(result); +} + } // namespace cast } // namespace media diff --git a/media/cast/cast_sender_impl.h b/media/cast/cast_sender_impl.h index c4680ab..e3f16fe 100644 --- a/media/cast/cast_sender_impl.h +++ b/media/cast/cast_sender_impl.h @@ -47,6 +47,9 @@ class CastSenderImpl : public CastSender { private: void ReceivedPacket(scoped_ptr<Packet> packet); + void OnVideoInitialized( + const CastInitializationCallback& initialization_cb, + media::cast::CastInitializationStatus result); CastInitializationCallback initialization_callback_; scoped_ptr<AudioSender> audio_sender_; @@ -57,8 +60,6 @@ class CastSenderImpl : public CastSender { // The transport sender is owned by the owner of the CastSender, and should be // valid throughout the lifetime of the CastSender. CastTransportSender* const transport_sender_; - uint32 ssrc_of_audio_sender_; - uint32 ssrc_of_video_sender_; // NOTE: Weak pointers must be invalidated before all other member variables. base::WeakPtrFactory<CastSenderImpl> weak_factory_; diff --git a/media/cast/net/rtp/framer.cc b/media/cast/net/rtp/framer.cc index 1eb424f..e807e94 100644 --- a/media/cast/net/rtp/framer.cc +++ b/media/cast/net/rtp/framer.cc @@ -44,7 +44,7 @@ bool Framer::InsertPacket(const uint8* payload_data, waiting_for_key_ = false; } - VLOG(0) << "InsertPacket frame:" << frame_id + VLOG(1) << "InsertPacket frame:" << frame_id << " packet:" << static_cast<int>(rtp_header.packet_id) << " max packet:" << static_cast<int>(rtp_header.max_packet_id); diff --git a/media/cast/sender/external_video_encoder.cc b/media/cast/sender/external_video_encoder.cc index 9e9bda1..5aca424 100644 --- a/media/cast/sender/external_video_encoder.cc +++ b/media/cast/sender/external_video_encoder.cc @@ -114,7 +114,11 @@ class LocalVideoEncodeAcceleratorClient UMA_HISTOGRAM_BOOLEAN("Cast.Sender.VideoEncodeAcceleratorInitializeSuccess", result); if (!result) { - NotifyError(VideoEncodeAccelerator::kInvalidArgumentError); + cast_environment_->PostTask( + CastEnvironment::MAIN, + FROM_HERE, + base::Bind(&ExternalVideoEncoder::EncoderInitialized, weak_owner_, + false)); return; } @@ -342,7 +346,8 @@ class LocalVideoEncodeAcceleratorClient cast_environment_->PostTask( CastEnvironment::MAIN, FROM_HERE, - base::Bind(&ExternalVideoEncoder::EncoderInitialized, weak_owner_)); + base::Bind(&ExternalVideoEncoder::EncoderInitialized, weak_owner_, + true)); } static void DestroyVideoEncodeAcceleratorOnEncoderThread( @@ -379,12 +384,14 @@ class LocalVideoEncodeAcceleratorClient ExternalVideoEncoder::ExternalVideoEncoder( scoped_refptr<CastEnvironment> cast_environment, const VideoSenderConfig& video_config, + const CastInitializationCallback& initialization_cb, const CreateVideoEncodeAcceleratorCallback& create_vea_cb, const CreateVideoEncodeMemoryCallback& create_video_encode_mem_cb) : video_config_(video_config), cast_environment_(cast_environment), encoder_active_(false), key_frame_requested_(false), + initialization_cb_(initialization_cb), weak_factory_(this) { DCHECK(cast_environment_->CurrentlyOn(CastEnvironment::MAIN)); @@ -399,9 +406,14 @@ ExternalVideoEncoder::ExternalVideoEncoder( ExternalVideoEncoder::~ExternalVideoEncoder() { } -void ExternalVideoEncoder::EncoderInitialized() { +void ExternalVideoEncoder::EncoderInitialized(bool success) { DCHECK(cast_environment_->CurrentlyOn(CastEnvironment::MAIN)); - encoder_active_ = true; + encoder_active_ = success; + DCHECK(!initialization_cb_.is_null()); + initialization_cb_.Run( + success ? + STATUS_VIDEO_INITIALIZED : STATUS_HW_VIDEO_ENCODER_NOT_SUPPORTED); + initialization_cb_.Reset(); } void ExternalVideoEncoder::EncoderError() { diff --git a/media/cast/sender/external_video_encoder.h b/media/cast/sender/external_video_encoder.h index 269fb3e..3a5f73b 100644 --- a/media/cast/sender/external_video_encoder.h +++ b/media/cast/sender/external_video_encoder.h @@ -28,6 +28,7 @@ class ExternalVideoEncoder : public VideoEncoder { ExternalVideoEncoder( scoped_refptr<CastEnvironment> cast_environment, const VideoSenderConfig& video_config, + const CastInitializationCallback& initialization_cb, const CreateVideoEncodeAcceleratorCallback& create_vea_cb, const CreateVideoEncodeMemoryCallback& create_video_encode_mem_cb); @@ -56,7 +57,9 @@ class ExternalVideoEncoder : public VideoEncoder { scoped_refptr<base::SingleThreadTaskRunner> encoder_task_runner); protected: - void EncoderInitialized(); + // If |success| is true then encoder is initialized successfully. + // Otherwise encoder initialization failed. + void EncoderInitialized(bool success); void EncoderError(); private: @@ -71,6 +74,8 @@ class ExternalVideoEncoder : public VideoEncoder { scoped_refptr<LocalVideoEncodeAcceleratorClient> video_accelerator_client_; scoped_refptr<base::SingleThreadTaskRunner> encoder_task_runner_; + CastInitializationCallback initialization_cb_; + // Weak pointer factory for posting back LocalVideoEncodeAcceleratorClient // notifications to ExternalVideoEncoder. // NOTE: Weak pointers must be invalidated before all other member variables. diff --git a/media/cast/sender/external_video_encoder_unittest.cc b/media/cast/sender/external_video_encoder_unittest.cc index 064c9e0..2f6fa9e 100644 --- a/media/cast/sender/external_video_encoder_unittest.cc +++ b/media/cast/sender/external_video_encoder_unittest.cc @@ -23,6 +23,8 @@ using testing::_; namespace { +void IgnoreInitializationStatus(CastInitializationStatus status) {} + class VEAFactory { public: VEAFactory(const scoped_refptr<base::SingleThreadTaskRunner>& task_runner, @@ -134,6 +136,7 @@ class ExternalVideoEncoderTest : public ::testing::Test { video_encoder_.reset(new ExternalVideoEncoder( cast_environment_, video_config_, + base::Bind(&IgnoreInitializationStatus), base::Bind(&VEAFactory::CreateVideoEncodeAccelerator, base::Unretained(&vea_factory)), base::Bind(&CreateSharedMemory))); @@ -229,6 +232,7 @@ TEST(ExternalVideoEncoderEarlyDestroyTest, DestroyBeforeVEACreatedCallback) { scoped_ptr<ExternalVideoEncoder> video_encoder(new ExternalVideoEncoder( cast_environment, video_config, + base::Bind(&IgnoreInitializationStatus), base::Bind(&VEAFactory::CreateVideoEncodeAccelerator, base::Unretained(&vea_factory)), base::Bind(&CreateSharedMemory))); diff --git a/media/cast/sender/video_sender.cc b/media/cast/sender/video_sender.cc index 9f8b6f9..f4dcb6e 100644 --- a/media/cast/sender/video_sender.cc +++ b/media/cast/sender/video_sender.cc @@ -26,6 +26,7 @@ namespace cast { VideoSender::VideoSender( scoped_refptr<CastEnvironment> cast_environment, const VideoSenderConfig& video_config, + const CastInitializationCallback& initialization_cb, const CreateVideoEncodeAcceleratorCallback& create_vea_cb, const CreateVideoEncodeMemoryCallback& create_video_encode_mem_cb, CastTransportSender* const transport_sender) @@ -51,11 +52,15 @@ VideoSender::VideoSender( DCHECK_GT(max_unacked_frames_, 0); if (video_config.use_external_encoder) { - video_encoder_.reset(new ExternalVideoEncoder(cast_environment, - video_config, - create_vea_cb, - create_video_encode_mem_cb)); + video_encoder_.reset(new ExternalVideoEncoder( + cast_environment, + video_config, + base::Bind(&VideoSender::OnEncoderInitialized, + weak_factory_.GetWeakPtr(), initialization_cb), + create_vea_cb, + create_video_encode_mem_cb)); } else { + // Software encoder is initialized immediately. congestion_control_.reset( NewAdaptiveCongestionControl(cast_environment->Clock(), video_config.max_bitrate, @@ -63,8 +68,15 @@ VideoSender::VideoSender( max_unacked_frames_)); video_encoder_.reset(new VideoEncoderImpl( cast_environment, video_config, max_unacked_frames_)); + cast_initialization_status_ = STATUS_VIDEO_INITIALIZED; + } + + if (cast_initialization_status_ == STATUS_VIDEO_INITIALIZED) { + cast_environment->PostTask( + CastEnvironment::MAIN, + FROM_HERE, + base::Bind(initialization_cb, cast_initialization_status_)); } - cast_initialization_status_ = STATUS_VIDEO_INITIALIZED; media::cast::CastTransportRtpConfig transport_config; transport_config.ssrc = video_config.ssrc; @@ -144,6 +156,13 @@ void VideoSender::OnAck(uint32 frame_id) { video_encoder_->LatestFrameIdToReference(frame_id); } +void VideoSender::OnEncoderInitialized( + const CastInitializationCallback& initialization_cb, + CastInitializationStatus status) { + cast_initialization_status_ = status; + initialization_cb.Run(status); +} + void VideoSender::OnEncodedVideoFrame( int encoder_bitrate, scoped_ptr<EncodedFrame> encoded_frame) { diff --git a/media/cast/sender/video_sender.h b/media/cast/sender/video_sender.h index f178316..9b6e62e 100644 --- a/media/cast/sender/video_sender.h +++ b/media/cast/sender/video_sender.h @@ -37,16 +37,13 @@ class VideoSender : public FrameSender, public: VideoSender(scoped_refptr<CastEnvironment> cast_environment, const VideoSenderConfig& video_config, + const CastInitializationCallback& initialization_cb, const CreateVideoEncodeAcceleratorCallback& create_vea_cb, const CreateVideoEncodeMemoryCallback& create_video_encode_mem_cb, CastTransportSender* const transport_sender); virtual ~VideoSender(); - CastInitializationStatus InitializationResult() const { - return cast_initialization_status_; - } - // Note: It is not guaranteed that |video_frame| will actually be encoded and // sent, if VideoSender detects too many frames in flight. Therefore, clients // should be careful about the rate at which this method is called. @@ -61,6 +58,11 @@ class VideoSender : public FrameSender, virtual void OnAck(uint32 frame_id) OVERRIDE; private: + // Called when the encoder is initialized or has failed to initialize. + void OnEncoderInitialized( + const CastInitializationCallback& initialization_cb, + CastInitializationStatus status); + // Called by the |video_encoder_| with the next EncodedFrame to send. void OnEncodedVideoFrame(int encoder_bitrate, scoped_ptr<EncodedFrame> encoded_frame); diff --git a/media/cast/sender/video_sender_unittest.cc b/media/cast/sender/video_sender_unittest.cc index 278b383..6ed846c 100644 --- a/media/cast/sender/video_sender_unittest.cc +++ b/media/cast/sender/video_sender_unittest.cc @@ -51,6 +51,11 @@ void CreateSharedMemory( callback.Run(shm.Pass()); } +void SaveInitializationStatus(CastInitializationStatus* out_status, + CastInitializationStatus in_status) { + *out_status = in_status; +} + class TestPacketSender : public PacketSender { public: TestPacketSender() @@ -111,11 +116,13 @@ class PeerVideoSender : public VideoSender { PeerVideoSender( scoped_refptr<CastEnvironment> cast_environment, const VideoSenderConfig& video_config, + const CastInitializationCallback& initialization_cb, const CreateVideoEncodeAcceleratorCallback& create_vea_cb, const CreateVideoEncodeMemoryCallback& create_video_encode_mem_cb, CastTransportSender* const transport_sender) : VideoSender(cast_environment, video_config, + initialization_cb, create_vea_cb, create_video_encode_mem_cb, transport_sender) {} @@ -159,7 +166,10 @@ class VideoSenderTest : public ::testing::Test { EXPECT_EQ(TRANSPORT_VIDEO_INITIALIZED, status); } - void InitEncoder(bool external) { + // If |external| is true then external video encoder (VEA) is used. + // |expect_init_sucess| is true if initialization is expected to succeed. + CastInitializationStatus InitEncoder(bool external, + bool expect_init_success) { VideoSenderConfig video_config; video_config.ssrc = 1; video_config.incoming_feedback_ssrc = 2; @@ -175,28 +185,36 @@ class VideoSenderTest : public ::testing::Test { video_config.max_frame_rate = 30; video_config.max_number_of_video_buffers_used = 1; video_config.codec = CODEC_VIDEO_VP8; + CastInitializationStatus status = STATUS_VIDEO_UNINITIALIZED; if (external) { - scoped_ptr<VideoEncodeAccelerator> fake_vea( - new test::FakeVideoEncodeAccelerator(task_runner_, - &stored_bitrates_)); + test::FakeVideoEncodeAccelerator* fake_vea = + new test::FakeVideoEncodeAccelerator( + task_runner_, &stored_bitrates_); + fake_vea->SetWillInitializationSucceed(expect_init_success); + scoped_ptr<VideoEncodeAccelerator> fake_vea_owner(fake_vea); video_sender_.reset( new PeerVideoSender(cast_environment_, video_config, + base::Bind(&SaveInitializationStatus, + &status), base::Bind(&CreateVideoEncodeAccelerator, task_runner_, - base::Passed(&fake_vea)), + base::Passed(&fake_vea_owner)), base::Bind(&CreateSharedMemory), transport_sender_.get())); } else { video_sender_.reset( new PeerVideoSender(cast_environment_, video_config, + base::Bind(&SaveInitializationStatus, + &status), CreateDefaultVideoEncodeAcceleratorCallback(), CreateDefaultVideoEncodeMemoryCallback(), transport_sender_.get())); } - ASSERT_EQ(STATUS_VIDEO_INITIALIZED, video_sender_->InitializationResult()); + task_runner_->RunTasks(); + return status; } scoped_refptr<media::VideoFrame> GetNewVideoFrame() { @@ -234,7 +252,7 @@ class VideoSenderTest : public ::testing::Test { }; TEST_F(VideoSenderTest, BuiltInEncoder) { - InitEncoder(false); + EXPECT_EQ(STATUS_VIDEO_INITIALIZED, InitEncoder(false, true)); scoped_refptr<media::VideoFrame> video_frame = GetNewVideoFrame(); const base::TimeTicks capture_time = testing_clock_->NowTicks(); @@ -246,8 +264,7 @@ TEST_F(VideoSenderTest, BuiltInEncoder) { } TEST_F(VideoSenderTest, ExternalEncoder) { - InitEncoder(true); - task_runner_->RunTasks(); + EXPECT_EQ(STATUS_VIDEO_INITIALIZED, InitEncoder(true, true)); scoped_refptr<media::VideoFrame> video_frame = GetNewVideoFrame(); @@ -262,14 +279,19 @@ TEST_F(VideoSenderTest, ExternalEncoder) { // Fixed bitrate is used for external encoder. Bitrate is only once // to the encoder. EXPECT_EQ(1u, stored_bitrates_.size()); + video_sender_.reset(NULL); + task_runner_->RunTasks(); +} - // We need to run the task to cleanup the GPU instance. +TEST_F(VideoSenderTest, ExternalEncoderInitFails) { + EXPECT_EQ(STATUS_HW_VIDEO_ENCODER_NOT_SUPPORTED, + InitEncoder(true, false)); video_sender_.reset(NULL); task_runner_->RunTasks(); } TEST_F(VideoSenderTest, RtcpTimer) { - InitEncoder(false); + EXPECT_EQ(STATUS_VIDEO_INITIALIZED, InitEncoder(false, true)); scoped_refptr<media::VideoFrame> video_frame = GetNewVideoFrame(); @@ -293,7 +315,7 @@ TEST_F(VideoSenderTest, RtcpTimer) { } TEST_F(VideoSenderTest, ResendTimer) { - InitEncoder(false); + EXPECT_EQ(STATUS_VIDEO_INITIALIZED, InitEncoder(false, true)); scoped_refptr<media::VideoFrame> video_frame = GetNewVideoFrame(); @@ -321,7 +343,7 @@ TEST_F(VideoSenderTest, ResendTimer) { } TEST_F(VideoSenderTest, LogAckReceivedEvent) { - InitEncoder(false); + EXPECT_EQ(STATUS_VIDEO_INITIALIZED, InitEncoder(false, true)); SimpleEventSubscriber event_subscriber; cast_environment_->Logging()->AddRawEventSubscriber(&event_subscriber); @@ -353,7 +375,7 @@ TEST_F(VideoSenderTest, LogAckReceivedEvent) { } TEST_F(VideoSenderTest, StopSendingInTheAbsenceOfAck) { - InitEncoder(false); + EXPECT_EQ(STATUS_VIDEO_INITIALIZED, InitEncoder(false, true)); // Send a stream of frames and don't ACK; by default we shouldn't have more // than 4 frames in flight. scoped_refptr<media::VideoFrame> video_frame = GetNewVideoFrame(); @@ -399,7 +421,7 @@ TEST_F(VideoSenderTest, StopSendingInTheAbsenceOfAck) { } TEST_F(VideoSenderTest, DuplicateAckRetransmit) { - InitEncoder(false); + EXPECT_EQ(STATUS_VIDEO_INITIALIZED, InitEncoder(false, true)); scoped_refptr<media::VideoFrame> video_frame = GetNewVideoFrame(); video_sender_->InsertRawVideoFrame(video_frame, testing_clock_->NowTicks()); RunTasks(33); @@ -439,7 +461,7 @@ TEST_F(VideoSenderTest, DuplicateAckRetransmit) { } TEST_F(VideoSenderTest, DuplicateAckRetransmitDoesNotCancelRetransmits) { - InitEncoder(false); + EXPECT_EQ(STATUS_VIDEO_INITIALIZED, InitEncoder(false, true)); scoped_refptr<media::VideoFrame> video_frame = GetNewVideoFrame(); video_sender_->InsertRawVideoFrame(video_frame, testing_clock_->NowTicks()); RunTasks(33); @@ -490,7 +512,7 @@ TEST_F(VideoSenderTest, DuplicateAckRetransmitDoesNotCancelRetransmits) { } TEST_F(VideoSenderTest, AcksCancelRetransmits) { - InitEncoder(false); + EXPECT_EQ(STATUS_VIDEO_INITIALIZED, InitEncoder(false, true)); transport_.SetPause(true); scoped_refptr<media::VideoFrame> video_frame = GetLargeNewVideoFrame(); video_sender_->InsertRawVideoFrame(video_frame, testing_clock_->NowTicks()); diff --git a/media/cast/test/end2end_unittest.cc b/media/cast/test/end2end_unittest.cc index d673f09..eea3902 100644 --- a/media/cast/test/end2end_unittest.cc +++ b/media/cast/test/end2end_unittest.cc @@ -613,6 +613,7 @@ class End2EndTest : public ::testing::Test { base::Bind(&VideoInitializationStatus), CreateDefaultVideoEncodeAcceleratorCallback(), CreateDefaultVideoEncodeMemoryCallback()); + task_runner_->RunTasks(); receiver_to_sender_.SetPacketReceiver( transport_sender_->PacketReceiverForTesting(), diff --git a/media/cast/test/fake_video_encode_accelerator.cc b/media/cast/test/fake_video_encode_accelerator.cc index 0442c0c..4076cb2 100644 --- a/media/cast/test/fake_video_encode_accelerator.cc +++ b/media/cast/test/fake_video_encode_accelerator.cc @@ -23,6 +23,7 @@ FakeVideoEncodeAccelerator::FakeVideoEncodeAccelerator( stored_bitrates_(stored_bitrates), client_(NULL), first_(true), + will_initialization_succeed_(true), weak_this_factory_(this) { DCHECK(stored_bitrates_); } @@ -37,6 +38,8 @@ bool FakeVideoEncodeAccelerator::Initialize( VideoCodecProfile output_profile, uint32 initial_bitrate, Client* client) { + if (!will_initialization_succeed_) + return false; client_ = client; if (output_profile != media::VP8PROFILE_ANY && output_profile != media::H264PROFILE_MAIN) { diff --git a/media/cast/test/fake_video_encode_accelerator.h b/media/cast/test/fake_video_encode_accelerator.h index 30e772b..4fc4312 100644 --- a/media/cast/test/fake_video_encode_accelerator.h +++ b/media/cast/test/fake_video_encode_accelerator.h @@ -45,6 +45,9 @@ class FakeVideoEncodeAccelerator : public VideoEncodeAccelerator { virtual void Destroy() OVERRIDE; void SendDummyFrameForTesting(bool key_frame); + void SetWillInitializationSucceed(bool will_initialization_succeed) { + will_initialization_succeed_ = will_initialization_succeed; + } private: void DoRequireBitstreamBuffers(unsigned int input_count, @@ -58,6 +61,7 @@ class FakeVideoEncodeAccelerator : public VideoEncodeAccelerator { std::vector<uint32>* const stored_bitrates_; VideoEncodeAccelerator::Client* client_; bool first_; + bool will_initialization_succeed_; std::list<int32> available_buffer_ids_; diff --git a/media/cast/test/simulator.cc b/media/cast/test/simulator.cc index b432b61..fbb36f8 100644 --- a/media/cast/test/simulator.cc +++ b/media/cast/test/simulator.cc @@ -311,6 +311,7 @@ void RunSimulation(const base::FilePath& source_path, base::Bind(&VideoInitializationStatus), CreateDefaultVideoEncodeAcceleratorCallback(), CreateDefaultVideoEncodeMemoryCallback()); + task_runner->RunTasks(); // Start sending. if (!source_path.empty()) { |