接着客户端传送54bytes的数据
Deserialize来解码得到的消息是,此时消耗掉4bytes
[cpp]
case RM_HEADER_MESSAGETYPE_WINACKSIZE:
{
return DeserializeWinAckSize(buffer, message[RM_WINACKSIZE]);
}
得到应答是25000000
所以回复
[cpp]
case RM_HEADER_MESSAGETYPE_WINACKSIZE:
{
return ProcessWinAckSize(pFrom, request);
}
[cpp]
bool BaseRTMPAppProtocolHandler::ProcessWinAckSize(BaseRTMPProtocol *pFrom,
Variant &request) {
if (request[RM_WINACKSIZE] != _V_NUMERIC) {
FATAL("Invalid message: %s", STR(request.ToString()));
return false;
}
uint32_t size = (uint32_t) request[RM_WINACKSIZE];
if ((size > 4 * 1024 * 1024) || size == 0) {
FATAL("Invalid message: %s", STR(request.ToString()));
return false;
}
pFrom->SetWinAckSize(request[RM_WINACKSIZE]);
return true;
}
已经从54bytes中去掉了12+4bytes还剩38
再去掉12bytes,还剩下26bytes
Deserialize来解码得到的消息是(此时这里把剩下的26bytes消耗完全)
[cpp]
case RM_HEADER_MESSAGETYPE_FLEX:
{
message[RM_INVOKE][RM_INVOKE_IS_FLEX] =
(bool)(H_MT(header) == RM_HEADER_MESSAGETYPE_FLEX);
return DeserializeInvoke(buffer, message[RM_INVOKE]);
}
在下面进行消息的处理(回应)
[cpp]
bool RTMPProtocolSerializer::DeserializeInvoke(IOBuffer &buffer, Variant &message) {
if (message[RM_INVOKE_IS_FLEX]) {
if (!buffer.Ignore(1)) {
FATAL("Unable to ignore 1 byte");
return false;
}
}
if (!_amf0.ReadShortString(buffer, message[RM_INVOKE_FUNCTION])) {
FATAL("Unable to read %s", STR(RM_INVOKE_FUNCTION));
return false;
}
if (!_amf0.ReadDouble(buffer, message[RM_INVOKE_ID])) {
FATAL("Unable to read %s", STR(RM_INVOKE_ID));
return false;
}
for (uint32_t i = 0; GETAVAILABLEBYTESCOUNT(buffer) > 0; i++) {
if (!_amf0.Read(buffer, message[RM_INVOKE_PARAMS][i])) {
FATAL("Unable to de-serialize invoke parameter %u", i);
return false;
}
}
return true;
}
[cpp]
bool BaseRTMPAppProtocolHandler::InboundMessageAvailable(BaseRTMPProtocol *pFrom,
Variant &request) {
case RM_HEADER_MESSAGETYPE_FLEX:
{
return ProcessInvoke(pFrom, request);
这里主要是处理ProcessInvokeCreateStream
}
}
[cpp]
bool BaseRTMPAppProtocolHandler::ProcessInvokeCreateStream(BaseRTMPProtocol *pFrom,
Variant &request) {
uint32_t id = 0;
//1. Create the neutral stream
if (pFrom->CreateNeutralStream(id) == NULL) {
FATAL("Unable to create stream");
return false;
}
//2. Send the response
Variant response = StreamMessageFactory::GetInvokeCreateStreamResult(request, id);
return SendRTMPMessage(pFrom, response);
}
到了这里数据就处理完了,一共发送了37bytes的数据给client