Skip to content

Commit 6f99c61

Browse files
author
Valentin Noel
committed
AvInputStream: extract data from file only if the stream cache is empty
1 parent 3426082 commit 6f99c61

File tree

1 file changed

+14
-25
lines changed

1 file changed

+14
-25
lines changed

src/AvTranscoder/codedStream/AvInputStream.cpp

Lines changed: 14 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -72,43 +72,32 @@ bool AvInputStream::readNextPacket( CodedData& data )
7272
if( ! _bufferized )
7373
throw std::runtime_error( "Can't read packet on non-bufferized input stream." );
7474

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+
}
8486

8587
return true;
8688
}
8789

8890
void AvInputStream::addPacket( AVPacket& packet )
8991
{
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
9493
if( ! _bufferized )
9594
return;
9695

97-
// is it possible to remove this copy ?
98-
// using : av_packet_unref ?
96+
CodedData data;
97+
_streamCache.push_back( data );
9998
_streamCache.back().getBuffer().resize( packet.size );
10099
if( packet.size != 0 )
101100
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;
112101
}
113102

114103
VideoCodec& AvInputStream::getVideoCodec()

0 commit comments

Comments
 (0)