| OLD | NEW |
| 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/logging.h" | 5 #include "base/logging.h" |
| 6 #include "services/media/framework/parts/lpcm_reformatter.h" | 6 #include "services/media/framework/parts/lpcm_reformatter.h" |
| 7 | 7 |
| 8 namespace mojo { | 8 namespace mojo { |
| 9 namespace media { | 9 namespace media { |
| 10 | 10 |
| (...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 242 PayloadAllocator* allocator, | 242 PayloadAllocator* allocator, |
| 243 PacketPtr* output) { | 243 PacketPtr* output) { |
| 244 DCHECK(input); | 244 DCHECK(input); |
| 245 DCHECK(allocator); | 245 DCHECK(allocator); |
| 246 DCHECK(output); | 246 DCHECK(output); |
| 247 | 247 |
| 248 uint64_t in_size = input->size(); | 248 uint64_t in_size = input->size(); |
| 249 if (in_size == 0) { | 249 if (in_size == 0) { |
| 250 // Zero-sized input packet. Make a copy. | 250 // Zero-sized input packet. Make a copy. |
| 251 *output = Packet::Create( | 251 *output = Packet::Create( |
| 252 input->presentation_time(), | 252 input->pts(), |
| 253 input->duration(), | |
| 254 input->end_of_stream(), | 253 input->end_of_stream(), |
| 255 0, | 254 0, |
| 256 nullptr, | 255 nullptr, |
| 257 nullptr); | 256 nullptr); |
| 258 return true; | 257 return true; |
| 259 } | 258 } |
| 260 | 259 |
| 261 size_t frame_count = input->duration(); | 260 size_t frame_count = in_type_.frame_count(in_size); |
| 262 uint64_t out_size = out_type_.min_buffer_size(frame_count); | 261 uint64_t out_size = out_type_.min_buffer_size(frame_count); |
| 263 | 262 |
| 264 void* buffer = allocator->AllocatePayloadBuffer(out_size); | 263 void* buffer = allocator->AllocatePayloadBuffer(out_size); |
| 265 if (buffer == nullptr) { | 264 if (buffer == nullptr) { |
| 266 LOG(WARNING) << "lpcm reformatter starved for buffers"; | 265 LOG(WARNING) << "lpcm reformatter starved for buffers"; |
| 267 // Starved for buffer space. Can't process now. | 266 // Starved for buffer space. Can't process now. |
| 268 *output = nullptr; | 267 *output = nullptr; |
| 269 return false; | 268 return false; |
| 270 } | 269 } |
| 271 | 270 |
| 272 const TIn* in_channel = static_cast<const TIn*>(input->payload()); | 271 const TIn* in_channel = static_cast<const TIn*>(input->payload()); |
| 273 TOut* out_channel = static_cast<TOut*>(buffer); | 272 TOut* out_channel = static_cast<TOut*>(buffer); |
| 274 | 273 |
| 275 for (uint32_t channel = 0; channel < in_type_.channels(); channel++) { | 274 for (uint32_t channel = 0; channel < in_type_.channels(); channel++) { |
| 276 const TIn* in_sample = in_channel; | 275 const TIn* in_sample = in_channel; |
| 277 TOut* out_sample = out_channel; | 276 TOut* out_sample = out_channel; |
| 278 for (size_t sample = 0; sample < frame_count; sample++) { | 277 for (size_t sample = 0; sample < frame_count; sample++) { |
| 279 CopySample(out_sample, in_sample); | 278 CopySample(out_sample, in_sample); |
| 280 in_sample += in_type_.channels(); | 279 in_sample += in_type_.channels(); |
| 281 out_sample += out_type_.channels(); | 280 out_sample += out_type_.channels(); |
| 282 } | 281 } |
| 283 ++in_channel; | 282 ++in_channel; |
| 284 ++out_channel; | 283 ++out_channel; |
| 285 } | 284 } |
| 286 | 285 |
| 287 *output = Packet::Create( | 286 *output = Packet::Create( |
| 288 input->presentation_time(), | 287 input->pts(), |
| 289 frame_count, | |
| 290 input->end_of_stream(), | 288 input->end_of_stream(), |
| 291 out_size, | 289 out_size, |
| 292 buffer, | 290 buffer, |
| 293 allocator); | 291 allocator); |
| 294 | 292 |
| 295 return true; | 293 return true; |
| 296 } | 294 } |
| 297 | 295 |
| 298 } // namespace media | 296 } // namespace media |
| 299 } // namespace mojo | 297 } // namespace mojo |
| OLD | NEW |