Welcome to mirror list, hosted at ThFree Co, Russian Federation.

OpusCodec.cpp « mumble « src - github.com/mumble-voip/mumble.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 291823ce4ea1b278f6f6b40e2dbd587b226d6379 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
// Copyright 2018-2021 The Mumble Developers. All rights reserved.
// Use of this source code is governed by a BSD-style license
// that can be found in the LICENSE file at the root of the
// Mumble source tree or at <https://www.mumble.info/LICENSE>.

#include "OpusCodec.h"

#include "Audio.h"
#include "MumbleApplication.h"
#include "Version.h"

#ifdef Q_CC_GNU
#	define RESOLVE(var)                                                        \
		{                                                                       \
			var    = reinterpret_cast< __typeof__(var) >(qlOpus.resolve(#var)); \
			bValid = bValid && var;                                             \
		}
#else
#	define RESOLVE(var)                                                                      \
		{                                                                                     \
			*reinterpret_cast< void ** >(&var) = static_cast< void * >(qlOpus.resolve(#var)); \
			bValid                             = bValid && var;                               \
		}
#endif

OpusCodec::OpusCodec() {
	bValid = false;
	qlOpus.setLoadHints(QLibrary::ResolveAllSymbolsHint);

	QStringList alternatives;
#if defined(Q_OS_MAC)
	alternatives << QString::fromLatin1("libopus0.dylib");
	alternatives << QString::fromLatin1("opus0.dylib");
	alternatives << QString::fromLatin1("libopus.dylib");
	alternatives << QString::fromLatin1("opus.dylib");
#elif defined(Q_OS_UNIX)
	alternatives << QString::fromLatin1("libopus.so.0");
	alternatives << QString::fromLatin1("libopus0.so");
	alternatives << QString::fromLatin1("libopus.so");
	alternatives << QString::fromLatin1("opus.so");
#else
	alternatives << QString::fromLatin1("opus0.dll");
	alternatives << QString::fromLatin1("opus.dll");
#endif
	foreach (const QString &lib, alternatives) {
		qlOpus.setFileName(MumbleApplication::instance()->applicationVersionRootPath() + QLatin1String("/") + lib);
		if (qlOpus.load()) {
			bValid = true;
			break;
		}

#ifdef Q_OS_MAC
		qlOpus.setFileName(QApplication::instance()->applicationDirPath() + QLatin1String("/../Codecs/") + lib);
		if (qlOpus.load()) {
			bValid = true;
			break;
		}
#endif

#ifdef MUMBLE_LIBRARY_PATH
		qlOpus.setFileName(QLatin1String(MUMTEXT(MUMBLE_LIBRARY_PATH) "/") + lib);
		if (qlOpus.load()) {
			bValid = true;
			break;
		}
#endif

		qlOpus.setFileName(lib);
		if (qlOpus.load()) {
			bValid = true;
			break;
		}
	}

	RESOLVE(opus_get_version_string);

	RESOLVE(opus_encode);
	RESOLVE(opus_decode_float);

	RESOLVE(opus_encoder_create);
	RESOLVE(opus_encoder_ctl);
	RESOLVE(opus_encoder_destroy);
	RESOLVE(opus_decoder_create);
	RESOLVE(opus_decoder_ctl);
	RESOLVE(opus_decoder_destroy);

	RESOLVE(opus_decoder_get_nb_samples);

	RESOLVE(opus_packet_get_samples_per_frame);
}

OpusCodec::~OpusCodec() {
	qlOpus.unload();
}

bool OpusCodec::isValid() const {
	return bValid;
}

void OpusCodec::report() const {
	qDebug("%s from %s", opus_get_version_string(), qPrintable(qlOpus.fileName()));
}

#undef RESOLVE