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

Side by Side Diff: services/media/common/media_pipe_base.cc

Issue 2097953002: Motown: Rename MediaProducer/Consumer to MediaPacketProducer/Consumer (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Renamed MojoConsumer and MojoProducer Created 4 years, 5 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 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 "services/media/common/media_pipe_base.h" 6 #include "services/media/common/media_pipe_base.h"
7 7
8 namespace mojo { 8 namespace mojo {
9 namespace media { 9 namespace media {
10 10
11 MediaPipeBase::MediaPipeBase() 11 MediaPipeBase::MediaPipeBase()
12 : binding_(this) { 12 : binding_(this) {
13 } 13 }
14 14
15 MediaPipeBase::~MediaPipeBase() { 15 MediaPipeBase::~MediaPipeBase() {
16 } 16 }
17 17
18 MojoResult MediaPipeBase::Init(InterfaceRequest<MediaConsumer> request) { 18 MojoResult MediaPipeBase::Init(InterfaceRequest<MediaPacketConsumer> request) {
19 // Double init? 19 // Double init?
20 if (IsInitialized()) { 20 if (IsInitialized()) {
21 return MOJO_RESULT_ALREADY_EXISTS; 21 return MOJO_RESULT_ALREADY_EXISTS;
22 } 22 }
23 23
24 binding_.Bind(request.Pass()); 24 binding_.Bind(request.Pass());
25 binding_.set_connection_error_handler([this]() -> void { 25 binding_.set_connection_error_handler([this]() -> void {
26 Reset(); 26 Reset();
27 }); 27 });
28 return MOJO_RESULT_OK; 28 return MOJO_RESULT_OK;
29 } 29 }
30 30
31 bool MediaPipeBase::IsInitialized() const { 31 bool MediaPipeBase::IsInitialized() const {
32 return binding_.is_bound(); 32 return binding_.is_bound();
33 } 33 }
34 34
35 void MediaPipeBase::Reset() { 35 void MediaPipeBase::Reset() {
36 if (binding_.is_bound()) { 36 if (binding_.is_bound()) {
37 binding_.Close(); 37 binding_.Close();
38 } 38 }
39 buffer_ = nullptr; 39 buffer_ = nullptr;
40 } 40 }
41 41
42 void MediaPipeBase::SetBuffer(ScopedSharedBufferHandle handle, 42 void MediaPipeBase::SetBuffer(ScopedSharedBufferHandle handle,
43 const SetBufferCallback& cbk) { 43 const SetBufferCallback& cbk) {
44 DCHECK(handle.is_valid()); 44 DCHECK(handle.is_valid());
45 45
46 // Double init? Close the connection. 46 // Double init? Close the connection.
47 if (buffer_) { 47 if (buffer_) {
48 LOG(ERROR) << "Attempting to set a new buffer on a MediaConsumer which " 48 LOG(ERROR) << "Attempting to set a new buffer on a MediaPacketConsumer "
49 "already has a buffer assigned. (size = " 49 "which already has a buffer assigned. (size = "
50 << buffer_->size() 50 << buffer_->size()
51 << ")"; 51 << ")";
52 Reset(); 52 Reset();
53 return; 53 return;
54 } 54 }
55 55
56 // Query the buffer for its size. If we fail to query the info, close the 56 // Query the buffer for its size. If we fail to query the info, close the
57 // connection. 57 // connection.
58 MojoResult res; 58 MojoResult res;
59 MojoBufferInformation info; 59 MojoBufferInformation info;
60 res = MojoGetBufferInformation(handle.get().value(), &info, sizeof(info)); 60 res = MojoGetBufferInformation(handle.get().value(), &info, sizeof(info));
61 if (res != MOJO_RESULT_OK) { 61 if (res != MOJO_RESULT_OK) {
62 LOG(ERROR) << "Failed to query shared buffer info (res = " << res << ")"; 62 LOG(ERROR) << "Failed to query shared buffer info (res = " << res << ")";
63 Reset(); 63 Reset();
64 return; 64 return;
65 } 65 }
66 66
67 // Invalid size? Close the connection. 67 // Invalid size? Close the connection.
68 uint64_t size = info.num_bytes; 68 uint64_t size = info.num_bytes;
69 if (!size || (size > MediaConsumer::kMaxBufferLen)) { 69 if (!size || (size > MediaPacketConsumer::kMaxBufferLen)) {
70 LOG(ERROR) << "Invalid shared buffer size (size = " << size << ")"; 70 LOG(ERROR) << "Invalid shared buffer size (size = " << size << ")";
71 Reset(); 71 Reset();
72 return; 72 return;
73 } 73 }
74 74
75 // Failed to map the buffer? Close the connection. 75 // Failed to map the buffer? Close the connection.
76 buffer_ = MappedSharedBuffer::Create(handle.Pass(), size); 76 buffer_ = MappedSharedBuffer::Create(handle.Pass(), size);
77 if (!buffer_) { 77 if (!buffer_) {
78 LOG(ERROR) << "Failed to map shared memory buffer (size = " << size << ")"; 78 LOG(ERROR) << "Failed to map shared memory buffer (size = " << size << ")";
79 Reset(); 79 Reset();
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
156 } 156 }
157 } 157 }
158 158
159 MediaPipeBase::MediaPacketState::MediaPacketState( 159 MediaPipeBase::MediaPacketState::MediaPacketState(
160 MediaPacketPtr packet, 160 MediaPacketPtr packet,
161 const MappedSharedBufferPtr& buffer, 161 const MappedSharedBufferPtr& buffer,
162 const SendPacketCallback& cbk) 162 const SendPacketCallback& cbk)
163 : packet_(packet.Pass()), 163 : packet_(packet.Pass()),
164 buffer_(buffer), 164 buffer_(buffer),
165 cbk_(cbk), 165 cbk_(cbk),
166 result_(MediaConsumer::SendResult::CONSUMED) { 166 result_(MediaPacketConsumer::SendResult::CONSUMED) {
167 DCHECK(packet_); 167 DCHECK(packet_);
168 DCHECK(packet_->payload); 168 DCHECK(packet_->payload);
169 } 169 }
170 170
171 MediaPipeBase::MediaPacketState::~MediaPacketState() { 171 MediaPipeBase::MediaPacketState::~MediaPacketState() {
172 cbk_.Run(result_); 172 cbk_.Run(result_);
173 } 173 }
174 174
175 void MediaPipeBase::MediaPacketState::SetResult( 175 void MediaPipeBase::MediaPacketState::SetResult(
176 MediaConsumer::SendResult result) { 176 MediaPacketConsumer::SendResult result) {
177 MediaConsumer::SendResult tmp = MediaConsumer::SendResult::CONSUMED; 177 MediaPacketConsumer::SendResult tmp =
178 MediaPacketConsumer::SendResult::CONSUMED;
178 result_.compare_exchange_strong(tmp, result); 179 result_.compare_exchange_strong(tmp, result);
179 } 180 }
180 181
181 MediaPipeBase::MappedSharedBufferPtr MediaPipeBase::MappedSharedBuffer::Create( 182 MediaPipeBase::MappedSharedBufferPtr MediaPipeBase::MappedSharedBuffer::Create(
182 ScopedSharedBufferHandle handle, 183 ScopedSharedBufferHandle handle,
183 uint64_t size) { 184 uint64_t size) {
184 MappedSharedBufferPtr ret(new MappedSharedBuffer(handle.Pass(), size)); 185 MappedSharedBufferPtr ret(new MappedSharedBuffer(handle.Pass(), size));
185 return ret->base() ? ret : nullptr; 186 return ret->base() ? ret : nullptr;
186 } 187 }
187 188
(...skipping 18 matching lines...) Expand all
206 if (MOJO_RESULT_OK != res) { 207 if (MOJO_RESULT_OK != res) {
207 LOG(ERROR) << "Failed to map shared buffer of size " << size_ 208 LOG(ERROR) << "Failed to map shared buffer of size " << size_
208 << " (res " << res << ")"; 209 << " (res " << res << ")";
209 DCHECK(base_ == nullptr); 210 DCHECK(base_ == nullptr);
210 handle_.reset(); 211 handle_.reset();
211 } 212 }
212 } 213 }
213 214
214 } // namespace media 215 } // namespace media
215 } // namespace mojo 216 } // namespace mojo
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698