diff --git a/src/media_server.cpp b/src/media_server.cpp index c667013..6b83a84 100644 --- a/src/media_server.cpp +++ b/src/media_server.cpp @@ -17,7 +17,9 @@ #include #include #include +#ifndef WIN32 #include +#endif uv_loop_t* MediaServer::loop_ = uv_default_loop(); uv_loop_t* MediaServer::hls_loop_ = uv_loop_new(); @@ -245,7 +247,11 @@ uv_loop_t* get_global_io_context() { int main(int argn, char** argv) { std::string cfg_file; - +#ifdef WIN32 + if(argn > 2 && !_stricmp(argv[1],"-c") ) { + cfg_file = argv[2]; + } +#else int opt = 0; while ((opt = getopt(argn, argv, "c:")) != -1) { switch (opt) { @@ -259,7 +265,7 @@ int main(int argn, char** argv) { return -1; } } - +#endif MediaServer::Run(cfg_file); return 0; diff --git a/src/net/rtmp/rtmp_handshake.cpp b/src/net/rtmp/rtmp_handshake.cpp index 45a964b..a9c8579 100644 --- a/src/net/rtmp/rtmp_handshake.cpp +++ b/src/net/rtmp/rtmp_handshake.cpp @@ -368,7 +368,7 @@ int c1s1_handle::try_schema1(uint8_t* data) { } void c1s1_handle::prepare_digest() { - c1_digest_offset_ = random(); + c1_digest_offset_ = rand(); uint32_t real_offset = calc_valid_digest_offset(c1_digest_offset_); digest_random0_size_ = real_offset; @@ -391,7 +391,7 @@ void c1s1_handle::prepare_digest() { } void c1s1_handle::prepare_key() { - c1_key_offset_ = random(); + c1_key_offset_ = rand(); uint32_t real_offset = calc_valid_key_offset(c1_key_offset_); key_random0_size_ = real_offset; diff --git a/src/net/rtmp/rtmp_handshake.hpp b/src/net/rtmp/rtmp_handshake.hpp index b46f07f..0a9df57 100644 --- a/src/net/rtmp/rtmp_handshake.hpp +++ b/src/net/rtmp/rtmp_handshake.hpp @@ -1,5 +1,6 @@ #ifndef RTMP_HANDSHAKE_HPP #define RTMP_HANDSHAKE_HPP + #include "rtmp_pub.hpp" #include "logger.hpp" #include "byte_stream.hpp" @@ -10,6 +11,7 @@ #include #include #include +#include #include #include #include @@ -62,7 +64,7 @@ static uint8_t GENUINE_FLASH_MEDIA_SERVER[] = { inline void rtmp_random_generate(uint8_t* bytes, int size) { for (int i = 0; i < size; i++) { // the common value in [0x0f, 0xf0] - bytes[i] = 0x0f + (random() % (256 - 0x0f - 0x0f)); + bytes[i] = 0x0f + (rand() % (256 - 0x0f - 0x0f)); } } diff --git a/src/net/rtprtcp/rtcp_fb_pub.hpp b/src/net/rtprtcp/rtcp_fb_pub.hpp index f714425..414d595 100644 --- a/src/net/rtprtcp/rtcp_fb_pub.hpp +++ b/src/net/rtprtcp/rtcp_fb_pub.hpp @@ -4,9 +4,12 @@ #include #include #include - #include +#ifdef WIN32 +#include +#else #include // htonl(), htons(), ntohl(), ntohs() +#endif /* 0 1 2 3 diff --git a/src/net/rtprtcp/rtcp_pspli.hpp b/src/net/rtprtcp/rtcp_pspli.hpp index a677d37..6192570 100644 --- a/src/net/rtprtcp/rtcp_pspli.hpp +++ b/src/net/rtprtcp/rtcp_pspli.hpp @@ -9,7 +9,6 @@ #include #include #include -#include #include class rtcp_pspli diff --git a/src/net/rtprtcp/rtcp_rr.hpp b/src/net/rtprtcp/rtcp_rr.hpp index a4caf53..7b69e66 100644 --- a/src/net/rtprtcp/rtcp_rr.hpp +++ b/src/net/rtprtcp/rtcp_rr.hpp @@ -8,7 +8,6 @@ #include #include #include -#include #include /* diff --git a/src/net/rtprtcp/rtcp_sr.hpp b/src/net/rtprtcp/rtcp_sr.hpp index a7030bb..b70e311 100644 --- a/src/net/rtprtcp/rtcp_sr.hpp +++ b/src/net/rtprtcp/rtcp_sr.hpp @@ -6,7 +6,6 @@ #include #include #include -#include #include /* diff --git a/src/net/rtprtcp/rtcp_xr_dlrr.hpp b/src/net/rtprtcp/rtcp_xr_dlrr.hpp index f0fc4a8..3ae25a1 100644 --- a/src/net/rtprtcp/rtcp_xr_dlrr.hpp +++ b/src/net/rtprtcp/rtcp_xr_dlrr.hpp @@ -4,7 +4,6 @@ #include #include #include -#include #include #include "rtprtcp_pub.hpp" diff --git a/src/net/rtprtcp/rtcp_xr_rrt.hpp b/src/net/rtprtcp/rtcp_xr_rrt.hpp index 293504c..78d80d3 100644 --- a/src/net/rtprtcp/rtcp_xr_rrt.hpp +++ b/src/net/rtprtcp/rtcp_xr_rrt.hpp @@ -5,7 +5,6 @@ #include #include #include -#include #include "rtprtcp_pub.hpp" /* diff --git a/src/net/rtprtcp/rtcpfb_nack.hpp b/src/net/rtprtcp/rtcpfb_nack.hpp index 284246b..5b0535e 100644 --- a/src/net/rtprtcp/rtcpfb_nack.hpp +++ b/src/net/rtprtcp/rtcpfb_nack.hpp @@ -7,7 +7,6 @@ #include #include #include -#include // htonl(), htons(), ntohl(), ntohs() #include /* diff --git a/src/net/rtprtcp/rtp_packet.cpp b/src/net/rtprtcp/rtp_packet.cpp index a17cf3d..d51bff6 100644 --- a/src/net/rtprtcp/rtp_packet.cpp +++ b/src/net/rtprtcp/rtp_packet.cpp @@ -3,7 +3,6 @@ #include "logger.hpp" #include "timeex.hpp" #include "byte_stream.hpp" -#include #include #include #include diff --git a/src/net/rtprtcp/rtp_packet.hpp b/src/net/rtprtcp/rtp_packet.hpp index a83d0fe..3a0a844 100644 --- a/src/net/rtprtcp/rtp_packet.hpp +++ b/src/net/rtprtcp/rtp_packet.hpp @@ -4,7 +4,6 @@ #include #include #include -#include #include #define RTP_SEQ_MOD (1<<16) diff --git a/src/net/rtprtcp/rtprtcp_pub.hpp b/src/net/rtprtcp/rtprtcp_pub.hpp index dfb46e2..62020a2 100644 --- a/src/net/rtprtcp/rtprtcp_pub.hpp +++ b/src/net/rtprtcp/rtprtcp_pub.hpp @@ -5,7 +5,11 @@ #include #include #include +#ifdef WIN32 +#include +#else #include // htonl(), htons(), ntohl(), ntohs() +#endif #define RTP_PACKET_MAX_SIZE 1500 #define RTP_PAYLOAD_MAX_SIZE 1200 diff --git a/src/net/stun/stun_packet.hpp b/src/net/stun/stun_packet.hpp index dd526e9..6cb3bf9 100644 --- a/src/net/stun/stun_packet.hpp +++ b/src/net/stun/stun_packet.hpp @@ -3,9 +3,7 @@ #include #include #include -#include // htonl(), htons(), ntohl(), ntohs() -#include // sockaddr_in, sockaddr_in6 -#include // struct sockaddr, struct sockaddr_storage, AF_INET, AF_INET6 +#include "ipaddress.hpp" #define STUN_HEADER_SIZE 20 diff --git a/src/net/webrtc/room_service.cpp b/src/net/webrtc/room_service.cpp index c3f6d10..edfeea7 100644 --- a/src/net/webrtc/room_service.cpp +++ b/src/net/webrtc/room_service.cpp @@ -39,6 +39,18 @@ static uint32_t make_live_audio_ssrc() { return ssrc; } +static CANDIDATE_INFO make_candidate(std::shared_ptr session_ptr){ + CANDIDATE_INFO candidate_data; + candidate_data.foundation = "0"; + candidate_data.component = 1; + candidate_data.transport = "udp"; + candidate_data.priority = 2113667327; + candidate_data.ip = session_ptr->get_candidates_ip(); + candidate_data.port = session_ptr->get_candidates_port(); + candidate_data.type = "host"; + return candidate_data; +} + std::shared_ptr GetorCreate_room_service(const std::string& roomId) { auto iter = s_rooms.find(roomId); if (iter != s_rooms.end()) { @@ -770,17 +782,7 @@ void room_service::handle_publish(const std::string& id, const std::string& meth finger_print_info fingerprint = session_ptr->get_local_finger_print(info.finger_print.type); support_info.finger_print.hash = fingerprint.value; - CANDIDATE_INFO candidate_data = { - .foundation = "0", - .component = 1, - .transport = "udp", - .priority = 2113667327, - .ip = session_ptr->get_candidates_ip(), - .port = session_ptr->get_candidates_port(), - .type = "host" - }; - - support_info.candidates.push_back(candidate_data); + support_info.candidates.push_back(make_candidate(session_ptr)); /********* suppot publish rtc information is ready ************/ std::string resp_sdp_str = user_ptr->rtc_media_info_2_sdp(support_info); @@ -1135,17 +1137,8 @@ void room_service::handle_live_subscribe(const std::string& id, finger_print_info fingerprint = session_ptr->get_local_finger_print(info.finger_print.type); support_info.finger_print.hash = fingerprint.value; - CANDIDATE_INFO candidate_data = { - .foundation = "0", - .component = 1, - .transport = "udp", - .priority = 2113667327, - .ip = session_ptr->get_candidates_ip(), - .port = session_ptr->get_candidates_port(), - .type = "host" - }; - - support_info.candidates.push_back(candidate_data); + + support_info.candidates.push_back(make_candidate(session_ptr)); //log_infof("get live subscribe support media info:\r\n%s", support_info.dump().c_str()); std::string resp_sdp_str = user_ptr->rtc_media_info_2_sdp(support_info); @@ -1290,17 +1283,7 @@ void room_service::handle_webrtc_subscribe(const std::string& id, finger_print_info fingerprint = session_ptr->get_local_finger_print(info.finger_print.type); support_info.finger_print.hash = fingerprint.value; - CANDIDATE_INFO candidate_data = { - .foundation = "0", - .component = 1, - .transport = "udp", - .priority = 2113667327, - .ip = session_ptr->get_candidates_ip(), - .port = session_ptr->get_candidates_port(), - .type = "host" - }; - - support_info.candidates.push_back(candidate_data); + support_info.candidates.push_back(make_candidate(session_ptr)); //log_infof("get subscribe support media info:\r\n%s", support_info.dump().c_str()); std::string resp_sdp_str = user_ptr->rtc_media_info_2_sdp(support_info); @@ -1373,17 +1356,7 @@ int room_service::handle_http_publish(const std::string& uid, const std::string& finger_print_info fingerprint = session_ptr->get_local_finger_print(info.finger_print.type); support_info.finger_print.hash = fingerprint.value; - CANDIDATE_INFO candidate_data = { - .foundation = "0", - .component = 1, - .transport = "udp", - .priority = 2113667327, - .ip = session_ptr->get_candidates_ip(), - .port = session_ptr->get_candidates_port(), - .type = "host" - }; - - support_info.candidates.push_back(candidate_data); + support_info.candidates.push_back(make_candidate(session_ptr)); /********* suppot publish rtc information is ready ************/ resp_sdp = user_ptr->rtc_media_info_2_sdp(support_info); @@ -1558,17 +1531,7 @@ int room_service::handle_http_webrtc_subscribe(std::shared_ptr user_p finger_print_info fingerprint = session_ptr->get_local_finger_print(info.finger_print.type); support_info.finger_print.hash = fingerprint.value; - CANDIDATE_INFO candidate_data = { - .foundation = "0", - .component = 1, - .transport = "udp", - .priority = 2113667327, - .ip = session_ptr->get_candidates_ip(), - .port = session_ptr->get_candidates_port(), - .type = "host" - }; - - support_info.candidates.push_back(candidate_data); + support_info.candidates.push_back(make_candidate(session_ptr)); //log_infof("http subscribe support media info:\r\n%s", support_info.dump().c_str()); resp_sdp = user_ptr->rtc_media_info_2_sdp(support_info); @@ -1722,17 +1685,7 @@ int room_service::handle_http_live_subscribe(std::shared_ptr user_ptr finger_print_info fingerprint = session_ptr->get_local_finger_print(info.finger_print.type); support_info.finger_print.hash = fingerprint.value; - CANDIDATE_INFO candidate_data = { - .foundation = "0", - .component = 1, - .transport = "udp", - .priority = 2113667327, - .ip = session_ptr->get_candidates_ip(), - .port = session_ptr->get_candidates_port(), - .type = "host" - }; - - support_info.candidates.push_back(candidate_data); + support_info.candidates.push_back(make_candidate(session_ptr)); //log_infof("get live subscribe support media info:\r\n%s", support_info.dump().c_str()); resp_sdp = user_ptr->rtc_media_info_2_sdp(support_info); diff --git a/src/net/webrtc/srtp_session.cpp b/src/net/webrtc/srtp_session.cpp index e135b5c..8b43066 100644 --- a/src/net/webrtc/srtp_session.cpp +++ b/src/net/webrtc/srtp_session.cpp @@ -2,7 +2,11 @@ #include "logger.hpp" #include #include +#ifdef WIN32 +#include +#else #include +#endif std::vector srtp_session::errors = { diff --git a/src/net/webrtc/support_rtc_info.cpp b/src/net/webrtc/support_rtc_info.cpp index a3d1c4f..7bf251d 100644 --- a/src/net/webrtc/support_rtc_info.cpp +++ b/src/net/webrtc/support_rtc_info.cpp @@ -7,111 +7,38 @@ #include static RTCP_FB support_rtcp_fb_list[] = { - { - .payload = 0, - .type = "goog-remb", - .subtype = "" - }, - { - .payload = 0, - .type = "nack", - .subtype = "" - }, - { - .payload = 0, - .type = "rrtr", - .subtype = "" - }, - { - .payload = 0, - .type = "nack", - .subtype = "pli" - }, + {0,"goog-remb",""}, + {0,"nack",""}, + {0,"rrtr",""}, + {0,"nack","pli"}, }; static HEADER_EXT support_header_ext_list[] = { - { - .uri = "urn:ietf:params:rtp-hdrext:sdes:mid", - .value = 0 - }, - { - .uri = "http://www.webrtc.org/experiments/rtp-hdrext/abs-send-time", - .value = 0 - } + {"urn:ietf:params:rtp-hdrext:sdes:mid", 0}, + {"http://www.webrtc.org/experiments/rtp-hdrext/abs-send-time",0} }; static RTP_ENCODING support_rtp_encoding_list[] = { - { - .codec = "VP8", - .payload = 0, - .clock_rate = 90000, - .media_type = MEDIA_VIDEO_TYPE - }, - { - .codec = "H264", - .payload = 0, - .clock_rate = 90000, - .media_type = MEDIA_VIDEO_TYPE - }, - { - .codec = "rtx", - .payload = 0, - .clock_rate = 90000, - .media_type = MEDIA_UNKOWN_TYPE - }, - { - .codec = "opus", - .payload = 0, - .clock_rate = 48000, - .media_type = MEDIA_AUDIO_TYPE - } + {"VP8", 0, 90000, "", MEDIA_VIDEO_TYPE}, + {"H264", 0, 90000, "", MEDIA_VIDEO_TYPE}, + {"rtx", 0, 90000, "", MEDIA_UNKOWN_TYPE}, + {"opus", 0, 48000, "", MEDIA_AUDIO_TYPE} }; static SSRC_INFO support_ssrc_info_list[] = { - { - .attribute = "cname", - .value = "", - .ssrc = 0 - } + {"cname","",0} }; static FMTP support_fmtp_list[] = { - { - .config = "useinbandfec=1", - .payload = 0 - }, - { - .config = "apt=", - .payload = 0 - }, - { - .config = "x-google-start-bitrate", - .payload = 0 - }, - { - .config = "profile-level-id=42e01f;level-asymmetry-allowed=1;packetization-mode=1", - .payload = 0 - }, - { - .config = "profile-level-id=42e01f;packetization-mode=1;level-asymmetry-allowed=1", - .payload = 0 - }, - { - .config = "level-asymmetry-allowed=1;packetization-mode=1;profile-level-id=42e01f", - .payload = 0 - }, - { - .config = "level-asymmetry-allowed=1;profile-level-id=42e01f;packetization-mode=1", - .payload = 0 - }, - { - .config = "packetization-mode=1;level-asymmetry-allowed=1;profile-level-id=42e01f", - .payload = 0 - }, - { - .config = "packetization-mode=1;profile-level-id=42e01f;level-asymmetry-allowed=1", - .payload = 0 - } + {"useinbandfec=1",0}, + {"apt=", 0}, + {"x-google-start-bitrate", 0}, + {"profile-level-id=42e01f;level-asymmetry-allowed=1;packetization-mode=1", 0}, + {"profile-level-id=42e01f;packetization-mode=1;level-asymmetry-allowed=1", 0}, + {"level-asymmetry-allowed=1;packetization-mode=1;profile-level-id=42e01f", 0}, + {"level-asymmetry-allowed=1;profile-level-id=42e01f;packetization-mode=1", 0}, + {"packetization-mode=1;level-asymmetry-allowed=1;profile-level-id=42e01f", 0}, + {"packetization-mode=1;profile-level-id=42e01f;level-asymmetry-allowed=1", 0} }; static int get_apt_payload(const std::string& apt) { diff --git a/src/net/webrtc/user_info.cpp b/src/net/webrtc/user_info.cpp index e4beb63..0453468 100644 --- a/src/net/webrtc/user_info.cpp +++ b/src/net/webrtc/user_info.cpp @@ -3,12 +3,14 @@ #include "utils/logger.hpp" #include "utils/timeex.hpp" #include "net/webrtc/rtp_h264_pack.hpp" -#include "transcode/transcode.hpp" #include "format/h264_header.hpp" #include "format/audio_pub.hpp" #include "media_stream_manager.hpp" #include #include +#ifdef ENABLE_FFMPEG +#include "transcode/transcode.hpp" +#endif static int64_t s_last_ts = 0; @@ -57,11 +59,13 @@ user_info::~user_info() { std::shared_ptr session_ptr = item.second; session_ptr->close_session(); } +#ifdef EANBLE_FFMPEG if (trans_) { trans_->stop(); delete trans_; trans_ = nullptr; } +#endif } void user_info::reset_media_info() { @@ -207,6 +211,7 @@ void user_info::on_rtmp_camera_callback(MEDIA_PACKET_PTR pkt_ptr) { return; } if (pkt_ptr->av_type_ == MEDIA_AUDIO_TYPE) { +#ifdef ENABLE_FFMPEG if (!trans_) { trans_ = new transcode(); trans_->set_output_audio_fmt("libfdk_aac"); @@ -236,6 +241,7 @@ void user_info::on_rtmp_camera_callback(MEDIA_PACKET_PTR pkt_ptr) { media_stream_manager::writer_media_packet(ret_pkt_ptr); //send_buffer(ret_pkt_ptr); } +#endif return; } @@ -274,11 +280,13 @@ live_user_info::live_user_info(const std::string& uid, live_user_info::~live_user_info() { +#ifdef ENABLE_FFMPEG if (trans_) { trans_->stop(); delete trans_; trans_ = nullptr; } +#endif } void live_user_info::updata_sps(uint8_t* sps, size_t sps_len) { @@ -425,7 +433,7 @@ int live_user_info::handle_audio_data(MEDIA_PACKET_PTR pkt_ptr) { publisher_id += "audio"; room_cb_->on_rtppacket_publisher2room(publisher_id, "audio", single_pkt); } - +#ifdef EANBLE_FFMPEG if (pkt_ptr->codec_type_ == MEDIA_CODEC_AAC) { MEDIA_PACKET_PTR raw_pkt_ptr = pkt_ptr->copy(); if (!trans_) { @@ -492,6 +500,7 @@ int live_user_info::handle_audio_data(MEDIA_PACKET_PTR pkt_ptr) { } } +#endif return 0; } diff --git a/src/net/websocket/wsimple/flv_websocket.cpp b/src/net/websocket/wsimple/flv_websocket.cpp index 34b916e..7b8d9d1 100644 --- a/src/net/websocket/wsimple/flv_websocket.cpp +++ b/src/net/websocket/wsimple/flv_websocket.cpp @@ -5,10 +5,12 @@ #include "logger.hpp" #include "utils/byte_stream.hpp" #include "format/flv/flv_demux.hpp" -#include "transcode/transcode.hpp" #include "net/websocket/ws_session.hpp" #include #include +#ifdef ENABLE_FFMPEG +#include "transcode/transcode.hpp" +#endif av_outputer::av_outputer() { @@ -20,17 +22,20 @@ av_outputer::~av_outputer() } void av_outputer::release() { +#ifdef ENABLE_FFMPEG if (trans_) { trans_->stop(); delete trans_; trans_ = nullptr; } +#endif } int av_outputer::output_packet(MEDIA_PACKET_PTR pkt_ptr) { int ret = 0; if ((pkt_ptr->av_type_ == MEDIA_AUDIO_TYPE) && (pkt_ptr->codec_type_ == MEDIA_CODEC_OPUS)) { +#ifdef ENABLE_FFMPEG if (trans_ == nullptr) { trans_ = new transcode(); trans_->set_output_audio_fmt("libfdk_aac"); @@ -56,6 +61,7 @@ int av_outputer::output_packet(MEDIA_PACKET_PTR pkt_ptr) { ret_pkt_ptr->streamname_ = pkt_ptr->streamname_; ret = media_stream_manager::writer_media_packet(ret_pkt_ptr); } +#endif } else { ret = flv_muxer::add_flv_media_header(pkt_ptr); if (ret < 0) { diff --git a/src/transcode/encode.cpp b/src/transcode/encode.cpp index efe1cba..81651ba 100644 --- a/src/transcode/encode.cpp +++ b/src/transcode/encode.cpp @@ -267,7 +267,7 @@ int audio_encode::send_frame(AVFrame* frame) { audio_pkt_p->pts = (audio_pkt_p->pts < 0) ? 0 :audio_pkt_p->pts; audio_pkt_p->dts = (audio_pkt_p->dts < 0) ? 0 :audio_pkt_p->dts; - av_packet_rescale_ts(audio_pkt_p, codec_ctx_->time_base, AV_TIME_BASE_Q); + av_packet_rescale_ts(audio_pkt_p, codec_ctx_->time_base, { 1, AV_TIME_BASE }); audio_pkt_p->dts = audio_pkt_p->dts / 1000; audio_pkt_p->pts = audio_pkt_p->pts / 1000; if (audio_codec_type_ == MEDIA_CODEC_OPUS) { diff --git a/src/utils/config.cpp b/src/utils/config.cpp index a499279..b3d87d7 100644 --- a/src/utils/config.cpp +++ b/src/utils/config.cpp @@ -32,7 +32,7 @@ int Config::load(const std::string& conf_file) { std::cout << "read file error:" << n << "\r\n"; return -2; } - + buffer_[n] = 0; return init(buffer_, n); } diff --git a/src/utils/ipaddress.hpp b/src/utils/ipaddress.hpp index 0d53ded..485f97e 100644 --- a/src/utils/ipaddress.hpp +++ b/src/utils/ipaddress.hpp @@ -1,8 +1,16 @@ #ifndef IP_ADDRESS_HPP #define IP_ADDRESS_HPP + +#ifdef WIN32 +#include +#include +#include +#else #include // htonl(), htons(), ntohl(), ntohs() #include // sockaddr_in, sockaddr_in6 #include // struct sockaddr, struct sockaddr_storage, AF_INET, AF_INET6 +#endif + #include #include #include diff --git a/src/utils/timeex.hpp b/src/utils/timeex.hpp index 8ba83fb..9907774 100644 --- a/src/utils/timeex.hpp +++ b/src/utils/timeex.hpp @@ -4,7 +4,7 @@ #include #include #include - +#include #define NTP_FRACT_UNIT (1LL << 32) typedef struct NTP_TIMESTAMP_S