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/debug/trace_event.h" | 8 #include "base/debug/trace_event.h" |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/memory/weak_ptr.h" | 10 #include "base/memory/weak_ptr.h" |
| 11 #include "base/strings/stringprintf.h" |
11 #include "base/sys_info.h" | 12 #include "base/sys_info.h" |
12 #include "chrome/renderer/media/cast_session.h" | 13 #include "chrome/renderer/media/cast_session.h" |
13 #include "chrome/renderer/media/cast_udp_transport.h" | 14 #include "chrome/renderer/media/cast_udp_transport.h" |
14 #include "content/public/renderer/media_stream_audio_sink.h" | 15 #include "content/public/renderer/media_stream_audio_sink.h" |
15 #include "content/public/renderer/media_stream_video_sink.h" | 16 #include "content/public/renderer/media_stream_video_sink.h" |
16 #include "content/public/renderer/render_thread.h" | 17 #include "content/public/renderer/render_thread.h" |
17 #include "content/public/renderer/video_encode_accelerator.h" | 18 #include "content/public/renderer/video_encode_accelerator.h" |
18 #include "media/audio/audio_parameters.h" | 19 #include "media/audio/audio_parameters.h" |
19 #include "media/base/audio_bus.h" | 20 #include "media/base/audio_bus.h" |
20 #include "media/base/audio_fifo.h" | 21 #include "media/base/audio_fifo.h" |
(...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
247 static void OnVideoFrame( | 248 static void OnVideoFrame( |
248 // These parameters are already bound when callback is created. | 249 // These parameters are already bound when callback is created. |
249 const gfx::Size& expected_coded_size, | 250 const gfx::Size& expected_coded_size, |
250 const CastRtpStream::ErrorCallback& error_callback, | 251 const CastRtpStream::ErrorCallback& error_callback, |
251 const scoped_refptr<media::cast::VideoFrameInput> frame_input, | 252 const scoped_refptr<media::cast::VideoFrameInput> frame_input, |
252 // These parameters are passed for each frame. | 253 // These parameters are passed for each frame. |
253 const scoped_refptr<media::VideoFrame>& frame, | 254 const scoped_refptr<media::VideoFrame>& frame, |
254 const media::VideoCaptureFormat& format, | 255 const media::VideoCaptureFormat& format, |
255 const base::TimeTicks& estimated_capture_time) { | 256 const base::TimeTicks& estimated_capture_time) { |
256 if (frame->coded_size() != expected_coded_size) { | 257 if (frame->coded_size() != expected_coded_size) { |
257 error_callback.Run("Video frame resolution does not match config."); | 258 error_callback.Run( |
| 259 base::StringPrintf("Video frame resolution does not match config." |
| 260 " Expected %dx%d. Got %dx%d.", |
| 261 expected_coded_size.width(), |
| 262 expected_coded_size.height(), |
| 263 frame->coded_size().width(), |
| 264 frame->coded_size().height())); |
258 return; | 265 return; |
259 } | 266 } |
260 | 267 |
261 base::TimeTicks timestamp; | 268 base::TimeTicks timestamp; |
262 if (estimated_capture_time.is_null()) | 269 if (estimated_capture_time.is_null()) |
263 timestamp = base::TimeTicks::Now(); | 270 timestamp = base::TimeTicks::Now(); |
264 else | 271 else |
265 timestamp = estimated_capture_time; | 272 timestamp = estimated_capture_time; |
266 | 273 |
267 // Used by chrome/browser/extension/api/cast_streaming/performance_test.cc | 274 // Used by chrome/browser/extension/api/cast_streaming/performance_test.cc |
(...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
477 else | 484 else |
478 return SupportedVideoParams(); | 485 return SupportedVideoParams(); |
479 } | 486 } |
480 | 487 |
481 CastRtpParams CastRtpStream::GetParams() { return params_; } | 488 CastRtpParams CastRtpStream::GetParams() { return params_; } |
482 | 489 |
483 void CastRtpStream::Start(const CastRtpParams& params, | 490 void CastRtpStream::Start(const CastRtpParams& params, |
484 const base::Closure& start_callback, | 491 const base::Closure& start_callback, |
485 const base::Closure& stop_callback, | 492 const base::Closure& stop_callback, |
486 const ErrorCallback& error_callback) { | 493 const ErrorCallback& error_callback) { |
487 VLOG(1) << "CastRtpStream::Start = " << (IsAudio() ? "audio" : "video"); | 494 VLOG(1) << "CastRtpStream::Start = " << (IsAudio() ? "audio" : "video"); |
488 stop_callback_ = stop_callback; | 495 stop_callback_ = stop_callback; |
489 error_callback_ = error_callback; | 496 error_callback_ = error_callback; |
490 | 497 |
491 if (IsAudio()) { | 498 if (IsAudio()) { |
492 AudioSenderConfig config; | 499 AudioSenderConfig config; |
493 if (!ToAudioSenderConfig(params, &config)) { | 500 if (!ToAudioSenderConfig(params, &config)) { |
494 DidEncounterError("Invalid parameters for audio."); | 501 DidEncounterError("Invalid parameters for audio."); |
495 return; | 502 return; |
496 } | 503 } |
497 | 504 |
(...skipping 26 matching lines...) Expand all Loading... |
524 cast_session_->StartVideo( | 531 cast_session_->StartVideo( |
525 config, | 532 config, |
526 base::Bind(&CastVideoSink::AddToTrack, video_sink_->AsWeakPtr()), | 533 base::Bind(&CastVideoSink::AddToTrack, video_sink_->AsWeakPtr()), |
527 base::Bind(&CastRtpStream::DidEncounterError, | 534 base::Bind(&CastRtpStream::DidEncounterError, |
528 weak_factory_.GetWeakPtr())); | 535 weak_factory_.GetWeakPtr())); |
529 start_callback.Run(); | 536 start_callback.Run(); |
530 } | 537 } |
531 } | 538 } |
532 | 539 |
533 void CastRtpStream::Stop() { | 540 void CastRtpStream::Stop() { |
534 VLOG(1) << "CastRtpStream::Stop = " << (IsAudio() ? "audio" : "video"); | 541 VLOG(1) << "CastRtpStream::Stop = " << (IsAudio() ? "audio" : "video"); |
535 audio_sink_.reset(); | 542 audio_sink_.reset(); |
536 video_sink_.reset(); | 543 video_sink_.reset(); |
537 if (!stop_callback_.is_null()) | 544 if (!stop_callback_.is_null()) |
538 stop_callback_.Run(); | 545 stop_callback_.Run(); |
539 } | 546 } |
540 | 547 |
541 void CastRtpStream::ToggleLogging(bool enable) { | 548 void CastRtpStream::ToggleLogging(bool enable) { |
| 549 VLOG(1) << "CastRtpStream::ToggleLogging(" << enable << ") = " |
| 550 << (IsAudio() ? "audio" : "video"); |
542 cast_session_->ToggleLogging(IsAudio(), enable); | 551 cast_session_->ToggleLogging(IsAudio(), enable); |
543 } | 552 } |
544 | 553 |
545 void CastRtpStream::GetRawEvents( | 554 void CastRtpStream::GetRawEvents( |
546 const base::Callback<void(scoped_ptr<base::BinaryValue>)>& callback, | 555 const base::Callback<void(scoped_ptr<base::BinaryValue>)>& callback, |
547 const std::string& extra_data) { | 556 const std::string& extra_data) { |
| 557 VLOG(1) << "CastRtpStream::GetRawEvents = " |
| 558 << (IsAudio() ? "audio" : "video"); |
548 cast_session_->GetEventLogsAndReset(IsAudio(), extra_data, callback); | 559 cast_session_->GetEventLogsAndReset(IsAudio(), extra_data, callback); |
549 } | 560 } |
550 | 561 |
551 void CastRtpStream::GetStats( | 562 void CastRtpStream::GetStats( |
552 const base::Callback<void(scoped_ptr<base::DictionaryValue>)>& callback) { | 563 const base::Callback<void(scoped_ptr<base::DictionaryValue>)>& callback) { |
| 564 VLOG(1) << "CastRtpStream::GetStats = " |
| 565 << (IsAudio() ? "audio" : "video"); |
553 cast_session_->GetStatsAndReset(IsAudio(), callback); | 566 cast_session_->GetStatsAndReset(IsAudio(), callback); |
554 } | 567 } |
555 | 568 |
556 bool CastRtpStream::IsAudio() const { | 569 bool CastRtpStream::IsAudio() const { |
557 return track_.source().type() == blink::WebMediaStreamSource::TypeAudio; | 570 return track_.source().type() == blink::WebMediaStreamSource::TypeAudio; |
558 } | 571 } |
559 | 572 |
560 void CastRtpStream::DidEncounterError(const std::string& message) { | 573 void CastRtpStream::DidEncounterError(const std::string& message) { |
| 574 VLOG(1) << "CastRtpStream::DidEncounterError(" << message << ") = " |
| 575 << (IsAudio() ? "audio" : "video"); |
561 // Save the WeakPtr first because the error callback might delete this object. | 576 // Save the WeakPtr first because the error callback might delete this object. |
562 base::WeakPtr<CastRtpStream> ptr = weak_factory_.GetWeakPtr(); | 577 base::WeakPtr<CastRtpStream> ptr = weak_factory_.GetWeakPtr(); |
563 error_callback_.Run(message); | 578 error_callback_.Run(message); |
564 content::RenderThread::Get()->GetMessageLoop()->PostTask( | 579 content::RenderThread::Get()->GetMessageLoop()->PostTask( |
565 FROM_HERE, | 580 FROM_HERE, |
566 base::Bind(&CastRtpStream::Stop, ptr)); | 581 base::Bind(&CastRtpStream::Stop, ptr)); |
567 } | 582 } |
OLD | NEW |