mirror of
https://github.com/ossrs/srs.git
synced 2025-03-09 15:49:59 +00:00
rename base message to ISrsMessage
This commit is contained in:
parent
d8a99dde52
commit
52a454c41b
2 changed files with 41 additions and 16 deletions
|
@ -320,12 +320,12 @@ int SrsProtocol::recv_message(SrsCommonMessage** pmsg)
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
int SrsProtocol::send_message(SrsOutputableMessage* msg)
|
int SrsProtocol::send_message(ISrsMessage* msg)
|
||||||
{
|
{
|
||||||
int ret = ERROR_SUCCESS;
|
int ret = ERROR_SUCCESS;
|
||||||
|
|
||||||
// free msg whatever return value.
|
// free msg whatever return value.
|
||||||
SrsAutoFree(SrsOutputableMessage, msg, false);
|
SrsAutoFree(ISrsMessage, msg, false);
|
||||||
|
|
||||||
if ((ret = msg->encode_packet()) != ERROR_SUCCESS) {
|
if ((ret = msg->encode_packet()) != ERROR_SUCCESS) {
|
||||||
srs_error("encode packet to message payload failed. ret=%d", ret);
|
srs_error("encode packet to message payload failed. ret=%d", ret);
|
||||||
|
@ -479,10 +479,15 @@ int SrsProtocol::on_recv_message(SrsCommonMessage* msg)
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
int SrsProtocol::on_send_message(SrsOutputableMessage* msg)
|
int SrsProtocol::on_send_message(ISrsMessage* msg)
|
||||||
{
|
{
|
||||||
int ret = ERROR_SUCCESS;
|
int ret = ERROR_SUCCESS;
|
||||||
|
|
||||||
|
if (!msg->can_decode()) {
|
||||||
|
srs_verbose("ignore the un-decodable message.");
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
SrsCommonMessage* common_msg = dynamic_cast<SrsCommonMessage*>(msg);
|
SrsCommonMessage* common_msg = dynamic_cast<SrsCommonMessage*>(msg);
|
||||||
if (!msg) {
|
if (!msg) {
|
||||||
srs_verbose("ignore the shared ptr message.");
|
srs_verbose("ignore the shared ptr message.");
|
||||||
|
@ -927,18 +932,18 @@ SrsChunkStream::~SrsChunkStream()
|
||||||
srs_freep(msg);
|
srs_freep(msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
SrsOutputableMessage::SrsOutputableMessage()
|
ISrsMessage::ISrsMessage()
|
||||||
{
|
{
|
||||||
payload = NULL;
|
payload = NULL;
|
||||||
size = 0;
|
size = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
SrsOutputableMessage::~SrsOutputableMessage()
|
ISrsMessage::~ISrsMessage()
|
||||||
{
|
{
|
||||||
free_payload();
|
free_payload();
|
||||||
}
|
}
|
||||||
|
|
||||||
void SrsOutputableMessage::free_payload()
|
void ISrsMessage::free_payload()
|
||||||
{
|
{
|
||||||
srs_freepa(payload);
|
srs_freepa(payload);
|
||||||
}
|
}
|
||||||
|
@ -955,6 +960,11 @@ SrsCommonMessage::~SrsCommonMessage()
|
||||||
srs_freep(stream);
|
srs_freep(stream);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool SrsCommonMessage::can_decode()
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
int SrsCommonMessage::decode_packet()
|
int SrsCommonMessage::decode_packet()
|
||||||
{
|
{
|
||||||
int ret = ERROR_SUCCESS;
|
int ret = ERROR_SUCCESS;
|
||||||
|
@ -1145,6 +1155,11 @@ void SrsSharedPtrMessage::free_payload()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool SrsSharedPtrMessage::can_decode()
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
int SrsSharedPtrMessage::initialize(SrsMessageHeader* header, char* payload, int size, int perfer_cid)
|
int SrsSharedPtrMessage::initialize(SrsMessageHeader* header, char* payload, int size, int perfer_cid)
|
||||||
{
|
{
|
||||||
int ret = ERROR_SUCCESS;
|
int ret = ERROR_SUCCESS;
|
||||||
|
|
|
@ -47,7 +47,7 @@ class SrsChunkStream;
|
||||||
class SrsAmf0Object;
|
class SrsAmf0Object;
|
||||||
class SrsAmf0Null;
|
class SrsAmf0Null;
|
||||||
class SrsAmf0Undefined;
|
class SrsAmf0Undefined;
|
||||||
class SrsOutputableMessage;
|
class ISrsMessage;
|
||||||
|
|
||||||
// convert class name to string.
|
// convert class name to string.
|
||||||
#define CLASS_NAME_STRING(className) #className
|
#define CLASS_NAME_STRING(className) #className
|
||||||
|
@ -112,7 +112,7 @@ public:
|
||||||
* then sendout over socket.
|
* then sendout over socket.
|
||||||
* @msg this method will free it whatever return value.
|
* @msg this method will free it whatever return value.
|
||||||
*/
|
*/
|
||||||
virtual int send_message(SrsOutputableMessage* msg);
|
virtual int send_message(ISrsMessage* msg);
|
||||||
private:
|
private:
|
||||||
/**
|
/**
|
||||||
* when recv message, update the context.
|
* when recv message, update the context.
|
||||||
|
@ -121,7 +121,7 @@ private:
|
||||||
/**
|
/**
|
||||||
* when message sentout, update the context.
|
* when message sentout, update the context.
|
||||||
*/
|
*/
|
||||||
virtual int on_send_message(SrsOutputableMessage* msg);
|
virtual int on_send_message(ISrsMessage* msg);
|
||||||
/**
|
/**
|
||||||
* try to recv interlaced message from peer,
|
* try to recv interlaced message from peer,
|
||||||
* return error if error occur and nerver set the pmsg,
|
* return error if error occur and nerver set the pmsg,
|
||||||
|
@ -235,7 +235,7 @@ public:
|
||||||
/**
|
/**
|
||||||
* message to output.
|
* message to output.
|
||||||
*/
|
*/
|
||||||
class SrsOutputableMessage
|
class ISrsMessage
|
||||||
{
|
{
|
||||||
// 4.1. Message Header
|
// 4.1. Message Header
|
||||||
public:
|
public:
|
||||||
|
@ -251,10 +251,16 @@ public:
|
||||||
int32_t size;
|
int32_t size;
|
||||||
int8_t* payload;
|
int8_t* payload;
|
||||||
public:
|
public:
|
||||||
SrsOutputableMessage();
|
ISrsMessage();
|
||||||
virtual ~SrsOutputableMessage();
|
virtual ~ISrsMessage();
|
||||||
protected:
|
protected:
|
||||||
virtual void free_payload();
|
virtual void free_payload();
|
||||||
|
public:
|
||||||
|
/**
|
||||||
|
* whether message canbe decoded.
|
||||||
|
* only update the context when message canbe decoded.
|
||||||
|
*/
|
||||||
|
virtual bool can_decode() = 0;
|
||||||
/**
|
/**
|
||||||
* encode functions.
|
* encode functions.
|
||||||
*/
|
*/
|
||||||
|
@ -274,10 +280,10 @@ public:
|
||||||
* common RTMP message defines in rtmp.part2.Message-Formats.pdf.
|
* common RTMP message defines in rtmp.part2.Message-Formats.pdf.
|
||||||
* cannbe parse and decode.
|
* cannbe parse and decode.
|
||||||
*/
|
*/
|
||||||
class SrsCommonMessage : public SrsOutputableMessage
|
class SrsCommonMessage : public ISrsMessage
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
typedef SrsOutputableMessage super;
|
typedef ISrsMessage super;
|
||||||
// decoded message payload.
|
// decoded message payload.
|
||||||
private:
|
private:
|
||||||
SrsStream* stream;
|
SrsStream* stream;
|
||||||
|
@ -285,6 +291,8 @@ private:
|
||||||
public:
|
public:
|
||||||
SrsCommonMessage();
|
SrsCommonMessage();
|
||||||
virtual ~SrsCommonMessage();
|
virtual ~SrsCommonMessage();
|
||||||
|
public:
|
||||||
|
virtual bool can_decode();
|
||||||
/**
|
/**
|
||||||
* decode functions.
|
* decode functions.
|
||||||
*/
|
*/
|
||||||
|
@ -324,10 +332,10 @@ public:
|
||||||
* for audio/video/data message that need less memory copy.
|
* for audio/video/data message that need less memory copy.
|
||||||
* and only for output.
|
* and only for output.
|
||||||
*/
|
*/
|
||||||
class SrsSharedPtrMessage : public SrsOutputableMessage
|
class SrsSharedPtrMessage : public ISrsMessage
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
typedef SrsOutputableMessage super;
|
typedef ISrsMessage super;
|
||||||
private:
|
private:
|
||||||
struct SrsSharedPtr
|
struct SrsSharedPtr
|
||||||
{
|
{
|
||||||
|
@ -345,6 +353,8 @@ public:
|
||||||
virtual ~SrsSharedPtrMessage();
|
virtual ~SrsSharedPtrMessage();
|
||||||
protected:
|
protected:
|
||||||
virtual void free_payload();
|
virtual void free_payload();
|
||||||
|
public:
|
||||||
|
virtual bool can_decode();
|
||||||
public:
|
public:
|
||||||
/**
|
/**
|
||||||
* set the shared payload.
|
* set the shared payload.
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue