Fixes no EOF being sent for ffmpeg read function
All checks were successful
Build and Push Docker Image / build-and-push (push) Successful in 4m4s

This commit is contained in:
2025-11-14 23:33:14 -05:00
parent eca382f0e3
commit ff7e46f2c5
2 changed files with 29 additions and 7 deletions

View File

@@ -3,13 +3,11 @@
//
#include "FFMPEGMetadata.hpp"
#include <array>
#include <cstring>
#include <iostream>
#include <memory>
#include "ffmpeg.hpp"
#include "fgl/defines.hpp"
extern "C" {
#include <libavcodec/avcodec.h>
@@ -17,8 +15,6 @@ extern "C" {
#include <libswscale/swscale.h>
}
std::string_view FFMPEGMetadata::name()
{
return "Video Metadata Module";

View File

@@ -3,6 +3,9 @@
//
#pragma once
#include <libavutil/error.h>
#include <spdlog/spdlog.h>
extern "C" {
#include <libavformat/avio.h>
}
@@ -10,6 +13,11 @@ extern "C" {
#include <cstdint>
#include <string_view>
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;
}