| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 MOJO_SERVICES_MEDIA_FACTORY_MEDIA_PLAYER_IMPL_H_ | 5 #ifndef MOJO_SERVICES_MEDIA_FACTORY_MEDIA_PLAYER_IMPL_H_ |
| 6 #define MOJO_SERVICES_MEDIA_FACTORY_MEDIA_PLAYER_IMPL_H_ | 6 #define MOJO_SERVICES_MEDIA_FACTORY_MEDIA_PLAYER_IMPL_H_ |
| 7 | 7 |
| 8 #include <limits> | 8 #include <limits> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 44 void Pause() override; | 44 void Pause() override; |
| 45 | 45 |
| 46 void Seek(int64_t position) override; | 46 void Seek(int64_t position) override; |
| 47 | 47 |
| 48 private: | 48 private: |
| 49 static constexpr int64_t kMinimumLeadTime = Timeline::ns_from_ms(30); | 49 static constexpr int64_t kMinimumLeadTime = Timeline::ns_from_ms(30); |
| 50 | 50 |
| 51 // Internal state. | 51 // Internal state. |
| 52 enum class State { | 52 enum class State { |
| 53 kWaiting, // Waiting for some work to complete. | 53 kWaiting, // Waiting for some work to complete. |
| 54 kPaused, | 54 kFlushed, // Paused with no data in the pipeline. |
| 55 kPlaying, | 55 kPrimed, // Paused with data in the pipeline. |
| 56 kPlaying, // Time is progressing. |
| 56 }; | 57 }; |
| 57 | 58 |
| 58 struct Stream { | 59 struct Stream { |
| 59 Stream(); | 60 Stream(); |
| 60 ~Stream(); | 61 ~Stream(); |
| 61 // TODO(dalesat): Have the sink enlist the decoder. | 62 // TODO(dalesat): Have the sink enlist the decoder. |
| 62 MediaTypeConverterPtr decoder_; | 63 MediaTypeConverterPtr decoder_; |
| 63 MediaSinkPtr sink_; | 64 MediaSinkPtr sink_; |
| 64 // The following fields are just temporaries used to solve lambda capture | 65 // The following fields are just temporaries used to solve lambda capture |
| 65 // problems. | 66 // problems. |
| 66 MediaProducerPtr encoded_producer_; | 67 MediaProducerPtr encoded_producer_; |
| 67 MediaProducerPtr decoded_producer_; | 68 MediaProducerPtr decoded_producer_; |
| 68 InterfaceHandle<MediaRenderer> renderer_; | 69 InterfaceHandle<MediaRenderer> renderer_; |
| 69 }; | 70 }; |
| 70 | 71 |
| 71 MediaPlayerImpl(InterfaceHandle<SeekingReader> reader, | 72 MediaPlayerImpl(InterfaceHandle<SeekingReader> reader, |
| 72 InterfaceHandle<MediaRenderer> audio_renderer, | 73 InterfaceHandle<MediaRenderer> audio_renderer, |
| 73 InterfaceHandle<MediaRenderer> video_renderer, | 74 InterfaceHandle<MediaRenderer> video_renderer, |
| 74 InterfaceRequest<MediaPlayer> request, | 75 InterfaceRequest<MediaPlayer> request, |
| 75 MediaFactoryService* owner); | 76 MediaFactoryService* owner); |
| 76 | 77 |
| 77 // Takes action based on current state. | 78 // Takes action based on current state. |
| 78 void Update(); | 79 void Update(); |
| 79 | 80 |
| 80 // Handles seeking in paused state. | |
| 81 void WhenPausedAndSeeking(); | |
| 82 | |
| 83 // Handles seeking in paused state with flushed pipeline. | |
| 84 void WhenFlushedAndSeeking(); | |
| 85 | |
| 86 // Sets the timeline transform. transform_subject_time_ is used for the | 81 // Sets the timeline transform. transform_subject_time_ is used for the |
| 87 // subject_time, and the effective_reference_time is now plus | 82 // subject_time, and the effective_reference_time is now plus |
| 88 // kMinimumLeadTime. | 83 // kMinimumLeadTime. |
| 89 void SetTimelineTransform(uint32_t reference_delta, uint32_t subject_delta); | 84 void SetTimelineTransform(uint32_t reference_delta, uint32_t subject_delta); |
| 90 | 85 |
| 91 // Prepares a stream. | 86 // Prepares a stream. |
| 92 void PrepareStream(Stream* stream, | 87 void PrepareStream(Stream* stream, |
| 93 size_t index, | 88 size_t index, |
| 94 const MediaTypePtr& input_media_type, | 89 const MediaTypePtr& input_media_type, |
| 95 const std::function<void()>& callback); | 90 const std::function<void()>& callback); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 110 void HandleTimelineControlSiteStatusUpdates( | 105 void HandleTimelineControlSiteStatusUpdates( |
| 111 uint64_t version = MediaTimelineControlSite::kInitialStatus, | 106 uint64_t version = MediaTimelineControlSite::kInitialStatus, |
| 112 MediaTimelineControlSiteStatusPtr status = nullptr); | 107 MediaTimelineControlSiteStatusPtr status = nullptr); |
| 113 | 108 |
| 114 MediaFactoryPtr factory_; | 109 MediaFactoryPtr factory_; |
| 115 MediaDemuxPtr demux_; | 110 MediaDemuxPtr demux_; |
| 116 MediaTimelineControllerPtr timeline_controller_; | 111 MediaTimelineControllerPtr timeline_controller_; |
| 117 MediaTimelineControlSitePtr timeline_control_site_; | 112 MediaTimelineControlSitePtr timeline_control_site_; |
| 118 TimelineConsumerPtr timeline_consumer_; | 113 TimelineConsumerPtr timeline_consumer_; |
| 119 std::vector<std::unique_ptr<Stream>> streams_; | 114 std::vector<std::unique_ptr<Stream>> streams_; |
| 115 |
| 116 // The state we're currently in. |
| 120 State state_ = State::kWaiting; | 117 State state_ = State::kWaiting; |
| 121 State target_state_ = State::kPaused; | 118 |
| 122 bool flushed_ = true; | 119 // The state we trying to transition to, either because the client has called |
| 120 // |Play| or |Pause| or because we've hit end-of-stream. |
| 121 State target_state_ = State::kFlushed; |
| 122 |
| 123 // Whether we're currently at end-of-stream. |
| 123 bool end_of_stream_ = false; | 124 bool end_of_stream_ = false; |
| 125 |
| 126 // The position we want to seek to (because the client called Seek) or |
| 127 // kUnspecifiedTime, which indicates there's no desire to seek. |
| 124 int64_t target_position_ = kUnspecifiedTime; | 128 int64_t target_position_ = kUnspecifiedTime; |
| 129 |
| 130 // The subject time to be used for SetTimelineTransform. The value is |
| 131 // kUnspecifiedTime if there's no need to seek or the position we want to |
| 132 // seek to if there is. |
| 125 int64_t transform_subject_time_ = kUnspecifiedTime; | 133 int64_t transform_subject_time_ = kUnspecifiedTime; |
| 134 |
| 135 // A function that translates local time into presentation time in ns. |
| 126 TimelineFunction timeline_function_; | 136 TimelineFunction timeline_function_; |
| 137 |
| 127 CallbackJoiner set_transform_joiner_; | 138 CallbackJoiner set_transform_joiner_; |
| 128 MediaMetadataPtr metadata_; | 139 MediaMetadataPtr metadata_; |
| 129 MojoPublisher<GetStatusCallback> status_publisher_; | 140 MojoPublisher<GetStatusCallback> status_publisher_; |
| 141 |
| 130 // The following fields are just temporaries used to solve lambda capture | 142 // The following fields are just temporaries used to solve lambda capture |
| 131 // problems. | 143 // problems. |
| 132 InterfaceHandle<MediaRenderer> audio_renderer_; | 144 InterfaceHandle<MediaRenderer> audio_renderer_; |
| 133 InterfaceHandle<MediaRenderer> video_renderer_; | 145 InterfaceHandle<MediaRenderer> video_renderer_; |
| 134 }; | 146 }; |
| 135 | 147 |
| 136 } // namespace media | 148 } // namespace media |
| 137 } // namespace mojo | 149 } // namespace mojo |
| 138 | 150 |
| 139 #endif // MOJO_SERVICES_MEDIA_FACTORY_MEDIA_PLAYER_IMPL_H_ | 151 #endif // MOJO_SERVICES_MEDIA_FACTORY_MEDIA_PLAYER_IMPL_H_ |
| OLD | NEW |