Skip to content

Commit 3426082

Browse files
author
Valentin Noel
committed
InputFile: into readNextPacket, return expected data (instead of caching it)
1 parent 8efd1f1 commit 3426082

File tree

2 files changed

+17
-10
lines changed

2 files changed

+17
-10
lines changed

src/AvTranscoder/file/InputFile.cpp

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ AvInputStream& InputFile::getStream( size_t index )
144144
return *_inputStreams.at( index );
145145
}
146146

147-
bool InputFile::readNextPacket( const size_t streamIndex )
147+
bool InputFile::readNextPacket( CodedData& data, const size_t streamIndex )
148148
{
149149
AVPacket packet;
150150
av_init_packet( &packet );
@@ -157,15 +157,21 @@ bool InputFile::readNextPacket( const size_t streamIndex )
157157
return false;
158158
}
159159

160-
// send packet to stream buffer
161-
_inputStreams.at( packet.stream_index )->addPacket( packet );
162-
163-
// We only read one stream and skip others
160+
// if the packet stream is the expected one
161+
// copy and return the packet data
164162
if( packet.stream_index == (int)streamIndex )
165163
{
164+
data.getBuffer().resize( packet.size );
165+
if( packet.size != 0 )
166+
memcpy( data.getPtr(), packet.data, packet.size );
166167
av_free_packet( &packet );
167168
return true;
168169
}
170+
// else add the packet data to the stream cache
171+
else
172+
{
173+
_inputStreams.at( packet.stream_index )->addPacket( packet );
174+
}
169175

170176
// do not delete these 2 lines
171177
// need to skip packet, delete this one and re-init for reading the next one

src/AvTranscoder/file/InputFile.hpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -86,16 +86,17 @@ class AvExport InputFile
8686
AVFormatContext& getFormatContext() const { return *_formatContext; }
8787

8888
/**
89-
* @brief Read the next packet for the specified stream
90-
* @note For performances, each readed stream needs to be bufferized using the readStream() method.
91-
* @return if next packet was succefully readed
89+
* @brief Read the next packet of the specified stream
90+
* @param data: data of next packet read
91+
* @note For performances, each read stream needs to be bufferized using the readStream() method.
92+
* @return if next packet was succefully read
9293
**/
93-
bool readNextPacket( const size_t streamIndex );
94+
bool readNextPacket( CodedData& data, const size_t streamIndex );
9495

9596
/**
9697
* @brief Seek input stream at specified frame
9798
* @note clean also buffers in each InputStream
98-
* @return if next packet was succefully readed
99+
* @return if next packet was succefully read
99100
**/
100101
void seekAtFrame( const size_t frame );
101102

0 commit comments

Comments
 (0)