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

Side by Side Diff: webrtc/modules/audio_device/android/audio_device_template.h

Issue 1335923002: Add RTC_ prefix to (D)CHECKs and related macros. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Rebase. Created 5 years, 3 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
OLDNEW
1 /* 1 /*
2 * Copyright (c) 2013 The WebRTC project authors. All Rights Reserved. 2 * Copyright (c) 2013 The WebRTC project authors. All Rights Reserved.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license 4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source 5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found 6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may 7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree. 8 * be found in the AUTHORS file in the root of the source tree.
9 */ 9 */
10 10
11 #ifndef WEBRTC_MODULES_AUDIO_DEVICE_ANDROID_AUDIO_DEVICE_TEMPLATE_H_ 11 #ifndef WEBRTC_MODULES_AUDIO_DEVICE_ANDROID_AUDIO_DEVICE_TEMPLATE_H_
12 #define WEBRTC_MODULES_AUDIO_DEVICE_ANDROID_AUDIO_DEVICE_TEMPLATE_H_ 12 #define WEBRTC_MODULES_AUDIO_DEVICE_ANDROID_AUDIO_DEVICE_TEMPLATE_H_
13 13
14 #include <android/log.h> 14 #include <android/log.h>
15 15
16 #include "webrtc/base/checks.h" 16 #include "webrtc/base/checks.h"
17 #include "webrtc/base/thread_checker.h" 17 #include "webrtc/base/thread_checker.h"
18 #include "webrtc/modules/audio_device/android/audio_manager.h" 18 #include "webrtc/modules/audio_device/android/audio_manager.h"
19 #include "webrtc/modules/audio_device/audio_device_generic.h" 19 #include "webrtc/modules/audio_device/audio_device_generic.h"
20 #include "webrtc/system_wrappers/interface/trace.h" 20 #include "webrtc/system_wrappers/interface/trace.h"
21 21
22 #define TAG "AudioDeviceTemplate" 22 #define TAG "AudioDeviceTemplate"
23 #define ALOGW(...) __android_log_print(ANDROID_LOG_WARN, TAG, __VA_ARGS__) 23 #define ALOGW(...) __android_log_print(ANDROID_LOG_WARN, TAG, __VA_ARGS__)
24 24
25 namespace webrtc { 25 namespace webrtc {
26 26
27 // InputType/OutputType can be any class that implements the capturing/rendering 27 // InputType/OutputType can be any class that implements the capturing/rendering
28 // part of the AudioDeviceGeneric API. 28 // part of the AudioDeviceGeneric API.
29 // Construction and destruction must be done on one and the same thread. Each 29 // Construction and destruction must be done on one and the same thread. Each
30 // internal implementation of InputType and OutputType will DCHECK if that is 30 // internal implementation of InputType and OutputType will RTC_DCHECK if that
31 // not the case. All implemented methods must also be called on the same thread. 31 // is not the case. All implemented methods must also be called on the same
32 // See comments in each InputType/OutputType class for more 32 // thread. See comments in each InputType/OutputType class for more info.
33 // It is possible to call the two static methods (SetAndroidAudioDeviceObjects 33 // It is possible to call the two static methods (SetAndroidAudioDeviceObjects
34 // and ClearAndroidAudioDeviceObjects) from a different thread but both will 34 // and ClearAndroidAudioDeviceObjects) from a different thread but both will
35 // CHECK that the calling thread is attached to a Java VM. 35 // RTC_CHECK that the calling thread is attached to a Java VM.
36 36
37 template <class InputType, class OutputType> 37 template <class InputType, class OutputType>
38 class AudioDeviceTemplate : public AudioDeviceGeneric { 38 class AudioDeviceTemplate : public AudioDeviceGeneric {
39 public: 39 public:
40 AudioDeviceTemplate(AudioDeviceModule::AudioLayer audio_layer, 40 AudioDeviceTemplate(AudioDeviceModule::AudioLayer audio_layer,
41 AudioManager* audio_manager) 41 AudioManager* audio_manager)
42 : audio_layer_(audio_layer), 42 : audio_layer_(audio_layer),
43 audio_manager_(audio_manager), 43 audio_manager_(audio_manager),
44 output_(audio_manager_), 44 output_(audio_manager_),
45 input_(audio_manager_), 45 input_(audio_manager_),
46 initialized_(false) { 46 initialized_(false) {
47 CHECK(audio_manager); 47 RTC_CHECK(audio_manager);
48 audio_manager_->SetActiveAudioLayer(audio_layer); 48 audio_manager_->SetActiveAudioLayer(audio_layer);
49 } 49 }
50 50
51 virtual ~AudioDeviceTemplate() { 51 virtual ~AudioDeviceTemplate() {
52 } 52 }
53 53
54 int32_t ActiveAudioLayer( 54 int32_t ActiveAudioLayer(
55 AudioDeviceModule::AudioLayer& audioLayer) const override { 55 AudioDeviceModule::AudioLayer& audioLayer) const override {
56 audioLayer = audio_layer_; 56 audioLayer = audio_layer_;
57 return 0; 57 return 0;
58 } 58 }
59 59
60 int32_t Init() override { 60 int32_t Init() override {
61 DCHECK(thread_checker_.CalledOnValidThread()); 61 RTC_DCHECK(thread_checker_.CalledOnValidThread());
62 DCHECK(!initialized_); 62 RTC_DCHECK(!initialized_);
63 if (!audio_manager_->Init()) 63 if (!audio_manager_->Init())
64 return -1; 64 return -1;
65 if (output_.Init() != 0) { 65 if (output_.Init() != 0) {
66 audio_manager_->Close(); 66 audio_manager_->Close();
67 return -1; 67 return -1;
68 } 68 }
69 if (input_.Init() != 0) { 69 if (input_.Init() != 0) {
70 output_.Terminate(); 70 output_.Terminate();
71 audio_manager_->Close(); 71 audio_manager_->Close();
72 return -1; 72 return -1;
73 } 73 }
74 initialized_ = true; 74 initialized_ = true;
75 return 0; 75 return 0;
76 } 76 }
77 77
78 int32_t Terminate() override { 78 int32_t Terminate() override {
79 DCHECK(thread_checker_.CalledOnValidThread()); 79 RTC_DCHECK(thread_checker_.CalledOnValidThread());
80 int32_t err = input_.Terminate(); 80 int32_t err = input_.Terminate();
81 err |= output_.Terminate(); 81 err |= output_.Terminate();
82 err |= !audio_manager_->Close(); 82 err |= !audio_manager_->Close();
83 initialized_ = false; 83 initialized_ = false;
84 DCHECK_EQ(err, 0); 84 RTC_DCHECK_EQ(err, 0);
85 return err; 85 return err;
86 } 86 }
87 87
88 bool Initialized() const override { 88 bool Initialized() const override {
89 DCHECK(thread_checker_.CalledOnValidThread()); 89 RTC_DCHECK(thread_checker_.CalledOnValidThread());
90 return initialized_; 90 return initialized_;
91 } 91 }
92 92
93 int16_t PlayoutDevices() override { 93 int16_t PlayoutDevices() override {
94 return 1; 94 return 1;
95 } 95 }
96 96
97 int16_t RecordingDevices() override { 97 int16_t RecordingDevices() override {
98 return 1; 98 return 1;
99 } 99 }
(...skipping 281 matching lines...) Expand 10 before | Expand all | Expand 10 after
381 381
382 int32_t PlayoutBuffer( 382 int32_t PlayoutBuffer(
383 AudioDeviceModule::BufferType& type, uint16_t& sizeMS) const override { 383 AudioDeviceModule::BufferType& type, uint16_t& sizeMS) const override {
384 FATAL() << "Should never be called"; 384 FATAL() << "Should never be called";
385 return -1; 385 return -1;
386 } 386 }
387 387
388 int32_t PlayoutDelay(uint16_t& delay_ms) const override { 388 int32_t PlayoutDelay(uint16_t& delay_ms) const override {
389 // Best guess we can do is to use half of the estimated total delay. 389 // Best guess we can do is to use half of the estimated total delay.
390 delay_ms = audio_manager_->GetDelayEstimateInMilliseconds() / 2; 390 delay_ms = audio_manager_->GetDelayEstimateInMilliseconds() / 2;
391 DCHECK_GT(delay_ms, 0); 391 RTC_DCHECK_GT(delay_ms, 0);
392 return 0; 392 return 0;
393 } 393 }
394 394
395 int32_t RecordingDelay(uint16_t& delay_ms) const override { 395 int32_t RecordingDelay(uint16_t& delay_ms) const override {
396 // Best guess we can do is to use half of the estimated total delay. 396 // Best guess we can do is to use half of the estimated total delay.
397 delay_ms = audio_manager_->GetDelayEstimateInMilliseconds() / 2; 397 delay_ms = audio_manager_->GetDelayEstimateInMilliseconds() / 2;
398 DCHECK_GT(delay_ms, 0); 398 RTC_DCHECK_GT(delay_ms, 0);
399 return 0; 399 return 0;
400 } 400 }
401 401
402 int32_t CPULoad(uint16_t& load) const override { 402 int32_t CPULoad(uint16_t& load) const override {
403 FATAL() << "Should never be called"; 403 FATAL() << "Should never be called";
404 return -1; 404 return -1;
405 } 405 }
406 406
407 bool PlayoutWarning() const override { 407 bool PlayoutWarning() const override {
408 return false; 408 return false;
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
449 return -1; 449 return -1;
450 } 450 }
451 451
452 // Returns true if the device both supports built in AEC and the device 452 // Returns true if the device both supports built in AEC and the device
453 // is not blacklisted. 453 // is not blacklisted.
454 bool BuiltInAECIsAvailable() const override { 454 bool BuiltInAECIsAvailable() const override {
455 return audio_manager_->IsAcousticEchoCancelerSupported(); 455 return audio_manager_->IsAcousticEchoCancelerSupported();
456 } 456 }
457 457
458 int32_t EnableBuiltInAEC(bool enable) override { 458 int32_t EnableBuiltInAEC(bool enable) override {
459 CHECK(BuiltInAECIsAvailable()) << "HW AEC is not available"; 459 RTC_CHECK(BuiltInAECIsAvailable()) << "HW AEC is not available";
460 return input_.EnableBuiltInAEC(enable); 460 return input_.EnableBuiltInAEC(enable);
461 } 461 }
462 462
463 private: 463 private:
464 rtc::ThreadChecker thread_checker_; 464 rtc::ThreadChecker thread_checker_;
465 465
466 // Local copy of the audio layer set during construction of the 466 // Local copy of the audio layer set during construction of the
467 // AudioDeviceModuleImpl instance. Read only value. 467 // AudioDeviceModuleImpl instance. Read only value.
468 const AudioDeviceModule::AudioLayer audio_layer_; 468 const AudioDeviceModule::AudioLayer audio_layer_;
469 469
470 // Non-owning raw pointer to AudioManager instance given to use at 470 // Non-owning raw pointer to AudioManager instance given to use at
471 // construction. The real object is owned by AudioDeviceModuleImpl and the 471 // construction. The real object is owned by AudioDeviceModuleImpl and the
472 // life time is the same as that of the AudioDeviceModuleImpl, hence there 472 // life time is the same as that of the AudioDeviceModuleImpl, hence there
473 // is no risk of reading a NULL pointer at any time in this class. 473 // is no risk of reading a NULL pointer at any time in this class.
474 AudioManager* const audio_manager_; 474 AudioManager* const audio_manager_;
475 475
476 OutputType output_; 476 OutputType output_;
477 477
478 InputType input_; 478 InputType input_;
479 479
480 bool initialized_; 480 bool initialized_;
481 }; 481 };
482 482
483 } // namespace webrtc 483 } // namespace webrtc
484 484
485 #endif // WEBRTC_MODULES_AUDIO_DEVICE_ANDROID_AUDIO_DEVICE_TEMPLATE_H_ 485 #endif // WEBRTC_MODULES_AUDIO_DEVICE_ANDROID_AUDIO_DEVICE_TEMPLATE_H_
OLDNEW
« no previous file with comments | « webrtc/modules/audio_coding/neteq/tools/rtpcat.cc ('k') | webrtc/modules/audio_device/android/audio_device_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698