Skip to content

Commit e65a4ca

Browse files
author
Clement Champetier
committed
InputStream: fix get properties of stream
Warning: getVideoProperties().at(index) != getVideoPropertiesWithStreamIndex(index)
1 parent d648898 commit e65a4ca

File tree

2 files changed

+61
-0
lines changed

2 files changed

+61
-0
lines changed

src/AvTranscoder/mediaProperty/FileProperties.cpp

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,54 @@ size_t FileProperties::getPacketSize() const
7474
return _formatContext->packet_size;
7575
}
7676

77+
VideoProperties& FileProperties::getVideoPropertiesWithStreamIndex( const size_t streamIndex )
78+
{
79+
for( std::vector< VideoProperties >::iterator it = _videoStreams.begin(); it != _videoStreams.end(); ++it )
80+
{
81+
if( it->getStreamIndex() == streamIndex )
82+
return *it;
83+
}
84+
std::string msg( "no video properties correspond to stream at index " );
85+
msg += streamIndex;
86+
throw std::runtime_error( msg );
87+
}
88+
89+
const avtranscoder::VideoProperties& FileProperties::getVideoPropertiesWithStreamIndex( const size_t streamIndex ) const
90+
{
91+
for( std::vector< VideoProperties >::const_iterator it = _videoStreams.begin(); it != _videoStreams.end(); ++it )
92+
{
93+
if( it->getStreamIndex() == streamIndex )
94+
return *it;
95+
}
96+
std::string msg( "no video properties correspond to stream at index " );
97+
msg += streamIndex;
98+
throw std::runtime_error( msg );
99+
}
100+
101+
AudioProperties& FileProperties::getAudioPropertiesWithStreamIndex( const size_t streamIndex )
102+
{
103+
for( std::vector< AudioProperties >::iterator it = _audioStreams.begin(); it != _audioStreams.end(); ++it )
104+
{
105+
if( it->getStreamIndex() == streamIndex )
106+
return *it;
107+
}
108+
std::string msg( "no audio properties correspond to stream at index " );
109+
msg += streamIndex;
110+
throw std::runtime_error( msg );
111+
}
112+
113+
const avtranscoder::AudioProperties& FileProperties::getAudioPropertiesWithStreamIndex( const size_t streamIndex ) const
114+
{
115+
for( std::vector< AudioProperties >::const_iterator it = _audioStreams.begin(); it != _audioStreams.end(); ++it )
116+
{
117+
if( it->getStreamIndex() == streamIndex )
118+
return *it;
119+
}
120+
std::string msg( "no audio properties correspond to stream at index " );
121+
msg += streamIndex;
122+
throw std::runtime_error( msg );
123+
}
124+
77125
size_t FileProperties::getNbStreams() const
78126
{
79127
if( ! _formatContext )

src/AvTranscoder/mediaProperty/FileProperties.hpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,15 +42,28 @@ class AvExport FileProperties
4242
size_t getNbAttachementStreams() const { return _attachementStreams.size(); }
4343
size_t getNbUnknownStreams() const { return _unknownStreams.size(); }
4444

45+
//@{
46+
// @brief Get the properties with the indicated stream index
47+
avtranscoder::VideoProperties& getVideoPropertiesWithStreamIndex( const size_t streamIndex );
48+
avtranscoder::AudioProperties& getAudioPropertiesWithStreamIndex( const size_t streamIndex );
49+
//@}
50+
51+
//@{
52+
// @brief Get the list of properties for a given type (video, audio...)
4553
std::vector< avtranscoder::VideoProperties >& getVideoProperties() { return _videoStreams; }
4654
std::vector< avtranscoder::AudioProperties >& getAudioProperties() { return _audioStreams; }
4755
std::vector< avtranscoder::DataProperties >& getDataProperties() { return _dataStreams; }
4856
std::vector< avtranscoder::SubtitleProperties >& getSubtitleProperties() { return _subtitleStreams; }
4957
std::vector< avtranscoder::AttachementProperties >& getAttachementProperties() { return _attachementStreams; }
5058
std::vector< avtranscoder::UnknownProperties >& getUnknownPropertiesProperties() { return _unknownStreams; }
59+
//@}
5160

5261
#ifndef SWIG
5362
const AVFormatContext& getAVFormatContext() { return *_formatContext; }
63+
64+
const avtranscoder::VideoProperties& getVideoPropertiesWithStreamIndex( const size_t streamIndex ) const;
65+
const avtranscoder::AudioProperties& getAudioPropertiesWithStreamIndex( const size_t streamIndex ) const;
66+
5467
const std::vector< avtranscoder::VideoProperties >& getVideoProperties() const { return _videoStreams; }
5568
const std::vector< avtranscoder::AudioProperties >& getAudioProperties() const { return _audioStreams; }
5669
const std::vector< avtranscoder::DataProperties >& getDataProperties() const { return _dataStreams; }

0 commit comments

Comments
 (0)