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

Side by Side 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 unified diff | Download patch
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "examples/media_test/media_test.h"
6 #include "mojo/services/media/common/cpp/linear_transform.h"
7 #include "mojo/services/media/common/cpp/local_time.h"
8 #include "mojo/services/media/control/interfaces/media_factory.mojom.h"
9
10 namespace examples {
11
12 // static
13 std::unique_ptr<MediaTest> MediaTest::Create(
14 mojo::ApplicationImpl* app,
15 const std::string& input_file_name) {
16 return std::unique_ptr<MediaTest>(new MediaTest(app, input_file_name));
17 }
18
19 MediaTest::MediaTest(
20 mojo::ApplicationImpl* app,
21 const std::string& input_file_name) :
22 state_(mojo::media::MediaState::UNPREPARED) {
23 mojo::media::MediaFactoryPtr factory;
24 app->ConnectToService("mojo:media_factory", &factory);
25
26 factory->CreatePlayer(input_file_name, GetProxy(&media_player_));
27
28 HandleStatusUpdates();
29 }
30
31 MediaTest::~MediaTest() {}
32
33 void MediaTest::RegisterUpdateCallback(const UpdateCallback& callback) {
34 update_callback_ = callback;
35 }
36
37 void MediaTest::Play() {
38 media_player_->Play();
39 }
40
41 void MediaTest::Pause() {
42 media_player_->Pause();
43 }
44
45 void MediaTest::Seek(int64_t position_ns) {
46 media_player_->Seek(position_ns);
47 }
48
49 mojo::media::MediaState MediaTest::state() const {
50 return state_;
51 }
52
53 int64_t MediaTest::position_ns() const {
54 if (!transform_) {
55 return 0;
56 }
57
58 // Create a linear transform that translates local time to presentation time.
59 // Note that 'reference' here refers to the presentation time, and 'target'
60 // refers to the local time.
61 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.
62 transform_->quad->target_offset,
63 transform_->quad->reference_delta,
64 transform_->quad->target_delta,
65 transform_->quad->reference_offset);
66
67 // Apply the transform to the current time.
68 int64_t position;
69 transform.DoForwardTransform(
70 mojo::media::LocalClock::now().time_since_epoch().count(),
71 &position);
72
73 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.
74 }
75
76 const mojo::media::MediaMetadataPtr& MediaTest::metadata() const {
77 return metadata_;
78 }
79
80 void MediaTest::HandleStatusUpdates(
81 uint64_t version,
82 mojo::media::MediaPlayerStatusPtr status) {
83 if (status) {
84 // Process status received from the player.
85 state_ = status->state;
86 transform_ = status->timeline_transform.Pass();
87 metadata_ = status->metadata.Pass();
88 if (update_callback_ != nullptr) {
89 update_callback_();
90 }
91 }
92
93 // Request a status update.
94 media_player_->GetStatus(
95 version,
96 [this](uint64_t version, mojo::media::MediaPlayerStatusPtr status) {
97 HandleStatusUpdates(version, status.Pass());
98 });
99 }
100
101 } // namespace examples
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698