Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
PHZ76 committed May 21, 2020
1 parent 6e035d9 commit e74c3cd
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 31 deletions.
8 changes: 4 additions & 4 deletions src/xop/RtmpChunk.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ int RtmpChunk::CreateMessageHeader(uint8_t fmt, RtmpMessage& rtmp_msg, char* buf

int RtmpChunk::CreateChunk(uint32_t csid, RtmpMessage& rtmp_msg, char* buf, uint32_t buf_size)
{
uint32_t buf_offset = 0, payloadOffset = 0;
uint32_t buf_offset = 0, payload_offset = 0;
uint32_t capacity = rtmp_msg.length + rtmp_msg.length / out_chunk_size_ * 5;
if (buf_size < capacity) {
return -1;
Expand All @@ -244,8 +244,8 @@ int RtmpChunk::CreateChunk(uint32_t csid, RtmpMessage& rtmp_msg, char* buf, uint
while (rtmp_msg.length > 0)
{
if (rtmp_msg.length > out_chunk_size_) {
memcpy(buf + buf_offset, rtmp_msg.payload.get() + payloadOffset, out_chunk_size_);
payloadOffset += out_chunk_size_;
memcpy(buf + buf_offset, rtmp_msg.payload.get() + payload_offset, out_chunk_size_);
payload_offset += out_chunk_size_;
buf_offset += out_chunk_size_;
rtmp_msg.length -= out_chunk_size_;

Expand All @@ -256,7 +256,7 @@ int RtmpChunk::CreateChunk(uint32_t csid, RtmpMessage& rtmp_msg, char* buf, uint
}
}
else {
memcpy(buf + buf_offset, rtmp_msg.payload.get() + payloadOffset, rtmp_msg.length);
memcpy(buf + buf_offset, rtmp_msg.payload.get() + payload_offset, rtmp_msg.length);
buf_offset += rtmp_msg.length;
rtmp_msg.length = 0;
break;
Expand Down
17 changes: 10 additions & 7 deletions src/xop/RtmpConnection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,18 +107,21 @@ void RtmpConnection::OnClose()
bool RtmpConnection::HandleChunk(BufferReader& buffer)
{
int ret = -1;
RtmpMessage rtmp_msg;


do
{
RtmpMessage rtmp_msg;
ret = rtmp_chunk_->Parse(buffer, rtmp_msg);
if (ret > 0) {
if (ret >= 0) {
if (rtmp_msg.IsCompleted()) {
ret = HandleMessage(rtmp_msg);
if (!HandleMessage(rtmp_msg)) {
return false;
}
}

if (ret == 0) {
break;
}
}
else if (ret == 0) {
break;
}
else if (ret < 0) {
return false;
Expand Down
25 changes: 5 additions & 20 deletions src/xop/RtmpMessage.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,35 +35,20 @@ struct RtmpMessage
index = 0;
timestamp = 0;
extend_timestamp = 0;
if (length > 0) {
payload.reset(new char[length]);
}
}

bool IsCompleted() const
{
if (index == length && payload != nullptr) {
if (index == length && length > 0 &&
payload != nullptr) {
return true;
}

return false;
}

RtmpMessage &operator=(const RtmpMessage& rtmp_msg)
{
if (this != &rtmp_msg) {
this->timestamp = rtmp_msg.timestamp;
this->length = rtmp_msg.length;
this->type_id = rtmp_msg.type_id;
this->stream_id = rtmp_msg.stream_id;
this->extend_timestamp = rtmp_msg.extend_timestamp;
this->_timestamp = rtmp_msg._timestamp;
this->codecId = rtmp_msg.codecId;
this->csid = rtmp_msg.csid;
this->index = rtmp_msg.index;
this->payload.reset(new char[this->length]);
memcpy(this->payload.get(), rtmp_msg.payload.get(), this->length);
}

return *this;
}
};

}
Expand Down

0 comments on commit e74c3cd

Please sign in to comment.