for #299, srs http server support dash vod stream over mp4 range. 2.0.103
正在显示
5 个修改的文件
包含
64 行增加
和
50 行删除
| @@ -306,51 +306,9 @@ int SrsGoHttpFileServer::serve_http(ISrsGoHttpResponseWriter* w, SrsHttpMessage* | @@ -306,51 +306,9 @@ int SrsGoHttpFileServer::serve_http(ISrsGoHttpResponseWriter* w, SrsHttpMessage* | ||
| 306 | // handle file according to its extension. | 306 | // handle file according to its extension. |
| 307 | // use vod stream for .flv/.fhv | 307 | // use vod stream for .flv/.fhv |
| 308 | if (srs_string_ends_with(fullpath, ".flv") || srs_string_ends_with(fullpath, ".fhv")) { | 308 | if (srs_string_ends_with(fullpath, ".flv") || srs_string_ends_with(fullpath, ".fhv")) { |
| 309 | - std::string start = r->query_get("start"); | ||
| 310 | - if (start.empty()) { | ||
| 311 | - return serve_file(w, r, fullpath); | ||
| 312 | - } | ||
| 313 | - | ||
| 314 | - int offset = ::atoi(start.c_str()); | ||
| 315 | - if (offset <= 0) { | ||
| 316 | - return serve_file(w, r, fullpath); | ||
| 317 | - } | ||
| 318 | - | ||
| 319 | - return serve_flv_stream(w, r, fullpath, offset); | 309 | + return serve_flv_file(w, r, fullpath); |
| 320 | } else if (srs_string_ends_with(fullpath, ".mp4")) { | 310 | } else if (srs_string_ends_with(fullpath, ".mp4")) { |
| 321 | - // for flash to request mp4 range in query string. | ||
| 322 | - // for example, http://digitalprimates.net/dash/DashTest.html?url=http://dashdemo.edgesuite.net/digitalprimates/nexus/oops-20120802-manifest.mpd | ||
| 323 | - std::string range = r->query_get("range"); | ||
| 324 | - // or, use bytes to request range, | ||
| 325 | - // for example, http://dashas.castlabs.com/demo/try.html | ||
| 326 | - if (range.empty()) { | ||
| 327 | - range = r->query_get("bytes"); | ||
| 328 | - } | ||
| 329 | - | ||
| 330 | - // rollback to serve whole file. | ||
| 331 | - size_t pos = string::npos; | ||
| 332 | - if (range.empty() || (pos = range.find("-")) == string::npos) { | ||
| 333 | - return serve_file(w, r, fullpath); | ||
| 334 | - } | ||
| 335 | - | ||
| 336 | - // parse the start in query string | ||
| 337 | - int start = 0; | ||
| 338 | - if (pos > 0) { | ||
| 339 | - start = ::atoi(range.substr(0, pos).c_str()); | ||
| 340 | - } | ||
| 341 | - | ||
| 342 | - // parse end in query string. | ||
| 343 | - int end = -1; | ||
| 344 | - if (pos < range.length() - 1) { | ||
| 345 | - end = ::atoi(range.substr(pos + 1).c_str()); | ||
| 346 | - } | ||
| 347 | - | ||
| 348 | - // invalid param, serve as whole mp4 file. | ||
| 349 | - if (start < 0 || (end != -1 && start > end)) { | ||
| 350 | - return serve_file(w, r, fullpath); | ||
| 351 | - } | ||
| 352 | - | ||
| 353 | - return serve_mp4_range(w, r, fullpath, start, end); | 311 | + return serve_mp4_file(w, r, fullpath); |
| 354 | } | 312 | } |
| 355 | 313 | ||
| 356 | // serve common static file. | 314 | // serve common static file. |
| @@ -427,12 +385,64 @@ int SrsGoHttpFileServer::serve_file(ISrsGoHttpResponseWriter* w, SrsHttpMessage* | @@ -427,12 +385,64 @@ int SrsGoHttpFileServer::serve_file(ISrsGoHttpResponseWriter* w, SrsHttpMessage* | ||
| 427 | return w->final_request(); | 385 | return w->final_request(); |
| 428 | } | 386 | } |
| 429 | 387 | ||
| 388 | +int SrsGoHttpFileServer::serve_flv_file(ISrsGoHttpResponseWriter* w, SrsHttpMessage* r, string fullpath) | ||
| 389 | +{ | ||
| 390 | + std::string start = r->query_get("start"); | ||
| 391 | + if (start.empty()) { | ||
| 392 | + return serve_file(w, r, fullpath); | ||
| 393 | + } | ||
| 394 | + | ||
| 395 | + int offset = ::atoi(start.c_str()); | ||
| 396 | + if (offset <= 0) { | ||
| 397 | + return serve_file(w, r, fullpath); | ||
| 398 | + } | ||
| 399 | + | ||
| 400 | + return serve_flv_stream(w, r, fullpath, offset); | ||
| 401 | +} | ||
| 402 | + | ||
| 403 | +int SrsGoHttpFileServer::serve_mp4_file(ISrsGoHttpResponseWriter* w, SrsHttpMessage* r, string fullpath) | ||
| 404 | +{ | ||
| 405 | + // for flash to request mp4 range in query string. | ||
| 406 | + // for example, http://digitalprimates.net/dash/DashTest.html?url=http://dashdemo.edgesuite.net/digitalprimates/nexus/oops-20120802-manifest.mpd | ||
| 407 | + std::string range = r->query_get("range"); | ||
| 408 | + // or, use bytes to request range, | ||
| 409 | + // for example, http://dashas.castlabs.com/demo/try.html | ||
| 410 | + if (range.empty()) { | ||
| 411 | + range = r->query_get("bytes"); | ||
| 412 | + } | ||
| 413 | + | ||
| 414 | + // rollback to serve whole file. | ||
| 415 | + size_t pos = string::npos; | ||
| 416 | + if (range.empty() || (pos = range.find("-")) == string::npos) { | ||
| 417 | + return serve_file(w, r, fullpath); | ||
| 418 | + } | ||
| 419 | + | ||
| 420 | + // parse the start in query string | ||
| 421 | + int start = 0; | ||
| 422 | + if (pos > 0) { | ||
| 423 | + start = ::atoi(range.substr(0, pos).c_str()); | ||
| 424 | + } | ||
| 425 | + | ||
| 426 | + // parse end in query string. | ||
| 427 | + int end = -1; | ||
| 428 | + if (pos < range.length() - 1) { | ||
| 429 | + end = ::atoi(range.substr(pos + 1).c_str()); | ||
| 430 | + } | ||
| 431 | + | ||
| 432 | + // invalid param, serve as whole mp4 file. | ||
| 433 | + if (start < 0 || (end != -1 && start > end)) { | ||
| 434 | + return serve_file(w, r, fullpath); | ||
| 435 | + } | ||
| 436 | + | ||
| 437 | + return serve_mp4_stream(w, r, fullpath, start, end); | ||
| 438 | +} | ||
| 439 | + | ||
| 430 | int SrsGoHttpFileServer::serve_flv_stream(ISrsGoHttpResponseWriter* w, SrsHttpMessage* r, string fullpath, int offset) | 440 | int SrsGoHttpFileServer::serve_flv_stream(ISrsGoHttpResponseWriter* w, SrsHttpMessage* r, string fullpath, int offset) |
| 431 | { | 441 | { |
| 432 | return serve_file(w, r, fullpath); | 442 | return serve_file(w, r, fullpath); |
| 433 | } | 443 | } |
| 434 | 444 | ||
| 435 | -int SrsGoHttpFileServer::serve_mp4_range(ISrsGoHttpResponseWriter* w, SrsHttpMessage* r, string fullpath, int start, int end) | 445 | +int SrsGoHttpFileServer::serve_mp4_stream(ISrsGoHttpResponseWriter* w, SrsHttpMessage* r, string fullpath, int start, int end) |
| 436 | { | 446 | { |
| 437 | return serve_file(w, r, fullpath); | 447 | return serve_file(w, r, fullpath); |
| 438 | } | 448 | } |
| @@ -149,6 +149,7 @@ public: | @@ -149,6 +149,7 @@ public: | ||
| 149 | // will trigger an implicit WriteHeader(http.StatusOK). | 149 | // will trigger an implicit WriteHeader(http.StatusOK). |
| 150 | // Thus explicit calls to WriteHeader are mainly used to | 150 | // Thus explicit calls to WriteHeader are mainly used to |
| 151 | // send error codes. | 151 | // send error codes. |
| 152 | + // @remark, user must set header then write or write_header. | ||
| 152 | virtual void write_header(int code) = 0; | 153 | virtual void write_header(int code) = 0; |
| 153 | }; | 154 | }; |
| 154 | 155 | ||
| @@ -211,11 +212,14 @@ public: | @@ -211,11 +212,14 @@ public: | ||
| 211 | virtual ~SrsGoHttpFileServer(); | 212 | virtual ~SrsGoHttpFileServer(); |
| 212 | public: | 213 | public: |
| 213 | virtual int serve_http(ISrsGoHttpResponseWriter* w, SrsHttpMessage* r); | 214 | virtual int serve_http(ISrsGoHttpResponseWriter* w, SrsHttpMessage* r); |
| 214 | -protected: | 215 | +private: |
| 215 | /** | 216 | /** |
| 216 | * serve the file by specified path | 217 | * serve the file by specified path |
| 217 | */ | 218 | */ |
| 218 | virtual int serve_file(ISrsGoHttpResponseWriter* w, SrsHttpMessage* r, std::string fullpath); | 219 | virtual int serve_file(ISrsGoHttpResponseWriter* w, SrsHttpMessage* r, std::string fullpath); |
| 220 | + virtual int serve_flv_file(ISrsGoHttpResponseWriter* w, SrsHttpMessage* r, std::string fullpath); | ||
| 221 | + virtual int serve_mp4_file(ISrsGoHttpResponseWriter* w, SrsHttpMessage* r, std::string fullpath); | ||
| 222 | +protected: | ||
| 219 | /** | 223 | /** |
| 220 | * when access flv file with x.flv?start=xxx | 224 | * when access flv file with x.flv?start=xxx |
| 221 | */ | 225 | */ |
| @@ -226,7 +230,7 @@ protected: | @@ -226,7 +230,7 @@ protected: | ||
| 226 | * @param end the end offset in bytes. -1 to end of file. | 230 | * @param end the end offset in bytes. -1 to end of file. |
| 227 | * @remark response data in [start, end]. | 231 | * @remark response data in [start, end]. |
| 228 | */ | 232 | */ |
| 229 | - virtual int serve_mp4_range(ISrsGoHttpResponseWriter* w, SrsHttpMessage* r, std::string fullpath, int start, int end); | 233 | + virtual int serve_mp4_stream(ISrsGoHttpResponseWriter* w, SrsHttpMessage* r, std::string fullpath, int start, int end); |
| 230 | protected: | 234 | protected: |
| 231 | /** | 235 | /** |
| 232 | * copy the fs to response writer in size bytes. | 236 | * copy the fs to response writer in size bytes. |
| @@ -141,7 +141,7 @@ int SrsVodStream::serve_flv_stream(ISrsGoHttpResponseWriter* w, SrsHttpMessage* | @@ -141,7 +141,7 @@ int SrsVodStream::serve_flv_stream(ISrsGoHttpResponseWriter* w, SrsHttpMessage* | ||
| 141 | return ret; | 141 | return ret; |
| 142 | } | 142 | } |
| 143 | 143 | ||
| 144 | -int SrsVodStream::serve_mp4_range(ISrsGoHttpResponseWriter* w, SrsHttpMessage* r, string fullpath, int start, int end) | 144 | +int SrsVodStream::serve_mp4_stream(ISrsGoHttpResponseWriter* w, SrsHttpMessage* r, string fullpath, int start, int end) |
| 145 | { | 145 | { |
| 146 | int ret = ERROR_SUCCESS; | 146 | int ret = ERROR_SUCCESS; |
| 147 | 147 |
| @@ -66,7 +66,7 @@ public: | @@ -66,7 +66,7 @@ public: | ||
| 66 | virtual ~SrsVodStream(); | 66 | virtual ~SrsVodStream(); |
| 67 | protected: | 67 | protected: |
| 68 | virtual int serve_flv_stream(ISrsGoHttpResponseWriter* w, SrsHttpMessage* r, std::string fullpath, int offset); | 68 | virtual int serve_flv_stream(ISrsGoHttpResponseWriter* w, SrsHttpMessage* r, std::string fullpath, int offset); |
| 69 | - virtual int serve_mp4_range(ISrsGoHttpResponseWriter* w, SrsHttpMessage* r, std::string fullpath, int start, int end); | 69 | + virtual int serve_mp4_stream(ISrsGoHttpResponseWriter* w, SrsHttpMessage* r, std::string fullpath, int start, int end); |
| 70 | }; | 70 | }; |
| 71 | 71 | ||
| 72 | /** | 72 | /** |
| @@ -31,7 +31,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | @@ -31,7 +31,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
| 31 | // current release version | 31 | // current release version |
| 32 | #define VERSION_MAJOR 2 | 32 | #define VERSION_MAJOR 2 |
| 33 | #define VERSION_MINOR 0 | 33 | #define VERSION_MINOR 0 |
| 34 | -#define VERSION_REVISION 102 | 34 | +#define VERSION_REVISION 103 |
| 35 | 35 | ||
| 36 | // server info. | 36 | // server info. |
| 37 | #define RTMP_SIG_SRS_KEY "SRS" | 37 | #define RTMP_SIG_SRS_KEY "SRS" |
-
请 注册 或 登录 后发表评论