正在显示
6 个修改的文件
包含
41 行增加
和
51 行删除
| @@ -212,6 +212,7 @@ usr sys idl wai hiq siq| read writ| recv send| in out | int csw | @@ -212,6 +212,7 @@ usr sys idl wai hiq siq| read writ| recv send| in out | int csw | ||
| 212 | * nginx v1.5.0: 139524 lines <br/> | 212 | * nginx v1.5.0: 139524 lines <br/> |
| 213 | 213 | ||
| 214 | ### History | 214 | ### History |
| 215 | +* v0.9, 2013-12-15, refine protocol, use int64_t timestamp for ts and jitter. | ||
| 215 | * v0.9, 2013-12-15, support set the live queue length(in seconds), drop when full. | 216 | * v0.9, 2013-12-15, support set the live queue length(in seconds), drop when full. |
| 216 | * v0.9, 2013-12-15, fix the forwarder reconnect bug, feed it the sequence header. | 217 | * v0.9, 2013-12-15, fix the forwarder reconnect bug, feed it the sequence header. |
| 217 | * v0.9, 2013-12-15, support reload the hls/forwarder/transcoder. | 218 | * v0.9, 2013-12-15, support reload the hls/forwarder/transcoder. |
| @@ -1272,14 +1272,13 @@ int SrsHls::on_audio(SrsSharedPtrMessage* audio) | @@ -1272,14 +1272,13 @@ int SrsHls::on_audio(SrsSharedPtrMessage* audio) | ||
| 1272 | return ret; | 1272 | return ret; |
| 1273 | } | 1273 | } |
| 1274 | 1274 | ||
| 1275 | - int64_t corrected_time = 0; | ||
| 1276 | - if ((ret = jitter->correct(audio, 0, 0, &corrected_time)) != ERROR_SUCCESS) { | 1275 | + if ((ret = jitter->correct(audio, 0, 0)) != ERROR_SUCCESS) { |
| 1277 | srs_error("rtmp jitter correct audio failed. ret=%d", ret); | 1276 | srs_error("rtmp jitter correct audio failed. ret=%d", ret); |
| 1278 | return ret; | 1277 | return ret; |
| 1279 | } | 1278 | } |
| 1280 | 1279 | ||
| 1281 | // the pts calc from rtmp/flv header. | 1280 | // the pts calc from rtmp/flv header. |
| 1282 | - int64_t pts = corrected_time * 90; | 1281 | + int64_t pts = audio->header.timestamp * 90; |
| 1283 | 1282 | ||
| 1284 | if ((ret = ts_cache->write_audio(codec, muxer, pts, sample)) != ERROR_SUCCESS) { | 1283 | if ((ret = ts_cache->write_audio(codec, muxer, pts, sample)) != ERROR_SUCCESS) { |
| 1285 | srs_error("ts cache write audio failed. ret=%d", ret); | 1284 | srs_error("ts cache write audio failed. ret=%d", ret); |
| @@ -1315,13 +1314,12 @@ int SrsHls::on_video(SrsSharedPtrMessage* video) | @@ -1315,13 +1314,12 @@ int SrsHls::on_video(SrsSharedPtrMessage* video) | ||
| 1315 | return ret; | 1314 | return ret; |
| 1316 | } | 1315 | } |
| 1317 | 1316 | ||
| 1318 | - int64_t corrected_time = 0; | ||
| 1319 | - if ((ret = jitter->correct(video, 0, 0, &corrected_time)) != ERROR_SUCCESS) { | 1317 | + if ((ret = jitter->correct(video, 0, 0)) != ERROR_SUCCESS) { |
| 1320 | srs_error("rtmp jitter correct video failed. ret=%d", ret); | 1318 | srs_error("rtmp jitter correct video failed. ret=%d", ret); |
| 1321 | return ret; | 1319 | return ret; |
| 1322 | } | 1320 | } |
| 1323 | 1321 | ||
| 1324 | - int64_t dts = corrected_time * 90; | 1322 | + int64_t dts = video->header.timestamp * 90; |
| 1325 | if ((ret = ts_cache->write_video(codec, muxer, dts, sample)) != ERROR_SUCCESS) { | 1323 | if ((ret = ts_cache->write_video(codec, muxer, dts, sample)) != ERROR_SUCCESS) { |
| 1326 | srs_error("ts cache write video failed. ret=%d", ret); | 1324 | srs_error("ts cache write video failed. ret=%d", ret); |
| 1327 | return ret; | 1325 | return ret; |
| @@ -354,7 +354,7 @@ int SrsProtocol::recv_message(SrsCommonMessage** pmsg) | @@ -354,7 +354,7 @@ int SrsProtocol::recv_message(SrsCommonMessage** pmsg) | ||
| 354 | } | 354 | } |
| 355 | 355 | ||
| 356 | if (msg->size <= 0 || msg->header.payload_length <= 0) { | 356 | if (msg->size <= 0 || msg->header.payload_length <= 0) { |
| 357 | - srs_trace("ignore empty message(type=%d, size=%d, time=%d, sid=%d).", | 357 | + srs_trace("ignore empty message(type=%d, size=%d, time=%"PRId64", sid=%d).", |
| 358 | msg->header.message_type, msg->header.payload_length, | 358 | msg->header.message_type, msg->header.payload_length, |
| 359 | msg->header.timestamp, msg->header.stream_id); | 359 | msg->header.timestamp, msg->header.stream_id); |
| 360 | srs_freep(msg); | 360 | srs_freep(msg); |
| @@ -405,12 +405,13 @@ int SrsProtocol::send_message(ISrsMessage* msg) | @@ -405,12 +405,13 @@ int SrsProtocol::send_message(ISrsMessage* msg) | ||
| 405 | 405 | ||
| 406 | // chunk message header, 11 bytes | 406 | // chunk message header, 11 bytes |
| 407 | // timestamp, 3bytes, big-endian | 407 | // timestamp, 3bytes, big-endian |
| 408 | - if (msg->header.timestamp >= RTMP_EXTENDED_TIMESTAMP) { | 408 | + u_int32_t timestamp = (u_int32_t)msg->header.timestamp; |
| 409 | + if (timestamp >= RTMP_EXTENDED_TIMESTAMP) { | ||
| 409 | *pheader++ = 0xFF; | 410 | *pheader++ = 0xFF; |
| 410 | *pheader++ = 0xFF; | 411 | *pheader++ = 0xFF; |
| 411 | *pheader++ = 0xFF; | 412 | *pheader++ = 0xFF; |
| 412 | } else { | 413 | } else { |
| 413 | - pp = (char*)&msg->header.timestamp; | 414 | + pp = (char*)×tamp; |
| 414 | *pheader++ = pp[2]; | 415 | *pheader++ = pp[2]; |
| 415 | *pheader++ = pp[1]; | 416 | *pheader++ = pp[1]; |
| 416 | *pheader++ = pp[0]; | 417 | *pheader++ = pp[0]; |
| @@ -433,8 +434,8 @@ int SrsProtocol::send_message(ISrsMessage* msg) | @@ -433,8 +434,8 @@ int SrsProtocol::send_message(ISrsMessage* msg) | ||
| 433 | *pheader++ = pp[3]; | 434 | *pheader++ = pp[3]; |
| 434 | 435 | ||
| 435 | // chunk extended timestamp header, 0 or 4 bytes, big-endian | 436 | // chunk extended timestamp header, 0 or 4 bytes, big-endian |
| 436 | - if(msg->header.timestamp >= RTMP_EXTENDED_TIMESTAMP){ | ||
| 437 | - pp = (char*)&msg->header.timestamp; | 437 | + if(timestamp >= RTMP_EXTENDED_TIMESTAMP){ |
| 438 | + pp = (char*)×tamp; | ||
| 438 | *pheader++ = pp[3]; | 439 | *pheader++ = pp[3]; |
| 439 | *pheader++ = pp[2]; | 440 | *pheader++ = pp[2]; |
| 440 | *pheader++ = pp[1]; | 441 | *pheader++ = pp[1]; |
| @@ -461,8 +462,9 @@ int SrsProtocol::send_message(ISrsMessage* msg) | @@ -461,8 +462,9 @@ int SrsProtocol::send_message(ISrsMessage* msg) | ||
| 461 | // must send the extended-timestamp to flash-player. | 462 | // must send the extended-timestamp to flash-player. |
| 462 | // @see: ngx_rtmp_prepare_message | 463 | // @see: ngx_rtmp_prepare_message |
| 463 | // @see: http://blog.csdn.net/win_lin/article/details/13363699 | 464 | // @see: http://blog.csdn.net/win_lin/article/details/13363699 |
| 464 | - if(msg->header.timestamp >= RTMP_EXTENDED_TIMESTAMP){ | ||
| 465 | - pp = (char*)&msg->header.timestamp; | 465 | + u_int32_t timestamp = (u_int32_t)msg->header.timestamp; |
| 466 | + if(timestamp >= RTMP_EXTENDED_TIMESTAMP){ | ||
| 467 | + pp = (char*)×tamp; | ||
| 466 | *pheader++ = pp[3]; | 468 | *pheader++ = pp[3]; |
| 467 | *pheader++ = pp[2]; | 469 | *pheader++ = pp[2]; |
| 468 | *pheader++ = pp[1]; | 470 | *pheader++ = pp[1]; |
| @@ -702,7 +704,7 @@ int SrsProtocol::recv_interlaced_message(SrsCommonMessage** pmsg) | @@ -702,7 +704,7 @@ int SrsProtocol::recv_interlaced_message(SrsCommonMessage** pmsg) | ||
| 702 | srs_verbose("cache new chunk stream: fmt=%d, cid=%d", fmt, cid); | 704 | srs_verbose("cache new chunk stream: fmt=%d, cid=%d", fmt, cid); |
| 703 | } else { | 705 | } else { |
| 704 | chunk = chunk_streams[cid]; | 706 | chunk = chunk_streams[cid]; |
| 705 | - srs_verbose("cached chunk stream: fmt=%d, cid=%d, size=%d, message(type=%d, size=%d, time=%d, sid=%d)", | 707 | + srs_verbose("cached chunk stream: fmt=%d, cid=%d, size=%d, message(type=%d, size=%d, time=%"PRId64", sid=%d)", |
| 706 | chunk->fmt, chunk->cid, (chunk->msg? chunk->msg->size : 0), chunk->header.message_type, chunk->header.payload_length, | 708 | chunk->fmt, chunk->cid, (chunk->msg? chunk->msg->size : 0), chunk->header.message_type, chunk->header.payload_length, |
| 707 | chunk->header.timestamp, chunk->header.stream_id); | 709 | chunk->header.timestamp, chunk->header.stream_id); |
| 708 | } | 710 | } |
| @@ -716,7 +718,7 @@ int SrsProtocol::recv_interlaced_message(SrsCommonMessage** pmsg) | @@ -716,7 +718,7 @@ int SrsProtocol::recv_interlaced_message(SrsCommonMessage** pmsg) | ||
| 716 | return ret; | 718 | return ret; |
| 717 | } | 719 | } |
| 718 | srs_verbose("read message header success. " | 720 | srs_verbose("read message header success. " |
| 719 | - "fmt=%d, mh_size=%d, ext_time=%d, size=%d, message(type=%d, size=%d, time=%d, sid=%d)", | 721 | + "fmt=%d, mh_size=%d, ext_time=%d, size=%d, message(type=%d, size=%d, time=%"PRId64", sid=%d)", |
| 720 | fmt, mh_size, chunk->extended_timestamp, (chunk->msg? chunk->msg->size : 0), chunk->header.message_type, | 722 | fmt, mh_size, chunk->extended_timestamp, (chunk->msg? chunk->msg->size : 0), chunk->header.message_type, |
| 721 | chunk->header.payload_length, chunk->header.timestamp, chunk->header.stream_id); | 723 | chunk->header.payload_length, chunk->header.timestamp, chunk->header.stream_id); |
| 722 | 724 | ||
| @@ -738,14 +740,14 @@ int SrsProtocol::recv_interlaced_message(SrsCommonMessage** pmsg) | @@ -738,14 +740,14 @@ int SrsProtocol::recv_interlaced_message(SrsCommonMessage** pmsg) | ||
| 738 | 740 | ||
| 739 | // not got an entire RTMP message, try next chunk. | 741 | // not got an entire RTMP message, try next chunk. |
| 740 | if (!msg) { | 742 | if (!msg) { |
| 741 | - srs_verbose("get partial message success. chunk_payload_size=%d, size=%d, message(type=%d, size=%d, time=%d, sid=%d)", | 743 | + srs_verbose("get partial message success. chunk_payload_size=%d, size=%d, message(type=%d, size=%d, time=%"PRId64", sid=%d)", |
| 742 | payload_size, (msg? msg->size : (chunk->msg? chunk->msg->size : 0)), chunk->header.message_type, chunk->header.payload_length, | 744 | payload_size, (msg? msg->size : (chunk->msg? chunk->msg->size : 0)), chunk->header.message_type, chunk->header.payload_length, |
| 743 | chunk->header.timestamp, chunk->header.stream_id); | 745 | chunk->header.timestamp, chunk->header.stream_id); |
| 744 | return ret; | 746 | return ret; |
| 745 | } | 747 | } |
| 746 | 748 | ||
| 747 | *pmsg = msg; | 749 | *pmsg = msg; |
| 748 | - srs_info("get entire message success. chunk_payload_size=%d, size=%d, message(type=%d, size=%d, time=%d, sid=%d)", | 750 | + srs_info("get entire message success. chunk_payload_size=%d, size=%d, message(type=%d, size=%d, time=%"PRId64", sid=%d)", |
| 749 | payload_size, (msg? msg->size : (chunk->msg? chunk->msg->size : 0)), chunk->header.message_type, chunk->header.payload_length, | 751 | payload_size, (msg? msg->size : (chunk->msg? chunk->msg->size : 0)), chunk->header.message_type, chunk->header.payload_length, |
| 750 | chunk->header.timestamp, chunk->header.stream_id); | 752 | chunk->header.timestamp, chunk->header.stream_id); |
| 751 | 753 | ||
| @@ -952,16 +954,16 @@ int SrsProtocol::read_message_header(SrsChunkStream* chunk, char fmt, int bh_siz | @@ -952,16 +954,16 @@ int SrsProtocol::read_message_header(SrsChunkStream* chunk, char fmt, int bh_siz | ||
| 952 | pp[1] = *p++; | 954 | pp[1] = *p++; |
| 953 | pp[2] = *p++; | 955 | pp[2] = *p++; |
| 954 | pp[3] = *p++; | 956 | pp[3] = *p++; |
| 955 | - srs_verbose("header read completed. fmt=%d, mh_size=%d, ext_time=%d, time=%d, payload=%d, type=%d, sid=%d", | 957 | + srs_verbose("header read completed. fmt=%d, mh_size=%d, ext_time=%d, time=%"PRId64", payload=%d, type=%d, sid=%d", |
| 956 | fmt, mh_size, chunk->extended_timestamp, chunk->header.timestamp, chunk->header.payload_length, | 958 | fmt, mh_size, chunk->extended_timestamp, chunk->header.timestamp, chunk->header.payload_length, |
| 957 | chunk->header.message_type, chunk->header.stream_id); | 959 | chunk->header.message_type, chunk->header.stream_id); |
| 958 | } else { | 960 | } else { |
| 959 | - srs_verbose("header read completed. fmt=%d, mh_size=%d, ext_time=%d, time=%d, payload=%d, type=%d", | 961 | + srs_verbose("header read completed. fmt=%d, mh_size=%d, ext_time=%d, time=%"PRId64", payload=%d, type=%d", |
| 960 | fmt, mh_size, chunk->extended_timestamp, chunk->header.timestamp, chunk->header.payload_length, | 962 | fmt, mh_size, chunk->extended_timestamp, chunk->header.timestamp, chunk->header.payload_length, |
| 961 | chunk->header.message_type); | 963 | chunk->header.message_type); |
| 962 | } | 964 | } |
| 963 | } else { | 965 | } else { |
| 964 | - srs_verbose("header read completed. fmt=%d, mh_size=%d, ext_time=%d, time=%d", | 966 | + srs_verbose("header read completed. fmt=%d, mh_size=%d, ext_time=%d, time=%"PRId64"", |
| 965 | fmt, mh_size, chunk->extended_timestamp, chunk->header.timestamp); | 967 | fmt, mh_size, chunk->extended_timestamp, chunk->header.timestamp); |
| 966 | } | 968 | } |
| 967 | } else { | 969 | } else { |
| @@ -986,7 +988,7 @@ int SrsProtocol::read_message_header(SrsChunkStream* chunk, char fmt, int bh_siz | @@ -986,7 +988,7 @@ int SrsProtocol::read_message_header(SrsChunkStream* chunk, char fmt, int bh_siz | ||
| 986 | 988 | ||
| 987 | // ffmpeg/librtmp may donot send this filed, need to detect the value. | 989 | // ffmpeg/librtmp may donot send this filed, need to detect the value. |
| 988 | // @see also: http://blog.csdn.net/win_lin/article/details/13363699 | 990 | // @see also: http://blog.csdn.net/win_lin/article/details/13363699 |
| 989 | - int32_t timestamp = 0x00; | 991 | + u_int32_t timestamp = 0x00; |
| 990 | char* pp = (char*)×tamp; | 992 | char* pp = (char*)×tamp; |
| 991 | pp[3] = *p++; | 993 | pp[3] = *p++; |
| 992 | pp[2] = *p++; | 994 | pp[2] = *p++; |
| @@ -995,14 +997,14 @@ int SrsProtocol::read_message_header(SrsChunkStream* chunk, char fmt, int bh_siz | @@ -995,14 +997,14 @@ int SrsProtocol::read_message_header(SrsChunkStream* chunk, char fmt, int bh_siz | ||
| 995 | 997 | ||
| 996 | // compare to the chunk timestamp, which is set by chunk message header | 998 | // compare to the chunk timestamp, which is set by chunk message header |
| 997 | // type 0,1 or 2. | 999 | // type 0,1 or 2. |
| 998 | - int32_t chunk_timestamp = chunk->header.timestamp; | 1000 | + u_int32_t chunk_timestamp = chunk->header.timestamp; |
| 999 | if (chunk_timestamp > RTMP_EXTENDED_TIMESTAMP && chunk_timestamp != timestamp) { | 1001 | if (chunk_timestamp > RTMP_EXTENDED_TIMESTAMP && chunk_timestamp != timestamp) { |
| 1000 | mh_size -= 4; | 1002 | mh_size -= 4; |
| 1001 | srs_verbose("ignore the 4bytes extended timestamp. mh_size=%d", mh_size); | 1003 | srs_verbose("ignore the 4bytes extended timestamp. mh_size=%d", mh_size); |
| 1002 | } else { | 1004 | } else { |
| 1003 | chunk->header.timestamp = timestamp; | 1005 | chunk->header.timestamp = timestamp; |
| 1004 | } | 1006 | } |
| 1005 | - srs_verbose("header read ext_time completed. time=%d", chunk->header.timestamp); | 1007 | + srs_verbose("header read ext_time completed. time=%"PRId64"", chunk->header.timestamp); |
| 1006 | } | 1008 | } |
| 1007 | 1009 | ||
| 1008 | // valid message | 1010 | // valid message |
| @@ -1032,7 +1034,7 @@ int SrsProtocol::read_message_payload(SrsChunkStream* chunk, int bh_size, int mh | @@ -1032,7 +1034,7 @@ int SrsProtocol::read_message_payload(SrsChunkStream* chunk, int bh_size, int mh | ||
| 1032 | buffer->erase(bh_size + mh_size); | 1034 | buffer->erase(bh_size + mh_size); |
| 1033 | 1035 | ||
| 1034 | srs_trace("get an empty RTMP " | 1036 | srs_trace("get an empty RTMP " |
| 1035 | - "message(type=%d, size=%d, time=%d, sid=%d)", chunk->header.message_type, | 1037 | + "message(type=%d, size=%d, time=%"PRId64", sid=%d)", chunk->header.message_type, |
| 1036 | chunk->header.payload_length, chunk->header.timestamp, chunk->header.stream_id); | 1038 | chunk->header.payload_length, chunk->header.timestamp, chunk->header.stream_id); |
| 1037 | 1039 | ||
| 1038 | *pmsg = chunk->msg; | 1040 | *pmsg = chunk->msg; |
| @@ -1073,13 +1075,13 @@ int SrsProtocol::read_message_payload(SrsChunkStream* chunk, int bh_size, int mh | @@ -1073,13 +1075,13 @@ int SrsProtocol::read_message_payload(SrsChunkStream* chunk, int bh_size, int mh | ||
| 1073 | if (chunk->header.payload_length == chunk->msg->size) { | 1075 | if (chunk->header.payload_length == chunk->msg->size) { |
| 1074 | *pmsg = chunk->msg; | 1076 | *pmsg = chunk->msg; |
| 1075 | chunk->msg = NULL; | 1077 | chunk->msg = NULL; |
| 1076 | - srs_verbose("get entire RTMP message(type=%d, size=%d, time=%d, sid=%d)", | 1078 | + srs_verbose("get entire RTMP message(type=%d, size=%d, time=%"PRId64", sid=%d)", |
| 1077 | chunk->header.message_type, chunk->header.payload_length, | 1079 | chunk->header.message_type, chunk->header.payload_length, |
| 1078 | chunk->header.timestamp, chunk->header.stream_id); | 1080 | chunk->header.timestamp, chunk->header.stream_id); |
| 1079 | return ret; | 1081 | return ret; |
| 1080 | } | 1082 | } |
| 1081 | 1083 | ||
| 1082 | - srs_verbose("get partial RTMP message(type=%d, size=%d, time=%d, sid=%d), partial size=%d", | 1084 | + srs_verbose("get partial RTMP message(type=%d, size=%d, time=%"PRId64", sid=%d), partial size=%d", |
| 1083 | chunk->header.message_type, chunk->header.payload_length, | 1085 | chunk->header.message_type, chunk->header.payload_length, |
| 1084 | chunk->header.timestamp, chunk->header.stream_id, | 1086 | chunk->header.timestamp, chunk->header.stream_id, |
| 1085 | chunk->msg->size); | 1087 | chunk->msg->size); |
| @@ -204,8 +204,9 @@ struct SrsMessageHeader | @@ -204,8 +204,9 @@ struct SrsMessageHeader | ||
| 204 | * Four-byte field that contains a timestamp of the message. | 204 | * Four-byte field that contains a timestamp of the message. |
| 205 | * The 4 bytes are packed in the big-endian order. | 205 | * The 4 bytes are packed in the big-endian order. |
| 206 | * @remark, used as calc timestamp when decode and encode time. | 206 | * @remark, used as calc timestamp when decode and encode time. |
| 207 | + * @remark, we use 64bits for large time for jitter detect and hls. | ||
| 207 | */ | 208 | */ |
| 208 | - u_int32_t timestamp; | 209 | + int64_t timestamp; |
| 209 | 210 | ||
| 210 | SrsMessageHeader(); | 211 | SrsMessageHeader(); |
| 211 | virtual ~SrsMessageHeader(); | 212 | virtual ~SrsMessageHeader(); |
| @@ -1126,7 +1127,7 @@ int srs_rtmp_expect_message(SrsProtocol* protocol, SrsCommonMessage** pmsg, T** | @@ -1126,7 +1127,7 @@ int srs_rtmp_expect_message(SrsProtocol* protocol, SrsCommonMessage** pmsg, T** | ||
| 1126 | T* pkt = dynamic_cast<T*>(msg->get_packet()); | 1127 | T* pkt = dynamic_cast<T*>(msg->get_packet()); |
| 1127 | if (!pkt) { | 1128 | if (!pkt) { |
| 1128 | delete msg; | 1129 | delete msg; |
| 1129 | - srs_trace("drop message(type=%d, size=%d, time=%d, sid=%d).", | 1130 | + srs_trace("drop message(type=%d, size=%d, time=%"PRId64", sid=%d).", |
| 1130 | msg->header.message_type, msg->header.payload_length, | 1131 | msg->header.message_type, msg->header.payload_length, |
| 1131 | msg->header.timestamp, msg->header.stream_id); | 1132 | msg->header.timestamp, msg->header.stream_id); |
| 1132 | continue; | 1133 | continue; |
| @@ -38,7 +38,7 @@ using namespace std; | @@ -38,7 +38,7 @@ using namespace std; | ||
| 38 | #include <srs_core_rtmp.hpp> | 38 | #include <srs_core_rtmp.hpp> |
| 39 | 39 | ||
| 40 | #define CONST_MAX_JITTER_MS 500 | 40 | #define CONST_MAX_JITTER_MS 500 |
| 41 | -#define DEFAULT_FRAME_TIME_MS 10 | 41 | +#define DEFAULT_FRAME_TIME_MS 40 |
| 42 | 42 | ||
| 43 | SrsRtmpJitter::SrsRtmpJitter() | 43 | SrsRtmpJitter::SrsRtmpJitter() |
| 44 | { | 44 | { |
| @@ -49,19 +49,13 @@ SrsRtmpJitter::~SrsRtmpJitter() | @@ -49,19 +49,13 @@ SrsRtmpJitter::~SrsRtmpJitter() | ||
| 49 | { | 49 | { |
| 50 | } | 50 | } |
| 51 | 51 | ||
| 52 | -// TODO: FIXME: remove the 64bits time, change the timestamp in heaer to 64bits. | ||
| 53 | -int SrsRtmpJitter::correct(SrsSharedPtrMessage* msg, int tba, int tbv, int64_t* corrected_time) | 52 | +int SrsRtmpJitter::correct(SrsSharedPtrMessage* msg, int tba, int tbv) |
| 54 | { | 53 | { |
| 55 | int ret = ERROR_SUCCESS; | 54 | int ret = ERROR_SUCCESS; |
| 56 | 55 | ||
| 57 | // set to 0 for metadata. | 56 | // set to 0 for metadata. |
| 58 | if (!msg->header.is_video() && !msg->header.is_audio()) { | 57 | if (!msg->header.is_video() && !msg->header.is_audio()) { |
| 59 | - if (corrected_time) { | ||
| 60 | - *corrected_time = 0; | ||
| 61 | - } | ||
| 62 | - | ||
| 63 | msg->header.timestamp = 0; | 58 | msg->header.timestamp = 0; |
| 64 | - | ||
| 65 | return ret; | 59 | return ret; |
| 66 | } | 60 | } |
| 67 | 61 | ||
| @@ -78,16 +72,16 @@ int SrsRtmpJitter::correct(SrsSharedPtrMessage* msg, int tba, int tbv, int64_t* | @@ -78,16 +72,16 @@ int SrsRtmpJitter::correct(SrsSharedPtrMessage* msg, int tba, int tbv, int64_t* | ||
| 78 | * 3. last_pkt_correct_time: simply add the positive delta, | 72 | * 3. last_pkt_correct_time: simply add the positive delta, |
| 79 | * and enforce the time monotonically. | 73 | * and enforce the time monotonically. |
| 80 | */ | 74 | */ |
| 81 | - u_int32_t time = msg->header.timestamp; | ||
| 82 | - int32_t delta = time - last_pkt_time; | 75 | + int64_t time = msg->header.timestamp; |
| 76 | + int64_t delta = time - last_pkt_time; | ||
| 83 | 77 | ||
| 84 | // if jitter detected, reset the delta. | 78 | // if jitter detected, reset the delta. |
| 85 | if (delta < 0 || delta > CONST_MAX_JITTER_MS) { | 79 | if (delta < 0 || delta > CONST_MAX_JITTER_MS) { |
| 86 | // calc the right diff by audio sample rate | 80 | // calc the right diff by audio sample rate |
| 87 | if (msg->header.is_audio() && sample_rate > 0) { | 81 | if (msg->header.is_audio() && sample_rate > 0) { |
| 88 | - delta = (int32_t)(delta * 1000.0 / sample_rate); | 82 | + delta = (int64_t)(delta * 1000.0 / sample_rate); |
| 89 | } else if (msg->header.is_video() && frame_rate > 0) { | 83 | } else if (msg->header.is_video() && frame_rate > 0) { |
| 90 | - delta = (int32_t)(delta * 1.0 / frame_rate); | 84 | + delta = (int64_t)(delta * 1.0 / frame_rate); |
| 91 | } else { | 85 | } else { |
| 92 | delta = DEFAULT_FRAME_TIME_MS; | 86 | delta = DEFAULT_FRAME_TIME_MS; |
| 93 | } | 87 | } |
| @@ -97,20 +91,16 @@ int SrsRtmpJitter::correct(SrsSharedPtrMessage* msg, int tba, int tbv, int64_t* | @@ -97,20 +91,16 @@ int SrsRtmpJitter::correct(SrsSharedPtrMessage* msg, int tba, int tbv, int64_t* | ||
| 97 | delta = DEFAULT_FRAME_TIME_MS; | 91 | delta = DEFAULT_FRAME_TIME_MS; |
| 98 | } | 92 | } |
| 99 | 93 | ||
| 100 | - srs_info("jitter detected, last_pts=%d, pts=%d, diff=%d, last_time=%d, time=%d, diff=%d", | 94 | + srs_info("jitter detected, last_pts=%"PRId64", pts=%"PRId64", diff=%"PRId64", last_time=%"PRId64", time=%"PRId64", diff=%"PRId64"", |
| 101 | last_pkt_time, time, time - last_pkt_time, last_pkt_correct_time, last_pkt_correct_time + delta, delta); | 95 | last_pkt_time, time, time - last_pkt_time, last_pkt_correct_time, last_pkt_correct_time + delta, delta); |
| 102 | } else { | 96 | } else { |
| 103 | - srs_verbose("timestamp no jitter. time=%d, last_pkt=%d, correct_to=%d", | 97 | + srs_verbose("timestamp no jitter. time=%"PRId64", last_pkt=%"PRId64", correct_to=%"PRId64"", |
| 104 | time, last_pkt_time, last_pkt_correct_time + delta); | 98 | time, last_pkt_time, last_pkt_correct_time + delta); |
| 105 | } | 99 | } |
| 106 | 100 | ||
| 107 | last_pkt_correct_time = srs_max(0, last_pkt_correct_time + delta); | 101 | last_pkt_correct_time = srs_max(0, last_pkt_correct_time + delta); |
| 108 | 102 | ||
| 109 | - if (corrected_time) { | ||
| 110 | - *corrected_time = last_pkt_correct_time; | ||
| 111 | - } | ||
| 112 | msg->header.timestamp = last_pkt_correct_time; | 103 | msg->header.timestamp = last_pkt_correct_time; |
| 113 | - | ||
| 114 | last_pkt_time = time; | 104 | last_pkt_time = time; |
| 115 | 105 | ||
| 116 | return ret; | 106 | return ret; |
| @@ -56,18 +56,16 @@ class SrsEncoder; | @@ -56,18 +56,16 @@ class SrsEncoder; | ||
| 56 | class SrsRtmpJitter | 56 | class SrsRtmpJitter |
| 57 | { | 57 | { |
| 58 | private: | 58 | private: |
| 59 | - u_int32_t last_pkt_time; | ||
| 60 | - u_int32_t last_pkt_correct_time; | 59 | + int64_t last_pkt_time; |
| 60 | + int64_t last_pkt_correct_time; | ||
| 61 | public: | 61 | public: |
| 62 | SrsRtmpJitter(); | 62 | SrsRtmpJitter(); |
| 63 | virtual ~SrsRtmpJitter(); | 63 | virtual ~SrsRtmpJitter(); |
| 64 | public: | 64 | public: |
| 65 | /** | 65 | /** |
| 66 | * detect the time jitter and correct it. | 66 | * detect the time jitter and correct it. |
| 67 | - * @param corrected_time output the 64bits time. | ||
| 68 | - * ignore if NULL. | ||
| 69 | */ | 67 | */ |
| 70 | - virtual int correct(SrsSharedPtrMessage* msg, int tba, int tbv, int64_t* corrected_time = NULL); | 68 | + virtual int correct(SrsSharedPtrMessage* msg, int tba, int tbv); |
| 71 | /** | 69 | /** |
| 72 | * get current client time, the last packet time. | 70 | * get current client time, the last packet time. |
| 73 | */ | 71 | */ |
-
请 注册 或 登录 后发表评论