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 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
121 MOJO_DCHECK(wav_info_.frame_size); | 121 MOJO_DCHECK(wav_info_.frame_size); |
122 MOJO_DCHECK(frames < | 122 MOJO_DCHECK(frames < |
123 std::numeric_limits<uint32_t>::max() / wav_info_.frame_size); | 123 std::numeric_limits<uint32_t>::max() / wav_info_.frame_size); |
124 | 124 |
125 return frames * wav_info_.frame_size; | 125 return frames * wav_info_.frame_size; |
126 } | 126 } |
127 | 127 |
128 AudioServerPtr audio_server_; | 128 AudioServerPtr audio_server_; |
129 AudioTrackPtr audio_track_; | 129 AudioTrackPtr audio_track_; |
130 AudioPipePtr audio_pipe_; | 130 AudioPipePtr audio_pipe_; |
131 RateControlPtr rate_control_; | 131 TimelineConsumerPtr timeline_consumer_; |
132 AudioPacket audio_packet_; | 132 AudioPacket audio_packet_; |
133 PacketCbk playout_complete_cbk_; | 133 PacketCbk playout_complete_cbk_; |
134 NetworkServicePtr network_service_; | 134 NetworkServicePtr network_service_; |
135 URLLoaderPtr url_loader_; | 135 URLLoaderPtr url_loader_; |
136 ScopedDataPipeConsumerHandle payload_; | 136 ScopedDataPipeConsumerHandle payload_; |
137 uint32_t payload_len_; | 137 uint32_t payload_len_; |
138 RIFFChunkHeader riff_hdr_; | 138 RIFFChunkHeader riff_hdr_; |
139 WAVHeader wav_info_; | 139 WAVHeader wav_info_; |
140 RIFFChunkHeader data_hdr_; | 140 RIFFChunkHeader data_hdr_; |
141 bool sent_first_packet_ = false; | 141 bool sent_first_packet_ = false; |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
189 void PlayWAVApp::Quit() { | 189 void PlayWAVApp::Quit() { |
190 if (audio_packet_.packet()) { | 190 if (audio_packet_.packet()) { |
191 MOJO_DCHECK(audio_pipe_); | 191 MOJO_DCHECK(audio_pipe_); |
192 audio_pipe_->CancelMediaPacket(&audio_packet_); | 192 audio_pipe_->CancelMediaPacket(&audio_packet_); |
193 } | 193 } |
194 | 194 |
195 payload_.reset(); | 195 payload_.reset(); |
196 url_loader_.reset(); | 196 url_loader_.reset(); |
197 network_service_.reset(); | 197 network_service_.reset(); |
198 audio_pipe_.reset(); | 198 audio_pipe_.reset(); |
199 rate_control_.reset(); | 199 timeline_consumer_.reset(); |
200 audio_track_.reset(); | 200 audio_track_.reset(); |
201 audio_server_.reset(); | 201 audio_server_.reset(); |
202 } | 202 } |
203 | 203 |
204 bool PlayWAVApp::BlockingRead(void* buf, uint32_t op_len) { | 204 bool PlayWAVApp::BlockingRead(void* buf, uint32_t op_len) { |
205 MojoResult res; | 205 MojoResult res; |
206 uint32_t amt; | 206 uint32_t amt; |
207 | 207 |
208 while (true) { | 208 while (true) { |
209 amt = op_len; | 209 amt = op_len; |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
283 cfg->media_type = MediaType::New(); | 283 cfg->media_type = MediaType::New(); |
284 cfg->media_type->medium = MediaTypeMedium::AUDIO; | 284 cfg->media_type->medium = MediaTypeMedium::AUDIO; |
285 cfg->media_type->details = MediaTypeDetails::New(); | 285 cfg->media_type->details = MediaTypeDetails::New(); |
286 cfg->media_type->details->set_audio(pcm_cfg.Pass()); | 286 cfg->media_type->details->set_audio(pcm_cfg.Pass()); |
287 cfg->media_type->encoding = MediaType::kAudioEncodingLpcm; | 287 cfg->media_type->encoding = MediaType::kAudioEncodingLpcm; |
288 | 288 |
289 // Configure the track based on the WAV header information. | 289 // Configure the track based on the WAV header information. |
290 MediaConsumerPtr media_pipe; | 290 MediaConsumerPtr media_pipe; |
291 audio_track_->Configure(cfg.Pass(), GetProxy(&media_pipe)); | 291 audio_track_->Configure(cfg.Pass(), GetProxy(&media_pipe)); |
292 | 292 |
293 // Grab the rate control interface for our audio renderer. | 293 // Grab the timeline consumer interface for our audio renderer. |
294 audio_track_->GetRateControl(GetProxy(&rate_control_)); | 294 MediaTimelineControlSitePtr timeline_control_site; |
295 rate_control_.set_connection_error_handler([this]() { | 295 audio_track_->GetTimelineControlSite(GetProxy(&timeline_control_site)); |
296 OnConnectionError("rate_control"); | 296 timeline_control_site->GetTimelineConsumer(GetProxy(&timeline_consumer_)); |
297 }); | 297 timeline_consumer_.set_connection_error_handler( |
| 298 [this]() { OnConnectionError("timeline_consumer"); }); |
298 | 299 |
299 // Set up our media pipe helper, configure its callback and water marks to | 300 // Set up our media pipe helper, configure its callback and water marks to |
300 // kick off the playback process. | 301 // kick off the playback process. |
301 audio_pipe_.reset(new CircularBufferMediaPipeAdapter(media_pipe.Pass())); | 302 audio_pipe_.reset(new CircularBufferMediaPipeAdapter(media_pipe.Pass())); |
302 audio_pipe_->Init(USecToBytes(BUF_DEPTH_USEC)); | 303 audio_pipe_->Init(USecToBytes(BUF_DEPTH_USEC)); |
303 audio_pipe_->SetWatermarks(USecToBytes(BUF_HI_WATER_USEC), | 304 audio_pipe_->SetWatermarks(USecToBytes(BUF_HI_WATER_USEC), |
304 USecToBytes(BUF_LO_WATER_USEC)); | 305 USecToBytes(BUF_LO_WATER_USEC)); |
305 audio_pipe_->SetSignalCallback( | 306 audio_pipe_->SetSignalCallback( |
306 [this](MediaResult res) -> void { | 307 [this](MediaResult res) -> void { |
307 OnNeedsData(res); | 308 OnNeedsData(res); |
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
494 } | 495 } |
495 | 496 |
496 if (res != MediaResult::OK) { | 497 if (res != MediaResult::OK) { |
497 MOJO_LOG(ERROR) << "Failed to send media packet! " | 498 MOJO_LOG(ERROR) << "Failed to send media packet! " |
498 << "(res = " << res << ")"; | 499 << "(res = " << res << ")"; |
499 PostShutdown(); | 500 PostShutdown(); |
500 return; | 501 return; |
501 } | 502 } |
502 | 503 |
503 if (!clock_started_ && (audio_pipe_->AboveHiWater() || !payload_len_)) { | 504 if (!clock_started_ && (audio_pipe_->AboveHiWater() || !payload_len_)) { |
504 LocalTime sched = LocalClock::now() + local_time::from_msec(50); | 505 timeline_consumer_->SetTimelineTransform( |
505 rate_control_->SetRateAtTargetTime(1, 1, sched.time_since_epoch().count()); | 506 kUnspecifiedTime, 1, 1, kUnspecifiedTime, kUnspecifiedTime, |
| 507 [](bool completed) {}); |
506 clock_started_ = true; | 508 clock_started_ = true; |
507 } | 509 } |
508 } | 510 } |
509 | 511 |
510 void PlayWAVApp::OnPlayoutComplete(MediaConsumer::SendResult res) { | 512 void PlayWAVApp::OnPlayoutComplete(MediaConsumer::SendResult res) { |
511 MOJO_DCHECK(!audio_pipe_->GetPending()); | 513 MOJO_DCHECK(!audio_pipe_->GetPending()); |
512 audio_pipe_ = nullptr; | 514 audio_pipe_ = nullptr; |
513 PostShutdown(); | 515 PostShutdown(); |
514 } | 516 } |
515 | 517 |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
553 } // namespace audio | 555 } // namespace audio |
554 } // namespace media | 556 } // namespace media |
555 } // namespace mojo | 557 } // namespace mojo |
556 | 558 |
557 MojoResult MojoMain(MojoHandle app_request) { | 559 MojoResult MojoMain(MojoHandle app_request) { |
558 mojo::ApplicationRunner runner( | 560 mojo::ApplicationRunner runner( |
559 std::unique_ptr<mojo::media::audio::examples::PlayWAVApp>( | 561 std::unique_ptr<mojo::media::audio::examples::PlayWAVApp>( |
560 new mojo::media::audio::examples::PlayWAVApp())); | 562 new mojo::media::audio::examples::PlayWAVApp())); |
561 return runner.Run(app_request); | 563 return runner.Run(app_request); |
562 } | 564 } |
OLD | NEW |