-
Notifications
You must be signed in to change notification settings - Fork 78
Expose av_read_frame error code #533
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
Conversation
…er-error Emit error signal when av_read_frame fails
| } | ||
|
|
||
| QAVPacket pkt; | ||
| av_packet_unref(pkt.packet()); |
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.
Interesting which issues you fixed there? means that could be av_packet_ref before the call to read()?
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.
Added av_packet_unref(pkt.packet()) before reuse to avoid leaks or stale data.
right, but have you seen actual leaks there?
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.
Yes, I added av_packet_unref(pkt.packet()) as a precaution before reusing the packet. While I haven’t observed concrete leaks in practice, this change ensures that old data does not remain attached to the reused packet. It is a defensive measure against stale state and follows FFmpeg’s own packet reuse recommendations.
src/QtAVPlayer/qavdemuxer.cpp
Outdated
| QMutexLocker locker(&d->mutex); | ||
| d->eof = eof; | ||
| if (pkt.packet()->stream_index < d->availableStreams.size()) | ||
| if (ret >= 0 && pkt.packet()->stream_index < d->availableStreams.size()) |
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.
there are several tests failed due to that stream must be available on AVERROR_EOF for the packet,
pkt.setStream should be called of EOF too. Since means need to flush codecs
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.
I will make sure pkt.setStream() is always called for EOF packets as well. That way, even when ret == AVERROR_EOF, the packet has valid stream metadata, and the decoder can correctly handle flushing. Thanks for pointing this out — this aligns with the test failures you mentioned.
src/QtAVPlayer/qavplayer.cpp
Outdated
| if (packet.stream()) { | ||
| QAVPacket packet; | ||
| int ret = demuxer.read(packet); | ||
| if (ret >= 0 && packet.stream()) { |
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.
// Empty packet points to EOF and it needs to flush codecs
there should be a check for AVERROR_EOF too allow to flush codecs
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.
Acknowledged. I will add an explicit check for AVERROR_EOF in the caller side (e.g. qavplayer.cpp) so that EOF packets still get processed by codecs instead of being discarded prematurely. This ensures proper flushing of codec buffers.
| else | ||
| pkt = QAVPacket(); | ||
| } else if (ret < 0) { | ||
| pkt = QAVPacket(); |
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.
the packet should not be empty for EOF cases
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.
Good point. Returning a completely empty packet on EOF is not correct. Instead, I will ensure that pkt.setStream(...) is still called in EOF cases, so the packet has the correct stream index even when it represents EOF. This way, codec flushing can happen as expected.
Summary
This PR refactors the
QAVDemuxer::readAPI to provide better error reporting and resource management while keeping backward compatibility.Previously,
read()returned aQAVPacket, which masked error codes and forced callers to check only whether the packet was valid.With this change, the new API returns an
int(FFmpeg error code), and theQAVPacketis passed by reference.Key Changes
New API
int read(QAVPacket &outPacket)that returns FFmpeg error codes directly (0or positive for success, negative values for EOF or errors).AVERROR_EOF,EAGAIN, network errors such as-10054).Deprecated Old API
QAVPacket read()is still available but marked withQT_DEPRECATED_X("Use read(QAVPacket &outPacket)")for backward compatibility.read(QAVPacket&).Improved Resource Management
av_packet_unref(pkt.packet())before reuse to avoid leaks or stale data.d->eofand flushes bitstream filters by sendingNULLtoav_bsf_send_packet.Error Propagation
ret >= 0 && packet.stream()ret == AVERROR_EOFret == AVERROR(EAGAIN)setError()inQAVPlayer.Bitstream Filter Handling
bsf_ret) directly if they occur.