| 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 341 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 352 virtual ~CastAudioSink() { | 352 virtual ~CastAudioSink() { |
| 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 virtual 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 virtual 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 |