mirror of
https://github.com/ossrs/srs.git
synced 2025-02-12 11:21:52 +00:00
fix bug of extended-timestamp, support librtmp/ffmpeg publish
This commit is contained in:
parent
0ed8807727
commit
3c8e1f8ff7
3 changed files with 29 additions and 3 deletions
|
@ -25,6 +25,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|||
|
||||
#include <srs_core_error.hpp>
|
||||
#include <srs_core_socket.hpp>
|
||||
#include <srs_core_log.hpp>
|
||||
|
||||
#define SOCKET_READ_SIZE 4096
|
||||
|
||||
|
@ -62,7 +63,11 @@ int SrsBuffer::ensure_buffer_bytes(SrsSocket* skt, int required_size)
|
|||
{
|
||||
int ret = ERROR_SUCCESS;
|
||||
|
||||
srs_assert(required_size >= 0);
|
||||
if (required_size < 0) {
|
||||
ret = ERROR_SYSTEM_SIZE_NEGATIVE;
|
||||
srs_error("size is negative. size=%d, ret=%d", required_size, ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
while (size() < required_size) {
|
||||
char buffer[SOCKET_READ_SIZE];
|
||||
|
|
|
@ -64,11 +64,13 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|||
#define ERROR_RTMP_CHUNK_SIZE 310
|
||||
#define ERROR_RTMP_TRY_SIMPLE_HS 311
|
||||
#define ERROR_RTMP_CH_SCHEMA 312
|
||||
#define ERROR_RTMP_PACKET_SIZE 313
|
||||
|
||||
#define ERROR_SYSTEM_STREAM_INIT 400
|
||||
#define ERROR_SYSTEM_PACKET_INVALID 401
|
||||
#define ERROR_SYSTEM_CLIENT_INVALID 402
|
||||
#define ERROR_SYSTEM_ASSERT_FAILED 403
|
||||
#define ERROR_SYSTEM_SIZE_NEGATIVE 404
|
||||
|
||||
// see librtmp.
|
||||
// failed when open ssl create the dh
|
||||
|
|
|
@ -827,6 +827,15 @@ int SrsProtocol::read_message_header(SrsChunkStream* chunk, char fmt, int bh_siz
|
|||
pp[0] = *p++;
|
||||
pp[3] = 0;
|
||||
|
||||
// if msg exists in cache, the size must not changed.
|
||||
if (chunk->msg->size > 0 && chunk->msg->size != chunk->header.payload_length) {
|
||||
ret = ERROR_RTMP_PACKET_SIZE;
|
||||
srs_error("msg exists in chunk cache, "
|
||||
"size=%d cannot change to %d, ret=%d",
|
||||
chunk->msg->size, chunk->header.payload_length, ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
chunk->header.message_type = *p++;
|
||||
|
||||
if (fmt == 0) {
|
||||
|
@ -867,11 +876,21 @@ int SrsProtocol::read_message_header(SrsChunkStream* chunk, char fmt, int bh_siz
|
|||
return ret;
|
||||
}
|
||||
|
||||
char* pp = (char*)&chunk->header.timestamp;
|
||||
// ffmpeg/librtmp may donot send this filed, need to detect the value.
|
||||
// @see also: http://blog.csdn.net/win_lin/article/details/13363699
|
||||
int32_t timestamp = 0x00;
|
||||
char* pp = (char*)×tamp;
|
||||
pp[3] = *p++;
|
||||
pp[2] = *p++;
|
||||
pp[1] = *p++;
|
||||
pp[0] = *p++;
|
||||
|
||||
if (chunk->header.timestamp > RTMP_EXTENDED_TIMESTAMP && chunk->header.timestamp != timestamp) {
|
||||
mh_size -= 4;
|
||||
srs_verbose("ignore the 4bytes extended timestamp. mh_size=%d", mh_size);
|
||||
} else {
|
||||
chunk->header.timestamp = timestamp;
|
||||
}
|
||||
srs_verbose("header read ext_time completed. time=%d", chunk->header.timestamp);
|
||||
}
|
||||
|
||||
|
@ -897,7 +916,7 @@ int SrsProtocol::read_message_payload(SrsChunkStream* chunk, int bh_size, int mh
|
|||
int ret = ERROR_SUCCESS;
|
||||
|
||||
// empty message
|
||||
if (chunk->header.payload_length == 0) {
|
||||
if (chunk->header.payload_length <= 0) {
|
||||
// need erase the header in buffer.
|
||||
buffer->erase(bh_size + mh_size);
|
||||
|
||||
|
|
Loading…
Reference in a new issue