Skip to content

Commit 108b7df

Browse files
author
Clement Champetier
committed
Move InputFile::seek to FormatContext::seek
Note: remove useless InputStreams clearBuffering call.
1 parent 05a6237 commit 108b7df

File tree

4 files changed

+20
-25
lines changed

4 files changed

+20
-25
lines changed

src/AvTranscoder/file/FormatContext.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,17 @@ AVStream& FormatContext::addAVStream( const AVCodec& avCodec )
133133
return *stream;
134134
}
135135

136+
void FormatContext::seek( uint64_t position )
137+
{
138+
if( (int)getStartTime() != AV_NOPTS_VALUE )
139+
position += getStartTime();
140+
141+
if( av_seek_frame( _avFormatContext, -1, position, AVSEEK_FLAG_BACKWARD ) < 0 )
142+
{
143+
LOG_ERROR( "Error when seek at " << position << " (in AV_TIME_BASE units) in file" )
144+
}
145+
}
146+
136147
std::vector<Option> FormatContext::getOptions()
137148
{
138149
std::vector<Option> optionsArray;

src/AvTranscoder/file/FormatContext.hpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,13 @@ class AvExport FormatContext
6161
void addMetaData( const std::string& key, const std::string& value );
6262
AVStream& addAVStream( const AVCodec& avCodec );
6363

64+
/**
65+
* @brief Seek at a specific position (in AV_TIME_BASE units)
66+
* @note before seek, add offset of start time
67+
* @note after seek, clear buffering of streams
68+
*/
69+
void seek( uint64_t position );
70+
6471
size_t getNbStreams() const { return _avFormatContext->nb_streams; }
6572
/// Get duration of the program, in seconds
6673
size_t getDuration() const { return _avFormatContext->duration; }

src/AvTranscoder/file/InputFile.cpp

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -144,29 +144,13 @@ bool InputFile::readNextPacket( CodedData& data, const size_t streamIndex )
144144
void InputFile::seekAtFrame( const size_t frame )
145145
{
146146
uint64_t position = frame / getFps() * AV_TIME_BASE;
147-
seek( position );
147+
_formatContext.seek( position );
148148
}
149149

150150
void InputFile::seekAtTime( const double time )
151151
{
152152
uint64_t position = time * AV_TIME_BASE;
153-
seek( position );
154-
}
155-
156-
void InputFile::seek( uint64_t position )
157-
{
158-
if( (int)_formatContext.getStartTime() != AV_NOPTS_VALUE )
159-
position += _formatContext.getStartTime();
160-
161-
if( av_seek_frame( &_formatContext.getAVFormatContext(), -1, position, AVSEEK_FLAG_BACKWARD ) < 0 )
162-
{
163-
LOG_ERROR( "Error when seek at " << position << " (in AV_TIME_BASE units) in file" )
164-
}
165-
166-
for( std::vector<InputStream*>::iterator it = _inputStreams.begin(); it != _inputStreams.end(); ++it )
167-
{
168-
(*it)->clearBuffering();
169-
}
153+
_formatContext.seek( position );
170154
}
171155

172156
void InputFile::activateStream( const size_t streamIndex, bool activate )

src/AvTranscoder/file/InputFile.hpp

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -104,13 +104,6 @@ class AvExport InputFile
104104
*/
105105
double getFps();
106106

107-
/**
108-
* @brief Seek at a specific position (in AV_TIME_BASE units)
109-
* @note before seek, add offset of start time
110-
* @note after seek, clear buffering of streams
111-
*/
112-
void seek( uint64_t position );
113-
114107
protected:
115108
FormatContext _formatContext;
116109
FileProperties _properties;

0 commit comments

Comments
 (0)