|
|
|
@ -69,11 +69,11 @@ int SrsConsumer::get_time()
|
|
|
|
|
return (int)last_pkt_correct_time;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int SrsConsumer::enqueue(SrsSharedPtrMessage* msg)
|
|
|
|
|
int SrsConsumer::enqueue(SrsSharedPtrMessage* msg, int audio_sample_rate)
|
|
|
|
|
{
|
|
|
|
|
int ret = ERROR_SUCCESS;
|
|
|
|
|
|
|
|
|
|
if ((ret = jitter_correct(msg)) != ERROR_SUCCESS) {
|
|
|
|
|
if ((ret = jitter_correct(msg, audio_sample_rate)) != ERROR_SUCCESS) {
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -111,7 +111,7 @@ int SrsConsumer::get_packets(int max_count, SrsSharedPtrMessage**& pmsgs, int& c
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int SrsConsumer::jitter_correct(SrsSharedPtrMessage* msg)
|
|
|
|
|
int SrsConsumer::jitter_correct(SrsSharedPtrMessage* msg, int audio_sample_rate)
|
|
|
|
|
{
|
|
|
|
|
int ret = ERROR_SUCCESS;
|
|
|
|
|
|
|
|
|
@ -130,10 +130,15 @@ int SrsConsumer::jitter_correct(SrsSharedPtrMessage* msg)
|
|
|
|
|
|
|
|
|
|
// if jitter detected, reset the delta.
|
|
|
|
|
if (delta < 0 || delta > CONST_MAX_JITTER_MS) {
|
|
|
|
|
delta = DEFAULT_FRAME_TIME_MS;
|
|
|
|
|
// calc the right diff by audio sample rate
|
|
|
|
|
if (msg->header.is_audio() && audio_sample_rate > 0) {
|
|
|
|
|
delta = (int32_t)(delta * 1000.0 / audio_sample_rate);
|
|
|
|
|
} else {
|
|
|
|
|
delta = DEFAULT_FRAME_TIME_MS;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
srs_info("jitter detected, delta=%d, last_pkt=%d, time=%d, correct_to=%d",
|
|
|
|
|
delta, last_pkt_time, time, last_pkt_correct_time + delta);
|
|
|
|
|
srs_info("jitter detected, last_pts=%d, pts=%d, diff=%d, last_time=%d, time=%d, diff=%d",
|
|
|
|
|
last_pkt_time, time, time - last_pkt_time, last_pkt_correct_time, last_pkt_correct_time + delta, delta);
|
|
|
|
|
} else {
|
|
|
|
|
srs_verbose("timestamp no jitter. time=%d, last_pkt=%d, correct_to=%d",
|
|
|
|
|
time, last_pkt_time, last_pkt_correct_time + delta);
|
|
|
|
@ -155,6 +160,8 @@ SrsSource::SrsSource(std::string _stream_url)
|
|
|
|
|
|
|
|
|
|
cached_video_count = 0;
|
|
|
|
|
enable_gop_cache = true;
|
|
|
|
|
|
|
|
|
|
audio_sample_rate = 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
SrsSource::~SrsSource()
|
|
|
|
@ -182,6 +189,13 @@ int SrsSource::on_meta_data(SrsCommonMessage* msg, SrsOnMetaDataPacket* metadata
|
|
|
|
|
metadata->metadata->set("server", new SrsAmf0String(
|
|
|
|
|
RTMP_SIG_SRS_KEY" "RTMP_SIG_SRS_VERSION" ("RTMP_SIG_SRS_URL_SHORT")"));
|
|
|
|
|
|
|
|
|
|
SrsAmf0Any* prop = NULL;
|
|
|
|
|
if ((prop = metadata->metadata->get_property("audiosamplerate")) != NULL) {
|
|
|
|
|
if (prop->is_number()) {
|
|
|
|
|
audio_sample_rate = (int)(srs_amf0_convert<SrsAmf0Number>(prop)->value);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// encode the metadata to payload
|
|
|
|
|
int size = metadata->get_payload_length();
|
|
|
|
|
if (size <= 0) {
|
|
|
|
@ -214,7 +228,7 @@ int SrsSource::on_meta_data(SrsCommonMessage* msg, SrsOnMetaDataPacket* metadata
|
|
|
|
|
std::vector<SrsConsumer*>::iterator it;
|
|
|
|
|
for (it = consumers.begin(); it != consumers.end(); ++it) {
|
|
|
|
|
SrsConsumer* consumer = *it;
|
|
|
|
|
if ((ret = consumer->enqueue(cache_metadata->copy())) != ERROR_SUCCESS) {
|
|
|
|
|
if ((ret = consumer->enqueue(cache_metadata->copy(), audio_sample_rate)) != ERROR_SUCCESS) {
|
|
|
|
|
srs_error("dispatch the metadata failed. ret=%d", ret);
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
@ -244,7 +258,7 @@ int SrsSource::on_audio(SrsCommonMessage* audio)
|
|
|
|
|
std::vector<SrsConsumer*>::iterator it;
|
|
|
|
|
for (it = consumers.begin(); it != consumers.end(); ++it) {
|
|
|
|
|
SrsConsumer* consumer = *it;
|
|
|
|
|
if ((ret = consumer->enqueue(msg->copy())) != ERROR_SUCCESS) {
|
|
|
|
|
if ((ret = consumer->enqueue(msg->copy(), audio_sample_rate)) != ERROR_SUCCESS) {
|
|
|
|
|
srs_error("dispatch the audio failed. ret=%d", ret);
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
@ -288,7 +302,7 @@ int SrsSource::on_video(SrsCommonMessage* video)
|
|
|
|
|
std::vector<SrsConsumer*>::iterator it;
|
|
|
|
|
for (it = consumers.begin(); it != consumers.end(); ++it) {
|
|
|
|
|
SrsConsumer* consumer = *it;
|
|
|
|
|
if ((ret = consumer->enqueue(msg->copy())) != ERROR_SUCCESS) {
|
|
|
|
|
if ((ret = consumer->enqueue(msg->copy(), audio_sample_rate)) != ERROR_SUCCESS) {
|
|
|
|
|
srs_error("dispatch the video failed. ret=%d", ret);
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
@ -319,19 +333,19 @@ int SrsSource::on_video(SrsCommonMessage* video)
|
|
|
|
|
consumer = new SrsConsumer(this);
|
|
|
|
|
consumers.push_back(consumer);
|
|
|
|
|
|
|
|
|
|
if (cache_metadata && (ret = consumer->enqueue(cache_metadata->copy())) != ERROR_SUCCESS) {
|
|
|
|
|
if (cache_metadata && (ret = consumer->enqueue(cache_metadata->copy(), audio_sample_rate)) != ERROR_SUCCESS) {
|
|
|
|
|
srs_error("dispatch metadata failed. ret=%d", ret);
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
srs_info("dispatch metadata success");
|
|
|
|
|
|
|
|
|
|
if (cache_sh_video && (ret = consumer->enqueue(cache_sh_video->copy())) != ERROR_SUCCESS) {
|
|
|
|
|
if (cache_sh_video && (ret = consumer->enqueue(cache_sh_video->copy(), audio_sample_rate)) != ERROR_SUCCESS) {
|
|
|
|
|
srs_error("dispatch video sequence header failed. ret=%d", ret);
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
srs_info("dispatch video sequence header success");
|
|
|
|
|
|
|
|
|
|
if (cache_sh_audio && (ret = consumer->enqueue(cache_sh_audio->copy())) != ERROR_SUCCESS) {
|
|
|
|
|
if (cache_sh_audio && (ret = consumer->enqueue(cache_sh_audio->copy(), audio_sample_rate)) != ERROR_SUCCESS) {
|
|
|
|
|
srs_error("dispatch audio sequence header failed. ret=%d", ret);
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
@ -340,7 +354,7 @@ int SrsSource::on_video(SrsCommonMessage* video)
|
|
|
|
|
std::vector<SrsSharedPtrMessage*>::iterator it;
|
|
|
|
|
for (it = gop_cache.begin(); it != gop_cache.end(); ++it) {
|
|
|
|
|
SrsSharedPtrMessage* msg = *it;
|
|
|
|
|
if ((ret = consumer->enqueue(msg->copy())) != ERROR_SUCCESS) {
|
|
|
|
|
if ((ret = consumer->enqueue(msg->copy(), audio_sample_rate)) != ERROR_SUCCESS) {
|
|
|
|
|
srs_error("dispatch cached gop failed. ret=%d", ret);
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|