| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 <memory> | 5 #include <memory> |
| 6 | 6 |
| 7 #include "mojo/public/c/system/main.h" | 7 #include "mojo/public/c/system/main.h" |
| 8 #include "mojo/public/cpp/application/application_delegate.h" | 8 #include "mojo/public/cpp/application/application_delegate.h" |
| 9 #include "mojo/public/cpp/application/application_impl.h" | 9 #include "mojo/public/cpp/application/application_impl.h" |
| 10 #include "mojo/public/cpp/application/application_runner.h" | 10 #include "mojo/public/cpp/application/application_runner.h" |
| (...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 260 | 260 |
| 261 LinearTransform::Ratio audio_rate(wav_info_.frame_rate, 1); | 261 LinearTransform::Ratio audio_rate(wav_info_.frame_rate, 1); |
| 262 LinearTransform::Ratio local_rate(LocalDuration::period::num, | 262 LinearTransform::Ratio local_rate(LocalDuration::period::num, |
| 263 LocalDuration::period::den); | 263 LocalDuration::period::den); |
| 264 LinearTransform::Ratio tmp; | 264 LinearTransform::Ratio tmp; |
| 265 bool success = LinearTransform::Ratio::Compose(audio_rate, local_rate, &tmp); | 265 bool success = LinearTransform::Ratio::Compose(audio_rate, local_rate, &tmp); |
| 266 MOJO_DCHECK(success); | 266 MOJO_DCHECK(success); |
| 267 | 267 |
| 268 AudioTrackConfigurationPtr cfg; | 268 AudioTrackConfigurationPtr cfg; |
| 269 cfg = AudioTrackConfiguration::New(); | 269 cfg = AudioTrackConfiguration::New(); |
| 270 cfg->max_frames = USecToFrames(BUF_DEPTH_USEC); | |
| 271 cfg->audio_frame_ratio = tmp.numerator; | 270 cfg->audio_frame_ratio = tmp.numerator; |
| 272 cfg->media_time_ratio = tmp.denominator; | 271 cfg->media_time_ratio = tmp.denominator; |
| 273 | 272 |
| 274 LpcmMediaTypeDetailsPtr pcm_cfg = LpcmMediaTypeDetails::New(); | 273 LpcmMediaTypeDetailsPtr pcm_cfg = LpcmMediaTypeDetails::New(); |
| 275 pcm_cfg->sample_format = (wav_info_.bits_per_sample == 8) | 274 pcm_cfg->sample_format = (wav_info_.bits_per_sample == 8) |
| 276 ? LpcmSampleFormat::UNSIGNED_8 | 275 ? LpcmSampleFormat::UNSIGNED_8 |
| 277 : LpcmSampleFormat::SIGNED_16; | 276 : LpcmSampleFormat::SIGNED_16; |
| 278 pcm_cfg->channels = wav_info_.channel_count; | 277 pcm_cfg->channels = wav_info_.channel_count; |
| 279 pcm_cfg->frames_per_second = wav_info_.frame_rate; | 278 pcm_cfg->frames_per_second = wav_info_.frame_rate; |
| 280 | 279 |
| 281 cfg->media_type = MediaType::New(); | 280 cfg->media_type = MediaType::New(); |
| 282 cfg->media_type->scheme = MediaTypeScheme::LPCM; | 281 cfg->media_type->scheme = MediaTypeScheme::LPCM; |
| 283 cfg->media_type->details = MediaTypeDetails::New(); | 282 cfg->media_type->details = MediaTypeDetails::New(); |
| 284 cfg->media_type->details->set_lpcm(pcm_cfg.Pass()); | 283 cfg->media_type->details->set_lpcm(pcm_cfg.Pass()); |
| 285 | 284 |
| 286 // Configure the track based on the WAV header information. | 285 // Configure the track based on the WAV header information. |
| 287 MediaPipePtr media_pipe; | 286 MediaPipePtr media_pipe; |
| 288 audio_track_->Configure(cfg.Pass(), GetProxy(&media_pipe)); | 287 audio_track_->Configure(cfg.Pass(), GetProxy(&media_pipe)); |
| 289 | 288 |
| 290 // Grab the rate control interface for our audio renderer. | 289 // Grab the rate control interface for our audio renderer. |
| 291 audio_track_->GetRateControl(GetProxy(&rate_control_)); | 290 audio_track_->GetRateControl(GetProxy(&rate_control_)); |
| 292 rate_control_.set_connection_error_handler([this]() { | 291 rate_control_.set_connection_error_handler([this]() { |
| 293 OnConnectionError("rate_control"); | 292 OnConnectionError("rate_control"); |
| 294 }); | 293 }); |
| 295 | 294 |
| 296 // Set up our media pipe helper, configure its callback and water marks to | 295 // Set up our media pipe helper, configure its callback and water marks to |
| 297 // kick off the playback process. | 296 // kick off the playback process. |
| 298 audio_pipe_.reset(new CircularBufferMediaPipeAdapter(media_pipe.Pass())); | 297 audio_pipe_.reset(new CircularBufferMediaPipeAdapter(media_pipe.Pass())); |
| 298 audio_pipe_->Init(USecToBytes(BUF_DEPTH_USEC)); |
| 299 audio_pipe_->SetWatermarks(USecToBytes(BUF_HI_WATER_USEC), | 299 audio_pipe_->SetWatermarks(USecToBytes(BUF_HI_WATER_USEC), |
| 300 USecToBytes(BUF_LO_WATER_USEC)); | 300 USecToBytes(BUF_LO_WATER_USEC)); |
| 301 audio_pipe_->SetSignalCallback( | 301 audio_pipe_->SetSignalCallback( |
| 302 [this](MediaResult res) -> void { | 302 [this](MediaResult res) -> void { |
| 303 OnNeedsData(res); | 303 OnNeedsData(res); |
| 304 }); | 304 }); |
| 305 } | 305 } |
| 306 | 306 |
| 307 bool PlayWAVApp::ReadAndValidateRIFFHeader() { | 307 bool PlayWAVApp::ReadAndValidateRIFFHeader() { |
| 308 // Read and sanity check the top level RIFF header | 308 // Read and sanity check the top level RIFF header |
| (...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 549 } // namespace audio | 549 } // namespace audio |
| 550 } // namespace media | 550 } // namespace media |
| 551 } // namespace mojo | 551 } // namespace mojo |
| 552 | 552 |
| 553 MojoResult MojoMain(MojoHandle app_request) { | 553 MojoResult MojoMain(MojoHandle app_request) { |
| 554 mojo::ApplicationRunner runner( | 554 mojo::ApplicationRunner runner( |
| 555 std::unique_ptr<mojo::media::audio::examples::PlayWAVApp>( | 555 std::unique_ptr<mojo::media::audio::examples::PlayWAVApp>( |
| 556 new mojo::media::audio::examples::PlayWAVApp())); | 556 new mojo::media::audio::examples::PlayWAVApp())); |
| 557 return runner.Run(app_request); | 557 return runner.Run(app_request); |
| 558 } | 558 } |
| OLD | NEW |