diff --git a/trunk/src/app/srs_app_dash.cpp b/trunk/src/app/srs_app_dash.cpp index 9b5a44a28..d71a91756 100644 --- a/trunk/src/app/srs_app_dash.cpp +++ b/trunk/src/app/srs_app_dash.cpp @@ -89,33 +89,40 @@ int SrsMpdWriter::write(SrsFormat* format) stringstream ss; ss << "" << endl - << "" << endl - << " " << endl; + << " maxSegmentDuration=\"PT" << fragment / 1000 << "S\" minBufferTime=\"PT" << fragment / 1000 << "S\" >" << endl + << " " << req->stream << "/" << "" << endl + << " " << endl; if (format->acodec) { - ss << " " << endl; - ss << " " << endl; - ss << " " << endl; + ss << " " << endl; + ss << " " << endl; + ss << " " << endl; ss << " " << endl; } if (format->vcodec) { int w = format->vcodec->width; int h = format->vcodec->height; - ss << " " << endl; - ss << " " << endl; - ss << " " << endl; + ss << " " << endl; + ss << " " << endl; + ss << " " << endl; ss << " " << endl; } ss << " " << endl << "" << endl; SrsFileWriter fw; - if ((ret = fw.open(full_path)) != ERROR_SUCCESS) { - srs_error("DASH: open MPD file=%s failed, ret=%d", full_path.c_str(), ret); + string full_path_tmp = full_path + ".tmp"; + if ((ret = fw.open(full_path_tmp)) != ERROR_SUCCESS) { + srs_error("DASH: open MPD file=%s failed, ret=%d", full_path_tmp.c_str(), ret); return ret; } @@ -125,6 +132,12 @@ int SrsMpdWriter::write(SrsFormat* format) return ret; } + if (::rename(full_path_tmp.c_str(), full_path.c_str()) < 0) { + ret = ERROR_DASH_WRITE_FAILED; + srs_error("DASH: rename %s to %s failed, ret=%d", full_path_tmp.c_str(), full_path.c_str(), ret); + return ret; + } + srs_trace("DASH: refresh MPD successed, size=%dB, file=%s", content.length(), full_path.c_str()); return ret; diff --git a/trunk/src/kernel/srs_kernel_error.hpp b/trunk/src/kernel/srs_kernel_error.hpp index d02bde8bc..e603f819d 100644 --- a/trunk/src/kernel/srs_kernel_error.hpp +++ b/trunk/src/kernel/srs_kernel_error.hpp @@ -261,6 +261,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. #define ERROR_FLV_REQUIRE_SPACE 3084 #define ERROR_MP4_AVCC_CHANGE 3085 #define ERROR_MP4_ASC_CHANGE 3086 +#define ERROR_DASH_WRITE_FAILED 3087 /////////////////////////////////////////////////////// // HTTP/StreamCaster/KAFKA protocol error. diff --git a/trunk/src/protocol/srs_http_stack.cpp b/trunk/src/protocol/srs_http_stack.cpp index 435c95b76..33b624a73 100644 --- a/trunk/src/protocol/srs_http_stack.cpp +++ b/trunk/src/protocol/srs_http_stack.cpp @@ -787,16 +787,24 @@ int SrsHttpCorsMux::initialize(ISrsHttpServeMux* worker, bool cros_enabled) int SrsHttpCorsMux::serve_http(ISrsHttpResponseWriter* w, ISrsHttpMessage* r) { - // method is OPTIONS and enable crossdomain, required crossdomain header. - if (r->is_http_options() && enabled) { - required = true; + // If CORS enabled, and there is a "Origin" header, it's CORS. + if (enabled) { + for (int i = 0; i < r->request_header_count(); i++) { + string k = r->request_header_key_at(i); + if (k == "Origin" || k == "origin") { + required = true; + break; + } + } } - // whenever crossdomain required, set crossdomain header. + // When CORS required, set the CORS headers. if (required) { - w->header()->set("Access-Control-Allow-Origin", "*"); - w->header()->set("Access-Control-Allow-Methods", "GET, POST, HEAD, PUT, DELETE"); - w->header()->set("Access-Control-Allow-Headers", "Cache-Control,X-Proxy-Authorization,X-Requested-With,Content-Type"); + SrsHttpHeader* h = w->header(); + h->set("Access-Control-Allow-Origin", "*"); + h->set("Access-Control-Allow-Methods", "GET, POST, HEAD, PUT, DELETE, OPTIONS"); + h->set("Access-Control-Expose-Headers", "Server,range,Content-Length,Content-Range"); + h->set("Access-Control-Allow-Headers", "origin,range,accept-encoding,referer,Cache-Control,X-Proxy-Authorization,X-Requested-With,Content-Type"); } // handle the http options.