Permalink
Browse files

Filesize over-estimation. If we hand out the original file-size, then

media servers (in this case minim) just serve up to that size. However,
the final file-size can be different. So over-estimating is better.
  • Loading branch information...
hzeller committed Oct 9, 2012
1 parent bf9934c commit 32959bdee078e5cf4ff141f4e56c6a3534fc0343
Showing with 14 additions and 1 deletion.
  1. +2 −1 folve-filesystem.cc
  2. +11 −0 folve-filesystem.h
  3. +1 −0 folve-main.cc
View
@@ -234,7 +234,7 @@ class SndFileHandler :
off_t new_size = estimated_end * current_file_size;
// Report a bit bigger size which is less harmful than programs
// reading short.
- new_size += 16384;
+ new_size += 65535;
if (new_size > file_stat_.st_size) { // Only go forward in size.
file_stat_.st_size = new_size;
}
@@ -263,6 +263,7 @@ class SndFileHandler :
// the filesize as we see it grow. Some clients continuously monitor
// the size of the file to check when to stop.
fstat(filedes_, &file_stat_);
+ file_stat_.st_size *= fs->file_oversize_factor();
start_estimating_size_ = 0.4 * file_stat_.st_size;
// The flac header we get is more rich than what we can create via
View
@@ -97,6 +97,17 @@ class FolveFilesystem {
void set_pre_buffer_size(int b) { pre_buffer_size_ = b; }
int pre_buffer_size() const { return pre_buffer_size_; }
+ // Some media servers look at the file size initially to decide which is
+ // the file-size they need to serve. However, the final file-size after
+ // convolving might be different (compression not really predictable) and
+ // we don't know that beforehand.
+ // So, we can't really hand out the original file size. But we don't really
+ // know the final file-size as well. So we multiply the original file size
+ // with a factor - overestimating seems to be less of a problem than
+ // understimating.
+ // This is the factor (maybe configurable later).
+ float file_oversize_factor() { return 1.5; }
+
// Some stats.
int total_file_openings() { return total_file_openings_; }
int total_file_reopen() { return total_file_reopen_; }
View
@@ -123,6 +123,7 @@ static int folve_getattr(const char *path, struct stat *stbuf) {
stbuf->st_mode & 0777, S_ISDIR(stbuf->st_mode) ? "DIR" : "",
(result == -1) ? strerror(errno) : "",
ctime(&stbuf->st_mtime)); // ctime ends with \n, so put that last
+ stbuf->st_size *= folve_rt.fs->file_oversize_factor();
if (result == -1)
return -errno;
} else {

0 comments on commit 32959bd

Please sign in to comment.