void Sender::sendTextData(const amf0::Node& textData) { if (streaming && dataStream) { rtmp::Packet packet; packet.channel = rtmp::Channel::AUDIO; packet.messageStreamId = 1; packet.timestamp = 0; packet.messageType = rtmp::MessageType::NOTIFY; amf0::Node commandName = std::string("onTextData"); commandName.encode(packet.data); amf0::Node argument1 = textData; argument1.encode(packet.data); amf0::Node argument2 = 0.0; argument2.encode(packet.data); std::vector<uint8_t> buffer; encodePacket(buffer, outChunkSize, packet, sentPackets); socket.send(buffer); } }
static RESULT sendOneUpdate(clntData_t *data, int sockFd) { RESULT res = G_FAIL; u32 size = 0; char *buffer = NULL; if(!data) { LOG_ERROR("update data is null"); return res; } if((size = encodePacket(data,&buffer)) <=0) { LOG_ERROR("Error in encoding"); return res; } if(sendData(sockFd,size,buffer) < size) { LOG_ERROR("Unable to send update message"); free(buffer); return res; } if(buffer != NULL) free(buffer); return G_OK; }
void Sender::sendPublish() { rtmp::Packet packet; packet.channel = rtmp::Channel::SOURCE; packet.messageStreamId = streamId; packet.timestamp = 0; packet.messageType = rtmp::MessageType::INVOKE; amf0::Node commandName = std::string("publish"); commandName.encode(packet.data); amf0::Node transactionIdNode = static_cast<double>(++invokeId); transactionIdNode.encode(packet.data); amf0::Node argument1(amf0::Marker::Null); argument1.encode(packet.data); amf0::Node argument2 = streamName; argument2.encode(packet.data); std::vector<uint8_t> buffer; encodePacket(buffer, outChunkSize, packet, sentPackets); #ifdef DEBUG std::cout << "Sending INVOKE " << commandName.asString() << ", transaction ID: " << invokeId << std::endl; #endif socket.send(buffer); invokes[invokeId] = commandName.asString(); }
void Sender::sendConnect() { rtmp::Packet packet; packet.channel = rtmp::Channel::SYSTEM; packet.messageStreamId = 0; packet.timestamp = 0; packet.messageType = rtmp::MessageType::INVOKE; amf0::Node commandName = std::string("connect"); commandName.encode(packet.data); amf0::Node transactionIdNode = static_cast<double>(++invokeId); transactionIdNode.encode(packet.data); amf0::Node argument1; argument1["app"] = application; argument1["flashVer"] = std::string("FMLE/3.0 (compatible; Lavf57.5.0)"); argument1["tcUrl"] = std::string("rtmp://127.0.0.1:") + std::to_string(socket.getPort()) + "/" + application; argument1["type"] = std::string("nonprivate"); argument1.encode(packet.data); std::vector<uint8_t> buffer; encodePacket(buffer, outChunkSize, packet, sentPackets); #ifdef DEBUG std::cout << "Sending INVOKE " << commandName.asString() << ", transaction ID: " << invokeId << std::endl; #endif socket.send(buffer); invokes[invokeId] = commandName.asString(); }
void Sender::sendVideo(uint64_t timestamp, const std::vector<uint8_t>& videoData) { if (streaming && videoStream) { rtmp::Packet packet; packet.channel = rtmp::Channel::VIDEO; packet.messageStreamId = 1; packet.timestamp = timestamp; packet.messageType = rtmp::MessageType::VIDEO_PACKET; packet.data = videoData; std::vector<uint8_t> buffer; encodePacket(buffer, outChunkSize, packet, sentPackets); socket.send(buffer); } }
void Sender::sendSetChunkSize() { rtmp::Packet packet; packet.channel = rtmp::Channel::SYSTEM; packet.timestamp = 0; packet.messageType = rtmp::MessageType::SET_CHUNK_SIZE; encodeInt(packet.data, 4, outChunkSize); std::vector<uint8_t> buffer; encodePacket(buffer, outChunkSize, packet, sentPackets); #ifdef DEBUG std::cout << "Sending SET_CHUNK_SIZE" << std::endl; #endif socket.send(buffer); }
virtual void packetSent(const Message &m, const Component *sender, MicroFlo::PortId senderPort) { const MicroFlo::NodeId senderId = sender->id(); //LOG("packet sent %d\n", senderId); const Port * port = findPortByEdge(options.info.outports, senderId, senderPort); if (port) { const char *outTopic = port->topic.c_str(); const std::string data = encodePacket(m.pkg); const int res = mosquitto_publish(this->connection, NULL, outTopic, data.size(), data.c_str(), 0, false); LOG("sending on MQTT topic %s: %s\n", outTopic, data.c_str()); if (res != MOSQ_ERR_SUCCESS) { //die("publish\n"); } } else { LOG("no MQTT topic associated\n"); } }
int testPacketBuilder() { PacketBuilder pb; std::vector<ProtocolPacket> packets; std::vector<uint8_t> encoded; ASSERT(pb.addData("foobar").size() == 0); ASSERT(pb.addData("foobar").size() == 0); ASSERT(pb.addData("foobar").size() == 0); packets = pb.addData("\nbar\ndata\n"); ASSERT(packets.size() == 0); pb = PacketBuilder(); encoded = encodePacket(ProtocolPacket(TYPE_DATA,1337,"foobar")); packets = pb.addData(encoded); ASSERT(packets.size() == 1); return 0; }
void Sender::sendMetaData(const amf0::Node& metaData) { if (streaming) { rtmp::Packet packet; packet.channel = rtmp::Channel::AUDIO; packet.messageStreamId = 1; packet.timestamp = 0; packet.messageType = rtmp::MessageType::NOTIFY; amf0::Node commandName = std::string("@setDataFrame"); commandName.encode(packet.data); amf0::Node argument1 = std::string("onMetaData"); argument1.encode(packet.data); amf0::Node filteredMetaData = amf0::Marker::ECMAArray; for (auto value : metaData.asMap()) { /// not in the blacklist if (metaDataBlacklist.find(value.first) == metaDataBlacklist.end()) { filteredMetaData[value.first] = value.second; } } amf0::Node argument2 = filteredMetaData; argument2.encode(packet.data); std::vector<uint8_t> buffer; encodePacket(buffer, outChunkSize, packet, sentPackets); socket.send(buffer); } }