Toggle navigation
Toggle navigation
此项目
正在载入...
Sign in
胡斌
/
srs
转到一个项目
Toggle navigation
项目
群组
代码片段
帮助
Toggle navigation pinning
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Network
Create a new issue
Builds
Commits
Authored by
winlin
2016-12-15 14:54:09 +0800
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
664844b5f55d4d372f3489038f972be1c8e945f7
664844b5
1 parent
f30b3073
merge from srs2. for #513.
显示空白字符变更
内嵌
并排对比
正在显示
16 个修改的文件
包含
21 行增加
和
549 行删除
trunk/conf/full.conf
trunk/conf/ram.hls.conf
trunk/ide/srs_xcode/srs_xcode.xcodeproj/project.pbxproj
trunk/src/app/srs_app_config.cpp
trunk/src/app/srs_app_config.hpp
trunk/src/app/srs_app_hls.cpp
trunk/src/app/srs_app_hls.hpp
trunk/src/app/srs_app_http_conn.cpp
trunk/src/app/srs_app_http_conn.hpp
trunk/src/app/srs_app_http_stream.cpp
trunk/src/app/srs_app_http_stream.hpp
trunk/src/app/srs_app_rtmp_conn.cpp
trunk/src/app/srs_app_server.cpp
trunk/src/app/srs_app_server.hpp
trunk/src/app/srs_app_source.cpp
trunk/src/app/srs_app_source.hpp
trunk/conf/full.conf
查看文件 @
664844b
...
...
@@ -963,12 +963,6 @@ vhost with-hls.srs.com {
# @see https://github.com/ossrs/srs/issues/264
# default: continue
hls_on_error
continue
;
# the hls storage: disk, ram or both.
# disk, to write hls m3u8/ts to disk.
# ram, serve m3u8/ts in memory, which use embedded http server to delivery.
# both, disk and ram.
# default: disk
hls_storage
disk
;
# the hls output path.
# the m3u8 file is configured by hls_path/hls_m3u8_file, the default is:
# ./objs/nginx/html/[app]/[stream].m3u8
...
...
@@ -1017,13 +1011,6 @@ vhost with-hls.srs.com {
# ...
# optional, default to empty string.
hls_entry_prefix
http
://
your
-
server
;
# the hls mount for hls_storage ram,
# which use srs embedded http server to delivery HLS,
# where the mount specifies the HTTP url to mount.
# @see the mount of http_remux.
# @remark the hls_mount must endswith .m3u8.
# default: [vhost]/[app]/[stream].m3u8
hls_mount
[
vhost
]/[
app
]/[
stream
].
m3u8
;
# the default audio codec of hls.
# when codec changed, write the PAT/PMT table, but maybe ok util next ts.
# so user can set the default codec for mp3.
...
...
trunk/conf/ram.hls.conf
已删除
100644 → 0
查看文件 @
f30b307
# the config for srs to delivery hls
# @see https://github.com/ossrs/srs/wiki/v1_CN_SampleHLS
# @see full.conf for detail config.
listen
1935
;
max_connections
1000
;
http_server
{
enabled
on
;
listen
8080
;
dir
./
objs
/
nginx
/
html
;
}
vhost
__
defaultVhost__
{
hls
{
enabled
on
;
hls_fragment
10
;
hls_window
60
;
hls_storage
ram
;
hls_mount
/[
app
]/[
stream
].
m3u8
;
}
}
trunk/ide/srs_xcode/srs_xcode.xcodeproj/project.pbxproj
查看文件 @
664844b
...
...
@@ -319,7 +319,6 @@
3C1EE6C91AB1080900576EE9 /* origin.conf */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; name = origin.conf; path = ../../../conf/origin.conf; sourceTree = "<group>"; };
3C1EE6CA1AB1080900576EE9 /* push.mpegts.over.udp.conf */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; name = push.mpegts.over.udp.conf; path = ../../../conf/push.mpegts.over.udp.conf; sourceTree = "<group>"; };
3C1EE6CB1AB1080900576EE9 /* push.rtsp.conf */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; name = push.rtsp.conf; path = ../../../conf/push.rtsp.conf; sourceTree = "<group>"; };
3C1EE6CC1AB1080900576EE9 /* ram.hls.conf */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; name = ram.hls.conf; path = ../../../conf/ram.hls.conf; sourceTree = "<group>"; };
3C1EE6CD1AB1080900576EE9 /* realtime.conf */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; name = realtime.conf; path = ../../../conf/realtime.conf; sourceTree = "<group>"; };
3C1EE6CE1AB1080900576EE9 /* rtmp.conf */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; name = rtmp.conf; path = ../../../conf/rtmp.conf; sourceTree = "<group>"; };
3C1EE6CF1AB1080900576EE9 /* security.deny.publish.conf */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; name = security.deny.publish.conf; path = ../../../conf/security.deny.publish.conf; sourceTree = "<group>"; };
...
...
@@ -755,7 +754,6 @@
3C8280281BAFF896004A1794 /* push.flv.conf */,
3C1EE6CA1AB1080900576EE9 /* push.mpegts.over.udp.conf */,
3C1EE6CB1AB1080900576EE9 /* push.rtsp.conf */,
3C1EE6CC1AB1080900576EE9 /* ram.hls.conf */,
3C1EE6CD1AB1080900576EE9 /* realtime.conf */,
3C1EE6CE1AB1080900576EE9 /* rtmp.conf */,
3C1EE6CF1AB1080900576EE9 /* security.deny.publish.conf */,
...
...
trunk/src/app/srs_app_config.cpp
查看文件 @
664844b
...
...
@@ -3910,6 +3910,11 @@ int SrsConfig::check_config()
srs_error
(
"unsupported vhost hls directive %s, ret=%d"
,
m
.
c_str
(),
ret
);
return
ret
;
}
// TODO: FIXME: remove it in future.
if
(
m
==
"hls_storage"
||
m
==
"hls_mount"
)
{
srs_warn
(
"HLS RAM is removed from SRS2 to SRS3+, please read https://github.com/ossrs/srs/issues/513."
);
}
}
}
else
if
(
n
==
"http_hooks"
)
{
for
(
int
j
=
0
;
j
<
(
int
)
conf
->
directives
.
size
();
j
++
)
{
...
...
@@ -6075,40 +6080,6 @@ string SrsConfig::get_hls_on_error(string vhost)
return
conf
->
arg0
();
}
string
SrsConfig
::
get_hls_storage
(
string
vhost
)
{
static
string
DEFAULT
=
"disk"
;
SrsConfDirective
*
conf
=
get_hls
(
vhost
);
if
(
!
conf
)
{
return
DEFAULT
;
}
conf
=
conf
->
get
(
"hls_storage"
);
if
(
!
conf
||
conf
->
arg0
().
empty
())
{
return
DEFAULT
;
}
return
conf
->
arg0
();
}
string
SrsConfig
::
get_hls_mount
(
string
vhost
)
{
static
string
DEFAULT
=
"[vhost]/[app]/[stream].m3u8"
;
SrsConfDirective
*
conf
=
get_hls
(
vhost
);
if
(
!
conf
)
{
return
DEFAULT
;
}
conf
=
conf
->
get
(
"hls_mount"
);
if
(
!
conf
||
conf
->
arg0
().
empty
())
{
return
DEFAULT
;
}
return
conf
->
arg0
();
}
string
SrsConfig
::
get_hls_acodec
(
string
vhost
)
{
static
string
DEFAULT
=
"aac"
;
...
...
trunk/src/app/srs_app_config.hpp
查看文件 @
664844b
...
...
@@ -1184,14 +1184,6 @@ public:
*/
virtual
std
::
string
get_hls_on_error
(
std
::
string
vhost
);
/**
* get the HLS storage type.
*/
virtual
std
::
string
get_hls_storage
(
std
::
string
vhost
);
/**
* get the HLS mount url for HTTP server.
*/
virtual
std
::
string
get_hls_mount
(
std
::
string
vhost
);
/**
* get the HLS default audio codec.
*/
virtual
std
::
string
get_hls_acodec
(
std
::
string
vhost
);
...
...
trunk/src/app/srs_app_hls.cpp
查看文件 @
664844b
...
...
@@ -61,14 +61,6 @@ using namespace std;
// reset the piece id when deviation overflow this.
#define SRS_JUMP_WHEN_PIECE_DEVIATION 20
ISrsHlsHandler
::
ISrsHlsHandler
()
{
}
ISrsHlsHandler
::~
ISrsHlsHandler
()
{
}
/**
* * the HLS section, only available when HLS enabled.
* */
...
...
@@ -294,7 +286,6 @@ string SrsDvrAsyncCallOnHlsNotify::to_string()
SrsHlsMuxer
::
SrsHlsMuxer
()
{
req
=
NULL
;
handler
=
NULL
;
hls_fragment
=
hls_window
=
0
;
hls_aof_ratio
=
1.0
;
deviation_ts
=
0
;
...
...
@@ -384,12 +375,10 @@ int SrsHlsMuxer::deviation()
return
deviation_ts
;
}
int
SrsHlsMuxer
::
initialize
(
ISrsHlsHandler
*
h
)
int
SrsHlsMuxer
::
initialize
()
{
int
ret
=
ERROR_SUCCESS
;
handler
=
h
;
if
((
ret
=
async
->
start
())
!=
ERROR_SUCCESS
)
{
return
ret
;
}
...
...
@@ -426,18 +415,9 @@ int SrsHlsMuxer::update_config(SrsRequest* r, string entry_prefix,
// when update config, reset the history target duration.
max_td
=
(
int
)(
fragment
*
_srs_config
->
get_hls_td_ratio
(
r
->
vhost
));
std
::
string
storage
=
_srs_config
->
get_hls_storage
(
r
->
vhost
);
if
(
storage
==
"ram"
)
{
should_write_cache
=
true
;
should_write_file
=
false
;
}
else
if
(
storage
==
"disk"
)
{
// TODO: FIXME: refine better for SRS2 only support disk.
should_write_cache
=
false
;
should_write_file
=
true
;
}
else
{
srs_assert
(
storage
==
"both"
);
should_write_cache
=
true
;
should_write_file
=
true
;
}
// create m3u8 dir once.
m3u8_dir
=
srs_path_dirname
(
m3u8
);
...
...
@@ -756,13 +736,6 @@ int SrsHlsMuxer::segment_close(string log_desc)
log_desc
.
c_str
(),
current
->
sequence_no
,
current
->
uri
.
c_str
(),
current
->
duration
,
current
->
segment_start_dts
);
// notify handler for update ts.
srs_assert
(
current
->
writer
);
if
(
handler
&&
(
ret
=
handler
->
on_update_ts
(
req
,
current
->
uri
,
current
->
writer
->
cache
()))
!=
ERROR_SUCCESS
)
{
srs_error
(
"notify handler for update ts failed. ret=%d"
,
ret
);
return
ret
;
}
// close the muxer of finished segment.
srs_freep
(
current
->
muxer
);
std
::
string
full_path
=
current
->
full_path
;
...
...
@@ -829,13 +802,6 @@ int SrsHlsMuxer::segment_close(string log_desc)
}
}
if
(
should_write_cache
)
{
if
((
ret
=
handler
->
on_remove_ts
(
req
,
segment
->
uri
))
!=
ERROR_SUCCESS
)
{
srs_warn
(
"remove the ts from ram hls failed. ret=%d"
,
ret
);
return
ret
;
}
}
srs_freep
(
segment
);
}
segment_to_remove
.
clear
();
...
...
@@ -958,12 +924,6 @@ int SrsHlsMuxer::_refresh_m3u8(string m3u8_file)
}
srs_info
(
"write m3u8 %s success."
,
m3u8_file
.
c_str
());
// notify handler for update m3u8.
if
(
handler
&&
(
ret
=
handler
->
on_update_m3u8
(
req
,
writer
.
cache
()))
!=
ERROR_SUCCESS
)
{
srs_error
(
"notify handler for update m3u8 failed. ret=%d"
,
ret
);
return
ret
;
}
return
ret
;
}
...
...
@@ -1171,7 +1131,6 @@ SrsHls::SrsHls()
{
req
=
NULL
;
source
=
NULL
;
handler
=
NULL
;
hls_enabled
=
false
;
hls_can_dispose
=
false
;
...
...
@@ -1243,15 +1202,14 @@ int SrsHls::cycle()
return
ret
;
}
int
SrsHls
::
initialize
(
SrsSource
*
s
,
ISrsHlsHandler
*
h
,
SrsRequest
*
r
)
int
SrsHls
::
initialize
(
SrsSource
*
s
,
SrsRequest
*
r
)
{
int
ret
=
ERROR_SUCCESS
;
source
=
s
;
handler
=
h
;
req
=
r
;
if
((
ret
=
muxer
->
initialize
(
h
))
!=
ERROR_SUCCESS
)
{
if
((
ret
=
muxer
->
initialize
())
!=
ERROR_SUCCESS
)
{
return
ret
;
}
...
...
trunk/src/app/srs_app_hls.hpp
查看文件 @
664844b
...
...
@@ -54,39 +54,6 @@ class SrsTsCache;
class
SrsTsContext
;
/**
* the handler for hls event.
* for example, we use memory only hls for
*/
class
ISrsHlsHandler
{
public
:
ISrsHlsHandler
();
virtual
~
ISrsHlsHandler
();
public
:
/**
* when publish stream
*/
virtual
int
on_hls_publish
(
SrsRequest
*
req
)
=
0
;
/**
* when update the m3u8 file.
*/
virtual
int
on_update_m3u8
(
SrsRequest
*
r
,
std
::
string
m3u8
)
=
0
;
/**
* when reap new ts file.
*/
virtual
int
on_update_ts
(
SrsRequest
*
r
,
std
::
string
uri
,
std
::
string
ts
)
=
0
;
/**
* when remove the specified ts file,
* for the hls to remove the expired ts not in hls window.
*/
virtual
int
on_remove_ts
(
SrsRequest
*
r
,
std
::
string
uri
)
=
0
;
/**
* when unpublish stream
*/
virtual
int
on_hls_unpublish
(
SrsRequest
*
req
)
=
0
;
};
/**
* * the HLS section, only available when HLS enabled.
* */
#ifdef SRS_AUTO_HLS
...
...
@@ -239,8 +206,7 @@ private:
std
::
string
m3u8
;
std
::
string
m3u8_url
;
private
:
ISrsHlsHandler
*
handler
;
// TODO: FIXME: supports reload.
// TODO: FIXME: remove it.
bool
should_write_cache
;
bool
should_write_file
;
private
:
...
...
@@ -277,7 +243,7 @@ public:
/**
* initialize the hls muxer.
*/
virtual
int
initialize
(
ISrsHlsHandler
*
h
);
virtual
int
initialize
();
/**
* when publish, update the config for muxer.
*/
...
...
@@ -390,7 +356,6 @@ class SrsHls
private
:
SrsHlsMuxer
*
muxer
;
SrsHlsCache
*
hls_cache
;
ISrsHlsHandler
*
handler
;
private
:
SrsRequest
*
req
;
bool
hls_enabled
;
...
...
@@ -426,7 +391,7 @@ public:
/**
* initialize the hls by handler and source.
*/
virtual
int
initialize
(
SrsSource
*
s
,
ISrsHlsHandler
*
h
,
SrsRequest
*
r
);
virtual
int
initialize
(
SrsSource
*
s
,
SrsRequest
*
r
);
/**
* publish stream event, continue to write the m3u8,
* for the muxer object not destroyed.
...
...
trunk/src/app/srs_app_http_conn.cpp
查看文件 @
664844b
...
...
@@ -1297,30 +1297,5 @@ void SrsHttpServer::http_unmount(SrsSource* s, SrsRequest* r)
http_stream
->
http_unmount
(
s
,
r
);
}
int
SrsHttpServer
::
mount_hls
(
SrsRequest
*
r
)
{
return
http_stream
->
mount_hls
(
r
);
}
int
SrsHttpServer
::
hls_update_m3u8
(
SrsRequest
*
r
,
std
::
string
m3u8
)
{
return
http_stream
->
hls_update_m3u8
(
r
,
m3u8
);
}
int
SrsHttpServer
::
hls_update_ts
(
SrsRequest
*
r
,
std
::
string
uri
,
std
::
string
ts
)
{
return
http_stream
->
hls_update_ts
(
r
,
uri
,
ts
);
}
int
SrsHttpServer
::
hls_remove_ts
(
SrsRequest
*
r
,
std
::
string
uri
)
{
return
http_stream
->
hls_remove_ts
(
r
,
uri
);
}
void
SrsHttpServer
::
unmount_hls
(
SrsRequest
*
r
)
{
http_stream
->
unmount_hls
(
r
);
}
#endif
...
...
trunk/src/app/srs_app_http_conn.hpp
查看文件 @
664844b
...
...
@@ -417,13 +417,6 @@ public:
public:
virtual
int
http_mount
(
SrsSource
*
s
,
SrsRequest
*
r
);
virtual
void
http_unmount
(
SrsSource
*
s
,
SrsRequest
*
r
);
// hls stream
public:
virtual
int
mount_hls
(
SrsRequest
*
r
);
virtual
int
hls_update_m3u8
(
SrsRequest
*
r
,
std
::
string
m3u8
);
virtual
int
hls_update_ts
(
SrsRequest
*
r
,
std
::
string
uri
,
std
::
string
ts
);
virtual
int
hls_remove_ts
(
SrsRequest
*
r
,
std
::
string
uri
);
virtual
void
unmount_hls
(
SrsRequest
*
r
);
};
#endif
...
...
trunk/src/app/srs_app_http_stream.cpp
查看文件 @
664844b
...
...
@@ -764,22 +764,6 @@ SrsHttpStreamServer::~SrsHttpStreamServer()
}
sflvs
.
clear
();
}
if
(
true
)
{
std
::
map
<
std
::
string
,
SrsHlsEntry
*>::
iterator
it
;
for
(
it
=
thls
.
begin
();
it
!=
thls
.
end
();
++
it
)
{
SrsHlsEntry
*
entry
=
it
->
second
;
srs_freep
(
entry
);
}
thls
.
clear
();
}
if
(
true
)
{
std
::
map
<
std
::
string
,
SrsHlsEntry
*>::
iterator
it
;
for
(
it
=
shls
.
begin
();
it
!=
shls
.
end
();
++
it
)
{
SrsHlsEntry
*
entry
=
it
->
second
;
srs_freep
(
entry
);
}
shls
.
clear
();
}
}
int
SrsHttpStreamServer
::
initialize
()
...
...
@@ -791,11 +775,6 @@ int SrsHttpStreamServer::initialize()
return
ret
;
}
// remux rtmp to hls live streaming
if
((
ret
=
initialize_hls_streaming
())
!=
ERROR_SUCCESS
)
{
return
ret
;
}
return
ret
;
}
...
...
@@ -961,190 +940,6 @@ int SrsHttpStreamServer::on_reload_vhost_http_remux_updated(string vhost)
return
ret
;
}
int
SrsHttpStreamServer
::
mount_hls
(
SrsRequest
*
r
)
{
int
ret
=
ERROR_SUCCESS
;
std
::
string
sid
=
r
->
get_stream_url
();
if
(
shls
.
find
(
sid
)
==
shls
.
end
())
{
srs_info
(
"ignore mount hls stream for disabled"
);
return
ret
;
}
SrsHlsEntry
*
entry
=
shls
[
sid
];
// TODO: FIXME: supports reload.
std
::
map
<
std
::
string
,
ISrsHttpHandler
*>::
iterator
it
;
for
(
it
=
entry
->
streams
.
begin
();
it
!=
entry
->
streams
.
end
();
++
it
)
{
ISrsHttpHandler
*
stream
=
it
->
second
;
stream
->
entry
->
enabled
=
true
;
}
return
ret
;
}
int
SrsHttpStreamServer
::
hls_update_m3u8
(
SrsRequest
*
r
,
string
m3u8
)
{
int
ret
=
ERROR_SUCCESS
;
std
::
string
mount
;
std
::
string
sid
=
r
->
get_stream_url
();
SrsHlsEntry
*
entry
=
NULL
;
// create stream from template when not found.
if
(
shls
.
find
(
sid
)
==
shls
.
end
())
{
if
(
thls
.
find
(
r
->
vhost
)
==
thls
.
end
())
{
srs_info
(
"ignore mount hls stream for disabled"
);
return
ret
;
}
SrsHlsEntry
*
tmpl
=
thls
[
r
->
vhost
];
srs_assert
(
tmpl
);
entry
=
new
SrsHlsEntry
();
mount
=
tmpl
->
mount
;
// replace the vhost variable
mount
=
srs_string_replace
(
mount
,
"[vhost]"
,
r
->
vhost
);
mount
=
srs_string_replace
(
mount
,
"[app]"
,
r
->
app
);
mount
=
srs_string_replace
(
mount
,
"[stream]"
,
r
->
stream
);
// remove the default vhost mount
mount
=
srs_string_replace
(
mount
,
SRS_CONSTS_RTMP_DEFAULT_VHOST
"/"
,
"/"
);
entry
->
tmpl
=
tmpl
;
entry
->
mount
=
mount
;
shls
[
sid
]
=
entry
;
if
(
entry
->
streams
.
find
(
mount
)
==
entry
->
streams
.
end
())
{
ISrsHttpHandler
*
he
=
new
SrsHlsM3u8Stream
();
entry
->
streams
[
mount
]
=
he
;
if
((
ret
=
mux
.
handle
(
mount
,
he
))
!=
ERROR_SUCCESS
)
{
srs_error
(
"handle mount=%s failed. ret=%d"
,
mount
.
c_str
(),
ret
);
return
ret
;
}
}
}
else
{
entry
=
shls
[
sid
];
}
mount
=
entry
->
mount
;
// update the m3u8 stream.
SrsHlsM3u8Stream
*
hms
=
dynamic_cast
<
SrsHlsM3u8Stream
*>
(
entry
->
streams
[
mount
]);
if
(
hms
)
{
hms
->
set_m3u8
(
m3u8
);
}
srs_trace
(
"hls update m3u8 ok, mount=%s"
,
mount
.
c_str
());
return
ret
;
}
int
SrsHttpStreamServer
::
hls_update_ts
(
SrsRequest
*
r
,
string
uri
,
string
ts
)
{
int
ret
=
ERROR_SUCCESS
;
std
::
string
sid
=
r
->
get_stream_url
();
// when no hls mounted, init with empty m3u8.
if
(
shls
.
find
(
sid
)
==
shls
.
end
())
{
if
((
ret
=
hls_update_m3u8
(
r
,
""
))
!=
ERROR_SUCCESS
)
{
return
ret
;
}
}
// find again, ignore if not exits.
if
(
shls
.
find
(
sid
)
==
shls
.
end
())
{
return
ret
;
}
SrsHlsEntry
*
entry
=
shls
[
sid
];
srs_assert
(
entry
);
srs_assert
(
entry
->
tmpl
);
std
::
string
mount
=
hls_mount_generate
(
r
,
uri
,
entry
->
tmpl
->
mount
);
if
(
entry
->
streams
.
find
(
mount
)
==
entry
->
streams
.
end
())
{
ISrsHttpHandler
*
he
=
new
SrsHlsTsStream
();
entry
->
streams
[
mount
]
=
he
;
if
((
ret
=
mux
.
handle
(
mount
,
he
))
!=
ERROR_SUCCESS
)
{
srs_error
(
"handle mount=%s failed. ret=%d"
,
mount
.
c_str
(),
ret
);
return
ret
;
}
}
// update the ts stream.
SrsHlsTsStream
*
hts
=
dynamic_cast
<
SrsHlsTsStream
*>
(
entry
->
streams
[
mount
]);
if
(
hts
)
{
hts
->
set_ts
(
ts
);
}
srs_trace
(
"hls update ts ok, mount=%s"
,
mount
.
c_str
());
return
ret
;
}
int
SrsHttpStreamServer
::
hls_remove_ts
(
SrsRequest
*
r
,
string
uri
)
{
int
ret
=
ERROR_SUCCESS
;
std
::
string
sid
=
r
->
get_stream_url
();
// when no hls mounted, ignore.
if
(
shls
.
find
(
sid
)
==
shls
.
end
())
{
return
ret
;
}
SrsHlsEntry
*
entry
=
shls
[
sid
];
srs_assert
(
entry
);
srs_assert
(
entry
->
tmpl
);
std
::
string
mount
=
hls_mount_generate
(
r
,
uri
,
entry
->
tmpl
->
mount
);
// ignore when no ts mounted.
if
(
entry
->
streams
.
find
(
mount
)
==
entry
->
streams
.
end
())
{
return
ret
;
}
// update the ts stream.
SrsHlsTsStream
*
hts
=
dynamic_cast
<
SrsHlsTsStream
*>
(
entry
->
streams
[
mount
]);
if
(
hts
)
{
hts
->
set_ts
(
""
);
// TODO: FIXME: unmount and remove the http handler.
}
srs_trace
(
"hls remove ts ok, mount=%s"
,
mount
.
c_str
());
return
ret
;
}
void
SrsHttpStreamServer
::
unmount_hls
(
SrsRequest
*
r
)
{
std
::
string
sid
=
r
->
get_stream_url
();
if
(
shls
.
find
(
sid
)
==
shls
.
end
())
{
srs_info
(
"ignore unmount hls stream for disabled"
);
return
;
}
SrsHlsEntry
*
entry
=
shls
[
sid
];
std
::
map
<
std
::
string
,
ISrsHttpHandler
*>::
iterator
it
;
for
(
it
=
entry
->
streams
.
begin
();
it
!=
entry
->
streams
.
end
();
++
it
)
{
ISrsHttpHandler
*
stream
=
it
->
second
;
stream
->
entry
->
enabled
=
false
;
}
}
int
SrsHttpStreamServer
::
on_reload_vhost_hls
(
string
vhost
)
{
int
ret
=
ERROR_SUCCESS
;
// TODO: FIXME: implements it.
return
ret
;
}
int
SrsHttpStreamServer
::
hijack
(
ISrsHttpMessage
*
request
,
ISrsHttpHandler
**
ph
)
{
int
ret
=
ERROR_SUCCESS
;
...
...
@@ -1233,7 +1028,7 @@ int SrsHttpStreamServer::hijack(ISrsHttpMessage* request, ISrsHttpHandler** ph)
}
SrsSource
*
s
=
NULL
;
if
((
ret
=
SrsSource
::
fetch_or_create
(
r
,
server
,
server
,
&
s
))
!=
ERROR_SUCCESS
)
{
if
((
ret
=
SrsSource
::
fetch_or_create
(
r
,
server
,
&
s
))
!=
ERROR_SUCCESS
)
{
return
ret
;
}
srs_assert
(
s
!=
NULL
);
...
...
@@ -1299,59 +1094,5 @@ int SrsHttpStreamServer::initialize_flv_entry(std::string vhost)
return
ret
;
}
int
SrsHttpStreamServer
::
initialize_hls_streaming
()
{
int
ret
=
ERROR_SUCCESS
;
// http hls live stream mount for each vhost.
SrsConfDirective
*
root
=
_srs_config
->
get_root
();
for
(
int
i
=
0
;
i
<
(
int
)
root
->
directives
.
size
();
i
++
)
{
SrsConfDirective
*
conf
=
root
->
at
(
i
);
if
(
!
conf
->
is_vhost
())
{
continue
;
}
std
::
string
vhost
=
conf
->
arg0
();
if
(
!
_srs_config
->
get_hls_enabled
(
vhost
))
{
continue
;
}
std
::
string
storage
=
_srs_config
->
get_hls_storage
(
vhost
);
if
(
storage
!=
"ram"
&&
storage
!=
"both"
)
{
continue
;
}
SrsHlsEntry
*
entry
=
new
SrsHlsEntry
();
entry
->
mount
=
_srs_config
->
get_hls_mount
(
vhost
);
thls
[
vhost
]
=
entry
;
srs_trace
(
"http hls live stream, vhost=%s, mount=%s"
,
vhost
.
c_str
(),
entry
->
mount
.
c_str
());
}
return
ret
;
}
string
SrsHttpStreamServer
::
hls_mount_generate
(
SrsRequest
*
r
,
string
uri
,
string
tmpl
)
{
std
::
string
mount
=
tmpl
;
// the ts is relative from the m3u8, the same start dir.
mount
=
srs_path_dirname
(
mount
);
// replace the vhost variable
mount
=
srs_string_replace
(
mount
,
"[vhost]"
,
r
->
vhost
);
mount
=
srs_string_replace
(
mount
,
"[app]"
,
r
->
app
);
// remove the default vhost mount
mount
=
srs_string_replace
(
mount
,
SRS_CONSTS_RTMP_DEFAULT_VHOST
"/"
,
"/"
);
// mount with ts.
mount
+=
"/"
;
mount
+=
uri
;
return
mount
;
}
#endif
...
...
trunk/src/app/srs_app_http_stream.hpp
查看文件 @
664844b
...
...
@@ -334,10 +334,6 @@ public:
std
::
map
<
std
::
string
,
SrsLiveEntry
*>
tflvs
;
// the http live streaming streams, crote by template.
std
::
map
<
std
::
string
,
SrsLiveEntry
*>
sflvs
;
// the hls live streaming template, to create streams.
std
::
map
<
std
::
string
,
SrsHlsEntry
*>
thls
;
// the hls live streaming streams, crote by template.
std
::
map
<
std
::
string
,
SrsHlsEntry
*>
shls
;
public
:
SrsHttpStreamServer
(
SrsServer
*
svr
);
virtual
~
SrsHttpStreamServer
();
...
...
@@ -347,26 +343,16 @@ public:
public:
virtual
int
http_mount
(
SrsSource
*
s
,
SrsRequest
*
r
);
virtual
void
http_unmount
(
SrsSource
*
s
,
SrsRequest
*
r
);
// hls stream
public:
virtual
int
mount_hls
(
SrsRequest
*
r
);
virtual
int
hls_update_m3u8
(
SrsRequest
*
r
,
std
::
string
m3u8
);
virtual
int
hls_update_ts
(
SrsRequest
*
r
,
std
::
string
uri
,
std
::
string
ts
);
virtual
int
hls_remove_ts
(
SrsRequest
*
r
,
std
::
string
uri
);
virtual
void
unmount_hls
(
SrsRequest
*
r
);
// interface ISrsReloadHandler.
public:
virtual
int
on_reload_vhost_added
(
std
::
string
vhost
);
virtual
int
on_reload_vhost_http_remux_updated
(
std
::
string
vhost
);
virtual
int
on_reload_vhost_hls
(
std
::
string
vhost
);
// interface ISrsHttpMatchHijacker
public:
virtual
int
hijack
(
ISrsHttpMessage
*
request
,
ISrsHttpHandler
**
ph
);
private
:
virtual
int
initialize_flv_streaming
();
virtual
int
initialize_flv_entry
(
std
::
string
vhost
);
virtual
int
initialize_hls_streaming
();
virtual
std
::
string
hls_mount_generate
(
SrsRequest
*
r
,
std
::
string
uri
,
std
::
string
tmpl
);
};
#endif
...
...
trunk/src/app/srs_app_rtmp_conn.cpp
查看文件 @
664844b
...
...
@@ -710,7 +710,7 @@ int SrsRtmpConn::stream_service_cycle()
// find a source to serve.
SrsSource
*
source
=
NULL
;
if
((
ret
=
SrsSource
::
fetch_or_create
(
req
,
server
,
server
,
&
source
))
!=
ERROR_SUCCESS
)
{
if
((
ret
=
SrsSource
::
fetch_or_create
(
req
,
server
,
&
source
))
!=
ERROR_SUCCESS
)
{
return
ret
;
}
srs_assert
(
source
!=
NULL
);
...
...
trunk/src/app/srs_app_server.cpp
查看文件 @
664844b
...
...
@@ -1514,67 +1514,3 @@ void SrsServer::on_unpublish(SrsSource* s, SrsRequest* r)
#endif
}
int
SrsServer
::
on_hls_publish
(
SrsRequest
*
r
)
{
int
ret
=
ERROR_SUCCESS
;
#ifdef SRS_AUTO_HTTP_SERVER
if
((
ret
=
http_server
->
mount_hls
(
r
))
!=
ERROR_SUCCESS
)
{
return
ret
;
}
#endif
return
ret
;
}
int
SrsServer
::
on_update_m3u8
(
SrsRequest
*
r
,
string
m3u8
)
{
int
ret
=
ERROR_SUCCESS
;
#ifdef SRS_AUTO_HTTP_SERVER
if
((
ret
=
http_server
->
hls_update_m3u8
(
r
,
m3u8
))
!=
ERROR_SUCCESS
)
{
return
ret
;
}
#endif
return
ret
;
}
int
SrsServer
::
on_update_ts
(
SrsRequest
*
r
,
string
uri
,
string
ts
)
{
int
ret
=
ERROR_SUCCESS
;
#ifdef SRS_AUTO_HTTP_SERVER
if
((
ret
=
http_server
->
hls_update_ts
(
r
,
uri
,
ts
))
!=
ERROR_SUCCESS
)
{
return
ret
;
}
#endif
return
ret
;
}
int
SrsServer
::
on_remove_ts
(
SrsRequest
*
r
,
string
uri
)
{
int
ret
=
ERROR_SUCCESS
;
#ifdef SRS_AUTO_HTTP_SERVER
if
((
ret
=
http_server
->
hls_remove_ts
(
r
,
uri
))
!=
ERROR_SUCCESS
)
{
return
ret
;
}
#endif
return
ret
;
}
int
SrsServer
::
on_hls_unpublish
(
SrsRequest
*
r
)
{
int
ret
=
ERROR_SUCCESS
;
#ifdef SRS_AUTO_HTTP_SERVER
http_server
->
unmount_hls
(
r
);
#endif
return
ret
;
}
...
...
trunk/src/app/srs_app_server.hpp
查看文件 @
664844b
...
...
@@ -237,7 +237,7 @@ public:
* start connection service thread, destroy client.
*/
class
SrsServer
:
virtual
public
ISrsReloadHandler
,
virtual
public
ISrsSourceHandler
,
virtual
public
ISrsHlsHandler
,
virtual
public
ISrsSourceHandler
,
virtual
public
IConnectionManager
{
private
:
...
...
@@ -391,13 +391,6 @@ public:
public:
virtual
int
on_publish
(
SrsSource
*
s
,
SrsRequest
*
r
);
virtual
void
on_unpublish
(
SrsSource
*
s
,
SrsRequest
*
r
);
// interface ISrsHlsHandler
public:
virtual
int
on_hls_publish
(
SrsRequest
*
r
);
virtual
int
on_update_m3u8
(
SrsRequest
*
r
,
std
::
string
m3u8
);
virtual
int
on_update_ts
(
SrsRequest
*
r
,
std
::
string
uri
,
std
::
string
ts
);
virtual
int
on_remove_ts
(
SrsRequest
*
r
,
std
::
string
uri
);
virtual
int
on_hls_unpublish
(
SrsRequest
*
r
);
};
#endif
...
...
trunk/src/app/srs_app_source.cpp
查看文件 @
664844b
...
...
@@ -737,7 +737,7 @@ ISrsSourceHandler::~ISrsSourceHandler()
std
::
map
<
std
::
string
,
SrsSource
*>
SrsSource
::
pool
;
int
SrsSource
::
fetch_or_create
(
SrsRequest
*
r
,
ISrsSourceHandler
*
h
,
ISrsHlsHandler
*
hh
,
SrsSource
**
pps
)
int
SrsSource
::
fetch_or_create
(
SrsRequest
*
r
,
ISrsSourceHandler
*
h
,
SrsSource
**
pps
)
{
int
ret
=
ERROR_SUCCESS
;
...
...
@@ -754,7 +754,7 @@ int SrsSource::fetch_or_create(SrsRequest* r, ISrsSourceHandler* h, ISrsHlsHandl
srs_assert
(
pool
.
find
(
stream_url
)
==
pool
.
end
());
source
=
new
SrsSource
();
if
((
ret
=
source
->
initialize
(
r
,
h
,
hh
))
!=
ERROR_SUCCESS
)
{
if
((
ret
=
source
->
initialize
(
r
,
h
))
!=
ERROR_SUCCESS
)
{
srs_freep
(
source
);
return
ret
;
}
...
...
@@ -1058,12 +1058,11 @@ bool SrsSource::expired()
return
false
;
}
int
SrsSource
::
initialize
(
SrsRequest
*
r
,
ISrsSourceHandler
*
h
,
ISrsHlsHandler
*
hh
)
int
SrsSource
::
initialize
(
SrsRequest
*
r
,
ISrsSourceHandler
*
h
)
{
int
ret
=
ERROR_SUCCESS
;
srs_assert
(
h
);
srs_assert
(
hh
);
srs_assert
(
!
req
);
handler
=
h
;
...
...
@@ -1071,7 +1070,7 @@ int SrsSource::initialize(SrsRequest* r, ISrsSourceHandler* h, ISrsHlsHandler* h
atc
=
_srs_config
->
get_atc
(
req
->
vhost
);
#ifdef SRS_AUTO_HLS
if
((
ret
=
hls
->
initialize
(
this
,
hh
,
req
))
!=
ERROR_SUCCESS
)
{
if
((
ret
=
hls
->
initialize
(
this
,
req
))
!=
ERROR_SUCCESS
)
{
return
ret
;
}
#endif
...
...
trunk/src/app/srs_app_source.hpp
查看文件 @
664844b
...
...
@@ -63,7 +63,6 @@ class SrsDvr;
class
SrsEncoder
;
#endif
class
SrsBuffer
;
class
ISrsHlsHandler
;
#ifdef SRS_AUTO_HDS
class
SrsHds
;
#endif
...
...
@@ -423,10 +422,9 @@ public:
* create source when fetch from cache failed.
* @param r the client request.
* @param h the event handler for source.
* @param hh the event handler for hls.
* @param pps the matched source, if success never be NULL.
*/
static
int
fetch_or_create
(
SrsRequest
*
r
,
ISrsSourceHandler
*
h
,
ISrsHlsHandler
*
hh
,
SrsSource
**
pps
);
static
int
fetch_or_create
(
SrsRequest
*
r
,
ISrsSourceHandler
*
h
,
SrsSource
**
pps
);
private
:
/**
* get the exists source, NULL when not exists.
...
...
@@ -533,7 +531,7 @@ public:
/**
* initialize the hls with handlers.
*/
virtual
int
initialize
(
SrsRequest
*
r
,
ISrsSourceHandler
*
h
,
ISrsHlsHandler
*
hh
);
virtual
int
initialize
(
SrsRequest
*
r
,
ISrsSourceHandler
*
h
);
// interface ISrsReloadHandler
public:
virtual
int
on_reload_vhost_play
(
std
::
string
vhost
);
...
...
请
注册
或
登录
后发表评论