| 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 <algorithm> | 5 #include <algorithm> |
| 6 #include <limits> | 6 #include <limits> |
| 7 | 7 |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "mojo/services/media/common/cpp/linear_transform.h" | 9 #include "mojo/services/media/common/cpp/linear_transform.h" |
| 10 #include "services/media/audio/audio_output_manager.h" | 10 #include "services/media/audio/audio_output_manager.h" |
| (...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 218 bytes_per_frame_ = 4; | 218 bytes_per_frame_ = 4; |
| 219 break; | 219 break; |
| 220 | 220 |
| 221 default: | 221 default: |
| 222 DCHECK(false); | 222 DCHECK(false); |
| 223 bytes_per_frame_ = 2; | 223 bytes_per_frame_ = 2; |
| 224 break; | 224 break; |
| 225 } | 225 } |
| 226 bytes_per_frame_ *= cfg->channels; | 226 bytes_per_frame_ *= cfg->channels; |
| 227 | 227 |
| 228 // Overflow trying to convert from frames to bytes? | 228 // Bind our pipe to the interface request. |
| 229 uint64_t requested_frames = configuration->max_frames; | 229 if (pipe_.Init(req.Pass()) != MOJO_RESULT_OK) { |
| 230 if (requested_frames > | 230 LOG(ERROR) << "Failed to media pipe to interface request."; |
| 231 (std::numeric_limits<size_t>::max() / bytes_per_frame_)) { | |
| 232 LOG(ERROR) << "Insufficient resources to create " | |
| 233 << requested_frames << " frame audio buffer."; | |
| 234 Shutdown(); | 231 Shutdown(); |
| 235 return; | 232 return; |
| 236 } | 233 } |
| 237 | |
| 238 size_t requested_bytes = (requested_frames * bytes_per_frame_); | |
| 239 | |
| 240 // Attempt to initialize our shared buffer and bind it to our interface | |
| 241 // request. | |
| 242 if (pipe_.Init(req.Pass(), requested_bytes) != MOJO_RESULT_OK) { | |
| 243 LOG(ERROR) << "Insufficient resources to create " | |
| 244 << requested_frames << " frame audio buffer."; | |
| 245 Shutdown(); | |
| 246 return; | |
| 247 } | |
| 248 | 234 |
| 249 // Stash our configuration. | 235 // Stash our configuration. |
| 250 format_ = cfg.Pass(); | 236 format_ = cfg.Pass(); |
| 251 | 237 |
| 252 // Have the audio output manager initialize our set of outputs. Note; there | 238 // Have the audio output manager initialize our set of outputs. Note; there |
| 253 // is currently no need for a lock here. Methods called from our user-facing | 239 // is currently no need for a lock here. Methods called from our user-facing |
| 254 // interfaces are seriailzed by nature of the mojo framework, and none of the | 240 // interfaces are seriailzed by nature of the mojo framework, and none of the |
| 255 // output manager's threads should ever need to manipulate the set. Cleanup | 241 // output manager's threads should ever need to manipulate the set. Cleanup |
| 256 // of outputs which have gone away is currently handled in a lazy fashion when | 242 // of outputs which have gone away is currently handled in a lazy fashion when |
| 257 // the track fails to promote its weak reference during an operation involving | 243 // the track fails to promote its weak reference during an operation involving |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 327 DCHECK(output); | 313 DCHECK(output); |
| 328 output->FlushPendingQueue(); | 314 output->FlushPendingQueue(); |
| 329 } | 315 } |
| 330 cbk.Run(); | 316 cbk.Run(); |
| 331 return true; | 317 return true; |
| 332 } | 318 } |
| 333 | 319 |
| 334 } // namespace audio | 320 } // namespace audio |
| 335 } // namespace media | 321 } // namespace media |
| 336 } // namespace mojo | 322 } // namespace mojo |
| OLD | NEW |