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