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 #ifndef EXAMPLES_MEDIA_TEST_MEDIA_TEST_H_ | 5 #ifndef EXAMPLES_MEDIA_TEST_MEDIA_TEST_H_ |
6 #define EXAMPLES_MEDIA_TEST_MEDIA_TEST_H_ | 6 #define EXAMPLES_MEDIA_TEST_MEDIA_TEST_H_ |
7 | 7 |
8 #include "base/macros.h" | 8 #include "base/macros.h" |
9 #include "mojo/public/cpp/application/application_impl.h" | 9 #include "mojo/public/cpp/application/application_impl.h" |
10 #include "mojo/services/media/common/cpp/linear_transform.h" | 10 #include "mojo/services/media/common/cpp/linear_transform.h" |
11 #include "mojo/services/media/common/interfaces/rate_control.mojom.h" | 11 #include "mojo/services/media/common/interfaces/rate_control.mojom.h" |
12 #include "mojo/services/media/control/interfaces/media_factory.mojom.h" | 12 #include "mojo/services/media/control/interfaces/media_factory.mojom.h" |
13 #include "mojo/services/media/control/interfaces/media_player.mojom.h" | 13 #include "mojo/services/media/control/interfaces/media_player.mojom.h" |
14 | 14 |
15 namespace mojo { | 15 namespace mojo { |
16 namespace media { | 16 namespace media { |
17 namespace examples { | 17 namespace examples { |
18 | 18 |
19 // Model for media test application. | 19 // Model for media test application. |
20 class MediaTest { | 20 class MediaTest { |
21 public: | 21 public: |
22 using UpdateCallback = std::function<void()>; | 22 using UpdateCallback = std::function<void()>; |
23 | 23 |
24 static std::unique_ptr<MediaTest> Create(mojo::ApplicationImpl* app, | 24 static std::unique_ptr<MediaTest> Create(mojo::ApplicationImpl* app, |
25 const std::string& input_file_name); | 25 const std::string& input_file_name); |
26 | 26 |
27 ~MediaTest(); | 27 ~MediaTest(); |
28 | 28 |
29 // Registers a callback signalling that the app should update its view. | 29 // Registers a callback signalling that the app should update its view. |
30 void RegisterUpdateCallback(const UpdateCallback& callback); | 30 void RegisterUpdateCallback(const UpdateCallback& callback) { |
| 31 update_callback_ = callback; |
| 32 } |
31 | 33 |
32 // Starts playback. | 34 // Starts playback. |
33 void Play(); | 35 void Play() { media_player_->Play(); } |
34 | 36 |
35 // Pauses playback. | 37 // Pauses playback. |
36 void Pause(); | 38 void Pause() { media_player_->Pause(); } |
37 | 39 |
38 // Seeks to the position indicated in nanoseconds from the start of the media. | 40 // Seeks to the position indicated in nanoseconds from the start of the media. |
39 void Seek(int64_t position_ns); | 41 void Seek(int64_t position_ns) { media_player_->Seek(position_ns); } |
| 42 |
| 43 // Returns the previous state of the player. |
| 44 MediaState previous_state() const { return previous_state_; } |
40 | 45 |
41 // Returns the current state of the player. | 46 // Returns the current state of the player. |
42 MediaState state() const; | 47 MediaState state() const { return state_; } |
43 | 48 |
44 // Returns the current presentation time in nanoseconds. | 49 // Returns the current presentation time in nanoseconds. |
45 int64_t position_ns() const; | 50 int64_t position_ns() const; |
46 | 51 |
47 // Returns the current media metadata, if there is any. | 52 // Returns the current media metadata, if there is any. |
48 const MediaMetadataPtr& metadata() const; | 53 const MediaMetadataPtr& metadata() const; |
49 | 54 |
50 private: | 55 private: |
51 MediaTest(mojo::ApplicationImpl* app, const std::string& input_file_name); | 56 MediaTest(mojo::ApplicationImpl* app, const std::string& input_file_name); |
52 | 57 |
53 // Handles a status update from the player. When called with the default | 58 // Handles a status update from the player. When called with the default |
54 // argument values, initiates status updates. | 59 // argument values, initiates status updates. |
55 void HandleStatusUpdates(uint64_t version = MediaPlayer::kInitialStatus, | 60 void HandleStatusUpdates(uint64_t version = MediaPlayer::kInitialStatus, |
56 MediaPlayerStatusPtr status = nullptr); | 61 MediaPlayerStatusPtr status = nullptr); |
57 | 62 |
58 MediaPlayerPtr media_player_; | 63 MediaPlayerPtr media_player_; |
59 MediaState state_; | 64 MediaState previous_state_ = MediaState::UNPREPARED; |
| 65 MediaState state_ = MediaState::UNPREPARED; |
60 LinearTransform transform_ = LinearTransform(0, 0, 1, 0); | 66 LinearTransform transform_ = LinearTransform(0, 0, 1, 0); |
61 MediaMetadataPtr metadata_; | 67 MediaMetadataPtr metadata_; |
62 UpdateCallback update_callback_; | 68 UpdateCallback update_callback_; |
63 | 69 |
64 DISALLOW_COPY_AND_ASSIGN(MediaTest); | 70 DISALLOW_COPY_AND_ASSIGN(MediaTest); |
65 }; | 71 }; |
66 | 72 |
67 } // namespace examples | 73 } // namespace examples |
68 } // namespace media | 74 } // namespace media |
69 } // namespace mojo | 75 } // namespace mojo |
70 | 76 |
71 #endif // EXAMPLES_MEDIA_TEST_MEDIA_TEST_H_ | 77 #endif // EXAMPLES_MEDIA_TEST_MEDIA_TEST_H_ |
OLD | NEW |