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

Side by Side Diff: services/media/framework_mojo/mojo_producer.cc

Issue 2006093004: Motown: Convert MediaSink to expose MediaTimelineControlSite (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Created 4 years, 6 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
« no previous file with comments | « services/media/framework_mojo/mojo_producer.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/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 24 matching lines...) Expand all
35 : Demand::kNegative; 35 : Demand::kNegative;
36 } else { 36 } else {
37 demand = Demand::kNeutral; 37 demand = Demand::kNeutral;
38 if (!mojo_allocator_.initialized()) { 38 if (!mojo_allocator_.initialized()) {
39 mojo_allocator_.InitNew(2048 * 1024); // TODO(dalesat): Made up! 39 mojo_allocator_.InitNew(2048 * 1024); // TODO(dalesat): Made up!
40 } 40 }
41 } 41 }
42 42
43 DCHECK(demand_callback_); 43 DCHECK(demand_callback_);
44 demand_callback_(demand); 44 demand_callback_(demand);
45 SetState(MediaState::PAUSED);
46 45
47 if (consumer_.is_bound()) { 46 if (consumer_.is_bound()) {
48 consumer_->Prime([this, callback]() { callback.Run(); }); 47 consumer_->Prime([this, callback]() { callback.Run(); });
49 } else { 48 } else {
50 callback.Run(); 49 callback.Run();
51 } 50 }
52 } 51 }
53 52
54 void MojoProducer::FlushConnection(const FlushConnectionCallback& callback) { 53 void MojoProducer::FlushConnection(const FlushConnectionCallback& callback) {
55 { 54 {
56 base::AutoLock lock(lock_); 55 base::AutoLock lock(lock_);
57 max_pushes_outstanding_ = 0; 56 max_pushes_outstanding_ = 0;
58 } 57 }
59 58
60 DCHECK(demand_callback_); 59 DCHECK(demand_callback_);
61 demand_callback_(Demand::kNegative); 60 demand_callback_(Demand::kNegative);
62 61
63 if (consumer_.is_bound()) { 62 if (consumer_.is_bound()) {
64 consumer_->Flush(callback); 63 consumer_->Flush(callback);
65 } else { 64 } else {
66 callback.Run(); 65 callback.Run();
67 } 66 }
68
69 first_pts_since_flush_ = Packet::kUnknownPts;
70 end_of_stream_ = false;
71 }
72
73 void MojoProducer::SetStatusCallback(const StatusCallback& callback) {
74 status_callback_ = callback;
75 }
76
77 int64_t MojoProducer::GetFirstPtsSinceFlush() {
78 return first_pts_since_flush_;
79 } 67 }
80 68
81 PayloadAllocator* MojoProducer::allocator() { 69 PayloadAllocator* MojoProducer::allocator() {
82 return &mojo_allocator_; 70 return &mojo_allocator_;
83 } 71 }
84 72
85 void MojoProducer::SetDemandCallback(const DemandCallback& demand_callback) { 73 void MojoProducer::SetDemandCallback(const DemandCallback& demand_callback) {
86 demand_callback_ = demand_callback; 74 demand_callback_ = demand_callback;
87 } 75 }
88 76
89 Demand MojoProducer::SupplyPacket(PacketPtr packet) { 77 Demand MojoProducer::SupplyPacket(PacketPtr packet) {
90 DCHECK(packet); 78 DCHECK(packet);
91 79
92 if (first_pts_since_flush_ == Packet::kUnknownPts) {
93 first_pts_since_flush_ = packet->pts();
94 }
95
96 // If we're not connected, throw the packet away. 80 // If we're not connected, throw the packet away.
97 if (!consumer_.is_bound()) { 81 if (!consumer_.is_bound()) {
98 if (packet->end_of_stream()) { 82 if (packet->end_of_stream()) {
99 { 83 base::AutoLock lock(lock_);
kulakowski 2016/05/24 20:27:52 I don't think you need to lock here.
100 base::AutoLock lock(lock_);
101 end_of_stream_ = true;
102 }
103 SetState(MediaState::ENDED);
104 return Demand::kNegative; 84 return Demand::kNegative;
105 } 85 }
106 86
107 return Demand::kNeutral; 87 return Demand::kNeutral;
108 } 88 }
109 89
110 Demand demand; 90 Demand demand;
111 91
112 { 92 {
113 base::AutoLock lock(lock_); 93 base::AutoLock lock(lock_);
114 DCHECK(current_pushes_outstanding_ < max_pushes_outstanding_); 94 DCHECK(current_pushes_outstanding_ < max_pushes_outstanding_);
115 DCHECK(!end_of_stream_) << "packet pushed after end-of-stream";
116 95
117 ++current_pushes_outstanding_; 96 ++current_pushes_outstanding_;
118 97
119 if (packet->end_of_stream()) { 98 if (packet->end_of_stream()) {
120 end_of_stream_ = true;
121 demand = Demand::kNegative; 99 demand = Demand::kNegative;
122 max_pushes_outstanding_ = 0; 100 max_pushes_outstanding_ = 0;
123 } else { 101 } else {
124 demand = current_pushes_outstanding_ < max_pushes_outstanding_ 102 demand = current_pushes_outstanding_ < max_pushes_outstanding_
125 ? Demand::kPositive 103 ? Demand::kPositive
126 : Demand::kNegative; 104 : Demand::kNegative;
127 } 105 }
128 } 106 }
129 107
130 MediaPacketPtr media_packet = CreateMediaPacket(packet); 108 MediaPacketPtr media_packet = CreateMediaPacket(packet);
(...skipping 15 matching lines...) Expand all
146 mojo_allocator_.InitNew(2048 * 1024); // TODO(dalesat): Made up! 124 mojo_allocator_.InitNew(2048 * 1024); // TODO(dalesat): Made up!
147 } 125 }
148 126
149 consumer_->SetBuffer(mojo_allocator_.GetDuplicateHandle(), 127 consumer_->SetBuffer(mojo_allocator_.GetDuplicateHandle(),
150 [callback]() { callback.Run(); }); 128 [callback]() { callback.Run(); });
151 } 129 }
152 130
153 void MojoProducer::Disconnect() { 131 void MojoProducer::Disconnect() {
154 DCHECK(demand_callback_); 132 DCHECK(demand_callback_);
155 demand_callback_(Demand::kNegative); 133 demand_callback_(Demand::kNegative);
156 SetState(MediaState::UNPREPARED);
157 consumer_.reset(); 134 consumer_.reset();
158 } 135 }
159 136
160 void MojoProducer::SendPacket(Packet* packet_raw_ptr, 137 void MojoProducer::SendPacket(Packet* packet_raw_ptr,
161 MediaPacketPtr media_packet) { 138 MediaPacketPtr media_packet) {
162 consumer_->SendPacket( 139 consumer_->SendPacket(
163 media_packet.Pass(), 140 media_packet.Pass(),
164 [this, packet_raw_ptr](MediaConsumer::SendResult send_result) { 141 [this, packet_raw_ptr](MediaConsumer::SendResult send_result) {
165 PacketPtr packet = PacketPtr(packet_raw_ptr); 142 PacketPtr packet = PacketPtr(packet_raw_ptr);
166 Demand demand; 143 Demand demand;
167 144
168 { 145 {
169 base::AutoLock lock(lock_); 146 base::AutoLock lock(lock_);
170 demand = --current_pushes_outstanding_ < max_pushes_outstanding_ 147 demand = --current_pushes_outstanding_ < max_pushes_outstanding_
171 ? Demand::kPositive 148 ? Demand::kPositive
172 : Demand::kNegative; 149 : Demand::kNegative;
173 } 150 }
174 151
175 DCHECK(demand_callback_); 152 DCHECK(demand_callback_);
176 demand_callback_(demand); 153 demand_callback_(demand);
177
178 if (end_of_stream_ && packet->end_of_stream()) {
179 SetState(MediaState::ENDED);
180 }
181 }); 154 });
182 } 155 }
183 156
184 void MojoProducer::SetState(MediaState state) {
185 if (state_ != state) {
186 state_ = state;
187 if (status_callback_) {
188 status_callback_(state_);
189 }
190 }
191 }
192
193 MediaPacketPtr MojoProducer::CreateMediaPacket(const PacketPtr& packet) { 157 MediaPacketPtr MojoProducer::CreateMediaPacket(const PacketPtr& packet) {
194 DCHECK(packet); 158 DCHECK(packet);
195 159
196 MediaPacketRegionPtr region = MediaPacketRegion::New(); 160 MediaPacketRegionPtr region = MediaPacketRegion::New();
197 region->offset = packet->size() == 0 161 region->offset = packet->size() == 0
198 ? 0 162 ? 0
199 : mojo_allocator_.OffsetFromPtr(packet->payload()); 163 : mojo_allocator_.OffsetFromPtr(packet->payload());
200 region->length = packet->size(); 164 region->length = packet->size();
201 165
202 MediaPacketPtr media_packet = MediaPacket::New(); 166 MediaPacketPtr media_packet = MediaPacket::New();
203 media_packet->pts = packet->pts(); 167 media_packet->pts = packet->pts();
204 media_packet->end_of_stream = packet->end_of_stream(); 168 media_packet->end_of_stream = packet->end_of_stream();
205 media_packet->payload = region.Pass(); 169 media_packet->payload = region.Pass();
206 170
207 return media_packet.Pass(); 171 return media_packet.Pass();
208 } 172 }
209 173
210 } // namespace media 174 } // namespace media
211 } // namespace mojo 175 } // namespace mojo
OLDNEW
« no previous file with comments | « services/media/framework_mojo/mojo_producer.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698