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

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

Issue 1823833003: Take advantage of MojoGetBufferInformation (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: rebase and fix a type mismatch which the android build caught Created 4 years, 9 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/common/media_pipe_base.h ('k') | services/media/framework_mojo/mojo_consumer.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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
(...skipping 22 matching lines...) Expand all
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 uint64_t size,
44 const SetBufferCallback& cbk) { 43 const SetBufferCallback& cbk) {
44 DCHECK(handle.is_valid());
45
45 // Double init? Close the connection. 46 // Double init? Close the connection.
46 if (buffer_) { 47 if (buffer_) {
47 LOG(ERROR) << "Attempting to set a new buffer (size = " 48 LOG(ERROR) << "Attempting to set a new buffer on a MediaConsumer which "
48 << size 49 "already has a buffer assigned. (size = "
49 << ") on a MediaConsumer which already has a buffer (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
57 // connection.
58 MojoResult res;
59 MojoBufferInformation info;
60 res = MojoGetBufferInformation(handle.get().value(), &info, sizeof(info));
61 if (res != MOJO_RESULT_OK) {
62 LOG(ERROR) << "Failed to query shared buffer info (res = " << res << ")";
63 Reset();
64 return;
65 }
66
56 // Invalid size? Close the connection. 67 // Invalid size? Close the connection.
68 uint64_t size = info.num_bytes;
57 if (!size || (size > MediaConsumer::kMaxBufferLen)) { 69 if (!size || (size > MediaConsumer::kMaxBufferLen)) {
58 LOG(ERROR) << "Invalid shared buffer size (size = " << size << ")"; 70 LOG(ERROR) << "Invalid shared buffer size (size = " << size << ")";
59 Reset(); 71 Reset();
60 return; 72 return;
61 } 73 }
62 74
63
64 // Failed to map the buffer? Close the connection. 75 // Failed to map the buffer? Close the connection.
65 buffer_ = MappedSharedBuffer::Create(handle.Pass(), size); 76 buffer_ = MappedSharedBuffer::Create(handle.Pass(), size);
66 if (!buffer_) { 77 if (!buffer_) {
67 LOG(ERROR) << "Failed to map shared memory buffer (size = " << size << ")"; 78 LOG(ERROR) << "Failed to map shared memory buffer (size = " << size << ")";
68 Reset(); 79 Reset();
69 return; 80 return;
70 } 81 }
71 82
72 cbk.Run(); 83 cbk.Run();
73 } 84 }
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
176 187
177 MediaPipeBase::MappedSharedBuffer::~MappedSharedBuffer() { 188 MediaPipeBase::MappedSharedBuffer::~MappedSharedBuffer() {
178 if (nullptr != base_) { 189 if (nullptr != base_) {
179 MojoResult res = UnmapBuffer(base_); 190 MojoResult res = UnmapBuffer(base_);
180 CHECK(res == MOJO_RESULT_OK); 191 CHECK(res == MOJO_RESULT_OK);
181 } 192 }
182 } 193 }
183 194
184 MediaPipeBase::MappedSharedBuffer::MappedSharedBuffer( 195 MediaPipeBase::MappedSharedBuffer::MappedSharedBuffer(
185 ScopedSharedBufferHandle handle, 196 ScopedSharedBufferHandle handle,
186 size_t size) 197 uint64_t size)
187 : handle_(handle.Pass()), 198 : handle_(handle.Pass()),
188 size_(size) { 199 size_(size) {
189 MojoResult res = MapBuffer(handle_.get(), 200 MojoResult res = MapBuffer(handle_.get(),
190 0u, 201 0u,
191 size_, 202 size_,
192 &base_, 203 &base_,
193 MOJO_MAP_BUFFER_FLAG_NONE); 204 MOJO_MAP_BUFFER_FLAG_NONE);
194 205
195 if (MOJO_RESULT_OK != res) { 206 if (MOJO_RESULT_OK != res) {
196 LOG(ERROR) << "Failed to map shared buffer of size " << size_ 207 LOG(ERROR) << "Failed to map shared buffer of size " << size_
197 << " (res " << res << ")"; 208 << " (res " << res << ")";
198 DCHECK(base_ == nullptr); 209 DCHECK(base_ == nullptr);
199 handle_.reset(); 210 handle_.reset();
200 } 211 }
201 } 212 }
202 213
203 } // namespace media 214 } // namespace media
204 } // namespace mojo 215 } // namespace mojo
OLDNEW
« no previous file with comments | « services/media/common/media_pipe_base.h ('k') | services/media/framework_mojo/mojo_consumer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698