mirror of
https://github.com/ossrs/srs.git
synced 2025-03-09 15:49:59 +00:00
for #299, srs http server support dash, flash request range in range or bytes.
This commit is contained in:
parent
1e26f54b5c
commit
e0ee8de2fb
5 changed files with 113 additions and 4 deletions
|
|
@ -317,6 +317,40 @@ int SrsGoHttpFileServer::serve_http(ISrsGoHttpResponseWriter* w, SrsHttpMessage*
|
|||
}
|
||||
|
||||
return serve_flv_stream(w, r, fullpath, offset);
|
||||
} else if (srs_string_ends_with(fullpath, ".mp4")) {
|
||||
// for flash to request mp4 range in query string.
|
||||
// for example, http://digitalprimates.net/dash/DashTest.html?url=http://dashdemo.edgesuite.net/digitalprimates/nexus/oops-20120802-manifest.mpd
|
||||
std::string range = r->query_get("range");
|
||||
// or, use bytes to request range,
|
||||
// for example, http://dashas.castlabs.com/demo/try.html
|
||||
if (range.empty()) {
|
||||
range = r->query_get("bytes");
|
||||
}
|
||||
|
||||
// rollback to serve whole file.
|
||||
size_t pos = string::npos;
|
||||
if (range.empty() || (pos = range.find("-")) == string::npos) {
|
||||
return serve_file(w, r, fullpath);
|
||||
}
|
||||
|
||||
// parse the start in query string
|
||||
int start = 0;
|
||||
if (pos > 0) {
|
||||
start = ::atoi(range.substr(0, pos).c_str());
|
||||
}
|
||||
|
||||
// parse end in query string.
|
||||
int end = -1;
|
||||
if (pos < range.length() - 1) {
|
||||
end = ::atoi(range.substr(pos + 1).c_str());
|
||||
}
|
||||
|
||||
// invalid param, serve as whole mp4 file.
|
||||
if (start < 0 || (end != -1 && start > end)) {
|
||||
return serve_file(w, r, fullpath);
|
||||
}
|
||||
|
||||
return serve_mp4_range(w, r, fullpath, start, end);
|
||||
}
|
||||
|
||||
// serve common static file.
|
||||
|
|
@ -377,7 +411,7 @@ int SrsGoHttpFileServer::serve_file(ISrsGoHttpResponseWriter* w, SrsHttpMessage*
|
|||
}
|
||||
|
||||
if (_mime.find(ext) == _mime.end()) {
|
||||
w->header()->set_content_type("text/html;charset=utf-8");
|
||||
w->header()->set_content_type("application/octet-stream");
|
||||
} else {
|
||||
w->header()->set_content_type(_mime[ext]);
|
||||
}
|
||||
|
|
@ -398,6 +432,11 @@ int SrsGoHttpFileServer::serve_flv_stream(ISrsGoHttpResponseWriter* w, SrsHttpMe
|
|||
return serve_file(w, r, fullpath);
|
||||
}
|
||||
|
||||
int SrsGoHttpFileServer::serve_mp4_range(ISrsGoHttpResponseWriter* w, SrsHttpMessage* r, string fullpath, int start, int end)
|
||||
{
|
||||
return serve_file(w, r, fullpath);
|
||||
}
|
||||
|
||||
int SrsGoHttpFileServer::copy(ISrsGoHttpResponseWriter* w, SrsFileReader* fs, SrsHttpMessage* r, int size)
|
||||
{
|
||||
int ret = ERROR_SUCCESS;
|
||||
|
|
@ -407,7 +446,8 @@ int SrsGoHttpFileServer::copy(ISrsGoHttpResponseWriter* w, SrsFileReader* fs, Sr
|
|||
|
||||
while (left > 0) {
|
||||
ssize_t nread = -1;
|
||||
if ((ret = fs->read(buf, __SRS_HTTP_TS_SEND_BUFFER_SIZE, &nread)) != ERROR_SUCCESS) {
|
||||
int max_read = srs_min(left, __SRS_HTTP_TS_SEND_BUFFER_SIZE);
|
||||
if ((ret = fs->read(buf, max_read, &nread)) != ERROR_SUCCESS) {
|
||||
break;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue