Esempio n. 1
0
void WSStreamerHandler::on_open(websocketpp::session_ptr client) {
	if (client->get_resource() != "/") {
		shared_ptr<ifstream> resource(new ifstream(client->get_resource().substr(1).c_str(), ios::binary));
		if (resource->is_open()) {
			cout << "INFO: Client has connected and opened " + client->get_resource() << endl;
			// Check if it is a rtpdump file. If it is, fast foward past file header
			if (resource->good()) {
				streampos filestart = resource->tellg();
				char* rtpdumphdr = new char[strlen(RTPPLAY_MAGIC)];
				resource->read(rtpdumphdr, strlen(RTPPLAY_MAGIC));
				if (resource->gcount() == strlen(RTPPLAY_MAGIC) && strncmp(rtpdumphdr, RTPPLAY_MAGIC, strlen(RTPPLAY_MAGIC)) == 0) {
					cout << "INFO: Requested file is an rtpdump file. Fast forwarding past file header" << endl;
					resource->ignore(sizeof(RD_hdr_t));
				}
				else {
					// Reset file to beginning if we do not see rtpdump header
					resource->seekg(filestart);
				}
				delete[] rtpdumphdr;
			}
			WSSClientInfo clientInfo;
			clientInfo.resource = resource;
			connections.insert(pair<websocketpp::session_ptr, WSSClientInfo>(client, clientInfo));
		}
		else {
			cerr << "ERROR: Client has connected but server is unable to access " + client->get_resource() << endl;
			client->send("ERROR: Failed to open resource");
		}
	}
}
Esempio n. 2
0
int sendNAL(websocketpp::session_ptr client, shared_ptr<ifstream> file, int nals) {
	if (file->good()) {
		vector<unsigned char> buffer = readNAL(*file.get(), nals);
		client->send(buffer);
		//debug.write((char*)&buffer[0], buffer.size());
		return buffer.size();
	}
	else {
		return 0;
	}
}
Esempio n. 3
0
streamsize sendChunk(websocketpp::session_ptr client, shared_ptr<ifstream> file, int chunk_size) {
	if (file->good()) {
		char* read_buffer = new char[chunk_size];
		vector<unsigned char> send_buffer;
		file->read(read_buffer, chunk_size);
		send_buffer.assign(read_buffer, read_buffer + file->gcount());
		client->send(send_buffer);
		delete [] read_buffer;
		return file->gcount();
	}
	else {
		return 0;
	}
}
Esempio n. 4
0
streamsize sendRTP(websocketpp::session_ptr client, shared_ptr<ifstream> file, int packets) {
	if (file->good()) {
		// Read file header
		char packet_hdr_array[sizeof(RD_packet_t)];
		file->read(packet_hdr_array, sizeof(packet_hdr_array));
		RD_packet_t* packet_hdr = (RD_packet_t*)packet_hdr_array;
		packet_hdr->length = ntohs(packet_hdr->length);
		packet_hdr->plen = ntohs(packet_hdr->plen);
		packet_hdr->offset = ntohl(packet_hdr->offset);
		// Extract actual RTP packet
		char* rtp_packet = new char[packet_hdr->plen];
		file->read(rtp_packet, packet_hdr->plen);
		vector<unsigned char> send_buffer;
		send_buffer.assign(rtp_packet, rtp_packet + file->gcount());
		client->send(send_buffer);
		delete [] rtp_packet;
		return file->gcount();
	}
	else {
		return 0;
	}
}
Esempio n. 5
0
void echo_server_handler::on_message(websocketpp::session_ptr client,
	const std::vector<unsigned char> &data) {
	client->send(data);
}
Esempio n. 6
0
void echo_server_handler::on_message(websocketpp::session_ptr client, const std::string &msg) {
	client->send(msg);
}