Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 Loading... | |
| 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 struct MojoBufferInformation info; | |
|
viettrungluu
2016/03/22 17:58:58
Up to you, but in most of our C++ code, we omit th
johngro
2016/03/22 18:16:40
Done.
| |
| 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 } | |
|
viettrungluu
2016/03/22 17:58:58
|return;|?
johngro
2016/03/22 18:16:40
good catch!
| |
| 65 | |
| 56 // Invalid size? Close the connection. | 66 // Invalid size? Close the connection. |
| 67 uint64_t size = info.num_bytes; | |
| 57 if (!size || (size > MediaConsumer::kMaxBufferLen)) { | 68 if (!size || (size > MediaConsumer::kMaxBufferLen)) { |
| 58 LOG(ERROR) << "Invalid shared buffer size (size = " << size << ")"; | 69 LOG(ERROR) << "Invalid shared buffer size (size = " << size << ")"; |
| 59 Reset(); | 70 Reset(); |
| 60 return; | 71 return; |
| 61 } | 72 } |
| 62 | 73 |
| 63 | |
| 64 // Failed to map the buffer? Close the connection. | 74 // Failed to map the buffer? Close the connection. |
| 65 buffer_ = MappedSharedBuffer::Create(handle.Pass(), size); | 75 buffer_ = MappedSharedBuffer::Create(handle.Pass(), size); |
| 66 if (!buffer_) { | 76 if (!buffer_) { |
| 67 LOG(ERROR) << "Failed to map shared memory buffer (size = " << size << ")"; | 77 LOG(ERROR) << "Failed to map shared memory buffer (size = " << size << ")"; |
| 68 Reset(); | 78 Reset(); |
| 69 return; | 79 return; |
| 70 } | 80 } |
| 71 | 81 |
| 72 cbk.Run(); | 82 cbk.Run(); |
| 73 } | 83 } |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 195 if (MOJO_RESULT_OK != res) { | 205 if (MOJO_RESULT_OK != res) { |
| 196 LOG(ERROR) << "Failed to map shared buffer of size " << size_ | 206 LOG(ERROR) << "Failed to map shared buffer of size " << size_ |
| 197 << " (res " << res << ")"; | 207 << " (res " << res << ")"; |
| 198 DCHECK(base_ == nullptr); | 208 DCHECK(base_ == nullptr); |
| 199 handle_.reset(); | 209 handle_.reset(); |
| 200 } | 210 } |
| 201 } | 211 } |
| 202 | 212 |
| 203 } // namespace media | 213 } // namespace media |
| 204 } // namespace mojo | 214 } // namespace mojo |
| OLD | NEW |