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" |
(...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
253 // |expected_natural_size| is the expected dimension of the video frame. | 253 // |expected_natural_size| is the expected dimension of the video frame. |
254 // |error_callback| is called if video formats don't match. | 254 // |error_callback| is called if video formats don't match. |
255 CastVideoSink(const blink::WebMediaStreamTrack& track, | 255 CastVideoSink(const blink::WebMediaStreamTrack& track, |
256 const gfx::Size& expected_natural_size, | 256 const gfx::Size& expected_natural_size, |
257 const CastRtpStream::ErrorCallback& error_callback) | 257 const CastRtpStream::ErrorCallback& error_callback) |
258 : track_(track), | 258 : track_(track), |
259 sink_added_(false), | 259 sink_added_(false), |
260 expected_natural_size_(expected_natural_size), | 260 expected_natural_size_(expected_natural_size), |
261 error_callback_(error_callback) {} | 261 error_callback_(error_callback) {} |
262 | 262 |
263 virtual ~CastVideoSink() { | 263 ~CastVideoSink() override { |
264 if (sink_added_) | 264 if (sink_added_) |
265 RemoveFromVideoTrack(this, track_); | 265 RemoveFromVideoTrack(this, track_); |
266 } | 266 } |
267 | 267 |
268 // This static method is used to forward video frames to |frame_input|. | 268 // This static method is used to forward video frames to |frame_input|. |
269 static void OnVideoFrame( | 269 static void OnVideoFrame( |
270 // These parameters are already bound when callback is created. | 270 // These parameters are already bound when callback is created. |
271 const gfx::Size& expected_natural_size, | 271 const gfx::Size& expected_natural_size, |
272 const CastRtpStream::ErrorCallback& error_callback, | 272 const CastRtpStream::ErrorCallback& error_callback, |
273 const scoped_refptr<media::cast::VideoFrameInput> frame_input, | 273 const scoped_refptr<media::cast::VideoFrameInput> frame_input, |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
342 int output_channels, | 342 int output_channels, |
343 int output_sample_rate) | 343 int output_sample_rate) |
344 : track_(track), | 344 : track_(track), |
345 sink_added_(false), | 345 sink_added_(false), |
346 error_callback_(error_callback), | 346 error_callback_(error_callback), |
347 weak_factory_(this), | 347 weak_factory_(this), |
348 output_channels_(output_channels), | 348 output_channels_(output_channels), |
349 output_sample_rate_(output_sample_rate), | 349 output_sample_rate_(output_sample_rate), |
350 input_preroll_(0) {} | 350 input_preroll_(0) {} |
351 | 351 |
352 virtual ~CastAudioSink() { | 352 ~CastAudioSink() override { |
353 if (sink_added_) | 353 if (sink_added_) |
354 RemoveFromAudioTrack(this, track_); | 354 RemoveFromAudioTrack(this, track_); |
355 } | 355 } |
356 | 356 |
357 // Called on real-time audio thread. | 357 // Called on real-time audio thread. |
358 // content::MediaStreamAudioSink implementation. | 358 // content::MediaStreamAudioSink implementation. |
359 virtual void OnData(const int16* audio_data, | 359 void OnData(const int16* audio_data, |
360 int sample_rate, | 360 int sample_rate, |
361 int number_of_channels, | 361 int number_of_channels, |
362 int number_of_frames) override { | 362 int number_of_frames) override { |
363 scoped_ptr<media::AudioBus> input_bus; | 363 scoped_ptr<media::AudioBus> input_bus; |
364 if (resampler_) { | 364 if (resampler_) { |
365 input_bus = ResampleData( | 365 input_bus = ResampleData( |
366 audio_data, sample_rate, number_of_channels, number_of_frames); | 366 audio_data, sample_rate, number_of_channels, number_of_frames); |
367 if (!input_bus) | 367 if (!input_bus) |
368 return; | 368 return; |
369 } else { | 369 } else { |
370 input_bus = media::AudioBus::Create( | 370 input_bus = media::AudioBus::Create( |
371 number_of_channels, number_of_frames); | 371 number_of_channels, number_of_frames); |
372 input_bus->FromInterleaved( | 372 input_bus->FromInterleaved( |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
409 output_channels_, | 409 output_channels_, |
410 output_sample_rate_ * fifo_input_bus_->frames() / sample_rate)); | 410 output_sample_rate_ * fifo_input_bus_->frames() / sample_rate)); |
411 | 411 |
412 // Resampler will then call ProvideData() below to fetch data from | 412 // Resampler will then call ProvideData() below to fetch data from |
413 // |input_data_|. | 413 // |input_data_|. |
414 resampler_->Resample(output_bus->frames(), output_bus.get()); | 414 resampler_->Resample(output_bus->frames(), output_bus.get()); |
415 return output_bus.Pass(); | 415 return output_bus.Pass(); |
416 } | 416 } |
417 | 417 |
418 // Called on real-time audio thread. | 418 // Called on real-time audio thread. |
419 virtual void OnSetFormat(const media::AudioParameters& params) override { | 419 void OnSetFormat(const media::AudioParameters& params) override { |
420 if (params.sample_rate() == output_sample_rate_) | 420 if (params.sample_rate() == output_sample_rate_) |
421 return; | 421 return; |
422 fifo_.reset(new media::AudioFifo( | 422 fifo_.reset(new media::AudioFifo( |
423 output_channels_, | 423 output_channels_, |
424 kBufferAudioData * params.frames_per_buffer())); | 424 kBufferAudioData * params.frames_per_buffer())); |
425 fifo_input_bus_ = media::AudioBus::Create( | 425 fifo_input_bus_ = media::AudioBus::Create( |
426 params.channels(), params.frames_per_buffer()); | 426 params.channels(), params.frames_per_buffer()); |
427 resampler_.reset(new media::MultiChannelResampler( | 427 resampler_.reset(new media::MultiChannelResampler( |
428 output_channels_, | 428 output_channels_, |
429 static_cast<double>(params.sample_rate()) / output_sample_rate_, | 429 static_cast<double>(params.sample_rate()) / output_sample_rate_, |
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
596 void CastRtpStream::DidEncounterError(const std::string& message) { | 596 void CastRtpStream::DidEncounterError(const std::string& message) { |
597 VLOG(1) << "CastRtpStream::DidEncounterError(" << message << ") = " | 597 VLOG(1) << "CastRtpStream::DidEncounterError(" << message << ") = " |
598 << (IsAudio() ? "audio" : "video"); | 598 << (IsAudio() ? "audio" : "video"); |
599 // Save the WeakPtr first because the error callback might delete this object. | 599 // Save the WeakPtr first because the error callback might delete this object. |
600 base::WeakPtr<CastRtpStream> ptr = weak_factory_.GetWeakPtr(); | 600 base::WeakPtr<CastRtpStream> ptr = weak_factory_.GetWeakPtr(); |
601 error_callback_.Run(message); | 601 error_callback_.Run(message); |
602 content::RenderThread::Get()->GetMessageLoop()->PostTask( | 602 content::RenderThread::Get()->GetMessageLoop()->PostTask( |
603 FROM_HERE, | 603 FROM_HERE, |
604 base::Bind(&CastRtpStream::Stop, ptr)); | 604 base::Bind(&CastRtpStream::Stop, ptr)); |
605 } | 605 } |
OLD | NEW |