code formatting

This commit is contained in:
badaix 2015-07-26 13:05:07 +02:00
parent b7d4034e43
commit 56389ad202
6 changed files with 114 additions and 107 deletions

View file

@ -39,7 +39,7 @@ public:
private: private:
void initAlsa(); void initAlsa();
void uninitAlsa(); void uninitAlsa();
void worker(); void worker();
snd_pcm_t* handle_; snd_pcm_t* handle_;
snd_pcm_uframes_t frames_; snd_pcm_uframes_t frames_;

View file

@ -38,55 +38,57 @@ BrowseAvahi::BrowseAvahi() : client_(NULL), sb_(NULL)
BrowseAvahi::~BrowseAvahi() BrowseAvahi::~BrowseAvahi()
{ {
if (sb_) if (sb_)
avahi_service_browser_free(sb_); avahi_service_browser_free(sb_);
if (client_) if (client_)
avahi_client_free(client_); avahi_client_free(client_);
if (simple_poll) if (simple_poll)
avahi_simple_poll_free(simple_poll); avahi_simple_poll_free(simple_poll);
} }
void BrowseAvahi::resolve_callback( void BrowseAvahi::resolve_callback(
AvahiServiceResolver *r, AvahiServiceResolver *r,
AVAHI_GCC_UNUSED AvahiIfIndex interface, AVAHI_GCC_UNUSED AvahiIfIndex interface,
AVAHI_GCC_UNUSED AvahiProtocol protocol, AVAHI_GCC_UNUSED AvahiProtocol protocol,
AvahiResolverEvent event, AvahiResolverEvent event,
const char *name, const char *name,
const char *type, const char *type,
const char *domain, const char *domain,
const char *host_name, const char *host_name,
const AvahiAddress *address, const AvahiAddress *address,
uint16_t port, uint16_t port,
AvahiStringList *txt, AvahiStringList *txt,
AvahiLookupResultFlags flags, AvahiLookupResultFlags flags,
AVAHI_GCC_UNUSED void* userdata) { AVAHI_GCC_UNUSED void* userdata)
{
BrowseAvahi* browseAvahi = static_cast<BrowseAvahi*>(userdata);
assert(r);
BrowseAvahi* browseAvahi = static_cast<BrowseAvahi*>(userdata); /* Called whenever a service has been resolved successfully or timed out */
assert(r);
/* Called whenever a service has been resolved successfully or timed out */ switch (event)
{
case AVAHI_RESOLVER_FAILURE:
logE << "(Resolver) Failed to resolve service '" << name << "' of type '" << type << "' in domain '" << domain << "': " << avahi_strerror(avahi_client_errno(avahi_service_resolver_get_client(r))) << "\n";
break;
switch (event) { case AVAHI_RESOLVER_FOUND:
case AVAHI_RESOLVER_FAILURE: {
logE << "(Resolver) Failed to resolve service '" << name << "' of type '" << type << "' in domain '" << domain << "': " << avahi_strerror(avahi_client_errno(avahi_service_resolver_get_client(r))) << "\n"; char a[AVAHI_ADDRESS_STR_MAX], *t;
break;
case AVAHI_RESOLVER_FOUND: { logO << "Service '" << name << "' of type '" << type << "' in domain '" << domain << "':\n";
char a[AVAHI_ADDRESS_STR_MAX], *t;
logO << "Service '" << name << "' of type '" << type << "' in domain '" << domain << "':\n"; avahi_address_snprint(a, sizeof(a), address);
avahi_address_snprint(a, sizeof(a), address);
browseAvahi->result_.host_ = host_name; browseAvahi->result_.host_ = host_name;
browseAvahi->result_.ip_ = a; browseAvahi->result_.ip_ = a;
browseAvahi->result_.port_ = port; browseAvahi->result_.port_ = port;
browseAvahi->result_.proto_ = protocol; browseAvahi->result_.proto_ = protocol;
browseAvahi->result_.valid_ = true; browseAvahi->result_.valid_ = true;
t = avahi_string_list_to_string(txt); t = avahi_string_list_to_string(txt);
logO logO
<< "\t" << host_name << ":" << port << "(" << a << ")\n" << "\t" << host_name << ":" << port << "(" << a << ")\n"
<< "\tTXT=" << t << "\n" << "\tTXT=" << t << "\n"
<< "\tProto=" << (int)protocol << "\n" << "\tProto=" << (int)protocol << "\n"
@ -96,100 +98,104 @@ void BrowseAvahi::resolve_callback(
<< "\twide_area: " << !!(flags & AVAHI_LOOKUP_RESULT_WIDE_AREA) << "\n" << "\twide_area: " << !!(flags & AVAHI_LOOKUP_RESULT_WIDE_AREA) << "\n"
<< "\tmulticast: " << !!(flags & AVAHI_LOOKUP_RESULT_MULTICAST) << "\n" << "\tmulticast: " << !!(flags & AVAHI_LOOKUP_RESULT_MULTICAST) << "\n"
<< "\tcached: " << !!(flags & AVAHI_LOOKUP_RESULT_CACHED) << "\n"; << "\tcached: " << !!(flags & AVAHI_LOOKUP_RESULT_CACHED) << "\n";
avahi_free(t); avahi_free(t);
} }
} }
avahi_service_resolver_free(r); avahi_service_resolver_free(r);
} }
void BrowseAvahi::browse_callback( void BrowseAvahi::browse_callback(
AvahiServiceBrowser *b, AvahiServiceBrowser *b,
AvahiIfIndex interface, AvahiIfIndex interface,
AvahiProtocol protocol, AvahiProtocol protocol,
AvahiBrowserEvent event, AvahiBrowserEvent event,
const char *name, const char *name,
const char *type, const char *type,
const char *domain, const char *domain,
AVAHI_GCC_UNUSED AvahiLookupResultFlags flags, AVAHI_GCC_UNUSED AvahiLookupResultFlags flags,
void* userdata) { void* userdata) {
// AvahiClient* client = (AvahiClient*)userdata; // AvahiClient* client = (AvahiClient*)userdata;
BrowseAvahi* browseAvahi = static_cast<BrowseAvahi*>(userdata); BrowseAvahi* browseAvahi = static_cast<BrowseAvahi*>(userdata);
assert(b); assert(b);
/* Called whenever a new services becomes available on the LAN or is removed from the LAN */ /* Called whenever a new services becomes available on the LAN or is removed from the LAN */
switch (event) { switch (event)
case AVAHI_BROWSER_FAILURE: {
case AVAHI_BROWSER_FAILURE:
logE << "(Browser) " << avahi_strerror(avahi_client_errno(avahi_service_browser_get_client(b))) << "\n";
avahi_simple_poll_quit(simple_poll);
return;
logE << "(Browser) " << avahi_strerror(avahi_client_errno(avahi_service_browser_get_client(b))) << "\n"; case AVAHI_BROWSER_NEW:
avahi_simple_poll_quit(simple_poll); logO << "(Browser) NEW: service '" << name << "' of type '" << type << "' in domain '" << domain << "'\n";
return;
case AVAHI_BROWSER_NEW: /* We ignore the returned resolver object. In the callback
logO << "(Browser) NEW: service '" << name << "' of type '" << type << "' in domain '" << domain << "'\n"; function we free it. If the server is terminated before
the callback function is called the server will free
the resolver for us. */
/* We ignore the returned resolver object. In the callback if (!(avahi_service_resolver_new(browseAvahi->client_, interface, protocol, name, type, domain, AVAHI_PROTO_UNSPEC, (AvahiLookupFlags)0, resolve_callback, userdata)))
function we free it. If the server is terminated before logE << "Failed to resolve service '" << name << "': " << avahi_strerror(avahi_client_errno(browseAvahi->client_)) << "\n";
the callback function is called the server will free
the resolver for us. */
if (!(avahi_service_resolver_new(browseAvahi->client_, interface, protocol, name, type, domain, AVAHI_PROTO_UNSPEC, (AvahiLookupFlags)0, resolve_callback, userdata))) break;
logE << "Failed to resolve service '" << name << "': " << avahi_strerror(avahi_client_errno(browseAvahi->client_)) << "\n";
break; case AVAHI_BROWSER_REMOVE:
logO << "(Browser) REMOVE: service '" << name << "' of type '" << type << "' in domain '" << domain << "'\n";
break;
case AVAHI_BROWSER_REMOVE: case AVAHI_BROWSER_ALL_FOR_NOW:
logO << "(Browser) REMOVE: service '" << name << "' of type '" << type << "' in domain '" << domain << "'\n"; case AVAHI_BROWSER_CACHE_EXHAUSTED:
break; logO << "(Browser) " << (event == AVAHI_BROWSER_CACHE_EXHAUSTED ? "CACHE_EXHAUSTED" : "ALL_FOR_NOW") << "\n";
break;
case AVAHI_BROWSER_ALL_FOR_NOW: }
case AVAHI_BROWSER_CACHE_EXHAUSTED:
logO << "(Browser) " << (event == AVAHI_BROWSER_CACHE_EXHAUSTED ? "CACHE_EXHAUSTED" : "ALL_FOR_NOW") << "\n";
break;
}
} }
void BrowseAvahi::client_callback(AvahiClient *c, AvahiClientState state, AVAHI_GCC_UNUSED void * userdata) { void BrowseAvahi::client_callback(AvahiClient *c, AvahiClientState state, AVAHI_GCC_UNUSED void * userdata) {
assert(c); assert(c);
/* Called whenever the client or server state changes */ /* Called whenever the client or server state changes */
// BrowseAvahi* browseAvahi = static_cast<BrowseAvahi*>(userdata); // BrowseAvahi* browseAvahi = static_cast<BrowseAvahi*>(userdata);
if (state == AVAHI_CLIENT_FAILURE) { if (state == AVAHI_CLIENT_FAILURE)
logE << "Server connection failure: " << avahi_strerror(avahi_client_errno(c)) << "\n"; {
avahi_simple_poll_quit(simple_poll); logE << "Server connection failure: " << avahi_strerror(avahi_client_errno(c)) << "\n";
} avahi_simple_poll_quit(simple_poll);
}
} }
bool BrowseAvahi::browse(const std::string& serviceName, int proto, AvahiResult& result, int timeout) bool BrowseAvahi::browse(const std::string& serviceName, int proto, AvahiResult& result, int timeout)
{ {
int error; int error;
/* Allocate main loop object */ /* Allocate main loop object */
if (!(simple_poll = avahi_simple_poll_new())) { if (!(simple_poll = avahi_simple_poll_new()))
logE << "Failed to create simple poll object.\n"; {
goto fail; logE << "Failed to create simple poll object.\n";
} goto fail;
}
/* Allocate a new client */ /* Allocate a new client */
client_ = avahi_client_new(avahi_simple_poll_get(simple_poll), (AvahiClientFlags)0, client_callback, this, &error); client_ = avahi_client_new(avahi_simple_poll_get(simple_poll), (AvahiClientFlags)0, client_callback, this, &error);
/* Check wether creating the client object succeeded */ /* Check wether creating the client object succeeded */
if (!client_) { if (!client_)
logE << "Failed to create client: " << avahi_strerror(error) << "\n"; {
goto fail; logE << "Failed to create client: " << avahi_strerror(error) << "\n";
} goto fail;
}
/* Create the service browser */ /* Create the service browser */
if (!(sb_ = avahi_service_browser_new(client_, AVAHI_IF_UNSPEC, proto, serviceName.c_str(), NULL, (AvahiLookupFlags)0, browse_callback, this))) { if (!(sb_ = avahi_service_browser_new(client_, AVAHI_IF_UNSPEC, proto, serviceName.c_str(), NULL, (AvahiLookupFlags)0, browse_callback, this)))
logE << "Failed to create service browser: " << avahi_strerror(avahi_client_errno(client_)) << "\n"; {
goto fail; logE << "Failed to create service browser: " << avahi_strerror(avahi_client_errno(client_)) << "\n";
} goto fail;
}
result_.valid_ = false; result_.valid_ = false;
while (timeout > 0) while (timeout > 0)
@ -200,7 +206,7 @@ bool BrowseAvahi::browse(const std::string& serviceName, int proto, AvahiResult&
{ {
result = result_; result = result_;
return true; return true;
} }
} }
fail: fail:

View file

@ -47,9 +47,9 @@ private:
static void resolve_callback(AvahiServiceResolver *r, AVAHI_GCC_UNUSED AvahiIfIndex interface, AVAHI_GCC_UNUSED AvahiProtocol protocol, AvahiResolverEvent event, const char *name, const char *type, const char *domain, const char *host_name, const AvahiAddress *address, uint16_t port, AvahiStringList *txt, AvahiLookupResultFlags flags, AVAHI_GCC_UNUSED void* userdata); static void resolve_callback(AvahiServiceResolver *r, AVAHI_GCC_UNUSED AvahiIfIndex interface, AVAHI_GCC_UNUSED AvahiProtocol protocol, AvahiResolverEvent event, const char *name, const char *type, const char *domain, const char *host_name, const AvahiAddress *address, uint16_t port, AvahiStringList *txt, AvahiLookupResultFlags flags, AVAHI_GCC_UNUSED void* userdata);
static void browse_callback(AvahiServiceBrowser *b, AvahiIfIndex interface, AvahiProtocol protocol, AvahiBrowserEvent event, const char *name, const char *type, const char *domain, AVAHI_GCC_UNUSED AvahiLookupResultFlags flags, void* userdata); static void browse_callback(AvahiServiceBrowser *b, AvahiIfIndex interface, AvahiProtocol protocol, AvahiBrowserEvent event, const char *name, const char *type, const char *domain, AVAHI_GCC_UNUSED AvahiLookupResultFlags flags, void* userdata);
static void client_callback(AvahiClient *c, AvahiClientState state, AVAHI_GCC_UNUSED void * userdata); static void client_callback(AvahiClient *c, AvahiClientState state, AVAHI_GCC_UNUSED void * userdata);
AvahiClient* client_; AvahiClient* client_;
AvahiResult result_; AvahiResult result_;
AvahiServiceBrowser* sb_; AvahiServiceBrowser* sb_;
}; };

View file

@ -20,7 +20,6 @@
#include <iostream> #include <iostream>
#include <string> #include <string>
#include <memory> #include <memory>
#include <unistd.h>
#include "oggDecoder.h" #include "oggDecoder.h"
#include "pcmDecoder.h" #include "pcmDecoder.h"
#include "flacDecoder.h" #include "flacDecoder.h"
@ -123,7 +122,7 @@ void Controller::worker()
decoder_->setHeader(headerChunk.get()); decoder_->setHeader(headerChunk.get());
msg::Request timeReq(kTime); msg::Request timeReq(kTime);
for (size_t n=0; n<100 && active_; ++n) for (size_t n=0; n<50 && active_; ++n)
{ {
shared_ptr<msg::Time> reply = clientConnection_->sendReq<msg::Time>(&timeReq, chronos::msec(2000)); shared_ptr<msg::Time> reply = clientConnection_->sendReq<msg::Time>(&timeReq, chronos::msec(2000));
if (reply) if (reply)

View file

@ -276,7 +276,10 @@ bool Stream::getPlayerChunk(void* outputBuffer, const cs::usec& outputBufferDacT
} }
} }
// framesCorrection = number of frames to be read more or less to get in-sync
long framesCorrection = correction.count()*format_.usRate(); long framesCorrection = correction.count()*format_.usRate();
// sample rate correction
if ((correctAfterXFrames_ != 0) && (playedFrames_ >= (unsigned long)abs(correctAfterXFrames_))) if ((correctAfterXFrames_ != 0) && (playedFrames_ >= (unsigned long)abs(correctAfterXFrames_)))
{ {
framesCorrection += (correctAfterXFrames_ > 0)?1:-1; framesCorrection += (correctAfterXFrames_ > 0)?1:-1;

View file

@ -17,7 +17,6 @@
USA. USA.
***/ ***/
#include <unistd.h>
#include "publishAvahi.h" #include "publishAvahi.h"
#include "common/log.h" #include "common/log.h"
@ -42,7 +41,7 @@ void PublishAvahi::publish(const std::vector<AvahiService>& services)
int error; int error;
/* Allocate main loop object */ /* Allocate main loop object */
if (!(simple_poll = avahi_simple_poll_new())) if (!(simple_poll = avahi_simple_poll_new()))
{ {
logE << "Failed to create simple poll object.\n"; logE << "Failed to create simple poll object.\n";
} }
@ -51,7 +50,7 @@ void PublishAvahi::publish(const std::vector<AvahiService>& services)
client = avahi_client_new(avahi_simple_poll_get(simple_poll), AVAHI_CLIENT_IGNORE_USER_CONFIG, client_callback, this, &error); client = avahi_client_new(avahi_simple_poll_get(simple_poll), AVAHI_CLIENT_IGNORE_USER_CONFIG, client_callback, this, &error);
/* Check wether creating the client object succeeded */ /* Check wether creating the client object succeeded */
if (!client) if (!client)
{ {
logE << "Failed to create client: " << avahi_strerror(error) << "\n"; logE << "Failed to create client: " << avahi_strerror(error) << "\n";
} }
@ -61,7 +60,7 @@ void PublishAvahi::publish(const std::vector<AvahiService>& services)
} }
void PublishAvahi::worker() void PublishAvahi::worker()
{ {
while (active_ && (avahi_simple_poll_iterate(simple_poll, 100) == 0)); while (active_ && (avahi_simple_poll_iterate(simple_poll, 100) == 0));
} }
@ -166,7 +165,7 @@ void PublishAvahi::create_services(AvahiClient *c) {
/* Add the same service for BSD LPR */ /* Add the same service for BSD LPR */
for (size_t n=0; n<services.size(); ++n) for (size_t n=0; n<services.size(); ++n)
{ {
if ((ret = avahi_entry_group_add_service(group, AVAHI_IF_UNSPEC, services[n].proto_, AvahiPublishFlags(0), name, services[n].name_.c_str(), NULL, NULL, services[n].port_, NULL)) < 0) if ((ret = avahi_entry_group_add_service(group, AVAHI_IF_UNSPEC, services[n].proto_, AvahiPublishFlags(0), name, services[n].name_.c_str(), NULL, NULL, services[n].port_, NULL)) < 0)
{ {
if (ret == AVAHI_ERR_COLLISION) if (ret == AVAHI_ERR_COLLISION)