Skip to content

Commit

Permalink
o Don't do unprotected read on status information such as
Browse files Browse the repository at this point in the history
  progress and max value seen.
o Update the max value seen before passing it over to stats server :)
  • Loading branch information
hzeller committed Sep 22, 2012
1 parent 7689c9a commit f00e6a4
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
14 changes: 11 additions & 3 deletions folve-filesystem.cc
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@
#include <string>
#include <zita-convolver.h>

#include <boost/thread/locks.hpp>
#include <boost/thread/mutex.hpp>

#include "conversion-buffer.h"
#include "file-handler-cache.h"
#include "file-handler.h"
Expand Down Expand Up @@ -199,15 +202,17 @@ class SndFileHandler :
}

virtual void GetHandlerStatus(struct HandlerStats *stats) {
boost::lock_guard<boost::mutex> l(stats_mutex_);
if (processor_ != NULL) {
base_stats_.max_output_value = processor_->max_output_value();
}
*stats = base_stats_;
const int frames_done = in_info_.frames - input_frames_left_;
if (frames_done == 0 || in_info_.frames == 0)
stats->progress = 0.0;
else
stats->progress = 1.0 * frames_done / in_info_.frames;
if (processor_ != NULL) {
base_stats_.max_output_value = processor_->max_output_value();
}

if (base_stats_.max_output_value > 1.0) {
// TODO: the status server could inspect this value and make better
// rendering.
Expand Down Expand Up @@ -370,6 +375,8 @@ class SndFileHandler :
}

virtual bool AddMoreSoundData() {
// We're changing some stats here such as frames_left and max level.
boost::lock_guard<boost::mutex> l(stats_mutex_);
if (processor_ && processor_->pending_writes() > 0) {
processor_->WriteProcessed(snd_out_, processor_->pending_writes());
return input_frames_left_;
Expand Down Expand Up @@ -547,6 +554,7 @@ class SndFileHandler :
const SF_INFO in_info_;
const std::string config_path_;

boost::mutex stats_mutex_;
HandlerStats base_stats_; // UI information about current file.

struct stat file_stat_; // we dynamically report a changing size.
Expand Down
1 change: 1 addition & 0 deletions status-server.cc
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@ static void AppendFileInfo(std::string *result, const char *progress_style,
} else {
result->append("<td colspan='3'>-</td>");
}

if (stats.max_output_value > 1e-6) {
Appendf(result, sDecibelColumn,
stats.max_output_value > 1.0 ? "#FF0505" : "white",
Expand Down

0 comments on commit f00e6a4

Please sign in to comment.