| 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 |
| 11 #include "mojo/public/cpp/application/application_impl.h" | 11 #include "mojo/public/cpp/application/application_impl.h" |
| 12 #include "mojo/public/cpp/bindings/binding.h" | 12 #include "mojo/public/cpp/bindings/binding.h" |
| 13 #include "mojo/services/media/common/cpp/timeline.h" | 13 #include "mojo/services/media/common/cpp/timeline.h" |
| 14 #include "mojo/services/media/common/cpp/timeline_function.h" | 14 #include "mojo/services/media/common/cpp/timeline_function.h" |
| 15 #include "mojo/services/media/common/interfaces/media_transport.mojom.h" | 15 #include "mojo/services/media/common/interfaces/media_transport.mojom.h" |
| 16 #include "mojo/services/media/control/interfaces/media_factory.mojom.h" | 16 #include "mojo/services/media/control/interfaces/media_factory.mojom.h" |
| 17 #include "mojo/services/media/core/interfaces/seeking_reader.mojom.h" | 17 #include "mojo/services/media/core/interfaces/seeking_reader.mojom.h" |
| 18 #include "mojo/services/media/core/interfaces/timeline_controller.mojom.h" |
| 18 #include "services/media/common/mojo_publisher.h" | 19 #include "services/media/common/mojo_publisher.h" |
| 19 #include "services/media/factory_service/factory_service.h" | 20 #include "services/media/factory_service/factory_service.h" |
| 20 #include "services/media/framework/util/callback_joiner.h" | 21 #include "services/media/framework/util/callback_joiner.h" |
| 21 | 22 |
| 22 namespace mojo { | 23 namespace mojo { |
| 23 namespace media { | 24 namespace media { |
| 24 | 25 |
| 25 // Mojo agent that renders streams from an origin specified by URL. | 26 // Mojo agent that renders streams from an origin specified by URL. |
| 26 class MediaPlayerImpl : public MediaFactoryService::Product<MediaPlayer>, | 27 class MediaPlayerImpl : public MediaFactoryService::Product<MediaPlayer>, |
| 27 public MediaPlayer { | 28 public MediaPlayer { |
| (...skipping 19 matching lines...) Expand all Loading... |
| 47 static constexpr int64_t kMinimumLeadTime = Timeline::ns_from_ms(30); | 48 static constexpr int64_t kMinimumLeadTime = Timeline::ns_from_ms(30); |
| 48 | 49 |
| 49 // Internal state. | 50 // Internal state. |
| 50 enum class State { | 51 enum class State { |
| 51 kWaiting, // Waiting for some work to complete. | 52 kWaiting, // Waiting for some work to complete. |
| 52 kPaused, | 53 kPaused, |
| 53 kPlaying, | 54 kPlaying, |
| 54 }; | 55 }; |
| 55 | 56 |
| 56 struct Stream { | 57 struct Stream { |
| 57 Stream(size_t index, MediaTypePtr media_type); | 58 Stream(); |
| 58 ~Stream(); | 59 ~Stream(); |
| 59 size_t index_; | 60 // TODO(dalesat): Have the sink enlist the decoder. |
| 60 bool enabled_ = false; | |
| 61 bool end_of_stream_ = false; | |
| 62 MediaTypePtr media_type_; | |
| 63 MediaTypeConverterPtr decoder_; | 61 MediaTypeConverterPtr decoder_; |
| 64 MediaSinkPtr sink_; | 62 MediaSinkPtr sink_; |
| 65 MediaTimelineControlSitePtr timeline_control_site_; | 63 // The following fields are just temporaries used to solve lambda capture |
| 66 TimelineConsumerPtr timeline_consumer_; | 64 // problems. |
| 67 MediaProducerPtr encoded_producer_; | 65 MediaProducerPtr encoded_producer_; |
| 68 MediaProducerPtr decoded_producer_; | 66 MediaProducerPtr decoded_producer_; |
| 69 }; | 67 }; |
| 70 | 68 |
| 71 MediaPlayerImpl(InterfaceHandle<SeekingReader> reader, | 69 MediaPlayerImpl(InterfaceHandle<SeekingReader> reader, |
| 72 InterfaceRequest<MediaPlayer> request, | 70 InterfaceRequest<MediaPlayer> request, |
| 73 MediaFactoryService* owner); | 71 MediaFactoryService* owner); |
| 74 | 72 |
| 75 // Takes action based on current state. | 73 // Takes action based on current state. |
| 76 void Update(); | 74 void Update(); |
| 77 | 75 |
| 78 // Handles seeking in paused state. | 76 // Handles seeking in paused state. |
| 79 void WhenPausedAndSeeking(); | 77 void WhenPausedAndSeeking(); |
| 80 | 78 |
| 81 // Handles seeking in paused state with flushed pipeline. | 79 // Handles seeking in paused state with flushed pipeline. |
| 82 void WhenFlushedAndSeeking(); | 80 void WhenFlushedAndSeeking(); |
| 83 | 81 |
| 84 // Sets the timeline transforms on all the sinks. transform_subject_time_ is | 82 // Sets the timeline transform. transform_subject_time_ is used for the |
| 85 // used for the subject_time, and the effective_reference_time is now plus an | 83 // subject_time, and the effective_reference_time is now plus |
| 86 // epsilon. | 84 // kMinimumLeadTime. |
| 87 void SetSinkTimelineTransforms(uint32_t reference_delta, | 85 void SetTimelineTransform(uint32_t reference_delta, uint32_t subject_delta); |
| 88 uint32_t subject_delta); | |
| 89 | |
| 90 // Sets the timeline transforms on all the sinks. | |
| 91 void SetSinkTimelineTransforms(int64_t subject_time, | |
| 92 uint32_t reference_delta, | |
| 93 uint32_t subject_delta, | |
| 94 int64_t effective_reference_time, | |
| 95 int64_t effective_subject_time); | |
| 96 | |
| 97 // Determines if all the enabled sinks have reached end-of-stream. Returns | |
| 98 // false if there are no enabled streams. | |
| 99 bool AllSinksAtEndOfStream(); | |
| 100 | 86 |
| 101 // Prepares a stream. | 87 // Prepares a stream. |
| 102 void PrepareStream(Stream* stream, | 88 void PrepareStream(Stream* stream, |
| 89 size_t index, |
| 90 const MediaTypePtr& input_media_type, |
| 103 const String& url, | 91 const String& url, |
| 104 const std::function<void()>& callback); | 92 const std::function<void()>& callback); |
| 105 | 93 |
| 106 // Creates a sink for a stream. | 94 // Creates a sink for a stream. |
| 107 void CreateSink(Stream* stream, | 95 void CreateSink(Stream* stream, |
| 108 const MediaTypePtr& input_media_type, | 96 const MediaTypePtr& input_media_type, |
| 109 const String& url, | 97 const String& url, |
| 110 const std::function<void()>& callback); | 98 const std::function<void()>& callback); |
| 111 | 99 |
| 112 // Handles a metadata update from the demux. When called with the default | 100 // Handles a metadata update from the demux. When called with the default |
| 113 // argument values, initiates demux metadata updates. | 101 // argument values, initiates demux metadata updates. |
| 114 void HandleDemuxMetadataUpdates( | 102 void HandleDemuxMetadataUpdates( |
| 115 uint64_t version = MediaDemux::kInitialMetadata, | 103 uint64_t version = MediaDemux::kInitialMetadata, |
| 116 MediaMetadataPtr metadata = nullptr); | 104 MediaMetadataPtr metadata = nullptr); |
| 117 | 105 |
| 118 // Handles a status update from a control site. When called with the default | 106 // Handles a status update from the control site. When called with the default |
| 119 // argument values, initiates control site. status updates. | 107 // argument values, initiates control site. status updates. |
| 120 void HandleTimelineControlSiteStatusUpdates( | 108 void HandleTimelineControlSiteStatusUpdates( |
| 121 Stream* stream, | |
| 122 uint64_t version = MediaTimelineControlSite::kInitialStatus, | 109 uint64_t version = MediaTimelineControlSite::kInitialStatus, |
| 123 MediaTimelineControlSiteStatusPtr status = nullptr); | 110 MediaTimelineControlSiteStatusPtr status = nullptr); |
| 124 | 111 |
| 125 MediaFactoryPtr factory_; | 112 MediaFactoryPtr factory_; |
| 126 MediaDemuxPtr demux_; | 113 MediaDemuxPtr demux_; |
| 114 MediaTimelineControllerPtr timeline_controller_; |
| 115 MediaTimelineControlSitePtr timeline_control_site_; |
| 116 TimelineConsumerPtr timeline_consumer_; |
| 127 std::vector<std::unique_ptr<Stream>> streams_; | 117 std::vector<std::unique_ptr<Stream>> streams_; |
| 128 State state_ = State::kWaiting; | 118 State state_ = State::kWaiting; |
| 129 State target_state_ = State::kPaused; | 119 State target_state_ = State::kPaused; |
| 130 bool flushed_ = true; | 120 bool flushed_ = true; |
| 121 bool end_of_stream_ = false; |
| 131 int64_t target_position_ = kUnspecifiedTime; | 122 int64_t target_position_ = kUnspecifiedTime; |
| 132 int64_t transform_subject_time_ = kUnspecifiedTime; | 123 int64_t transform_subject_time_ = kUnspecifiedTime; |
| 133 TimelineFunction timeline_function_; | 124 TimelineFunction timeline_function_; |
| 134 CallbackJoiner set_transform_joiner_; | 125 CallbackJoiner set_transform_joiner_; |
| 135 MediaMetadataPtr metadata_; | 126 MediaMetadataPtr metadata_; |
| 136 MojoPublisher<GetStatusCallback> status_publisher_; | 127 MojoPublisher<GetStatusCallback> status_publisher_; |
| 137 }; | 128 }; |
| 138 | 129 |
| 139 } // namespace media | 130 } // namespace media |
| 140 } // namespace mojo | 131 } // namespace mojo |
| 141 | 132 |
| 142 #endif // MOJO_SERVICES_MEDIA_FACTORY_MEDIA_PLAYER_IMPL_H_ | 133 #endif // MOJO_SERVICES_MEDIA_FACTORY_MEDIA_PLAYER_IMPL_H_ |
| OLD | NEW |