| 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/timeline_function.h" | 10 #include "mojo/services/media/common/cpp/timeline_function.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 enum class State { kPaused, kPlaying, kEnded }; |
| 23 |
| 22 using UpdateCallback = std::function<void()>; | 24 using UpdateCallback = std::function<void()>; |
| 23 | 25 |
| 24 static std::unique_ptr<MediaTest> Create(mojo::ApplicationImpl* app, | 26 static std::unique_ptr<MediaTest> Create(mojo::ApplicationImpl* app, |
| 25 const std::string& input_file_name); | 27 const std::string& input_file_name); |
| 26 | 28 |
| 27 ~MediaTest(); | 29 ~MediaTest(); |
| 28 | 30 |
| 29 // Registers a callback signalling that the app should update its view. | 31 // Registers a callback signalling that the app should update its view. |
| 30 void RegisterUpdateCallback(const UpdateCallback& callback) { | 32 void RegisterUpdateCallback(const UpdateCallback& callback) { |
| 31 update_callback_ = callback; | 33 update_callback_ = callback; |
| 32 } | 34 } |
| 33 | 35 |
| 34 // Starts playback. | 36 // Starts playback. |
| 35 void Play() { media_player_->Play(); } | 37 void Play() { media_player_->Play(); } |
| 36 | 38 |
| 37 // Pauses playback. | 39 // Pauses playback. |
| 38 void Pause() { media_player_->Pause(); } | 40 void Pause() { media_player_->Pause(); } |
| 39 | 41 |
| 40 // Seeks to the position indicated in nanoseconds from the start of the media. | 42 // Seeks to the position indicated in nanoseconds from the start of the media. |
| 41 void Seek(int64_t position_ns) { media_player_->Seek(position_ns); } | 43 void Seek(int64_t position_ns) { media_player_->Seek(position_ns); } |
| 42 | 44 |
| 43 // Returns the previous state of the player. | 45 // Returns the previous state of the player. |
| 44 MediaState previous_state() const { return previous_state_; } | 46 State previous_state() const { return previous_state_; } |
| 45 | 47 |
| 46 // Returns the current state of the player. | 48 // Returns the current state of the player. |
| 47 MediaState state() const { return state_; } | 49 State state() const { return state_; } |
| 48 | 50 |
| 49 // Returns the current presentation time in nanoseconds. | 51 // Returns the current presentation time in nanoseconds. |
| 50 int64_t position_ns() const; | 52 int64_t position_ns() const; |
| 51 | 53 |
| 52 // Returns the current media metadata, if there is any. | 54 // Returns the current media metadata, if there is any. |
| 53 const MediaMetadataPtr& metadata() const; | 55 const MediaMetadataPtr& metadata() const; |
| 54 | 56 |
| 55 private: | 57 private: |
| 56 MediaTest(mojo::ApplicationImpl* app, const std::string& input_file_name); | 58 MediaTest(mojo::ApplicationImpl* app, const std::string& input_file_name); |
| 57 | 59 |
| 58 // Handles a status update from the player. When called with the default | 60 // Handles a status update from the player. When called with the default |
| 59 // argument values, initiates status updates. | 61 // argument values, initiates status updates. |
| 60 void HandleStatusUpdates(uint64_t version = MediaPlayer::kInitialStatus, | 62 void HandleStatusUpdates(uint64_t version = MediaPlayer::kInitialStatus, |
| 61 MediaPlayerStatusPtr status = nullptr); | 63 MediaPlayerStatusPtr status = nullptr); |
| 62 | 64 |
| 63 MediaPlayerPtr media_player_; | 65 MediaPlayerPtr media_player_; |
| 64 MediaState previous_state_ = MediaState::UNPREPARED; | 66 State previous_state_ = State::kPaused; |
| 65 MediaState state_ = MediaState::UNPREPARED; | 67 State state_ = State::kPaused; |
| 66 TimelineFunction timeline_function_; | 68 TimelineFunction timeline_function_; |
| 67 MediaMetadataPtr metadata_; | 69 MediaMetadataPtr metadata_; |
| 68 UpdateCallback update_callback_; | 70 UpdateCallback update_callback_; |
| 69 | 71 |
| 70 DISALLOW_COPY_AND_ASSIGN(MediaTest); | 72 DISALLOW_COPY_AND_ASSIGN(MediaTest); |
| 71 }; | 73 }; |
| 72 | 74 |
| 73 } // namespace examples | 75 } // namespace examples |
| 74 } // namespace media | 76 } // namespace media |
| 75 } // namespace mojo | 77 } // namespace mojo |
| 76 | 78 |
| 77 #endif // EXAMPLES_MEDIA_TEST_MEDIA_TEST_H_ | 79 #endif // EXAMPLES_MEDIA_TEST_MEDIA_TEST_H_ |
| OLD | NEW |