| 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 "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
| 9 #include "base/debug/trace_event.h" | 9 #include "base/debug/trace_event.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 98 payload.max_frame_rate = media::cast::kDefaultMaxFrameRate; | 98 payload.max_frame_rate = media::cast::kDefaultMaxFrameRate; |
| 99 payload.width = 1280; | 99 payload.width = 1280; |
| 100 payload.height = 720; | 100 payload.height = 720; |
| 101 payload.codec_name = kCodecNameH264; | 101 payload.codec_name = kCodecNameH264; |
| 102 return payload; | 102 return payload; |
| 103 } | 103 } |
| 104 | 104 |
| 105 bool IsHardwareVP8EncodingSupported() { | 105 bool IsHardwareVP8EncodingSupported() { |
| 106 const base::CommandLine* cmd_line = base::CommandLine::ForCurrentProcess(); | 106 const base::CommandLine* cmd_line = base::CommandLine::ForCurrentProcess(); |
| 107 if (cmd_line->HasSwitch(switches::kDisableCastStreamingHWEncoding)) { | 107 if (cmd_line->HasSwitch(switches::kDisableCastStreamingHWEncoding)) { |
| 108 VLOG(1) << "Disabled hardware VP8 support for Cast Streaming."; | 108 DVLOG(1) << "Disabled hardware VP8 support for Cast Streaming."; |
| 109 return false; | 109 return false; |
| 110 } | 110 } |
| 111 | 111 |
| 112 // Query for hardware VP8 encoder support. | 112 // Query for hardware VP8 encoder support. |
| 113 std::vector<media::VideoEncodeAccelerator::SupportedProfile> vea_profiles = | 113 std::vector<media::VideoEncodeAccelerator::SupportedProfile> vea_profiles = |
| 114 content::GetSupportedVideoEncodeAcceleratorProfiles(); | 114 content::GetSupportedVideoEncodeAcceleratorProfiles(); |
| 115 for (size_t i = 0; i < vea_profiles.size(); ++i) { | 115 for (size_t i = 0; i < vea_profiles.size(); ++i) { |
| 116 if (vea_profiles[i].profile >= media::VP8PROFILE_MIN && | 116 if (vea_profiles[i].profile >= media::VP8PROFILE_MIN && |
| 117 vea_profiles[i].profile <= media::VP8PROFILE_MAX) { | 117 vea_profiles[i].profile <= media::VP8PROFILE_MAX) { |
| 118 return true; | 118 return true; |
| 119 } | 119 } |
| 120 } | 120 } |
| 121 return false; | 121 return false; |
| 122 } | 122 } |
| 123 | 123 |
| 124 bool IsHardwareH264EncodingSupported() { | 124 bool IsHardwareH264EncodingSupported() { |
| 125 const base::CommandLine* cmd_line = base::CommandLine::ForCurrentProcess(); | 125 const base::CommandLine* cmd_line = base::CommandLine::ForCurrentProcess(); |
| 126 if (cmd_line->HasSwitch(switches::kDisableCastStreamingHWEncoding)) { | 126 if (cmd_line->HasSwitch(switches::kDisableCastStreamingHWEncoding)) { |
| 127 VLOG(1) << "Disabled hardware h264 support for Cast Streaming."; | 127 DVLOG(1) << "Disabled hardware h264 support for Cast Streaming."; |
| 128 return false; | 128 return false; |
| 129 } | 129 } |
| 130 | 130 |
| 131 // Query for hardware H.264 encoder support. | 131 // Query for hardware H.264 encoder support. |
| 132 std::vector<media::VideoEncodeAccelerator::SupportedProfile> vea_profiles = | 132 std::vector<media::VideoEncodeAccelerator::SupportedProfile> vea_profiles = |
| 133 content::GetSupportedVideoEncodeAcceleratorProfiles(); | 133 content::GetSupportedVideoEncodeAcceleratorProfiles(); |
| 134 for (size_t i = 0; i < vea_profiles.size(); ++i) { | 134 for (size_t i = 0; i < vea_profiles.size(); ++i) { |
| 135 if (vea_profiles[i].profile >= media::H264PROFILE_MIN && | 135 if (vea_profiles[i].profile >= media::H264PROFILE_MIN && |
| 136 vea_profiles[i].profile <= media::H264PROFILE_MAX) { | 136 vea_profiles[i].profile <= media::H264PROFILE_MAX) { |
| 137 return true; | 137 return true; |
| (...skipping 383 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 521 else | 521 else |
| 522 return SupportedVideoParams(); | 522 return SupportedVideoParams(); |
| 523 } | 523 } |
| 524 | 524 |
| 525 CastRtpParams CastRtpStream::GetParams() { return params_; } | 525 CastRtpParams CastRtpStream::GetParams() { return params_; } |
| 526 | 526 |
| 527 void CastRtpStream::Start(const CastRtpParams& params, | 527 void CastRtpStream::Start(const CastRtpParams& params, |
| 528 const base::Closure& start_callback, | 528 const base::Closure& start_callback, |
| 529 const base::Closure& stop_callback, | 529 const base::Closure& stop_callback, |
| 530 const ErrorCallback& error_callback) { | 530 const ErrorCallback& error_callback) { |
| 531 VLOG(1) << "CastRtpStream::Start = " << (IsAudio() ? "audio" : "video"); | 531 DVLOG(1) << "CastRtpStream::Start = " << (IsAudio() ? "audio" : "video"); |
| 532 stop_callback_ = stop_callback; | 532 stop_callback_ = stop_callback; |
| 533 error_callback_ = error_callback; | 533 error_callback_ = error_callback; |
| 534 | 534 |
| 535 if (IsAudio()) { | 535 if (IsAudio()) { |
| 536 AudioSenderConfig config; | 536 AudioSenderConfig config; |
| 537 if (!ToAudioSenderConfig(params, &config)) { | 537 if (!ToAudioSenderConfig(params, &config)) { |
| 538 DidEncounterError("Invalid parameters for audio."); | 538 DidEncounterError("Invalid parameters for audio."); |
| 539 return; | 539 return; |
| 540 } | 540 } |
| 541 | 541 |
| (...skipping 26 matching lines...) Expand all Loading... |
| 568 cast_session_->StartVideo( | 568 cast_session_->StartVideo( |
| 569 config, | 569 config, |
| 570 base::Bind(&CastVideoSink::AddToTrack, video_sink_->AsWeakPtr()), | 570 base::Bind(&CastVideoSink::AddToTrack, video_sink_->AsWeakPtr()), |
| 571 base::Bind(&CastRtpStream::DidEncounterError, | 571 base::Bind(&CastRtpStream::DidEncounterError, |
| 572 weak_factory_.GetWeakPtr())); | 572 weak_factory_.GetWeakPtr())); |
| 573 start_callback.Run(); | 573 start_callback.Run(); |
| 574 } | 574 } |
| 575 } | 575 } |
| 576 | 576 |
| 577 void CastRtpStream::Stop() { | 577 void CastRtpStream::Stop() { |
| 578 VLOG(1) << "CastRtpStream::Stop = " << (IsAudio() ? "audio" : "video"); | 578 DVLOG(1) << "CastRtpStream::Stop = " << (IsAudio() ? "audio" : "video"); |
| 579 audio_sink_.reset(); | 579 audio_sink_.reset(); |
| 580 video_sink_.reset(); | 580 video_sink_.reset(); |
| 581 if (!stop_callback_.is_null()) | 581 if (!stop_callback_.is_null()) |
| 582 stop_callback_.Run(); | 582 stop_callback_.Run(); |
| 583 } | 583 } |
| 584 | 584 |
| 585 void CastRtpStream::ToggleLogging(bool enable) { | 585 void CastRtpStream::ToggleLogging(bool enable) { |
| 586 VLOG(1) << "CastRtpStream::ToggleLogging(" << enable << ") = " | 586 DVLOG(1) << "CastRtpStream::ToggleLogging(" << enable << ") = " |
| 587 << (IsAudio() ? "audio" : "video"); | 587 << (IsAudio() ? "audio" : "video"); |
| 588 cast_session_->ToggleLogging(IsAudio(), enable); | 588 cast_session_->ToggleLogging(IsAudio(), enable); |
| 589 } | 589 } |
| 590 | 590 |
| 591 void CastRtpStream::GetRawEvents( | 591 void CastRtpStream::GetRawEvents( |
| 592 const base::Callback<void(scoped_ptr<base::BinaryValue>)>& callback, | 592 const base::Callback<void(scoped_ptr<base::BinaryValue>)>& callback, |
| 593 const std::string& extra_data) { | 593 const std::string& extra_data) { |
| 594 VLOG(1) << "CastRtpStream::GetRawEvents = " | 594 DVLOG(1) << "CastRtpStream::GetRawEvents = " |
| 595 << (IsAudio() ? "audio" : "video"); | 595 << (IsAudio() ? "audio" : "video"); |
| 596 cast_session_->GetEventLogsAndReset(IsAudio(), extra_data, callback); | 596 cast_session_->GetEventLogsAndReset(IsAudio(), extra_data, callback); |
| 597 } | 597 } |
| 598 | 598 |
| 599 void CastRtpStream::GetStats( | 599 void CastRtpStream::GetStats( |
| 600 const base::Callback<void(scoped_ptr<base::DictionaryValue>)>& callback) { | 600 const base::Callback<void(scoped_ptr<base::DictionaryValue>)>& callback) { |
| 601 VLOG(1) << "CastRtpStream::GetStats = " | 601 DVLOG(1) << "CastRtpStream::GetStats = " |
| 602 << (IsAudio() ? "audio" : "video"); | 602 << (IsAudio() ? "audio" : "video"); |
| 603 cast_session_->GetStatsAndReset(IsAudio(), callback); | 603 cast_session_->GetStatsAndReset(IsAudio(), callback); |
| 604 } | 604 } |
| 605 | 605 |
| 606 bool CastRtpStream::IsAudio() const { | 606 bool CastRtpStream::IsAudio() const { |
| 607 return track_.source().type() == blink::WebMediaStreamSource::TypeAudio; | 607 return track_.source().type() == blink::WebMediaStreamSource::TypeAudio; |
| 608 } | 608 } |
| 609 | 609 |
| 610 void CastRtpStream::DidEncounterError(const std::string& message) { | 610 void CastRtpStream::DidEncounterError(const std::string& message) { |
| 611 VLOG(1) << "CastRtpStream::DidEncounterError(" << message << ") = " | 611 DVLOG(1) << "CastRtpStream::DidEncounterError(" << message << ") = " |
| 612 << (IsAudio() ? "audio" : "video"); | 612 << (IsAudio() ? "audio" : "video"); |
| 613 // Save the WeakPtr first because the error callback might delete this object. | 613 // Save the WeakPtr first because the error callback might delete this object. |
| 614 base::WeakPtr<CastRtpStream> ptr = weak_factory_.GetWeakPtr(); | 614 base::WeakPtr<CastRtpStream> ptr = weak_factory_.GetWeakPtr(); |
| 615 error_callback_.Run(message); | 615 error_callback_.Run(message); |
| 616 content::RenderThread::Get()->GetMessageLoop()->PostTask( | 616 content::RenderThread::Get()->GetMessageLoop()->PostTask( |
| 617 FROM_HERE, | 617 FROM_HERE, |
| 618 base::Bind(&CastRtpStream::Stop, ptr)); | 618 base::Bind(&CastRtpStream::Stop, ptr)); |
| 619 } | 619 } |
| OLD | NEW |