status_t WifiDisplaySource::onTeardownRequest( int32_t sessionID, int32_t cseq, const sp<ParsedMessage> &data) { ALOGI("Received TEARDOWN request."); int32_t playbackSessionID; sp<PlaybackSession> playbackSession = findPlaybackSession(data, &playbackSessionID); if (playbackSession == NULL) { sendErrorResponse(sessionID, "454 Session Not Found", cseq); return ERROR_MALFORMED; } AString response = "RTSP/1.0 200 OK\r\n"; AppendCommonResponse(&response, cseq, playbackSessionID); response.append("Connection: close\r\n"); response.append("\r\n"); mNetSession->sendRequest(sessionID, response.c_str()); if (mState == AWAITING_CLIENT_TEARDOWN) { CHECK(mStopReplyID != NULL); finishStop(); } else { mClient->onDisplayError(IRemoteDisplayClient::kDisplayErrorUnknown); } return OK; }
AString cMojangAPI::MakeUUIDDashed(const AString & a_UUID) { // Note: we only check the string's length, not the actual content switch (a_UUID.size()) { case 36: { // Already is a dashed UUID, only lowercase return StrToLower(a_UUID); } case 32: { // Insert dashes at the proper positions: AString res; res.reserve(36); res.append(a_UUID, 0, 8); res.push_back('-'); res.append(a_UUID, 8, 4); res.push_back('-'); res.append(a_UUID, 12, 4); res.push_back('-'); res.append(a_UUID, 16, 4); res.push_back('-'); res.append(a_UUID, 20, 12); return StrToLower(res); } } LOGWARNING("%s: Not an UUID: \"%s\".", __FUNCTION__, a_UUID.c_str()); return ""; }
AString cCompositeChat::ExtractText(void) const { AString Msg; for (cParts::const_iterator itr = m_Parts.begin(), end = m_Parts.end(); itr != end; ++itr) { switch ((*itr)->m_PartType) { case ptText: case ptClientTranslated: case ptRunCommand: case ptSuggestCommand: { Msg.append((*itr)->m_Text); break; } case ptUrl: { Msg.append((static_cast<cUrlPart *>(*itr))->m_Url); break; } case ptShowAchievement: { break; } } // switch (PartType) } // for itr - m_Parts[] return Msg; }
status_t WifiDisplaySource::sendM16(int32_t sessionID) { AString request = "GET_PARAMETER rtsp://localhost/wfd1.0 RTSP/1.0\r\n"; AppendCommonResponse(&request, mNextCSeq); CHECK_EQ(sessionID, mClientSessionID); request.append( AStringPrintf("Session: %d\r\n", mClientInfo.mPlaybackSessionID)); request.append("\r\n"); // Empty body status_t err = mNetSession->sendRequest(sessionID, request.c_str(), request.size()); if (err != OK) { return err; } registerResponseHandler( sessionID, mNextCSeq, &WifiDisplaySource::onReceiveM16Response); ++mNextCSeq; scheduleKeepAlive(sessionID); return OK; }
static AString codecResultsToXml(const KeyedVector<AString, CodecSettings> &results) { AString ret; for (size_t i = 0; i < results.size(); ++i) { AString name; AString mime; if (!splitString(results.keyAt(i), " ", &name, &mime)) { continue; } AString codec = AStringPrintf(" <MediaCodec name=\"%s\" type=\"%s\" update=\"true\" >\n", name.c_str(), mime.c_str()); ret.append(codec); const CodecSettings &settings = results.valueAt(i); for (size_t i = 0; i < settings.size(); ++i) { // WARNING: we assume all the settings are "Limit". Currently we have only one type // of setting in this case, which is "max-supported-instances". AString setting = AStringPrintf( " <Limit name=\"%s\" value=\"%s\" />\n", settings.keyAt(i).c_str(), settings.valueAt(i).c_str()); ret.append(setting); } ret.append(" </MediaCodec>\n"); } return ret; }
status_t WifiDisplaySource::sendM3(int32_t sessionID) { AString body = "wfd_content_protection\r\n" "wfd_video_formats\r\n" "wfd_audio_codecs\r\n" "wfd_client_rtp_ports\r\n"; AString request = "GET_PARAMETER rtsp://localhost/wfd1.0 RTSP/1.0\r\n"; AppendCommonResponse(&request, mNextCSeq); request.append("Content-Type: text/parameters\r\n"); request.append(AStringPrintf("Content-Length: %d\r\n", body.size())); request.append("\r\n"); request.append(body); status_t err = mNetSession->sendRequest(sessionID, request.c_str(), request.size()); if (err != OK) { return err; } registerResponseHandler( sessionID, mNextCSeq, &WifiDisplaySource::onReceiveM3Response); ++mNextCSeq; return OK; }
AString cMojangAPI::MakeUUIDShort(const AString & a_UUID) { // Note: we only check the string's length, not the actual content switch (a_UUID.size()) { case 32: { // Already is a short UUID, only lowercase return StrToLower(a_UUID); } case 36: { // Remove the dashes from the string by appending together the parts between them: AString res; res.reserve(32); res.append(a_UUID, 0, 8); res.append(a_UUID, 9, 4); res.append(a_UUID, 14, 4); res.append(a_UUID, 19, 4); res.append(a_UUID, 24, 12); return StrToLower(res); } } LOGWARNING("%s: Not an UUID: \"%s\".", __FUNCTION__, a_UUID.c_str()); return ""; }
AString cWebAdmin::GetHTMLEscapedString(const AString & a_Input) { AString dst; dst.reserve(a_Input.length()); // Loop over input and substitute HTML characters for their alternatives: size_t len = a_Input.length(); for (size_t i = 0; i < len; i++) { switch (a_Input[i]) { case '&': dst.append("&"); break; case '\'': dst.append("'"); break; case '"': dst.append("""); break; case '<': dst.append("<"); break; case '>': dst.append(">"); break; default: { dst.push_back(a_Input[i]); break; } } // switch (a_Input[i]) } // for i - a_Input[] return dst; }
status_t WifiDisplaySource::onOptionsRequest( int32_t sessionID, int32_t cseq, const sp<ParsedMessage> &data) { int32_t playbackSessionID; sp<PlaybackSession> playbackSession = findPlaybackSession(data, &playbackSessionID); if (playbackSession != NULL) { playbackSession->updateLiveness(); } AString response = "RTSP/1.0 200 OK\r\n"; AppendCommonResponse(&response, cseq); response.append( "Public: org.wfa.wfd1.0, SETUP, TEARDOWN, PLAY, PAUSE, " "GET_PARAMETER, SET_PARAMETER\r\n"); response.append("\r\n"); status_t err = mNetSession->sendRequest(sessionID, response.c_str()); if (err == OK) { err = sendM3(sessionID); } return err; }
MediaCodecList::MediaCodecList() : mInitCheck(NO_INIT) { FILE *file = fopen("/etc/media_codecs.xml", "r"); if (file == NULL) { ALOGW("unable to open media codecs configuration xml file."); return; } parseXMLFile(file); if (mInitCheck == OK) { // These are currently still used by the video editing suite. addMediaCodec(true /* encoder */, "AACEncoder", "audio/mp4a-latm"); addMediaCodec( false /* encoder */, "OMX.google.raw.decoder", "audio/raw"); } // for CTS #ifndef ANDROID_DEFAULT_CODE #ifdef MTK_REMOVE_WMA_COMPONENT ALOGD("ASF BUILD OPTION IS CLOSED"); const char* wma_name = "OMX.MTK.AUDIO.DECODER.WMA"; size_t indexForWma = findCodecByName(wma_name); if(indexForWma >= 0) mCodecInfos.removeAt(indexForWma); #endif #ifndef MTK_AUDIO_RAW_SUPPORT ALOGD("PCM Component BUILD OPTION IS CLOSED"); const char* pcm_name = "OMX.MTK.AUDIO.DECODER.RAW"; size_t indexForRaw = findCodecByName(pcm_name); if(indexForRaw >= 0) mCodecInfos.removeAt(indexForRaw); #endif #endif #if 0 for (size_t i = 0; i < mCodecInfos.size(); ++i) { const CodecInfo &info = mCodecInfos.itemAt(i); AString line = info.mName; line.append(" supports "); for (size_t j = 0; j < mTypes.size(); ++j) { uint32_t value = mTypes.valueAt(j); if (info.mTypes & (1ul << value)) { line.append(mTypes.keyAt(j)); line.append(" "); } } ALOGI("%s", line.c_str()); } #endif fclose(file); file = NULL; }
void SfDelegate::onInitiateConnection( const GURL &url, const KeyedVector<String8, String8> *extra, off64_t offset) { CHECK(mURLRequest == NULL); mURLRequest = new net::URLRequest(url, this); mAtEOS = false; mRangeRequested = false; #ifndef ANDROID_DEFAULT_CODE if (offset != 0 || extra != NULL || !gCustomizeHeaders.empty()) { #else if (offset != 0 || extra != NULL) { #endif net::HttpRequestHeaders headers = mURLRequest->extra_request_headers(); if (offset != 0) { headers.AddHeaderFromString( StringPrintf("Range: bytes=%lld-", offset).c_str()); mRangeRequested = true; } if (extra != NULL) { for (size_t i = 0; i < extra->size(); ++i) { AString s; s.append(extra->keyAt(i).string()); s.append(": "); s.append(extra->valueAt(i).string()); headers.AddHeaderFromString(s.c_str()); } } #ifndef ANDROID_DEFAULT_CODE if (!gCustomizeHeaders.empty()) { MY_LOGI(StringPrintf("Customize headers, %s", gCustomizeHeaders.c_str()).c_str()); headers.AddHeaderFromString(gCustomizeHeaders.c_str()); } #endif mURLRequest->SetExtraRequestHeaders(headers); } mURLRequest->set_context(gReqContext); mURLRequest->Start(); } void SfDelegate::initiateDisconnect() { MessageLoop *loop = gNetworkThread->message_loop(); loop->PostTask( FROM_HERE, NewRunnableFunction( &SfDelegate::OnInitiateDisconnectWrapper, this)); }
int CompressStringGZIP(const char * a_Data, size_t a_Length, AString & a_Compressed) { // Compress a_Data into a_Compressed using GZIP; return Z_XXX error constants same as zlib's compress2() a_Compressed.reserve(a_Length); char Buffer[64 KiB]; z_stream strm; memset(&strm, 0, sizeof(strm)); strm.next_in = reinterpret_cast<Bytef *>(const_cast<char *>(a_Data)); strm.avail_in = static_cast<uInt>(a_Length); strm.next_out = reinterpret_cast<Bytef *>(Buffer); strm.avail_out = sizeof(Buffer); int res = deflateInit2(&strm, 9, Z_DEFLATED, 31, 9, Z_DEFAULT_STRATEGY); if (res != Z_OK) { LOG("%s: compression initialization failed: %d (\"%s\").", __FUNCTION__, res, strm.msg); return res; } for (;;) { res = deflate(&strm, Z_FINISH); switch (res) { case Z_OK: { // Some data has been compressed. Consume the buffer and continue compressing a_Compressed.append(Buffer, sizeof(Buffer) - strm.avail_out); strm.next_out = reinterpret_cast<Bytef *>(Buffer); strm.avail_out = sizeof(Buffer); if (strm.avail_in == 0) { // All data has been compressed deflateEnd(&strm); return Z_OK; } break; } case Z_STREAM_END: { // Finished compressing. Consume the rest of the buffer and return a_Compressed.append(Buffer, sizeof(Buffer) - strm.avail_out); deflateEnd(&strm); return Z_OK; } default: { // An error has occurred, log it and return the error value LOG("%s: compression failed: %d (\"%s\").", __FUNCTION__, res, strm.msg); deflateEnd(&strm); return res; } } // switch (res) } // while (true) }
status_t WifiDisplaySource::sendM4(int32_t sessionID) { CHECK_EQ(sessionID, mClientSessionID); AString body; if (mSinkSupportsVideo) { body.append("wfd_video_formats: "); VideoFormats chosenVideoFormat; chosenVideoFormat.disableAll(); chosenVideoFormat.setNativeResolution( mChosenVideoResolutionType, mChosenVideoResolutionIndex); chosenVideoFormat.setProfileLevel( mChosenVideoResolutionType, mChosenVideoResolutionIndex, mChosenVideoProfile, mChosenVideoLevel); body.append(chosenVideoFormat.getFormatSpec(true /* forM4Message */)); body.append("\r\n"); } if (mSinkSupportsAudio) { body.append( AStringPrintf("wfd_audio_codecs: %s\r\n", (mUsingPCMAudio ? "LPCM 00000002 00" // 2 ch PCM 48kHz : "AAC 00000001 00"))); // 2 ch AAC 48kHz } body.append( AStringPrintf( "wfd_presentation_URL: rtsp://%s/wfd1.0/streamid=0 none\r\n", mClientInfo.mLocalIP.c_str())); body.append( AStringPrintf( "wfd_client_rtp_ports: %s\r\n", mWfdClientRtpPorts.c_str())); AString request = "SET_PARAMETER rtsp://localhost/wfd1.0 RTSP/1.0\r\n"; AppendCommonResponse(&request, mNextCSeq); request.append("Content-Type: text/parameters\r\n"); request.append(AStringPrintf("Content-Length: %d\r\n", body.size())); request.append("\r\n"); request.append(body); status_t err = mNetSession->sendRequest(sessionID, request.c_str(), request.size()); if (err != OK) { return err; } registerResponseHandler( sessionID, mNextCSeq, &WifiDisplaySource::onReceiveM4Response); ++mNextCSeq; return OK; }
extern int InflateString(const char * a_Data, size_t a_Length, AString & a_Uncompressed) { a_Uncompressed.reserve(a_Length); char Buffer[64 KiB]; z_stream strm; memset(&strm, 0, sizeof(strm)); strm.next_in = reinterpret_cast<Bytef *>(const_cast<char *>(a_Data)); strm.avail_in = static_cast<uInt>(a_Length); strm.next_out = reinterpret_cast<Bytef *>(Buffer); strm.avail_out = sizeof(Buffer); int res = inflateInit(&strm); // Force GZIP decoding if (res != Z_OK) { LOG("%s: inflation initialization failed: %d (\"%s\").", __FUNCTION__, res, strm.msg); return res; } for (;;) { res = inflate(&strm, Z_NO_FLUSH); switch (res) { case Z_OK: { // Some data has been uncompressed. Consume the buffer and continue uncompressing a_Uncompressed.append(Buffer, sizeof(Buffer) - strm.avail_out); strm.next_out = reinterpret_cast<Bytef *>(Buffer); strm.avail_out = sizeof(Buffer); if (strm.avail_in == 0) { // All data has been uncompressed inflateEnd(&strm); return Z_OK; } break; } case Z_STREAM_END: { // Finished uncompressing. Consume the rest of the buffer and return a_Uncompressed.append(Buffer, sizeof(Buffer) - strm.avail_out); inflateEnd(&strm); return Z_OK; } default: { // An error has occurred, log it and return the error value LOG("%s: inflation failed: %d (\"%s\").", __FUNCTION__, res, strm.msg); inflateEnd(&strm); return res; } } // switch (res) } // while (true) }
bool ARTSPConnection::handleServerRequest(const sp<ARTSPResponse> &request) { // Implementation of server->client requests is optional for all methods // but we do need to respond, even if it's just to say that we don't // support the method. ssize_t space1 = request->mStatusLine.find(" "); CHECK_GE(space1, 0); AString response; response.append("RTSP/1.0 501 Not Implemented\r\n"); ssize_t i = request->mHeaders.indexOfKey("cseq"); if (i >= 0) { AString value = request->mHeaders.valueAt(i); unsigned long cseq; if (!ParseSingleUnsignedLong(value.c_str(), &cseq)) { return false; } response.append("CSeq: "); response.append(cseq); response.append("\r\n"); } response.append("\r\n"); size_t numBytesSent = 0; while (numBytesSent < response.size()) { ssize_t n = send(mSocket, response.c_str() + numBytesSent, response.size() - numBytesSent, 0); if (n < 0 && errno == EINTR) { continue; } if (n <= 0) { if (n == 0) { // Server closed the connection. ALOGE("Server unexpectedly closed the connection."); } else { ALOGE("Error sending rtsp response (%s).", strerror(errno)); } performDisconnect(); return false; } numBytesSent += (size_t)n; } return true; }
void ARTSPConnection::onSendRequest(const sp<AMessage> &msg) { sp<AMessage> reply; CHECK(msg->findMessage("reply", &reply)); if (mState != CONNECTED) { reply->setInt32("result", -ENOTCONN); reply->post(); return; } AString request; CHECK(msg->findString("request", &request)); // Find the boundary between headers and the body. ssize_t i = request.find("\r\n\r\n"); CHECK_GE(i, 0); int32_t cseq = mNextCSeq++; AString cseqHeader = "CSeq: "; cseqHeader.append(cseq); cseqHeader.append("\r\n"); request.insert(cseqHeader, i + 2); LOGV("%s", request.c_str()); size_t numBytesSent = 0; while (numBytesSent < request.size()) { ssize_t n = send(mSocket, request.c_str() + numBytesSent, request.size() - numBytesSent, 0); if (n == 0) { // Server closed the connection. LOGE("Server unexpectedly closed the connection."); reply->setInt32("result", ERROR_IO); reply->post(); return; } else if (n < 0) { if (errno == EINTR) { continue; } LOGE("Error sending rtsp request."); reply->setInt32("result", -errno); reply->post(); return; } numBytesSent += (size_t)n; } mPendingRequests.add(cseq, reply); }
status_t WifiDisplaySource::onPlayRequest( int32_t sessionID, int32_t cseq, const sp<ParsedMessage> &data) { int32_t playbackSessionID; sp<PlaybackSession> playbackSession = findPlaybackSession(data, &playbackSessionID); if (playbackSession == NULL) { sendErrorResponse(sessionID, "454 Session Not Found", cseq); return ERROR_MALFORMED; } if (mState != AWAITING_CLIENT_PLAY && mState != PAUSED_TO_PLAYING && mState != PAUSED) { ALOGW("Received PLAY request but we're in state %d", mState); sendErrorResponse( sessionID, "455 Method Not Valid in This State", cseq); return INVALID_OPERATION; } ALOGI("Received PLAY request."); if (mPlaybackSessionEstablished) { finishPlay(); } else { ALOGI("deferring PLAY request until session established."); } AString response = "RTSP/1.0 200 OK\r\n"; AppendCommonResponse(&response, cseq, playbackSessionID); response.append("Range: npt=now-\r\n"); response.append("\r\n"); status_t err = mNetSession->sendRequest(sessionID, response.c_str()); if (err != OK) { return err; } if (mState == PAUSED_TO_PLAYING || mPlaybackSessionEstablished) { mState = PLAYING; return OK; } CHECK_EQ(mState, AWAITING_CLIENT_PLAY); mState = ABOUT_TO_PLAY; return OK; }
void WifiDisplaySource::sendErrorResponse( int32_t sessionID, const char *errorDetail, int32_t cseq) { AString response; response.append("RTSP/1.0 "); response.append(errorDetail); response.append("\r\n"); AppendCommonResponse(&response, cseq); response.append("\r\n"); mNetSession->sendRequest(sessionID, response.c_str()); }
void cByteBuffer::ReadAgain(AString & a_Out) { // Return the data between m_DataStart and m_ReadPos (the data that has been read but not committed) // Used by ProtoProxy to repeat communication twice, once for parsing and the other time for the remote party CHECK_THREAD; CheckValid(); int DataStart = m_DataStart; if (m_ReadPos < m_DataStart) { // Across the ringbuffer end, read the first part and adjust next part's start: a_Out.append(m_Buffer + m_DataStart, m_BufferSize - m_DataStart); DataStart = 0; } a_Out.append(m_Buffer + DataStart, m_ReadPos - DataStart); }
bool cByteBuffer::ReadString(AString & a_String, int a_Count) { CHECK_THREAD; CheckValid(); ASSERT(a_Count >= 0); NEEDBYTES(a_Count); a_String.clear(); a_String.reserve(a_Count); int BytesToEndOfBuffer = m_BufferSize - m_ReadPos; ASSERT(BytesToEndOfBuffer >= 0); // Sanity check if (BytesToEndOfBuffer <= a_Count) { // Reading across the ringbuffer end, read the first part and adjust parameters: if (BytesToEndOfBuffer > 0) { a_String.assign(m_Buffer + m_ReadPos, BytesToEndOfBuffer); a_Count -= BytesToEndOfBuffer; } m_ReadPos = 0; } // Read the rest of the bytes in a single read (guaranteed to fit): if (a_Count > 0) { a_String.append(m_Buffer + m_ReadPos, a_Count); m_ReadPos += a_Count; } return true; }
AString cWebAdmin::GetDefaultPage(void) { AString Content; Content += "<h4>Server Name:</h4>"; Content += "<p>" + AString( cRoot::Get()->GetServer()->GetServerID() ) + "</p>"; Content += "<h4>Plugins:</h4><ul>"; cPluginManager * PM = cPluginManager::Get(); const cPluginManager::PluginMap & List = PM->GetAllPlugins(); for (cPluginManager::PluginMap::const_iterator itr = List.begin(); itr != List.end(); ++itr) { if (itr->second == NULL) { continue; } AString VersionNum; AppendPrintf(Content, "<li>%s V.%i</li>", itr->second->GetName().c_str(), itr->second->GetVersion()); } Content += "</ul>"; Content += "<h4>Players:</h4><ul>"; cPlayerAccum PlayerAccum; cWorld * World = cRoot::Get()->GetDefaultWorld(); // TODO - Create a list of worlds and players if( World != NULL ) { World->ForEachPlayer(PlayerAccum); Content.append(PlayerAccum.m_Contents); } Content += "</ul><br>"; return Content; }
status_t WifiDisplaySource::onSetParameterRequest( int32_t sessionID, int32_t cseq, const sp<ParsedMessage> &data) { int32_t playbackSessionID; sp<PlaybackSession> playbackSession = findPlaybackSession(data, &playbackSessionID); if (playbackSession == NULL) { sendErrorResponse(sessionID, "454 Session Not Found", cseq); return ERROR_MALFORMED; } if (strstr(data->getContent(), "wfd_idr_request\r\n")) { playbackSession->requestIDRFrame(); } playbackSession->updateLiveness(); AString response = "RTSP/1.0 200 OK\r\n"; AppendCommonResponse(&response, cseq, playbackSessionID); response.append("\r\n"); status_t err = mNetSession->sendRequest(sessionID, response.c_str()); return err; }
void cSslHTTPConnection::GetOutgoingData(AString & a_Data) { for (;;) { // Write as many bytes from our buffer to SSL's encryption as possible: int NumWritten = 0; if (!m_OutgoingData.empty()) { NumWritten = m_Ssl.WritePlain(m_OutgoingData.data(), m_OutgoingData.size()); if (NumWritten > 0) { m_OutgoingData.erase(0, (size_t)NumWritten); } } // Read as many bytes from SSL's "outgoing" buffer as possible: char Buffer[32000]; size_t NumBytes = m_Ssl.ReadOutgoing(Buffer, sizeof(Buffer)); if (NumBytes > 0) { a_Data.append(Buffer, NumBytes); } // If both failed, bail out: if ((NumWritten <= 0) && (NumBytes == 0)) { return; } } }
MediaCodecList::MediaCodecList() : mInitCheck(NO_INIT) { FILE *file; file = fopen("/system/etc/media_codecs.xml", "r"); if (file == NULL) { /* Also try the old /etc/media_codecs.xml path */ file = fopen("/etc/media_codecs.xml", "r"); if (file == NULL) { ALOGW("unable to open media codecs configuration xml file."); return; } } parseXMLFile(file); if (mInitCheck == OK) { // These are currently still used by the video editing suite. addMediaCodec(true /* encoder */, "AACEncoder", "audio/mp4a-latm"); addMediaCodec( false /* encoder */, "OMX.google.raw.decoder", "audio/raw"); } #if 0 for (size_t i = 0; i < mCodecInfos.size(); ++i) { const CodecInfo &info = mCodecInfos.itemAt(i); AString line = info.mName; line.append(" supports "); for (size_t j = 0; j < mTypes.size(); ++j) { uint32_t value = mTypes.valueAt(j); if (info.mTypes & (1ul << value)) { line.append(mTypes.keyAt(j)); line.append(" "); } } ALOGI("%s", line.c_str()); } #endif fclose(file); file = NULL; }
ALog_AFile::ALog_AFile( ASynchronization *pSynch, const AFilename& baseFilename, ALog::EVENT_MASK mask // = ALog::DEFAULT ) : ALog(pSynch, mask), mp_File(NULL), m_CycleSleep(DEFAULT_CYCLE_SLEEP), m_LoggerThread(ALog_AFile::threadprocLogger, false), m_logMaxFileSize(DEFAULT_MAX_FILE_SIZE), m_enableLogFileRotate(true), m_DeleteFileObject(true), m_enableSeparateFilesForErrors(true) { //a_Base filename AFilename f(baseFilename); AString newFilename; f.emitFilenameNoExt(newFilename); //a_Timestamp of when the process was started ATime timeNow; newFilename.append('.'); timeNow.emitYYYY_MM_DD_HHMMSS(newFilename); //a_Counter newFilename.append(".(6).",5); f.emitExtension(newFilename); m_filenameRotation.parse(newFilename); //a_Find the last file used for logging AString filename(1024, 256); f.useFilename().clear(); m_filenameRotation.next(f.useFilename()); while (AFileSystem::exists(f)) { f.clear(); m_filenameRotation.next(f.useFilename()); } mp_File = new AFile_Physical(f, ASW("ab+",3)); //a_Initialize thread m_LoggerThread.setThis(this); m_LoggerThread.start(); }
void cCompositeChat::AddStyle(AString & a_Style, const AString & a_AddStyle) { if (a_AddStyle.empty()) { return; } if (a_AddStyle[0] == '@') { size_t idx = a_Style.find('@'); if ((idx != AString::npos) && (idx != a_Style.length())) { a_Style.erase(idx, 2); } a_Style.append(a_AddStyle); return; } a_Style.append(a_AddStyle); }
AStringVector cFile::GetFolderContents(const AString & a_Folder) { AStringVector AllFiles; #ifdef _WIN32 // If the folder name doesn't contain the terminating slash / backslash, add it: AString FileFilter = a_Folder; if ( !FileFilter.empty() && (FileFilter[FileFilter.length() - 1] != '\\') && (FileFilter[FileFilter.length() - 1] != '/') ) { FileFilter.push_back('\\'); } // Find all files / folders: FileFilter.append("*.*"); HANDLE hFind; WIN32_FIND_DATAA FindFileData; if ((hFind = FindFirstFileA(FileFilter.c_str(), &FindFileData)) != INVALID_HANDLE_VALUE) { do { AllFiles.push_back(FindFileData.cFileName); } while (FindNextFileA(hFind, &FindFileData)); FindClose(hFind); } #else // _WIN32 DIR * dp; AString Folder = a_Folder; if (Folder.empty()) { Folder = "."; } if ((dp = opendir(Folder.c_str())) == nullptr) { LOGERROR("Error (%i) opening directory \"%s\"\n", errno, Folder.c_str()); } else { struct dirent *dirp; while ((dirp = readdir(dp)) != nullptr) { AllFiles.push_back(dirp->d_name); } closedir(dp); } #endif // else _WIN32 return AllFiles; }
void cCommandOutputCallback::Out(const char * a_Fmt, ...) { AString Output; va_list args; va_start(args, a_Fmt); AppendVPrintf(Output, a_Fmt, args); va_end(args); Output.append("\n"); Out(Output); }
static AString globalResultsToXml(const CodecSettings &results) { AString ret; for (size_t i = 0; i < results.size(); ++i) { AString setting = AStringPrintf( " <Setting name=\"%s\" value=\"%s\" />\n", results.keyAt(i).c_str(), results.valueAt(i).c_str()); ret.append(setting); } return ret; }
status_t WifiDisplaySource::onPlayRequest( int32_t sessionID, int32_t cseq, const sp<ParsedMessage> &data) { int32_t playbackSessionID; sp<PlaybackSession> playbackSession = findPlaybackSession(data, &playbackSessionID); if (playbackSession == NULL) { sendErrorResponse(sessionID, "454 Session Not Found", cseq); return ERROR_MALFORMED; } ALOGI("Received PLAY request."); status_t err = playbackSession->play(); CHECK_EQ(err, (status_t)OK); AString response = "RTSP/1.0 200 OK\r\n"; AppendCommonResponse(&response, cseq, playbackSessionID); response.append("Range: npt=now-\r\n"); response.append("\r\n"); err = mNetSession->sendRequest(sessionID, response.c_str()); if (err != OK) { return err; } if (mState == PAUSED_TO_PLAYING) { mState = PLAYING; return OK; } playbackSession->finishPlay(); CHECK_EQ(mState, AWAITING_CLIENT_PLAY); mState = ABOUT_TO_PLAY; return OK; }