| 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 <math.h> | 5 #include <math.h> |
| 6 #include <memory> | 6 #include <memory> |
| 7 | 7 |
| 8 #include "mojo/public/c/system/main.h" | 8 #include "mojo/public/c/system/main.h" |
| 9 #include "mojo/public/cpp/application/application_delegate.h" | 9 #include "mojo/public/cpp/application/application_delegate.h" |
| 10 #include "mojo/public/cpp/application/application_impl.h" | 10 #include "mojo/public/cpp/application/application_impl.h" |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 114 sink_desc.reset(); | 114 sink_desc.reset(); |
| 115 | 115 |
| 116 // Grab the rate control interface for our audio renderer. | 116 // Grab the rate control interface for our audio renderer. |
| 117 audio_track_->GetRateControl(GetProxy(&rate_control_)); | 117 audio_track_->GetRateControl(GetProxy(&rate_control_)); |
| 118 rate_control_.set_connection_error_handler([this]() { | 118 rate_control_.set_connection_error_handler([this]() { |
| 119 OnConnectionError("rate_control"); | 119 OnConnectionError("rate_control"); |
| 120 }); | 120 }); |
| 121 | 121 |
| 122 // Configure our sink for 16-bit 48KHz mono. | 122 // Configure our sink for 16-bit 48KHz mono. |
| 123 AudioTrackConfigurationPtr cfg = AudioTrackConfiguration::New(); | 123 AudioTrackConfigurationPtr cfg = AudioTrackConfiguration::New(); |
| 124 cfg->max_frames = USecToBytes(BUF_DEPTH_USEC) / FRAME_BYTES; | |
| 125 | 124 |
| 126 LpcmMediaTypeDetailsPtr pcm_cfg = LpcmMediaTypeDetails::New(); | 125 LpcmMediaTypeDetailsPtr pcm_cfg = LpcmMediaTypeDetails::New(); |
| 127 pcm_cfg->sample_format = LpcmSampleFormat::SIGNED_16; | 126 pcm_cfg->sample_format = LpcmSampleFormat::SIGNED_16; |
| 128 pcm_cfg->channels = 1; | 127 pcm_cfg->channels = 1; |
| 129 pcm_cfg->frames_per_second = SAMP_FREQ; | 128 pcm_cfg->frames_per_second = SAMP_FREQ; |
| 130 | 129 |
| 131 cfg->media_type = MediaType::New(); | 130 cfg->media_type = MediaType::New(); |
| 132 cfg->media_type->scheme = MediaTypeScheme::LPCM; | 131 cfg->media_type->scheme = MediaTypeScheme::LPCM; |
| 133 cfg->media_type->details = MediaTypeDetails::New(); | 132 cfg->media_type->details = MediaTypeDetails::New(); |
| 134 cfg->media_type->details->set_lpcm(pcm_cfg.Pass()); | 133 cfg->media_type->details->set_lpcm(pcm_cfg.Pass()); |
| 135 | 134 |
| 136 MediaPipePtr pipe; | 135 MediaPipePtr pipe; |
| 137 audio_track_->Configure(cfg.Pass(), GetProxy(&pipe)); | 136 audio_track_->Configure(cfg.Pass(), GetProxy(&pipe)); |
| 138 | 137 |
| 139 // Now that the configuration request is in-flight and we our media pipe | 138 // Now that the configuration request is in-flight and we our media pipe |
| 140 // proxy, pass its interface to our circular buffer helper, set up our | 139 // proxy, pass its interface to our circular buffer helper, set up our |
| 141 // high/low water marks, register our callback, and start to buffer our audio. | 140 // high/low water marks, register our callback, and start to buffer our audio. |
| 142 audio_pipe_.reset(new CircularBufferMediaPipeAdapter(pipe.Pass())); | 141 audio_pipe_.reset(new CircularBufferMediaPipeAdapter(pipe.Pass())); |
| 142 audio_pipe_->Init(USecToBytes(BUF_DEPTH_USEC)); |
| 143 audio_pipe_->SetSignalCallback( | 143 audio_pipe_->SetSignalCallback( |
| 144 [this](MediaResult res) -> void { | 144 [this](MediaResult res) -> void { |
| 145 GenerateToneCbk(res); | 145 GenerateToneCbk(res); |
| 146 }); | 146 }); |
| 147 audio_pipe_->SetWatermarks(USecToBytes(BUF_HI_WATER_USEC), | 147 audio_pipe_->SetWatermarks(USecToBytes(BUF_HI_WATER_USEC), |
| 148 USecToBytes(BUF_LO_WATER_USEC)); | 148 USecToBytes(BUF_LO_WATER_USEC)); |
| 149 } | 149 } |
| 150 | 150 |
| 151 void PlayToneApp::GenerateToneCbk(MediaResult res) { | 151 void PlayToneApp::GenerateToneCbk(MediaResult res) { |
| 152 using MappedPacket = CircularBufferMediaPipeAdapter::MappedPacket; | 152 using MappedPacket = CircularBufferMediaPipeAdapter::MappedPacket; |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 246 } // namespace audio | 246 } // namespace audio |
| 247 } // namespace media | 247 } // namespace media |
| 248 } // namespace mojo | 248 } // namespace mojo |
| 249 | 249 |
| 250 MojoResult MojoMain(MojoHandle app_request) { | 250 MojoResult MojoMain(MojoHandle app_request) { |
| 251 mojo::ApplicationRunner runner( | 251 mojo::ApplicationRunner runner( |
| 252 std::unique_ptr<mojo::media::audio::examples::PlayToneApp>( | 252 std::unique_ptr<mojo::media::audio::examples::PlayToneApp>( |
| 253 new mojo::media::audio::examples::PlayToneApp())); | 253 new mojo::media::audio::examples::PlayToneApp())); |
| 254 return runner.Run(app_request); | 254 return runner.Run(app_request); |
| 255 } | 255 } |
| OLD | NEW |