Skip to content

Commit

Permalink
Added a bidirectional transmission testing application. (#348)
Browse files Browse the repository at this point in the history
- Added a relay bidirectional application.
- Added relay classes in testmedia.
- Reused epoll direction enum. 
- Added possibility for verbose locking.
  • Loading branch information
ethouris authored and rndi committed Apr 20, 2018
1 parent d9aa9e7 commit 1b6aa2b
Show file tree
Hide file tree
Showing 9 changed files with 900 additions and 146 deletions.
4 changes: 4 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -732,6 +732,10 @@ if ( ENABLE_CXX11 )
srt_add_testprogram(srt-test-file)
srt_make_application(srt-test-file)
endif()

srt_add_testprogram(srt-test-relay)
srt_make_application(srt-test-relay)
target_compile_definitions(srt-test-relay PUBLIC -DSRT_ENABLE_VERBOSE_LOCK)
endif()

endif()
Expand Down
41 changes: 41 additions & 0 deletions apps/verbose.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,59 @@ namespace Verbose
{
bool on = false;
std::ostream* cverb = &std::cerr;
#if SRT_ENABLE_VERBOSE_LOCK
std::mutex vlock;
#endif

Log& Log::operator<<(LogNoEol)
{
noeol = true;
return *this;
}

#if SRT_ENABLE_VERBOSE_LOCK
Log& Log::operator<<(LogLock)
{
lockline = true;
return *this;
}
#endif

Log::~Log()
{
if (on && !noeol)
{
#if SRT_ENABLE_VERBOSE_LOCK
if (lockline)
{
// Lock explicitly, as requested, and wait for the opportunity.
vlock.lock();
}
else if (vlock.try_lock())
{
// Successfully locked, so unlock immediately, locking wasn't requeted.
vlock.unlock();
}
else
{
// Failed to lock, which means that some other thread has locked it first.
// This means that some other thread wants to print the whole line and doesn't
// want to be disturbed during this process. Lock the thread then as this is
// the only way to wait until it's unlocked. However, do not block your printing
// with locking, because you were not requested to lock (treat this mutex as
// an entry semaphore, which may only occasionally block the whole line).
vlock.lock();
vlock.unlock();
}
#endif
(*cverb) << std::endl;
#if SRT_ENABLE_VERBOSE_LOCK

// If lockline is set, the lock was requested and WAS DONE, so unlock.
// Otherwise locking WAS NOT DONE.
if (lockline)
vlock.unlock();
#endif
}
}
}
25 changes: 24 additions & 1 deletion apps/verbose.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@
#define INC__VERBOSE_HPP

#include <iostream>
#if SRT_ENABLE_VERBOSE_LOCK
#include <mutex>
#endif

namespace Verbose
{
Expand All @@ -20,13 +23,24 @@ extern bool on;
extern std::ostream* cverb;

struct LogNoEol { LogNoEol() {} };
#if SRT_ENABLE_VERBOSE_LOCK
struct LogLock { LogLock() {} };
#endif

class Log
{
bool noeol;
#if SRT_ENABLE_VERBOSE_LOCK
bool lockline;
#endif
public:

Log(): noeol(false) {}
Log():
noeol(false)
#if SRT_ENABLE_VERBOSE_LOCK
,lockline(false)
#endif
{}

template <class V>
Log& operator<<(const V& arg)
Expand All @@ -37,13 +51,22 @@ class Log
(*cverb) << arg;
return *this;
}

Log& operator<<(LogNoEol);
#if SRT_ENABLE_VERBOSE_LOCK
Log& operator<<(LogLock);
#endif
~Log();
};

}

inline Verbose::Log Verb() { return Verbose::Log(); }

// Manipulator tags
static const Verbose::LogNoEol VerbNoEOL;
#if SRT_ENABLE_VERBOSE_LOCK
static const Verbose::LogLock VerbLock;
#endif

#endif
9 changes: 9 additions & 0 deletions srtcore/srt.h
Original file line number Diff line number Diff line change
Expand Up @@ -464,6 +464,7 @@ enum SRT_KM_STATE

enum SRT_EPOLL_OPT
{
SRT_EPOLL_OPT_NONE = 0, // fallback
// this values are defined same as linux epoll.h
// so that if system values are used by mistake, they should have the same effect
SRT_EPOLL_IN = 0x1,
Expand All @@ -478,6 +479,14 @@ inline SRT_EPOLL_OPT operator|(SRT_EPOLL_OPT a1, SRT_EPOLL_OPT a2)
{
return SRT_EPOLL_OPT( (int)a1 | (int)a2 );
}

inline bool operator&(int flags, SRT_EPOLL_OPT eflg)
{
// Using an enum prevents treating int automatically as enum,
// requires explicit enum to be passed here, and minimizes the
// risk that the right side value will contain multiple flags.
return flags & int(eflg);
}
#endif


Expand Down
Loading

0 comments on commit 1b6aa2b

Please sign in to comment.