| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "chrome/renderer/media/cast_rtp_stream.h" | 5 #include "chrome/renderer/media/cast_rtp_stream.h" |
| 6 | 6 |
| 7 #include <stdint.h> | 7 #include <stdint.h> |
| 8 #include <algorithm> | 8 #include <algorithm> |
| 9 #include <utility> | 9 #include <utility> |
| 10 | 10 |
| (...skipping 325 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 336 consecutive_refresh_count_(0), | 336 consecutive_refresh_count_(0), |
| 337 expecting_a_refresh_frame_(false) {} | 337 expecting_a_refresh_frame_(false) {} |
| 338 | 338 |
| 339 ~CastVideoSink() override { | 339 ~CastVideoSink() override { |
| 340 MediaStreamVideoSink::DisconnectFromTrack(); | 340 MediaStreamVideoSink::DisconnectFromTrack(); |
| 341 } | 341 } |
| 342 | 342 |
| 343 // Attach this sink to a video track represented by |track_|. | 343 // Attach this sink to a video track represented by |track_|. |
| 344 // Data received from the track will be submitted to |frame_input|. | 344 // Data received from the track will be submitted to |frame_input|. |
| 345 void AddToTrack( | 345 void AddToTrack( |
| 346 bool is_sink_secure, |
| 346 const scoped_refptr<media::cast::VideoFrameInput>& frame_input) { | 347 const scoped_refptr<media::cast::VideoFrameInput>& frame_input) { |
| 347 DCHECK(deliverer_); | 348 DCHECK(deliverer_); |
| 348 deliverer_->WillConnectToTrack(AsWeakPtr(), frame_input); | 349 deliverer_->WillConnectToTrack(AsWeakPtr(), frame_input); |
| 349 refresh_timer_.Start( | 350 refresh_timer_.Start( |
| 350 FROM_HERE, | 351 FROM_HERE, |
| 351 base::TimeDelta::FromMilliseconds(kRefreshIntervalMilliseconds), | 352 base::TimeDelta::FromMilliseconds(kRefreshIntervalMilliseconds), |
| 352 base::Bind(&CastVideoSink::OnRefreshTimerFired, | 353 base::Bind(&CastVideoSink::OnRefreshTimerFired, |
| 353 base::Unretained(this))); | 354 base::Unretained(this))); |
| 354 MediaStreamVideoSink::ConnectToTrack(track_, | 355 MediaStreamVideoSink::ConnectToTrack( |
| 355 base::Bind(&Deliverer::OnVideoFrame, | 356 track_, base::Bind(&Deliverer::OnVideoFrame, deliverer_), |
| 356 deliverer_)); | 357 is_sink_secure); |
| 357 } | 358 } |
| 358 | 359 |
| 359 private: | 360 private: |
| 360 class Deliverer : public base::RefCountedThreadSafe<Deliverer> { | 361 class Deliverer : public base::RefCountedThreadSafe<Deliverer> { |
| 361 public: | 362 public: |
| 362 explicit Deliverer(const CastRtpStream::ErrorCallback& error_callback) | 363 explicit Deliverer(const CastRtpStream::ErrorCallback& error_callback) |
| 363 : main_task_runner_(base::ThreadTaskRunnerHandle::Get()), | 364 : main_task_runner_(base::ThreadTaskRunnerHandle::Get()), |
| 364 error_callback_(error_callback) {} | 365 error_callback_(error_callback) {} |
| 365 | 366 |
| 366 void WillConnectToTrack( | 367 void WillConnectToTrack( |
| (...skipping 309 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 676 if (!ToVideoSenderConfig(params, &config)) { | 677 if (!ToVideoSenderConfig(params, &config)) { |
| 677 DidEncounterError("Invalid parameters for video."); | 678 DidEncounterError("Invalid parameters for video."); |
| 678 return; | 679 return; |
| 679 } | 680 } |
| 680 // See the code for audio above for explanation of callbacks. | 681 // See the code for audio above for explanation of callbacks. |
| 681 video_sink_.reset(new CastVideoSink( | 682 video_sink_.reset(new CastVideoSink( |
| 682 track_, | 683 track_, |
| 683 media::BindToCurrentLoop(base::Bind(&CastRtpStream::DidEncounterError, | 684 media::BindToCurrentLoop(base::Bind(&CastRtpStream::DidEncounterError, |
| 684 weak_factory_.GetWeakPtr())))); | 685 weak_factory_.GetWeakPtr())))); |
| 685 cast_session_->StartVideo( | 686 cast_session_->StartVideo( |
| 686 config, | 687 config, base::Bind(&CastVideoSink::AddToTrack, video_sink_->AsWeakPtr(), |
| 687 base::Bind(&CastVideoSink::AddToTrack, video_sink_->AsWeakPtr()), | 688 !params.payload.aes_key.empty()), |
| 688 base::Bind(&CastRtpStream::DidEncounterError, | 689 base::Bind(&CastRtpStream::DidEncounterError, |
| 689 weak_factory_.GetWeakPtr())); | 690 weak_factory_.GetWeakPtr())); |
| 690 start_callback.Run(); | 691 start_callback.Run(); |
| 691 } | 692 } |
| 692 } | 693 } |
| 693 | 694 |
| 694 void CastRtpStream::Stop() { | 695 void CastRtpStream::Stop() { |
| 695 DVLOG(1) << "CastRtpStream::Stop = " << (IsAudio() ? "audio" : "video"); | 696 DVLOG(1) << "CastRtpStream::Stop = " << (IsAudio() ? "audio" : "video"); |
| 696 if (stop_callback_.is_null()) | 697 if (stop_callback_.is_null()) |
| 697 return; // Already stopped. | 698 return; // Already stopped. |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 731 DCHECK(content::RenderThread::Get()); | 732 DCHECK(content::RenderThread::Get()); |
| 732 DVLOG(1) << "CastRtpStream::DidEncounterError(" << message << ") = " | 733 DVLOG(1) << "CastRtpStream::DidEncounterError(" << message << ") = " |
| 733 << (IsAudio() ? "audio" : "video"); | 734 << (IsAudio() ? "audio" : "video"); |
| 734 // Save the WeakPtr first because the error callback might delete this object. | 735 // Save the WeakPtr first because the error callback might delete this object. |
| 735 base::WeakPtr<CastRtpStream> ptr = weak_factory_.GetWeakPtr(); | 736 base::WeakPtr<CastRtpStream> ptr = weak_factory_.GetWeakPtr(); |
| 736 error_callback_.Run(message); | 737 error_callback_.Run(message); |
| 737 base::ThreadTaskRunnerHandle::Get()->PostTask( | 738 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 738 FROM_HERE, | 739 FROM_HERE, |
| 739 base::Bind(&CastRtpStream::Stop, ptr)); | 740 base::Bind(&CastRtpStream::Stop, ptr)); |
| 740 } | 741 } |
| OLD | NEW |