[rygel] core: More power to HTTPSeek
- From: Zeeshan Ali Khattak <zeeshanak src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [rygel] core: More power to HTTPSeek
- Date: Thu, 10 Dec 2009 18:07:22 +0000 (UTC)
commit c2175d0d4fed20716db0fc7a7ddc6e8451a43526
Author: Zeeshan Ali (Khattak) <zeeshanak gnome org>
Date: Tue Dec 8 17:21:38 2009 +0200
core: More power to HTTPSeek
Now HTTPSeek is given HTTPRequest object and it extracts all needed info
from there at construction time and therefore there is no need to pass the
length and other args to it's add_response_headers method.
src/rygel/rygel-http-identity-handler.vala | 5 +-
src/rygel/rygel-http-request.vala | 4 +-
src/rygel/rygel-http-seek.vala | 71 +++++++++++++++++---------
src/rygel/rygel-http-transcode-handler.vala | 3 +-
4 files changed, 51 insertions(+), 32 deletions(-)
---
diff --git a/src/rygel/rygel-http-identity-handler.vala b/src/rygel/rygel-http-identity-handler.vala
index 008dfcb..e171b1f 100644
--- a/src/rygel/rygel-http-identity-handler.vala
+++ b/src/rygel/rygel-http-identity-handler.vala
@@ -50,8 +50,7 @@ internal class Rygel.HTTPIdentityHandler : Rygel.HTTPRequestHandler {
if (request.thumbnail == null && request.item.should_stream ()) {
if (request.time_range != null) {
- request.time_range.add_response_headers (request.msg,
- request.item.duration);
+ request.time_range.add_response_headers ();
}
} else {
request.msg.response_headers.append ("Accept-Ranges", "bytes");
@@ -60,7 +59,7 @@ internal class Rygel.HTTPIdentityHandler : Rygel.HTTPRequestHandler {
if (length > 0) {
request.msg.response_headers.set_content_length (length);
}
- request.byte_range.add_response_headers (request.msg, size);
+ request.byte_range.add_response_headers ();
}
}
diff --git a/src/rygel/rygel-http-request.vala b/src/rygel/rygel-http-request.vala
index 8fb2552..1c8ea44 100644
--- a/src/rygel/rygel-http-request.vala
+++ b/src/rygel/rygel-http-request.vala
@@ -132,8 +132,8 @@ internal class Rygel.HTTPRequest : GLib.Object, Rygel.StateMachine {
private async void handle_item_request () {
try {
- this.byte_range = HTTPSeek.from_byte_range(this.msg);
- this.time_range = HTTPSeek.from_time_range(this.msg);
+ this.byte_range = HTTPSeek.from_byte_range (this);
+ this.time_range = HTTPSeek.from_time_range (this);
// Add headers
this.request_handler.add_response_headers (this);
diff --git a/src/rygel/rygel-http-seek.vala b/src/rygel/rygel-http-seek.vala
index 67970a8..cf4e6d5 100644
--- a/src/rygel/rygel-http-seek.vala
+++ b/src/rygel/rygel-http-seek.vala
@@ -29,33 +29,37 @@ internal errordomain Rygel.HTTPSeekError {
}
internal class Rygel.HTTPSeek : GLib.Object {
+ public Soup.Message msg { get; private set; }
public Format format { get; private set; }
// These are either number of bytes or microseconds
public int64 start { get; private set; }
public int64 stop { get; private set; }
-
- public int64 length {
- get {
- return this.stop + 1 - this.start;
- }
- }
-
- public HTTPSeek (Format format,
- int64 start,
- int64 stop) {
+ public int64 length { get; private set; }
+
+ public HTTPSeek (Soup.Message msg,
+ Format format,
+ int64 start,
+ int64 stop,
+ int64 length) {
+ this.msg = msg;
this.format = format;
this.start = start;
this.stop = stop;
+ this.length = length;
+
+ if (length > 0) {
+ this.stop = stop.clamp (start + 1, length - 1);
+ }
}
- public static HTTPSeek? from_byte_range (Soup.Message msg)
+ public static HTTPSeek? from_byte_range (HTTPRequest request)
throws HTTPSeekError {
string range, pos;
string[] range_tokens;
int64 start = 0, stop = -1;
- range = msg.request_headers.get ("Range");
+ range = request.msg.request_headers.get ("Range");
if (range == null) {
return null;
}
@@ -78,6 +82,13 @@ internal class Rygel.HTTPSeek : GLib.Object {
throw new HTTPSeekError.INVALID_RANGE ("Invalid Range '%s'", range);
}
+ int64 length;
+ if (request.thumbnail != null) {
+ length = request.thumbnail.size;
+ } else {
+ length = request.item.size;
+ }
+
// Get last byte position if specified
pos = range_tokens[1];
if (pos[0].isdigit ()) {
@@ -86,11 +97,17 @@ internal class Rygel.HTTPSeek : GLib.Object {
throw new HTTPSeekError.INVALID_RANGE ("Invalid Range '%s'",
range);
}
- } else if (pos != "") {
+ } else if (pos == "") {
+ stop = length - 1;
+ } else {
throw new HTTPSeekError.INVALID_RANGE ("Invalid Range '%s'", range);
}
- return new HTTPSeek (Format.BYTES, start, stop);
+ return new HTTPSeek (request.msg,
+ Format.BYTES,
+ start,
+ stop,
+ length);
}
// FIXME: We are only accepting time range in this format:
@@ -100,13 +117,13 @@ internal class Rygel.HTTPSeek : GLib.Object {
// and not
//
// TimeSeekRange.dlna.org : npt=10:19:25.7-13:23:33.6
- public static HTTPSeek? from_time_range (Soup.Message msg)
+ public static HTTPSeek? from_time_range (HTTPRequest request)
throws HTTPSeekError {
string range, time;
string[] range_tokens;
int64 start = 0, stop = -1;
- range = msg.request_headers.get ("TimeSeekRange.dlna.org");
+ range = request.msg.request_headers.get ("TimeSeekRange.dlna.org");
if (range == null) {
return null;
}
@@ -136,14 +153,20 @@ internal class Rygel.HTTPSeek : GLib.Object {
throw new HTTPSeekError.INVALID_RANGE ("Invalid Range '%s'",
range);
}
- } else if (time != "") {
+ } else if (time == "") {
+ stop = request.item.duration - 1;
+ } else {
throw new HTTPSeekError.INVALID_RANGE ("Invalid Range '%s'", range);
}
- return new HTTPSeek (Format.TIME, start, stop);
+ return new HTTPSeek (request.msg,
+ Format.TIME,
+ start,
+ stop,
+ request.item.duration);
}
- public void add_response_headers (Soup.Message msg, int64 length) {
+ public void add_response_headers () {
string header;
string value;
double start = 0;
@@ -161,10 +184,7 @@ internal class Rygel.HTTPSeek : GLib.Object {
value = "bytes ";
start = (double) this.start;
stop = (double) this.stop;
- }
- if (length > 0) {
- stop = stop.clamp (start + 1, (double) length - 1);
}
value += start.to_string () + "-";
@@ -173,12 +193,13 @@ internal class Rygel.HTTPSeek : GLib.Object {
value += stop.to_string();
}
- if (length > 0) {
- value += "/" + length.to_string();
+ if (this.length > 0) {
+ value += "/" + this.length.to_string ();
} else {
value += "/*";
}
- msg.response_headers.append (header, value);
+ this.msg.response_headers.append (header, value);
+ this.msg.response_headers.set_content_length (this.length);
}
}
diff --git a/src/rygel/rygel-http-transcode-handler.vala b/src/rygel/rygel-http-transcode-handler.vala
index 05ce34d..5cb43de 100644
--- a/src/rygel/rygel-http-transcode-handler.vala
+++ b/src/rygel/rygel-http-transcode-handler.vala
@@ -41,8 +41,7 @@ internal class Rygel.HTTPTranscodeHandler : HTTPRequestHandler {
request.msg.response_headers.append ("Content-Type",
this.transcoder.mime_type);
if (request.time_range != null) {
- request.time_range.add_response_headers (request.msg,
- request.item.duration);
+ request.time_range.add_response_headers ();
}
// Chain-up
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]