Skip to content

Commit

Permalink
修复windows编译错误
Browse files Browse the repository at this point in the history
  • Loading branch information
mtdxc committed Jul 5, 2022
1 parent eff64d1 commit d2081c3
Show file tree
Hide file tree
Showing 23 changed files with 94 additions and 182 deletions.
10 changes: 8 additions & 2 deletions src/media_server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@
#include <stdint.h>
#include <stddef.h>
#include <iostream>
#ifndef WIN32
#include <unistd.h>
#endif

uv_loop_t* MediaServer::loop_ = uv_default_loop();
uv_loop_t* MediaServer::hls_loop_ = uv_loop_new();
Expand Down Expand Up @@ -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) {
Expand All @@ -259,7 +265,7 @@ int main(int argn, char** argv) {
return -1;
}
}

#endif
MediaServer::Run(cfg_file);

return 0;
Expand Down
4 changes: 2 additions & 2 deletions src/net/rtmp/rtmp_handshake.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down
4 changes: 3 additions & 1 deletion src/net/rtmp/rtmp_handshake.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#ifndef RTMP_HANDSHAKE_HPP
#define RTMP_HANDSHAKE_HPP

#include "rtmp_pub.hpp"
#include "logger.hpp"
#include "byte_stream.hpp"
Expand All @@ -10,6 +11,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
#include <openssl/ssl.h>
#include <openssl/evp.h>
#include <openssl/hmac.h>
#include <openssl/dh.h>
Expand Down Expand Up @@ -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));
}
}

Expand Down
5 changes: 4 additions & 1 deletion src/net/rtprtcp/rtcp_fb_pub.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,12 @@
#include <stddef.h>
#include <string>
#include <cstring>

#include <stdio.h>
#ifdef WIN32
#include <WinSock2.h>
#else
#include <arpa/inet.h> // htonl(), htons(), ntohl(), ntohs()
#endif

/*
0 1 2 3
Expand Down
1 change: 0 additions & 1 deletion src/net/rtprtcp/rtcp_pspli.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
#include <stddef.h>
#include <string>
#include <cstring>
#include <arpa/inet.h>
#include <sstream>

class rtcp_pspli
Expand Down
1 change: 0 additions & 1 deletion src/net/rtprtcp/rtcp_rr.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
#include <stddef.h>
#include <string>
#include <cstring>
#include <arpa/inet.h>
#include <sstream>

/*
Expand Down
1 change: 0 additions & 1 deletion src/net/rtprtcp/rtcp_sr.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
#include <stddef.h>
#include <string>
#include <cstring>
#include <arpa/inet.h>
#include <sstream>

/*
Expand Down
1 change: 0 additions & 1 deletion src/net/rtprtcp/rtcp_xr_dlrr.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
#include <stddef.h>
#include <string>
#include <string.h>
#include <arpa/inet.h>
#include <vector>
#include "rtprtcp_pub.hpp"

Expand Down
1 change: 0 additions & 1 deletion src/net/rtprtcp/rtcp_xr_rrt.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
#include <string>
#include <string.h>
#include <assert.h>
#include <arpa/inet.h>
#include "rtprtcp_pub.hpp"

/*
Expand Down
1 change: 0 additions & 1 deletion src/net/rtprtcp/rtcpfb_nack.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
#include <cstring>
#include <sstream>
#include <stdio.h>
#include <arpa/inet.h> // htonl(), htons(), ntohl(), ntohs()
#include <vector>

/*
Expand Down
1 change: 0 additions & 1 deletion src/net/rtprtcp/rtp_packet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
#include "logger.hpp"
#include "timeex.hpp"
#include "byte_stream.hpp"
#include <arpa/inet.h>
#include <sstream>
#include <cstring>
#include <assert.h>
Expand Down
1 change: 0 additions & 1 deletion src/net/rtprtcp/rtp_packet.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
#include <stdint.h>
#include <stddef.h>
#include <string>
#include <arpa/inet.h>
#include <map>

#define RTP_SEQ_MOD (1<<16)
Expand Down
4 changes: 4 additions & 0 deletions src/net/rtprtcp/rtprtcp_pub.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@
#include <stddef.h>
#include <string>
#include <sstream>
#ifdef WIN32
#include <WinSock2.h>
#else
#include <arpa/inet.h> // htonl(), htons(), ntohl(), ntohs()
#endif

#define RTP_PACKET_MAX_SIZE 1500
#define RTP_PAYLOAD_MAX_SIZE 1200
Expand Down
4 changes: 1 addition & 3 deletions src/net/stun/stun_packet.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@
#include <string>
#include <stdint.h>
#include <stddef.h>
#include <arpa/inet.h> // htonl(), htons(), ntohl(), ntohs()
#include <netinet/in.h> // sockaddr_in, sockaddr_in6
#include <sys/socket.h> // struct sockaddr, struct sockaddr_storage, AF_INET, AF_INET6
#include "ipaddress.hpp"

#define STUN_HEADER_SIZE 20

Expand Down
85 changes: 19 additions & 66 deletions src/net/webrtc/room_service.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,18 @@ static uint32_t make_live_audio_ssrc() {
return ssrc;
}

static CANDIDATE_INFO make_candidate(std::shared_ptr<webrtc_session> 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<room_service> GetorCreate_room_service(const std::string& roomId) {
auto iter = s_rooms.find(roomId);
if (iter != s_rooms.end()) {
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -1558,17 +1531,7 @@ int room_service::handle_http_webrtc_subscribe(std::shared_ptr<user_info> 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);
Expand Down Expand Up @@ -1722,17 +1685,7 @@ int room_service::handle_http_live_subscribe(std::shared_ptr<user_info> 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);
Expand Down
4 changes: 4 additions & 0 deletions src/net/webrtc/srtp_session.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@
#include "logger.hpp"
#include <vector>
#include <cstring>
#ifdef WIN32
#include <WinSock2.h>
#else
#include <netinet/in.h>
#endif

std::vector<const char*> srtp_session::errors =
{
Expand Down
Loading

0 comments on commit d2081c3

Please sign in to comment.