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 <deque> | 8 #include <deque> |
9 #include <limits> | 9 #include <limits> |
10 #include <vector> | 10 #include <vector> |
11 | 11 |
12 #include "mojo/public/cpp/application/application_impl.h" | 12 #include "mojo/public/cpp/application/application_impl.h" |
13 #include "mojo/public/cpp/bindings/binding.h" | 13 #include "mojo/public/cpp/bindings/binding.h" |
14 #include "mojo/services/media/common/interfaces/media_transport.mojom.h" | 14 #include "mojo/services/media/common/interfaces/media_transport.mojom.h" |
15 #include "mojo/services/media/control/interfaces/media_factory.mojom.h" | 15 #include "mojo/services/media/control/interfaces/media_factory.mojom.h" |
16 #include "services/media/factory_service/factory_service.h" | 16 #include "services/media/factory_service/factory_service.h" |
17 #include "services/media/factory_service/watched.h" | 17 #include "services/media/factory_service/watched.h" |
18 | 18 |
19 namespace mojo { | 19 namespace mojo { |
20 namespace media { | 20 namespace media { |
21 | 21 |
22 // Mojo agent that renders streams from an origin specified by URL. | 22 // Mojo agent that renders streams from an origin specified by URL. |
23 class MediaPlayerImpl | 23 class MediaPlayerImpl : public MediaFactoryService::Product, |
24 : public MediaFactoryService::Product, | 24 public MediaPlayer { |
25 public MediaPlayer { | |
26 public: | 25 public: |
27 static std::shared_ptr<MediaPlayerImpl> Create( | 26 static std::shared_ptr<MediaPlayerImpl> Create( |
28 const String& originUrl, | 27 const String& originUrl, |
29 InterfaceRequest<MediaPlayer> request, | 28 InterfaceRequest<MediaPlayer> request, |
30 MediaFactoryService* owner); | 29 MediaFactoryService* owner); |
31 | 30 |
32 ~MediaPlayerImpl() override; | 31 ~MediaPlayerImpl() override; |
33 | 32 |
34 // MediaPlayer implementation. | 33 // MediaPlayer implementation. |
35 void GetStatus(uint64_t version_last_seen, const GetStatusCallback& callback) | 34 void GetStatus(uint64_t version_last_seen, |
36 override; | 35 const GetStatusCallback& callback) override; |
37 | 36 |
38 void Play() override; | 37 void Play() override; |
39 | 38 |
40 void Pause() override; | 39 void Pause() override; |
41 | 40 |
42 void Seek(int64_t position) override; | 41 void Seek(int64_t position) override; |
43 | 42 |
44 private: | 43 private: |
45 const int64_t kNotSeeking = std::numeric_limits<int64_t>::max(); | 44 const int64_t kNotSeeking = std::numeric_limits<int64_t>::max(); |
46 | 45 |
47 struct Stream { | 46 struct Stream { |
48 Stream(); | 47 Stream(); |
49 ~Stream(); | 48 ~Stream(); |
50 bool enabled_ = false; | 49 bool enabled_ = false; |
51 Watched<MediaState> state_; | 50 Watched<MediaState> state_; |
52 MediaSourceStreamDescriptorPtr descriptor_; | 51 MediaSourceStreamDescriptorPtr descriptor_; |
53 MediaTypeConverterPtr decoder_; | 52 MediaTypeConverterPtr decoder_; |
54 MediaSinkPtr sink_; | 53 MediaSinkPtr sink_; |
55 MediaProducerPtr encoded_producer_; | 54 MediaProducerPtr encoded_producer_; |
56 MediaProducerPtr decoded_producer_; | 55 MediaProducerPtr decoded_producer_; |
57 }; | 56 }; |
58 | 57 |
59 MediaPlayerImpl( | 58 MediaPlayerImpl(const String& originUrl, |
60 const String& originUrl, | 59 InterfaceRequest<MediaPlayer> request, |
61 InterfaceRequest<MediaPlayer> request, | 60 MediaFactoryService* owner); |
62 MediaFactoryService* owner); | |
63 | 61 |
64 // Handles events in paused state. | 62 // Handles events in paused state. |
65 void WhenPaused(); | 63 void WhenPaused(); |
66 | 64 |
67 // Handles events in playing state. | 65 // Handles events in playing state. |
68 void WhenPlaying(); | 66 void WhenPlaying(); |
69 | 67 |
70 // Handles events when seeking in paused state. | 68 // Handles events when seeking in paused state. |
71 void WhenPausedAndSeeking(); | 69 void WhenPausedAndSeeking(); |
72 | 70 |
73 // Handles events when seeking with flushed pipeline. | 71 // Handles events when seeking with flushed pipeline. |
74 void WhenFlushedAndSeeking(); | 72 void WhenFlushedAndSeeking(); |
75 | 73 |
76 // Tells the sinks to change state and returns an Event that occurs when this | 74 // Tells the sinks to change state and returns an Event that occurs when this |
77 // is accomplished. | 75 // is accomplished. |
78 Event ChangeSinkStates(MediaState media_state); | 76 Event ChangeSinkStates(MediaState media_state); |
79 | 77 |
80 // Returns an Event the occurs when all sinks are in the indicated state. | 78 // Returns an Event the occurs when all sinks are in the indicated state. |
81 Event AllSinkStatesBecome(MediaState media_state); | 79 Event AllSinkStatesBecome(MediaState media_state); |
82 | 80 |
83 // Sets the reported_media_state_ field, calling StatusUpdated as needed. | 81 // Sets the reported_media_state_ field, calling StatusUpdated as needed. |
84 void SetReportedMediaState(MediaState media_state); | 82 void SetReportedMediaState(MediaState media_state); |
85 | 83 |
86 // Prepares a stream. | 84 // Prepares a stream. |
87 Event PrepareStream(const std::unique_ptr<Stream>& stream, const String& url); | 85 Event PrepareStream(const std::unique_ptr<Stream>& stream, const String& url); |
88 | 86 |
89 // Creates a sink for a stream. | 87 // Creates a sink for a stream. |
90 // TODO(dalesat): Use raw pointers rather than const std::unique_ptr<>&. | 88 // TODO(dalesat): Use raw pointers rather than const std::unique_ptr<>&. |
91 void CreateSink( | 89 void CreateSink(const std::unique_ptr<Stream>& stream, |
92 const std::unique_ptr<Stream>& stream, | 90 const MediaTypePtr& input_media_type, |
93 const MediaTypePtr& input_media_type, | 91 const String& url, |
94 const String& url, | 92 Event event); |
95 Event event); | |
96 | 93 |
97 // Increments the status version and runs pending status request callbacks. | 94 // Increments the status version and runs pending status request callbacks. |
98 void StatusUpdated(); | 95 void StatusUpdated(); |
99 | 96 |
100 // Runs a status request callback. | 97 // Runs a status request callback. |
101 void RunStatusCallback(const GetStatusCallback& callback) const; | 98 void RunStatusCallback(const GetStatusCallback& callback) const; |
102 | 99 |
103 // Handles a status update from the source. When called with the default | 100 // Handles a status update from the source. When called with the default |
104 // argument values, initiates source status updates. | 101 // argument values, initiates source status updates. |
105 void HandleSourceStatusUpdates( | 102 void HandleSourceStatusUpdates(uint64_t version = MediaSource::kInitialStatus, |
106 uint64_t version = MediaSource::kInitialStatus, | 103 MediaSourceStatusPtr status = nullptr); |
107 MediaSourceStatusPtr status = nullptr); | |
108 | 104 |
109 // Handles a status update from a sink. When called with the default | 105 // Handles a status update from a sink. When called with the default |
110 // argument values, initiates sink status updates. | 106 // argument values, initiates sink status updates. |
111 void HandleSinkStatusUpdates( | 107 void HandleSinkStatusUpdates(const std::unique_ptr<Stream>& stream, |
112 const std::unique_ptr<Stream>& stream, | 108 uint64_t version = MediaSink::kInitialStatus, |
113 uint64_t version = MediaSink::kInitialStatus, | 109 MediaSinkStatusPtr status = nullptr); |
114 MediaSinkStatusPtr status = nullptr); | |
115 | 110 |
116 Event event_; | 111 Event event_; |
117 Binding<MediaPlayer> binding_; | 112 Binding<MediaPlayer> binding_; |
118 MediaFactoryPtr factory_; | 113 MediaFactoryPtr factory_; |
119 MediaSourcePtr source_; | 114 MediaSourcePtr source_; |
120 std::vector<std::unique_ptr<Stream>> streams_; | 115 std::vector<std::unique_ptr<Stream>> streams_; |
121 uint64_t status_version_ = 1u; | 116 uint64_t status_version_ = 1u; |
122 bool flushed_ = true; | 117 bool flushed_ = true; |
123 MediaState reported_media_state_ = MediaState::UNPREPARED; | 118 MediaState reported_media_state_ = MediaState::UNPREPARED; |
124 Watched<MediaState> target_state_; | 119 Watched<MediaState> target_state_; |
125 Watched<int64_t> target_position_; | 120 Watched<int64_t> target_position_; |
126 TimelineTransformPtr transform_; | 121 TimelineTransformPtr transform_; |
127 MediaMetadataPtr metadata_; | 122 MediaMetadataPtr metadata_; |
128 std::deque<GetStatusCallback> pending_status_requests_; | 123 std::deque<GetStatusCallback> pending_status_requests_; |
129 }; | 124 }; |
130 | 125 |
131 } // namespace media | 126 } // namespace media |
132 } // namespace mojo | 127 } // namespace mojo |
133 | 128 |
134 #endif // MOJO_SERVICES_MEDIA_FACTORY_MEDIA_PLAYER_IMPL_H_ | 129 #endif // MOJO_SERVICES_MEDIA_FACTORY_MEDIA_PLAYER_IMPL_H_ |
OLD | NEW |