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

Feature/temp dir #823

Merged
merged 2 commits into from
Jun 4, 2023
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
1 change: 1 addition & 0 deletions trunk-recorder/call.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ class Call {
virtual int get_sys_num() = 0;
virtual std::string get_short_name() = 0;
virtual std::string get_capture_dir() = 0;
virtual std::string get_temp_dir() = 0;
virtual void set_freq(double f) = 0;
virtual long get_talkgroup() = 0;

Expand Down
36 changes: 33 additions & 3 deletions trunk-recorder/call_concluder/call_concluder.cc
Original file line number Diff line number Diff line change
Expand Up @@ -217,10 +217,43 @@ Call_Data_t upload_call_worker(Call_Data_t call_info) {
return call_info;
}


// static int rec_counter=0;
Call_Data_t Call_Concluder::create_base_filename(Call *call, Call_Data_t call_info) {
char base_filename[255];
time_t work_start_time = call->get_start_time();
std::stringstream base_path_stream;
tm *ltm = localtime(&work_start_time);
// Found some good advice on Streams and Strings here: https://blog.sensecodons.com/2013/04/dont-let-stdstringstreamstrcstr-happen.html
base_path_stream << call->get_capture_dir() << "/" << call->get_short_name() << "/" << 1900 + ltm->tm_year << "/" << 1 + ltm->tm_mon << "/" << ltm->tm_mday;
std::string base_path_string = base_path_stream.str();
boost::filesystem::create_directories(base_path_string);

int nchars;

if (call->get_tdma_slot() == -1) {
nchars = snprintf(base_filename, 255, "%s/%ld-%ld_%.0f", base_path_string.c_str(), call->get_talkgroup(), work_start_time, call->get_freq());
} else {
// this is for the case when it is a DMR recorder and 2 wav files are created, the slot is needed to keep them separate.
nchars = snprintf(base_filename, 255, "%s/%ld-%ld_%.0f.%d", base_path_string.c_str(), call->get_talkgroup(), work_start_time, call->get_freq(), call->get_tdma_slot());
}
if (nchars >= 255) {
BOOST_LOG_TRIVIAL(error) << "Call: Path longer than 255 charecters";
}
snprintf(call_info.filename, 300, "%s-call_%lu.wav", base_filename, call->get_call_num());
snprintf(call_info.status_filename, 300, "%s-call_%lu.json", base_filename, call->get_call_num());
snprintf(call_info.converted, 300, "%s-call_%lu.m4a", base_filename, call->get_call_num());

return call_info;
}


Call_Data_t Call_Concluder::create_call_data(Call *call, System *sys, Config config) {
Call_Data_t call_info;
double total_length = 0;

call_info = create_base_filename(call, call_info);

call_info.status = INITIAL;
call_info.process_call_time = time(0);
call_info.retry_attempt = 0;
Expand Down Expand Up @@ -303,9 +336,6 @@ Call_Data_t Call_Concluder::create_call_data(Call *call, System *sys, Config con

if (it == call_info.transmission_list.begin()) {
call_info.start_time = t.start_time;
snprintf(call_info.filename, 300, "%s-call_%lu.wav", t.base_filename, call_info.call_num);
snprintf(call_info.status_filename, 300, "%s-call_%lu.json", t.base_filename, call_info.call_num);
snprintf(call_info.converted, 300, "%s-call_%lu.m4a", t.base_filename, call_info.call_num);
}

if (std::next(it) == call_info.transmission_list.end()) {
Expand Down
4 changes: 4 additions & 0 deletions trunk-recorder/call_concluder/call_concluder.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,13 @@ class Call_Concluder {
public:
static std::list<Call_Data_t> retry_call_list;
static std::list<std::future<Call_Data_t>> call_data_workers;

static Call_Data_t create_call_data(Call *call, System *sys, Config config);
static void conclude_call(Call *call, System *sys, Config config);
static void manage_call_data_workers();

private:
static Call_Data_t create_base_filename(Call *call, Call_Data_t call_info);
};

#endif
5 changes: 5 additions & 0 deletions trunk-recorder/call_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@
std::string Call_impl::get_capture_dir() {
return this->config.capture_dir;
}

std::string Call_impl::get_temp_dir() {
return this->config.temp_dir;
}

/*
Call * Call::make(long t, double f, System *s, Config c) {

Expand Down
1 change: 1 addition & 0 deletions trunk-recorder/call_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ class Call_impl : public Call {
int get_sys_num();
std::string get_short_name();
std::string get_capture_dir();
std::string get_temp_dir();
void set_freq(double f);
long get_talkgroup();

Expand Down
2 changes: 1 addition & 1 deletion trunk-recorder/global_structs.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ struct Transmission {
double freq;
double length;
char filename[255];
char base_filename[255];
};

struct Config {
Expand All @@ -25,6 +24,7 @@ struct Config {
std::string instance_key;
std::string instance_id;
std::string capture_dir;
std::string temp_dir;
std::string debug_recorder_address;
std::string log_dir;
bool new_call_from_update;
Expand Down
22 changes: 9 additions & 13 deletions trunk-recorder/gr_blocks/transmission_sink.cc
Original file line number Diff line number Diff line change
Expand Up @@ -79,22 +79,22 @@ transmission_sink::transmission_sink(int n_channels, unsigned int sample_rate, i


// static int rec_counter=0;
void transmission_sink::create_base_filename() {
void transmission_sink::create_filename() {
time_t work_start_time = d_start_time;
std::stringstream path_stream;
std::stringstream temp_path_stream;
tm *ltm = localtime(&work_start_time);
// Found some good advice on Streams and Strings here: https://blog.sensecodons.com/2013/04/dont-let-stdstringstreamstrcstr-happen.html
path_stream << d_current_call_capture_dir << "/" << d_current_call_short_name << "/" << 1900 + ltm->tm_year << "/" << 1 + ltm->tm_mon << "/" << ltm->tm_mday;
std::string path_string = path_stream.str();
boost::filesystem::create_directories(path_string);
temp_path_stream << d_current_call_temp_dir << "/" << d_current_call_short_name;
std::string temp_path_string = temp_path_stream.str();
boost::filesystem::create_directories(temp_path_string);

int nchars;

if (d_slot == -1) {
nchars = snprintf(current_base_filename, 255, "%s/%ld-%ld_%.0f", path_string.c_str(), d_current_call_talkgroup, work_start_time, d_current_call_freq);
nchars = snprintf(current_filename, 255, "%s/%ld-%ld_%.0f.wav", temp_path_string.c_str(), d_current_call_talkgroup, work_start_time, d_current_call_freq);
} else {
// this is for the case when it is a DMR recorder and 2 wav files are created, the slot is needed to keep them separate.
nchars = snprintf(current_base_filename, 255, "%s/%ld-%ld_%.0f.%d", path_string.c_str(), d_current_call_talkgroup, work_start_time, d_current_call_freq, d_slot);
nchars = snprintf(current_filename, 255, "%s/%ld-%ld_%.0f.%d.wav", temp_path_string.c_str(), d_current_call_talkgroup, work_start_time, d_current_call_freq, d_slot);
}
if (nchars >= 255) {
BOOST_LOG_TRIVIAL(error) << "Call: Path longer than 255 charecters";
Expand Down Expand Up @@ -127,9 +127,8 @@ bool transmission_sink::start_recording(Call *call) {
} else {
d_current_call_talkgroup_encoded = call->get_talkgroup();
}

d_current_call_short_name = call->get_short_name();
d_current_call_capture_dir = call->get_capture_dir();
d_current_call_temp_dir = call->get_temp_dir();
d_prior_transmission_length = 0;
d_error_count = 0;
d_spike_count = 0;
Expand Down Expand Up @@ -246,7 +245,6 @@ void transmission_sink::end_transmission() {
transmission.length = length_in_seconds(); // length in seconds
d_prior_transmission_length = d_prior_transmission_length + transmission.length;
strcpy(transmission.filename, current_filename); // Copy the filename
strcpy(transmission.base_filename, current_base_filename);
this->add_transmission(transmission);

// Reset the recorder to be ready to record the next Transmission
Expand Down Expand Up @@ -514,9 +512,7 @@ int transmission_sink::dowork(int noutput_items, gr_vector_const_void_star &inpu
}

// create a new filename, based on the current time and source.
create_base_filename();
strcpy(current_filename, current_base_filename);
strcat(current_filename, ".wav");
create_filename();
if (!open_internal(current_filename)) {
BOOST_LOG_TRIVIAL(error) << "can't open file";
return noutput_items;
Expand Down
5 changes: 2 additions & 3 deletions trunk-recorder/gr_blocks/transmission_sink.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,11 @@ class BLOCKS_API transmission_sink : virtual public sync_block {
long curr_src_id;
long next_src_id;
char current_filename[255];
char current_base_filename[255];
Call *d_current_call;
long d_current_call_num;
long d_current_call_recorder_num;
std::string d_current_call_short_name;
std::string d_current_call_capture_dir;
std::string d_current_call_temp_dir;
double d_current_call_freq;
double d_prior_transmission_length;
long d_current_call_talkgroup;
Expand Down Expand Up @@ -121,7 +120,7 @@ class BLOCKS_API transmission_sink : virtual public sync_block {
unsigned int sample_rate,
int bits_per_sample);
virtual ~transmission_sink();
void create_base_filename();
void create_filename();
char *get_filename();
bool start_recording(Call *call);
bool start_recording(Call *call, int slot);
Expand Down
21 changes: 18 additions & 3 deletions trunk-recorder/main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,10 @@ bool load_config(string config_file) {
return false;
}

BOOST_LOG_TRIVIAL(info) << "\n-------------------------------------\n Trunk Recorder\n-------------------------------------\n";

BOOST_LOG_TRIVIAL(info) << "\n\n-------------------------------------\nINSTANCE\n-------------------------------------\n";

config.log_file = pt.get<bool>("logFile", false);
config.log_dir = pt.get<std::string>("logDir", "logs");
if (config.log_file) {
Expand All @@ -165,16 +169,27 @@ bool load_config(string config_file) {
BOOST_LOG_TRIVIAL(info) << "Log to File: " << config.log_file;
BOOST_LOG_TRIVIAL(info) << "Log Directory: " << config.log_dir;

BOOST_LOG_TRIVIAL(info) << "\n-------------------------------------\n Trunk Recorder\n-------------------------------------\n";
std::string defaultTempDir = boost::filesystem::current_path().string();

BOOST_LOG_TRIVIAL(info) << "\n\n-------------------------------------\nINSTANCE\n-------------------------------------\n";
if (boost::filesystem::exists("/dev/shm")) {
defaultTempDir = "/dev/shm";
}
config.temp_dir = pt.get<std::string>("tempDir", defaultTempDir);
size_t pos = config.temp_dir.find_last_of("/");

if (pos == config.temp_dir.length() - 1) {
config.temp_dir.erase(config.temp_dir.length() - 1);
}

BOOST_LOG_TRIVIAL(info) << "Temporary Transmission Directory: " << config.temp_dir;

config.capture_dir = pt.get<std::string>("captureDir", boost::filesystem::current_path().string());
size_t pos = config.capture_dir.find_last_of("/");
pos = config.capture_dir.find_last_of("/");

if (pos == config.capture_dir.length() - 1) {
config.capture_dir.erase(config.capture_dir.length() - 1);
}

BOOST_LOG_TRIVIAL(info) << "Capture Directory: " << config.capture_dir;
config.upload_server = pt.get<std::string>("uploadServer", "");
BOOST_LOG_TRIVIAL(info) << "Upload Server: " << config.upload_server;
Expand Down