Home | History | Annotate | Download | only in mock
      1 /*
      2  *  Copyright (c) 2013 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_VOICE_ENGINE_INCLUDE_MOCK_FAKE_VOE_EXTERNAL_MEDIA_H_
     12 #define WEBRTC_VOICE_ENGINE_INCLUDE_MOCK_FAKE_VOE_EXTERNAL_MEDIA_H_
     13 
     14 #include <map>
     15 
     16 #include "webrtc/system_wrappers/interface/scoped_ptr.h"
     17 #include "webrtc/test/fake_common.h"
     18 #include "webrtc/voice_engine/include/voe_external_media.h"
     19 
     20 namespace webrtc {
     21 
     22 class FakeVoEExternalMedia : public VoEExternalMedia {
     23  public:
     24   FakeVoEExternalMedia() {}
     25   virtual ~FakeVoEExternalMedia() {}
     26 
     27   WEBRTC_STUB(Release, ());
     28   WEBRTC_FUNC(RegisterExternalMediaProcessing,
     29       (int channel, ProcessingTypes type, VoEMediaProcess& processObject)) {
     30     callback_map_[type] = &processObject;
     31     return 0;
     32   }
     33   WEBRTC_FUNC(DeRegisterExternalMediaProcessing,
     34       (int channel, ProcessingTypes type)) {
     35     callback_map_.erase(type);
     36     return 0;
     37   }
     38   WEBRTC_STUB(SetExternalRecordingStatus, (bool enable));
     39   WEBRTC_STUB(SetExternalPlayoutStatus, (bool enable));
     40   WEBRTC_STUB(ExternalRecordingInsertData,
     41       (const int16_t speechData10ms[], int lengthSamples,
     42        int samplingFreqHz, int current_delay_ms));
     43   WEBRTC_STUB(ExternalPlayoutGetData,
     44       (int16_t speechData10ms[], int samplingFreqHz,
     45        int current_delay_ms, int& lengthSamples));
     46   WEBRTC_STUB(GetAudioFrame, (int channel, int desired_sample_rate_hz,
     47                               AudioFrame* frame));
     48   WEBRTC_STUB(SetExternalMixing, (int channel, bool enable));
     49 
     50   // Use this to trigger the Process() callback to a registered media processor.
     51   // If |audio| is NULL, a zero array of the correct length will be forwarded.
     52   void CallProcess(ProcessingTypes type, int16_t* audio,
     53                    int samples_per_channel, int sample_rate_hz,
     54                    int num_channels) {
     55     const int length = samples_per_channel * num_channels;
     56     scoped_ptr<int16_t[]> data;
     57     if (!audio) {
     58       data.reset(new int16_t[length]);
     59       memset(data.get(), 0, length * sizeof(data[0]));
     60       audio = data.get();
     61     }
     62 
     63     std::map<ProcessingTypes, VoEMediaProcess*>::const_iterator it =
     64         callback_map_.find(type);
     65     if (it != callback_map_.end()) {
     66       it->second->Process(0, type, audio, samples_per_channel, sample_rate_hz,
     67                           num_channels == 2 ? true : false);
     68     }
     69   }
     70 
     71  private:
     72   std::map<ProcessingTypes, VoEMediaProcess*> callback_map_;
     73 };
     74 
     75 }  // namespace webrtc
     76 
     77 #endif  //  WEBRTC_VOICE_ENGINE_INCLUDE_MOCK_FAKE_VOE_EXTERNAL_MEDIA_H_
     78