File tree Expand file tree Collapse file tree 5 files changed +33
-16
lines changed Expand file tree Collapse file tree 5 files changed +33
-16
lines changed Original file line number Diff line number Diff line change @@ -42,6 +42,11 @@ InputFile::InputFile( const std::string& filename )
42
42
m_formatContext = NULL ;
43
43
throw std::runtime_error ( " unable to find stream informations" );
44
44
}
45
+
46
+ for ( size_t streamIndex = 0 ; streamIndex < m_formatContext->nb_streams ; ++streamIndex )
47
+ {
48
+ m_inputStreams.push_back ( InputStream ( m_filename, streamIndex ) );
49
+ }
45
50
}
46
51
47
52
InputFile::~InputFile ()
@@ -118,9 +123,9 @@ InputFile& InputFile::analyse()
118
123
return *this ;
119
124
}
120
125
121
- InputStream InputFile::getStream ( size_t index )
126
+ InputStream& InputFile::getStream ( size_t index )
122
127
{
123
- return InputStream ( m_filename, index );
128
+ return m_inputStreams. at ( index );
124
129
}
125
130
126
131
}
Original file line number Diff line number Diff line change @@ -29,15 +29,16 @@ class InputFile
29
29
// *** Metadatas section ***
30
30
// run the analyse on the file after a setup.
31
31
InputFile& analyse ();
32
- // get properties on the file
32
+ // / get file properties
33
33
const Properties& getProperties () const { return m_properties; }
34
34
35
- InputStream getStream ( size_t index );
35
+ InputStream& getStream ( size_t index );
36
36
37
37
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;
41
42
};
42
43
43
44
}
Original file line number Diff line number Diff line change @@ -38,16 +38,22 @@ bool InputStream::readNextPacket( DataStream& data ) const
38
38
AVPacket packet;
39
39
av_init_packet ( &packet );
40
40
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
+ }
47
53
48
54
av_free_packet ( &packet );
49
55
50
- return true ;
56
+ return data. getBuffer (). size () != 0 ;
51
57
}
52
58
53
59
bool InputStream::readNextPacket ( AVPacket& packet ) const
@@ -66,6 +72,11 @@ bool InputStream::readNextPacket( AVPacket& packet ) const
66
72
{
67
73
return true ;
68
74
}
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 );
69
80
}
70
81
}
71
82
Original file line number Diff line number Diff line change @@ -54,7 +54,7 @@ class InputStream
54
54
55
55
private:
56
56
AVFormatContext* m_formatContext;
57
- const size_t m_streamIndex;
57
+ size_t m_streamIndex;
58
58
};
59
59
60
60
}
Original file line number Diff line number Diff line change @@ -64,7 +64,7 @@ InputStreamVideo::~InputStreamVideo()
64
64
}
65
65
if ( m_frame != NULL )
66
66
{
67
- // av_frame_free( &m_frame );
67
+ av_frame_free ( &m_frame );
68
68
m_frame = NULL ;
69
69
}
70
70
}
You can’t perform that action at this time.
0 commit comments