|
|
|
@ -18,6 +18,8 @@
|
|
|
|
|
#include <sstream>
|
|
|
|
|
|
|
|
|
|
std::shared_ptr<srt2rtmp> srt2rtmp::s_srt2rtmp_ptr;
|
|
|
|
|
std::mutex srt2rtmp::_srt_error_mutex;
|
|
|
|
|
std::map<std::string, int> srt2rtmp::_srt_error_map;
|
|
|
|
|
|
|
|
|
|
std::shared_ptr<srt2rtmp> srt2rtmp::get_instance() {
|
|
|
|
|
if (!s_srt2rtmp_ptr) {
|
|
|
|
@ -155,6 +157,7 @@ void srt2rtmp::handle_close_rtmpsession(const std::string& key_path) {
|
|
|
|
|
srs_error_t srt2rtmp::cycle() {
|
|
|
|
|
srs_error_t err = srs_success;
|
|
|
|
|
_lastcheck_ts = 0;
|
|
|
|
|
int err_code = -1;
|
|
|
|
|
|
|
|
|
|
while(true) {
|
|
|
|
|
SRT_DATA_MSG_PTR msg_ptr = get_data_message();
|
|
|
|
@ -165,7 +168,11 @@ srs_error_t srt2rtmp::cycle() {
|
|
|
|
|
switch (msg_ptr->msg_type()) {
|
|
|
|
|
case SRT_MSG_DATA_TYPE:
|
|
|
|
|
{
|
|
|
|
|
handle_ts_data(msg_ptr);
|
|
|
|
|
err_code = handle_ts_data(msg_ptr);
|
|
|
|
|
if (err_code != ERROR_SUCCESS) {
|
|
|
|
|
std::unique_lock<std::mutex> locker(_srt_error_mutex);
|
|
|
|
|
_srt_error_map[msg_ptr->get_path()] = err_code;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case SRT_MSG_CLOSE_TYPE:
|
|
|
|
@ -194,7 +201,7 @@ srs_error_t srt2rtmp::cycle() {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void srt2rtmp::handle_ts_data(SRT_DATA_MSG_PTR data_ptr) {
|
|
|
|
|
int srt2rtmp::handle_ts_data(SRT_DATA_MSG_PTR data_ptr) {
|
|
|
|
|
RTMP_CLIENT_PTR rtmp_ptr;
|
|
|
|
|
auto iter = _rtmp_client_map.find(data_ptr->get_path());
|
|
|
|
|
if (iter == _rtmp_client_map.end()) {
|
|
|
|
@ -205,9 +212,7 @@ void srt2rtmp::handle_ts_data(SRT_DATA_MSG_PTR data_ptr) {
|
|
|
|
|
rtmp_ptr = iter->second;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
rtmp_ptr->receive_ts_data(data_ptr);
|
|
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
return rtmp_ptr->receive_ts_data(data_ptr);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void srt2rtmp::handle_log_data(SRT_DATA_MSG_PTR data_ptr) {
|
|
|
|
@ -347,9 +352,8 @@ srs_error_t rtmp_client::connect() {
|
|
|
|
|
return err;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void rtmp_client::receive_ts_data(SRT_DATA_MSG_PTR data_ptr) {
|
|
|
|
|
_ts_demux_ptr->decode(data_ptr, shared_from_this());//on_data_callback is the decode callback
|
|
|
|
|
return;
|
|
|
|
|
int rtmp_client::receive_ts_data(SRT_DATA_MSG_PTR data_ptr) {
|
|
|
|
|
return _ts_demux_ptr->decode(data_ptr, shared_from_this());//on_data_callback is the decode callback
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
srs_error_t rtmp_client::write_h264_sps_pps(uint32_t dts, uint32_t pts) {
|
|
|
|
@ -672,13 +676,13 @@ srs_error_t rtmp_client::on_ts_audio(std::shared_ptr<SrsBuffer> avs_ptr, uint64_
|
|
|
|
|
return err;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void rtmp_client::on_data_callback(SRT_DATA_MSG_PTR data_ptr, unsigned int media_type,
|
|
|
|
|
int rtmp_client::on_data_callback(SRT_DATA_MSG_PTR data_ptr, unsigned int media_type,
|
|
|
|
|
uint64_t dts, uint64_t pts)
|
|
|
|
|
{
|
|
|
|
|
srs_error_t err = srs_success;
|
|
|
|
|
if (!data_ptr || (data_ptr->get_data() == nullptr) || (data_ptr->data_len() == 0)) {
|
|
|
|
|
assert(0);
|
|
|
|
|
return;
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
auto avs_ptr = std::make_shared<SrsBuffer>((char*)data_ptr->get_data(), data_ptr->data_len());
|
|
|
|
@ -689,13 +693,16 @@ void rtmp_client::on_data_callback(SRT_DATA_MSG_PTR data_ptr, unsigned int media
|
|
|
|
|
err = on_ts_audio(avs_ptr, dts, pts);
|
|
|
|
|
} else {
|
|
|
|
|
srs_error("mpegts demux unkown stream type:0x%02x, only support h264+aac", media_type);
|
|
|
|
|
return;
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (err != srs_success) {
|
|
|
|
|
srs_error("send media data error:", srs_error_code(err));
|
|
|
|
|
srs_error("send media data error:%s", srs_error_desc(err).c_str());
|
|
|
|
|
int err_code = srs_error_code(err);
|
|
|
|
|
srs_freep(err);
|
|
|
|
|
return err_code;
|
|
|
|
|
}
|
|
|
|
|
return;
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
rtmp_packet_queue::rtmp_packet_queue():_queue_timeout(QUEUE_DEF_TIMEOUT)
|
|
|
|
|