正在显示
2 个修改的文件
包含
57 行增加
和
1 行删除
@@ -163,6 +163,61 @@ int SrsHttpVhost::do_process_request(SrsSocket* skt, SrsHttpMessage* req) | @@ -163,6 +163,61 @@ int SrsHttpVhost::do_process_request(SrsSocket* skt, SrsHttpMessage* req) | ||
163 | 163 | ||
164 | std::string fullpath = get_request_file(req); | 164 | std::string fullpath = get_request_file(req); |
165 | 165 | ||
166 | + if (srs_string_ends_with(fullpath, ".ts")) { | ||
167 | + // TODO: FIXME: use more advance cache. | ||
168 | + // for ts video large file, use bytes to write it. | ||
169 | + int fd = ::open(fullpath.c_str(), O_RDONLY); | ||
170 | + if (fd < 0) { | ||
171 | + ret = ERROR_HTTP_OPEN_FILE; | ||
172 | + srs_warn("open file %s failed, ret=%d", fullpath.c_str(), ret); | ||
173 | + return ret; | ||
174 | + } | ||
175 | + | ||
176 | + int64_t length = (int64_t)::lseek(fd, 0, SEEK_END); | ||
177 | + ::lseek(fd, 0, SEEK_SET); | ||
178 | + | ||
179 | + // write http header for ts. | ||
180 | + std::stringstream ss; | ||
181 | + | ||
182 | + res_status_line(ss)->res_content_type_mpegts(ss) | ||
183 | + ->res_content_length(ss, (int)length); | ||
184 | + | ||
185 | + if (req->requires_crossdomain()) { | ||
186 | + res_enable_crossdomain(ss); | ||
187 | + } | ||
188 | + | ||
189 | + res_header_eof(ss); | ||
190 | + | ||
191 | + // flush http header to peer | ||
192 | + if ((ret = res_flush(skt, ss)) != ERROR_SUCCESS) { | ||
193 | + return ret; | ||
194 | + } | ||
195 | + | ||
196 | + // write body. | ||
197 | + int64_t left = length; | ||
198 | + const static int HTTP_PKT_SIZE = 4096; | ||
199 | + char* buf = new char[HTTP_PKT_SIZE]; | ||
200 | + SrsAutoFree(char, buf, true); | ||
201 | + | ||
202 | + while (left > 0) { | ||
203 | + ssize_t nread = -1; | ||
204 | + // TODO: FIXME: use st_read. | ||
205 | + if ((nread = ::read(fd, buf, HTTP_PKT_SIZE)) < 0) { | ||
206 | + ::close(fd); | ||
207 | + ret = ERROR_HTTP_READ_FILE; | ||
208 | + srs_warn("read file %s failed, ret=%d", fullpath.c_str(), ret); | ||
209 | + return ret; | ||
210 | + } | ||
211 | + | ||
212 | + left -= nread; | ||
213 | + if ((ret = skt->write(buf, nread, NULL)) != ERROR_SUCCESS) { | ||
214 | + break; | ||
215 | + } | ||
216 | + } | ||
217 | + ::close(fd); | ||
218 | + | ||
219 | + return ret; | ||
220 | + } else { | ||
166 | // TODO: FIXME: refine the file stream. | 221 | // TODO: FIXME: refine the file stream. |
167 | int fd = ::open(fullpath.c_str(), O_RDONLY); | 222 | int fd = ::open(fullpath.c_str(), O_RDONLY); |
168 | if (fd < 0) { | 223 | if (fd < 0) { |
@@ -208,6 +263,7 @@ int SrsHttpVhost::do_process_request(SrsSocket* skt, SrsHttpMessage* req) | @@ -208,6 +263,7 @@ int SrsHttpVhost::do_process_request(SrsSocket* skt, SrsHttpMessage* req) | ||
208 | } else { | 263 | } else { |
209 | return res_text(skt, req, str); | 264 | return res_text(skt, req, str); |
210 | } | 265 | } |
266 | + } | ||
211 | 267 | ||
212 | return ret; | 268 | return ret; |
213 | } | 269 | } |
@@ -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 "0" | 32 | #define VERSION_MAJOR "0" |
33 | #define VERSION_MINOR "9" | 33 | #define VERSION_MINOR "9" |
34 | -#define VERSION_REVISION "72" | 34 | +#define VERSION_REVISION "73" |
35 | #define RTMP_SIG_SRS_VERSION VERSION_MAJOR"."VERSION_MINOR"."VERSION_REVISION | 35 | #define RTMP_SIG_SRS_VERSION VERSION_MAJOR"."VERSION_MINOR"."VERSION_REVISION |
36 | // server info. | 36 | // server info. |
37 | #define RTMP_SIG_SRS_KEY "srs" | 37 | #define RTMP_SIG_SRS_KEY "srs" |
-
请 注册 或 登录 后发表评论