• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  *  Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
3  *
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
6  *  tree. An additional intellectual property rights grant can be found
7  *  in the file PATENTS.  All contributing project authors may
8  *  be found in the AUTHORS file in the root of the source tree.
9  */
10 
11 #ifndef WEBRTC_MODULES_AUDIO_PROCESSING_ECHO_CONTROL_MOBILE_IMPL_H_
12 #define WEBRTC_MODULES_AUDIO_PROCESSING_ECHO_CONTROL_MOBILE_IMPL_H_
13 
14 #include "webrtc/base/criticalsection.h"
15 #include "webrtc/base/scoped_ptr.h"
16 #include "webrtc/common_audio/swap_queue.h"
17 #include "webrtc/modules/audio_processing/include/audio_processing.h"
18 #include "webrtc/modules/audio_processing/processing_component.h"
19 
20 namespace webrtc {
21 
22 class AudioBuffer;
23 
24 class EchoControlMobileImpl : public EchoControlMobile,
25                               public ProcessingComponent {
26  public:
27   EchoControlMobileImpl(const AudioProcessing* apm,
28                         rtc::CriticalSection* crit_render,
29                         rtc::CriticalSection* crit_capture);
30 
31   virtual ~EchoControlMobileImpl();
32 
33   int ProcessRenderAudio(const AudioBuffer* audio);
34   int ProcessCaptureAudio(AudioBuffer* audio);
35 
36   // EchoControlMobile implementation.
37   bool is_enabled() const override;
38   RoutingMode routing_mode() const override;
39   bool is_comfort_noise_enabled() const override;
40 
41   // ProcessingComponent implementation.
42   int Initialize() override;
43 
44   // Reads render side data that has been queued on the render call.
45   void ReadQueuedRenderData();
46 
47  private:
48   // EchoControlMobile implementation.
49   int Enable(bool enable) override;
50   int set_routing_mode(RoutingMode mode) override;
51   int enable_comfort_noise(bool enable) override;
52   int SetEchoPath(const void* echo_path, size_t size_bytes) override;
53   int GetEchoPath(void* echo_path, size_t size_bytes) const override;
54 
55   // ProcessingComponent implementation.
56   // Called holding both the render and capture locks.
57   void* CreateHandle() const override;
58   int InitializeHandle(void* handle) const override;
59   int ConfigureHandle(void* handle) const override;
60   void DestroyHandle(void* handle) const override;
61   size_t num_handles_required() const override;
62   int GetHandleError(void* handle) const override;
63 
64   void AllocateRenderQueue();
65 
66   // Not guarded as its public API is thread safe.
67   const AudioProcessing* apm_;
68 
69   rtc::CriticalSection* const crit_render_ ACQUIRED_BEFORE(crit_capture_);
70   rtc::CriticalSection* const crit_capture_;
71 
72   RoutingMode routing_mode_ GUARDED_BY(crit_capture_);
73   bool comfort_noise_enabled_ GUARDED_BY(crit_capture_);
74   unsigned char* external_echo_path_ GUARDED_BY(crit_render_)
75       GUARDED_BY(crit_capture_);
76 
77   size_t render_queue_element_max_size_ GUARDED_BY(crit_render_)
78       GUARDED_BY(crit_capture_);
79 
80   std::vector<int16_t> render_queue_buffer_ GUARDED_BY(crit_render_);
81   std::vector<int16_t> capture_queue_buffer_ GUARDED_BY(crit_capture_);
82 
83   // Lock protection not needed.
84   rtc::scoped_ptr<
85       SwapQueue<std::vector<int16_t>, RenderQueueItemVerifier<int16_t>>>
86       render_signal_queue_;
87 };
88 }  // namespace webrtc
89 
90 #endif  // WEBRTC_MODULES_AUDIO_PROCESSING_ECHO_CONTROL_MOBILE_IMPL_H_
91