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

Side by Side Diff: services/media/factory_service/media_sink_impl.cc

Issue 1945903006: Motown: Move responsibility for binding to MediaFactoryService::Product (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Change per feedback - rename Abort to UnbindAndReleaseFromOwner 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 #include "base/logging.h" 5 #include "base/logging.h"
6 #include "mojo/services/media/common/cpp/linear_transform.h" 6 #include "mojo/services/media/common/cpp/linear_transform.h"
7 #include "mojo/services/media/common/cpp/local_time.h" 7 #include "mojo/services/media/common/cpp/local_time.h"
8 #include "services/media/factory_service/media_sink_impl.h" 8 #include "services/media/factory_service/media_sink_impl.h"
9 #include "services/media/framework/util/conversion_pipeline_builder.h" 9 #include "services/media/framework/util/conversion_pipeline_builder.h"
10 #include "services/media/framework_mojo/mojo_type_conversions.h" 10 #include "services/media/framework_mojo/mojo_type_conversions.h"
11 11
12 namespace mojo { 12 namespace mojo {
13 namespace media { 13 namespace media {
14 14
15 // static 15 // static
16 std::shared_ptr<MediaSinkImpl> MediaSinkImpl::Create( 16 std::shared_ptr<MediaSinkImpl> MediaSinkImpl::Create(
17 const String& destination_url, 17 const String& destination_url,
18 MediaTypePtr media_type, 18 MediaTypePtr media_type,
19 InterfaceRequest<MediaSink> request, 19 InterfaceRequest<MediaSink> request,
20 MediaFactoryService* owner) { 20 MediaFactoryService* owner) {
21 return std::shared_ptr<MediaSinkImpl>(new MediaSinkImpl( 21 return std::shared_ptr<MediaSinkImpl>(new MediaSinkImpl(
22 destination_url, media_type.Pass(), request.Pass(), owner)); 22 destination_url, media_type.Pass(), request.Pass(), owner));
23 } 23 }
24 24
25 MediaSinkImpl::MediaSinkImpl(const String& destination_url, 25 MediaSinkImpl::MediaSinkImpl(const String& destination_url,
26 MediaTypePtr media_type, 26 MediaTypePtr media_type,
27 InterfaceRequest<MediaSink> request, 27 InterfaceRequest<MediaSink> request,
28 MediaFactoryService* owner) 28 MediaFactoryService* owner)
29 : MediaFactoryService::Product(owner), 29 : MediaFactoryService::Product<MediaSink>(this, request.Pass(), owner),
30 binding_(this, request.Pass()),
31 consumer_(MojoConsumer::Create()), 30 consumer_(MojoConsumer::Create()),
32 producer_(MojoProducer::Create()) { 31 producer_(MojoProducer::Create()) {
33 DCHECK(destination_url); 32 DCHECK(destination_url);
34 DCHECK(media_type); 33 DCHECK(media_type);
35 34
36 // Go away when the client is no longer connected.
37 binding_.set_connection_error_handler([this]() { ReleaseFromOwner(); });
38
39 status_publisher_.SetCallbackRunner( 35 status_publisher_.SetCallbackRunner(
40 [this](const GetStatusCallback& callback, uint64_t version) { 36 [this](const GetStatusCallback& callback, uint64_t version) {
41 MediaSinkStatusPtr status = MediaSinkStatus::New(); 37 MediaSinkStatusPtr status = MediaSinkStatus::New();
42 status->state = (producer_state_ == MediaState::PAUSED && rate_ != 0.0) 38 status->state = (producer_state_ == MediaState::PAUSED && rate_ != 0.0)
43 ? MediaState::PLAYING 39 ? MediaState::PLAYING
44 : producer_state_; 40 : producer_state_;
45 status->timeline_transform = status_transform_.Clone(); 41 status->timeline_transform = status_transform_.Clone();
46 callback.Run(version, status.Pass()); 42 callback.Run(version, status.Pass());
47 }); 43 });
48 44
(...skipping 27 matching lines...) Expand all
76 72
77 // TODO(dalesat): Temporary, remove. 73 // TODO(dalesat): Temporary, remove.
78 if (destination_url == "nowhere") { 74 if (destination_url == "nowhere") {
79 // Throwing away the content. 75 // Throwing away the content.
80 graph_.ConnectParts(consumer_ref, producer_ref); 76 graph_.ConnectParts(consumer_ref, producer_ref);
81 graph_.Prepare(); 77 graph_.Prepare();
82 ready_.Occur(); 78 ready_.Occur();
83 return; 79 return;
84 } 80 }
85 81
86 if (destination_url != "mojo:audio_server") { 82 RCHECK(destination_url == "mojo:audio_server");
87 LOG(ERROR) << "mojo:audio_server is the only supported destination";
88 if (binding_.is_bound()) {
89 binding_.Close();
90 }
91 return;
92 }
93 83
94 // TODO(dalesat): Once we have c++14, get rid of this shared pointer hack. 84 // TODO(dalesat): Once we have c++14, get rid of this shared pointer hack.
95 std::shared_ptr<StreamType> captured_stream_type( 85 std::shared_ptr<StreamType> captured_stream_type(
96 media_type.To<std::unique_ptr<StreamType>>().release()); 86 media_type.To<std::unique_ptr<StreamType>>().release());
97 87
98 // An AudioTrackController knows how to talk to an audio track, interrogating 88 // An AudioTrackController knows how to talk to an audio track, interrogating
99 // it for supported stream types and configuring it for the chosen stream 89 // it for supported stream types and configuring it for the chosen stream
100 // type. 90 // type.
101 controller_.reset(new AudioTrackController(destination_url, app())); 91 controller_.reset(new AudioTrackController(destination_url, app()));
102 92
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after
263 status_transform_->quad->target_delta = rate_frames_per_tick.denominator; 253 status_transform_->quad->target_delta = rate_frames_per_tick.denominator;
264 LinearTransform::Ratio::Reduce(&status_transform_->quad->reference_delta, 254 LinearTransform::Ratio::Reduce(&status_transform_->quad->reference_delta,
265 &status_transform_->quad->target_delta); 255 &status_transform_->quad->target_delta);
266 256
267 rate_ = target_rate_; 257 rate_ = target_rate_;
268 status_publisher_.SendUpdates(); 258 status_publisher_.SendUpdates();
269 } 259 }
270 260
271 } // namespace media 261 } // namespace media
272 } // namespace mojo 262 } // namespace mojo
OLDNEW
« no previous file with comments | « services/media/factory_service/media_sink_impl.h ('k') | services/media/factory_service/media_source_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698