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

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

Issue 2085593002: Motown: Change player state machine to support preroll (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Make SetTimelineTransform calls more uniform with respect to other operations affecting the state m… Created 4 years, 6 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
« no previous file with comments | « no previous file | services/media/factory_service/media_player_impl.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
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
87 // subject_time, and the effective_reference_time is now plus
88 // kMinimumLeadTime.
89 void SetTimelineTransform(uint32_t reference_delta, uint32_t subject_delta);
90
91 // Prepares a stream. 81 // Prepares a stream.
92 void PrepareStream(Stream* stream, 82 void PrepareStream(Stream* stream,
93 size_t index, 83 size_t index,
94 const MediaTypePtr& input_media_type, 84 const MediaTypePtr& input_media_type,
95 const std::function<void()>& callback); 85 const std::function<void()>& callback);
96 86
97 // Creates a sink for a stream. 87 // Creates a sink for a stream.
98 void CreateSink(Stream* stream, 88 void CreateSink(Stream* stream,
99 const MediaTypePtr& input_media_type, 89 const MediaTypePtr& input_media_type,
100 const std::function<void()>& callback); 90 const std::function<void()>& callback);
101 91
102 // Handles a metadata update from the demux. When called with the default 92 // Handles a metadata update from the demux. When called with the default
103 // argument values, initiates demux metadata updates. 93 // argument values, initiates demux metadata updates.
104 void HandleDemuxMetadataUpdates( 94 void HandleDemuxMetadataUpdates(
105 uint64_t version = MediaDemux::kInitialMetadata, 95 uint64_t version = MediaDemux::kInitialMetadata,
106 MediaMetadataPtr metadata = nullptr); 96 MediaMetadataPtr metadata = nullptr);
107 97
108 // Handles a status update from the control site. When called with the default 98 // Handles a status update from the control site. When called with the default
109 // argument values, initiates control site. status updates. 99 // argument values, initiates control site. status updates.
110 void HandleTimelineControlSiteStatusUpdates( 100 void HandleTimelineControlSiteStatusUpdates(
111 uint64_t version = MediaTimelineControlSite::kInitialStatus, 101 uint64_t version = MediaTimelineControlSite::kInitialStatus,
112 MediaTimelineControlSiteStatusPtr status = nullptr); 102 MediaTimelineControlSiteStatusPtr status = nullptr);
113 103
114 MediaFactoryPtr factory_; 104 MediaFactoryPtr factory_;
115 MediaDemuxPtr demux_; 105 MediaDemuxPtr demux_;
116 MediaTimelineControllerPtr timeline_controller_; 106 MediaTimelineControllerPtr timeline_controller_;
117 MediaTimelineControlSitePtr timeline_control_site_; 107 MediaTimelineControlSitePtr timeline_control_site_;
118 TimelineConsumerPtr timeline_consumer_; 108 TimelineConsumerPtr timeline_consumer_;
119 std::vector<std::unique_ptr<Stream>> streams_; 109 std::vector<std::unique_ptr<Stream>> streams_;
110
111 // The state we're currently in.
120 State state_ = State::kWaiting; 112 State state_ = State::kWaiting;
121 State target_state_ = State::kPaused; 113
122 bool flushed_ = true; 114 // The state we trying to transition to, either because the client has called
115 // |Play| or |Pause| or because we've hit end-of-stream.
116 State target_state_ = State::kFlushed;
117
118 // Whether we're currently at end-of-stream.
123 bool end_of_stream_ = false; 119 bool end_of_stream_ = false;
120
121 // The position we want to seek to (because the client called Seek) or
122 // kUnspecifiedTime, which indicates there's no desire to seek.
124 int64_t target_position_ = kUnspecifiedTime; 123 int64_t target_position_ = kUnspecifiedTime;
124
125 // The subject time to be used for SetTimelineTransform. The value is
126 // kUnspecifiedTime if there's no need to seek or the position we want to
127 // seek to if there is.
125 int64_t transform_subject_time_ = kUnspecifiedTime; 128 int64_t transform_subject_time_ = kUnspecifiedTime;
129
130 // A function that translates local time into presentation time in ns.
126 TimelineFunction timeline_function_; 131 TimelineFunction timeline_function_;
132
127 CallbackJoiner set_transform_joiner_; 133 CallbackJoiner set_transform_joiner_;
128 MediaMetadataPtr metadata_; 134 MediaMetadataPtr metadata_;
129 MojoPublisher<GetStatusCallback> status_publisher_; 135 MojoPublisher<GetStatusCallback> status_publisher_;
136
130 // The following fields are just temporaries used to solve lambda capture 137 // The following fields are just temporaries used to solve lambda capture
131 // problems. 138 // problems.
132 InterfaceHandle<MediaRenderer> audio_renderer_; 139 InterfaceHandle<MediaRenderer> audio_renderer_;
133 InterfaceHandle<MediaRenderer> video_renderer_; 140 InterfaceHandle<MediaRenderer> video_renderer_;
134 }; 141 };
135 142
136 } // namespace media 143 } // namespace media
137 } // namespace mojo 144 } // namespace mojo
138 145
139 #endif // MOJO_SERVICES_MEDIA_FACTORY_MEDIA_PLAYER_IMPL_H_ 146 #endif // MOJO_SERVICES_MEDIA_FACTORY_MEDIA_PLAYER_IMPL_H_
OLDNEW
« no previous file with comments | « no previous file | services/media/factory_service/media_player_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698