Commit 4b915419 authored by Jean-Baptiste Dubois's avatar Jean-Baptiste Dubois Committed by Jens Georg
Browse files

engine: Add large files (> 4GB) streaming support.

https://bugzilla.gnome.org/show_bug.cgi?id=709551
parent 9da3ca39
......@@ -27,6 +27,8 @@ dnl Disable generation of static libraries
LT_PREREQ([2.2.6])
LT_INIT([dlopen disable-static])
AC_SYS_LARGEFILE
dnl Required versions of library packages
dnl Not all of these are actually used, depending on the configure options.
GLIB_REQUIRED=2.31.13
......
......@@ -8,6 +8,7 @@ librygel_media_engine_simple_la_SOURCES = \
rygel-simple-data-source.vala
librygel_media_engine_simple_la_VALAFLAGS = \
--pkg posix \
$(RYGEL_COMMON_LIBRYGEL_SERVER_VALAFLAGS) \
$(RYGEL_COMMON_VALAFLAGS)
......
......@@ -34,8 +34,8 @@ internal class Rygel.SimpleDataSource : DataSource, Object {
private Thread<void*> thread;
private Mutex mutex = Mutex ();
private Cond cond = Cond ();
private uint64 first_byte = 0;
private uint64 last_byte = 0;
private Posix.off_t first_byte = 0;
private Posix.off_t last_byte = 0;
private bool frozen = false;
private bool stop_thread = false;
private HTTPSeek offsets = null;
......@@ -103,13 +103,26 @@ internal class Rygel.SimpleDataSource : DataSource, Object {
private void* thread_func () {
var file = File.new_for_commandline_arg (this.uri);
debug ("Spawning new thread for streaming file %s", this.uri);
int fd = -1;
try {
var mapped = new MappedFile (file.get_path (), false);
fd = Posix.open (file.get_path (), Posix.O_RDONLY, 0);
if (fd < 0) {
throw new IOError.FAILED ("Failed to open file '%s': %s",
file.get_path (),
Posix.strerror (Posix.errno));
}
if (this.offsets != null) {
this.first_byte = this.offsets.start;
this.last_byte = this.offsets.stop + 1;
this.first_byte = (Posix.off_t) this.offsets.start;
this.last_byte = (Posix.off_t) this.offsets.stop + 1;
} else {
this.last_byte = mapped.get_length ();
this.first_byte = 0;
this.last_byte = Posix.lseek (fd, 0, Posix.SEEK_END);
Posix.lseek (fd, 0, Posix.SEEK_SET);
}
if (this.first_byte != 0) {
Posix.lseek (fd, this.first_byte, Posix.SEEK_SET);
}
while (true) {
......@@ -134,9 +147,15 @@ internal class Rygel.SimpleDataSource : DataSource, Object {
stop = this.last_byte;
}
unowned uint8[] data = (uint8[]) mapped.get_contents ();
data.length = (int) mapped.get_length ();
uint8[] slice = data[start:stop];
var slice = new uint8[stop - start];
var len = (int) Posix.read (fd, slice, slice.length);
if (len < 0) {
throw new IOError.FAILED ("Failed to read file '%s': %s",
file.get_path (),
Posix.strerror (Posix.errno));
}
slice.length = len;
this.first_byte = stop;
// There's a potential race condition here.
......@@ -149,7 +168,11 @@ internal class Rygel.SimpleDataSource : DataSource, Object {
});
}
} catch (Error error) {
warning ("Failed to map file: %s", error.message);
warning ("Failed to stream file %s: %s",
file.get_path (),
error.message);
} finally {
Posix.close (fd);
}
// Signal that we're done streaming
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment