bool C4Record::StartStreaming(bool fInitial) { if (!fRecording) return false; if (fStreaming) return false; // Get temporary file name StdCopyStrBuf sTempFilename(sFilename); MakeTempFilename(&sTempFilename); // Save start state (without copy of scenario!) C4GameSaveRecord saveRec(fInitial, Index, Game.Parameters.isLeague(), false); if (!saveRec.Save(sTempFilename.getData())) return FALSE; saveRec.Close(); // Add file into stream, delete file fStreaming = true; if (!StreamFile(sTempFilename.getData(), sFilename.getData())) { fStreaming = false; return false; } // Okay EraseFile(sTempFilename.getData()); iStreamingPos = 0; return true; }
bool C4Record::AddFile(const char *szLocalFilename, const char *szAddAs, bool fDelete) { if (!fRecording) return false; // Streaming? if (fStreaming) { // Special stripping for streaming StdCopyStrBuf szFile(szLocalFilename); if (SEqualNoCase(GetExtension(szAddAs), "c4p")) { // Create a copy MakeTempFilename(&szFile); if (!CopyItem(szLocalFilename, szFile.getData())) return false; // Strip it if (!C4Player::Strip(szFile.getData(), true)) return false; } // Add to stream if (!StreamFile(szFile.getData(), szAddAs)) return false; // Remove temporary file if (szFile != szLocalFilename) EraseItem(szFile.getData()); } // Add to record group if (fDelete) { if (!RecordGrp.Move(szLocalFilename, szAddAs)) return false; } else { if (!RecordGrp.Add(szLocalFilename, szAddAs)) return false; } return true; }
void AudioStreamingServer::Serve(const std::shared_ptr<ISocket>& clientSocket) { try { char recvBuffer[DEFAULT_BUFFER_SIZE]; int read = clientSocket->Receive(recvBuffer, DEFAULT_BUFFER_SIZE); HttpRequest request(recvBuffer, read); std::string requestUrl = httpExtractor->ExtractGET(request); requestUrl = urlCodec->DecodeURL(requestUrl); const char* songsearch = "/songsearch/"; if(requestUrl.find(songsearch) == 0) { std::string keyword = requestUrl.substr(strlen(songsearch)); SendMediaList(clientSocket, keyword, httpExtractor->ExtractHOST(request)); } else if(audioLibrary->FileExists(requestUrl.substr(1))) { std::ifstream audioFile(audioLibrary->GetFullPath(requestUrl), std::ifstream::binary); if(audioFile.is_open()) { std::string extension = FindExtension(requestUrl); std::transform(extension.begin(), extension.end(), extension.begin(), tolower); StreamFile(clientSocket, audioFile, EXTENSION_TO_CONTENT_TYPE[extension]); } else { SendNotFound(clientSocket); } } else { SendNotFound(clientSocket); } } catch(const GenericAudioStreamerException& e) { std::lock_guard<std::mutex> guard(stderrMutex); std::cerr << e.what(); } catch(const IHttpRequestExtractor::HttpExtractionException& e) { HttpResponse response(HTTP_1_1, BAD_REQUEST, NONE, 0); SendResponseHeader(clientSocket, response); } }
void SquawkSynthSD::play(Fat16 melody) { SquawkSynth::pause(); file = StreamFile(melody); SquawkSynth::play(&file); }