YGG_API void FrameStreamWriter::Flush(Path path) { if (!path) throw Exception("FrameStreamWriter: path was empty"); if (!path.IsFile()) throw Exception(Concatenate("FrameStreamWriter: \"", path.Absolute(), "\" is not a valid file path")); std::ofstream outStream((ystr)path, std::ios::out | std::ios::binary); if (!outStream) throw Exception(Concatenate("FrameStreamWriter: \"", path.Absolute(), "\" could not be opened for writing.")); //metadata if (metadata) { Write(outStream, (uint64_t)metadata.Size()); outStream.write((const char*)metadata.Data(), metadata.Size()); } else Write(outStream, 0ull); //total frame count Write(outStream, currentFrame); //duration Write(outStream, duration); //key frames Write(outStream, (uint64_t)keyFrames.size()); //key frame count (outStream).write((const char*)keyFrames.data(), keyFrames.size() * sizeof(uint64_t)); //frame datasets Write(outStream, (uint64_t)frameData.size()); //frame data stream count for (auto& fd : frameData) { //key hash Write(outStream, fd.first); //element size Write(outStream, fd.second->ElementSize); //frames Write(outStream, (uint64_t)fd.second->Frames.size()); for (size_t i = 0u; i < fd.second->Frames.size(); ++i) { //frame number Write(outStream, fd.second->Frames[i]); //data (outStream).write((const char*)fd.second->Data[i], fd.second->ElementSize); } } outStream.close(); }
YGG_API FrameStreamReader::FrameStreamReader(Path path) { if (!path) throw Exception("FrameStreamReader: path was empty"); if (!path.IsExtantFile()) throw Exception(Concatenate(YL("The path \""), path.Absolute(), "\" did not exist.")); file.reset(new MappedFile(path)); data = (uint8_t*)file->Data(); Initialize(); }