| 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_impl_base.h" | 8 #include "mojo/public/cpp/application/application_impl_base.h" |
| 9 #include "mojo/public/cpp/application/connect.h" | 9 #include "mojo/public/cpp/application/connect.h" |
| 10 #include "mojo/public/cpp/application/run_application.h" | 10 #include "mojo/public/cpp/application/run_application.h" |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 53 public: | 53 public: |
| 54 ~PlayWAVApp() override { OnQuit(); } | 54 ~PlayWAVApp() override { OnQuit(); } |
| 55 | 55 |
| 56 // ApplicationImplBase overrides: | 56 // ApplicationImplBase overrides: |
| 57 void OnInitialize() override; | 57 void OnInitialize() override; |
| 58 void OnQuit() override; | 58 void OnQuit() override; |
| 59 | 59 |
| 60 private: | 60 private: |
| 61 using AudioPipePtr = std::unique_ptr<CircularBufferMediaPipeAdapter>; | 61 using AudioPipePtr = std::unique_ptr<CircularBufferMediaPipeAdapter>; |
| 62 using AudioPacket = CircularBufferMediaPipeAdapter::MappedPacket; | 62 using AudioPacket = CircularBufferMediaPipeAdapter::MappedPacket; |
| 63 using PacketCbk = MediaConsumer::SendPacketCallback; | 63 using PacketCbk = MediaPacketConsumer::SendPacketCallback; |
| 64 | 64 |
| 65 // TODO(johngro): endianness! | 65 // TODO(johngro): endianness! |
| 66 struct PACKED RIFFChunkHeader { | 66 struct PACKED RIFFChunkHeader { |
| 67 uint32_t four_cc; | 67 uint32_t four_cc; |
| 68 uint32_t length; | 68 uint32_t length; |
| 69 }; | 69 }; |
| 70 | 70 |
| 71 struct PACKED WAVHeader { | 71 struct PACKED WAVHeader { |
| 72 uint32_t wave_four_cc; | 72 uint32_t wave_four_cc; |
| 73 uint32_t fmt_four_cc; | 73 uint32_t fmt_four_cc; |
| (...skipping 22 matching lines...) Expand all Loading... |
| 96 static const std::set<uint16_t> VALID_BITS_PER_SAMPLES; | 96 static const std::set<uint16_t> VALID_BITS_PER_SAMPLES; |
| 97 | 97 |
| 98 bool BlockingRead(void* buf, uint32_t len); | 98 bool BlockingRead(void* buf, uint32_t len); |
| 99 void ProcessHTTPResponse(URLResponsePtr resp); | 99 void ProcessHTTPResponse(URLResponsePtr resp); |
| 100 | 100 |
| 101 bool ReadAndValidateRIFFHeader(); | 101 bool ReadAndValidateRIFFHeader(); |
| 102 bool ReadAndValidateWAVHeader(); | 102 bool ReadAndValidateWAVHeader(); |
| 103 bool ReadAndValidateDATAHeader(); | 103 bool ReadAndValidateDATAHeader(); |
| 104 | 104 |
| 105 void OnNeedsData(MediaResult res); | 105 void OnNeedsData(MediaResult res); |
| 106 void OnPlayoutComplete(MediaConsumer::SendResult res); | 106 void OnPlayoutComplete(MediaPacketConsumer::SendResult res); |
| 107 void OnConnectionError(const std::string& connection_name); | 107 void OnConnectionError(const std::string& connection_name); |
| 108 void PostShutdown(); | 108 void PostShutdown(); |
| 109 void Shutdown(); | 109 void Shutdown(); |
| 110 | 110 |
| 111 uint32_t USecToFrames(uint32_t usec) { | 111 uint32_t USecToFrames(uint32_t usec) { |
| 112 uint64_t ret = (static_cast<uint64_t>(usec) * wav_info_.frame_rate) | 112 uint64_t ret = (static_cast<uint64_t>(usec) * wav_info_.frame_rate) |
| 113 / 1000000; | 113 / 1000000; |
| 114 MOJO_DCHECK(ret < std::numeric_limits<uint32_t>::max()); | 114 MOJO_DCHECK(ret < std::numeric_limits<uint32_t>::max()); |
| 115 return ret; | 115 return ret; |
| 116 } | 116 } |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 168 GetProxy(&network_service_)); | 168 GetProxy(&network_service_)); |
| 169 audio_server_.set_connection_error_handler([this]() { | 169 audio_server_.set_connection_error_handler([this]() { |
| 170 OnConnectionError("network_service"); | 170 OnConnectionError("network_service"); |
| 171 }); | 171 }); |
| 172 | 172 |
| 173 network_service_->CreateURLLoader(GetProxy(&url_loader_)); | 173 network_service_->CreateURLLoader(GetProxy(&url_loader_)); |
| 174 url_loader_.set_connection_error_handler([this]() { | 174 url_loader_.set_connection_error_handler([this]() { |
| 175 OnConnectionError("url_loader"); | 175 OnConnectionError("url_loader"); |
| 176 }); | 176 }); |
| 177 | 177 |
| 178 playout_complete_cbk_ = PacketCbk([this](MediaConsumer::SendResult res) { | 178 playout_complete_cbk_ = |
| 179 this->OnPlayoutComplete(res); | 179 PacketCbk([this](MediaPacketConsumer::SendResult res) { |
| 180 }); | 180 this->OnPlayoutComplete(res); |
| 181 }); |
| 181 | 182 |
| 182 URLRequestPtr req(URLRequest::New()); | 183 URLRequestPtr req(URLRequest::New()); |
| 183 req->url = TEST_FILE; | 184 req->url = TEST_FILE; |
| 184 req->method = "GET"; | 185 req->method = "GET"; |
| 185 | 186 |
| 186 auto cbk = [this](URLResponsePtr resp) { ProcessHTTPResponse(resp.Pass()); }; | 187 auto cbk = [this](URLResponsePtr resp) { ProcessHTTPResponse(resp.Pass()); }; |
| 187 url_loader_->Start(req.Pass(), URLLoader::StartCallback(cbk)); | 188 url_loader_->Start(req.Pass(), URLLoader::StartCallback(cbk)); |
| 188 } | 189 } |
| 189 | 190 |
| 190 void PlayWAVApp::OnQuit() { | 191 void PlayWAVApp::OnQuit() { |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 275 pcm_cfg->frames_per_second = wav_info_.frame_rate; | 276 pcm_cfg->frames_per_second = wav_info_.frame_rate; |
| 276 | 277 |
| 277 MediaTypePtr media_type = MediaType::New(); | 278 MediaTypePtr media_type = MediaType::New(); |
| 278 media_type->medium = MediaTypeMedium::AUDIO; | 279 media_type->medium = MediaTypeMedium::AUDIO; |
| 279 media_type->details = MediaTypeDetails::New(); | 280 media_type->details = MediaTypeDetails::New(); |
| 280 media_type->details->set_audio(pcm_cfg.Pass()); | 281 media_type->details->set_audio(pcm_cfg.Pass()); |
| 281 media_type->encoding = MediaType::kAudioEncodingLpcm; | 282 media_type->encoding = MediaType::kAudioEncodingLpcm; |
| 282 | 283 |
| 283 // Configure the track based on the WAV header information. | 284 // Configure the track based on the WAV header information. |
| 284 media_renderer_->SetMediaType(media_type.Pass()); | 285 media_renderer_->SetMediaType(media_type.Pass()); |
| 285 MediaConsumerPtr media_pipe; | 286 MediaPacketConsumerPtr media_pipe; |
| 286 media_renderer_->GetConsumer(GetProxy(&media_pipe)); | 287 media_renderer_->GetPacketConsumer(GetProxy(&media_pipe)); |
| 287 | 288 |
| 288 // Grab the timeline consumer interface for our audio renderer. | 289 // Grab the timeline consumer interface for our audio renderer. |
| 289 MediaTimelineControlPointPtr timeline_control_point; | 290 MediaTimelineControlPointPtr timeline_control_point; |
| 290 media_renderer_->GetTimelineControlPoint(GetProxy(&timeline_control_point)); | 291 media_renderer_->GetTimelineControlPoint(GetProxy(&timeline_control_point)); |
| 291 timeline_control_point->GetTimelineConsumer(GetProxy(&timeline_consumer_)); | 292 timeline_control_point->GetTimelineConsumer(GetProxy(&timeline_consumer_)); |
| 292 timeline_consumer_.set_connection_error_handler( | 293 timeline_consumer_.set_connection_error_handler( |
| 293 [this]() { OnConnectionError("timeline_consumer"); }); | 294 [this]() { OnConnectionError("timeline_consumer"); }); |
| 294 | 295 |
| 295 // Set up our media pipe helper, configure its callback and water marks to | 296 // Set up our media pipe helper, configure its callback and water marks to |
| 296 // kick off the playback process. | 297 // kick off the playback process. |
| (...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 501 timeline_transform->reference_time = kUnspecifiedTime; | 502 timeline_transform->reference_time = kUnspecifiedTime; |
| 502 timeline_transform->subject_time = kUnspecifiedTime; | 503 timeline_transform->subject_time = kUnspecifiedTime; |
| 503 timeline_transform->reference_delta = 1; | 504 timeline_transform->reference_delta = 1; |
| 504 timeline_transform->subject_delta = 1; | 505 timeline_transform->subject_delta = 1; |
| 505 timeline_consumer_->SetTimelineTransform(timeline_transform.Pass(), | 506 timeline_consumer_->SetTimelineTransform(timeline_transform.Pass(), |
| 506 [](bool completed) {}); | 507 [](bool completed) {}); |
| 507 clock_started_ = true; | 508 clock_started_ = true; |
| 508 } | 509 } |
| 509 } | 510 } |
| 510 | 511 |
| 511 void PlayWAVApp::OnPlayoutComplete(MediaConsumer::SendResult res) { | 512 void PlayWAVApp::OnPlayoutComplete(MediaPacketConsumer::SendResult res) { |
| 512 MOJO_DCHECK(!audio_pipe_->GetPending()); | 513 MOJO_DCHECK(!audio_pipe_->GetPending()); |
| 513 audio_pipe_ = nullptr; | 514 audio_pipe_ = nullptr; |
| 514 PostShutdown(); | 515 PostShutdown(); |
| 515 } | 516 } |
| 516 | 517 |
| 517 void PlayWAVApp::OnConnectionError(const std::string& connection_name) { | 518 void PlayWAVApp::OnConnectionError(const std::string& connection_name) { |
| 518 if (!shutting_down_) { | 519 if (!shutting_down_) { |
| 519 MOJO_LOG(ERROR) << connection_name << " connection closed unexpectedly!"; | 520 MOJO_LOG(ERROR) << connection_name << " connection closed unexpectedly!"; |
| 520 PostShutdown(); | 521 PostShutdown(); |
| 521 } | 522 } |
| (...skipping 30 matching lines...) Expand all Loading... |
| 552 | 553 |
| 553 } // namespace examples | 554 } // namespace examples |
| 554 } // namespace audio | 555 } // namespace audio |
| 555 } // namespace media | 556 } // namespace media |
| 556 } // namespace mojo | 557 } // namespace mojo |
| 557 | 558 |
| 558 MojoResult MojoMain(MojoHandle app_request) { | 559 MojoResult MojoMain(MojoHandle app_request) { |
| 559 mojo::media::audio::examples::PlayWAVApp play_wav_app; | 560 mojo::media::audio::examples::PlayWAVApp play_wav_app; |
| 560 return mojo::RunApplication(app_request, &play_wav_app); | 561 return mojo::RunApplication(app_request, &play_wav_app); |
| 561 } | 562 } |
| OLD | NEW |