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

Unified Diff: examples/media_test/media_test.cc

Issue 1809703003: Motown: Add examples/media_test, a command line media player app. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Created 4 years, 9 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 side-by-side diff with in-line comments
Download patch
Index: examples/media_test/media_test.cc
diff --git a/examples/media_test/media_test.cc b/examples/media_test/media_test.cc
new file mode 100644
index 0000000000000000000000000000000000000000..e93063735c47c9a88eec50b1a447f65e8de76c35
--- /dev/null
+++ b/examples/media_test/media_test.cc
@@ -0,0 +1,101 @@
+// Copyright 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "examples/media_test/media_test.h"
+#include "mojo/services/media/common/cpp/linear_transform.h"
+#include "mojo/services/media/common/cpp/local_time.h"
+#include "mojo/services/media/control/interfaces/media_factory.mojom.h"
+
+namespace examples {
+
+// static
+std::unique_ptr<MediaTest> MediaTest::Create(
+ mojo::ApplicationImpl* app,
+ const std::string& input_file_name) {
+ return std::unique_ptr<MediaTest>(new MediaTest(app, input_file_name));
+}
+
+MediaTest::MediaTest(
+ mojo::ApplicationImpl* app,
+ const std::string& input_file_name) :
+ state_(mojo::media::MediaState::UNPREPARED) {
+ mojo::media::MediaFactoryPtr factory;
+ app->ConnectToService("mojo:media_factory", &factory);
+
+ factory->CreatePlayer(input_file_name, GetProxy(&media_player_));
+
+ HandleStatusUpdates();
+}
+
+MediaTest::~MediaTest() {}
+
+void MediaTest::RegisterUpdateCallback(const UpdateCallback& callback) {
+ update_callback_ = callback;
+}
+
+void MediaTest::Play() {
+ media_player_->Play();
+}
+
+void MediaTest::Pause() {
+ media_player_->Pause();
+}
+
+void MediaTest::Seek(int64_t position_ns) {
+ media_player_->Seek(position_ns);
+}
+
+mojo::media::MediaState MediaTest::state() const {
+ return state_;
+}
+
+int64_t MediaTest::position_ns() const {
+ if (!transform_) {
+ return 0;
+ }
+
+ // Create a linear transform that translates local time to presentation time.
+ // Note that 'reference' here refers to the presentation time, and 'target'
+ // refers to the local time.
+ mojo::media::LinearTransform transform(
johngro 2016/03/21 22:10:46 transform_ does not appear to be getting used for
dalesat 2016/03/21 23:58:35 Done.
+ transform_->quad->target_offset,
+ transform_->quad->reference_delta,
+ transform_->quad->target_delta,
+ transform_->quad->reference_offset);
+
+ // Apply the transform to the current time.
+ int64_t position;
+ transform.DoForwardTransform(
+ mojo::media::LocalClock::now().time_since_epoch().count(),
+ &position);
+
+ return position;
johngro 2016/03/21 22:10:46 if you have an idea of what the asset's duration i
dalesat 2016/03/21 23:58:35 Done.
+}
+
+const mojo::media::MediaMetadataPtr& MediaTest::metadata() const {
+ return metadata_;
+}
+
+void MediaTest::HandleStatusUpdates(
+ uint64_t version,
+ mojo::media::MediaPlayerStatusPtr status) {
+ if (status) {
+ // Process status received from the player.
+ state_ = status->state;
+ transform_ = status->timeline_transform.Pass();
+ metadata_ = status->metadata.Pass();
+ if (update_callback_ != nullptr) {
+ update_callback_();
+ }
+ }
+
+ // Request a status update.
+ media_player_->GetStatus(
+ version,
+ [this](uint64_t version, mojo::media::MediaPlayerStatusPtr status) {
+ HandleStatusUpdates(version, status.Pass());
+ });
+}
+
+} // namespace examples

Powered by Google App Engine
This is Rietveld 408576698