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 { |
11 namespace media { | 11 namespace media { |
12 namespace examples { | 12 namespace examples { |
13 | 13 |
14 // static | 14 // static |
15 std::unique_ptr<MediaTest> MediaTest::Create( | 15 std::unique_ptr<MediaTest> MediaTest::Create( |
16 mojo::ApplicationImpl* app, | 16 mojo::ApplicationImpl* app, |
17 const std::string& input_file_name) { | 17 const std::string& input_file_name) { |
18 return std::unique_ptr<MediaTest>(new MediaTest(app, input_file_name)); | 18 return std::unique_ptr<MediaTest>(new MediaTest(app, input_file_name)); |
19 } | 19 } |
20 | 20 |
21 MediaTest::MediaTest( | 21 MediaTest::MediaTest(mojo::ApplicationImpl* app, |
22 mojo::ApplicationImpl* app, | 22 const std::string& input_file_name) |
23 const std::string& input_file_name) : | 23 : state_(MediaState::UNPREPARED) { |
24 state_(MediaState::UNPREPARED) { | |
25 MediaFactoryPtr factory; | 24 MediaFactoryPtr factory; |
26 app->ConnectToService("mojo:media_factory", &factory); | 25 app->ConnectToService("mojo:media_factory", &factory); |
27 | 26 |
28 factory->CreatePlayer(input_file_name, GetProxy(&media_player_)); | 27 factory->CreatePlayer(input_file_name, GetProxy(&media_player_)); |
29 | 28 |
30 HandleStatusUpdates(); | 29 HandleStatusUpdates(); |
31 } | 30 } |
32 | 31 |
33 MediaTest::~MediaTest() {} | 32 MediaTest::~MediaTest() {} |
34 | 33 |
(...skipping 13 matching lines...) Expand all Loading... |
48 media_player_->Seek(position_ns); | 47 media_player_->Seek(position_ns); |
49 } | 48 } |
50 | 49 |
51 MediaState MediaTest::state() const { | 50 MediaState MediaTest::state() const { |
52 return state_; | 51 return state_; |
53 } | 52 } |
54 | 53 |
55 int64_t MediaTest::position_ns() const { | 54 int64_t MediaTest::position_ns() const { |
56 // Apply the transform to the current time. | 55 // Apply the transform to the current time. |
57 int64_t position; | 56 int64_t position; |
58 transform_.DoForwardTransform( | 57 transform_.DoForwardTransform(LocalClock::now().time_since_epoch().count(), |
59 LocalClock::now().time_since_epoch().count(), | 58 &position); |
60 &position); | |
61 | 59 |
62 MOJO_DCHECK(position >= 0); | 60 MOJO_DCHECK(position >= 0); |
63 | 61 |
64 if (metadata_ && | 62 if (metadata_ && static_cast<uint64_t>(position) > metadata_->duration) { |
65 static_cast<uint64_t>(position) > metadata_->duration) { | |
66 position = metadata_->duration; | 63 position = metadata_->duration; |
67 } | 64 } |
68 | 65 |
69 return position; | 66 return position; |
70 } | 67 } |
71 | 68 |
72 const MediaMetadataPtr& MediaTest::metadata() const { | 69 const MediaMetadataPtr& MediaTest::metadata() const { |
73 return metadata_; | 70 return metadata_; |
74 } | 71 } |
75 | 72 |
76 void MediaTest::HandleStatusUpdates( | 73 void MediaTest::HandleStatusUpdates(uint64_t version, |
77 uint64_t version, | 74 MediaPlayerStatusPtr status) { |
78 MediaPlayerStatusPtr status) { | |
79 if (status) { | 75 if (status) { |
80 // Process status received from the player. | 76 // Process status received from the player. |
81 state_ = status->state; | 77 state_ = status->state; |
82 | 78 |
83 // Create a linear transform that translates local time to presentation | 79 // Create a linear transform that translates local time to presentation |
84 // time. Note that 'reference' here refers to the presentation time, and | 80 // time. Note that 'reference' here refers to the presentation time, and |
85 // 'target' refers to the local time. | 81 // 'target' refers to the local time. |
86 if (status->timeline_transform) { | 82 if (status->timeline_transform) { |
87 transform_ = LinearTransform( | 83 transform_ = |
88 status->timeline_transform->quad->target_offset, | 84 LinearTransform(status->timeline_transform->quad->target_offset, |
89 status->timeline_transform->quad->reference_delta, | 85 status->timeline_transform->quad->reference_delta, |
90 status->timeline_transform->quad->target_delta, | 86 status->timeline_transform->quad->target_delta, |
91 status->timeline_transform->quad->reference_offset); | 87 status->timeline_transform->quad->reference_offset); |
92 } | 88 } |
93 | 89 |
94 metadata_ = status->metadata.Pass(); | 90 metadata_ = status->metadata.Pass(); |
95 | 91 |
96 if (update_callback_ != nullptr) { | 92 if (update_callback_ != nullptr) { |
97 update_callback_(); | 93 update_callback_(); |
98 } | 94 } |
99 } | 95 } |
100 | 96 |
101 // Request a status update. | 97 // Request a status update. |
102 media_player_->GetStatus( | 98 media_player_->GetStatus( |
103 version, | 99 version, [this](uint64_t version, MediaPlayerStatusPtr status) { |
104 [this](uint64_t version, MediaPlayerStatusPtr status) { | |
105 HandleStatusUpdates(version, status.Pass()); | 100 HandleStatusUpdates(version, status.Pass()); |
106 }); | 101 }); |
107 } | 102 } |
108 | 103 |
109 } // namespace examples | 104 } // namespace examples |
110 } // namespace media | 105 } // namespace media |
111 } // namespace mojo | 106 } // namespace mojo |
OLD | NEW |