Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(375)

Side by Side Diff: examples/media_test/media_test_app.cc

Issue 2015643002: Add (optional) options to Run[Main]Application(). (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: doh Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 <deque> 5 #include <deque>
6 #include <iomanip> 6 #include <iomanip>
7 #include <iostream> 7 #include <iostream>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/message_loop/message_loop.h"
10 #include "examples/media_test/keystroke.h" 11 #include "examples/media_test/keystroke.h"
11 #include "examples/media_test/media_test.h" 12 #include "examples/media_test/media_test.h"
12 #include "mojo/application/application_runner_chromium.h"
13 #include "mojo/public/c/system/main.h" 13 #include "mojo/public/c/system/main.h"
14 #include "mojo/public/cpp/application/application_delegate.h" 14 #include "mojo/public/cpp/application/application_impl_base.h"
15 #include "mojo/public/cpp/application/application_impl.h" 15 #include "mojo/public/cpp/application/run_application.h"
16 16
17 namespace mojo { 17 namespace mojo {
18 namespace media { 18 namespace media {
19 namespace examples { 19 namespace examples {
20 20
21 class MediaTestApp : public mojo::ApplicationDelegate { 21 class MediaTestApp : public mojo::ApplicationImplBase {
22 public: 22 public:
23 MediaTestApp() {} 23 MediaTestApp() {}
24 24
25 ~MediaTestApp() override {} 25 ~MediaTestApp() override {}
26 26
27 // ApplicationDelegate implementation. 27 // ApplicationImplBase overrides.
28 void Initialize(mojo::ApplicationImpl* app) override { 28 void OnInitialize() override {
29 app_ = app; 29 ProcessArgs(args());
30 ProcessArgs(app->args());
31 30
32 std::cout << std::endl << "MEDIA TEST" << std::endl << std::endl; 31 std::cout << std::endl << "MEDIA TEST" << std::endl << std::endl;
33 32
34 if (input_file_names_.empty()) { 33 if (input_file_names_.empty()) {
35 std::cout << "Please provide the names of the files you want to play;" 34 std::cout << "Please provide the names of the files you want to play;"
36 << " for example:" << std::endl 35 << " for example:" << std::endl
37 << "mojo/devtools/common/mojo_run \\" << std::endl 36 << "mojo/devtools/common/mojo_run \\" << std::endl
38 << " \"https://core.mojoapps.io/media_test.mojo \\" 37 << " \"https://core.mojoapps.io/media_test.mojo \\"
39 << std::endl 38 << std::endl
40 << " http:/localhost/superstition.ogg \\" << std::endl 39 << " http:/localhost/superstition.ogg \\" << std::endl
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
88 } 87 }
89 } 88 }
90 89
91 input_file_names_iter_ = input_file_names_.begin(); 90 input_file_names_iter_ = input_file_names_.begin();
92 } 91 }
93 92
94 // Creates a new MediaTest object to play the file referenced by 93 // Creates a new MediaTest object to play the file referenced by
95 // input_file_names_iter_. 94 // input_file_names_iter_.
96 void CreateNewMediaTest() { 95 void CreateNewMediaTest() {
97 MOJO_DCHECK(input_file_names_iter_ != input_file_names_.end()); 96 MOJO_DCHECK(input_file_names_iter_ != input_file_names_.end());
98 media_test_ = MediaTest::Create(app_, *input_file_names_iter_); 97 media_test_ = MediaTest::Create(shell(), *input_file_names_iter_);
99 98
100 metadata_shown_ = false; 99 metadata_shown_ = false;
101 media_test_->RegisterUpdateCallback( 100 media_test_->RegisterUpdateCallback(
102 [this]() { HandleMediaTestUpdateCallback(); }); 101 [this]() { HandleMediaTestUpdateCallback(); });
103 102
104 media_test_->Play(); 103 media_test_->Play();
105 } 104 }
106 105
107 void HandleMediaTestUpdateCallback() { 106 void HandleMediaTestUpdateCallback() {
108 if (media_test_->state() == MediaTest::State::kEnded && 107 if (media_test_->state() == MediaTest::State::kEnded &&
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after
287 void PlayNext() { 286 void PlayNext() {
288 if (++input_file_names_iter_ == input_file_names_.end()) { 287 if (++input_file_names_iter_ == input_file_names_.end()) {
289 input_file_names_iter_ = input_file_names_.begin(); 288 input_file_names_iter_ = input_file_names_.begin();
290 } else { 289 } else {
291 CreateNewMediaTest(); 290 CreateNewMediaTest();
292 } 291 }
293 } 292 }
294 293
295 const char* clear_line() const { return paint_ ? kClearLine : ""; } 294 const char* clear_line() const { return paint_ ? kClearLine : ""; }
296 295
297 mojo::ApplicationImpl* app_;
298 std::unique_ptr<MediaTest> media_test_; 296 std::unique_ptr<MediaTest> media_test_;
299 std::deque<std::string> input_file_names_; 297 std::deque<std::string> input_file_names_;
300 decltype(input_file_names_.begin()) input_file_names_iter_; 298 decltype(input_file_names_.begin()) input_file_names_iter_;
301 bool quit_ = false; 299 bool quit_ = false;
302 bool paint_ = true; 300 bool paint_ = true;
303 bool metadata_shown_ = false; 301 bool metadata_shown_ = false;
304 uint64_t duration_ns_; 302 uint64_t duration_ns_;
305 303
306 DISALLOW_COPY_AND_ASSIGN(MediaTestApp); 304 DISALLOW_COPY_AND_ASSIGN(MediaTestApp);
307 }; 305 };
308 306
309 const char* MediaTestApp::kHome = "\r"; 307 const char* MediaTestApp::kHome = "\r";
310 const char* MediaTestApp::kClearLine = "\033[K"; 308 const char* MediaTestApp::kClearLine = "\033[K";
311 const char* MediaTestApp::kUp = "\033[A"; 309 const char* MediaTestApp::kUp = "\033[A";
312 310
313 } // namespace examples 311 } // namespace examples
314 } // namespace media 312 } // namespace media
315 } // namespace mojo 313 } // namespace mojo
316 314
317 MojoResult MojoMain(MojoHandle application_request) { 315 MojoResult MojoMain(MojoHandle application_request) {
318 mojo::ApplicationRunnerChromium runner( 316 mojo::media::examples::MediaTestApp media_test_app;
319 new mojo::media::examples::MediaTestApp); 317 return mojo::RunMainApplication(application_request, &media_test_app);
320 return runner.Run(application_request);
321 } 318 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698