Skip to content

Commit 20c3306

Browse files
authored
Merge pull request #287 from cchampet/fix_analyseInputFileOnWindows
FileProperties: fix InputFile analysis
2 parents f8044f8 + 499097a commit 20c3306

File tree

2 files changed

+23
-28
lines changed

2 files changed

+23
-28
lines changed

src/AvTranscoder/properties/FileProperties.cpp

Lines changed: 22 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ FileProperties::FileProperties(const InputFile& file)
1515
: _file(file)
1616
, _formatContext(&file.getFormatContext())
1717
, _avFormatContext(&file.getFormatContext().getAVFormatContext())
18+
, _streamsProperties()
1819
, _videoStreams()
1920
, _audioStreams()
2021
, _dataStreams()
@@ -36,7 +37,12 @@ void FileProperties::extractStreamProperties(IProgress& progress, const EAnalyse
3637
const_cast<InputFile&>(_file).seekAtFrame(0, AVSEEK_FLAG_BACKWARD);
3738

3839
// clear properties
39-
clearStreamProperties();
40+
_videoStreams.clear();
41+
_audioStreams.clear();
42+
_dataStreams.clear();
43+
_subtitleStreams.clear();
44+
_attachementStreams.clear();
45+
_unknownStreams.clear();
4046

4147
// reload properties
4248
for(size_t streamIndex = 0; streamIndex < _formatContext->getNbStreams(); ++streamIndex)
@@ -86,41 +92,44 @@ void FileProperties::extractStreamProperties(IProgress& progress, const EAnalyse
8692
}
8793
}
8894

95+
// clear streams
96+
_streamsProperties.clear();
97+
8998
// once the streams vectors are filled, add their references the base streams vector
9099
for(size_t streamIndex = 0; streamIndex < _videoStreams.size(); ++streamIndex)
91100
{
92101
const size_t videoStreamIndex = _videoStreams.at(streamIndex).getStreamIndex();
93-
_streams[videoStreamIndex] = &_videoStreams.at(streamIndex);
102+
_streamsProperties[videoStreamIndex] = &_videoStreams.at(streamIndex);
94103
}
95104

96105
for(size_t streamIndex = 0; streamIndex < _audioStreams.size(); ++streamIndex)
97106
{
98107
const size_t audioStreamIndex = _audioStreams.at(streamIndex).getStreamIndex();
99-
_streams[audioStreamIndex] = &_audioStreams.at(streamIndex);
108+
_streamsProperties[audioStreamIndex] = &_audioStreams.at(streamIndex);
100109
}
101110

102111
for(size_t streamIndex = 0; streamIndex < _dataStreams.size(); ++streamIndex)
103112
{
104113
const size_t dataStreamIndex = _dataStreams.at(streamIndex).getStreamIndex();
105-
_streams[dataStreamIndex] = &_dataStreams.at(streamIndex);
114+
_streamsProperties[dataStreamIndex] = &_dataStreams.at(streamIndex);
106115
}
107116

108117
for(size_t streamIndex = 0; streamIndex < _subtitleStreams.size(); ++streamIndex)
109118
{
110119
const size_t subtitleStreamIndex = _subtitleStreams.at(streamIndex).getStreamIndex();
111-
_streams[subtitleStreamIndex] = &_subtitleStreams.at(streamIndex);
120+
_streamsProperties[subtitleStreamIndex] = &_subtitleStreams.at(streamIndex);
112121
}
113122

114123
for(size_t streamIndex = 0; streamIndex < _attachementStreams.size(); ++streamIndex)
115124
{
116125
const size_t attachementStreamIndex = _attachementStreams.at(streamIndex).getStreamIndex();
117-
_streams[attachementStreamIndex] = &_attachementStreams.at(streamIndex);
126+
_streamsProperties[attachementStreamIndex] = &_attachementStreams.at(streamIndex);
118127
}
119128

120129
for(size_t streamIndex = 0; streamIndex < _unknownStreams.size(); ++streamIndex)
121130
{
122131
const size_t unknownStreamIndex = _unknownStreams.at(streamIndex).getStreamIndex();
123-
_streams[unknownStreamIndex] = &_unknownStreams.at(streamIndex);
132+
_streamsProperties[unknownStreamIndex] = &_unknownStreams.at(streamIndex);
124133
}
125134

126135
// Returns at the beginning of the stream after any deep analysis
@@ -216,19 +225,19 @@ size_t FileProperties::getPacketSize() const
216225

217226
const avtranscoder::StreamProperties& FileProperties::getStreamPropertiesWithIndex(const size_t streamIndex) const
218227
{
219-
avtranscoder::StreamProperties* properties = _streams.find(streamIndex)->second;
228+
avtranscoder::StreamProperties* properties = _streamsProperties.find(streamIndex)->second;
220229
if(properties)
221230
return *properties;
222-
std::stringstream os;
223-
os << "No stream properties correspond to stream at index ";
224-
os << streamIndex;
225-
throw std::runtime_error(os.str());
231+
std::stringstream msg;
232+
msg << "No stream properties correspond to stream at index ";
233+
msg << streamIndex;
234+
throw std::runtime_error(msg.str());
226235
}
227236

228237
const std::vector<avtranscoder::StreamProperties*> FileProperties::getStreamProperties() const
229238
{
230239
std::vector<avtranscoder::StreamProperties*> streams;
231-
for(std::map<size_t, StreamProperties*>::const_iterator it = _streams.begin(); it != _streams.end(); ++it)
240+
for(std::map<size_t, StreamProperties*>::const_iterator it = _streamsProperties.begin(); it != _streamsProperties.end(); ++it)
232241
{
233242
streams.push_back(it->second);
234243
}
@@ -373,18 +382,6 @@ std::string FileProperties::allPropertiesAsJson() const
373382
return writer.build();
374383
}
375384

376-
void FileProperties::clearStreamProperties()
377-
{
378-
_streams.clear();
379-
380-
_videoStreams.clear();
381-
_audioStreams.clear();
382-
_dataStreams.clear();
383-
_subtitleStreams.clear();
384-
_attachementStreams.clear();
385-
_unknownStreams.clear();
386-
}
387-
388385
std::ostream& operator<<(std::ostream& flux, const FileProperties& fileProperties)
389386
{
390387
flux << std::left;

src/AvTranscoder/properties/FileProperties.hpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -107,15 +107,13 @@ class AvExport FileProperties
107107
}
108108
#endif
109109

110-
void clearStreamProperties(); ///< Clear all array of stream properties
111-
112110
private:
113111
const InputFile& _file; ///< Has link (no ownership)
114112
const FormatContext* _formatContext; ///< Has link (no ownership)
115113
const AVFormatContext* _avFormatContext; ///< Has link (no ownership)
116114

117115
std::map<size_t, StreamProperties*>
118-
_streams; ///< Map of properties per stream index (of all types) - only references to the following properties
116+
_streamsProperties; ///< Map of properties per stream index (of all types) - only references to the following properties
119117

120118
std::vector<VideoProperties> _videoStreams; ///< Array of properties per video stream
121119
std::vector<AudioProperties> _audioStreams; ///< Array of properties per audio stream

0 commit comments

Comments
 (0)