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

Side by Side Diff: media/audio/mac/audio_low_latency_input_mac.cc

Issue 1534273002: Switch to standard integer types in media/. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: more Created 5 years 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
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/audio/mac/audio_low_latency_input_mac.h" 5 #include "media/audio/mac/audio_low_latency_input_mac.h"
6 6
7 #include <CoreServices/CoreServices.h> 7 #include <CoreServices/CoreServices.h>
8 8
9 #include "base/basictypes.h"
10 #include "base/logging.h" 9 #include "base/logging.h"
11 #include "base/mac/mac_logging.h" 10 #include "base/mac/mac_logging.h"
12 #include "base/metrics/histogram_macros.h" 11 #include "base/metrics/histogram_macros.h"
13 #include "base/metrics/sparse_histogram.h" 12 #include "base/metrics/sparse_histogram.h"
14 #include "base/time/time.h" 13 #include "base/time/time.h"
15 #include "media/audio/mac/audio_manager_mac.h" 14 #include "media/audio/mac/audio_manager_mac.h"
16 #include "media/base/audio_bus.h" 15 #include "media/base/audio_bus.h"
17 #include "media/base/data_buffer.h" 16 #include "media/base/data_buffer.h"
18 17
19 namespace media { 18 namespace media {
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
82 81
83 DVLOG(1) << "Desired ouput format: " << format_; 82 DVLOG(1) << "Desired ouput format: " << format_;
84 83
85 // Derive size (in bytes) of the buffers that we will render to. 84 // Derive size (in bytes) of the buffers that we will render to.
86 UInt32 data_byte_size = number_of_frames_ * format_.mBytesPerFrame; 85 UInt32 data_byte_size = number_of_frames_ * format_.mBytesPerFrame;
87 DVLOG(1) << "Size of data buffer in bytes : " << data_byte_size; 86 DVLOG(1) << "Size of data buffer in bytes : " << data_byte_size;
88 87
89 // Allocate AudioBuffers to be used as storage for the received audio. 88 // Allocate AudioBuffers to be used as storage for the received audio.
90 // The AudioBufferList structure works as a placeholder for the 89 // The AudioBufferList structure works as a placeholder for the
91 // AudioBuffer structure, which holds a pointer to the actual data buffer. 90 // AudioBuffer structure, which holds a pointer to the actual data buffer.
92 audio_data_buffer_.reset(new uint8[data_byte_size]); 91 audio_data_buffer_.reset(new uint8_t[data_byte_size]);
93 audio_buffer_list_.mNumberBuffers = 1; 92 audio_buffer_list_.mNumberBuffers = 1;
94 93
95 AudioBuffer* audio_buffer = audio_buffer_list_.mBuffers; 94 AudioBuffer* audio_buffer = audio_buffer_list_.mBuffers;
96 audio_buffer->mNumberChannels = input_params.channels(); 95 audio_buffer->mNumberChannels = input_params.channels();
97 audio_buffer->mDataByteSize = data_byte_size; 96 audio_buffer->mDataByteSize = data_byte_size;
98 audio_buffer->mData = audio_data_buffer_.get(); 97 audio_buffer->mData = audio_data_buffer_.get();
99 } 98 }
100 99
101 AUAudioInputStream::~AUAudioInputStream() {} 100 AUAudioInputStream::~AUAudioInputStream() {}
102 101
(...skipping 411 matching lines...) Expand 10 before | Expand all | Expand 10 after
514 // See crbug/428706 for details. 513 // See crbug/428706 for details.
515 UInt32 new_size = number_of_frames * audio_input->format_.mBytesPerFrame; 514 UInt32 new_size = number_of_frames * audio_input->format_.mBytesPerFrame;
516 AudioBuffer* audio_buffer = audio_input->audio_buffer_list()->mBuffers; 515 AudioBuffer* audio_buffer = audio_input->audio_buffer_list()->mBuffers;
517 if (new_size != audio_buffer->mDataByteSize) { 516 if (new_size != audio_buffer->mDataByteSize) {
518 if (new_size > audio_buffer->mDataByteSize) { 517 if (new_size > audio_buffer->mDataByteSize) {
519 // This can happen if the device is unpluged during recording. We 518 // This can happen if the device is unpluged during recording. We
520 // allocate enough memory here to avoid depending on how CoreAudio 519 // allocate enough memory here to avoid depending on how CoreAudio
521 // handles it. 520 // handles it.
522 // See See http://www.crbug.com/434681 for one example when we can enter 521 // See See http://www.crbug.com/434681 for one example when we can enter
523 // this scope. 522 // this scope.
524 audio_input->audio_data_buffer_.reset(new uint8[new_size]); 523 audio_input->audio_data_buffer_.reset(new uint8_t[new_size]);
525 audio_buffer->mData = audio_input->audio_data_buffer_.get(); 524 audio_buffer->mData = audio_input->audio_data_buffer_.get();
526 } 525 }
527 526
528 // Update the |mDataByteSize| to match |number_of_frames|. 527 // Update the |mDataByteSize| to match |number_of_frames|.
529 audio_buffer->mDataByteSize = new_size; 528 audio_buffer->mDataByteSize = new_size;
530 } 529 }
531 530
532 // Receive audio from the AUHAL from the output scope of the Audio Unit. 531 // Receive audio from the AUHAL from the output scope of the Audio Unit.
533 OSStatus result = AudioUnitRender(audio_input->audio_unit(), 532 OSStatus result = AudioUnitRender(audio_input->audio_unit(),
534 flags, 533 flags,
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
575 // Update the capture latency. 574 // Update the capture latency.
576 double capture_latency_frames = GetCaptureLatency(time_stamp); 575 double capture_latency_frames = GetCaptureLatency(time_stamp);
577 576
578 // The AGC volume level is updated once every second on a separate thread. 577 // The AGC volume level is updated once every second on a separate thread.
579 // Note that, |volume| is also updated each time SetVolume() is called 578 // Note that, |volume| is also updated each time SetVolume() is called
580 // through IPC by the render-side AGC. 579 // through IPC by the render-side AGC.
581 double normalized_volume = 0.0; 580 double normalized_volume = 0.0;
582 GetAgcVolume(&normalized_volume); 581 GetAgcVolume(&normalized_volume);
583 582
584 AudioBuffer& buffer = io_data->mBuffers[0]; 583 AudioBuffer& buffer = io_data->mBuffers[0];
585 uint8* audio_data = reinterpret_cast<uint8*>(buffer.mData); 584 uint8_t* audio_data = reinterpret_cast<uint8_t*>(buffer.mData);
586 uint32 capture_delay_bytes = static_cast<uint32> 585 uint32_t capture_delay_bytes = static_cast<uint32_t>(
587 ((capture_latency_frames + 0.5) * format_.mBytesPerFrame); 586 (capture_latency_frames + 0.5) * format_.mBytesPerFrame);
588 DCHECK(audio_data); 587 DCHECK(audio_data);
589 if (!audio_data) 588 if (!audio_data)
590 return kAudioUnitErr_InvalidElement; 589 return kAudioUnitErr_InvalidElement;
591 590
592 // Dynamically increase capacity of the FIFO to handle larger buffers from 591 // Dynamically increase capacity of the FIFO to handle larger buffers from
593 // CoreAudio. This can happen in combination with Apple Thunderbolt Displays 592 // CoreAudio. This can happen in combination with Apple Thunderbolt Displays
594 // when the Display Audio is used as capture source and the cable is first 593 // when the Display Audio is used as capture source and the cable is first
595 // remove and then inserted again. 594 // remove and then inserted again.
596 // See http://www.crbug.com/434681 for details. 595 // See http://www.crbug.com/434681 for details.
597 if (static_cast<int>(number_of_frames) > fifo_.GetUnfilledFrames()) { 596 if (static_cast<int>(number_of_frames) > fifo_.GetUnfilledFrames()) {
(...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after
803 buffer_size_was_changed_); 802 buffer_size_was_changed_);
804 UMA_HISTOGRAM_COUNTS_1000("Media.Audio.NumberOfOutputStreamsMac", 803 UMA_HISTOGRAM_COUNTS_1000("Media.Audio.NumberOfOutputStreamsMac",
805 manager_->output_streams()); 804 manager_->output_streams());
806 UMA_HISTOGRAM_COUNTS_1000("Media.Audio.NumberOfLowLatencyInputStreamsMac", 805 UMA_HISTOGRAM_COUNTS_1000("Media.Audio.NumberOfLowLatencyInputStreamsMac",
807 manager_->low_latency_input_streams()); 806 manager_->low_latency_input_streams());
808 UMA_HISTOGRAM_COUNTS_1000("Media.Audio.NumberOfBasicInputStreamsMac", 807 UMA_HISTOGRAM_COUNTS_1000("Media.Audio.NumberOfBasicInputStreamsMac",
809 manager_->basic_input_streams()); 808 manager_->basic_input_streams());
810 } 809 }
811 810
812 } // namespace media 811 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698