| 1050 | } |
| 1051 | |
| 1052 | int RtmpContext::SendConnectRequest(const butil::EndPoint& remote_side, int fd, bool simplified_rtmp) { |
| 1053 | butil::IOBuf req_buf; |
| 1054 | { |
| 1055 | butil::IOBufAsZeroCopyOutputStream zc_stream(&req_buf); |
| 1056 | AMFOutputStream ostream(&zc_stream); |
| 1057 | WriteAMFString(RTMP_AMF0_COMMAND_CONNECT, &ostream); |
| 1058 | WriteAMFUint32(1, &ostream); |
| 1059 | RtmpConnectRequest req; |
| 1060 | if (_client_options->app.empty()) { |
| 1061 | LOG(ERROR) << "RtmpClientOptions.app must be set"; |
| 1062 | return -1; |
| 1063 | } |
| 1064 | req.set_app(_client_options->app); |
| 1065 | if (!_client_options->flashVer.empty()) { |
| 1066 | req.set_flashver(_client_options->flashVer); |
| 1067 | } |
| 1068 | if (!_client_options->swfUrl.empty()) { |
| 1069 | req.set_swfurl(_client_options->swfUrl); |
| 1070 | } |
| 1071 | // formulate tcUrl |
| 1072 | if (_client_options->tcUrl.empty()) { |
| 1073 | std::string* const tcurl = req.mutable_tcurl(); |
| 1074 | tcurl->reserve(32 + _client_options->app.size()); |
| 1075 | tcurl->append("rtmp://"); |
| 1076 | tcurl->append(butil::endpoint2str(remote_side).c_str()); |
| 1077 | tcurl->push_back('/'); |
| 1078 | tcurl->append(_client_options->app); |
| 1079 | } else { |
| 1080 | req.set_tcurl(_client_options->tcUrl); |
| 1081 | } |
| 1082 | req.set_fpad(_client_options->fpad); |
| 1083 | req.set_capabilities(239); // Copy from SRS |
| 1084 | req.set_audiocodecs(_client_options->audioCodecs); |
| 1085 | req.set_videocodecs(_client_options->videoCodecs); |
| 1086 | req.set_videofunction(_client_options->videoFunction); |
| 1087 | if (!_client_options->pageUrl.empty()) { |
| 1088 | req.set_pageurl(_client_options->pageUrl); |
| 1089 | } |
| 1090 | req.set_objectencoding(RTMP_AMF0); |
| 1091 | req.set_stream_multiplexing(true); |
| 1092 | WriteAMFObject(req, &ostream); |
| 1093 | if (!ostream.good()) { |
| 1094 | LOG(ERROR) << "Fail to serialize connect request"; |
| 1095 | return -1; |
| 1096 | } |
| 1097 | } |
| 1098 | RtmpMessageHeader header; |
| 1099 | header.message_length = req_buf.size(); |
| 1100 | header.message_type = RTMP_MESSAGE_COMMAND_AMF0; |
| 1101 | header.stream_id = RTMP_CONTROL_MESSAGE_STREAM_ID; |
| 1102 | |
| 1103 | butil::IOBuf msg_buf; |
| 1104 | if (simplified_rtmp) { |
| 1105 | char buf[5]; |
| 1106 | char* p = buf; |
| 1107 | *p++ = RTMP_DEFAULT_VERSION; |
| 1108 | memcpy(p, SIMPLIFIED_RTMP_MAGIC_NUMBER, MAGIC_NUMBER_SIZE); |
| 1109 | msg_buf.append(buf, sizeof(buf)); |
no test coverage detected