Skip to content

Commit 42f78c9

Browse files
author
Clement Champetier
committed
FileProperties: update how to construct the properties
* Keep a reference to the InputFile. * This new reference will be used to refactor the decoding in case of deep analysis.
1 parent 163a02a commit 42f78c9

File tree

5 files changed

+15
-13
lines changed

5 files changed

+15
-13
lines changed

src/AvTranscoder/file/InputFile.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ InputFile::InputFile(const std::string& filename)
3030
_formatContext.findStreamInfo();
3131

3232
// Get the stream information as properties
33-
_properties = new FileProperties(_formatContext);
33+
_properties = new FileProperties(*this);
3434

3535
// Create streams
3636
for(size_t streamIndex = 0; streamIndex < _formatContext.getNbStreams(); ++streamIndex)

src/AvTranscoder/file/InputFile.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ class AvExport InputFile
7979

8080
std::string getFilename() const { return _filename; }
8181

82-
FormatContext& getFormatContext() { return _formatContext; }
82+
const FormatContext& getFormatContext() const { return _formatContext; }
8383

8484
/**
8585
* @brief Set the format of the input file

src/AvTranscoder/properties/FileProperties.cpp

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,10 @@
1111
namespace avtranscoder
1212
{
1313

14-
FileProperties::FileProperties(const FormatContext& formatContext)
15-
: _formatContext(&formatContext)
16-
, _avFormatContext(&formatContext.getAVFormatContext())
14+
FileProperties::FileProperties(const InputFile& file)
15+
: _file(file)
16+
, _formatContext(&file.getFormatContext())
17+
, _avFormatContext(&file.getFormatContext().getAVFormatContext())
1718
, _videoStreams()
1819
, _audioStreams()
1920
, _dataStreams()
@@ -31,8 +32,8 @@ FileProperties::FileProperties(const FormatContext& formatContext)
3132
void FileProperties::extractStreamProperties(IProgress& progress, const EAnalyseLevel level)
3233
{
3334
// Returns at the beginning of the stream before any deep analysis
34-
if(level > eAnalyseLevelHeader && !isRawFormat())
35-
const_cast<FormatContext*>(_formatContext)->seek(0, AVSEEK_FLAG_BACKWARD);
35+
if(level > eAnalyseLevelHeader && ! isRawFormat())
36+
const_cast<InputFile&>(_file).seekAtFrame(0, AVSEEK_FLAG_BACKWARD);
3637

3738
// clear properties
3839
clearStreamProperties();
@@ -123,8 +124,8 @@ void FileProperties::extractStreamProperties(IProgress& progress, const EAnalyse
123124
}
124125

125126
// Returns at the beginning of the stream after any deep analysis
126-
if(level > eAnalyseLevelHeader && !isRawFormat())
127-
const_cast<FormatContext*>(_formatContext)->seek(0, AVSEEK_FLAG_BACKWARD);
127+
if(level > eAnalyseLevelHeader && ! isRawFormat())
128+
const_cast<InputFile&>(_file).seekAtFrame(0, AVSEEK_FLAG_BACKWARD);
128129
}
129130

130131
std::string FileProperties::getFilename() const

src/AvTranscoder/properties/FileProperties.hpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
#include <AvTranscoder/common.hpp>
55
#include <AvTranscoder/properties/util.hpp>
6-
#include <AvTranscoder/file/FormatContext.hpp>
6+
#include <AvTranscoder/file/InputFile.hpp>
77
#include <AvTranscoder/progress/IProgress.hpp>
88

99
#include <AvTranscoder/properties/StreamProperties.hpp>
@@ -29,7 +29,7 @@ class AvExport FileProperties
2929
* @note The default streams analyse level is eAnalyseLevelHeader
3030
* @see FormatContext
3131
*/
32-
FileProperties(const FormatContext& formatContext);
32+
FileProperties(const InputFile& file);
3333

3434
/**
3535
* @brief Relaunch streams analysis with a specific level.
@@ -62,7 +62,7 @@ class AvExport FileProperties
6262
size_t getNbAttachementStreams() const { return _attachementStreams.size(); }
6363
size_t getNbUnknownStreams() const { return _unknownStreams.size(); }
6464

65-
const FormatContext& getFormatContext() const { return *_formatContext; }
65+
const InputFile& getInputFile() const { return _file; }
6666

6767
//@{
6868
// @brief Get the properties at the indicated stream index
@@ -110,6 +110,7 @@ class AvExport FileProperties
110110
void clearStreamProperties(); ///< Clear all array of stream properties
111111

112112
private:
113+
const InputFile& _file; ///< Has link (no ownership)
113114
const FormatContext* _formatContext; ///< Has link (no ownership)
114115
const AVFormatContext* _avFormatContext; ///< Has link (no ownership)
115116

src/AvTranscoder/properties/VideoProperties.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -559,7 +559,7 @@ void VideoProperties::analyseGopStructure(IProgress& progress)
559559
avcodec_close(_codecContext);
560560

561561
// Returns at the beginning of the stream
562-
const_cast<FormatContext*>(&_fileProperties->getFormatContext())->seek(0, AVSEEK_FLAG_BYTE);
562+
const_cast<InputFile&>(_fileProperties->getInputFile()).seekAtFrame(0, AVSEEK_FLAG_BYTE);
563563

564564
// Check GOP size
565565
if(_gopSize <= 0)

0 commit comments

Comments
 (0)