@@ -72,43 +72,32 @@ bool AvInputStream::readNextPacket( CodedData& data )
72
72
if ( ! _bufferized )
73
73
throw std::runtime_error ( " Can't read packet on non-bufferized input stream." );
74
74
75
- if ( _streamCache.empty () )
76
- _inputFile->readNextPacket ( _streamIndex );
77
-
78
- if ( _streamCache.empty () )
79
- return false ;
80
-
81
- _streamCache.front ().getBuffer ().swap ( data.getBuffer () );
82
-
83
- _streamCache.erase ( _streamCache.begin () );
75
+ // if packet is already cached
76
+ if ( ! _streamCache.empty () )
77
+ {
78
+ _streamCache.front ().getBuffer ().swap ( data.getBuffer () );
79
+ _streamCache.erase ( _streamCache.begin () );
80
+ }
81
+ // else read next packet
82
+ else
83
+ {
84
+ return _inputFile->readNextPacket ( data, _streamIndex ) && _streamCache.empty ();
85
+ }
84
86
85
87
return true ;
86
88
}
87
89
88
90
void AvInputStream::addPacket ( AVPacket& packet )
89
91
{
90
- // std::cout << "add packet for stream " << _streamIndex << std::endl;
91
- CodedData data;
92
- _streamCache.push_back ( data );
93
-
92
+ // Do not cache data if the stream is declared as unused in process
94
93
if ( ! _bufferized )
95
94
return ;
96
95
97
- // is it possible to remove this copy ?
98
- // using : av_packet_unref ?
96
+ CodedData data;
97
+ _streamCache. push_back ( data );
99
98
_streamCache.back ().getBuffer ().resize ( packet.size );
100
99
if ( packet.size != 0 )
101
100
memcpy ( _streamCache.back ().getPtr (), packet.data , packet.size );
102
-
103
- // std::vector<unsigned char> tmpData( 0,0 );
104
- // &tmpData[0] = packet.data;
105
- // tmpData.size( packet.size );
106
-
107
- // remove reference on packet because it's passed to CodedData
108
- // packet.data = NULL;
109
- // packet.size = 0;
110
-
111
- // std::cout << this << " buffer size " << _streamCache.size() << std::endl;
112
101
}
113
102
114
103
VideoCodec& AvInputStream::getVideoCodec ()
0 commit comments