From 60385aa34746327cabc1bfdb2190027d6b21e9e5 Mon Sep 17 00:00:00 2001 From: Martchus Date: Sun, 23 Apr 2023 20:55:47 +0200 Subject: [PATCH] Generalize copy functions in GenericFileElement to eventually use sendfile64() Since we're still using `container().stream()` in `copyInternal()` this change is still not really effective. --- genericfileelement.h | 36 ++++++++++++++++++++++----------- matroska/matroskaattachment.cpp | 2 ++ matroska/matroskacues.cpp | 2 ++ 3 files changed, 28 insertions(+), 12 deletions(-) diff --git a/genericfileelement.h b/genericfileelement.h index e5d0adf..9f21444 100644 --- a/genericfileelement.h +++ b/genericfileelement.h @@ -116,13 +116,17 @@ public: static constexpr std::uint32_t maximumIdLengthSupported(); static constexpr std::uint32_t maximumSizeLengthSupported(); static constexpr std::uint8_t minimumElementSize(); - void copyHeader(std::ostream &targetStream, Diagnostics &diag, AbortableProgressFeedback *progress); - void copyWithoutChilds(std::ostream &targetStream, Diagnostics &diag, AbortableProgressFeedback *progress); - void copyEntirely(std::ostream &targetStream, Diagnostics &diag, AbortableProgressFeedback *progress); + template + void copyHeader(TargetStream &targetStream, Diagnostics &diag, AbortableProgressFeedback *progress); + template + void copyWithoutChilds(TargetStream &targetStream, Diagnostics &diag, AbortableProgressFeedback *progress); + template + void copyEntirely(TargetStream &targetStream, Diagnostics &diag, AbortableProgressFeedback *progress); void makeBuffer(); void discardBuffer(); - void copyBuffer(std::ostream &targetStream); - void copyPreferablyFromBuffer(std::ostream &targetStream, Diagnostics &diag, AbortableProgressFeedback *progress); + template void copyBuffer(TargetStream &targetStream); + template + void copyPreferablyFromBuffer(TargetStream &targetStream, Diagnostics &diag, AbortableProgressFeedback *progress); const std::unique_ptr &buffer(); ImplementationType *denoteFirstChild(std::uint32_t offset); @@ -139,8 +143,9 @@ protected: std::unique_ptr m_buffer; private: + template void copyInternal( - std::ostream &targetStream, std::uint64_t startOffset, std::uint64_t bytesToCopy, Diagnostics &diag, AbortableProgressFeedback *progress); + TargetStream &targetStream, std::uint64_t startOffset, std::uint64_t bytesToCopy, Diagnostics &diag, AbortableProgressFeedback *progress); ContainerType *m_container; bool m_parsed; @@ -840,7 +845,8 @@ void GenericFileElement::validateSubsequentElementStructure( * \brief Writes the header information of the element to the specified \a targetStream. */ template -void GenericFileElement::copyHeader(std::ostream &targetStream, Diagnostics &diag, AbortableProgressFeedback *progress) +template +void GenericFileElement::copyHeader(TargetStream &targetStream, Diagnostics &diag, AbortableProgressFeedback *progress) { copyInternal(targetStream, startOffset(), headerSize(), diag, progress); } @@ -849,7 +855,8 @@ void GenericFileElement::copyHeader(std::ostream &targetStre * \brief Writes the element without its children to the specified \a targetStream. */ template -void GenericFileElement::copyWithoutChilds(std::ostream &targetStream, Diagnostics &diag, AbortableProgressFeedback *progress) +template +void GenericFileElement::copyWithoutChilds(TargetStream &targetStream, Diagnostics &diag, AbortableProgressFeedback *progress) { if (std::uint32_t firstChildOffset = this->firstChildOffset()) { copyInternal(targetStream, startOffset(), firstChildOffset, diag, progress); @@ -862,7 +869,8 @@ void GenericFileElement::copyWithoutChilds(std::ostream &tar * \brief Writes the entire element including all children to the specified \a targetStream. */ template -void GenericFileElement::copyEntirely(std::ostream &targetStream, Diagnostics &diag, AbortableProgressFeedback *progress) +template +void GenericFileElement::copyEntirely(TargetStream &targetStream, Diagnostics &diag, AbortableProgressFeedback *progress) { copyInternal(targetStream, startOffset(), totalSize(), diag, progress); } @@ -890,7 +898,9 @@ template inline void GenericFileElement inline void GenericFileElement::copyBuffer(std::ostream &targetStream) +template +template +inline void GenericFileElement::copyBuffer(TargetStream &targetStream) { targetStream.write(m_buffer.get(), static_cast(totalSize())); } @@ -900,8 +910,9 @@ template inline void GenericFileElement +template inline void GenericFileElement::copyPreferablyFromBuffer( - std::ostream &targetStream, Diagnostics &diag, AbortableProgressFeedback *progress) + TargetStream &targetStream, Diagnostics &diag, AbortableProgressFeedback *progress) { m_buffer ? copyBuffer(targetStream) : copyEntirely(targetStream, diag, progress); } @@ -923,8 +934,9 @@ template inline const std::unique_ptr &Generi * \sa copyEntireAtomToStream() */ template +template void GenericFileElement::copyInternal( - std::ostream &targetStream, std::uint64_t startOffset, std::uint64_t bytesToCopy, Diagnostics &diag, AbortableProgressFeedback *progress) + TargetStream &targetStream, std::uint64_t startOffset, std::uint64_t bytesToCopy, Diagnostics &diag, AbortableProgressFeedback *progress) { // ensure the header has been parsed correctly try { diff --git a/matroska/matroskaattachment.cpp b/matroska/matroskaattachment.cpp index 5ed0583..8db1f32 100644 --- a/matroska/matroskaattachment.cpp +++ b/matroska/matroskaattachment.cpp @@ -3,6 +3,8 @@ #include "./matroskacontainer.h" #include "./matroskaid.h" +#include "../mediafileinfo.h" + #include #include diff --git a/matroska/matroskacues.cpp b/matroska/matroskacues.cpp index b3a2b58..55d269e 100644 --- a/matroska/matroskacues.cpp +++ b/matroska/matroskacues.cpp @@ -1,6 +1,8 @@ #include "./matroskacues.h" #include "./matroskacontainer.h" +#include "../mediafileinfo.h" + #include using namespace std;