| 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/bind_helpers.h" | 6 #include "base/bind_helpers.h" |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/message_loop/message_loop.h" | 8 #include "base/message_loop/message_loop.h" |
| 9 #include "services/media/framework_mojo/mojo_producer.h" | 9 #include "services/media/framework_mojo/mojo_producer.h" |
| 10 | 10 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 22 | 22 |
| 23 void MojoProducer::AddBinding(InterfaceRequest<MediaProducer> producer) { | 23 void MojoProducer::AddBinding(InterfaceRequest<MediaProducer> producer) { |
| 24 bindings_.AddBinding(this, producer.Pass()); | 24 bindings_.AddBinding(this, producer.Pass()); |
| 25 } | 25 } |
| 26 | 26 |
| 27 void MojoProducer::PrimeConnection(const FlushConnectionCallback& callback) { | 27 void MojoProducer::PrimeConnection(const FlushConnectionCallback& callback) { |
| 28 Demand demand; | 28 Demand demand; |
| 29 | 29 |
| 30 { | 30 { |
| 31 base::AutoLock lock(lock_); | 31 base::AutoLock lock(lock_); |
| 32 max_pushes_outstanding_ = 10; // TODO(dalesat): Made up! | 32 max_pushes_outstanding_ = 10; // TODO(dalesat): Made up! |
| 33 demand = current_pushes_outstanding_ < max_pushes_outstanding_ ? | 33 demand = current_pushes_outstanding_ < max_pushes_outstanding_ ? |
| 34 Demand::kPositive : | 34 Demand::kPositive : |
| 35 Demand::kNegative; | 35 Demand::kNegative; |
| 36 } | 36 } |
| 37 | 37 |
| 38 DCHECK(demand_callback_); | 38 DCHECK(demand_callback_); |
| 39 demand_callback_(demand); | 39 demand_callback_(demand); |
| 40 SetState(MediaState::PAUSED); | 40 SetState(MediaState::PAUSED); |
| 41 | 41 |
| 42 DCHECK(consumer_.is_bound()); | 42 DCHECK(consumer_.is_bound()); |
| 43 consumer_->Prime([this, callback]() { | 43 consumer_->Prime([this, callback]() { |
| 44 callback.Run(); | 44 callback.Run(); |
| 45 }); | 45 }); |
| 46 } | 46 } |
| 47 | 47 |
| 48 void MojoProducer::FlushConnection(const FlushConnectionCallback& callback) { | 48 void MojoProducer::FlushConnection(const FlushConnectionCallback& callback) { |
| 49 { | 49 { |
| 50 base::AutoLock lock(lock_); | 50 base::AutoLock lock(lock_); |
| 51 max_pushes_outstanding_ = 0; | 51 max_pushes_outstanding_ = 0; |
| 52 } | 52 } |
| 53 | 53 |
| 54 DCHECK(demand_callback_); | 54 DCHECK(demand_callback_); |
| 55 demand_callback_(Demand::kNegative); | 55 demand_callback_(Demand::kNegative); |
| 56 | 56 |
| 57 DCHECK(consumer_.is_bound()); | 57 DCHECK(consumer_.is_bound()); |
| 58 consumer_->Flush(callback); | 58 consumer_->Flush(callback); |
| 59 first_presentation_time_since_flush_ = Packet::kUnknownPresentationTime; | 59 first_presentation_time_since_flush_ = Packet::kUnknownPresentationTime; |
| 60 end_of_stream_= false; | 60 end_of_stream_ = false; |
| 61 } | 61 } |
| 62 | 62 |
| 63 void MojoProducer::SetStatusCallback( | 63 void MojoProducer::SetStatusCallback( |
| 64 const StatusCallback& callback) { | 64 const StatusCallback& callback) { |
| 65 status_callback_ = callback; | 65 status_callback_ = callback; |
| 66 } | 66 } |
| 67 | 67 |
| 68 int64_t MojoProducer::GetFirstPresentationTimeSinceFlush() { | 68 int64_t MojoProducer::GetFirstPresentationTimeSinceFlush() { |
| 69 return first_presentation_time_since_flush_; | 69 return first_presentation_time_since_flush_; |
| 70 } | 70 } |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 123 } | 123 } |
| 124 | 124 |
| 125 void MojoProducer::Connect( | 125 void MojoProducer::Connect( |
| 126 InterfaceHandle<MediaConsumer> consumer, | 126 InterfaceHandle<MediaConsumer> consumer, |
| 127 const ConnectCallback& callback) { | 127 const ConnectCallback& callback) { |
| 128 DCHECK(consumer); | 128 DCHECK(consumer); |
| 129 | 129 |
| 130 consumer_ = MediaConsumerPtr::Create(std::move(consumer)); | 130 consumer_ = MediaConsumerPtr::Create(std::move(consumer)); |
| 131 | 131 |
| 132 if (!mojo_allocator_.initialized()) { | 132 if (!mojo_allocator_.initialized()) { |
| 133 mojo_allocator_.InitNew(256 * 1024); // TODO(dalesat): Made up! | 133 mojo_allocator_.InitNew(256 * 1024); // TODO(dalesat): Made up! |
| 134 } | 134 } |
| 135 | 135 |
| 136 consumer_->SetBuffer( | 136 consumer_->SetBuffer( |
| 137 mojo_allocator_.GetDuplicateHandle(), | 137 mojo_allocator_.GetDuplicateHandle(), |
| 138 mojo_allocator_.size(), | |
| 139 [callback]() { | 138 [callback]() { |
| 140 callback.Run(); | 139 callback.Run(); |
| 141 }); | 140 }); |
| 142 } | 141 } |
| 143 | 142 |
| 144 void MojoProducer::Disconnect() { | 143 void MojoProducer::Disconnect() { |
| 145 DCHECK(demand_callback_); | 144 DCHECK(demand_callback_); |
| 146 demand_callback_(Demand::kNegative); | 145 demand_callback_(Demand::kNegative); |
| 147 SetState(MediaState::UNPREPARED); | 146 SetState(MediaState::UNPREPARED); |
| 148 consumer_.reset(); | 147 consumer_.reset(); |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 193 | 192 |
| 194 MediaPacketPtr media_packet = MediaPacket::New(); | 193 MediaPacketPtr media_packet = MediaPacket::New(); |
| 195 media_packet->pts = packet->presentation_time(); | 194 media_packet->pts = packet->presentation_time(); |
| 196 media_packet->duration = packet->duration(); | 195 media_packet->duration = packet->duration(); |
| 197 media_packet->end_of_stream = packet->end_of_stream(); | 196 media_packet->end_of_stream = packet->end_of_stream(); |
| 198 media_packet->payload = region.Pass(); | 197 media_packet->payload = region.Pass(); |
| 199 | 198 |
| 200 return media_packet.Pass(); | 199 return media_packet.Pass(); |
| 201 } | 200 } |
| 202 | 201 |
| 203 } // namespace media | 202 } // namespace media |
| 204 } // namespace mojo | 203 } // namespace mojo |
| OLD | NEW |