X-Git-Url: https://git.sesse.net/?p=cubemap;a=blobdiff_plain;f=server.cpp;h=d3b936f0b9c1f869c34c5dbf05c1beb32ad90a8e;hp=9d15e08771d582f65f43e43a9a18ac7dfcd62e7e;hb=6544fa0ec3f3a501bcb89ea977756911bd7f3ebd;hpb=4934a0983fee26765a3c1a5b6bf5834ba6e7e52c;ds=sidebyside diff --git a/server.cpp b/server.cpp index 9d15e08..d3b936f 100644 --- a/server.cpp +++ b/server.cpp @@ -295,11 +295,11 @@ int Server::lookup_stream_by_url(const string &url) const return stream_url_it->second; } -int Server::add_stream(const string &url, size_t backlog_size, size_t prebuffering_bytes, Stream::Encoding encoding) +int Server::add_stream(const string &url, size_t backlog_size, size_t prebuffering_bytes, Stream::Encoding encoding, Stream::Encoding src_encoding) { MutexLock lock(&mutex); stream_url_map.insert(make_pair(url, streams.size())); - streams.push_back(new Stream(url, backlog_size, prebuffering_bytes, encoding)); + streams.push_back(new Stream(url, backlog_size, prebuffering_bytes, encoding, src_encoding)); return streams.size() - 1; } @@ -331,6 +331,13 @@ void Server::set_encoding(int stream_index, Stream::Encoding encoding) assert(stream_index >= 0 && stream_index < ssize_t(streams.size())); streams[stream_index]->encoding = encoding; } + +void Server::set_src_encoding(int stream_index, Stream::Encoding encoding) +{ + MutexLock lock(&mutex); + assert(stream_index >= 0 && stream_index < ssize_t(streams.size())); + streams[stream_index]->src_encoding = encoding; +} void Server::set_header(int stream_index, const string &http_header, const string &stream_header) { @@ -359,7 +366,7 @@ void Server::set_pacing_rate(int stream_index, uint32_t pacing_rate) streams[stream_index]->pacing_rate = pacing_rate; } -void Server::add_ping(const std::string &url, const std::string &allow_origin) +void Server::add_gen204(const std::string &url, const std::string &allow_origin) { MutexLock lock(&mutex); assert(clients.empty()); @@ -425,8 +432,8 @@ read_request_again: int error_code = parse_request(client); if (error_code == 200) { construct_header(client); - } else if (error_code == -200) { - construct_pong(client); + } else if (error_code == 204) { + construct_204(client); } else { construct_error(client, error_code); } @@ -659,7 +666,7 @@ int Server::parse_request(Client *client) if (ping_url_map_it == ping_url_map.end()) { return 404; // Not found. } else { - return -200; // Special internal error code for pong. + return 204; // No error. } } @@ -737,27 +744,23 @@ void Server::construct_error(Client *client, int error_code) } } -void Server::construct_pong(Client *client) +void Server::construct_204(Client *client) { map::const_iterator ping_url_map_it = ping_url_map.find(client->url); assert(ping_url_map_it != ping_url_map.end()); if (ping_url_map_it->second.empty()) { client->header_or_short_response = - "HTTP/1.0 200 OK\r\n" - "Content-type: text/plain\r\n" - "\r\n" - "Pong!\r\n"; + "HTTP/1.0 204 No Content\r\n" + "\r\n"; } else { - char pong[256]; - snprintf(pong, 256, - "HTTP/1.0 200 OK\r\n" - "Content-type: text/plain\r\n" + char response[256]; + snprintf(response, 256, + "HTTP/1.0 204 No Content\r\n" "Access-Control-Allow-Origin: %s\r\n" - "\r\n" - "Pong!\r\n", + "\r\n", ping_url_map_it->second.c_str()); - client->header_or_short_response = pong; + client->header_or_short_response = response; } // Switch states.