Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
Z
ZLMediaKit
概览
Overview
Details
Activity
Cycle Analytics
版本库
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
问题
0
Issues
0
列表
Board
标记
里程碑
合并请求
0
Merge Requests
0
CI / CD
CI / CD
流水线
作业
日程表
图表
维基
Wiki
代码片段
Snippets
成员
Collapse sidebar
Close sidebar
活动
图像
聊天
创建新问题
作业
提交
Issue Boards
Open sidebar
张翔宇
ZLMediaKit
Commits
bf39cf3e
Commit
bf39cf3e
authored
Jun 28, 2019
by
xiongziliang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
整理优化代码
parent
3e841423
隐藏空白字符变更
内嵌
并排
正在显示
29 个修改的文件
包含
272 行增加
和
256 行删除
+272
-256
src/Common/MediaSource.cpp
+0
-1
src/Common/MediaSource.h
+2
-1
src/Common/Parser.cpp
+33
-0
src/Common/Parser.h
+182
-0
src/Http/HttpClient.cpp
+1
-1
src/Http/HttpClient.h
+2
-1
src/Http/HttpCookieManager.h
+1
-1
src/Http/HttpSession.h
+1
-1
src/Player/PlayerBase.cpp
+0
-1
src/Pusher/PusherBase.cpp
+0
-1
src/Rtmp/RtmpPlayer.cpp
+0
-1
src/Rtmp/RtmpProtocol.cpp
+0
-1
src/Rtmp/RtmpPusher.cpp
+0
-1
src/Rtsp/RtpBroadCaster.h
+0
-1
src/Rtsp/RtpReceiver.h
+0
-1
src/Rtsp/Rtsp.cpp
+6
-29
src/Rtsp/Rtsp.h
+14
-178
src/Rtsp/RtspMediaSource.h
+8
-9
src/Rtsp/RtspPlayer.cpp
+3
-3
src/Rtsp/RtspPlayer.h
+2
-3
src/Rtsp/RtspPlayerImp.h
+5
-5
src/Rtsp/RtspPusher.cpp
+2
-2
src/Rtsp/RtspPusher.h
+1
-2
src/Rtsp/RtspSession.cpp
+3
-3
src/Rtsp/RtspSession.h
+0
-1
src/Rtsp/RtspSplitter.h
+1
-1
src/RtspMuxer/RtpCodec.h
+0
-1
src/RtspMuxer/RtspDemuxer.cpp
+3
-3
src/RtspMuxer/RtspDemuxer.h
+2
-3
没有找到文件。
src/Common/MediaSource.cpp
查看文件 @
bf39cf3e
...
...
@@ -28,7 +28,6 @@
#include "MediaSource.h"
#include "MediaFile/MediaReader.h"
#include "Util/util.h"
#include "Rtsp/Rtsp.h"
#include "Network/sockutil.h"
#include "Network/TcpSession.h"
...
...
src/Common/MediaSource.h
查看文件 @
bf39cf3e
...
...
@@ -34,10 +34,11 @@
#include <functional>
#include <unordered_map>
#include "Common/config.h"
#include "Common/Parser.h"
#include "Util/logger.h"
#include "Util/TimeTicker.h"
#include "Util/NoticeCenter.h"
#include "
Rtsp/Rtsp
.h"
#include "
Extension/Track
.h"
using
namespace
std
;
using
namespace
toolkit
;
...
...
src/Common/Parser.cpp
0 → 100644
查看文件 @
bf39cf3e
//
// Created by xzl on 2019/6/28.
//
#include "Parser.h"
namespace
mediakit
{
string
FindField
(
const
char
*
buf
,
const
char
*
start
,
const
char
*
end
,
int
bufSize
)
{
if
(
bufSize
<=
0
){
bufSize
=
strlen
(
buf
);
}
const
char
*
msg_start
=
buf
,
*
msg_end
=
buf
+
bufSize
;
int
len
=
0
;
if
(
start
!=
NULL
)
{
len
=
strlen
(
start
);
msg_start
=
strstr
(
buf
,
start
);
}
if
(
msg_start
==
NULL
)
{
return
""
;
}
msg_start
+=
len
;
if
(
end
!=
NULL
)
{
msg_end
=
strstr
(
msg_start
,
end
);
if
(
msg_end
==
NULL
)
{
return
""
;
}
}
return
string
(
msg_start
,
msg_end
);
}
}
//
namespace
mediakit
\ No newline at end of file
src/Common/Parser.h
0 → 100644
查看文件 @
bf39cf3e
//
// Created by xzl on 2019/6/28.
//
#ifndef ZLMEDIAKIT_PARSER_H
#define ZLMEDIAKIT_PARSER_H
#include <map>
#include <string>
#include "Util/util.h"
using
namespace
std
;
using
namespace
toolkit
;
namespace
mediakit
{
string
FindField
(
const
char
*
buf
,
const
char
*
start
,
const
char
*
end
,
int
bufSize
=
0
);
struct
StrCaseCompare
{
bool
operator
()(
const
string
&
__x
,
const
string
&
__y
)
const
{
return
strcasecmp
(
__x
.
data
(),
__y
.
data
())
<
0
;
}
};
class
StrCaseMap
:
public
multimap
<
string
,
string
,
StrCaseCompare
>
{
public
:
typedef
multimap
<
string
,
string
,
StrCaseCompare
>
Super
;
StrCaseMap
()
=
default
;
~
StrCaseMap
()
=
default
;
string
&
operator
[](
const
string
&
key
){
auto
it
=
find
(
key
);
if
(
it
==
end
()){
it
=
Super
::
emplace
(
key
,
""
);
}
return
it
->
second
;
}
template
<
class
K
,
class
V
>
void
emplace
(
K
&&
k
,
V
&&
v
)
{
auto
it
=
find
(
k
);
if
(
it
!=
end
()){
return
;
}
Super
::
emplace
(
std
::
forward
<
K
>
(
k
),
std
::
forward
<
V
>
(
v
));
}
template
<
class
K
,
class
V
>
void
emplace_force
(
K
&&
k
,
V
&&
v
)
{
Super
::
emplace
(
std
::
forward
<
K
>
(
k
),
std
::
forward
<
V
>
(
v
));
}
};
class
Parser
{
public
:
Parser
()
{}
virtual
~
Parser
()
{}
void
Parse
(
const
char
*
buf
)
{
//解析
const
char
*
start
=
buf
;
Clear
();
while
(
true
)
{
auto
line
=
FindField
(
start
,
NULL
,
"
\r\n
"
);
if
(
line
.
size
()
==
0
)
{
break
;
}
if
(
start
==
buf
)
{
_strMethod
=
FindField
(
line
.
data
(),
NULL
,
" "
);
_strFullUrl
=
FindField
(
line
.
data
(),
" "
,
" "
);
auto
args_pos
=
_strFullUrl
.
find
(
'?'
);
if
(
args_pos
!=
string
::
npos
)
{
_strUrl
=
_strFullUrl
.
substr
(
0
,
args_pos
);
_params
=
_strFullUrl
.
substr
(
args_pos
+
1
);
_mapUrlArgs
=
parseArgs
(
_params
);
}
else
{
_strUrl
=
_strFullUrl
;
}
_strTail
=
FindField
(
line
.
data
(),
(
_strFullUrl
+
" "
).
data
(),
NULL
);
}
else
{
auto
field
=
FindField
(
line
.
data
(),
NULL
,
": "
);
auto
value
=
FindField
(
line
.
data
(),
": "
,
NULL
);
if
(
field
.
size
()
!=
0
)
{
_mapHeaders
.
emplace_force
(
field
,
value
);
}
}
start
=
start
+
line
.
size
()
+
2
;
if
(
strncmp
(
start
,
"
\r\n
"
,
2
)
==
0
)
{
//协议解析完毕
_strContent
=
FindField
(
start
,
"
\r\n
"
,
NULL
);
break
;
}
}
}
const
string
&
Method
()
const
{
//rtsp方法
return
_strMethod
;
}
const
string
&
Url
()
const
{
//rtsp url
return
_strUrl
;
}
const
string
&
FullUrl
()
const
{
//rtsp url with args
return
_strFullUrl
;
}
const
string
&
Tail
()
const
{
//RTSP/1.0
return
_strTail
;
}
const
string
&
operator
[](
const
char
*
name
)
const
{
//rtsp field
auto
it
=
_mapHeaders
.
find
(
name
);
if
(
it
==
_mapHeaders
.
end
())
{
return
_strNull
;
}
return
it
->
second
;
}
const
string
&
Content
()
const
{
return
_strContent
;
}
void
Clear
()
{
_strMethod
.
clear
();
_strUrl
.
clear
();
_strFullUrl
.
clear
();
_params
.
clear
();
_strTail
.
clear
();
_strContent
.
clear
();
_mapHeaders
.
clear
();
_mapUrlArgs
.
clear
();
}
const
string
&
Params
()
const
{
return
_params
;
}
void
setUrl
(
const
string
&
url
)
{
this
->
_strUrl
=
url
;
}
void
setContent
(
const
string
&
content
)
{
this
->
_strContent
=
content
;
}
StrCaseMap
&
getValues
()
const
{
return
_mapHeaders
;
}
StrCaseMap
&
getUrlArgs
()
const
{
return
_mapUrlArgs
;
}
static
StrCaseMap
parseArgs
(
const
string
&
str
,
const
char
*
pair_delim
=
"&"
,
const
char
*
key_delim
=
"="
)
{
StrCaseMap
ret
;
auto
arg_vec
=
split
(
str
,
pair_delim
);
for
(
string
&
key_val
:
arg_vec
)
{
auto
key
=
FindField
(
key_val
.
data
(),
NULL
,
key_delim
);
auto
val
=
FindField
(
key_val
.
data
(),
key_delim
,
NULL
);
ret
.
emplace_force
(
key
,
val
);
}
return
ret
;
}
private
:
string
_strMethod
;
string
_strUrl
;
string
_strTail
;
string
_strContent
;
string
_strNull
;
string
_strFullUrl
;
string
_params
;
mutable
StrCaseMap
_mapHeaders
;
mutable
StrCaseMap
_mapUrlArgs
;
};
}
//namespace mediakit
#endif //ZLMEDIAKIT_PARSER_H
src/Http/HttpClient.cpp
查看文件 @
bf39cf3e
...
...
@@ -26,7 +26,7 @@
#include <cstdlib>
#include "HttpClient.h"
#include "
Rtsp/Rtsp
.h"
#include "
Common/config
.h"
namespace
mediakit
{
...
...
src/Http/HttpClient.h
查看文件 @
bf39cf3e
...
...
@@ -31,9 +31,10 @@
#include <string.h>
#include <functional>
#include <memory>
#include "Rtsp/Rtsp.h"
#include "Util/util.h"
#include "Util/mini.h"
#include "Network/TcpClient.h"
#include "Common/Parser.h"
#include "HttpRequestSplitter.h"
#include "HttpCookie.h"
#include "HttpChunkedSplitter.h"
...
...
src/Http/HttpCookieManager.h
查看文件 @
bf39cf3e
...
...
@@ -32,7 +32,7 @@
#include "Util/mini.h"
#include "Util/TimeTicker.h"
#include "Network/Socket.h"
#include "
Rtsp/Rtsp
.h"
#include "
Common/Parser
.h"
using
namespace
std
;
using
namespace
toolkit
;
...
...
src/Http/HttpSession.h
查看文件 @
bf39cf3e
...
...
@@ -28,7 +28,7 @@
#include <functional>
#include "Common/config.h"
#include "
Rtsp/Rtsp
.h"
#include "
Common/Parser
.h"
#include "Network/TcpSession.h"
#include "Network/TcpServer.h"
#include "Rtmp/RtmpMediaSource.h"
...
...
src/Player/PlayerBase.cpp
查看文件 @
bf39cf3e
...
...
@@ -26,7 +26,6 @@
#include <algorithm>
#include "PlayerBase.h"
#include "Rtsp/Rtsp.h"
#include "Rtsp/RtspPlayerImp.h"
#include "Rtmp/RtmpPlayerImp.h"
using
namespace
toolkit
;
...
...
src/Pusher/PusherBase.cpp
查看文件 @
bf39cf3e
...
...
@@ -26,7 +26,6 @@
#include <algorithm>
#include "PusherBase.h"
#include "Rtsp/Rtsp.h"
#include "Rtsp/RtspPusher.h"
#include "Rtmp/RtmpPusher.h"
...
...
src/Rtmp/RtmpPlayer.cpp
查看文件 @
bf39cf3e
...
...
@@ -25,7 +25,6 @@
*/
#include "RtmpPlayer.h"
#include "Rtsp/Rtsp.h"
#include "Rtmp/utils.h"
#include "Util/util.h"
#include "Util/onceToken.h"
...
...
src/Rtmp/RtmpProtocol.cpp
查看文件 @
bf39cf3e
...
...
@@ -24,7 +24,6 @@
* SOFTWARE.
*/
#include "RtmpProtocol.h"
#include "Rtsp/Rtsp.h"
#include "Rtmp/utils.h"
#include "Util/util.h"
#include "Util/onceToken.h"
...
...
src/Rtmp/RtmpPusher.cpp
查看文件 @
bf39cf3e
...
...
@@ -25,7 +25,6 @@
*/
#include "RtmpPusher.h"
#include "Rtmp/utils.h"
#include "Rtsp/Rtsp.h"
#include "Util/util.h"
#include "Util/onceToken.h"
#include "Thread/ThreadPool.h"
...
...
src/Rtsp/RtpBroadCaster.h
查看文件 @
bf39cf3e
...
...
@@ -33,7 +33,6 @@
#include <unordered_set>
#include <unordered_map>
#include "Common/config.h"
#include "Rtsp.h"
#include "RtspMediaSource.h"
#include "Util/mini.h"
#include "Network/Socket.h"
...
...
src/Rtsp/RtpReceiver.h
查看文件 @
bf39cf3e
...
...
@@ -31,7 +31,6 @@
#include <map>
#include <string>
#include <memory>
#include "Rtsp.h"
#include "RtspMuxer/RtpCodec.h"
#include "RtspMediaSource.h"
...
...
src/Rtsp/Rtsp.cpp
查看文件 @
bf39cf3e
...
...
@@ -26,34 +26,11 @@
#include <stdlib.h>
#include "Rtsp.h"
#include "Common/Parser.h"
namespace
mediakit
{
string
FindField
(
const
char
*
buf
,
const
char
*
start
,
const
char
*
end
,
int
bufSize
)
{
if
(
bufSize
<=
0
){
bufSize
=
strlen
(
buf
);
}
const
char
*
msg_start
=
buf
,
*
msg_end
=
buf
+
bufSize
;
int
len
=
0
;
if
(
start
!=
NULL
)
{
len
=
strlen
(
start
);
msg_start
=
strstr
(
buf
,
start
);
}
if
(
msg_start
==
NULL
)
{
return
""
;
}
msg_start
+=
len
;
if
(
end
!=
NULL
)
{
msg_end
=
strstr
(
msg_start
,
end
);
if
(
msg_end
==
NULL
)
{
return
""
;
}
}
return
string
(
msg_start
,
msg_end
);
}
void
SdpAttr
::
load
(
const
string
&
sdp
)
{
void
SdpParser
::
load
(
const
string
&
sdp
)
{
_track_map
.
clear
();
string
key
;
SdpTrack
::
Ptr
track
=
std
::
make_shared
<
SdpTrack
>
();
...
...
@@ -88,7 +65,7 @@ void SdpAttr::load(const string &sdp) {
case
'm'
:{
_track_map
[
key
]
=
track
;
track
=
std
::
make_shared
<
SdpTrack
>
();
key
=
FindField
(
opt_val
.
data
(),
nullptr
,
" "
);
;
key
=
FindField
(
opt_val
.
data
(),
nullptr
,
" "
);
track
->
_m
=
opt_val
;
}
break
;
...
...
@@ -161,11 +138,11 @@ void SdpAttr::load(const string &sdp) {
}
}
bool
Sdp
Att
r
::
available
()
const
{
bool
Sdp
Parse
r
::
available
()
const
{
return
getTrack
(
TrackAudio
)
||
getTrack
(
TrackVideo
);
}
SdpTrack
::
Ptr
Sdp
Att
r
::
getTrack
(
TrackType
type
)
const
{
SdpTrack
::
Ptr
Sdp
Parse
r
::
getTrack
(
TrackType
type
)
const
{
for
(
auto
&
pr
:
_track_map
){
if
(
pr
.
second
->
_type
==
type
){
return
pr
.
second
;
...
...
@@ -174,7 +151,7 @@ SdpTrack::Ptr SdpAttr::getTrack(TrackType type) const {
return
nullptr
;
}
vector
<
SdpTrack
::
Ptr
>
Sdp
Att
r
::
getAvailableTrack
()
const
{
vector
<
SdpTrack
::
Ptr
>
Sdp
Parse
r
::
getAvailableTrack
()
const
{
vector
<
SdpTrack
::
Ptr
>
ret
;
auto
video
=
getTrack
(
TrackVideo
);
if
(
video
){
...
...
src/Rtsp/Rtsp.h
查看文件 @
bf39cf3e
...
...
@@ -63,6 +63,15 @@ public:
TrackType
type
;
};
class
RtcpCounter
{
public
:
uint32_t
pktCnt
=
0
;
uint32_t
octCount
=
0
;
//网络字节序
uint32_t
timeStamp
=
0
;
uint32_t
lastTimeStamp
=
0
;
};
class
SdpTrack
{
public
:
typedef
std
::
shared_ptr
<
SdpTrack
>
Ptr
;
...
...
@@ -98,13 +107,13 @@ public:
uint32_t
_time_stamp
=
0
;
};
class
Sdp
Att
r
{
class
Sdp
Parse
r
{
public
:
typedef
std
::
shared_ptr
<
Sdp
Att
r
>
Ptr
;
typedef
std
::
shared_ptr
<
Sdp
Parse
r
>
Ptr
;
Sdp
Att
r
()
{}
Sdp
Att
r
(
const
string
&
sdp
)
{
load
(
sdp
);
}
~
Sdp
Att
r
()
{}
Sdp
Parse
r
()
{}
Sdp
Parse
r
(
const
string
&
sdp
)
{
load
(
sdp
);
}
~
Sdp
Parse
r
()
{}
void
load
(
const
string
&
sdp
);
bool
available
()
const
;
SdpTrack
::
Ptr
getTrack
(
TrackType
type
)
const
;
...
...
@@ -114,179 +123,6 @@ private:
};
class
RtcpCounter
{
public
:
uint32_t
pktCnt
=
0
;
uint32_t
octCount
=
0
;
//网络字节序
uint32_t
timeStamp
=
0
;
uint32_t
lastTimeStamp
=
0
;
};
string
FindField
(
const
char
*
buf
,
const
char
*
start
,
const
char
*
end
,
int
bufSize
=
0
);
struct
StrCaseCompare
{
bool
operator
()(
const
string
&
__x
,
const
string
&
__y
)
const
{
return
strcasecmp
(
__x
.
data
(),
__y
.
data
())
<
0
;
}
};
class
StrCaseMap
:
public
multimap
<
string
,
string
,
StrCaseCompare
>
{
public
:
typedef
multimap
<
string
,
string
,
StrCaseCompare
>
Super
;
StrCaseMap
()
=
default
;
~
StrCaseMap
()
=
default
;
string
&
operator
[](
const
string
&
key
){
auto
it
=
find
(
key
);
if
(
it
==
end
()){
it
=
Super
::
emplace
(
key
,
""
);
}
return
it
->
second
;
}
template
<
class
K
,
class
V
>
void
emplace
(
K
&&
k
,
V
&&
v
)
{
auto
it
=
find
(
k
);
if
(
it
!=
end
()){
return
;
}
Super
::
emplace
(
std
::
forward
<
K
>
(
k
),
std
::
forward
<
V
>
(
v
));
}
template
<
class
K
,
class
V
>
void
emplace_force
(
K
&&
k
,
V
&&
v
)
{
Super
::
emplace
(
std
::
forward
<
K
>
(
k
),
std
::
forward
<
V
>
(
v
));
}
};
class
Parser
{
public
:
Parser
()
{}
virtual
~
Parser
()
{}
void
Parse
(
const
char
*
buf
)
{
//解析
const
char
*
start
=
buf
;
Clear
();
while
(
true
)
{
auto
line
=
FindField
(
start
,
NULL
,
"
\r\n
"
);
if
(
line
.
size
()
==
0
)
{
break
;
}
if
(
start
==
buf
)
{
_strMethod
=
FindField
(
line
.
data
(),
NULL
,
" "
);
_strFullUrl
=
FindField
(
line
.
data
(),
" "
,
" "
);
auto
args_pos
=
_strFullUrl
.
find
(
'?'
);
if
(
args_pos
!=
string
::
npos
)
{
_strUrl
=
_strFullUrl
.
substr
(
0
,
args_pos
);
_params
=
_strFullUrl
.
substr
(
args_pos
+
1
);
_mapUrlArgs
=
parseArgs
(
_params
);
}
else
{
_strUrl
=
_strFullUrl
;
}
_strTail
=
FindField
(
line
.
data
(),
(
_strFullUrl
+
" "
).
data
(),
NULL
);
}
else
{
auto
field
=
FindField
(
line
.
data
(),
NULL
,
": "
);
auto
value
=
FindField
(
line
.
data
(),
": "
,
NULL
);
if
(
field
.
size
()
!=
0
)
{
_mapHeaders
.
emplace_force
(
field
,
value
);
}
}
start
=
start
+
line
.
size
()
+
2
;
if
(
strncmp
(
start
,
"
\r\n
"
,
2
)
==
0
)
{
//协议解析完毕
_strContent
=
FindField
(
start
,
"
\r\n
"
,
NULL
);
break
;
}
}
}
const
string
&
Method
()
const
{
//rtsp方法
return
_strMethod
;
}
const
string
&
Url
()
const
{
//rtsp url
return
_strUrl
;
}
const
string
&
FullUrl
()
const
{
//rtsp url with args
return
_strFullUrl
;
}
const
string
&
Tail
()
const
{
//RTSP/1.0
return
_strTail
;
}
const
string
&
operator
[](
const
char
*
name
)
const
{
//rtsp field
auto
it
=
_mapHeaders
.
find
(
name
);
if
(
it
==
_mapHeaders
.
end
())
{
return
_strNull
;
}
return
it
->
second
;
}
const
string
&
Content
()
const
{
return
_strContent
;
}
void
Clear
()
{
_strMethod
.
clear
();
_strUrl
.
clear
();
_strFullUrl
.
clear
();
_params
.
clear
();
_strTail
.
clear
();
_strContent
.
clear
();
_mapHeaders
.
clear
();
_mapUrlArgs
.
clear
();
}
const
string
&
Params
()
const
{
return
_params
;
}
void
setUrl
(
const
string
&
url
)
{
this
->
_strUrl
=
url
;
}
void
setContent
(
const
string
&
content
)
{
this
->
_strContent
=
content
;
}
StrCaseMap
&
getValues
()
const
{
return
_mapHeaders
;
}
StrCaseMap
&
getUrlArgs
()
const
{
return
_mapUrlArgs
;
}
static
StrCaseMap
parseArgs
(
const
string
&
str
,
const
char
*
pair_delim
=
"&"
,
const
char
*
key_delim
=
"="
)
{
StrCaseMap
ret
;
auto
arg_vec
=
split
(
str
,
pair_delim
);
for
(
string
&
key_val
:
arg_vec
)
{
auto
key
=
FindField
(
key_val
.
data
(),
NULL
,
key_delim
);
auto
val
=
FindField
(
key_val
.
data
(),
key_delim
,
NULL
);
ret
.
emplace_force
(
key
,
val
);
}
return
ret
;
}
private
:
string
_strMethod
;
string
_strUrl
;
string
_strTail
;
string
_strContent
;
string
_strNull
;
string
_strFullUrl
;
string
_params
;
mutable
StrCaseMap
_mapHeaders
;
mutable
StrCaseMap
_mapUrlArgs
;
};
/**
* rtsp sdp基类
*/
...
...
src/Rtsp/RtspMediaSource.h
查看文件 @
bf39cf3e
...
...
@@ -32,7 +32,6 @@
#include <memory>
#include <functional>
#include <unordered_map>
#include "Rtsp.h"
#include "Common/config.h"
#include "Common/MediaSource.h"
#include "RtspMuxer/RtpCodec.h"
...
...
@@ -79,14 +78,14 @@ public:
}
virtual
uint32_t
getSsrc
(
TrackType
trackType
)
{
auto
track
=
_sdp
Att
r
.
getTrack
(
trackType
);
auto
track
=
_sdp
Parse
r
.
getTrack
(
trackType
);
if
(
!
track
){
return
0
;
}
return
track
->
_ssrc
;
}
virtual
uint16_t
getSeqence
(
TrackType
trackType
)
{
auto
track
=
_sdp
Att
r
.
getTrack
(
trackType
);
auto
track
=
_sdp
Parse
r
.
getTrack
(
trackType
);
if
(
!
track
){
return
0
;
}
...
...
@@ -94,11 +93,11 @@ public:
}
uint32_t
getTimeStamp
(
TrackType
trackType
)
override
{
auto
track
=
_sdp
Att
r
.
getTrack
(
trackType
);
auto
track
=
_sdp
Parse
r
.
getTrack
(
trackType
);
if
(
track
)
{
return
track
->
_time_stamp
;
}
auto
tracks
=
_sdp
Att
r
.
getAvailableTrack
();
auto
tracks
=
_sdp
Parse
r
.
getAvailableTrack
();
switch
(
tracks
.
size
()){
case
0
:
return
0
;
case
1
:
return
tracks
[
0
]
->
_time_stamp
;
...
...
@@ -107,7 +106,7 @@ public:
}
virtual
void
setTimeStamp
(
uint32_t
uiStamp
)
{
auto
tracks
=
_sdp
Att
r
.
getAvailableTrack
();
auto
tracks
=
_sdp
Parse
r
.
getAvailableTrack
();
for
(
auto
&
track
:
tracks
)
{
track
->
_time_stamp
=
uiStamp
;
}
...
...
@@ -116,14 +115,14 @@ public:
virtual
void
onGetSDP
(
const
string
&
sdp
)
{
//派生类设置该媒体源媒体描述信息
_strSdp
=
sdp
;
_sdp
Att
r
.
load
(
sdp
);
_sdp
Parse
r
.
load
(
sdp
);
if
(
_pRing
){
regist
();
}
}
void
onWrite
(
const
RtpPacket
::
Ptr
&
rtppt
,
bool
keyPos
)
override
{
auto
track
=
_sdp
Att
r
.
getTrack
(
rtppt
->
type
);
auto
track
=
_sdp
Parse
r
.
getTrack
(
rtppt
->
type
);
if
(
track
){
track
->
_seq
=
rtppt
->
sequence
;
track
->
_time_stamp
=
rtppt
->
timeStamp
;
...
...
@@ -166,7 +165,7 @@ private:
}
}
protected
:
Sdp
Attr
_sdpAtt
r
;
Sdp
Parser
_sdpParse
r
;
string
_strSdp
;
//媒体描述信息
RingType
::
Ptr
_pRing
;
//rtp环形缓冲
int
_ringSize
;
...
...
src/Rtsp/RtspPlayer.cpp
查看文件 @
bf39cf3e
...
...
@@ -220,13 +220,13 @@ void RtspPlayer::handleResDESCRIBE(const Parser& parser) {
}
//解析sdp
_sdp
Att
r
.
load
(
parser
.
Content
());
_aTrackInfo
=
_sdp
Att
r
.
getAvailableTrack
();
_sdp
Parse
r
.
load
(
parser
.
Content
());
_aTrackInfo
=
_sdp
Parse
r
.
getAvailableTrack
();
if
(
_aTrackInfo
.
empty
())
{
throw
std
::
runtime_error
(
"无有效的Sdp Track"
);
}
if
(
!
onCheckSDP
(
parser
.
Content
(),
_sdp
Att
r
))
{
if
(
!
onCheckSDP
(
parser
.
Content
(),
_sdp
Parse
r
))
{
throw
std
::
runtime_error
(
"onCheckSDP faied"
);
}
...
...
src/Rtsp/RtspPlayer.h
查看文件 @
bf39cf3e
...
...
@@ -29,7 +29,6 @@
#include <string>
#include <memory>
#include "Rtsp.h"
#include "RtspSession.h"
#include "RtspMediaSource.h"
#include "Player/PlayerBase.h"
...
...
@@ -60,7 +59,7 @@ public:
float
getPacketLossRate
(
TrackType
type
)
const
override
;
protected
:
//派生类回调函数
virtual
bool
onCheckSDP
(
const
string
&
strSdp
,
const
Sdp
Attr
&
sdpAtt
r
)
=
0
;
virtual
bool
onCheckSDP
(
const
string
&
strSdp
,
const
Sdp
Parser
&
parse
r
)
=
0
;
virtual
void
onRecvRTP
(
const
RtpPacket
::
Ptr
&
pRtppt
,
const
SdpTrack
::
Ptr
&
track
)
=
0
;
uint32_t
getProgressMilliSecond
()
const
;
void
seekToMilliSecond
(
uint32_t
ms
);
...
...
@@ -123,7 +122,7 @@ private:
void
sendReceiverReport
(
bool
overTcp
,
int
iTrackIndex
);
private
:
string
_strUrl
;
Sdp
Attr
_sdpAtt
r
;
Sdp
Parser
_sdpParse
r
;
vector
<
SdpTrack
::
Ptr
>
_aTrackInfo
;
function
<
void
(
const
Parser
&
)
>
_onHandshake
;
Socket
::
Ptr
_apRtpSock
[
2
];
//RTP端口,trackid idx 为数组下标
...
...
src/Rtsp/RtspPlayerImp.h
查看文件 @
bf39cf3e
...
...
@@ -61,19 +61,19 @@ public:
};
private
:
//派生类回调函数
bool
onCheckSDP
(
const
string
&
sdp
,
const
Sdp
Attr
&
sdpAtt
r
)
override
{
bool
onCheckSDP
(
const
string
&
sdp
,
const
Sdp
Parser
&
parse
r
)
override
{
_pRtspMediaSrc
=
dynamic_pointer_cast
<
RtspMediaSource
>
(
_pMediaSrc
);
if
(
_pRtspMediaSrc
){
_pRtspMediaSrc
->
onGetSDP
(
sdp
);
}
_parser
.
reset
(
new
RtspDemuxer
(
sdpAtt
r
));
_parser
.
reset
(
new
RtspDemuxer
(
parse
r
));
return
true
;
}
void
onRecvRTP
(
const
RtpPacket
::
Ptr
&
rtp
pt
,
const
SdpTrack
::
Ptr
&
track
)
override
{
void
onRecvRTP
(
const
RtpPacket
::
Ptr
&
rtp
,
const
SdpTrack
::
Ptr
&
track
)
override
{
if
(
_pRtspMediaSrc
){
_pRtspMediaSrc
->
onWrite
(
rtp
pt
,
true
);
_pRtspMediaSrc
->
onWrite
(
rtp
,
true
);
}
_parser
->
inputRtp
(
rtp
pt
);
_parser
->
inputRtp
(
rtp
);
//由于我们重载isInited方法强制认为一旦获取sdp那么就初始化Track成功,
//所以我们不需要在后续检验是否初始化成功
...
...
src/Rtsp/RtspPusher.cpp
查看文件 @
bf39cf3e
...
...
@@ -169,8 +169,8 @@ void RtspPusher::sendAnnounce() {
throw
std
::
runtime_error
(
"the media source was released"
);
}
//解析sdp
_sdp
Att
r
.
load
(
src
->
getSdp
());
_aTrackInfo
=
_sdp
Att
r
.
getAvailableTrack
();
_sdp
Parse
r
.
load
(
src
->
getSdp
());
_aTrackInfo
=
_sdp
Parse
r
.
getAvailableTrack
();
if
(
_aTrackInfo
.
empty
())
{
throw
std
::
runtime_error
(
"无有效的Sdp Track"
);
...
...
src/Rtsp/RtspPusher.h
查看文件 @
bf39cf3e
...
...
@@ -7,7 +7,6 @@
#include <string>
#include <memory>
#include "Rtsp.h"
#include "RtspMediaSource.h"
#include "Util/util.h"
#include "Util/logger.h"
...
...
@@ -81,7 +80,7 @@ private:
Event
_onPublished
;
string
_strUrl
;
Sdp
Attr
_sdpAtt
r
;
Sdp
Parser
_sdpParse
r
;
vector
<
SdpTrack
::
Ptr
>
_aTrackInfo
;
string
_strSession
;
unsigned
int
_uiCseq
=
1
;
...
...
src/Rtsp/RtspSession.cpp
查看文件 @
bf39cf3e
...
...
@@ -244,7 +244,7 @@ void RtspSession::handleReq_ANNOUNCE(const Parser &parser) {
_strSession
=
makeRandStr
(
12
);
_strSdp
=
parser
.
Content
();
_aTrackInfo
=
Sdp
Att
r
(
_strSdp
).
getAvailableTrack
();
_aTrackInfo
=
Sdp
Parse
r
(
_strSdp
).
getAvailableTrack
();
_pushSrc
=
std
::
make_shared
<
RtspToRtmpMediaSource
>
(
_mediaInfo
.
_vhost
,
_mediaInfo
.
_app
,
_mediaInfo
.
_streamid
);
_pushSrc
->
setListener
(
dynamic_pointer_cast
<
MediaSourceEvent
>
(
shared_from_this
()));
...
...
@@ -363,8 +363,8 @@ void RtspSession::onAuthSuccess() {
}
//找到了响应的rtsp流
strongSelf
->
_strSdp
=
rtsp_src
->
getSdp
();
Sdp
Attr
sdpAtt
r
(
strongSelf
->
_strSdp
);
strongSelf
->
_aTrackInfo
=
sdp
Att
r
.
getAvailableTrack
();
Sdp
Parser
sdpParse
r
(
strongSelf
->
_strSdp
);
strongSelf
->
_aTrackInfo
=
sdp
Parse
r
.
getAvailableTrack
();
if
(
strongSelf
->
_aTrackInfo
.
empty
())
{
//该流无效
strongSelf
->
send_StreamNotFound
();
...
...
src/Rtsp/RtspSession.h
查看文件 @
bf39cf3e
...
...
@@ -36,7 +36,6 @@
#include "Common/config.h"
#include "Network/TcpSession.h"
#include "Player/PlayerBase.h"
#include "Rtsp.h"
#include "RtpBroadCaster.h"
#include "RtspMediaSource.h"
#include "RtspSplitter.h"
...
...
src/Rtsp/RtspSplitter.h
查看文件 @
bf39cf3e
...
...
@@ -27,7 +27,7 @@
#ifndef ZLMEDIAKIT_RTSPSPLITTER_H
#define ZLMEDIAKIT_RTSPSPLITTER_H
#include "
Rtsp
.h"
#include "
Common/Parser
.h"
#include "Http/HttpRequestSplitter.h"
namespace
mediakit
{
...
...
src/RtspMuxer/RtpCodec.h
查看文件 @
bf39cf3e
...
...
@@ -29,7 +29,6 @@
#include <memory>
#include "Util/RingBuffer.h"
#include "Rtsp/Rtsp.h"
#include "Player/PlayerBase.h"
using
namespace
toolkit
;
...
...
src/RtspMuxer/RtspDemuxer.cpp
查看文件 @
bf39cf3e
...
...
@@ -35,14 +35,14 @@ using namespace std;
namespace
mediakit
{
RtspDemuxer
::
RtspDemuxer
(
const
string
&
sdp
)
{
loadSdp
(
Sdp
Att
r
(
sdp
));
loadSdp
(
Sdp
Parse
r
(
sdp
));
}
RtspDemuxer
::
RtspDemuxer
(
const
Sdp
Att
r
&
attr
)
{
RtspDemuxer
::
RtspDemuxer
(
const
Sdp
Parse
r
&
attr
)
{
loadSdp
(
attr
);
}
void
RtspDemuxer
::
loadSdp
(
const
Sdp
Att
r
&
attr
)
{
void
RtspDemuxer
::
loadSdp
(
const
Sdp
Parse
r
&
attr
)
{
auto
tracks
=
attr
.
getAvailableTrack
();
for
(
auto
&
track
:
tracks
){
switch
(
track
->
_type
)
{
...
...
src/RtspMuxer/RtspDemuxer.h
查看文件 @
bf39cf3e
...
...
@@ -28,7 +28,6 @@
#define SRC_RTP_RTSPDEMUXER_H_
#include <unordered_map>
#include "Rtsp/Rtsp.h"
#include "Player/PlayerBase.h"
#include "Util/TimeTicker.h"
#include "RtspMuxer/RtpCodec.h"
...
...
@@ -42,7 +41,7 @@ class RtspDemuxer : public Demuxer{
public
:
typedef
std
::
shared_ptr
<
RtspDemuxer
>
Ptr
;
RtspDemuxer
(
const
string
&
sdp
);
RtspDemuxer
(
const
Sdp
Attr
&
att
r
);
RtspDemuxer
(
const
Sdp
Parser
&
parse
r
);
virtual
~
RtspDemuxer
(){};
/**
...
...
@@ -54,7 +53,7 @@ public:
private
:
void
makeAudioTrack
(
const
SdpTrack
::
Ptr
&
audio
);
void
makeVideoTrack
(
const
SdpTrack
::
Ptr
&
video
);
void
loadSdp
(
const
Sdp
Attr
&
att
r
);
void
loadSdp
(
const
Sdp
Parser
&
parse
r
);
private
:
RtpCodec
::
Ptr
_audioRtpDecoder
;
RtpCodec
::
Ptr
_videoRtpDecoder
;
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论