| 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 #include "base/bind.h" | 5 #include "base/bind.h" |
| 6 #include "base/logging.h" | 6 #include "base/logging.h" |
| 7 #include "base/message_loop/message_loop.h" | 7 #include "base/message_loop/message_loop.h" |
| 8 #include "mojo/services/media/common/cpp/timeline.h" | 8 #include "mojo/services/media/common/cpp/timeline.h" |
| 9 #include "services/media/common/timeline_control_site.h" | 9 #include "services/media/common/timeline_control_site.h" |
| 10 | 10 |
| (...skipping 18 matching lines...) Expand all Loading... |
| 29 ClearPendingTimelineFunctionUnsafe(false); | 29 ClearPendingTimelineFunctionUnsafe(false); |
| 30 | 30 |
| 31 status_publisher_.SetCallbackRunner( | 31 status_publisher_.SetCallbackRunner( |
| 32 [this](const GetStatusCallback& callback, uint64_t version) { | 32 [this](const GetStatusCallback& callback, uint64_t version) { |
| 33 MediaTimelineControlSiteStatusPtr status; | 33 MediaTimelineControlSiteStatusPtr status; |
| 34 { | 34 { |
| 35 base::AutoLock lock(lock_); | 35 base::AutoLock lock(lock_); |
| 36 status = MediaTimelineControlSiteStatus::New(); | 36 status = MediaTimelineControlSiteStatus::New(); |
| 37 status->timeline_transform = | 37 status->timeline_transform = |
| 38 TimelineTransform::From(current_timeline_function_); | 38 TimelineTransform::From(current_timeline_function_); |
| 39 status->end_of_stream = false; // TODO(dalesat): Provide this. | 39 status->end_of_stream = ReachedEndOfStreamUnsafe(); |
| 40 } | 40 } |
| 41 callback.Run(version, status.Pass()); | 41 callback.Run(version, status.Pass()); |
| 42 }); | 42 }); |
| 43 } | 43 } |
| 44 | 44 |
| 45 TimelineControlSite::~TimelineControlSite() {} | 45 TimelineControlSite::~TimelineControlSite() {} |
| 46 | 46 |
| 47 void TimelineControlSite::Bind( | 47 void TimelineControlSite::Bind( |
| 48 InterfaceRequest<MediaTimelineControlSite> request) { | 48 InterfaceRequest<MediaTimelineControlSite> request) { |
| 49 if (control_site_binding_.is_bound()) { | 49 if (control_site_binding_.is_bound()) { |
| (...skipping 25 matching lines...) Expand all Loading... |
| 75 void TimelineControlSite::SnapshotCurrentFunction(int64_t reference_time, | 75 void TimelineControlSite::SnapshotCurrentFunction(int64_t reference_time, |
| 76 TimelineFunction* out, | 76 TimelineFunction* out, |
| 77 uint32_t* generation) { | 77 uint32_t* generation) { |
| 78 DCHECK(out); | 78 DCHECK(out); |
| 79 base::AutoLock lock(lock_); | 79 base::AutoLock lock(lock_); |
| 80 ApplyPendingChangesUnsafe(reference_time); | 80 ApplyPendingChangesUnsafe(reference_time); |
| 81 *out = current_timeline_function_; | 81 *out = current_timeline_function_; |
| 82 if (generation) { | 82 if (generation) { |
| 83 *generation = generation_; | 83 *generation = generation_; |
| 84 } | 84 } |
| 85 |
| 86 if (ReachedEndOfStreamUnsafe() && !end_of_stream_published_) { |
| 87 end_of_stream_published_ = true; |
| 88 task_runner_->PostTask( |
| 89 FROM_HERE, base::Bind(&MojoPublisher<GetStatusCallback>::SendUpdates, |
| 90 base::Unretained(&status_publisher_))); |
| 91 } |
| 92 } |
| 93 |
| 94 void TimelineControlSite::SetEndOfStreamPts(int64_t end_of_stream_pts) { |
| 95 base::AutoLock lock(lock_); |
| 96 if (end_of_stream_pts_ != end_of_stream_pts) { |
| 97 end_of_stream_pts_ = end_of_stream_pts; |
| 98 end_of_stream_published_ = false; |
| 99 } |
| 100 } |
| 101 |
| 102 bool TimelineControlSite::ReachedEndOfStreamUnsafe() { |
| 103 lock_.AssertAcquired(); |
| 104 |
| 105 return end_of_stream_pts_ != kUnspecifiedTime && |
| 106 current_timeline_function_(Timeline::local_now()) >= |
| 107 end_of_stream_pts_; |
| 85 } | 108 } |
| 86 | 109 |
| 87 void TimelineControlSite::GetStatus(uint64_t version_last_seen, | 110 void TimelineControlSite::GetStatus(uint64_t version_last_seen, |
| 88 const GetStatusCallback& callback) { | 111 const GetStatusCallback& callback) { |
| 89 status_publisher_.Get(version_last_seen, callback); | 112 status_publisher_.Get(version_last_seen, callback); |
| 90 } | 113 } |
| 91 | 114 |
| 92 void TimelineControlSite::GetTimelineConsumer( | 115 void TimelineControlSite::GetTimelineConsumer( |
| 93 InterfaceRequest<TimelineConsumer> timeline_consumer) { | 116 InterfaceRequest<TimelineConsumer> timeline_consumer) { |
| 94 if (consumer_binding_.is_bound()) { | 117 if (consumer_binding_.is_bound()) { |
| (...skipping 13 matching lines...) Expand all Loading... |
| 108 base::AutoLock lock(lock_); | 131 base::AutoLock lock(lock_); |
| 109 | 132 |
| 110 // At most one of the effective times must be specified. | 133 // At most one of the effective times must be specified. |
| 111 RCHECK(effective_reference_time == kUnspecifiedTime || | 134 RCHECK(effective_reference_time == kUnspecifiedTime || |
| 112 effective_subject_time == kUnspecifiedTime); | 135 effective_subject_time == kUnspecifiedTime); |
| 113 // effective_subject_time can only be used if we're progressing already. | 136 // effective_subject_time can only be used if we're progressing already. |
| 114 RCHECK(effective_subject_time == kUnspecifiedTime || | 137 RCHECK(effective_subject_time == kUnspecifiedTime || |
| 115 current_timeline_function_.subject_delta() != 0); | 138 current_timeline_function_.subject_delta() != 0); |
| 116 RCHECK(reference_delta != 0); | 139 RCHECK(reference_delta != 0); |
| 117 | 140 |
| 141 if (subject_time != kUnspecifiedTime && |
| 142 end_of_stream_pts_ != kUnspecifiedTime) { |
| 143 end_of_stream_pts_ = kUnspecifiedTime; |
| 144 end_of_stream_published_ = false; |
| 145 } |
| 146 |
| 118 if (effective_subject_time != kUnspecifiedTime) { | 147 if (effective_subject_time != kUnspecifiedTime) { |
| 119 // Infer effective_reference_time from effective_subject_time. | 148 // Infer effective_reference_time from effective_subject_time. |
| 120 effective_reference_time = | 149 effective_reference_time = |
| 121 current_timeline_function_.ApplyInverse(effective_subject_time); | 150 current_timeline_function_.ApplyInverse(effective_subject_time); |
| 122 | 151 |
| 123 if (subject_time == kUnspecifiedTime) { | 152 if (subject_time == kUnspecifiedTime) { |
| 124 // Infer subject_time from effective_subject_time. | 153 // Infer subject_time from effective_subject_time. |
| 125 subject_time = effective_subject_time; | 154 subject_time = effective_subject_time; |
| 126 } | 155 } |
| 127 } else { | 156 } else { |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 184 } | 213 } |
| 185 | 214 |
| 186 // static | 215 // static |
| 187 void TimelineControlSite::RunCallback(SetTimelineTransformCallback callback, | 216 void TimelineControlSite::RunCallback(SetTimelineTransformCallback callback, |
| 188 bool completed) { | 217 bool completed) { |
| 189 callback.Run(completed); | 218 callback.Run(completed); |
| 190 } | 219 } |
| 191 | 220 |
| 192 } // namespace media | 221 } // namespace media |
| 193 } // namespace mojo | 222 } // namespace mojo |
| OLD | NEW |