Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[devel] Fixed atomic setting of locked line in Verb #3004

Merged
merged 2 commits into from
Aug 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions apps/verbose.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#define INC_SRT_VERBOSE_HPP

#include <iostream>
#include "atomic.h"

namespace Verbose
{
Expand All @@ -25,13 +26,17 @@ struct LogLock { LogLock() {} };
class Log
{
bool noeol = false;
bool lockline = false;
srt::sync::atomic<bool> lockline;

// Disallow creating dynamic objects
void* operator new(size_t) = delete;

public:

Log() {}
Log(const Log& ) {}
Fixed Show fixed Hide fixed


template <class V>
Log& operator<<(const V& arg)
{
Expand Down Expand Up @@ -71,7 +76,7 @@ inline void Print(Log& ) {}
template <typename Arg1, typename... Args>
inline void Print(Log& out, Arg1&& arg1, Args&&... args)
{
out << std::forward(arg1);
out << arg1;
Print(out, args...);
}

Expand All @@ -87,6 +92,13 @@ inline void Verb(Args&&... args)
Verbose::Print(log, args...);
}

template <typename... Args>
inline void Verror(Args&&... args)
{
Verbose::ErrLog log;
Verbose::Print(log, args...);
}


// Manipulator tags
static const Verbose::LogNoEol VerbNoEOL;
Expand Down
52 changes: 26 additions & 26 deletions testing/srt-test-live.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ bool CheckMediaSpec(const string& prefix, const vector<string>& spec, string& w_
for (string& a: adrs)
w_outspec += a + ",";

Verb() << "NOTE: " << prefix << " specification set as: " << (w_outspec);
Verb("NOTE: ", prefix, " specification set as: ", (w_outspec));

return true;
}
Expand All @@ -294,20 +294,20 @@ extern "C" int SrtCheckGroupHook(void* , SRTSOCKET acpsock, int , const sockaddr
int type;
int size = sizeof type;
srt_getsockflag(acpsock, SRTO_GROUPCONNECT, &type, &size);
Verb() << "listener: @" << acpsock << " - accepting " << (type ? "GROUP" : "SINGLE") << VerbNoEOL;
Verb("listener: @", acpsock, " - accepting ", (type ? "GROUP" : "SINGLE"), VerbNoEOL);
if (type != 0)
{
SRT_GROUP_TYPE gt;
size = sizeof gt;
if (-1 != srt_getsockflag(acpsock, SRTO_GROUPTYPE, &gt, &size))
{
if (gt < Size(gtypes))
Verb() << " type=" << gtypes[gt] << VerbNoEOL;
Verb(" type=", gtypes[gt], VerbNoEOL);
else
Verb() << " type=" << int(gt) << VerbNoEOL;
Verb(" type=", int(gt), VerbNoEOL);
}
}
Verb() << " connection";
Verb(" connection");

return 0;
}
Expand All @@ -317,7 +317,7 @@ extern "C" int SrtUserPasswordHook(void* , SRTSOCKET acpsock, int hsv, const soc
{
if (hsv < 5)
{
Verb() << "SrtUserPasswordHook: HS version 4 doesn't support extended handshake";
Verb("SrtUserPasswordHook: HS version 4 doesn't support extended handshake");
return -1;
}

Expand Down Expand Up @@ -818,7 +818,7 @@ int main( int argc, char** argv )
return 0;
}

Verb() << "MEDIA CREATION FAILED: " << x.what() << " - exiting.";
Verb("MEDIA CREATION FAILED: ", x.what(), " - exiting.");

// Don't speak anything when no -v option.
// (the "requested interrupt" will be printed anyway)
Expand Down Expand Up @@ -847,10 +847,10 @@ int main( int argc, char** argv )

if (transmit_use_sourcetime && src->uri.type() != UriParser::SRT)
{
Verb() << "WARNING: -st option is effective only if the target type is SRT";
Verb("WARNING: -st option is effective only if the target type is SRT");
}

Verb() << "STARTING TRANSMISSION: '" << source_spec << "' --> '" << target_spec << "'";
Verb("STARTING TRANSMISSION: '", source_spec, "' --> '", target_spec, "'");

// After the time has been spent in the creation
// (including waiting for connection)
Expand All @@ -876,41 +876,41 @@ int main( int argc, char** argv )
{
if (stoptime == 0 && timeout != -1 )
{
Verb() << "[." << VerbNoEOL;
Verb("[.", VerbNoEOL);
alarm(timeout);
}
else
{
alarm(0);
}
Verb() << " << ... " << VerbNoEOL;
Verb(", ... ", VerbNoEOL);
g_interrupt_reason = "reading";
const MediaPacket& data = src->Read(chunk);
Verb() << " << " << data.payload.size() << " -> " << VerbNoEOL;
Verb(", ", data.payload.size(), " -> ", VerbNoEOL);
if ( data.payload.empty() && src->End() )
{
Verb() << "EOS";
Verb("EOS");
break;
}
g_interrupt_reason = "writing";
tar->Write(data);
if (stoptime == 0 && timeout != -1 )
{
Verb() << ".] " << VerbNoEOL;
Verb(".] ", VerbNoEOL);
alarm(0);
}

if ( tar->Broken() )
{
Verb() << " OUTPUT broken";
Verb(" OUTPUT broken");
break;
}

Verb() << "sent";
Verb("sent");

if (::transmit_int_state)
{
Verror() << "\n (interrupted on request)";
Verror("\n (interrupted on request)");
break;
}

Expand All @@ -922,7 +922,7 @@ int main( int argc, char** argv )
int remain = int(stoptime - final_delay - elapsed);
if (remain < 0)
{
Verror() << "\n (interrupted on timeout: elapsed " << elapsed << "s) - waiting " << final_delay << "s for cleanup";
Verror("\n (interrupted on timeout: elapsed ", elapsed, "s) - waiting ", final_delay, "s for cleanup");
this_thread::sleep_for(chrono::seconds(final_delay));
break;
}
Expand All @@ -934,42 +934,42 @@ int main( int argc, char** argv )

if (!skip_flushing)
{
Verror() << "(DEBUG) EOF when reading file. Looping until the sending bufer depletes.\n";
Verror("(DEBUG) EOF when reading file. Looping until the sending bufer depletes.\n");
for (;;)
{
size_t still = tar->Still();
if (still == 0)
{
Verror() << "(DEBUG) DEPLETED. Done.\n";
Verror("(DEBUG) DEPLETED. Done.\n");
break;
}

Verror() << "(DEBUG)... still " << still << " bytes (sleep 1s)\n";
Verror("(DEBUG)... still ", still, " bytes (sleep 1s)\n");
this_thread::sleep_for(chrono::seconds(1));
}
}
} catch (std::exception& x) { // Catches TransmissionError and AlarmExit

if (stoptime != 0 && ::timer_state)
{
Verror() << "Exit on timeout.";
Verror("Exit on timeout.");
}
else if (::transmit_int_state)
{
Verror() << "Exit on interrupt.";
Verror("Exit on interrupt.");
// Do nothing.
}
else
{
Verror() << "STD EXCEPTION: " << x.what();
Verror("STD EXCEPTION: ", x.what());
}

if ( crashonx )
throw;

if (final_delay > 0)
{
Verror() << "Waiting " << final_delay << "s for possible cleanup...";
Verror("Waiting ", final_delay, "s for possible cleanup...");
this_thread::sleep_for(chrono::seconds(final_delay));
}
if (stoptime != 0 && ::timer_state)
Expand All @@ -979,7 +979,7 @@ int main( int argc, char** argv )

} catch (...) {

Verror() << "UNKNOWN type of EXCEPTION";
Verror("UNKNOWN type of EXCEPTION");
if ( crashonx )
throw;

Expand Down
4 changes: 2 additions & 2 deletions testing/srt-test-multiplex.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -403,15 +403,15 @@ void Stall()
++i_next;
if (i->has_quit)
{
Verb() << "Found QUIT mediumpair: " << i->name << " - removing from base";
Verb("Found QUIT mediumpair: ", i->name, " - removing from base");
i->Stop();
g_media_base.media.erase(i);
}
}

if (g_media_base.media.empty())
{
Verb() << "All media have quit. Marking exit.";
Verb("All media have quit. Marking exit.");
break;
}
}
Expand Down
Loading