Skip to content

Commit 456cff2

Browse files
author
Clement Champetier
committed
InputFile: refactore order of functions
Getters and setters together.
1 parent 3256bee commit 456cff2

File tree

2 files changed

+55
-44
lines changed

2 files changed

+55
-44
lines changed

src/AvTranscoder/file/InputFile.cpp

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -133,18 +133,6 @@ FileProperties InputFile::analyseFile( const std::string& filename, IProgress& p
133133
return file.getProperties();
134134
}
135135

136-
AVMediaType InputFile::getStreamType( size_t index )
137-
{
138-
if( index >= _formatContext->nb_streams )
139-
return AVMEDIA_TYPE_UNKNOWN;
140-
return _formatContext->streams[index]->codec->codec_type;
141-
}
142-
143-
AvInputStream& InputFile::getStream( size_t index )
144-
{
145-
return *_inputStreams.at( index );
146-
}
147-
148136
bool InputFile::readNextPacket( CodedData& data, const size_t streamIndex )
149137
{
150138
AVPacket packet;
@@ -199,6 +187,29 @@ void InputFile::activateStream( const size_t streamIndex, bool activate )
199187
_inputStreams.at( streamIndex )->activate( activate );
200188
}
201189

190+
AvInputStream& InputFile::getStream( size_t index )
191+
{
192+
try
193+
{
194+
return *_inputStreams.at( index );
195+
}
196+
catch( const std::out_of_range& e )
197+
{
198+
std::stringstream msg;
199+
msg << getFilename();
200+
msg << " has no stream at index ";
201+
msg << index;
202+
throw std::runtime_error( msg.str() );
203+
}
204+
}
205+
206+
AVMediaType InputFile::getStreamType( size_t index )
207+
{
208+
if( index >= _formatContext->nb_streams )
209+
return AVMEDIA_TYPE_UNKNOWN;
210+
return _formatContext->streams[index]->codec->codec_type;
211+
}
212+
202213
bool InputFile::isStreamActivated( const size_t streamIndex )
203214
{
204215
return _inputStreams.at( streamIndex )->isActivated();

src/AvTranscoder/file/InputFile.hpp

Lines changed: 32 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -36,45 +36,13 @@ class AvExport InputFile
3636

3737
virtual ~InputFile();
3838

39-
/**
40-
* @return Return the resource to access
41-
**/
42-
std::string getFilename() const { return _filename; }
43-
4439
/**
4540
* @brief Run the analyse on the file after a setup.
4641
* call this function before getProperties().
4742
* @param progress callback to get analysis progression
4843
* @param level by default eAnalyseLevelFirstGop
4944
**/
5045
void analyse( IProgress& progress, const EAnalyseLevel level = eAnalyseLevelFirstGop );
51-
52-
/**
53-
* @brief Return media properties on the current InputFile.
54-
* @note require to launch analyse() before to fill the property struture
55-
* @return structure of media metadatas
56-
**/
57-
const FileProperties& getProperties() const { return _properties; }
58-
59-
/**
60-
* @brief Get stream type: video, audio, subtitle, etc.
61-
* @param index stream index
62-
* @return media stream type of specified index stream
63-
**/
64-
AVMediaType getStreamType( size_t index );
65-
66-
/**
67-
* @brief Get stream type: video, audio, subtitle, etc.
68-
* @param index stream index
69-
* @return media stream type of specified index stream
70-
**/
71-
AvInputStream& getStream( size_t index );
72-
73-
/**
74-
* @brief Get LibAV/FFmpeg AVFormatContext
75-
* @return format context on current InputFile
76-
**/
77-
AVFormatContext& getAVFormatContext() const { return *_formatContext; }
7846

7947
/**
8048
* @brief Read the next packet of the specified stream
@@ -95,11 +63,43 @@ class AvExport InputFile
9563
* @note Activate a stream results in buffered its data when processing
9664
**/
9765
void activateStream( const size_t streamIndex, const bool activate = true );
66+
67+
/**
68+
* @return Return the resource to access
69+
**/
70+
std::string getFilename() const { return _filename; }
71+
72+
/**
73+
* @brief Return media properties on the current InputFile.
74+
* @note require to launch analyse() before to fill the property struture
75+
* @return structure of media metadatas
76+
**/
77+
const FileProperties& getProperties() const { return _properties; }
78+
79+
/**
80+
* @brief Get stream type: video, audio, subtitle, etc.
81+
* @param index stream index
82+
* @return media stream type of specified index stream
83+
**/
84+
AvInputStream& getStream( size_t index );
85+
86+
/**
87+
* @brief Get stream type: video, audio, subtitle, etc.
88+
* @param index stream index
89+
* @return media stream type of specified index stream
90+
**/
91+
AVMediaType getStreamType( size_t index );
9892

9993
/**
10094
* @brief Indicate that the stream is activated
10195
**/
10296
bool isStreamActivated( const size_t streamIndex );
97+
98+
/**
99+
* @brief Get LibAV/FFmpeg AVFormatContext
100+
* @return format context on current InputFile
101+
**/
102+
AVFormatContext& getAVFormatContext() const { return *_formatContext; }
103103

104104
/**
105105
* @brief Set the format of the input file

0 commit comments

Comments
 (0)