From 1443a1ae845233f1fa853b11a32c1b120e123854 Mon Sep 17 00:00:00 2001 From: Clement Champetier Date: Wed, 22 Apr 2015 12:28:49 +0200 Subject: [PATCH] FormatContext: add flag parameter to the seek function --- src/AvTranscoder/file/FormatContext.cpp | 4 ++-- src/AvTranscoder/file/FormatContext.hpp | 7 ++++--- src/AvTranscoder/file/InputFile.cpp | 4 ++-- src/AvTranscoder/mediaProperty/FileProperties.cpp | 4 ++-- 4 files changed, 10 insertions(+), 9 deletions(-) diff --git a/src/AvTranscoder/file/FormatContext.cpp b/src/AvTranscoder/file/FormatContext.cpp index f19f3102..4c3c070b 100644 --- a/src/AvTranscoder/file/FormatContext.cpp +++ b/src/AvTranscoder/file/FormatContext.cpp @@ -133,12 +133,12 @@ AVStream& FormatContext::addAVStream( const AVCodec& avCodec ) return *stream; } -void FormatContext::seek( uint64_t position ) +void FormatContext::seek( uint64_t position, const int flag ) { if( (int)getStartTime() != AV_NOPTS_VALUE ) position += getStartTime(); - if( av_seek_frame( _avFormatContext, -1, position, AVSEEK_FLAG_BACKWARD ) < 0 ) + if( av_seek_frame( _avFormatContext, -1, position, flag ) < 0 ) { LOG_ERROR( "Error when seek at " << position << " (in AV_TIME_BASE units) in file" ) } diff --git a/src/AvTranscoder/file/FormatContext.hpp b/src/AvTranscoder/file/FormatContext.hpp index 394410d8..219e7dbc 100644 --- a/src/AvTranscoder/file/FormatContext.hpp +++ b/src/AvTranscoder/file/FormatContext.hpp @@ -62,11 +62,12 @@ class AvExport FormatContext AVStream& addAVStream( const AVCodec& avCodec ); /** - * @brief Seek at a specific position (in AV_TIME_BASE units) + * @brief Seek at a specific position + * @param position: can be in AV_TIME_BASE units, in frames... depending on the flag value + * @param flag: seeking mode (AVSEEK_FLAG_xxx) * @note before seek, add offset of start time - * @note after seek, clear buffering of streams */ - void seek( uint64_t position ); + void seek( uint64_t position, const int flag ); size_t getNbStreams() const { return _avFormatContext->nb_streams; } /// Get duration of the program, in seconds diff --git a/src/AvTranscoder/file/InputFile.cpp b/src/AvTranscoder/file/InputFile.cpp index 983a9c0c..ace44270 100644 --- a/src/AvTranscoder/file/InputFile.cpp +++ b/src/AvTranscoder/file/InputFile.cpp @@ -86,13 +86,13 @@ bool InputFile::readNextPacket( CodedData& data, const size_t streamIndex ) void InputFile::seekAtFrame( const size_t frame ) { uint64_t position = frame / getFps() * AV_TIME_BASE; - _formatContext.seek( position ); + _formatContext.seek( position, AVSEEK_FLAG_BACKWARD ); } void InputFile::seekAtTime( const double time ) { uint64_t position = time * AV_TIME_BASE; - _formatContext.seek( position ); + _formatContext.seek( position, AVSEEK_FLAG_BACKWARD ); } void InputFile::activateStream( const size_t streamIndex, bool activate ) diff --git a/src/AvTranscoder/mediaProperty/FileProperties.cpp b/src/AvTranscoder/mediaProperty/FileProperties.cpp index e0dc9ac0..483e5ab9 100644 --- a/src/AvTranscoder/mediaProperty/FileProperties.cpp +++ b/src/AvTranscoder/mediaProperty/FileProperties.cpp @@ -31,7 +31,7 @@ void FileProperties::extractStreamProperties( IProgress& progress, const EAnalys // if the analysis level wiil decode some streams parts, seek at the beginning if( level > eAnalyseLevelHeader ) - const_cast( _formatContext )->seek( 0 ); + const_cast( _formatContext )->seek( 0, AVSEEK_FLAG_BACKWARD ); for( size_t streamIndex = 0; streamIndex < _formatContext->getNbStreams(); ++streamIndex ) { @@ -88,7 +88,7 @@ void FileProperties::extractStreamProperties( IProgress& progress, const EAnalys // if the analysis level has decoded some streams parts, return at the beginning if( level > eAnalyseLevelHeader ) - const_cast( _formatContext )->seek( 0 ); + const_cast( _formatContext )->seek( 0, AVSEEK_FLAG_BACKWARD ); } std::string FileProperties::getFilename() const