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

Side by Side Diff: trunk/src/media/audio/win/audio_low_latency_input_win.cc

Issue 335343004: Revert 277794 "Modifies AudioInputCallback::OnData and use media..." (Closed) Base URL: svn://svn.chromium.org/chrome/
Patch Set: Created 6 years, 6 months 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 | Annotate | Revision Log
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/win/audio_low_latency_input_win.h" 5 #include "media/audio/win/audio_low_latency_input_win.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "base/memory/scoped_ptr.h" 8 #include "base/memory/scoped_ptr.h"
9 #include "base/strings/utf_string_conversions.h" 9 #include "base/strings/utf_string_conversions.h"
10 #include "media/audio/win/audio_manager_win.h" 10 #include "media/audio/win/audio_manager_win.h"
11 #include "media/audio/win/avrt_wrapper_win.h" 11 #include "media/audio/win/avrt_wrapper_win.h"
12 #include "media/base/audio_bus.h"
13 12
14 using base::win::ScopedComPtr; 13 using base::win::ScopedComPtr;
15 using base::win::ScopedCOMInitializer; 14 using base::win::ScopedCOMInitializer;
16 15
17 namespace media { 16 namespace media {
18 namespace { 17 namespace {
19 18
20 // Returns true if |device| represents the default communication capture device. 19 // Returns true if |device| represents the default communication capture device.
21 bool IsDefaultCommunicationDevice(IMMDeviceEnumerator* enumerator, 20 bool IsDefaultCommunicationDevice(IMMDeviceEnumerator* enumerator,
22 IMMDevice* device) { 21 IMMDevice* device) {
23 ScopedComPtr<IMMDevice> communications; 22 ScopedComPtr<IMMDevice> communications;
24 if (FAILED(enumerator->GetDefaultAudioEndpoint(eCapture, eCommunications, 23 if (FAILED(enumerator->GetDefaultAudioEndpoint(eCapture, eCommunications,
25 communications.Receive()))) { 24 communications.Receive()))) {
26 return false; 25 return false;
27 } 26 }
28 27
29 base::win::ScopedCoMem<WCHAR> communications_id, device_id; 28 base::win::ScopedCoMem<WCHAR> communications_id, device_id;
30 device->GetId(&device_id); 29 device->GetId(&device_id);
31 communications->GetId(&communications_id); 30 communications->GetId(&communications_id);
32 return lstrcmpW(communications_id, device_id) == 0; 31 return lstrcmpW(communications_id, device_id) == 0;
33 } 32 }
34 33
35 } // namespace 34 } // namespace
36 35
37 WASAPIAudioInputStream::WASAPIAudioInputStream(AudioManagerWin* manager, 36 WASAPIAudioInputStream::WASAPIAudioInputStream(
38 const AudioParameters& params, 37 AudioManagerWin* manager,
39 const std::string& device_id) 38 const AudioParameters& params,
39 const std::string& device_id)
40 : manager_(manager), 40 : manager_(manager),
41 capture_thread_(NULL), 41 capture_thread_(NULL),
42 opened_(false), 42 opened_(false),
43 started_(false), 43 started_(false),
44 frame_size_(0), 44 frame_size_(0),
45 packet_size_frames_(0), 45 packet_size_frames_(0),
46 packet_size_bytes_(0), 46 packet_size_bytes_(0),
47 endpoint_buffer_size_frames_(0), 47 endpoint_buffer_size_frames_(0),
48 effects_(params.effects()), 48 effects_(params.effects()),
49 device_id_(device_id), 49 device_id_(device_id),
50 perf_count_to_100ns_units_(0.0), 50 perf_count_to_100ns_units_(0.0),
51 ms_to_frame_count_(0.0), 51 ms_to_frame_count_(0.0),
52 sink_(NULL), 52 sink_(NULL) {
53 audio_bus_(media::AudioBus::Create(params)) {
54 DCHECK(manager_); 53 DCHECK(manager_);
55 54
56 // Load the Avrt DLL if not already loaded. Required to support MMCSS. 55 // Load the Avrt DLL if not already loaded. Required to support MMCSS.
57 bool avrt_init = avrt::Initialize(); 56 bool avrt_init = avrt::Initialize();
58 DCHECK(avrt_init) << "Failed to load the Avrt.dll"; 57 DCHECK(avrt_init) << "Failed to load the Avrt.dll";
59 58
60 // Set up the desired capture format specified by the client. 59 // Set up the desired capture format specified by the client.
61 format_.nSamplesPerSec = params.sample_rate(); 60 format_.nSamplesPerSec = params.sample_rate();
62 format_.wFormatTag = WAVE_FORMAT_PCM; 61 format_.wFormatTag = WAVE_FORMAT_PCM;
63 format_.wBitsPerSample = params.bits_per_sample(); 62 format_.wBitsPerSample = params.bits_per_sample();
(...skipping 366 matching lines...) Expand 10 before | Expand all | Expand 10 after
430 429
431 // Get a cached AGC volume level which is updated once every second 430 // Get a cached AGC volume level which is updated once every second
432 // on the audio manager thread. Note that, |volume| is also updated 431 // on the audio manager thread. Note that, |volume| is also updated
433 // each time SetVolume() is called through IPC by the render-side AGC. 432 // each time SetVolume() is called through IPC by the render-side AGC.
434 GetAgcVolume(&volume); 433 GetAgcVolume(&volume);
435 434
436 // Deliver captured data to the registered consumer using a packet 435 // Deliver captured data to the registered consumer using a packet
437 // size which was specified at construction. 436 // size which was specified at construction.
438 uint32 delay_frames = static_cast<uint32>(audio_delay_frames + 0.5); 437 uint32 delay_frames = static_cast<uint32>(audio_delay_frames + 0.5);
439 while (buffer_frame_index >= packet_size_frames_) { 438 while (buffer_frame_index >= packet_size_frames_) {
440 // Copy data to audio bus to match the OnData interface. 439 uint8* audio_data =
441 uint8* audio_data = reinterpret_cast<uint8*>(capture_buffer.get()); 440 reinterpret_cast<uint8*>(capture_buffer.get());
442 audio_bus_->FromInterleaved(
443 audio_data, audio_bus_->frames(), format_.wBitsPerSample / 8);
444 441
445 // Deliver data packet, delay estimation and volume level to 442 // Deliver data packet, delay estimation and volume level to
446 // the user. 443 // the user.
447 sink_->OnData( 444 sink_->OnData(this,
448 this, audio_bus_.get(), delay_frames * frame_size_, volume); 445 audio_data,
446 packet_size_bytes_,
447 delay_frames * frame_size_,
448 volume);
449 449
450 // Store parts of the recorded data which can't be delivered 450 // Store parts of the recorded data which can't be delivered
451 // using the current packet size. The stored section will be used 451 // using the current packet size. The stored section will be used
452 // either in the next while-loop iteration or in the next 452 // either in the next while-loop iteration or in the next
453 // capture event. 453 // capture event.
454 memmove(&capture_buffer[0], 454 memmove(&capture_buffer[0],
455 &capture_buffer[packet_size_bytes_], 455 &capture_buffer[packet_size_bytes_],
456 (buffer_frame_index - packet_size_frames_) * frame_size_); 456 (buffer_frame_index - packet_size_frames_) * frame_size_);
457 457
458 buffer_frame_index -= packet_size_frames_; 458 buffer_frame_index -= packet_size_frames_;
(...skipping 272 matching lines...) Expand 10 before | Expand all | Expand 10 after
731 return hr; 731 return hr;
732 732
733 // Obtain a reference to the ISimpleAudioVolume interface which enables 733 // Obtain a reference to the ISimpleAudioVolume interface which enables
734 // us to control the master volume level of an audio session. 734 // us to control the master volume level of an audio session.
735 hr = audio_client_->GetService(__uuidof(ISimpleAudioVolume), 735 hr = audio_client_->GetService(__uuidof(ISimpleAudioVolume),
736 simple_audio_volume_.ReceiveVoid()); 736 simple_audio_volume_.ReceiveVoid());
737 return hr; 737 return hr;
738 } 738 }
739 739
740 } // namespace media 740 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698