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 <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 "examples/media_test/keystroke.h" | 10 #include "examples/media_test/keystroke.h" |
(...skipping 16 matching lines...) Expand all Loading... |
27 | 27 |
28 // ApplicationDelegate implementation. | 28 // ApplicationDelegate implementation. |
29 void Initialize(mojo::ApplicationImpl* app) override { | 29 void Initialize(mojo::ApplicationImpl* app) override { |
30 app_ = app; | 30 app_ = app; |
31 ProcessArgs(app->args()); | 31 ProcessArgs(app->args()); |
32 | 32 |
33 std::cout << std::endl << "MEDIA TEST" << std::endl << std::endl; | 33 std::cout << std::endl << "MEDIA TEST" << std::endl << std::endl; |
34 | 34 |
35 if (input_file_names_.empty()) { | 35 if (input_file_names_.empty()) { |
36 std::cout << "Please provide the names of the files you want to play;" | 36 std::cout << "Please provide the names of the files you want to play;" |
37 << " for example:" << std::endl; | 37 << " for example:" << std::endl |
38 std::cout << "mojo/devtools/common/mojo_run \\" << std::endl; | 38 << "mojo/devtools/common/mojo_run \\" << std::endl |
39 std::cout << " \"https://core.mojoapps.io/media_test.mojo \\" | 39 << " \"https://core.mojoapps.io/media_test.mojo \\" |
40 << std::endl; | |
41 std::cout << " file:///usr/local/google/home/you/superstition.ogg \\" | |
42 << std::endl; | |
43 std::cout << " file:///usr/local/google/home/you/higherground.ogg\"" | |
44 << std::endl | 40 << std::endl |
| 41 << " http:/localhost/superstition.ogg \\" << std::endl |
| 42 << " http:/localhost/higherground.ogg\"" << std::endl |
45 << std::endl; | 43 << std::endl; |
46 base::MessageLoop::current()->Quit(); | 44 base::MessageLoop::current()->Quit(); |
47 return; | 45 return; |
48 } | 46 } |
49 | 47 |
50 std::cout << " <enter> play/pause" << std::endl; | 48 std::cout << " <enter> play/pause" << std::endl |
51 std::cout << " n<enter> next file" << std::endl; | 49 << " n<enter> next file" << std::endl |
52 std::cout << " p<enter> previous file" << std::endl; | 50 << " p<enter> previous file" << std::endl |
53 std::cout << " <digit><enter> seek (0% - 90%)" << std::endl; | 51 << " <digit><enter> seek (0% - 90%)" << std::endl |
54 std::cout << " q<enter> quit" << std::endl << std::endl; | 52 << " q<enter> quit" << std::endl |
| 53 << std::endl; |
55 | 54 |
56 if (paint_) { | 55 if (paint_) { |
57 std::cout << " duration <none>" << std::endl; | 56 std::cout << " duration <none>" << std::endl |
58 std::cout << " title <none>" << std::endl; | 57 << " title <none>" << std::endl |
59 std::cout << " artist <none>" << std::endl; | 58 << " artist <none>" << std::endl |
60 std::cout << " album <none>" << std::endl; | 59 << " album <none>" << std::endl |
61 std::cout << " publisher <none>" << std::endl; | 60 << " publisher <none>" << std::endl |
62 std::cout << " genre <none>" << std::endl; | 61 << " genre <none>" << std::endl |
63 std::cout << " composer <none>" << std::endl << std::endl; | 62 << " composer <none>" << std::endl |
64 std::cout << std::endl << std::endl << kUp << std::flush; | 63 << std::endl |
| 64 << std::endl |
| 65 << std::endl |
| 66 << kUp << std::flush; |
65 } | 67 } |
66 | 68 |
67 CreateNewMediaTest(); | 69 CreateNewMediaTest(); |
68 Poll(); | 70 Poll(); |
69 } | 71 } |
70 | 72 |
71 bool ConfigureIncomingConnection( | 73 bool ConfigureIncomingConnection( |
72 mojo::ApplicationConnection* connection) override { | 74 mojo::ApplicationConnection* connection) override { |
73 return true; | 75 return true; |
74 } | 76 } |
(...skipping 27 matching lines...) Expand all Loading... |
102 media_test_ = MediaTest::Create(app_, *input_file_names_iter_); | 104 media_test_ = MediaTest::Create(app_, *input_file_names_iter_); |
103 | 105 |
104 metadata_shown_ = false; | 106 metadata_shown_ = false; |
105 media_test_->RegisterUpdateCallback( | 107 media_test_->RegisterUpdateCallback( |
106 [this]() { HandleMediaTestUpdateCallback(); }); | 108 [this]() { HandleMediaTestUpdateCallback(); }); |
107 | 109 |
108 media_test_->Play(); | 110 media_test_->Play(); |
109 } | 111 } |
110 | 112 |
111 void HandleMediaTestUpdateCallback() { | 113 void HandleMediaTestUpdateCallback() { |
112 if (media_test_->state() == MediaState::ENDED) { | 114 if (media_test_->state() == MediaState::ENDED && |
| 115 media_test_->previous_state() != MediaState::ENDED) { |
113 // MediaTest doesn't appreciate being deleted in this callback. | 116 // MediaTest doesn't appreciate being deleted in this callback. |
114 // Next time Poll runs, we move on to the next file. | 117 // Next time Poll runs, we move on to the next file. |
115 base::MessageLoop::current()->PostTask( | 118 base::MessageLoop::current()->PostTask( |
116 FROM_HERE, | 119 FROM_HERE, |
117 base::Bind(&MediaTestApp::PlayNext, base::Unretained(this))); | 120 base::Bind(&MediaTestApp::PlayNext, base::Unretained(this))); |
118 } | 121 } |
119 | 122 |
120 const MediaMetadataPtr& metadata = media_test_->metadata(); | 123 const MediaMetadataPtr& metadata = media_test_->metadata(); |
121 | 124 |
122 if (metadata) { | 125 if (metadata) { |
123 duration_ns_ = metadata->duration; | 126 duration_ns_ = metadata->duration; |
124 } | 127 } |
125 | 128 |
126 if (paint_) { | 129 if (paint_) { |
127 // Move the cursor up the terminal so we paint over the old metadata | 130 // Move the cursor up the terminal so we paint over the old metadata |
128 // (7 lines) a blank line and the state line (total of 9 lines). | 131 // (7 lines) a blank line and the state line (total of 9 lines). |
129 std::cout << kHome << kUp << kUp << kUp << kUp << kUp << kUp << kUp << kUp | 132 std::cout << kHome << kUp << kUp << kUp << kUp << kUp << kUp << kUp << kUp |
130 << kUp; | 133 << kUp; |
131 } | 134 } |
132 | 135 |
133 if (!paint_ && metadata_shown_) { | 136 if (!paint_ && metadata_shown_) { |
134 // Do nothing. | 137 // Do nothing. |
135 } else if (metadata) { | 138 } else if (metadata) { |
136 metadata_shown_ = true; | 139 metadata_shown_ = true; |
137 std::cout << " duration " << std::fixed << std::setprecision(1) | 140 std::cout << " duration " << std::fixed << std::setprecision(1) |
138 << double(metadata->duration) / ns_per_second << " seconds" | 141 << double(metadata->duration) / ns_per_second << " seconds" |
139 << clear_line() << std::endl; | 142 << clear_line() << std::endl |
140 std::cout << " title " | 143 << " title " |
141 << (metadata->title ? metadata->title : "<none>") | 144 << (metadata->title ? metadata->title : "<none>") |
142 << clear_line() << std::endl; | 145 << clear_line() << std::endl |
143 std::cout << " artist " | 146 << " artist " |
144 << (metadata->artist ? metadata->artist : "<none>") | 147 << (metadata->artist ? metadata->artist : "<none>") |
145 << clear_line() << std::endl; | 148 << clear_line() << std::endl |
146 std::cout << " album " | 149 << " album " |
147 << (metadata->album ? metadata->album : "<none>") | 150 << (metadata->album ? metadata->album : "<none>") |
148 << clear_line() << std::endl; | 151 << clear_line() << std::endl |
149 std::cout << " publisher " | 152 << " publisher " |
150 << (metadata->publisher ? metadata->publisher : "<none>") | 153 << (metadata->publisher ? metadata->publisher : "<none>") |
151 << clear_line() << std::endl; | 154 << clear_line() << std::endl |
152 std::cout << " genre " | 155 << " genre " |
153 << (metadata->genre ? metadata->genre : "<none>") | 156 << (metadata->genre ? metadata->genre : "<none>") |
154 << clear_line() << std::endl; | 157 << clear_line() << std::endl |
155 std::cout << " composer " | 158 << " composer " |
156 << (metadata->composer ? metadata->composer : "<none>") | 159 << (metadata->composer ? metadata->composer : "<none>") |
157 << clear_line() << std::endl | 160 << clear_line() << std::endl |
158 << std::endl; | 161 << std::endl; |
159 } else if (paint_) { | 162 } else if (paint_) { |
160 std::cout << " duration <none>" << kClearLine << std::endl; | 163 std::cout << " duration <none>" << kClearLine << std::endl |
161 std::cout << " title <none>" << kClearLine << std::endl; | 164 << " title <none>" << kClearLine << std::endl |
162 std::cout << " artist <none>" << kClearLine << std::endl; | 165 << " artist <none>" << kClearLine << std::endl |
163 std::cout << " album <none>" << kClearLine << std::endl; | 166 << " album <none>" << kClearLine << std::endl |
164 std::cout << " publisher <none>" << kClearLine << std::endl; | 167 << " publisher <none>" << kClearLine << std::endl |
165 std::cout << " genre <none>" << kClearLine << std::endl; | 168 << " genre <none>" << kClearLine << std::endl |
166 std::cout << " composer <none>" << kClearLine << std::endl; | 169 << " composer <none>" << kClearLine << std::endl |
167 std::cout << std::endl; | 170 << std::endl; |
168 } | 171 } |
169 std::cout << " " << state_string() << clear_line() << std::endl; | 172 std::cout << " " << state_string() << clear_line() << std::endl; |
170 } | 173 } |
171 | 174 |
172 // Returns a string describing the MediaTest object's state. | 175 // Returns a string describing the MediaTest object's state. |
173 const char* state_string() const { | 176 const char* state_string() const { |
174 switch (media_test_->state()) { | 177 switch (media_test_->state()) { |
175 case MediaState::FAULT: | 178 case MediaState::FAULT: |
176 return "FAULT"; | 179 return "FAULT"; |
177 case MediaState::UNPREPARED: | 180 case MediaState::UNPREPARED: |
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
319 | 322 |
320 } // namespace examples | 323 } // namespace examples |
321 } // namespace media | 324 } // namespace media |
322 } // namespace mojo | 325 } // namespace mojo |
323 | 326 |
324 MojoResult MojoMain(MojoHandle application_request) { | 327 MojoResult MojoMain(MojoHandle application_request) { |
325 mojo::ApplicationRunnerChromium runner( | 328 mojo::ApplicationRunnerChromium runner( |
326 new mojo::media::examples::MediaTestApp); | 329 new mojo::media::examples::MediaTestApp); |
327 return runner.Run(application_request); | 330 return runner.Run(application_request); |
328 } | 331 } |
OLD | NEW |