| 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_impl_base.h" |
| 9 #include "mojo/public/cpp/application/application_impl.h" | |
| 10 #include "mojo/public/cpp/application/application_runner.h" | |
| 11 #include "mojo/public/cpp/application/connect.h" | 9 #include "mojo/public/cpp/application/connect.h" |
| 10 #include "mojo/public/cpp/application/run_application.h" |
| 12 #include "mojo/public/cpp/system/data_pipe.h" | 11 #include "mojo/public/cpp/system/data_pipe.h" |
| 13 #include "mojo/public/cpp/system/wait.h" | 12 #include "mojo/public/cpp/system/wait.h" |
| 14 #include "mojo/public/cpp/utility/run_loop.h" | 13 #include "mojo/public/cpp/utility/run_loop.h" |
| 15 #include "mojo/services/media/audio/interfaces/audio_server.mojom.h" | 14 #include "mojo/services/media/audio/interfaces/audio_server.mojom.h" |
| 16 #include "mojo/services/media/audio/interfaces/audio_track.mojom.h" | 15 #include "mojo/services/media/audio/interfaces/audio_track.mojom.h" |
| 17 #include "mojo/services/media/common/cpp/circular_buffer_media_pipe_adapter.h" | 16 #include "mojo/services/media/common/cpp/circular_buffer_media_pipe_adapter.h" |
| 18 #include "mojo/services/media/common/cpp/linear_transform.h" | 17 #include "mojo/services/media/common/cpp/linear_transform.h" |
| 19 #include "mojo/services/media/common/cpp/local_time.h" | 18 #include "mojo/services/media/common/cpp/local_time.h" |
| 20 #include "mojo/services/network/interfaces/network_service.mojom.h" | 19 #include "mojo/services/network/interfaces/network_service.mojom.h" |
| 21 #include "mojo/services/network/interfaces/url_loader.mojom.h" | 20 #include "mojo/services/network/interfaces/url_loader.mojom.h" |
| (...skipping 20 matching lines...) Expand all Loading... |
| 42 namespace audio { | 41 namespace audio { |
| 43 namespace examples { | 42 namespace examples { |
| 44 | 43 |
| 45 static constexpr const char* TEST_FILE = | 44 static constexpr const char* TEST_FILE = |
| 46 "http://localhost/test_content/piano2.wav"; | 45 "http://localhost/test_content/piano2.wav"; |
| 47 static constexpr uint32_t BUF_DEPTH_USEC = 500000; | 46 static constexpr uint32_t BUF_DEPTH_USEC = 500000; |
| 48 static constexpr uint32_t BUF_LO_WATER_USEC = 400000; | 47 static constexpr uint32_t BUF_LO_WATER_USEC = 400000; |
| 49 static constexpr uint32_t BUF_HI_WATER_USEC = 450000; | 48 static constexpr uint32_t BUF_HI_WATER_USEC = 450000; |
| 50 static constexpr uint32_t CHUNK_SIZE_USEC = 10000; | 49 static constexpr uint32_t CHUNK_SIZE_USEC = 10000; |
| 51 | 50 |
| 52 class PlayWAVApp : public ApplicationDelegate { | 51 class PlayWAVApp : public ApplicationImplBase { |
| 53 public: | 52 public: |
| 54 ~PlayWAVApp() override { Quit(); } | 53 ~PlayWAVApp() override { OnQuit(); } |
| 55 | 54 |
| 56 // ApplicationDelegate | 55 // ApplicationImplBase overrides: |
| 57 void Initialize(ApplicationImpl* app) override; | 56 void OnInitialize() override; |
| 58 void Quit() override; | 57 void OnQuit() override; |
| 59 | 58 |
| 60 private: | 59 private: |
| 61 using AudioPipePtr = std::unique_ptr<CircularBufferMediaPipeAdapter>; | 60 using AudioPipePtr = std::unique_ptr<CircularBufferMediaPipeAdapter>; |
| 62 using AudioPacket = CircularBufferMediaPipeAdapter::MappedPacket; | 61 using AudioPacket = CircularBufferMediaPipeAdapter::MappedPacket; |
| 63 using PacketCbk = MediaConsumer::SendPacketCallback; | 62 using PacketCbk = MediaConsumer::SendPacketCallback; |
| 64 | 63 |
| 65 // TODO(johngro): endianness! | 64 // TODO(johngro): endianness! |
| 66 struct PACKED RIFFChunkHeader { | 65 struct PACKED RIFFChunkHeader { |
| 67 uint32_t four_cc; | 66 uint32_t four_cc; |
| 68 uint32_t length; | 67 uint32_t length; |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 150 | 149 |
| 151 const std::set<uint16_t> PlayWAVApp::VALID_FRAME_RATES({ | 150 const std::set<uint16_t> PlayWAVApp::VALID_FRAME_RATES({ |
| 152 8000, 16000, 24000, 32000, 48000, | 151 8000, 16000, 24000, 32000, 48000, |
| 153 11025, 22050, 44100, | 152 11025, 22050, 44100, |
| 154 }); | 153 }); |
| 155 | 154 |
| 156 const std::set<uint16_t> PlayWAVApp::VALID_BITS_PER_SAMPLES({ | 155 const std::set<uint16_t> PlayWAVApp::VALID_BITS_PER_SAMPLES({ |
| 157 8, 16, | 156 8, 16, |
| 158 }); | 157 }); |
| 159 | 158 |
| 160 void PlayWAVApp::Initialize(ApplicationImpl* app) { | 159 void PlayWAVApp::OnInitialize() { |
| 161 ConnectToService(app->shell(), "mojo:audio_server", GetProxy(&audio_server_)); | 160 ConnectToService(shell(), "mojo:audio_server", GetProxy(&audio_server_)); |
| 162 audio_server_.set_connection_error_handler([this]() { | 161 audio_server_.set_connection_error_handler([this]() { |
| 163 OnConnectionError("audio_server"); | 162 OnConnectionError("audio_server"); |
| 164 }); | 163 }); |
| 165 | 164 |
| 166 ConnectToService(app->shell(), "mojo:network_service", | 165 ConnectToService(shell(), "mojo:network_service", |
| 167 GetProxy(&network_service_)); | 166 GetProxy(&network_service_)); |
| 168 audio_server_.set_connection_error_handler([this]() { | 167 audio_server_.set_connection_error_handler([this]() { |
| 169 OnConnectionError("network_service"); | 168 OnConnectionError("network_service"); |
| 170 }); | 169 }); |
| 171 | 170 |
| 172 network_service_->CreateURLLoader(GetProxy(&url_loader_)); | 171 network_service_->CreateURLLoader(GetProxy(&url_loader_)); |
| 173 url_loader_.set_connection_error_handler([this]() { | 172 url_loader_.set_connection_error_handler([this]() { |
| 174 OnConnectionError("url_loader"); | 173 OnConnectionError("url_loader"); |
| 175 }); | 174 }); |
| 176 | 175 |
| 177 playout_complete_cbk_ = PacketCbk([this](MediaConsumer::SendResult res) { | 176 playout_complete_cbk_ = PacketCbk([this](MediaConsumer::SendResult res) { |
| 178 this->OnPlayoutComplete(res); | 177 this->OnPlayoutComplete(res); |
| 179 }); | 178 }); |
| 180 | 179 |
| 181 URLRequestPtr req(URLRequest::New()); | 180 URLRequestPtr req(URLRequest::New()); |
| 182 req->url = TEST_FILE; | 181 req->url = TEST_FILE; |
| 183 req->method = "GET"; | 182 req->method = "GET"; |
| 184 | 183 |
| 185 auto cbk = [this](URLResponsePtr resp) { ProcessHTTPResponse(resp.Pass()); }; | 184 auto cbk = [this](URLResponsePtr resp) { ProcessHTTPResponse(resp.Pass()); }; |
| 186 url_loader_->Start(req.Pass(), URLLoader::StartCallback(cbk)); | 185 url_loader_->Start(req.Pass(), URLLoader::StartCallback(cbk)); |
| 187 } | 186 } |
| 188 | 187 |
| 189 void PlayWAVApp::Quit() { | 188 void PlayWAVApp::OnQuit() { |
| 190 if (audio_packet_.packet()) { | 189 if (audio_packet_.packet()) { |
| 191 MOJO_DCHECK(audio_pipe_); | 190 MOJO_DCHECK(audio_pipe_); |
| 192 audio_pipe_->CancelMediaPacket(&audio_packet_); | 191 audio_pipe_->CancelMediaPacket(&audio_packet_); |
| 193 } | 192 } |
| 194 | 193 |
| 195 payload_.reset(); | 194 payload_.reset(); |
| 196 url_loader_.reset(); | 195 url_loader_.reset(); |
| 197 network_service_.reset(); | 196 network_service_.reset(); |
| 198 audio_pipe_.reset(); | 197 audio_pipe_.reset(); |
| 199 timeline_consumer_.reset(); | 198 timeline_consumer_.reset(); |
| (...skipping 340 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 540 // have registered on interfaces) before finally destroying our application | 539 // have registered on interfaces) before finally destroying our application |
| 541 // object. | 540 // object. |
| 542 // | 541 // |
| 543 // The net result is that we end up spurious "connection closed unexpectedly" | 542 // The net result is that we end up spurious "connection closed unexpectedly" |
| 544 // error messages when we are actually shutting down cleanly. For now, we | 543 // error messages when we are actually shutting down cleanly. For now, we |
| 545 // suppress this by having a shutting_down_ flag and suppressing the error | 544 // suppress this by having a shutting_down_ flag and suppressing the error |
| 546 // message which show up after shutdown has been triggered. When the proper | 545 // message which show up after shutdown has been triggered. When the proper |
| 547 // pattern for shutting down an app has been established, come back here and | 546 // pattern for shutting down an app has been established, come back here and |
| 548 // remove all this junk. | 547 // remove all this junk. |
| 549 void PlayWAVApp::Shutdown() { | 548 void PlayWAVApp::Shutdown() { |
| 550 Quit(); | 549 OnQuit(); |
| 551 RunLoop::current()->Quit(); | 550 RunLoop::current()->Quit(); |
| 552 } | 551 } |
| 553 | 552 |
| 554 } // namespace examples | 553 } // namespace examples |
| 555 } // namespace audio | 554 } // namespace audio |
| 556 } // namespace media | 555 } // namespace media |
| 557 } // namespace mojo | 556 } // namespace mojo |
| 558 | 557 |
| 559 MojoResult MojoMain(MojoHandle app_request) { | 558 MojoResult MojoMain(MojoHandle app_request) { |
| 560 mojo::ApplicationRunner runner( | 559 mojo::media::audio::examples::PlayWAVApp play_wav_app; |
| 561 std::unique_ptr<mojo::media::audio::examples::PlayWAVApp>( | 560 return mojo::RunMainApplication(app_request, &play_wav_app); |
| 562 new mojo::media::audio::examples::PlayWAVApp())); | |
| 563 return runner.Run(app_request); | |
| 564 } | 561 } |
| OLD | NEW |