Commit 23ee9809 authored by Guillaume Roguez's avatar Guillaume Roguez Committed by Adrien Béraud

GCC4.8 support

Change-Id: I71a949f016df91c7032af63a46bbbc9f241f70b0
parent c8208423
......@@ -32,7 +32,6 @@
#include "logger.h"
#include "manager.h"
#include <regex>
#include <algorithm> // for std::find
#include <stdexcept>
......@@ -40,12 +39,27 @@
#include <cstdlib>
#include <fstream>
// Std-C++11 regex feature implemented only since GCC 4.9
// Using pcre library as replacement
//#if defined(__GNUC__) && __GNUC__ == 4 && __GNUC_MINOR__ < 9
#define USE_PCRE_REGEX
#include <pcre.h>
//#else
//#include <regex>
//#endif
// uncomment to log pulseaudio sink and sources
//#define PA_LOG_SINK_SOURCES
namespace ring {
static const std::regex PA_EC_SUFIX {".echo-cancel(\\..+)?$"};
#ifdef USE_PCRE_REGEX
static const char* ec_pcre_error;
static int ec_pcre_erroffset;
static const std::unique_ptr<pcre, decltype(pcre_free)> PA_EC_SUFFIX {pcre_compile("\\.echo-cancel(?:\\..+)?$", 0, &ec_pcre_error, &ec_pcre_erroffset, nullptr), pcre_free};
#else
static const std::regex PA_EC_SUFFIX {"\\.echo-cancel(?:\\..+)?$"};
#endif
PulseMainLoopLock::PulseMainLoopLock(pa_threaded_mainloop *loop) : loop_(loop), destroyLoop_(false)
{
......@@ -293,7 +307,7 @@ bool endsWith(const std::string& str, const std::string& ending)
const PaDeviceInfos* findBest(const std::vector<PaDeviceInfos>& list) {
if (list.empty()) return nullptr;
/*for (const auto& info : list)
if (info.monitor_of == PA_INVALID_INDEX && not endsWith(info.name, PA_EC_SUFIX))
if (info.monitor_of == PA_INVALID_INDEX && not endsWith(info.name, PA_EC_SUFFIX))
return &info;*/
for (const auto& info : list)
if (info.monitor_of == PA_INVALID_INDEX)
......@@ -524,10 +538,22 @@ void PulseLayer::ringtoneToSpeaker()
std::string stripEchoSufix(std::string deviceName) {
return std::regex_replace(deviceName, PA_EC_SUFIX, "");
/*return endsWith(deviceName, PA_EC_SUFIX)
? deviceName.substr(0, deviceName.size() - PA_EC_SUFIX.size())
: deviceName;*/
#ifdef USE_PCRE_REGEX
if (PA_EC_SUFFIX) {
static const constexpr int resSize = 3;
int resPos[resSize] = {};
int rc = pcre_exec(PA_EC_SUFFIX.get(), nullptr, deviceName.c_str(), deviceName.size(), 0, 0, resPos, resSize);
if (rc > 0) {
int start = resPos[0];
int length = resPos[1];
deviceName.replace(start, length, "");
}
} else
RING_ERR("PCRE compilation failed at offset %d: %s\n", ec_pcre_erroffset, ec_pcre_error);
return deviceName;
#else
return std::regex_replace(deviceName, PA_EC_SUFFIX, "");
#endif
}
void
......@@ -539,14 +565,12 @@ PulseLayer::context_changed_callback(pa_context* c,
}
void
PulseLayer::contextChanged(pa_context* c, pa_subscription_event_type_t type,
uint32_t idx UNUSED)
PulseLayer::contextChanged(pa_context* c UNUSED, pa_subscription_event_type_t type,
uint32_t idx UNUSED)
{
bool reset = false;
switch (type & PA_SUBSCRIPTION_EVENT_FACILITY_MASK) {
pa_operation *op;
case PA_SUBSCRIPTION_EVENT_SINK:
switch (type & PA_SUBSCRIPTION_EVENT_TYPE_MASK) {
case PA_SUBSCRIPTION_EVENT_NEW:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment