Commit 56d6eb0f by ziyue

批量替换tab为4个空格

parent a5c3db4e
...@@ -269,9 +269,9 @@ API_EXPORT int API_CALL mk_media_input_aac(mk_media ctx, const void *data, int l ...@@ -269,9 +269,9 @@ API_EXPORT int API_CALL mk_media_input_aac(mk_media ctx, const void *data, int l
} }
API_EXPORT int API_CALL mk_media_input_pcm(mk_media ctx, void *data , int len, uint64_t pts){ API_EXPORT int API_CALL mk_media_input_pcm(mk_media ctx, void *data , int len, uint64_t pts){
assert(ctx && data && len > 0); assert(ctx && data && len > 0);
MediaHelper::Ptr* obj = (MediaHelper::Ptr*) ctx; MediaHelper::Ptr* obj = (MediaHelper::Ptr*) ctx;
return (*obj)->getChannel()->inputPCM((char*)data, len, pts); return (*obj)->getChannel()->inputPCM((char*)data, len, pts);
} }
API_EXPORT int API_CALL mk_media_input_audio(mk_media ctx, const void* data, int len, uint64_t dts){ API_EXPORT int API_CALL mk_media_input_audio(mk_media ctx, const void* data, int len, uint64_t dts){
......
...@@ -30,109 +30,109 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. ...@@ -30,109 +30,109 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
namespace RTC namespace RTC
{ {
using TransportTuple = toolkit::Session; using TransportTuple = toolkit::Session;
class IceServer class IceServer
{ {
public: public:
enum class IceState enum class IceState
{ {
NEW = 1, NEW = 1,
CONNECTED, CONNECTED,
COMPLETED, COMPLETED,
DISCONNECTED DISCONNECTED
}; };
public: public:
class Listener class Listener
{ {
public: public:
virtual ~Listener() = default; virtual ~Listener() = default;
public: public:
/** /**
* These callbacks are guaranteed to be called before ProcessStunPacket() * These callbacks are guaranteed to be called before ProcessStunPacket()
* returns, so the given pointers are still usable. * returns, so the given pointers are still usable.
*/ */
virtual void OnIceServerSendStunPacket( virtual void OnIceServerSendStunPacket(
const RTC::IceServer* iceServer, const RTC::StunPacket* packet, RTC::TransportTuple* tuple) = 0; const RTC::IceServer* iceServer, const RTC::StunPacket* packet, RTC::TransportTuple* tuple) = 0;
virtual void OnIceServerSelectedTuple( virtual void OnIceServerSelectedTuple(
const RTC::IceServer* iceServer, RTC::TransportTuple* tuple) = 0; const RTC::IceServer* iceServer, RTC::TransportTuple* tuple) = 0;
virtual void OnIceServerConnected(const RTC::IceServer* iceServer) = 0; virtual void OnIceServerConnected(const RTC::IceServer* iceServer) = 0;
virtual void OnIceServerCompleted(const RTC::IceServer* iceServer) = 0; virtual void OnIceServerCompleted(const RTC::IceServer* iceServer) = 0;
virtual void OnIceServerDisconnected(const RTC::IceServer* iceServer) = 0; virtual void OnIceServerDisconnected(const RTC::IceServer* iceServer) = 0;
}; };
public: public:
IceServer(Listener* listener, const std::string& usernameFragment, const std::string& password); IceServer(Listener* listener, const std::string& usernameFragment, const std::string& password);
public: public:
void ProcessStunPacket(RTC::StunPacket* packet, RTC::TransportTuple* tuple); void ProcessStunPacket(RTC::StunPacket* packet, RTC::TransportTuple* tuple);
const std::string& GetUsernameFragment() const const std::string& GetUsernameFragment() const
{ {
return this->usernameFragment; return this->usernameFragment;
} }
const std::string& GetPassword() const const std::string& GetPassword() const
{ {
return this->password; return this->password;
} }
IceState GetState() const IceState GetState() const
{ {
return this->state; return this->state;
} }
RTC::TransportTuple* GetSelectedTuple(bool try_last_tuple = false) const RTC::TransportTuple* GetSelectedTuple(bool try_last_tuple = false) const
{ {
return try_last_tuple ? this->lastSelectedTuple.lock().get() : this->selectedTuple; return try_last_tuple ? this->lastSelectedTuple.lock().get() : this->selectedTuple;
} }
void SetUsernameFragment(const std::string& usernameFragment) void SetUsernameFragment(const std::string& usernameFragment)
{ {
this->oldUsernameFragment = this->usernameFragment; this->oldUsernameFragment = this->usernameFragment;
this->usernameFragment = usernameFragment; this->usernameFragment = usernameFragment;
} }
void SetPassword(const std::string& password) void SetPassword(const std::string& password)
{ {
this->oldPassword = this->password; this->oldPassword = this->password;
this->password = password; this->password = password;
} }
bool IsValidTuple(const RTC::TransportTuple* tuple) const; bool IsValidTuple(const RTC::TransportTuple* tuple) const;
void RemoveTuple(RTC::TransportTuple* tuple); void RemoveTuple(RTC::TransportTuple* tuple);
// This should be just called in 'connected' or completed' state // This should be just called in 'connected' or completed' state
// and the given tuple must be an already valid tuple. // and the given tuple must be an already valid tuple.
void ForceSelectedTuple(const RTC::TransportTuple* tuple); void ForceSelectedTuple(const RTC::TransportTuple* tuple);
const std::list<RTC::TransportTuple *>& GetTuples() const { return tuples; } const std::list<RTC::TransportTuple *>& GetTuples() const { return tuples; }
private: private:
void HandleTuple(RTC::TransportTuple* tuple, bool hasUseCandidate); void HandleTuple(RTC::TransportTuple* tuple, bool hasUseCandidate);
/** /**
* Store the given tuple and return its stored address. * Store the given tuple and return its stored address.
*/ */
RTC::TransportTuple* AddTuple(RTC::TransportTuple* tuple); RTC::TransportTuple* AddTuple(RTC::TransportTuple* tuple);
/** /**
* If the given tuple exists return its stored address, nullptr otherwise. * If the given tuple exists return its stored address, nullptr otherwise.
*/ */
RTC::TransportTuple* HasTuple(const RTC::TransportTuple* tuple) const; RTC::TransportTuple* HasTuple(const RTC::TransportTuple* tuple) const;
/** /**
* Set the given tuple as the selected tuple. * Set the given tuple as the selected tuple.
* NOTE: The given tuple MUST be already stored within the list. * NOTE: The given tuple MUST be already stored within the list.
*/ */
void SetSelectedTuple(RTC::TransportTuple* storedTuple); void SetSelectedTuple(RTC::TransportTuple* storedTuple);
private: private:
// Passed by argument. // Passed by argument.
Listener* listener{ nullptr }; Listener* listener{ nullptr };
// Others. // Others.
std::string usernameFragment; std::string usernameFragment;
std::string password; std::string password;
std::string oldUsernameFragment; std::string oldUsernameFragment;
std::string oldPassword; std::string oldPassword;
IceState state{ IceState::NEW }; IceState state{ IceState::NEW };
std::list<RTC::TransportTuple *> tuples; std::list<RTC::TransportTuple *> tuples;
RTC::TransportTuple *selectedTuple; RTC::TransportTuple *selectedTuple;
std::weak_ptr<RTC::TransportTuple> lastSelectedTuple; std::weak_ptr<RTC::TransportTuple> lastSelectedTuple;
//最大不超过mtu //最大不超过mtu
static constexpr size_t StunSerializeBufferSize{ 1600 }; static constexpr size_t StunSerializeBufferSize{ 1600 };
uint8_t StunSerializeBuffer[StunSerializeBufferSize]; uint8_t StunSerializeBuffer[StunSerializeBufferSize];
}; };
} // namespace RTC } // namespace RTC
#endif #endif
...@@ -18,104 +18,104 @@ namespace RTC ...@@ -18,104 +18,104 @@ namespace RTC
uint16_t maxRetransmits{ 0u }; uint16_t maxRetransmits{ 0u };
}; };
class SctpAssociation class SctpAssociation
{ {
public: public:
enum class SctpState enum class SctpState
{ {
NEW = 1, NEW = 1,
CONNECTING, CONNECTING,
CONNECTED, CONNECTED,
FAILED, FAILED,
CLOSED CLOSED
}; };
private: private:
enum class StreamDirection enum class StreamDirection
{ {
INCOMING = 1, INCOMING = 1,
OUTGOING OUTGOING
}; };
public: public:
class Listener class Listener
{ {
public: public:
virtual void OnSctpAssociationConnecting(RTC::SctpAssociation* sctpAssociation) = 0; virtual void OnSctpAssociationConnecting(RTC::SctpAssociation* sctpAssociation) = 0;
virtual void OnSctpAssociationConnected(RTC::SctpAssociation* sctpAssociation) = 0; virtual void OnSctpAssociationConnected(RTC::SctpAssociation* sctpAssociation) = 0;
virtual void OnSctpAssociationFailed(RTC::SctpAssociation* sctpAssociation) = 0; virtual void OnSctpAssociationFailed(RTC::SctpAssociation* sctpAssociation) = 0;
virtual void OnSctpAssociationClosed(RTC::SctpAssociation* sctpAssociation) = 0; virtual void OnSctpAssociationClosed(RTC::SctpAssociation* sctpAssociation) = 0;
virtual void OnSctpAssociationSendData( virtual void OnSctpAssociationSendData(
RTC::SctpAssociation* sctpAssociation, const uint8_t* data, size_t len) = 0; RTC::SctpAssociation* sctpAssociation, const uint8_t* data, size_t len) = 0;
virtual void OnSctpAssociationMessageReceived( virtual void OnSctpAssociationMessageReceived(
RTC::SctpAssociation* sctpAssociation, RTC::SctpAssociation* sctpAssociation,
uint16_t streamId, uint16_t streamId,
uint32_t ppid, uint32_t ppid,
const uint8_t* msg, const uint8_t* msg,
size_t len) = 0; size_t len) = 0;
}; };
public: public:
static bool IsSctp(const uint8_t* data, size_t len) static bool IsSctp(const uint8_t* data, size_t len)
{ {
// clang-format off // clang-format off
return ( return (
(len >= 12) && (len >= 12) &&
// Must have Source Port Number and Destination Port Number set to 5000 (hack). // Must have Source Port Number and Destination Port Number set to 5000 (hack).
(Utils::Byte::Get2Bytes(data, 0) == 5000) && (Utils::Byte::Get2Bytes(data, 0) == 5000) &&
(Utils::Byte::Get2Bytes(data, 2) == 5000) (Utils::Byte::Get2Bytes(data, 2) == 5000)
); );
// clang-format on // clang-format on
} }
public: public:
SctpAssociation( SctpAssociation(
Listener* listener, uint16_t os, uint16_t mis, size_t maxSctpMessageSize, bool isDataChannel); Listener* listener, uint16_t os, uint16_t mis, size_t maxSctpMessageSize, bool isDataChannel);
virtual ~SctpAssociation(); virtual ~SctpAssociation();
public: public:
void TransportConnected(); void TransportConnected();
size_t GetMaxSctpMessageSize() const size_t GetMaxSctpMessageSize() const
{ {
return this->maxSctpMessageSize; return this->maxSctpMessageSize;
} }
SctpState GetState() const SctpState GetState() const
{ {
return this->state; return this->state;
} }
void ProcessSctpData(const uint8_t* data, size_t len); void ProcessSctpData(const uint8_t* data, size_t len);
void SendSctpMessage(const RTC::SctpStreamParameters &params, uint32_t ppid, const uint8_t* msg, size_t len); void SendSctpMessage(const RTC::SctpStreamParameters &params, uint32_t ppid, const uint8_t* msg, size_t len);
void HandleDataConsumer(const RTC::SctpStreamParameters &params); void HandleDataConsumer(const RTC::SctpStreamParameters &params);
void DataProducerClosed(const RTC::SctpStreamParameters &params); void DataProducerClosed(const RTC::SctpStreamParameters &params);
void DataConsumerClosed(const RTC::SctpStreamParameters &params); void DataConsumerClosed(const RTC::SctpStreamParameters &params);
private: private:
void ResetSctpStream(uint16_t streamId, StreamDirection); void ResetSctpStream(uint16_t streamId, StreamDirection);
void AddOutgoingStreams(bool force = false); void AddOutgoingStreams(bool force = false);
public: public:
/* Callbacks fired by usrsctp events. */ /* Callbacks fired by usrsctp events. */
virtual void OnUsrSctpSendSctpData(void* buffer, size_t len); virtual void OnUsrSctpSendSctpData(void* buffer, size_t len);
virtual void OnUsrSctpReceiveSctpData(uint16_t streamId, uint16_t ssn, uint32_t ppid, int flags, const uint8_t* data, size_t len); virtual void OnUsrSctpReceiveSctpData(uint16_t streamId, uint16_t ssn, uint32_t ppid, int flags, const uint8_t* data, size_t len);
virtual void OnUsrSctpReceiveSctpNotification(union sctp_notification* notification, size_t len); virtual void OnUsrSctpReceiveSctpNotification(union sctp_notification* notification, size_t len);
private: private:
// Passed by argument. // Passed by argument.
Listener* listener{ nullptr }; Listener* listener{ nullptr };
uint16_t os{ 1024u }; uint16_t os{ 1024u };
uint16_t mis{ 1024u }; uint16_t mis{ 1024u };
size_t maxSctpMessageSize{ 262144u }; size_t maxSctpMessageSize{ 262144u };
bool isDataChannel{ false }; bool isDataChannel{ false };
// Allocated by this. // Allocated by this.
uint8_t* messageBuffer{ nullptr }; uint8_t* messageBuffer{ nullptr };
// Others. // Others.
SctpState state{ SctpState::NEW }; SctpState state{ SctpState::NEW };
struct socket* socket{ nullptr }; struct socket* socket{ nullptr };
uint16_t desiredOs{ 0u }; uint16_t desiredOs{ 0u };
size_t messageBufferLen{ 0u }; size_t messageBufferLen{ 0u };
uint16_t lastSsnReceived{ 0u }; // Valid for us since no SCTP I-DATA support. uint16_t lastSsnReceived{ 0u }; // Valid for us since no SCTP I-DATA support.
std::shared_ptr<SctpEnv> _env; std::shared_ptr<SctpEnv> _env;
}; };
//保证线程安全 //保证线程安全
class SctpAssociationImp : public SctpAssociation, public std::enable_shared_from_this<SctpAssociationImp>{ class SctpAssociationImp : public SctpAssociation, public std::enable_shared_from_this<SctpAssociationImp>{
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论