| OLD | NEW |
| 1 /* | 1 /* |
| 2 * libjingle | 2 * libjingle |
| 3 * Copyright 2012 Google Inc. | 3 * Copyright 2012 Google Inc. |
| 4 * | 4 * |
| 5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
| 6 * modification, are permitted provided that the following conditions are met: | 6 * modification, are permitted provided that the following conditions are met: |
| 7 * | 7 * |
| 8 * 1. Redistributions of source code must retain the above copyright notice, | 8 * 1. Redistributions of source code must retain the above copyright notice, |
| 9 * this list of conditions and the following disclaimer. | 9 * this list of conditions and the following disclaimer. |
| 10 * 2. Redistributions in binary form must reproduce the above copyright notice, | 10 * 2. Redistributions in binary form must reproduce the above copyright notice, |
| (...skipping 22 matching lines...) Expand all Loading... |
| 33 | 33 |
| 34 // Note P postfix of a function indicates that it should only be called by the | 34 // Note P postfix of a function indicates that it should only be called by the |
| 35 // processing thread. | 35 // processing thread. |
| 36 | 36 |
| 37 #ifndef TALK_APP_WEBRTC_TEST_FAKEAUDIOCAPTUREMODULE_H_ | 37 #ifndef TALK_APP_WEBRTC_TEST_FAKEAUDIOCAPTUREMODULE_H_ |
| 38 #define TALK_APP_WEBRTC_TEST_FAKEAUDIOCAPTUREMODULE_H_ | 38 #define TALK_APP_WEBRTC_TEST_FAKEAUDIOCAPTUREMODULE_H_ |
| 39 | 39 |
| 40 #include "webrtc/base/basictypes.h" | 40 #include "webrtc/base/basictypes.h" |
| 41 #include "webrtc/base/criticalsection.h" | 41 #include "webrtc/base/criticalsection.h" |
| 42 #include "webrtc/base/messagehandler.h" | 42 #include "webrtc/base/messagehandler.h" |
| 43 #include "webrtc/base/scoped_ptr.h" |
| 43 #include "webrtc/base/scoped_ref_ptr.h" | 44 #include "webrtc/base/scoped_ref_ptr.h" |
| 44 #include "webrtc/common_types.h" | 45 #include "webrtc/common_types.h" |
| 45 #include "webrtc/modules/audio_device/include/audio_device.h" | 46 #include "webrtc/modules/audio_device/include/audio_device.h" |
| 46 | 47 |
| 47 namespace rtc { | 48 namespace rtc { |
| 48 | |
| 49 class Thread; | 49 class Thread; |
| 50 | |
| 51 } // namespace rtc | 50 } // namespace rtc |
| 52 | 51 |
| 53 class FakeAudioCaptureModule | 52 class FakeAudioCaptureModule |
| 54 : public webrtc::AudioDeviceModule, | 53 : public webrtc::AudioDeviceModule, |
| 55 public rtc::MessageHandler { | 54 public rtc::MessageHandler { |
| 56 public: | 55 public: |
| 57 typedef uint16 Sample; | 56 typedef uint16 Sample; |
| 58 | 57 |
| 59 // The value for the following constants have been derived by running VoE | 58 // The value for the following constants have been derived by running VoE |
| 60 // using a real ADM. The constants correspond to 10ms of mono audio at 44kHz. | 59 // using a real ADM. The constants correspond to 10ms of mono audio at 44kHz. |
| 61 static const int kNumberSamples = 440; | 60 static const int kNumberSamples = 440; |
| 62 static const int kNumberBytesPerSample = sizeof(Sample); | 61 static const int kNumberBytesPerSample = sizeof(Sample); |
| 63 | 62 |
| 64 // Creates a FakeAudioCaptureModule or returns NULL on failure. | 63 // Creates a FakeAudioCaptureModule or returns NULL on failure. |
| 65 // |process_thread| is used to push and pull audio frames to and from the | 64 static rtc::scoped_refptr<FakeAudioCaptureModule> Create(); |
| 66 // returned instance. Note: ownership of |process_thread| is not handed over. | |
| 67 static rtc::scoped_refptr<FakeAudioCaptureModule> Create( | |
| 68 rtc::Thread* process_thread); | |
| 69 | 65 |
| 70 // Returns the number of frames that have been successfully pulled by the | 66 // Returns the number of frames that have been successfully pulled by the |
| 71 // instance. Note that correctly detecting success can only be done if the | 67 // instance. Note that correctly detecting success can only be done if the |
| 72 // pulled frame was generated/pushed from a FakeAudioCaptureModule. | 68 // pulled frame was generated/pushed from a FakeAudioCaptureModule. |
| 73 int frames_received() const; | 69 int frames_received() const; |
| 74 | 70 |
| 75 // Following functions are inherited from webrtc::AudioDeviceModule. | 71 // Following functions are inherited from webrtc::AudioDeviceModule. |
| 76 // Only functions called by PeerConnection are implemented, the rest do | 72 // Only functions called by PeerConnection are implemented, the rest do |
| 77 // nothing and return success. If a function is not expected to be called by | 73 // nothing and return success. If a function is not expected to be called by |
| 78 // PeerConnection an assertion is triggered if it is in fact called. | 74 // PeerConnection an assertion is triggered if it is in fact called. |
| (...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 199 | 195 |
| 200 // The following function is inherited from rtc::MessageHandler. | 196 // The following function is inherited from rtc::MessageHandler. |
| 201 void OnMessage(rtc::Message* msg) override; | 197 void OnMessage(rtc::Message* msg) override; |
| 202 | 198 |
| 203 protected: | 199 protected: |
| 204 // The constructor is protected because the class needs to be created as a | 200 // The constructor is protected because the class needs to be created as a |
| 205 // reference counted object (for memory managment reasons). It could be | 201 // reference counted object (for memory managment reasons). It could be |
| 206 // exposed in which case the burden of proper instantiation would be put on | 202 // exposed in which case the burden of proper instantiation would be put on |
| 207 // the creator of a FakeAudioCaptureModule instance. To create an instance of | 203 // the creator of a FakeAudioCaptureModule instance. To create an instance of |
| 208 // this class use the Create(..) API. | 204 // this class use the Create(..) API. |
| 209 explicit FakeAudioCaptureModule(rtc::Thread* process_thread); | 205 explicit FakeAudioCaptureModule(); |
| 210 // The destructor is protected because it is reference counted and should not | 206 // The destructor is protected because it is reference counted and should not |
| 211 // be deleted directly. | 207 // be deleted directly. |
| 212 virtual ~FakeAudioCaptureModule(); | 208 virtual ~FakeAudioCaptureModule(); |
| 213 | 209 |
| 214 private: | 210 private: |
| 215 // Initializes the state of the FakeAudioCaptureModule. This API is called on | 211 // Initializes the state of the FakeAudioCaptureModule. This API is called on |
| 216 // creation by the Create() API. | 212 // creation by the Create() API. |
| 217 bool Initialize(); | 213 bool Initialize(); |
| 218 // SetBuffer() sets all samples in send_buffer_ to |value|. | 214 // SetBuffer() sets all samples in send_buffer_ to |value|. |
| 219 void SetSendBuffer(int value); | 215 void SetSendBuffer(int value); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 232 | 228 |
| 233 // Starts the periodic calling of ProcessFrame() in a thread safe way. | 229 // Starts the periodic calling of ProcessFrame() in a thread safe way. |
| 234 void StartProcessP(); | 230 void StartProcessP(); |
| 235 // Periodcally called function that ensures that frames are pulled and pushed | 231 // Periodcally called function that ensures that frames are pulled and pushed |
| 236 // periodically if enabled/started. | 232 // periodically if enabled/started. |
| 237 void ProcessFrameP(); | 233 void ProcessFrameP(); |
| 238 // Pulls frames from the registered webrtc::AudioTransport. | 234 // Pulls frames from the registered webrtc::AudioTransport. |
| 239 void ReceiveFrameP(); | 235 void ReceiveFrameP(); |
| 240 // Pushes frames to the registered webrtc::AudioTransport. | 236 // Pushes frames to the registered webrtc::AudioTransport. |
| 241 void SendFrameP(); | 237 void SendFrameP(); |
| 242 // Stops the periodic calling of ProcessFrame() in a thread safe way. | |
| 243 void StopProcessP(); | |
| 244 | 238 |
| 245 // The time in milliseconds when Process() was last called or 0 if no call | 239 // The time in milliseconds when Process() was last called or 0 if no call |
| 246 // has been made. | 240 // has been made. |
| 247 uint32 last_process_time_ms_; | 241 uint32 last_process_time_ms_; |
| 248 | 242 |
| 249 // Callback for playout and recording. | 243 // Callback for playout and recording. |
| 250 webrtc::AudioTransport* audio_callback_; | 244 webrtc::AudioTransport* audio_callback_; |
| 251 | 245 |
| 252 bool recording_; // True when audio is being pushed from the instance. | 246 bool recording_; // True when audio is being pushed from the instance. |
| 253 bool playing_; // True when audio is being pulled by the instance. | 247 bool playing_; // True when audio is being pulled by the instance. |
| 254 | 248 |
| 255 bool play_is_initialized_; // True when the instance is ready to pull audio. | 249 bool play_is_initialized_; // True when the instance is ready to pull audio. |
| 256 bool rec_is_initialized_; // True when the instance is ready to push audio. | 250 bool rec_is_initialized_; // True when the instance is ready to push audio. |
| 257 | 251 |
| 258 // Input to and output from RecordedDataIsAvailable(..) makes it possible to | 252 // Input to and output from RecordedDataIsAvailable(..) makes it possible to |
| 259 // modify the current mic level. The implementation does not care about the | 253 // modify the current mic level. The implementation does not care about the |
| 260 // mic level so it just feeds back what it receives. | 254 // mic level so it just feeds back what it receives. |
| 261 uint32_t current_mic_level_; | 255 uint32_t current_mic_level_; |
| 262 | 256 |
| 263 // next_frame_time_ is updated in a non-drifting manner to indicate the next | 257 // next_frame_time_ is updated in a non-drifting manner to indicate the next |
| 264 // wall clock time the next frame should be generated and received. started_ | 258 // wall clock time the next frame should be generated and received. started_ |
| 265 // ensures that next_frame_time_ can be initialized properly on first call. | 259 // ensures that next_frame_time_ can be initialized properly on first call. |
| 266 bool started_; | 260 bool started_; |
| 267 uint32 next_frame_time_; | 261 uint32 next_frame_time_; |
| 268 | 262 |
| 269 // User provided thread context. | 263 rtc::scoped_ptr<rtc::Thread> process_thread_; |
| 270 rtc::Thread* process_thread_; | |
| 271 | 264 |
| 272 // Buffer for storing samples received from the webrtc::AudioTransport. | 265 // Buffer for storing samples received from the webrtc::AudioTransport. |
| 273 char rec_buffer_[kNumberSamples * kNumberBytesPerSample]; | 266 char rec_buffer_[kNumberSamples * kNumberBytesPerSample]; |
| 274 // Buffer for samples to send to the webrtc::AudioTransport. | 267 // Buffer for samples to send to the webrtc::AudioTransport. |
| 275 char send_buffer_[kNumberSamples * kNumberBytesPerSample]; | 268 char send_buffer_[kNumberSamples * kNumberBytesPerSample]; |
| 276 | 269 |
| 277 // Counter of frames received that have samples of high enough amplitude to | 270 // Counter of frames received that have samples of high enough amplitude to |
| 278 // indicate that the frames are not faked somewhere in the audio pipeline | 271 // indicate that the frames are not faked somewhere in the audio pipeline |
| 279 // (e.g. by a jitter buffer). | 272 // (e.g. by a jitter buffer). |
| 280 int frames_received_; | 273 int frames_received_; |
| 281 | 274 |
| 282 // Protects variables that are accessed from process_thread_ and | 275 // Protects variables that are accessed from process_thread_ and |
| 283 // the main thread. | 276 // the main thread. |
| 284 mutable rtc::CriticalSection crit_; | 277 mutable rtc::CriticalSection crit_; |
| 285 // Protects |audio_callback_| that is accessed from process_thread_ and | 278 // Protects |audio_callback_| that is accessed from process_thread_ and |
| 286 // the main thread. | 279 // the main thread. |
| 287 rtc::CriticalSection crit_callback_; | 280 rtc::CriticalSection crit_callback_; |
| 288 }; | 281 }; |
| 289 | 282 |
| 290 #endif // TALK_APP_WEBRTC_TEST_FAKEAUDIOCAPTUREMODULE_H_ | 283 #endif // TALK_APP_WEBRTC_TEST_FAKEAUDIOCAPTUREMODULE_H_ |
| OLD | NEW |