Skip to content
项目
群组
代码片段
帮助
正在加载...
登录
切换导航
M
mediasoup
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
聂卓夫
mediasoup
Commits
32bdc24e
提交
32bdc24e
authored
12月 02, 2016
作者:
Iñaki Baz Castillo
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Initial work in RtpStream
上级
5a157b6d
隐藏空白字符变更
内嵌
并排
正在显示
7 个修改的文件
包含
278 行增加
和
39 行删除
+278
-39
RtpBuffer.h
worker/include/RTC/RtpBuffer.h
+10
-12
RtpReceiver.h
worker/include/RTC/RtpReceiver.h
+2
-2
RtpStream.h
worker/include/RTC/RtpStream.h
+32
-0
mediasoup-worker.gyp
worker/mediasoup-worker.gyp
+2
-0
RtpBuffer.cpp
worker/src/RTC/RtpBuffer.cpp
+92
-15
RtpReceiver.cpp
worker/src/RTC/RtpReceiver.cpp
+18
-10
RtpStream.cpp
worker/src/RTC/RtpStream.cpp
+122
-0
没有找到文件。
worker/include/RTC/RtpBuffer.h
浏览文件 @
32bdc24e
...
...
@@ -4,30 +4,28 @@
#include "common.h"
#include "RTC/RtpPacket.h"
#include <vector>
#define MS_RTP_PACKET_MAX_SIZE 65536
#include <list>
namespace
RTC
{
class
RtpBuffer
{
p
ublic
:
struct
Item
p
rivate
:
struct
Storage
Item
{
uint8_t
raw
[
MS_RTP_PACKET_MAX_SIZE
];
RTC
::
RtpPacket
*
packet
=
nullptr
;
uint8_t
store
[
65536
];
};
public
:
RtpBuffer
(
size_t
capability
);
virtual
~
RtpBuffer
();
RtpBuffer
(
size_t
size
);
~
RtpBuffer
();
void
Add
(
RTC
::
RtpPacket
*
packet
);
bool
Add
(
RTC
::
RtpPacket
*
packet
);
private
:
std
::
vector
<
Item
>
items
;
size_t
pos
=
0
;
bool
full
=
false
;
std
::
vector
<
StorageItem
>
storage
;
typedef
std
::
list
<
RTC
::
RtpPacket
*>
Packets
;
Packets
packets
;
};
}
...
...
worker/include/RTC/RtpReceiver.h
浏览文件 @
32bdc24e
...
...
@@ -4,7 +4,7 @@
#include "common.h"
#include "RTC/RtpDictionaries.h"
#include "RTC/RtpPacket.h"
#include "RTC/Rtp
Buffer
.h"
#include "RTC/Rtp
Stream
.h"
#include "RTC/RTCP/ReceiverReport.h"
#include "RTC/RTCP/Feedback.h"
#include "Channel/Request.h"
...
...
@@ -66,7 +66,7 @@ namespace RTC
RTC
::
Transport
*
transport
=
nullptr
;
// Allocated by this.
RTC
::
RtpParameters
*
rtpParameters
=
nullptr
;
RTC
::
Rtp
Buffer
*
rtpBuffer
=
nullptr
;
RTC
::
Rtp
Stream
*
rtpStream
=
nullptr
;
// Others.
bool
rtpRawEventEnabled
=
false
;
bool
rtpObjectEventEnabled
=
false
;
...
...
worker/include/RTC/RtpStream.h
0 → 100644
浏览文件 @
32bdc24e
#ifndef MS_RTC_RTP_STREAM_H
#define MS_RTC_RTP_STREAM_H
#include "common.h"
#include "RTC/RtpPacket.h"
#include <vector>
#include <list>
namespace
RTC
{
class
RtpStream
{
private
:
struct
StorageItem
{
uint8_t
store
[
65536
];
};
public
:
RtpStream
(
size_t
bufferSize
);
~
RtpStream
();
bool
AddPacket
(
RTC
::
RtpPacket
*
packet
);
private
:
std
::
vector
<
StorageItem
>
storage
;
typedef
std
::
list
<
RTC
::
RtpPacket
*>
Packets
;
Packets
packets
;
};
}
#endif
worker/mediasoup-worker.gyp
浏览文件 @
32bdc24e
...
...
@@ -36,6 +36,7 @@
'src/RTC/RtpPacket.cpp',
'src/RTC/RtpReceiver.cpp',
'src/RTC/RtpSender.cpp',
'src/RTC/RtpStream.cpp',
'src/RTC/SrtpSession.cpp',
'src/RTC/StunMessage.cpp',
'src/RTC/TcpConnection.cpp',
...
...
@@ -113,6 +114,7 @@
'include/RTC/RtpPacket.h',
'include/RTC/RtpReceiver.h',
'include/RTC/RtpSender.h',
'include/RTC/RtpStream.h',
'include/RTC/SrtpSession.h',
'include/RTC/StunMessage.h',
'include/RTC/TcpConnection.h',
...
...
worker/src/RTC/RtpBuffer.cpp
浏览文件 @
32bdc24e
// TODO: https://tools.ietf.org/html/rfc3550#appendix-A.1
#define MS_CLASS "RTC::RtpBuffer"
#include "RTC/RtpBuffer.h"
...
...
@@ -7,8 +9,8 @@ namespace RTC
{
/* Instance methods. */
RtpBuffer
::
RtpBuffer
(
size_t
capability
)
:
items
(
capability
)
RtpBuffer
::
RtpBuffer
(
size_t
size
)
:
storage
(
size
)
{
MS_TRACE
();
}
...
...
@@ -18,28 +20,103 @@ namespace RTC
MS_TRACE
();
// Delete cloned packets.
for
(
auto
&
item
:
this
->
item
s
)
for
(
auto
&
packet
:
this
->
packet
s
)
{
if
(
item
.
packet
)
delete
item
.
packet
;
delete
packet
;
}
}
void
RtpBuffer
::
Add
(
RTC
::
RtpPacket
*
packet
)
bool
RtpBuffer
::
Add
(
RTC
::
RtpPacket
*
packet
)
{
MS_TRACE
();
Item
*
item
=
std
::
addressof
(
this
->
items
[
this
->
pos
]);
MS_WARN
(
"BEGIN | seq_number: %"
PRIu16
,
packet
->
GetSequenceNumber
());
// If empty do it easy.
if
(
this
->
packets
.
size
()
==
0
)
{
MS_WARN
(
" empty packet list"
);
auto
store
=
this
->
storage
[
0
].
store
;
auto
cloned_packet
=
packet
->
Clone
(
store
);
this
->
packets
.
push_back
(
cloned_packet
);
MS_WARN
(
"END | seq_number: %"
PRIu16
,
packet
->
GetSequenceNumber
());
return
true
;
}
// Otherwise, do the stuff.
Packets
::
iterator
new_it
;
uint8_t
*
store
=
nullptr
;
auto
it_r
=
this
->
packets
.
rbegin
();
for
(;
it_r
!=
this
->
packets
.
rend
();
it_r
++
)
{
auto
current_packet
=
*
it_r
;
if
(
packet
->
GetSequenceNumber
()
>
current_packet
->
GetSequenceNumber
())
{
// Get a forward iterator pointing to the same element.
auto
it
=
it_r
.
base
();
new_it
=
this
->
packets
.
insert
(
it
,
nullptr
);
// Exit the loop.
break
;
}
}
// If the packet was older than anything in the storate, just ignore it.
if
(
it_r
==
this
->
packets
.
rend
())
{
// TODO: Wrong, this will drop all the received packets once sequence_number
// reaches 65535
MS_WARN
(
" packet is older than anything in the storage, ignoring it"
);
MS_WARN
(
"END | seq_number: %"
PRIu16
,
packet
->
GetSequenceNumber
());
return
false
;
}
MS_WARN
(
" packets.size:%zu, storage.size:%zu"
,
this
->
packets
.
size
(),
this
->
storage
.
size
());
// If the storage is not full use the next free area.
if
(
this
->
packets
.
size
()
-
1
<
this
->
storage
.
size
())
{
MS_WARN
(
" storage not full"
);
// Store points to the next free mem area.
store
=
this
->
storage
[
this
->
packets
.
size
()
-
1
].
store
;
}
// Otherwise remove the first packet list entry and replace its storage area.
else
{
auto
first_packet
=
*
(
this
->
packets
.
begin
());
MS_WARN
(
" storage full, deleting first list packet with seq_number: %"
PRIu16
,
first_packet
->
GetSequenceNumber
());
// Store points to the store used by the first packet.
store
=
(
uint8_t
*
)
first_packet
->
GetRaw
();
// Free the first packet.
delete
first_packet
;
// Remove the first element in the list.
this
->
packets
.
pop_front
();
}
// Update the new list entry so it points to the cloned packed.
*
new_it
=
packet
->
Clone
(
store
);
// Delete previous RTP packet (if any).
if
(
item
->
packet
)
delete
item
->
packet
;
MS_WARN
(
"END | seq_number: %"
PRIu16
,
packet
->
GetSequenceNumber
());
// Clone the given RTP packet and store it.
item
->
packet
=
packet
->
Clone
(
item
->
raw
);
MS_WARN
(
"<DUMP>"
);
for
(
auto
&
packet
:
this
->
packets
)
{
MS_WARN
(
" - seq_number: %"
PRIu16
,
packet
->
GetSequenceNumber
());
}
MS_WARN
(
"</DUMP>
\n
"
);
this
->
pos
=
(
this
->
pos
+
1
)
%
this
->
items
.
size
();
if
(
!
this
->
full
&&
this
->
pos
==
0
)
this
->
full
=
true
;
return
true
;
}
}
worker/src/RTC/RtpReceiver.cpp
浏览文件 @
32bdc24e
...
...
@@ -6,8 +6,6 @@
#include "MediaSoupError.h"
#include "Logger.h"
#define RTP_BUFFER_SIZE 100
namespace
RTC
{
/* Instance methods. */
...
...
@@ -20,8 +18,8 @@ namespace RTC
{
MS_TRACE
();
// Create the Rtp
Buffer
instance.
this
->
rtp
Buffer
=
new
RTC
::
RtpBuffer
(
RTP_BUFFER_SIZE
);
// Create the Rtp
Stream
instance.
this
->
rtp
Stream
=
new
RTC
::
RtpStream
(
50
);
}
RtpReceiver
::~
RtpReceiver
()
...
...
@@ -40,8 +38,8 @@ namespace RTC
if
(
this
->
rtpParameters
)
delete
this
->
rtpParameters
;
if
(
this
->
rtp
Buffer
)
delete
this
->
rtp
Buffer
;
if
(
this
->
rtp
Stream
)
delete
this
->
rtp
Stream
;
// Notify.
event_data
[
k_class
]
=
"RtpReceiver"
;
...
...
@@ -217,6 +215,20 @@ namespace RTC
// TODO: Check if stopped, etc (not yet done)
// Store in the buffer
// TODO: Must check what kind of packet we are storing, right?
// TODO: RtpStream.AddPacket() should return true if the packet is valid and
// false if it must be ignored.
// TODO: testing for just audio (remove)
if
(
this
->
kind
==
RTC
::
Media
::
Kind
::
AUDIO
)
{
// TODO: Enable when properly implemented.
// if (!this->rtpStream->AddPacket(packet))
// return;
this
->
rtpStream
->
AddPacket
(
packet
);
}
// Notify the listener.
this
->
listener
->
onRtpPacket
(
this
,
packet
);
...
...
@@ -248,10 +260,6 @@ namespace RTC
this
->
notifier
->
EmitWithBinary
(
this
->
rtpReceiverId
,
"rtpobject"
,
event_data
,
packet
->
GetPayload
(),
packet
->
GetPayloadLength
());
}
// Store in the buffer
// TODO: Must check what kind of packet we are storing, right?
this
->
rtpBuffer
->
Add
(
packet
);
}
void
RtpReceiver
::
FillRtpParameters
()
...
...
worker/src/RTC/RtpStream.cpp
0 → 100644
浏览文件 @
32bdc24e
// TODO: https://tools.ietf.org/html/rfc3550#appendix-A.1
#define MS_CLASS "RTC::RtpStream"
#include "RTC/RtpStream.h"
#include "Logger.h"
namespace
RTC
{
/* Instance methods. */
RtpStream
::
RtpStream
(
size_t
bufferSize
)
:
storage
(
bufferSize
)
{
MS_TRACE
();
}
RtpStream
::~
RtpStream
()
{
MS_TRACE
();
// Delete cloned packets.
for
(
auto
&
packet
:
this
->
packets
)
{
delete
packet
;
}
}
bool
RtpStream
::
AddPacket
(
RTC
::
RtpPacket
*
packet
)
{
MS_TRACE
();
MS_WARN
(
"BEGIN | seq_number: %"
PRIu16
,
packet
->
GetSequenceNumber
());
// If empty do it easy.
if
(
this
->
packets
.
size
()
==
0
)
{
MS_WARN
(
" empty packet list"
);
auto
store
=
this
->
storage
[
0
].
store
;
auto
cloned_packet
=
packet
->
Clone
(
store
);
this
->
packets
.
push_back
(
cloned_packet
);
MS_WARN
(
"END | seq_number: %"
PRIu16
,
packet
->
GetSequenceNumber
());
return
true
;
}
// Otherwise, do the stuff.
Packets
::
iterator
new_it
;
uint8_t
*
store
=
nullptr
;
auto
it_r
=
this
->
packets
.
rbegin
();
for
(;
it_r
!=
this
->
packets
.
rend
();
it_r
++
)
{
auto
current_packet
=
*
it_r
;
if
(
packet
->
GetSequenceNumber
()
>
current_packet
->
GetSequenceNumber
())
{
// Get a forward iterator pointing to the same element.
auto
it
=
it_r
.
base
();
new_it
=
this
->
packets
.
insert
(
it
,
nullptr
);
// Exit the loop.
break
;
}
}
// If the packet was older than anything in the storate, just ignore it.
if
(
it_r
==
this
->
packets
.
rend
())
{
// TODO: Wrong, this will drop all the received packets once sequence_number
// reaches 65535
MS_WARN
(
" packet is older than anything in the storage, ignoring it"
);
MS_WARN
(
"END | seq_number: %"
PRIu16
,
packet
->
GetSequenceNumber
());
return
false
;
}
MS_WARN
(
" packets.size:%zu, storage.size:%zu"
,
this
->
packets
.
size
(),
this
->
storage
.
size
());
// If the storage is not full use the next free area.
if
(
this
->
packets
.
size
()
-
1
<
this
->
storage
.
size
())
{
MS_WARN
(
" storage not full"
);
// Store points to the next free mem area.
store
=
this
->
storage
[
this
->
packets
.
size
()
-
1
].
store
;
}
// Otherwise remove the first packet list entry and replace its storage area.
else
{
auto
first_packet
=
*
(
this
->
packets
.
begin
());
MS_WARN
(
" storage full, deleting first list packet with seq_number: %"
PRIu16
,
first_packet
->
GetSequenceNumber
());
// Store points to the store used by the first packet.
store
=
(
uint8_t
*
)
first_packet
->
GetRaw
();
// Free the first packet.
delete
first_packet
;
// Remove the first element in the list.
this
->
packets
.
pop_front
();
}
// Update the new list entry so it points to the cloned packed.
*
new_it
=
packet
->
Clone
(
store
);
MS_WARN
(
"END | seq_number: %"
PRIu16
,
packet
->
GetSequenceNumber
());
MS_WARN
(
"<DUMP>"
);
for
(
auto
&
packet
:
this
->
packets
)
{
MS_WARN
(
" - seq_number: %"
PRIu16
,
packet
->
GetSequenceNumber
());
}
MS_WARN
(
"</DUMP>
\n
"
);
return
true
;
}
}
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论