修复rtmp兼容性bug
This commit is contained in:
parent
1f52c727ca
commit
e4904623a7
|
|
@ -128,6 +128,7 @@ public:
|
|||
|
||||
class RtmpPacket : public Buffer{
|
||||
public:
|
||||
friend class RtmpProtocol;
|
||||
using Ptr = std::shared_ptr<RtmpPacket>;
|
||||
bool is_abs_stamp;
|
||||
uint8_t type_id;
|
||||
|
|
@ -214,6 +215,16 @@ private:
|
|||
clear();
|
||||
}
|
||||
|
||||
RtmpPacket &operator=(const RtmpPacket &that) {
|
||||
is_abs_stamp = that.is_abs_stamp;
|
||||
stream_index = that.stream_index;
|
||||
body_size = that.body_size;
|
||||
type_id = that.type_id;
|
||||
ts_field = that.ts_field;
|
||||
time_stamp = that.time_stamp;
|
||||
return *this;
|
||||
}
|
||||
|
||||
private:
|
||||
//对象个数统计
|
||||
ObjectStatistic<RtmpPacket> _statistic;
|
||||
|
|
|
|||
|
|
@ -565,13 +565,20 @@ const char* RtmpProtocol::handle_rtmp(const char *data, size_t len) {
|
|||
//need more data
|
||||
return ptr;
|
||||
}
|
||||
|
||||
RtmpHeader &header = *((RtmpHeader *) (ptr + offset));
|
||||
auto &packet_ptr = _map_chunk_data[_now_chunk_id];
|
||||
if (!packet_ptr) {
|
||||
packet_ptr = RtmpPacket::create();
|
||||
auto &pr = _map_chunk_data[_now_chunk_id];
|
||||
auto &now_packet = pr.first;
|
||||
auto &last_packet = pr.second;
|
||||
if (!now_packet) {
|
||||
now_packet = RtmpPacket::create();
|
||||
if (last_packet) {
|
||||
//恢复chunk上下文
|
||||
*now_packet = *last_packet;
|
||||
}
|
||||
//绝对时间戳标记复位
|
||||
now_packet->is_abs_stamp = false;
|
||||
}
|
||||
auto &chunk_data = *packet_ptr;
|
||||
auto &chunk_data = *now_packet;
|
||||
chunk_data.chunk_id = _now_chunk_id;
|
||||
switch (header_len) {
|
||||
case 12:
|
||||
|
|
@ -598,7 +605,7 @@ const char* RtmpProtocol::handle_rtmp(const char *data, size_t len) {
|
|||
throw std::runtime_error("非法的bodySize");
|
||||
}
|
||||
|
||||
auto more = min(_chunk_size_in, (size_t)(chunk_data.body_size - chunk_data.buffer.size()));
|
||||
auto more = min(_chunk_size_in, (size_t) (chunk_data.body_size - chunk_data.buffer.size()));
|
||||
if (len < header_len + offset + more) {
|
||||
//need more data
|
||||
return ptr;
|
||||
|
|
@ -612,10 +619,12 @@ const char* RtmpProtocol::handle_rtmp(const char *data, size_t len) {
|
|||
//frame is ready
|
||||
_now_stream_index = chunk_data.stream_index;
|
||||
chunk_data.time_stamp = time_stamp + (chunk_data.is_abs_stamp ? 0 : chunk_data.time_stamp);
|
||||
//保存chunk上下文
|
||||
last_packet = now_packet;
|
||||
if (chunk_data.body_size) {
|
||||
handle_chunk(std::move(packet_ptr));
|
||||
handle_chunk(std::move(now_packet));
|
||||
} else {
|
||||
packet_ptr = nullptr;
|
||||
now_packet = nullptr;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -106,7 +106,7 @@ private:
|
|||
//////////Rtmp parser//////////
|
||||
function<const char * (const char *data, size_t len)> _next_step_func;
|
||||
////////////Chunk////////////
|
||||
unordered_map<int, RtmpPacket::Ptr> _map_chunk_data;
|
||||
unordered_map<int, std::pair<RtmpPacket::Ptr/*now*/, RtmpPacket::Ptr/*last*/> > _map_chunk_data;
|
||||
};
|
||||
|
||||
} /* namespace mediakit */
|
||||
|
|
|
|||
Loading…
Reference in New Issue