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_pts_since_flush_ = Packet::kUnknownPts; | 59 first_pts_since_flush_ = Packet::kUnknownPts; |
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::GetFirstPtsSinceFlush() { | 68 int64_t MojoProducer::GetFirstPtsSinceFlush() { |
69 return first_pts_since_flush_; | 69 return first_pts_since_flush_; |
70 } | 70 } |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
122 } | 122 } |
123 | 123 |
124 void MojoProducer::Connect( | 124 void MojoProducer::Connect( |
125 InterfaceHandle<MediaConsumer> consumer, | 125 InterfaceHandle<MediaConsumer> consumer, |
126 const ConnectCallback& callback) { | 126 const ConnectCallback& callback) { |
127 DCHECK(consumer); | 127 DCHECK(consumer); |
128 | 128 |
129 consumer_ = MediaConsumerPtr::Create(std::move(consumer)); | 129 consumer_ = MediaConsumerPtr::Create(std::move(consumer)); |
130 | 130 |
131 if (!mojo_allocator_.initialized()) { | 131 if (!mojo_allocator_.initialized()) { |
132 mojo_allocator_.InitNew(256 * 1024); // TODO(dalesat): Made up! | 132 mojo_allocator_.InitNew(256 * 1024); // TODO(dalesat): Made up! |
133 } | 133 } |
134 | 134 |
135 consumer_->SetBuffer( | 135 consumer_->SetBuffer( |
136 mojo_allocator_.GetDuplicateHandle(), | 136 mojo_allocator_.GetDuplicateHandle(), |
137 mojo_allocator_.size(), | |
138 [callback]() { | 137 [callback]() { |
139 callback.Run(); | 138 callback.Run(); |
140 }); | 139 }); |
141 } | 140 } |
142 | 141 |
143 void MojoProducer::Disconnect() { | 142 void MojoProducer::Disconnect() { |
144 DCHECK(demand_callback_); | 143 DCHECK(demand_callback_); |
145 demand_callback_(Demand::kNegative); | 144 demand_callback_(Demand::kNegative); |
146 SetState(MediaState::UNPREPARED); | 145 SetState(MediaState::UNPREPARED); |
147 consumer_.reset(); | 146 consumer_.reset(); |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
191 region->length = packet->size(); | 190 region->length = packet->size(); |
192 | 191 |
193 MediaPacketPtr media_packet = MediaPacket::New(); | 192 MediaPacketPtr media_packet = MediaPacket::New(); |
194 media_packet->pts = packet->pts(); | 193 media_packet->pts = packet->pts(); |
195 media_packet->end_of_stream = packet->end_of_stream(); | 194 media_packet->end_of_stream = packet->end_of_stream(); |
196 media_packet->payload = region.Pass(); | 195 media_packet->payload = region.Pass(); |
197 | 196 |
198 return media_packet.Pass(); | 197 return media_packet.Pass(); |
199 } | 198 } |
200 | 199 |
201 } // namespace media | 200 } // namespace media |
202 } // namespace mojo | 201 } // namespace mojo |
OLD | NEW |