正在显示
2 个修改的文件
包含
41 行增加
和
16 行删除
| @@ -320,12 +320,12 @@ int SrsProtocol::recv_message(SrsCommonMessage** pmsg) | @@ -320,12 +320,12 @@ int SrsProtocol::recv_message(SrsCommonMessage** pmsg) | ||
| 320 | return ret; | 320 | return ret; |
| 321 | } | 321 | } |
| 322 | 322 | ||
| 323 | -int SrsProtocol::send_message(SrsOutputableMessage* msg) | 323 | +int SrsProtocol::send_message(ISrsMessage* msg) |
| 324 | { | 324 | { |
| 325 | int ret = ERROR_SUCCESS; | 325 | int ret = ERROR_SUCCESS; |
| 326 | 326 | ||
| 327 | // free msg whatever return value. | 327 | // free msg whatever return value. |
| 328 | - SrsAutoFree(SrsOutputableMessage, msg, false); | 328 | + SrsAutoFree(ISrsMessage, msg, false); |
| 329 | 329 | ||
| 330 | if ((ret = msg->encode_packet()) != ERROR_SUCCESS) { | 330 | if ((ret = msg->encode_packet()) != ERROR_SUCCESS) { |
| 331 | srs_error("encode packet to message payload failed. ret=%d", ret); | 331 | srs_error("encode packet to message payload failed. ret=%d", ret); |
| @@ -479,10 +479,15 @@ int SrsProtocol::on_recv_message(SrsCommonMessage* msg) | @@ -479,10 +479,15 @@ int SrsProtocol::on_recv_message(SrsCommonMessage* msg) | ||
| 479 | return ret; | 479 | return ret; |
| 480 | } | 480 | } |
| 481 | 481 | ||
| 482 | -int SrsProtocol::on_send_message(SrsOutputableMessage* msg) | 482 | +int SrsProtocol::on_send_message(ISrsMessage* msg) |
| 483 | { | 483 | { |
| 484 | int ret = ERROR_SUCCESS; | 484 | int ret = ERROR_SUCCESS; |
| 485 | 485 | ||
| 486 | + if (!msg->can_decode()) { | ||
| 487 | + srs_verbose("ignore the un-decodable message."); | ||
| 488 | + return ret; | ||
| 489 | + } | ||
| 490 | + | ||
| 486 | SrsCommonMessage* common_msg = dynamic_cast<SrsCommonMessage*>(msg); | 491 | SrsCommonMessage* common_msg = dynamic_cast<SrsCommonMessage*>(msg); |
| 487 | if (!msg) { | 492 | if (!msg) { |
| 488 | srs_verbose("ignore the shared ptr message."); | 493 | srs_verbose("ignore the shared ptr message."); |
| @@ -927,18 +932,18 @@ SrsChunkStream::~SrsChunkStream() | @@ -927,18 +932,18 @@ SrsChunkStream::~SrsChunkStream() | ||
| 927 | srs_freep(msg); | 932 | srs_freep(msg); |
| 928 | } | 933 | } |
| 929 | 934 | ||
| 930 | -SrsOutputableMessage::SrsOutputableMessage() | 935 | +ISrsMessage::ISrsMessage() |
| 931 | { | 936 | { |
| 932 | payload = NULL; | 937 | payload = NULL; |
| 933 | size = 0; | 938 | size = 0; |
| 934 | } | 939 | } |
| 935 | 940 | ||
| 936 | -SrsOutputableMessage::~SrsOutputableMessage() | 941 | +ISrsMessage::~ISrsMessage() |
| 937 | { | 942 | { |
| 938 | free_payload(); | 943 | free_payload(); |
| 939 | } | 944 | } |
| 940 | 945 | ||
| 941 | -void SrsOutputableMessage::free_payload() | 946 | +void ISrsMessage::free_payload() |
| 942 | { | 947 | { |
| 943 | srs_freepa(payload); | 948 | srs_freepa(payload); |
| 944 | } | 949 | } |
| @@ -955,6 +960,11 @@ SrsCommonMessage::~SrsCommonMessage() | @@ -955,6 +960,11 @@ SrsCommonMessage::~SrsCommonMessage() | ||
| 955 | srs_freep(stream); | 960 | srs_freep(stream); |
| 956 | } | 961 | } |
| 957 | 962 | ||
| 963 | +bool SrsCommonMessage::can_decode() | ||
| 964 | +{ | ||
| 965 | + return true; | ||
| 966 | +} | ||
| 967 | + | ||
| 958 | int SrsCommonMessage::decode_packet() | 968 | int SrsCommonMessage::decode_packet() |
| 959 | { | 969 | { |
| 960 | int ret = ERROR_SUCCESS; | 970 | int ret = ERROR_SUCCESS; |
| @@ -1145,6 +1155,11 @@ void SrsSharedPtrMessage::free_payload() | @@ -1145,6 +1155,11 @@ void SrsSharedPtrMessage::free_payload() | ||
| 1145 | } | 1155 | } |
| 1146 | } | 1156 | } |
| 1147 | 1157 | ||
| 1158 | +bool SrsSharedPtrMessage::can_decode() | ||
| 1159 | +{ | ||
| 1160 | + return true; | ||
| 1161 | +} | ||
| 1162 | + | ||
| 1148 | int SrsSharedPtrMessage::initialize(SrsMessageHeader* header, char* payload, int size, int perfer_cid) | 1163 | int SrsSharedPtrMessage::initialize(SrsMessageHeader* header, char* payload, int size, int perfer_cid) |
| 1149 | { | 1164 | { |
| 1150 | int ret = ERROR_SUCCESS; | 1165 | int ret = ERROR_SUCCESS; |
| @@ -47,7 +47,7 @@ class SrsChunkStream; | @@ -47,7 +47,7 @@ class SrsChunkStream; | ||
| 47 | class SrsAmf0Object; | 47 | class SrsAmf0Object; |
| 48 | class SrsAmf0Null; | 48 | class SrsAmf0Null; |
| 49 | class SrsAmf0Undefined; | 49 | class SrsAmf0Undefined; |
| 50 | -class SrsOutputableMessage; | 50 | +class ISrsMessage; |
| 51 | 51 | ||
| 52 | // convert class name to string. | 52 | // convert class name to string. |
| 53 | #define CLASS_NAME_STRING(className) #className | 53 | #define CLASS_NAME_STRING(className) #className |
| @@ -112,7 +112,7 @@ public: | @@ -112,7 +112,7 @@ public: | ||
| 112 | * then sendout over socket. | 112 | * then sendout over socket. |
| 113 | * @msg this method will free it whatever return value. | 113 | * @msg this method will free it whatever return value. |
| 114 | */ | 114 | */ |
| 115 | - virtual int send_message(SrsOutputableMessage* msg); | 115 | + virtual int send_message(ISrsMessage* msg); |
| 116 | private: | 116 | private: |
| 117 | /** | 117 | /** |
| 118 | * when recv message, update the context. | 118 | * when recv message, update the context. |
| @@ -121,7 +121,7 @@ private: | @@ -121,7 +121,7 @@ private: | ||
| 121 | /** | 121 | /** |
| 122 | * when message sentout, update the context. | 122 | * when message sentout, update the context. |
| 123 | */ | 123 | */ |
| 124 | - virtual int on_send_message(SrsOutputableMessage* msg); | 124 | + virtual int on_send_message(ISrsMessage* msg); |
| 125 | /** | 125 | /** |
| 126 | * try to recv interlaced message from peer, | 126 | * try to recv interlaced message from peer, |
| 127 | * return error if error occur and nerver set the pmsg, | 127 | * return error if error occur and nerver set the pmsg, |
| @@ -235,7 +235,7 @@ public: | @@ -235,7 +235,7 @@ public: | ||
| 235 | /** | 235 | /** |
| 236 | * message to output. | 236 | * message to output. |
| 237 | */ | 237 | */ |
| 238 | -class SrsOutputableMessage | 238 | +class ISrsMessage |
| 239 | { | 239 | { |
| 240 | // 4.1. Message Header | 240 | // 4.1. Message Header |
| 241 | public: | 241 | public: |
| @@ -251,10 +251,16 @@ public: | @@ -251,10 +251,16 @@ public: | ||
| 251 | int32_t size; | 251 | int32_t size; |
| 252 | int8_t* payload; | 252 | int8_t* payload; |
| 253 | public: | 253 | public: |
| 254 | - SrsOutputableMessage(); | ||
| 255 | - virtual ~SrsOutputableMessage(); | 254 | + ISrsMessage(); |
| 255 | + virtual ~ISrsMessage(); | ||
| 256 | protected: | 256 | protected: |
| 257 | virtual void free_payload(); | 257 | virtual void free_payload(); |
| 258 | +public: | ||
| 259 | + /** | ||
| 260 | + * whether message canbe decoded. | ||
| 261 | + * only update the context when message canbe decoded. | ||
| 262 | + */ | ||
| 263 | + virtual bool can_decode() = 0; | ||
| 258 | /** | 264 | /** |
| 259 | * encode functions. | 265 | * encode functions. |
| 260 | */ | 266 | */ |
| @@ -274,10 +280,10 @@ public: | @@ -274,10 +280,10 @@ public: | ||
| 274 | * common RTMP message defines in rtmp.part2.Message-Formats.pdf. | 280 | * common RTMP message defines in rtmp.part2.Message-Formats.pdf. |
| 275 | * cannbe parse and decode. | 281 | * cannbe parse and decode. |
| 276 | */ | 282 | */ |
| 277 | -class SrsCommonMessage : public SrsOutputableMessage | 283 | +class SrsCommonMessage : public ISrsMessage |
| 278 | { | 284 | { |
| 279 | private: | 285 | private: |
| 280 | - typedef SrsOutputableMessage super; | 286 | + typedef ISrsMessage super; |
| 281 | // decoded message payload. | 287 | // decoded message payload. |
| 282 | private: | 288 | private: |
| 283 | SrsStream* stream; | 289 | SrsStream* stream; |
| @@ -285,6 +291,8 @@ private: | @@ -285,6 +291,8 @@ private: | ||
| 285 | public: | 291 | public: |
| 286 | SrsCommonMessage(); | 292 | SrsCommonMessage(); |
| 287 | virtual ~SrsCommonMessage(); | 293 | virtual ~SrsCommonMessage(); |
| 294 | +public: | ||
| 295 | + virtual bool can_decode(); | ||
| 288 | /** | 296 | /** |
| 289 | * decode functions. | 297 | * decode functions. |
| 290 | */ | 298 | */ |
| @@ -324,10 +332,10 @@ public: | @@ -324,10 +332,10 @@ public: | ||
| 324 | * for audio/video/data message that need less memory copy. | 332 | * for audio/video/data message that need less memory copy. |
| 325 | * and only for output. | 333 | * and only for output. |
| 326 | */ | 334 | */ |
| 327 | -class SrsSharedPtrMessage : public SrsOutputableMessage | 335 | +class SrsSharedPtrMessage : public ISrsMessage |
| 328 | { | 336 | { |
| 329 | private: | 337 | private: |
| 330 | - typedef SrsOutputableMessage super; | 338 | + typedef ISrsMessage super; |
| 331 | private: | 339 | private: |
| 332 | struct SrsSharedPtr | 340 | struct SrsSharedPtr |
| 333 | { | 341 | { |
| @@ -346,6 +354,8 @@ public: | @@ -346,6 +354,8 @@ public: | ||
| 346 | protected: | 354 | protected: |
| 347 | virtual void free_payload(); | 355 | virtual void free_payload(); |
| 348 | public: | 356 | public: |
| 357 | + virtual bool can_decode(); | ||
| 358 | +public: | ||
| 349 | /** | 359 | /** |
| 350 | * set the shared payload. | 360 | * set the shared payload. |
| 351 | */ | 361 | */ |
-
请 注册 或 登录 后发表评论