Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(89)

Side by Side Diff: services/media/factory_service/media_player_impl.h

Issue 2006093004: Motown: Convert MediaSink to expose MediaTimelineControlSite (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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"
14 #include "mojo/services/media/common/cpp/timeline_function.h"
13 #include "mojo/services/media/common/interfaces/media_transport.mojom.h" 15 #include "mojo/services/media/common/interfaces/media_transport.mojom.h"
14 #include "mojo/services/media/control/interfaces/media_factory.mojom.h" 16 #include "mojo/services/media/control/interfaces/media_factory.mojom.h"
15 #include "mojo/services/media/core/interfaces/seeking_reader.mojom.h" 17 #include "mojo/services/media/core/interfaces/seeking_reader.mojom.h"
16 #include "services/media/common/mojo_publisher.h" 18 #include "services/media/common/mojo_publisher.h"
17 #include "services/media/factory_service/factory_service.h" 19 #include "services/media/factory_service/factory_service.h"
20 #include "services/media/framework/util/callback_joiner.h"
18 21
19 namespace mojo { 22 namespace mojo {
20 namespace media { 23 namespace media {
21 24
22 // Mojo agent that renders streams from an origin specified by URL. 25 // Mojo agent that renders streams from an origin specified by URL.
23 class MediaPlayerImpl : public MediaFactoryService::Product<MediaPlayer>, 26 class MediaPlayerImpl : public MediaFactoryService::Product<MediaPlayer>,
24 public MediaPlayer { 27 public MediaPlayer {
25 public: 28 public:
26 static std::shared_ptr<MediaPlayerImpl> Create( 29 static std::shared_ptr<MediaPlayerImpl> Create(
27 InterfaceHandle<SeekingReader> reader, 30 InterfaceHandle<SeekingReader> reader,
28 InterfaceRequest<MediaPlayer> request, 31 InterfaceRequest<MediaPlayer> request,
29 MediaFactoryService* owner); 32 MediaFactoryService* owner);
30 33
31 ~MediaPlayerImpl() override; 34 ~MediaPlayerImpl() override;
32 35
33 // MediaPlayer implementation. 36 // MediaPlayer implementation.
34 void GetStatus(uint64_t version_last_seen, 37 void GetStatus(uint64_t version_last_seen,
35 const GetStatusCallback& callback) override; 38 const GetStatusCallback& callback) override;
36 39
37 void Play() override; 40 void Play() override;
38 41
39 void Pause() override; 42 void Pause() override;
40 43
41 void Seek(int64_t position) override; 44 void Seek(int64_t position) override;
42 45
43 private: 46 private:
44 const int64_t kNotSeeking = std::numeric_limits<int64_t>::max(); 47 static constexpr int64_t kMinimumLeadTime = Timeline::ns_from_ms(30);
45 48
46 // Internal state. 49 // Internal state.
47 enum class State { 50 enum class State {
48 kWaiting, // Waiting for some work to complete. 51 kWaiting, // Waiting for some work to complete.
49 kPaused, 52 kPaused,
50 kWaitingForSinksToPlay,
51 kPlaying, 53 kPlaying,
52 kWaitingForSinksToPause
53 };
54
55 // For matching sink states.
56 enum class SinkState {
57 kPaused,
58 kPlaying,
59 kEnded,
60 kPausedOrEnded,
61 kPlayingOrEnded
62 }; 54 };
63 55
64 struct Stream { 56 struct Stream {
65 Stream(size_t index, MediaTypePtr media_type); 57 Stream(size_t index, MediaTypePtr media_type);
66 ~Stream(); 58 ~Stream();
67 size_t index_; 59 size_t index_;
68 bool enabled_ = false; 60 bool enabled_ = false;
69 MediaState state_ = MediaState::UNPREPARED; 61 bool end_of_stream_ = false;
70 MediaTypePtr media_type_; 62 MediaTypePtr media_type_;
71 MediaTypeConverterPtr decoder_; 63 MediaTypeConverterPtr decoder_;
72 MediaSinkPtr sink_; 64 MediaSinkPtr sink_;
65 MediaTimelineControlSitePtr timeline_control_site_;
66 TimelineConsumerPtr timeline_consumer_;
73 MediaProducerPtr encoded_producer_; 67 MediaProducerPtr encoded_producer_;
74 MediaProducerPtr decoded_producer_; 68 MediaProducerPtr decoded_producer_;
75 }; 69 };
76 70
77 MediaPlayerImpl(InterfaceHandle<SeekingReader> reader, 71 MediaPlayerImpl(InterfaceHandle<SeekingReader> reader,
78 InterfaceRequest<MediaPlayer> request, 72 InterfaceRequest<MediaPlayer> request,
79 MediaFactoryService* owner); 73 MediaFactoryService* owner);
80 74
81 // Takes action based on current state. 75 // Takes action based on current state.
82 void Update(); 76 void Update();
83 77
84 // Handles seeking in paused state. 78 // Handles seeking in paused state.
85 void WhenPausedAndSeeking(); 79 void WhenPausedAndSeeking();
86 80
87 // Handles seeking in paused state with flushed pipeline. 81 // Handles seeking in paused state with flushed pipeline.
88 void WhenFlushedAndSeeking(); 82 void WhenFlushedAndSeeking();
89 83
90 // Tells the sinks to change state. 84 // Sets the timeline transforms on all the sinks. transform_subject_time_ is
91 void ChangeSinkStates(MediaState media_state); 85 // used for the subject_time, and the effective_reference_time is now plus an
86 // epsilon.
87 void SetSinkTimelineTransforms(uint32_t reference_delta,
88 uint32_t subject_delta);
92 89
93 // Determines if all the enabled sinks have the specified state. 90 // Sets the timeline transforms on all the sinks.
94 bool AllSinksAre(SinkState sink_state); 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);
95 96
96 // Sets the reported_media_state_ field, calling StatusUpdated as needed. 97 // Determines if all the enabled sinks have reached end-of-stream. Returns
97 void SetReportedMediaState(MediaState media_state); 98 // false if there are no enabled streams.
99 bool AllSinksAtEndOfStream();
98 100
99 // Prepares a stream. 101 // Prepares a stream.
100 void PrepareStream(Stream* stream, 102 void PrepareStream(Stream* stream,
101 const String& url, 103 const String& url,
102 const std::function<void()>& callback); 104 const std::function<void()>& callback);
103 105
104 // Creates a sink for a stream. 106 // Creates a sink for a stream.
105 void CreateSink(Stream* stream, 107 void CreateSink(Stream* stream,
106 const MediaTypePtr& input_media_type, 108 const MediaTypePtr& input_media_type,
107 const String& url, 109 const String& url,
108 const std::function<void()>& callback); 110 const std::function<void()>& callback);
109 111
110 // Handles a metadata update from the demux. When called with the default 112 // Handles a metadata update from the demux. When called with the default
111 // argument values, initiates demux metadata updates. 113 // argument values, initiates demux metadata updates.
112 void HandleDemuxMetadataUpdates( 114 void HandleDemuxMetadataUpdates(
113 uint64_t version = MediaDemux::kInitialMetadata, 115 uint64_t version = MediaDemux::kInitialMetadata,
114 MediaMetadataPtr metadata = nullptr); 116 MediaMetadataPtr metadata = nullptr);
115 117
116 // Handles a status update from a sink. When called with the default 118 // Handles a status update from a control site. When called with the default
117 // argument values, initiates sink status updates. 119 // argument values, initiates control site. status updates.
118 void HandleSinkStatusUpdates(Stream* stream, 120 void HandleTimelineControlSiteStatusUpdates(
119 uint64_t version = MediaSink::kInitialStatus, 121 Stream* stream,
120 MediaSinkStatusPtr status = nullptr); 122 uint64_t version = MediaTimelineControlSite::kInitialStatus,
123 MediaTimelineControlSiteStatusPtr status = nullptr);
121 124
122 MediaFactoryPtr factory_; 125 MediaFactoryPtr factory_;
123 MediaDemuxPtr demux_; 126 MediaDemuxPtr demux_;
124 std::vector<std::unique_ptr<Stream>> streams_; 127 std::vector<std::unique_ptr<Stream>> streams_;
125 State state_ = State::kWaiting; 128 State state_ = State::kWaiting;
129 State target_state_ = State::kPaused;
126 bool flushed_ = true; 130 bool flushed_ = true;
127 MediaState reported_media_state_ = MediaState::UNPREPARED; 131 int64_t target_position_ = kUnspecifiedTime;
128 MediaState target_state_ = MediaState::PAUSED; 132 int64_t transform_subject_time_ = kUnspecifiedTime;
129 int64_t target_position_ = kNotSeeking; 133 TimelineFunction timeline_function_;
130 TimelineTransformPtr transform_; 134 CallbackJoiner set_transform_joiner_;
131 MediaMetadataPtr metadata_; 135 MediaMetadataPtr metadata_;
132 MojoPublisher<GetStatusCallback> status_publisher_; 136 MojoPublisher<GetStatusCallback> status_publisher_;
133 }; 137 };
134 138
135 } // namespace media 139 } // namespace media
136 } // namespace mojo 140 } // namespace mojo
137 141
138 #endif // MOJO_SERVICES_MEDIA_FACTORY_MEDIA_PLAYER_IMPL_H_ 142 #endif // MOJO_SERVICES_MEDIA_FACTORY_MEDIA_PLAYER_IMPL_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698