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

Unified Diff: services/media/factory_service/media_sink_impl.cc

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 side-by-side diff with in-line comments
Download patch
Index: services/media/factory_service/media_sink_impl.cc
diff --git a/services/media/factory_service/media_sink_impl.cc b/services/media/factory_service/media_sink_impl.cc
index 1fec5bdf855bee755bec001a4943ac4e7aa37772..e6bbeec8402f52a09b34f49d3350a8cd60a0ad16 100644
--- a/services/media/factory_service/media_sink_impl.cc
+++ b/services/media/factory_service/media_sink_impl.cc
@@ -3,8 +3,6 @@
// found in the LICENSE file.
#include "base/logging.h"
-#include "mojo/services/media/common/cpp/timeline.h"
-#include "mojo/services/media/common/cpp/timeline_function.h"
#include "services/media/factory_service/media_sink_impl.h"
#include "services/media/framework/util/conversion_pipeline_builder.h"
#include "services/media/framework_mojo/mojo_type_conversions.h"
@@ -32,16 +30,6 @@ MediaSinkImpl::MediaSinkImpl(const String& destination_url,
DCHECK(destination_url);
DCHECK(media_type);
- status_publisher_.SetCallbackRunner([this](const GetStatusCallback& callback,
- uint64_t version) {
- MediaSinkStatusPtr status = MediaSinkStatus::New();
- status->state = (producer_state_ == MediaState::PAUSED && rate_ != 0.0)
- ? MediaState::PLAYING
- : producer_state_;
- status->timeline_transform = TimelineTransform::From(timeline_function_);
- callback.Run(version, status.Pass());
- });
-
PartRef consumer_ref = graph_.Add(consumer_);
PartRef producer_ref = graph_.Add(producer_);
@@ -58,18 +46,9 @@ MediaSinkImpl::MediaSinkImpl(const String& destination_url,
DCHECK(producer_);
graph_.FlushOutput(consumer_ref.output());
producer_->FlushConnection(callback);
- flushed_ = true;
});
});
- producer_->SetStatusCallback([this](MediaState state) {
- producer_state_ = state;
- status_publisher_.SendUpdates();
- if (state == MediaState::ENDED) {
- Pause();
- }
- });
-
// TODO(dalesat): Temporary, remove.
if (destination_url == "nowhere") {
// Throwing away the content.
@@ -104,38 +83,21 @@ MediaSinkImpl::MediaSinkImpl(const String& destination_url,
&graph_, &out, &producer_stream_type);
if (!result) {
// Failed to build conversion pipeline.
- producer_state_ = MediaState::FAULT;
- status_publisher_.SendUpdates();
+ LOG(WARNING) << "failed to build conversion pipeline";
+ // TODO(dalesat): Add problem reporting.
return;
}
graph_.ConnectOutputToPart(out, producer_ref);
- if (producer_stream_type->medium() == StreamType::Medium::kAudio) {
- frames_per_ns_ =
- TimelineRate(producer_stream_type->audio()->frames_per_second(),
- Timeline::ns_from_seconds(1));
-
- } else {
- // Unsupported producer stream type.
- LOG(ERROR) << "unsupported producer stream type";
- abort();
- }
-
- controller_->Configure(
- std::move(producer_stream_type),
- [this](MediaConsumerPtr consumer,
- MediaTimelineControlSitePtr timeline_control_site) {
- DCHECK(consumer);
- DCHECK(timeline_control_site);
- timeline_control_site->GetTimelineConsumer(
- GetProxy(&timeline_consumer_));
- producer_->Connect(consumer.Pass(), [this]() {
- graph_.Prepare();
- ready_.Occur();
- MaybeSetRate();
- });
- });
+ controller_->Configure(std::move(producer_stream_type),
+ [this](MediaConsumerPtr consumer) {
+ DCHECK(consumer);
+ producer_->Connect(consumer.Pass(), [this]() {
+ graph_.Prepare();
+ ready_.Occur();
+ });
+ });
});
}
@@ -145,69 +107,13 @@ void MediaSinkImpl::GetConsumer(InterfaceRequest<MediaConsumer> consumer) {
consumer_->AddBinding(consumer.Pass());
}
-void MediaSinkImpl::GetStatus(uint64_t version_last_seen,
- const GetStatusCallback& callback) {
- status_publisher_.Get(version_last_seen, callback);
-}
-
-void MediaSinkImpl::Play() {
- target_rate_ = 1.0;
- MaybeSetRate();
-}
-
-void MediaSinkImpl::Pause() {
- target_rate_ = 0.0;
- MaybeSetRate();
-}
-
-void MediaSinkImpl::MaybeSetRate() {
- if (producer_state_ < MediaState::PAUSED || rate_ == target_rate_) {
- return;
- }
-
- if (!timeline_consumer_) {
- rate_ = target_rate_;
- status_publisher_.SendUpdates();
- return;
+void MediaSinkImpl::GetTimelineControlSite(
+ InterfaceRequest<MediaTimelineControlSite> req) {
+ if (!controller_) {
+ LOG(ERROR) << "GetTimelineControlSite not implemented for 'nowhere' case";
+ abort();
}
-
- // TODO(dalesat): start_local_time and start_presentation_time should be
- // supplied via the mojo interface. For now, start_local_time is hard-coded
- // to be 30ms in the future, and start_presentation_time is grabbed from the
- // first primed packet or is calculated from start_local_time based on the
- // previous timeline function.
-
- // The local time when we want the rate to change.
- int64_t start_local_time = Timeline::local_now() + Timeline::ns_from_ms(30);
-
- // The media time corresponding to start_local_time.
- int64_t start_presentation_time;
- if (flushed_ && producer_->GetFirstPtsSinceFlush() != Packet::kUnknownPts) {
- // We're getting started initially or after a flush/prime, so the media
- // time corresponding to start_local_time should be the PTS of
- // the first packet converted to ns (rather than frame) units.
- start_presentation_time =
- producer_->GetFirstPtsSinceFlush() / frames_per_ns_;
- } else {
- // We're resuming, so the media time corresponding to start_local_time can
- // be calculated using the existing transform.
- start_presentation_time = timeline_function_(start_local_time);
- }
-
- flushed_ = false;
-
- // Update the transform.
- timeline_function_ = TimelineFunction(
- start_local_time, start_presentation_time, TimelineRate(target_rate_));
-
- // Set the rate.
- timeline_consumer_->SetTimelineTransform(
- timeline_function_.subject_time(), timeline_function_.reference_delta(),
- timeline_function_.subject_delta(), timeline_function_.reference_time(),
- kUnspecifiedTime, [](bool completed) {});
-
- rate_ = target_rate_;
- status_publisher_.SendUpdates();
+ controller_->GetTimelineControlSite(req.Pass());
}
} // namespace media

Powered by Google App Engine
This is Rietveld 408576698