-
Notifications
You must be signed in to change notification settings - Fork 3
Fix read next packet #14
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -144,7 +144,7 @@ AvInputStream& InputFile::getStream( size_t index ) | |
return *_inputStreams.at( index ); | ||
} | ||
|
||
bool InputFile::readNextPacket( const size_t streamIndex ) | ||
bool InputFile::readNextPacket( CodedData& data, const size_t streamIndex ) | ||
{ | ||
AVPacket packet; | ||
av_init_packet( &packet ); | ||
|
@@ -157,15 +157,21 @@ bool InputFile::readNextPacket( const size_t streamIndex ) | |
return false; | ||
} | ||
|
||
// send packet to stream buffer | ||
_inputStreams.at( packet.stream_index )->addPacket( packet ); | ||
|
||
// We only read one stream and skip others | ||
// if the packet stream is the expected one | ||
// copy and return the packet data | ||
if( packet.stream_index == (int)streamIndex ) | ||
{ | ||
data.getBuffer().resize( packet.size ); | ||
if( packet.size != 0 ) | ||
memcpy( data.getPtr(), packet.data, packet.size ); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could add a function into Frame (CodedData) instead of duplicating this code, no? |
||
av_free_packet( &packet ); | ||
return true; | ||
} | ||
// else add the packet data to the stream cache | ||
else | ||
{ | ||
_inputStreams.at( packet.stream_index )->addPacket( packet ); | ||
} | ||
|
||
// do not delete these 2 lines | ||
// need to skip packet, delete this one and re-init for reading the next one | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -86,16 +86,17 @@ class AvExport InputFile | |
AVFormatContext& getFormatContext() const { return *_formatContext; } | ||
|
||
/** | ||
* @brief Read the next packet for the specified stream | ||
* @note For performances, each readed stream needs to be bufferized using the readStream() method. | ||
* @return if next packet was succefully readed | ||
* @brief Read the next packet of the specified stream | ||
* @param data: data of next packet read | ||
* @note For performances, each read stream needs to be bufferized using the readStream() method. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. not clear... |
||
* @return if next packet was succefully read | ||
**/ | ||
bool readNextPacket( const size_t streamIndex ); | ||
bool readNextPacket( CodedData& data, const size_t streamIndex ); | ||
|
||
/** | ||
* @brief Seek input stream at specified frame | ||
* @note clean also buffers in each InputStream | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
* @return if next packet was succefully readed | ||
* @return if next packet was succefully read | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @return if next packet was read successfully |
||
**/ | ||
void seekAtFrame( const size_t frame ); | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"Because vectors use an array as their underlying storage, erasing elements in positions other than the vector end causes the container to relocate all the elements after the segment erased to their new positions. This is generally an inefficient operation compared to the one performed for the same operation by other kinds of sequence containers (such as list or forward_list)."
Use an std::queue instead.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh yes, indeed !
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done in PR #15