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

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

Issue 1923763002: Motown: Ffmpeg video decoder (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 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/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
11 namespace mojo { 11 namespace mojo {
12 namespace media { 12 namespace media {
13 13
14 MojoProducer::MojoProducer() { 14 MojoProducer::MojoProducer() {
15 task_runner_ = base::MessageLoop::current()->task_runner(); 15 task_runner_ = base::MessageLoop::current()->task_runner();
16 DCHECK(task_runner_); 16 DCHECK(task_runner_);
17 } 17 }
18 18
19 MojoProducer::~MojoProducer() { 19 MojoProducer::~MojoProducer() {
20 base::AutoLock lock(lock_); 20 base::AutoLock lock(lock_);
21 } 21 }
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 PrimeConnectionCallback& callback) {
28 Demand demand; 28 Demand demand;
29 29
30 if (consumer_.is_bound()) { 30 if (consumer_.is_bound()) {
31 base::AutoLock lock(lock_); 31 base::AutoLock lock(lock_);
32 max_pushes_outstanding_ = 10; // TODO(dalesat): Made up! 32 max_pushes_outstanding_ = 3; // 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 } 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(256 * 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); 45 SetState(MediaState::PAUSED);
46 46
47 if (consumer_.is_bound()) { 47 if (consumer_.is_bound()) {
48 consumer_->Prime([this, callback]() { callback.Run(); }); 48 consumer_->Prime([this, callback]() { callback.Run(); });
49 } else { 49 } else {
50 callback.Run(); 50 callback.Run();
51 } 51 }
52 } 52 }
53 53
54 void MojoProducer::FlushConnection(const FlushConnectionCallback& callback) { 54 void MojoProducer::FlushConnection(const FlushConnectionCallback& callback) {
55 { 55 {
56 base::AutoLock lock(lock_); 56 base::AutoLock lock(lock_);
57 max_pushes_outstanding_ = 0; 57 max_pushes_outstanding_ = 0;
58 } 58 }
59 59
60 DCHECK(demand_callback_); 60 DCHECK(demand_callback_);
61 demand_callback_(Demand::kNegative); 61 demand_callback_(Demand::kNegative);
62 62
63 DCHECK(consumer_.is_bound()); 63 if (consumer_.is_bound()) {
64 consumer_->Flush(callback); 64 consumer_->Flush(callback);
65 } else {
66 callback.Run();
67 }
68
65 first_pts_since_flush_ = Packet::kUnknownPts; 69 first_pts_since_flush_ = Packet::kUnknownPts;
66 end_of_stream_ = false; 70 end_of_stream_ = false;
67 } 71 }
68 72
69 void MojoProducer::SetStatusCallback(const StatusCallback& callback) { 73 void MojoProducer::SetStatusCallback(const StatusCallback& callback) {
70 status_callback_ = callback; 74 status_callback_ = callback;
71 } 75 }
72 76
73 int64_t MojoProducer::GetFirstPtsSinceFlush() { 77 int64_t MojoProducer::GetFirstPtsSinceFlush() {
74 return first_pts_since_flush_; 78 return first_pts_since_flush_;
75 } 79 }
76 80
77 PayloadAllocator* MojoProducer::allocator() { 81 PayloadAllocator* MojoProducer::allocator() {
78 return &mojo_allocator_; 82 return &mojo_allocator_;
79 } 83 }
80 84
81 void MojoProducer::SetDemandCallback(const DemandCallback& demand_callback) { 85 void MojoProducer::SetDemandCallback(const DemandCallback& demand_callback) {
82 demand_callback_ = demand_callback; 86 demand_callback_ = demand_callback;
83 } 87 }
84 88
85 Demand MojoProducer::SupplyPacket(PacketPtr packet) { 89 Demand MojoProducer::SupplyPacket(PacketPtr packet) {
86 DCHECK(packet); 90 DCHECK(packet);
87 91
88 if (first_pts_since_flush_ == Packet::kUnknownPts) { 92 if (first_pts_since_flush_ == Packet::kUnknownPts) {
89 first_pts_since_flush_ = packet->pts(); 93 first_pts_since_flush_ = packet->pts();
90 } 94 }
91 95
92 // If we're no longer connected, throw the packet away. 96 // If we're not connected, throw the packet away.
93 if (!consumer_.is_bound()) { 97 if (!consumer_.is_bound()) {
98 if (packet->end_of_stream()) {
99 {
100 base::AutoLock lock(lock_);
101 end_of_stream_ = true;
102 }
103 SetState(MediaState::ENDED);
104 return Demand::kNegative;
105 }
106
94 return Demand::kNeutral; 107 return Demand::kNeutral;
95 } 108 }
96 109
97 Demand demand; 110 Demand demand;
98 111
99 { 112 {
100 base::AutoLock lock(lock_); 113 base::AutoLock lock(lock_);
101 DCHECK(current_pushes_outstanding_ < max_pushes_outstanding_); 114 DCHECK(current_pushes_outstanding_ < max_pushes_outstanding_);
102 DCHECK(!end_of_stream_) << "packet pushed after end-of-stream"; 115 DCHECK(!end_of_stream_) << "packet pushed after end-of-stream";
103 116
(...skipping 19 matching lines...) Expand all
123 return demand; 136 return demand;
124 } 137 }
125 138
126 void MojoProducer::Connect(InterfaceHandle<MediaConsumer> consumer, 139 void MojoProducer::Connect(InterfaceHandle<MediaConsumer> consumer,
127 const ConnectCallback& callback) { 140 const ConnectCallback& callback) {
128 DCHECK(consumer); 141 DCHECK(consumer);
129 142
130 consumer_ = MediaConsumerPtr::Create(std::move(consumer)); 143 consumer_ = MediaConsumerPtr::Create(std::move(consumer));
131 144
132 if (!mojo_allocator_.initialized()) { 145 if (!mojo_allocator_.initialized()) {
133 mojo_allocator_.InitNew(256 * 1024); // TODO(dalesat): Made up! 146 mojo_allocator_.InitNew(2048 * 1024); // TODO(dalesat): Made up!
134 } 147 }
135 148
136 consumer_->SetBuffer(mojo_allocator_.GetDuplicateHandle(), 149 consumer_->SetBuffer(mojo_allocator_.GetDuplicateHandle(),
137 [callback]() { callback.Run(); }); 150 [callback]() { callback.Run(); });
138 } 151 }
139 152
140 void MojoProducer::Disconnect() { 153 void MojoProducer::Disconnect() {
141 DCHECK(demand_callback_); 154 DCHECK(demand_callback_);
142 demand_callback_(Demand::kNegative); 155 demand_callback_(Demand::kNegative);
143 SetState(MediaState::UNPREPARED); 156 SetState(MediaState::UNPREPARED);
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
189 MediaPacketPtr media_packet = MediaPacket::New(); 202 MediaPacketPtr media_packet = MediaPacket::New();
190 media_packet->pts = packet->pts(); 203 media_packet->pts = packet->pts();
191 media_packet->end_of_stream = packet->end_of_stream(); 204 media_packet->end_of_stream = packet->end_of_stream();
192 media_packet->payload = region.Pass(); 205 media_packet->payload = region.Pass();
193 206
194 return media_packet.Pass(); 207 return media_packet.Pass();
195 } 208 }
196 209
197 } // namespace media 210 } // namespace media
198 } // namespace mojo 211 } // namespace mojo
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698