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 "examples/media_test/media_test.h" | 5 #include "examples/media_test/media_test.h" |
6 #include "mojo/services/media/common/cpp/linear_transform.h" | 6 #include "mojo/services/media/common/cpp/linear_transform.h" |
7 #include "mojo/services/media/common/cpp/local_time.h" | 7 #include "mojo/services/media/common/cpp/local_time.h" |
8 #include "mojo/services/media/control/interfaces/media_factory.mojom.h" | 8 #include "mojo/services/media/control/interfaces/media_factory.mojom.h" |
9 | 9 |
10 namespace mojo { | 10 namespace mojo { |
(...skipping 13 matching lines...) Expand all Loading... |
24 MediaFactoryPtr factory; | 24 MediaFactoryPtr factory; |
25 app->ConnectToService("mojo:media_factory", &factory); | 25 app->ConnectToService("mojo:media_factory", &factory); |
26 | 26 |
27 factory->CreatePlayer(input_file_name, GetProxy(&media_player_)); | 27 factory->CreatePlayer(input_file_name, GetProxy(&media_player_)); |
28 | 28 |
29 HandleStatusUpdates(); | 29 HandleStatusUpdates(); |
30 } | 30 } |
31 | 31 |
32 MediaTest::~MediaTest() {} | 32 MediaTest::~MediaTest() {} |
33 | 33 |
34 void MediaTest::RegisterUpdateCallback(const UpdateCallback& callback) { | |
35 update_callback_ = callback; | |
36 } | |
37 | |
38 void MediaTest::Play() { | |
39 media_player_->Play(); | |
40 } | |
41 | |
42 void MediaTest::Pause() { | |
43 media_player_->Pause(); | |
44 } | |
45 | |
46 void MediaTest::Seek(int64_t position_ns) { | |
47 media_player_->Seek(position_ns); | |
48 } | |
49 | |
50 MediaState MediaTest::state() const { | |
51 return state_; | |
52 } | |
53 | |
54 int64_t MediaTest::position_ns() const { | 34 int64_t MediaTest::position_ns() const { |
55 // Apply the transform to the current time. | 35 // Apply the transform to the current time. |
56 int64_t position; | 36 int64_t position; |
57 transform_.DoForwardTransform(LocalClock::now().time_since_epoch().count(), | 37 transform_.DoForwardTransform(LocalClock::now().time_since_epoch().count(), |
58 &position); | 38 &position); |
59 | 39 |
60 MOJO_DCHECK(position >= 0); | 40 MOJO_DCHECK(position >= 0); |
61 | 41 |
62 if (metadata_ && static_cast<uint64_t>(position) > metadata_->duration) { | 42 if (metadata_ && static_cast<uint64_t>(position) > metadata_->duration) { |
63 position = metadata_->duration; | 43 position = metadata_->duration; |
64 } | 44 } |
65 | 45 |
66 return position; | 46 return position; |
67 } | 47 } |
68 | 48 |
69 const MediaMetadataPtr& MediaTest::metadata() const { | 49 const MediaMetadataPtr& MediaTest::metadata() const { |
70 return metadata_; | 50 return metadata_; |
71 } | 51 } |
72 | 52 |
73 void MediaTest::HandleStatusUpdates(uint64_t version, | 53 void MediaTest::HandleStatusUpdates(uint64_t version, |
74 MediaPlayerStatusPtr status) { | 54 MediaPlayerStatusPtr status) { |
75 if (status) { | 55 if (status) { |
76 // Process status received from the player. | 56 // Process status received from the player. |
| 57 previous_state_ = state_; |
77 state_ = status->state; | 58 state_ = status->state; |
78 | 59 |
79 // Create a linear transform that translates local time to presentation | 60 // Create a linear transform that translates local time to presentation |
80 // time. Note that 'reference' here refers to the presentation time, and | 61 // time. Note that 'reference' here refers to the presentation time, and |
81 // 'target' refers to the local time. | 62 // 'target' refers to the local time. |
82 if (status->timeline_transform) { | 63 if (status->timeline_transform) { |
83 transform_ = | 64 transform_ = |
84 LinearTransform(status->timeline_transform->quad->target_offset, | 65 LinearTransform(status->timeline_transform->quad->target_offset, |
85 status->timeline_transform->quad->reference_delta, | 66 status->timeline_transform->quad->reference_delta, |
86 status->timeline_transform->quad->target_delta, | 67 status->timeline_transform->quad->target_delta, |
(...skipping 10 matching lines...) Expand all Loading... |
97 // Request a status update. | 78 // Request a status update. |
98 media_player_->GetStatus( | 79 media_player_->GetStatus( |
99 version, [this](uint64_t version, MediaPlayerStatusPtr status) { | 80 version, [this](uint64_t version, MediaPlayerStatusPtr status) { |
100 HandleStatusUpdates(version, status.Pass()); | 81 HandleStatusUpdates(version, status.Pass()); |
101 }); | 82 }); |
102 } | 83 } |
103 | 84 |
104 } // namespace examples | 85 } // namespace examples |
105 } // namespace media | 86 } // namespace media |
106 } // namespace mojo | 87 } // namespace mojo |
OLD | NEW |