Implement the receive frame correctly

This commit is contained in:
2019-04-02 14:38:47 +02:00
parent 5e73aaff5f
commit be6b774d68
2 changed files with 16 additions and 27 deletions
+9 -17
View File
@@ -50,8 +50,8 @@ void writer_utils::create_destination_folder(const string& output_file)
WriterManager::WriterManager(const unordered_map<string, DATA_TYPE>& parameters_type):
parameters_type(parameters_type), logs(10),
receiving_flag(false), writing_flag(false), killed_flag(false),
n_received_frames(0), n_written_frames(0), n_expected_frames(0)
writing_flag(false), killed_flag(false),
n_frames_to_receive(0), n_frames_to_write(0)
{
#ifdef DEBUG_OUTPUT
using namespace date;
@@ -152,21 +152,6 @@ bool WriterManager::is_killed() const
return killed_flag.load();
}
void WriterManager::received_frame(size_t frame_index)
{
n_received_frames++;
}
void WriterManager::written_frame(size_t frame_index)
{
n_written_frames++;
}
void WriterManager::lost_frame(size_t frame_index)
{
n_lost_frames++;
}
bool WriterManager::are_all_parameters_set()
{
for (const auto& parameter : parameters_type) {
@@ -186,3 +171,10 @@ bool WriterManager::are_all_parameters_set()
return true;
}
bool WriterManager::receive_frame() {
if (n_frames_to_receive > 0) {
return (n_frames_to_receive.fetch_sub(1) >= 0);
}
return false;
}
+7 -10
View File
@@ -32,13 +32,11 @@ class WriterManager
const std::unordered_map<std::string, DATA_TYPE>& parameters_type;
const std::deque<WriterManagerLog> logs;
std::atomic<bool> receiving_flag;
std::atomic<bool> writing_flag;
std::atomic<bool> killed_flag;
std::atomic<uint64_t> n_received_frames;
std::atomic<uint64_t> n_written_frames;
std::atomic<int64_t> n_expected_frames;
std::atomic<int64_t> n_frames_to_receive;
std::atomic<int64_t> n_frames_to_write;
public:
WriterManager(const std::unordered_map<std::string, DATA_TYPE>& parameters_type);
@@ -53,15 +51,14 @@ class WriterManager
std::unordered_map<std::string, boost::any> get_parameters();
const std::unordered_map<std::string, DATA_TYPE>& get_parameters_type() const;
bool is_running();
// Return True if the frame is to be received, False if is to be dropped.
bool receive_frame();
// True if the writer process should conitnue.
bool is_running() const;
bool is_killed() const;
bool are_all_parameters_set();
std::string get_output_file() const;
void received_frame(size_t frame_index);
void written_frame(size_t frame_index);
void lost_frame(size_t frame_index);
};
#endif