Skip to content

Commit e6edcbc

Browse files
update input API
1 parent f6fc8b7 commit e6edcbc

File tree

5 files changed

+33
-16
lines changed

5 files changed

+33
-16
lines changed

src/AvTranscoder/InputFile.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,11 @@ InputFile::InputFile( const std::string& filename )
4242
m_formatContext = NULL;
4343
throw std::runtime_error( "unable to find stream informations" );
4444
}
45+
46+
for( size_t streamIndex = 0; streamIndex < m_formatContext->nb_streams; ++streamIndex )
47+
{
48+
m_inputStreams.push_back( InputStream( m_filename, streamIndex ) );
49+
}
4550
}
4651

4752
InputFile::~InputFile()
@@ -118,9 +123,9 @@ InputFile& InputFile::analyse()
118123
return *this;
119124
}
120125

121-
InputStream InputFile::getStream( size_t index )
126+
InputStream& InputFile::getStream( size_t index )
122127
{
123-
return InputStream( m_filename, index );
128+
return m_inputStreams.at( index );
124129
}
125130

126131
}

src/AvTranscoder/InputFile.hpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,16 @@ class InputFile
2929
// *** Metadatas section ***
3030
// run the analyse on the file after a setup.
3131
InputFile& analyse();
32-
// get properties on the file
32+
/// get file properties
3333
const Properties& getProperties() const { return m_properties; }
3434

35-
InputStream getStream( size_t index );
35+
InputStream& getStream( size_t index );
3636

3737
protected:
38-
AVFormatContext* m_formatContext;
39-
Properties m_properties;
40-
std::string m_filename;
38+
AVFormatContext* m_formatContext;
39+
Properties m_properties;
40+
std::string m_filename;
41+
std::vector<InputStream> m_inputStreams;
4142
};
4243

4344
}

src/AvTranscoder/InputStream.cpp

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,16 +38,22 @@ bool InputStream::readNextPacket( DataStream& data ) const
3838
AVPacket packet;
3939
av_init_packet( &packet );
4040

41-
readNextPacket( packet );
42-
43-
// is it possible to remove this copy ?
44-
// using : av_packet_unref ?
45-
data.getBuffer().resize( packet.size );
46-
memcpy( data.getPtr(), packet.data, packet.size );
41+
if( readNextPacket( packet ) )
42+
{
43+
// is it possible to remove this copy ?
44+
// using : av_packet_unref ?
45+
data.getBuffer().resize( packet.size );
46+
if( packet.size != 0 )
47+
memcpy( data.getPtr(), packet.data, packet.size );
48+
}
49+
else
50+
{
51+
data.getBuffer().resize( 0 );
52+
}
4753

4854
av_free_packet( &packet );
4955

50-
return true;
56+
return data.getBuffer().size() != 0;
5157
}
5258

5359
bool InputStream::readNextPacket( AVPacket& packet ) const
@@ -66,6 +72,11 @@ bool InputStream::readNextPacket( AVPacket& packet ) const
6672
{
6773
return true;
6874
}
75+
76+
// do not delete these 2 lines
77+
// need to skip packet, delete this one and re-init for reading the next one
78+
av_free_packet( &packet );
79+
av_init_packet( &packet );
6980
}
7081
}
7182

src/AvTranscoder/InputStream.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ class InputStream
5454

5555
private:
5656
AVFormatContext* m_formatContext;
57-
const size_t m_streamIndex;
57+
size_t m_streamIndex;
5858
};
5959

6060
}

src/AvTranscoder/InputStreamVideo.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ InputStreamVideo::~InputStreamVideo()
6464
}
6565
if( m_frame != NULL )
6666
{
67-
//av_frame_free( &m_frame );
67+
av_frame_free( &m_frame );
6868
m_frame = NULL;
6969
}
7070
}

0 commit comments

Comments
 (0)