| 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 "media/cast/test/utility/in_process_receiver.h" | 5 #include "media/cast/test/utility/in_process_receiver.h" |
| 6 | 6 |
| 7 #include "base/bind_helpers.h" | 7 #include "base/bind_helpers.h" |
| 8 #include "base/time/time.h" | 8 #include "base/time/time.h" |
| 9 #include "media/base/video_frame.h" | 9 #include "media/base/video_frame.h" |
| 10 #include "media/cast/cast_config.h" | 10 #include "media/cast/cast_config.h" |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 70 cast_receiver_ = CastReceiver::Create( | 70 cast_receiver_ = CastReceiver::Create( |
| 71 cast_environment_, audio_config_, video_config_, transport_.get()); | 71 cast_environment_, audio_config_, video_config_, transport_.get()); |
| 72 | 72 |
| 73 // TODO(hubbe): Make the cast receiver do this automatically. | 73 // TODO(hubbe): Make the cast receiver do this automatically. |
| 74 transport_->StartReceiving(cast_receiver_->packet_receiver()); | 74 transport_->StartReceiving(cast_receiver_->packet_receiver()); |
| 75 | 75 |
| 76 PullNextAudioFrame(); | 76 PullNextAudioFrame(); |
| 77 PullNextVideoFrame(); | 77 PullNextVideoFrame(); |
| 78 } | 78 } |
| 79 | 79 |
| 80 void InProcessReceiver::GotAudioFrame(scoped_ptr<PcmAudioFrame> audio_frame, | 80 void InProcessReceiver::GotAudioFrame(scoped_ptr<AudioBus> audio_frame, |
| 81 const base::TimeTicks& playout_time) { | 81 const base::TimeTicks& playout_time, |
| 82 bool is_continuous) { |
| 82 DCHECK(cast_environment_->CurrentlyOn(CastEnvironment::MAIN)); | 83 DCHECK(cast_environment_->CurrentlyOn(CastEnvironment::MAIN)); |
| 83 OnAudioFrame(audio_frame.Pass(), playout_time); | 84 if (audio_frame.get()) { |
| 84 // TODO(miu): Put this back here: PullNextAudioFrame(); | 85 // TODO(miu): Remove use of deprecated PcmAudioFrame and also pass |
| 86 // |is_continuous| flag. |
| 87 scoped_ptr<PcmAudioFrame> pcm_frame(new PcmAudioFrame()); |
| 88 pcm_frame->channels = audio_frame->channels(); |
| 89 pcm_frame->frequency = audio_config_.frequency; |
| 90 pcm_frame->samples.resize(audio_frame->channels() * audio_frame->frames()); |
| 91 audio_frame->ToInterleaved( |
| 92 audio_frame->frames(), sizeof(int16), &pcm_frame->samples.front()); |
| 93 OnAudioFrame(pcm_frame.Pass(), playout_time); |
| 94 } |
| 95 PullNextAudioFrame(); |
| 85 } | 96 } |
| 86 | 97 |
| 87 void InProcessReceiver::GotVideoFrame( | 98 void InProcessReceiver::GotVideoFrame( |
| 88 const scoped_refptr<VideoFrame>& video_frame, | 99 const scoped_refptr<VideoFrame>& video_frame, |
| 89 const base::TimeTicks& render_time) { | 100 const base::TimeTicks& render_time) { |
| 90 DCHECK(cast_environment_->CurrentlyOn(CastEnvironment::MAIN)); | 101 DCHECK(cast_environment_->CurrentlyOn(CastEnvironment::MAIN)); |
| 91 OnVideoFrame(video_frame, render_time); | 102 OnVideoFrame(video_frame, render_time); |
| 92 PullNextVideoFrame(); | 103 PullNextVideoFrame(); |
| 93 } | 104 } |
| 94 | 105 |
| 95 void InProcessReceiver::PullNextAudioFrame() { | 106 void InProcessReceiver::PullNextAudioFrame() { |
| 96 DCHECK(cast_environment_->CurrentlyOn(CastEnvironment::MAIN)); | 107 DCHECK(cast_environment_->CurrentlyOn(CastEnvironment::MAIN)); |
| 97 cast_receiver_->frame_receiver()->GetRawAudioFrame( | 108 cast_receiver_->frame_receiver()->GetRawAudioFrame( |
| 98 1 /* 10 ms of samples */, | |
| 99 audio_config_.frequency, | |
| 100 base::Bind(&InProcessReceiver::GotAudioFrame, | 109 base::Bind(&InProcessReceiver::GotAudioFrame, |
| 101 weak_factory_.GetWeakPtr())); | 110 weak_factory_.GetWeakPtr())); |
| 102 // TODO(miu): Fix audio decoder so that it never drops a request for the next | |
| 103 // frame of audio. Once fixed, remove this, and add PullNextAudioFrame() to | |
| 104 // the end of GotAudioFrame(), so that it behaves just like GotVideoFrame(). | |
| 105 // http://crbug.com/347361 | |
| 106 cast_environment_->PostDelayedTask( | |
| 107 CastEnvironment::MAIN, | |
| 108 FROM_HERE, | |
| 109 base::Bind(&InProcessReceiver::PullNextAudioFrame, | |
| 110 weak_factory_.GetWeakPtr()), | |
| 111 base::TimeDelta::FromMilliseconds(10)); | |
| 112 } | 111 } |
| 113 | 112 |
| 114 void InProcessReceiver::PullNextVideoFrame() { | 113 void InProcessReceiver::PullNextVideoFrame() { |
| 115 DCHECK(cast_environment_->CurrentlyOn(CastEnvironment::MAIN)); | 114 DCHECK(cast_environment_->CurrentlyOn(CastEnvironment::MAIN)); |
| 116 cast_receiver_->frame_receiver()->GetRawVideoFrame(base::Bind( | 115 cast_receiver_->frame_receiver()->GetRawVideoFrame(base::Bind( |
| 117 &InProcessReceiver::GotVideoFrame, weak_factory_.GetWeakPtr())); | 116 &InProcessReceiver::GotVideoFrame, weak_factory_.GetWeakPtr())); |
| 118 } | 117 } |
| 119 | 118 |
| 120 // static | 119 // static |
| 121 void InProcessReceiver::WillDestroyReceiver(InProcessReceiver* receiver) { | 120 void InProcessReceiver::WillDestroyReceiver(InProcessReceiver* receiver) { |
| 122 DCHECK(receiver->cast_environment_->CurrentlyOn(CastEnvironment::MAIN)); | 121 DCHECK(receiver->cast_environment_->CurrentlyOn(CastEnvironment::MAIN)); |
| 123 } | 122 } |
| 124 | 123 |
| 125 } // namespace cast | 124 } // namespace cast |
| 126 } // namespace media | 125 } // namespace media |
| OLD | NEW |