summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJean-Baptiste Dubois <jean-baptiste.dubois@parrot.com>2013-10-07 09:49:01 +0200
committerJens Georg <jensg@openismus.com>2013-10-15 11:20:57 +0200
commit4b915419791115bfbd63d79d2b59701550d86ec1 (patch)
tree14b2529f3cdf2c395272bf0492eff41814363b3f
parent9da3ca39438f91c7e0fa7bc3192ae54449e41c62 (diff)
downloadrygel-4b915419791115bfbd63d79d2b59701550d86ec1.tar.gz
engine: Add large files (> 4GB) streaming support.
https://bugzilla.gnome.org/show_bug.cgi?id=709551
-rw-r--r--configure.ac2
-rw-r--r--src/media-engines/simple/Makefile.am1
-rw-r--r--src/media-engines/simple/rygel-simple-data-source.vala43
3 files changed, 36 insertions, 10 deletions
diff --git a/configure.ac b/configure.ac
index 3e4982ef..a460a802 100644
--- a/configure.ac
+++ b/configure.ac
@@ -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
diff --git a/src/media-engines/simple/Makefile.am b/src/media-engines/simple/Makefile.am
index 3a6aa8ed..67b3dfb3 100644
--- a/src/media-engines/simple/Makefile.am
+++ b/src/media-engines/simple/Makefile.am
@@ -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)
diff --git a/src/media-engines/simple/rygel-simple-data-source.vala b/src/media-engines/simple/rygel-simple-data-source.vala
index d0ccbd4d..3f66941e 100644
--- a/src/media-engines/simple/rygel-simple-data-source.vala
+++ b/src/media-engines/simple/rygel-simple-data-source.vala
@@ -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