From ff7e46f2c534fa6d1f56fbe1a7f8a09b0f3232b5 Mon Sep 17 00:00:00 2001 From: kj16609 Date: Fri, 14 Nov 2025 23:33:14 -0500 Subject: [PATCH] Fixes no EOF being sent for ffmpeg read function --- IDHANModules/premade/FFMPEGMetadata.cpp | 4 ---- IDHANModules/premade/ffmpeg.hpp | 32 ++++++++++++++++++++++--- 2 files changed, 29 insertions(+), 7 deletions(-) diff --git a/IDHANModules/premade/FFMPEGMetadata.cpp b/IDHANModules/premade/FFMPEGMetadata.cpp index ce97cdf..87f7ee0 100644 --- a/IDHANModules/premade/FFMPEGMetadata.cpp +++ b/IDHANModules/premade/FFMPEGMetadata.cpp @@ -3,13 +3,11 @@ // #include "FFMPEGMetadata.hpp" -#include #include #include #include #include "ffmpeg.hpp" -#include "fgl/defines.hpp" extern "C" { #include @@ -17,8 +15,6 @@ extern "C" { #include } - - std::string_view FFMPEGMetadata::name() { return "Video Metadata Module"; diff --git a/IDHANModules/premade/ffmpeg.hpp b/IDHANModules/premade/ffmpeg.hpp index 5c791ff..b9e18f5 100644 --- a/IDHANModules/premade/ffmpeg.hpp +++ b/IDHANModules/premade/ffmpeg.hpp @@ -3,6 +3,9 @@ // #pragma once +#include +#include + extern "C" { #include } @@ -10,6 +13,11 @@ extern "C" { #include #include +namespace idhan +{ +namespace log = spdlog; +} + struct OpaqueInfo { std::string_view m_data; @@ -20,40 +28,58 @@ inline int readFunction( void* opaque, std::uint8_t* buffer, int buffer_size ) { auto& buffer_view { *static_cast< OpaqueInfo* >( opaque ) }; + const bool cursor_oob { buffer_view.m_cursor > buffer_view.m_data.size() }; + if ( cursor_oob ) return AVERROR_EOF; + auto* data { buffer_view.m_data.data() }; - if ( buffer_view.m_cursor >= buffer_view.m_data.size() ) return 0; data += buffer_view.m_cursor; const std::int64_t size { static_cast< std::int64_t >( buffer_view.m_data.size() ) - buffer_view.m_cursor }; const std::int64_t min_size { std::min( size, static_cast< std::int64_t >( buffer_size ) ) }; + + if ( min_size == 0 ) return AVERROR_EOF; + std::memcpy( buffer, data, min_size ); buffer_view.m_cursor += min_size; - return min_size; + return static_cast< int >( min_size ); } inline std::int64_t seekFunction( void* opaque, std::int64_t offset, int whence ) { auto& buffer_view { *static_cast< OpaqueInfo* >( opaque ) }; + idhan::log::info( "Asked to seek from whence {} and offset {}", whence, offset ); switch ( whence ) { case SEEK_SET: + idhan::log::info( "Asked to seek to specific offset {}", offset ); buffer_view.m_cursor = offset; break; case SEEK_CUR: + idhan::log::info( "Asked to seek to an +{} from cursor", offset ); buffer_view.m_cursor += offset; break; case SEEK_END: + idhan::log::info( "Asked to seek to end" ); buffer_view.m_cursor = static_cast< std::int64_t >( buffer_view.m_data.size() ) + offset; break; case AVSEEK_SIZE: + idhan::log::info( "Asked to seek size" ); return static_cast< std::int64_t >( buffer_view.m_data.size() ); default: - return -1; + { + idhan::log::info( "Asked to seek to whence that ended in default" ); + return -1; + } } + if ( buffer_view.m_cursor < 0 ) + buffer_view.m_cursor = 0; + else if ( buffer_view.m_cursor >= buffer_view.m_data.size() ) + buffer_view.m_cursor = buffer_view.m_data.size(); + return buffer_view.m_cursor; }