bool FileLogLocation::OpenFile() { _canLog = false; _fileStream.close(); _fileIsClosed = true; double ts; GETCLOCKS(ts); ts = (ts / CLOCKS_PER_SECOND) * 1000; string temp = format("%s.%"PRIu64".%"PRIu64, STR(_fileName), (uint64_t) getpid(), (uint64_t) ts); ios_base::openmode openMode = ios_base::out | ios_base::binary | ios_base::trunc; _fileStream.open(STR(temp), openMode); if (_fileStream.fail()) return false; _fileStream << "PID: " << getpid() << "; TIMESTAMP: " << time(NULL) << endl; if (_fileHistorySize > 0) { ADD_VECTOR_END(_history, temp); while (_history.size() > _fileHistorySize) { deleteFile(_history[0]); _history.erase(_history.begin()); } } _currentLength = 0; _canLog = true; _fileIsClosed = false; return true; }
bool BaseMediaDocument::Process() { double startTime = 0; double endTime = 0; GETCLOCKS(startTime); //1. Compute the names _mediaFilePath = (string) _metadata[META_SERVER_FULL_PATH]; _metaFilePath = _mediaFilePath + "."MEDIA_TYPE_META; _seekFilePath = _mediaFilePath + "."MEDIA_TYPE_SEEK; _keyframeSeek = (bool)_metadata[CONF_APPLICATION_KEYFRAMESEEK]; _seekGranularity = (uint32_t) _metadata[CONF_APPLICATION_SEEKGRANULARITY]; //1. Open the media file #ifdef HAS_MMAP if (!_mediaFile.Initialize(_mediaFilePath, 4 * 1024 * 1024, true)) { FATAL("Unable to open media file: %s", STR(_mediaFilePath)); return false; } #else if (!_mediaFile.Initialize(_mediaFilePath)) { FATAL("Unable to open media file: %s", STR(_mediaFilePath)); return false; } #endif //4. Read the document if (!ParseDocument()) { FATAL("Unable to parse document"); return false; } //5. Build the frames if (!BuildFrames()) { FATAL("Unable to build frames"); return false; } //6. Save the seek file if (!SaveSeekFile()) { FATAL("Unable to save seeking file"); return false; } //7. Build the meta if (!SaveMetaFile()) { FATAL("Unable to save meta file"); return false; } GETCLOCKS(endTime); INFO("%"PRIz"u frames computed in %.2f seconds at a speed of %.2f FPS", _frames.size(), (endTime - startTime) / (double) CLOCKS_PER_SECOND, (double) _frames.size() / ((endTime - startTime) / (double) CLOCKS_PER_SECOND)); if (_frames.size() != 0) { uint32_t totalSeconds = (uint32_t) (((uint32_t) _frames[_frames.size() - 1].absoluteTime) / 1000); uint32_t hours = totalSeconds / 3600; uint32_t minutes = (totalSeconds - hours * 3600) / 60; uint32_t seconds = (totalSeconds - hours * 3600 - minutes * 60); INFO("File size: %"PRIu64" bytes; Duration: %u:%u:%u (%u sec); Optimal bandwidth: %.2f kb/s", _mediaFile.Size(), hours, minutes, seconds, totalSeconds, (double) _streamCapabilities.bandwidthHint); } moveFile(_seekFilePath + ".tmp", _seekFilePath); moveFile(_metaFilePath + ".tmp", _metaFilePath); chmod(STR(_seekFilePath), S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP); chmod(STR(_metaFilePath), S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP); return true; }