Save recent Widevine CDM logs
Bug: 162255728 Test: cdm unit tests Change-Id: Ibc0daf374bedd8ac2a9a0515835e2775045962a7
This commit is contained in:
@@ -7,6 +7,11 @@
|
|||||||
#ifndef WVCDM_UTIL_LOG_H_
|
#ifndef WVCDM_UTIL_LOG_H_
|
||||||
#define WVCDM_UTIL_LOG_H_
|
#define WVCDM_UTIL_LOG_H_
|
||||||
|
|
||||||
|
#include <cstdint>
|
||||||
|
#include <deque>
|
||||||
|
#include <mutex>
|
||||||
|
#include <string>
|
||||||
|
#include <vector>
|
||||||
#include "util_common.h"
|
#include "util_common.h"
|
||||||
|
|
||||||
namespace wvcdm {
|
namespace wvcdm {
|
||||||
@@ -27,6 +32,24 @@ typedef enum {
|
|||||||
|
|
||||||
extern LogPriority g_cutoff;
|
extern LogPriority g_cutoff;
|
||||||
|
|
||||||
|
struct LogMessage {
|
||||||
|
int64_t time_ms_;
|
||||||
|
LogPriority priority_;
|
||||||
|
std::string message_;
|
||||||
|
};
|
||||||
|
|
||||||
|
class LogBuffer {
|
||||||
|
public:
|
||||||
|
static const int MAX_CAPACITY = 100;
|
||||||
|
void addLog(const LogMessage& log);
|
||||||
|
std::vector<LogMessage> getLogs();
|
||||||
|
private:
|
||||||
|
std::deque<LogMessage> buffer_;
|
||||||
|
std::mutex mutex_;
|
||||||
|
};
|
||||||
|
|
||||||
|
extern LogBuffer g_logbuf;
|
||||||
|
|
||||||
// Enable/disable verbose logging (LOGV).
|
// Enable/disable verbose logging (LOGV).
|
||||||
// This function is supplied for cases where the system layer does not
|
// This function is supplied for cases where the system layer does not
|
||||||
// initialize logging. This is also needed to initialize logging in
|
// initialize logging. This is also needed to initialize logging in
|
||||||
|
|||||||
@@ -26,7 +26,9 @@
|
|||||||
|
|
||||||
#include <stdarg.h>
|
#include <stdarg.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
#include <sys/time.h>
|
||||||
|
|
||||||
|
#include <mutex>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -38,8 +40,20 @@
|
|||||||
|
|
||||||
namespace wvcdm {
|
namespace wvcdm {
|
||||||
|
|
||||||
|
namespace {
|
||||||
|
int64_t GetCurrentTimeMs() {
|
||||||
|
struct timeval tv{};
|
||||||
|
gettimeofday(&tv, NULL);
|
||||||
|
auto msec1 = static_cast<int64_t>(tv.tv_sec) * 1000;
|
||||||
|
auto msec2 = static_cast<int64_t>(tv.tv_usec) / 1000;
|
||||||
|
return msec1 + msec2;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
LogPriority g_cutoff = LOG_VERBOSE;
|
LogPriority g_cutoff = LOG_VERBOSE;
|
||||||
|
|
||||||
|
LogBuffer g_logbuf;
|
||||||
|
|
||||||
void InitLogging() {}
|
void InitLogging() {}
|
||||||
|
|
||||||
void Log(const char* file, const char* function, int line, LogPriority level,
|
void Log(const char* file, const char* function, int line, LogPriority level,
|
||||||
@@ -86,6 +100,22 @@ void Log(const char* file, const char* function, int line, LogPriority level,
|
|||||||
}
|
}
|
||||||
|
|
||||||
__android_log_write(prio, LOG_TAG, buf);
|
__android_log_write(prio, LOG_TAG, buf);
|
||||||
|
if (level <= LOG_INFO) {
|
||||||
|
g_logbuf.addLog({GetCurrentTimeMs(), level, buf});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void LogBuffer::addLog(const LogMessage& log) {
|
||||||
|
std::unique_lock<std::mutex> lock(mutex_);
|
||||||
|
buffer_.push_back(log);
|
||||||
|
while (buffer_.size() > MAX_CAPACITY) {
|
||||||
|
buffer_.pop_front();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
std::vector<LogMessage> LogBuffer::getLogs() {
|
||||||
|
std::unique_lock<std::mutex> lock(mutex_);
|
||||||
|
return {buffer_.begin(), buffer_.end()};
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace wvcdm
|
} // namespace wvcdm
|
||||||
|
|||||||
Reference in New Issue
Block a user