Skip to content
Merged
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
30 changes: 12 additions & 18 deletions src/rtpstream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
#include <vector>
#include <errno.h>
#include <sstream>
#include <fcntl.h>

/* stub to add extra debugging/logging... */
static void debugprint(const char* format, ...)
Expand Down Expand Up @@ -151,27 +152,20 @@ class DebugFile

bool open(const char* filename)
{
if (fp)
{
return true;
}
std::lock_guard lock(mutex);
if (!fp)
{
fp = fopen(filename, "w");
}
if (fp) return true;
int fd = ::open(filename, O_WRONLY | O_CREAT | O_TRUNC, 0644);
if (fd < 0) return false;
fp = fdopen(fd, "w");
return !!fp;
}

void close()
{
std::lock_guard lock(mutex);
if (fp)
{
std::lock_guard lock(mutex);
if (fp)
{
fclose(fp);
}
fclose(fp);
fp = nullptr;
}
}
Expand All @@ -196,11 +190,11 @@ class DebugFile
void printVector(char const *note, std::vector<unsigned long> const &v) const;
void printf(const char* format, ...) const
{
std::lock_guard lock(mutex);
if (!fp)
{
return;
}
std::lock_guard lock(mutex);
va_list args;
va_start(args, format);
// fprintf(fp, "TID: %lu ", tid_self());
Expand Down Expand Up @@ -336,11 +330,11 @@ void DebugFile::printHex(
int moreinfo
) const
{
std::lock_guard lock(mutex);
if (!fp || !note || !string || !rtpcheck_debug)
{
return;
}
std::lock_guard lock(mutex);
fprintf(fp, "TID: %lu %s %u 0x%llx %d [", tid_self(), note, size, extrainfo, moreinfo);
for (unsigned int i = 0; i < size; i++)
{
Expand All @@ -351,11 +345,11 @@ void DebugFile::printHex(

void DebugFile::printVector(char const* note, std::vector<unsigned long> const &v) const
{
std::lock_guard lock(mutex);
if (!fp || !note || !rtpcheck_debug)
{
return;
}
std::lock_guard lock(mutex);
fprintf(fp, "TID: %lu %s\n", tid_self(), note);
for (unsigned int i = 0; i < v.size(); i++)
{
Expand All @@ -365,11 +359,11 @@ void DebugFile::printVector(char const* note, std::vector<unsigned long> const &

void RtpEchoDebugFile::printReceived(unsigned char const* data, unsigned int size) const
{
std::lock_guard lock(mutex);
if (!fp || !data)
{
return;
}
std::lock_guard lock(mutex);
fprintf(fp, "DATA SUCCESSFULLY RECEIVED [%s] nr = %u...",
type == Type::Audio ? "AUDIO" : "VIDEO",
size);
Expand All @@ -382,11 +376,11 @@ void RtpEchoDebugFile::printReceived(unsigned char const* data, unsigned int siz

void SrtpDebugFile::printCrypto(const SrtpInfoParams &p) const
{
std::lock_guard lock(mutex);
if (!fp)
{
return;
}
std::lock_guard lock(mutex);
fprintf(fp, "found : %d\n", p.found);
fprintf(fp, "primary_cryptotag : %d\n", p.primary_cryptotag);
fprintf(fp, "secondary_cryptotag : %d\n", p.secondary_cryptotag);
Expand Down
Loading