OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef MOJO_SERVICES_MEDIA_COMMON_TIMELINE_CONTROL_SITE_IMPL_H_ |
| 6 #define MOJO_SERVICES_MEDIA_COMMON_TIMELINE_CONTROL_SITE_IMPL_H_ |
| 7 |
| 8 #include "base/single_thread_task_runner.h" |
| 9 #include "base/synchronization/lock.h" |
| 10 #include "mojo/public/cpp/bindings/binding.h" |
| 11 #include "mojo/services/media/common/cpp/timeline_function.h" |
| 12 #include "mojo/services/media/core/interfaces/timeline_controller.mojom.h" |
| 13 #include "services/media/common/mojo_publisher.h" |
| 14 |
| 15 namespace mojo { |
| 16 namespace media { |
| 17 |
| 18 // MediaTimelineControlSite implementation. |
| 19 class TimelineControlSite : public MediaTimelineControlSite, |
| 20 public TimelineConsumer { |
| 21 public: |
| 22 TimelineControlSite(); |
| 23 |
| 24 ~TimelineControlSite() override; |
| 25 |
| 26 // Binds to the control site. If a binding exists already, it is closed. |
| 27 void Bind(InterfaceRequest<MediaTimelineControlSite> request); |
| 28 |
| 29 // Determines whether the control site is currently bound. |
| 30 bool is_bound() { return control_site_binding_.is_bound(); } |
| 31 |
| 32 // Unbinds from clients and resets to initial state. |
| 33 void Reset(); |
| 34 |
| 35 // Get the TimelineFunction for the reference_time (which should be 'now', |
| 36 // approximately). |
| 37 void SnapshotCurrentFunction(int64_t reference_time, |
| 38 TimelineFunction* out, |
| 39 uint32_t* generation = nullptr); |
| 40 |
| 41 // MediaTimelineControlSite implementation. |
| 42 void GetStatus(uint64_t version_last_seen, |
| 43 const GetStatusCallback& callback) override; |
| 44 |
| 45 void GetTimelineConsumer( |
| 46 InterfaceRequest<TimelineConsumer> timeline_consumer) override; |
| 47 |
| 48 // TimelineConsumer implementation. |
| 49 void SetTimelineTransform( |
| 50 int64_t subject_time, |
| 51 uint32_t reference_delta, |
| 52 uint32_t subject_delta, |
| 53 int64_t effective_reference_time, |
| 54 int64_t effective_subject_time, |
| 55 const SetTimelineTransformCallback& callback) override; |
| 56 |
| 57 private: |
| 58 // Applies pending_timeline_function_ if it's time to do so based on the |
| 59 // given reference time. |
| 60 void ApplyPendingChangesUnsafe(int64_t reference_time); |
| 61 |
| 62 // Clears the pending timeline function and calls its associated callback |
| 63 // with the indicated completed status. |
| 64 void ClearPendingTimelineFunctionUnsafe(bool completed); |
| 65 |
| 66 // Determines if an unrealized timeline function is currently pending. |
| 67 bool TimelineFunctionPendingUnsafe() { |
| 68 return pending_timeline_function_.reference_time() != kUnspecifiedTime; |
| 69 } |
| 70 |
| 71 // Unbinds from clients and resets to initial state. |
| 72 void ResetUnsafe(); |
| 73 |
| 74 static void RunCallback(SetTimelineTransformCallback callback, |
| 75 bool completed); |
| 76 |
| 77 Binding<MediaTimelineControlSite> control_site_binding_; |
| 78 Binding<TimelineConsumer> consumer_binding_; |
| 79 MojoPublisher<GetStatusCallback> status_publisher_; |
| 80 |
| 81 base::Lock lock_; |
| 82 // BEGIN fields synchronized using lock_. |
| 83 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; |
| 84 TimelineFunction current_timeline_function_; |
| 85 TimelineFunction pending_timeline_function_; |
| 86 SetTimelineTransformCallback set_timeline_transform_callback_; |
| 87 uint32_t generation_ = 1; |
| 88 // END fields synchronized using lock_. |
| 89 }; |
| 90 |
| 91 } // namespace media |
| 92 } // namespace mojo |
| 93 |
| 94 #endif // MOJO_SERVICES_MEDIA_COMMON_TIMELINE_CONTROL_SITE_IMPL_H_ |
OLD | NEW |