Skip to content
Snippets Groups Projects
Commit 6ac8a5db authored by Guillaume Roguez's avatar Guillaume Roguez Committed by Tristan Matthews
Browse files

daemon: (video) replace anonymous namespace by static keyword

Also minor code cleanup.

Rationale:
The C++ standard has un-deprecated the use of the static keyword.
But the superiority of anonymous namespaces is mainly for type 
declarations (including structures and classes).

For variables and functions, the static keyword is functionally
equivalent to using an anonymous namespace.

But there is a major drawback with the latter!
Name mangling for anonymous namespaces is such that it's awkward
to type/find a local symbol declared in them when using a debugger
such as gdb.

Refs #50143

Change-Id: I925af61d14db08fafa37bfbfeedde95feadd0948
parent f13705c0
Branches
Tags
No related merge requests found
......@@ -39,18 +39,13 @@
#include <string>
#include <iostream>
std::map<std::string, std::string> encoders_;
std::vector<std::string> installed_video_codecs_;
namespace {
using std::string;
using std::map;
using std::vector;
map<string, string> encoders_;
vector<string> installed_video_codecs_;
void findInstalledVideoCodecs()
static void
findInstalledVideoCodecs()
{
vector<string> libav_codecs;
std::vector<std::string> libav_codecs;
AVCodec *p = NULL;
while ((p = av_codec_next(p)))
if (p->type == AVMEDIA_TYPE_VIDEO)
......@@ -64,20 +59,18 @@ void findInstalledVideoCodecs()
}
}
} // end anon namespace
namespace libav_utils {
vector<string> getVideoCodecList()
std::vector<std::string> getVideoCodecList()
{
if (installed_video_codecs_.empty())
findInstalledVideoCodecs();
return installed_video_codecs_;
}
namespace {
// protect libav/ffmpeg access with pthreads
int avcodecManageMutex(void **data, enum AVLockOp op)
static int
avcodecManageMutex(void **data, enum AVLockOp op)
{
pthread_mutex_t **mutex = reinterpret_cast<pthread_mutex_t**>(data);
int ret = 0;
......@@ -108,7 +101,12 @@ int avcodecManageMutex(void **data, enum AVLockOp op)
return AVERROR(ret);
}
void init_once()
std::map<std::string, std::string> encodersMap()
{
return encoders_;
}
static void init_once()
{
av_register_all();
avdevice_register_all();
......@@ -141,13 +139,6 @@ void init_once()
findInstalledVideoCodecs();
}
}
map<string, string> encodersMap()
{
return encoders_;
}
static pthread_once_t already_called = PTHREAD_ONCE_INIT;
void sfl_avcodec_init()
......
......@@ -48,12 +48,10 @@
# define SOCK_NONBLOCK O_NONBLOCK
#endif
namespace {
static const int NET_POLL_TIMEOUT = 100; /* poll() timeout in ms */
int ff_network_wait_fd(int fd)
static int
ff_network_wait_fd(int fd)
{
struct pollfd p = { fd, POLLOUT, 0 };
int ret;
......@@ -61,7 +59,8 @@ int ff_network_wait_fd(int fd)
return ret < 0 ? errno : p.revents & (POLLOUT | POLLERR | POLLHUP) ? 0 : -EAGAIN;
}
struct addrinfo* udp_resolve_host(const char *node, int service)
static struct
addrinfo* udp_resolve_host(const char *node, int service)
{
struct addrinfo hints, *res = 0;
int error;
......@@ -81,8 +80,8 @@ struct addrinfo* udp_resolve_host(const char *node, int service)
return res;
}
unsigned udp_set_url(struct sockaddr_storage *addr,
const char *hostname, int port)
static unsigned
udp_set_url(struct sockaddr_storage *addr, const char *hostname, int port)
{
struct addrinfo *res0;
int addr_len;
......@@ -96,8 +95,8 @@ unsigned udp_set_url(struct sockaddr_storage *addr,
return addr_len;
}
int udp_socket_create(sockaddr_storage *addr, socklen_t *addr_len,
int local_port)
static int
udp_socket_create(sockaddr_storage *addr, socklen_t *addr_len, int local_port)
{
int udp_fd = -1;
struct addrinfo *res0 = NULL, *res = NULL;
......@@ -135,12 +134,10 @@ int udp_socket_create(sockaddr_storage *addr, socklen_t *addr_len,
return udp_fd;
}
const int RTP_BUFFER_SIZE = 1472;
}
namespace sfl_video {
static const int RTP_BUFFER_SIZE = 1472;
SocketPair::SocketPair(const char *uri, int localPort) :
rtcpWriteMutex_(),
rtpHandle_(0),
......
......@@ -39,18 +39,18 @@
#include <cstring>
#include <cassert>
namespace {
static std::atomic<bool> done(false);
std::atomic<bool> done(false);
void signal_handler(int /*sig*/)
static void
signal_handler(int /*sig*/)
{
done = true;
}
const char test_data[] = "abcdefghijklmnopqrstuvwxyz";
static const char test_data[] = "abcdefghijklmnopqrstuvwxyz";
void sink_thread()
static void
sink_thread()
{
sfl_video::SHMSink sink("bob");;
if (!sink.start())
......@@ -66,7 +66,8 @@ void sink_thread()
std::cerr << "Exitting sink thread" << std::endl;
}
void run_client()
static void
run_client()
{
SHMSrc src("bob");;
bool started = false;
......@@ -92,7 +93,8 @@ void run_client()
std::cerr << "Got characters, exitting client process" << std::endl;
}
void run_daemon()
static void
run_daemon()
{
std::thread bob(sink_thread);
/* Wait for child process. */
......@@ -116,9 +118,6 @@ void run_daemon()
// wait for thread
bob.join();
}
} // end anonymous namespace
int main()
{
signal(SIGINT, signal_handler);
......
......@@ -194,7 +194,10 @@ namespace {
const std::string name_;
};
int getNumber(const string &name, size_t *sharp)
}
static int
getNumber(const string &name, size_t *sharp)
{
size_t len = name.length();
// name is too short to be numbered
......@@ -214,7 +217,8 @@ namespace {
return -1;
}
void giveUniqueName(VideoV4l2Device &dev, const vector<VideoV4l2Device> &devices)
static void
giveUniqueName(VideoV4l2Device &dev, const vector<VideoV4l2Device> &devices)
{
start:
for (auto &item : devices) {
......@@ -232,7 +236,6 @@ start:
}
}
}
} // end anonymous namespace
VideoDeviceMonitorImpl::~VideoDeviceMonitorImpl()
{
......
......@@ -122,8 +122,8 @@ static const unsigned pixelformats_supported[] = {
*
*/
namespace {
unsigned int pixelformat_score(unsigned pixelformat)
static unsigned int
pixelformat_score(unsigned pixelformat)
{
for (const auto &item : pixelformats_supported)
if (item == pixelformat)
......@@ -131,7 +131,6 @@ unsigned int pixelformat_score(unsigned pixelformat)
return UINT_MAX - 1;
}
}
VideoV4l2Size::VideoV4l2Size(unsigned height, unsigned width) :
height(height), width(width), rates_() {}
......@@ -259,14 +258,13 @@ VideoV4l2Channel::getSizes(int fd, unsigned int pixelformat)
return fmt.fmt.pix.pixelformat;
}
namespace {
bool isCIF(const VideoV4l2Size &size)
static bool
isCIF(const VideoV4l2Size &size)
{
const unsigned CIF_WIDTH = 352;
const unsigned CIF_HEIGHT = 288;
return size.width == CIF_WIDTH and size.height == CIF_HEIGHT;
}
}
// Put CIF resolution (352x288) first in the list since it is more prevalent in
// VoIP
......@@ -327,7 +325,6 @@ VideoV4l2Size VideoV4l2Channel::getSize(const string &name) const
return sizes_.back();
}
VideoV4l2Device::VideoV4l2Device(const string &device) :
device(device), name(), channels_()
{
......
......@@ -210,14 +210,13 @@ VideoEncoder::startIO()
av_dump_format(outputCtx_, 0, outputCtx_->filename, 1);
}
namespace {
void print_averror(const char *funcname, int err)
static void
print_averror(const char *funcname, int err)
{
char errbuf[64];
av_strerror(err, errbuf, sizeof(errbuf));
ERROR("%s failed: %s", funcname, errbuf);
}
}
int VideoEncoder::encode(VideoFrame &input, bool is_keyframe, int64_t frame_number)
{
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment