1 // Copyright 2005-2019 The Mumble Developers. All rights reserved.
2 // Use of this source code is governed by a BSD-style license
3 // that can be found in the LICENSE file at the root of the
4 // Mumble source tree or at <https://www.mumble.info/LICENSE>.
5 
6 #ifndef MUMBLE_MUMBLE_OPUSCODEC_H_
7 #define MUMBLE_MUMBLE_OPUSCODEC_H_
8 
9 #include <opus.h>
10 
11 #include <QtCore/QLibrary>
12 
13 #ifndef Q_OS_WIN
14 #define __cdecl
15 #endif
16 
17 /// Loads Opus from a shared library and acts as a wrapper for its functions.
18 class OpusCodec {
19 	private:
20 		Q_DISABLE_COPY(OpusCodec)
21 	protected:
22 		QLibrary qlOpus;
23 		bool bValid;
24 	public:
25 		OpusCodec();
26 		virtual ~OpusCodec();
27 
28 		bool isValid() const;
29 		void report() const;
30 
31 		const char *(__cdecl *opus_get_version_string)();
32 
33 		OpusEncoder *(__cdecl *opus_encoder_create)(opus_int32 Fs, int channels, int application, int *error);
34 		int (__cdecl *opus_encoder_ctl)(OpusEncoder *st, int request, ...);
35 		void (__cdecl *opus_encoder_destroy)(OpusEncoder *st);
36 		OpusDecoder *(__cdecl *opus_decoder_create)(opus_int32 Fs, int channels, int *error);
37 		void (__cdecl *opus_decoder_destroy)(OpusDecoder *st);
38 
39 		int (__cdecl *opus_encode)(OpusEncoder *st, const opus_int16 *pcm, int frame_size, unsigned char *compressed, int nbCompressedBytes);
40 		int (__cdecl *opus_decode_float)(OpusDecoder *st, const unsigned char *data, opus_int32 len, float *pcm, int frame_size, int decode_fec);
41 
42 		int (__cdecl *opus_packet_get_nb_frames)(const unsigned char packet[], opus_int32 len);
43 		int (__cdecl *opus_packet_get_samples_per_frame)(const unsigned char *data, opus_int32 Fs);
44 };
45 
46 #endif  // OPUSCODEC_H_
47