1 /* 2 * Copyright (c) 2011 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 #ifndef WEBRTC_VOICE_ENGINE_VOE_EXTERNAL_MEDIA_H 11 #define WEBRTC_VOICE_ENGINE_VOE_EXTERNAL_MEDIA_H 12 13 #include "webrtc/common_types.h" 14 15 namespace webrtc { 16 17 class VoiceEngine; 18 class AudioFrame; 19 20 class WEBRTC_DLLEXPORT VoEMediaProcess 21 { 22 public: 23 // The VoiceEngine user should override the Process() method in a 24 // derived class. Process() will be called when audio is ready to 25 // be processed. The audio can be accessed in several different modes 26 // given by the |type| parameter. The function should modify the 27 // original data and ensure that it is copied back to the |audio10ms| 28 // array. The number of samples in the frame cannot be changed. 29 // The sampling frequency will depend upon the codec used. 30 // If |isStereo| is true, audio10ms will contain 16-bit PCM data 31 // samples in interleaved stereo format (L0,R0,L1,R1,...). 32 virtual void Process(int channel, ProcessingTypes type, 33 int16_t audio10ms[], int length, 34 int samplingFreq, bool isStereo) = 0; 35 36 protected: 37 virtual ~VoEMediaProcess() {} 38 }; 39 40 class WEBRTC_DLLEXPORT VoEExternalMedia 41 { 42 public: 43 // Factory for the VoEExternalMedia sub-API. Increases an internal 44 // reference counter if successful. Returns NULL if the API is not 45 // supported or if construction fails. 46 static VoEExternalMedia* GetInterface(VoiceEngine* voiceEngine); 47 48 // Releases the VoEExternalMedia sub-API and decreases an internal 49 // reference counter. Returns the new reference count. This value should 50 // be zero for all sub-API:s before the VoiceEngine object can be safely 51 // deleted. 52 virtual int Release() = 0; 53 54 // Installs a VoEMediaProcess derived instance and activates external 55 // media for the specified |channel| and |type|. 56 virtual int RegisterExternalMediaProcessing( 57 int channel, ProcessingTypes type, VoEMediaProcess& processObject) = 0; 58 59 // Removes the VoEMediaProcess derived instance and deactivates external 60 // media for the specified |channel| and |type|. 61 virtual int DeRegisterExternalMediaProcessing( 62 int channel, ProcessingTypes type) = 0; 63 64 // Pulls an audio frame from the specified |channel| for external mixing. 65 // If the |desired_sample_rate_hz| is 0, the signal will be returned with 66 // its native frequency, otherwise it will be resampled. Valid frequencies 67 // are 16, 22, 32, 44 or 48 kHz. 68 virtual int GetAudioFrame(int channel, int desired_sample_rate_hz, 69 AudioFrame* frame) = 0; 70 71 // Sets the state of external mixing. Cannot be changed during playback. 72 virtual int SetExternalMixing(int channel, bool enable) = 0; 73 74 // Don't use. To be removed. 75 virtual int SetExternalRecordingStatus(bool enable) { return -1; } 76 virtual int SetExternalPlayoutStatus(bool enable) { return -1; } 77 virtual int ExternalRecordingInsertData( 78 const int16_t speechData10ms[], int lengthSamples, 79 int samplingFreqHz, int current_delay_ms) { return -1; } 80 virtual int ExternalPlayoutGetData( 81 int16_t speechData10ms[], int samplingFreqHz, 82 int current_delay_ms, int& lengthSamples) { return -1; } 83 84 protected: 85 VoEExternalMedia() {} 86 virtual ~VoEExternalMedia() {} 87 }; 88 89 } // namespace webrtc 90 91 #endif // WEBRTC_VOICE_ENGINE_VOE_EXTERNAL_MEDIA_H 92