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
2015-10-13 16:06:37 +0800
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
d9f991ed2f95535d59bb2775d22f80bf2f9a430c
d9f991ed
1 parent
ca73534d
use system utility for string finds
隐藏空白字符变更
内嵌
并排对比
正在显示
16 个修改的文件
包含
111 行增加
和
112 行删除
trunk/src/app/srs_app_caster_flv.cpp
trunk/src/app/srs_app_dvr.cpp
trunk/src/app/srs_app_http_conn.cpp
trunk/src/app/srs_app_http_static.cpp
trunk/src/app/srs_app_http_stream.cpp
trunk/src/app/srs_app_ingest.cpp
trunk/src/app/srs_app_mpegts_udp.cpp
trunk/src/app/srs_app_rtsp.cpp
trunk/src/app/srs_app_st.hpp
trunk/src/kernel/srs_kernel_utility.cpp
trunk/src/kernel/srs_kernel_utility.hpp
trunk/src/libs/srs_librtmp.cpp
trunk/src/protocol/srs_http_stack.cpp
trunk/src/protocol/srs_protocol_utility.cpp
trunk/src/protocol/srs_protocol_utility.hpp
trunk/src/protocol/srs_rtsp_stack.cpp
trunk/src/app/srs_app_caster_flv.cpp
查看文件 @
d9f991e
...
...
@@ -268,19 +268,8 @@ int SrsDynamicHttpConn::connect()
// parse uri
if
(
!
req
)
{
req
=
new
SrsRequest
();
size_t
pos
=
string
::
npos
;
string
uri
=
req
->
tcUrl
=
output
;
// tcUrl, stream
if
((
pos
=
uri
.
rfind
(
"/"
))
!=
string
::
npos
)
{
req
->
stream
=
uri
.
substr
(
pos
+
1
);
req
->
tcUrl
=
uri
=
uri
.
substr
(
0
,
pos
);
}
srs_discovery_tc_url
(
req
->
tcUrl
,
req
->
schema
,
req
->
host
,
req
->
vhost
,
req
->
app
,
req
->
port
,
req
->
param
);
srs_parse_rtmp_url
(
output
,
req
->
tcUrl
,
req
->
stream
);
srs_discovery_tc_url
(
req
->
tcUrl
,
req
->
schema
,
req
->
host
,
req
->
vhost
,
req
->
app
,
req
->
port
,
req
->
param
);
}
// connect host.
...
...
trunk/src/app/srs_app_dvr.cpp
查看文件 @
d9f991e
...
...
@@ -107,7 +107,7 @@ int SrsFlvSegment::open(bool use_tmp_file)
bool
fresh_flv_file
=
!
srs_path_exists
(
path
);
// create dir first.
std
::
string
dir
=
path
.
substr
(
0
,
path
.
rfind
(
"/"
)
);
std
::
string
dir
=
srs_path_dirname
(
path
);
if
((
ret
=
srs_create_dir_recursively
(
dir
))
!=
ERROR_SUCCESS
)
{
srs_error
(
"create dir=%s failed. ret=%d"
,
dir
.
c_str
(),
ret
);
return
ret
;
...
...
trunk/src/app/srs_app_http_conn.cpp
查看文件 @
d9f991e
...
...
@@ -572,12 +572,7 @@ int SrsHttpMessage::update(string url, bool allow_jsonp, http_parser* header, Sr
}
// parse ext.
_ext
=
_uri
->
get_path
();
if
((
pos
=
_ext
.
rfind
(
"."
))
!=
string
::
npos
)
{
_ext
=
_ext
.
substr
(
pos
);
}
else
{
_ext
=
""
;
}
_ext
=
srs_path_filext
(
_uri
->
get_path
());
// parse jsonp request message.
if
(
allow_jsonp
)
{
...
...
@@ -816,23 +811,23 @@ SrsRequest* SrsHttpMessage::to_request(string vhost)
{
SrsRequest
*
req
=
new
SrsRequest
();
req
->
app
=
_uri
->
get_path
();
size_t
pos
=
string
::
npos
;
if
((
pos
=
req
->
app
.
rfind
(
"/"
))
!=
string
::
npos
)
{
req
->
stream
=
req
->
app
.
substr
(
pos
+
1
);
req
->
app
=
req
->
app
.
substr
(
0
,
pos
);
}
if
((
pos
=
req
->
stream
.
rfind
(
"."
))
!=
string
::
npos
)
{
req
->
stream
=
req
->
stream
.
substr
(
0
,
pos
);
}
// http path, for instance, /live/livestream.flv, parse to
// app: /live
// stream: livestream.flv
srs_parse_rtmp_url
(
_uri
->
get_path
(),
req
->
app
,
req
->
stream
);
// trim the start slash, for instance, /live to live
req
->
app
=
srs_string_trim_start
(
req
->
app
,
"/"
);
// remove the extension, for instance, livestream.flv to livestream
req
->
stream
=
srs_path_filename
(
req
->
stream
);
req
->
tcUrl
=
"rtmp://"
+
vhost
+
req
->
app
;
// generate others.
req
->
tcUrl
=
"rtmp://"
+
vhost
+
"/"
+
req
->
app
;
req
->
pageUrl
=
get_request_header
(
"Referer"
);
req
->
objectEncoding
=
0
;
srs_discovery_tc_url
(
req
->
tcUrl
,
req
->
schema
,
req
->
host
,
req
->
vhost
,
req
->
app
,
req
->
port
,
req
->
param
);
srs_discovery_tc_url
(
req
->
tcUrl
,
req
->
schema
,
req
->
host
,
req
->
vhost
,
req
->
app
,
req
->
port
,
req
->
param
);
req
->
strip
();
return
req
;
...
...
trunk/src/app/srs_app_http_static.cpp
查看文件 @
d9f991e
...
...
@@ -242,7 +242,7 @@ int SrsHttpStaticServer::initialize()
mount
=
srs_string_replace
(
mount
,
SRS_CONSTS_RTMP_DEFAULT_VHOST
"/"
,
"/"
);
// the dir mount must always ends with "/"
if
(
mount
!=
"/"
&&
mount
.
rfind
(
"/"
)
!=
mount
.
length
()
-
1
)
{
if
(
mount
!=
"/"
&&
!
srs_string_ends_with
(
mount
,
"/"
)
)
{
mount
+=
"/"
;
}
...
...
trunk/src/app/srs_app_http_stream.cpp
查看文件 @
d9f991e
...
...
@@ -611,11 +611,7 @@ SrsLiveEntry::SrsLiveEntry(std::string m, bool h)
req
=
NULL
;
source
=
NULL
;
std
::
string
ext
;
size_t
pos
=
string
::
npos
;
if
((
pos
=
m
.
rfind
(
"."
))
!=
string
::
npos
)
{
ext
=
m
.
substr
(
pos
);
}
std
::
string
ext
=
srs_path_filext
(
m
);
_is_flv
=
(
ext
==
".flv"
);
_is_ts
=
(
ext
==
".ts"
);
_is_mp3
=
(
ext
==
".mp3"
);
...
...
@@ -1319,10 +1315,7 @@ string SrsHttpStreamServer::hls_mount_generate(SrsRequest* r, string uri, string
std
::
string
mount
=
tmpl
;
// the ts is relative from the m3u8, the same start dir.
size_t
pos
=
string
::
npos
;
if
((
pos
=
mount
.
rfind
(
"/"
))
!=
string
::
npos
)
{
mount
=
mount
.
substr
(
0
,
pos
);
}
mount
=
srs_path_dirname
(
mount
);
// replace the vhost variable
mount
=
srs_string_replace
(
mount
,
"[vhost]"
,
r
->
vhost
);
...
...
trunk/src/app/srs_app_ingest.cpp
查看文件 @
d9f991e
...
...
@@ -35,6 +35,7 @@ using namespace std;
#include <srs_app_pithy_print.hpp>
#include <srs_kernel_utility.hpp>
#include <srs_app_utility.hpp>
#include <srs_protocol_utility.hpp>
// when error, ingester sleep for a while and retry.
// ingest never sleep a long time, for we must start the stream ASAP.
...
...
@@ -354,17 +355,9 @@ int SrsIngester::initialize_ffmpeg(SrsFFMPEG* ffmpeg, SrsConfDirective* vhost, S
}
// find the app and stream in rtmp url
std
::
string
url
=
output
;
std
::
string
app
,
stream
;
size_t
pos
=
std
::
string
::
npos
;
if
((
pos
=
url
.
rfind
(
"/"
))
!=
std
::
string
::
npos
)
{
stream
=
url
.
substr
(
pos
+
1
);
url
=
url
.
substr
(
0
,
pos
);
}
if
((
pos
=
url
.
rfind
(
"/"
))
!=
std
::
string
::
npos
)
{
app
=
url
.
substr
(
pos
+
1
);
url
=
url
.
substr
(
0
,
pos
);
}
srs_parse_rtmp_url
(
output
,
app
,
stream
);
size_t
pos
;
if
((
pos
=
app
.
rfind
(
"?"
))
!=
std
::
string
::
npos
)
{
app
=
app
.
substr
(
0
,
pos
);
}
...
...
trunk/src/app/srs_app_mpegts_udp.cpp
查看文件 @
d9f991e
...
...
@@ -611,19 +611,8 @@ int SrsMpegtsOverUdp::connect()
// parse uri
if
(
!
req
)
{
req
=
new
SrsRequest
();
size_t
pos
=
string
::
npos
;
string
uri
=
req
->
tcUrl
=
output
;
// tcUrl, stream
if
((
pos
=
uri
.
rfind
(
"/"
))
!=
string
::
npos
)
{
req
->
stream
=
uri
.
substr
(
pos
+
1
);
req
->
tcUrl
=
uri
=
uri
.
substr
(
0
,
pos
);
}
srs_discovery_tc_url
(
req
->
tcUrl
,
req
->
schema
,
req
->
host
,
req
->
vhost
,
req
->
app
,
req
->
port
,
req
->
param
);
srs_parse_rtmp_url
(
output
,
req
->
tcUrl
,
req
->
stream
);
srs_discovery_tc_url
(
req
->
tcUrl
,
req
->
schema
,
req
->
host
,
req
->
vhost
,
req
->
app
,
req
->
port
,
req
->
param
);
}
// connect host.
...
...
trunk/src/app/srs_app_rtsp.cpp
查看文件 @
d9f991e
...
...
@@ -270,10 +270,7 @@ int SrsRtspConn::do_cycle()
if
((
pos
=
rtsp_tcUrl
.
rfind
(
".sdp"
))
!=
string
::
npos
)
{
rtsp_tcUrl
=
rtsp_tcUrl
.
substr
(
0
,
pos
);
}
if
((
pos
=
rtsp_tcUrl
.
rfind
(
"/"
))
!=
string
::
npos
)
{
rtsp_stream
=
rtsp_tcUrl
.
substr
(
pos
+
1
);
rtsp_tcUrl
=
rtsp_tcUrl
.
substr
(
0
,
pos
);
}
srs_parse_rtmp_url
(
rtsp_tcUrl
,
rtsp_tcUrl
,
rtsp_stream
);
srs_assert
(
req
->
sdp
);
video_id
=
::
atoi
(
req
->
sdp
->
video_stream_id
.
c_str
());
...
...
@@ -651,8 +648,6 @@ int SrsRtspConn::connect()
// parse uri
if
(
!
req
)
{
req
=
new
SrsRequest
();
std
::
string
schema
,
host
,
vhost
,
app
,
port
,
param
;
srs_discovery_tc_url
(
rtsp_tcUrl
,
schema
,
host
,
vhost
,
app
,
port
,
param
);
...
...
@@ -660,19 +655,10 @@ int SrsRtspConn::connect()
std
::
string
output
=
output_template
;
output
=
srs_string_replace
(
output
,
"[app]"
,
app
);
output
=
srs_string_replace
(
output
,
"[stream]"
,
rtsp_stream
);
size_t
pos
=
string
::
npos
;
string
uri
=
req
->
tcUrl
=
output
;
// tcUrl, stream
if
((
pos
=
uri
.
rfind
(
"/"
))
!=
string
::
npos
)
{
req
->
stream
=
uri
.
substr
(
pos
+
1
);
req
->
tcUrl
=
uri
=
uri
.
substr
(
0
,
pos
);
}
srs_discovery_tc_url
(
req
->
tcUrl
,
req
->
schema
,
req
->
host
,
req
->
vhost
,
req
->
app
,
req
->
port
,
req
->
param
);
req
=
new
SrsRequest
();
srs_parse_rtmp_url
(
output
,
req
->
tcUrl
,
req
->
stream
);
srs_discovery_tc_url
(
req
->
tcUrl
,
req
->
schema
,
req
->
host
,
req
->
vhost
,
req
->
app
,
req
->
port
,
req
->
param
);
}
// connect host.
...
...
trunk/src/app/srs_app_st.hpp
查看文件 @
d9f991e
...
...
@@ -202,6 +202,17 @@ public:
virtual
int
writev
(
const
iovec
*
iov
,
int
iov_size
,
ssize_t
*
nwrite
);
};
/**
* the common tcp client, to connect to specified TCP server,
* reconnect and close the connection.
*/
class
SrsTcpClient
{
public
:
SrsTcpClient
();
virtual
~
SrsTcpClient
();
};
// initialize st, requires epoll.
extern
int
srs_st_init
();
...
...
trunk/src/kernel/srs_kernel_utility.cpp
查看文件 @
d9f991e
...
...
@@ -464,6 +464,29 @@ string srs_path_basename(string path)
return
dirname
;
}
string
srs_path_filename
(
string
path
)
{
std
::
string
filename
=
path
;
size_t
pos
=
string
::
npos
;
if
((
pos
=
filename
.
rfind
(
"."
))
!=
string
::
npos
)
{
return
filename
.
substr
(
0
,
pos
);
}
return
filename
;
}
string
srs_path_filext
(
string
path
)
{
size_t
pos
=
string
::
npos
;
if
((
pos
=
path
.
rfind
(
"."
))
!=
string
::
npos
)
{
return
path
.
substr
(
pos
);
}
return
""
;
}
bool
srs_avc_startswith_annexb
(
SrsBuffer
*
stream
,
int
*
pnb_start_code
)
{
...
...
@@ -471,7 +494,7 @@ bool srs_avc_startswith_annexb(SrsBuffer* stream, int* pnb_start_code)
char
*
p
=
bytes
;
for
(;;)
{
if
(
!
stream
->
require
(
p
-
bytes
+
3
))
{
if
(
!
stream
->
require
(
(
int
)(
p
-
bytes
+
3
)
))
{
return
false
;
}
...
...
trunk/src/kernel/srs_kernel_utility.hpp
查看文件 @
d9f991e
...
...
@@ -96,10 +96,14 @@ extern int srs_create_dir_recursively(std::string dir);
// whether path exists.
extern
bool
srs_path_exists
(
std
::
string
path
);
// get the dirname of path
// get the dirname of path
, for instance, filename("/live/livestream")="/live"
extern
std
::
string
srs_path_dirname
(
std
::
string
path
);
// get the basename of path
// get the basename of path
, for instance, filename("/live/livestream")="livestream"
extern
std
::
string
srs_path_basename
(
std
::
string
path
);
// get the filename of path, for instance, filename("livestream.flv")="livestream"
extern
std
::
string
srs_path_filename
(
std
::
string
path
);
// get the file extension of path, for instance, filext("live.flv")=".flv"
extern
std
::
string
srs_path_filext
(
std
::
string
path
);
/**
* whether stream starts with the avc NALU in "AnnexB"
...
...
trunk/src/libs/srs_librtmp.cpp
查看文件 @
d9f991e
...
...
@@ -464,16 +464,9 @@ int srs_librtmp_context_parse_uri(Context* context)
{
int
ret
=
ERROR_SUCCESS
;
// parse uri
size_t
pos
=
string
::
npos
;
string
uri
=
context
->
url
;
// tcUrl, stream
if
((
pos
=
uri
.
rfind
(
"/"
))
!=
string
::
npos
)
{
context
->
stream
=
uri
.
substr
(
pos
+
1
);
context
->
tcUrl
=
uri
=
uri
.
substr
(
0
,
pos
);
}
std
::
string
schema
;
srs_parse_rtmp_url
(
context
->
url
,
context
->
tcUrl
,
context
->
stream
);
srs_discovery_tc_url
(
context
->
tcUrl
,
schema
,
context
->
host
,
context
->
vhost
,
context
->
app
,
context
->
port
,
context
->
param
);
...
...
trunk/src/protocol/srs_http_stack.cpp
查看文件 @
d9f991e
...
...
@@ -377,11 +377,7 @@ int SrsHttpFileServer::serve_file(ISrsHttpResponseWriter* w, ISrsHttpMessage* r,
}
if
(
true
)
{
size_t
pos
;
std
::
string
ext
=
fullpath
;
if
((
pos
=
ext
.
rfind
(
"."
))
!=
string
::
npos
)
{
ext
=
ext
.
substr
(
pos
);
}
std
::
string
ext
=
srs_path_filext
(
fullpath
);
if
(
_mime
.
find
(
ext
)
==
_mime
.
end
())
{
w
->
header
()
->
set_content_type
(
"application/octet-stream"
);
...
...
trunk/src/protocol/srs_protocol_utility.cpp
查看文件 @
d9f991e
...
...
@@ -44,7 +44,7 @@ using namespace std;
void
srs_discovery_tc_url
(
string
tcUrl
,
string
&
schema
,
string
&
host
,
string
&
vhost
,
string
&
app
,
int
&
port
,
st
d
::
st
ring
&
param
string
&
app
,
int
&
port
,
string
&
param
)
{
size_t
pos
=
std
::
string
::
npos
;
std
::
string
url
=
tcUrl
;
...
...
@@ -229,7 +229,7 @@ int srs_rtmp_create_msg(char type, u_int32_t timestamp, char* data, int size, in
return
ret
;
}
st
d
::
string
srs_generate_stream_url
(
std
::
string
vhost
,
std
::
string
app
,
std
::
string
stream
)
st
ring
srs_generate_stream_url
(
string
vhost
,
string
app
,
string
stream
)
{
std
::
string
url
=
""
;
...
...
@@ -244,6 +244,18 @@ std::string srs_generate_stream_url(std::string vhost, std::string app, std::str
return
url
;
}
void
srs_parse_rtmp_url
(
string
url
,
string
&
tcUrl
,
string
&
stream
)
{
size_t
pos
;
if
((
pos
=
url
.
rfind
(
"/"
))
!=
string
::
npos
)
{
stream
=
url
.
substr
(
pos
+
1
);
tcUrl
=
url
.
substr
(
0
,
pos
);
}
else
{
tcUrl
=
url
;
}
}
string
srs_generate_rtmp_url
(
string
server
,
int
port
,
string
vhost
,
string
app
,
string
stream
)
{
std
::
stringstream
ss
;
...
...
trunk/src/protocol/srs_protocol_utility.hpp
查看文件 @
d9f991e
...
...
@@ -101,16 +101,34 @@ extern bool srs_bytes_equals(void* pa, void* pb, int size);
* @param data the packet bytes. user should never free it.
* @param ppmsg output the shared ptr message. user should free it.
*/
extern
int
srs_rtmp_create_msg
(
char
type
,
u_int32_t
timestamp
,
char
*
data
,
int
size
,
int
stream_id
,
SrsSharedPtrMessage
**
ppmsg
);
extern
int
srs_rtmp_create_msg
(
char
type
,
u_int32_t
timestamp
,
char
*
data
,
int
size
,
int
stream_id
,
SrsSharedPtrMessage
**
ppmsg
);
// get the stream identify, vhost/app/stream.
extern
std
::
string
srs_generate_stream_url
(
std
::
string
vhost
,
std
::
string
app
,
std
::
string
stream
);
extern
std
::
string
srs_generate_stream_url
(
std
::
string
vhost
,
std
::
string
app
,
std
::
string
stream
);
// parse the rtmp url to tcUrl/stream,
// for example, rtmp://v.ossrs.net/live/livestream to
// tcUrl: rtmp://v.ossrs.net/live
// stream: livestream
extern
void
srs_parse_rtmp_url
(
std
::
string
url
,
std
::
string
&
tcUrl
,
std
::
string
&
stream
);
// genereate the rtmp url, for instance, rtmp://server:port/app...vhost...vhost/stream
extern
std
::
string
srs_generate_rtmp_url
(
std
::
string
server
,
int
port
,
std
::
string
vhost
,
std
::
string
app
,
std
::
string
stream
);
extern
std
::
string
srs_generate_rtmp_url
(
std
::
string
server
,
int
port
,
std
::
string
vhost
,
std
::
string
app
,
std
::
string
stream
);
// write large numbers of iovs.
extern
int
srs_write_large_iovs
(
ISrsProtocolReaderWriter
*
skt
,
iovec
*
iovs
,
int
size
,
ssize_t
*
pnwrite
=
NULL
);
extern
int
srs_write_large_iovs
(
ISrsProtocolReaderWriter
*
skt
,
iovec
*
iovs
,
int
size
,
ssize_t
*
pnwrite
=
NULL
);
#endif
...
...
trunk/src/protocol/srs_rtsp_stack.cpp
查看文件 @
d9f991e
...
...
@@ -988,10 +988,7 @@ int SrsRtspStack::do_recv_message(SrsRtspRequest* req)
// for setup, parse the stream id from uri.
if
(
req
->
is_setup
())
{
size_t
pos
=
string
::
npos
;
std
::
string
stream_id
;
if
((
pos
=
req
->
uri
.
rfind
(
"/"
))
!=
string
::
npos
)
{
stream_id
=
req
->
uri
.
substr
(
pos
+
1
);
}
std
::
string
stream_id
=
srs_path_basename
(
req
->
uri
);
if
((
pos
=
stream_id
.
find
(
"="
))
!=
string
::
npos
)
{
stream_id
=
stream_id
.
substr
(
pos
+
1
);
}
...
...
请
注册
或
登录
后发表评论