OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "media/mojo/common/media_type_converters.h" | 5 #include "media/mojo/common/media_type_converters.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include "base/memory/ptr_util.h" | 10 #include "base/memory/ptr_util.h" |
(...skipping 293 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
304 return buffer; | 304 return buffer; |
305 } | 305 } |
306 | 306 |
307 // static | 307 // static |
308 scoped_refptr<media::AudioBuffer> | 308 scoped_refptr<media::AudioBuffer> |
309 TypeConverter<scoped_refptr<media::AudioBuffer>, media::mojom::AudioBufferPtr>:: | 309 TypeConverter<scoped_refptr<media::AudioBuffer>, media::mojom::AudioBufferPtr>:: |
310 Convert(const media::mojom::AudioBufferPtr& input) { | 310 Convert(const media::mojom::AudioBufferPtr& input) { |
311 if (input->end_of_stream) | 311 if (input->end_of_stream) |
312 return media::AudioBuffer::CreateEOSBuffer(); | 312 return media::AudioBuffer::CreateEOSBuffer(); |
313 | 313 |
| 314 if (input->frame_count <= 0 || |
| 315 static_cast<size_t>(input->sample_format) > media::kSampleFormatMax || |
| 316 static_cast<size_t>(input->channel_layout) > media::CHANNEL_LAYOUT_MAX || |
| 317 ChannelLayoutToChannelCount(input->channel_layout) != |
| 318 input->channel_count) { |
| 319 LOG(ERROR) << "Receive an invalid audio buffer, replace it with EOS."; |
| 320 return media::AudioBuffer::CreateEOSBuffer(); |
| 321 } |
| 322 |
| 323 if (IsBitstream(input->sample_format)) { |
| 324 uint8_t* data = input->data.data(); |
| 325 return media::AudioBuffer::CopyBitstreamFrom( |
| 326 input->sample_format, input->channel_layout, input->channel_count, |
| 327 input->sample_rate, input->frame_count, &data, input->data.size(), |
| 328 input->timestamp); |
| 329 } |
| 330 |
314 // Setup channel pointers. AudioBuffer::CopyFrom() will only use the first | 331 // Setup channel pointers. AudioBuffer::CopyFrom() will only use the first |
315 // one in the case of interleaved data. | 332 // one in the case of interleaved data. |
316 std::vector<const uint8_t*> channel_ptrs(input->channel_count, nullptr); | 333 std::vector<const uint8_t*> channel_ptrs(input->channel_count, nullptr); |
317 const size_t size_per_channel = input->data.size() / input->channel_count; | 334 const size_t size_per_channel = input->data.size() / input->channel_count; |
318 DCHECK_EQ(0u, input->data.size() % input->channel_count); | 335 DCHECK_EQ(0u, input->data.size() % input->channel_count); |
319 for (int i = 0; i < input->channel_count; ++i) | 336 for (int i = 0; i < input->channel_count; ++i) |
320 channel_ptrs[i] = input->data.data() + i * size_per_channel; | 337 channel_ptrs[i] = input->data.data() + i * size_per_channel; |
321 | 338 |
322 return media::AudioBuffer::CopyFrom( | 339 return media::AudioBuffer::CopyFrom( |
323 input->sample_format, input->channel_layout, input->channel_count, | 340 input->sample_format, input->channel_layout, input->channel_count, |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
384 input->format, input->coded_size, input->visible_rect, | 401 input->format, input->coded_size, input->visible_rect, |
385 input->natural_size, std::move(data->frame_data), | 402 input->natural_size, std::move(data->frame_data), |
386 base::saturated_cast<size_t>(data->frame_data_size), | 403 base::saturated_cast<size_t>(data->frame_data_size), |
387 base::saturated_cast<size_t>(data->y_offset), | 404 base::saturated_cast<size_t>(data->y_offset), |
388 base::saturated_cast<size_t>(data->u_offset), | 405 base::saturated_cast<size_t>(data->u_offset), |
389 base::saturated_cast<size_t>(data->v_offset), data->y_stride, | 406 base::saturated_cast<size_t>(data->v_offset), data->y_stride, |
390 data->u_stride, data->v_stride, input->timestamp); | 407 data->u_stride, data->v_stride, input->timestamp); |
391 } | 408 } |
392 | 409 |
393 } // namespace mojo | 410 } // namespace mojo |
OLD | NEW |