LibMedia: Allow signalling of EOF to decoders
This is used by FFmpeg's H.264 decoder to determine when to output any buffered frames after data runs out.
This commit is contained in:
parent
634e5ff491
commit
0e9c746b48
6 changed files with 26 additions and 0 deletions
|
|
@ -20,6 +20,7 @@ public:
|
|||
virtual ~AudioDecoder() { }
|
||||
|
||||
virtual DecoderErrorOr<void> receive_coded_data(AK::Duration timestamp, ReadonlyBytes coded_data) = 0;
|
||||
virtual void signal_end_of_stream() = 0;
|
||||
// Writes all buffered audio samples to the provided block.
|
||||
virtual DecoderErrorOr<void> write_next_block(AudioBlock&) = 0;
|
||||
|
||||
|
|
|
|||
|
|
@ -104,6 +104,17 @@ DecoderErrorOr<void> FFmpegAudioDecoder::receive_coded_data(AK::Duration timesta
|
|||
}
|
||||
}
|
||||
|
||||
void FFmpegAudioDecoder::signal_end_of_stream()
|
||||
{
|
||||
m_packet->data = nullptr;
|
||||
m_packet->size = 0;
|
||||
m_packet->pts = 0;
|
||||
m_packet->dts = 0;
|
||||
|
||||
auto result = avcodec_send_packet(m_codec_context, m_packet);
|
||||
VERIFY(result == 0 || result == AVERROR_EOF);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
static float float_sample_from_frame_data(u8** data, size_t plane, size_t index);
|
||||
|
||||
|
|
|
|||
|
|
@ -20,6 +20,7 @@ public:
|
|||
virtual ~FFmpegAudioDecoder() override;
|
||||
|
||||
virtual DecoderErrorOr<void> receive_coded_data(AK::Duration timestamp, ReadonlyBytes coded_data) override;
|
||||
virtual void signal_end_of_stream() override;
|
||||
// Writes all buffered audio samples to the provided block.
|
||||
virtual DecoderErrorOr<void> write_next_block(AudioBlock&) override;
|
||||
|
||||
|
|
|
|||
|
|
@ -130,6 +130,17 @@ DecoderErrorOr<void> FFmpegVideoDecoder::receive_coded_data(AK::Duration timesta
|
|||
}
|
||||
}
|
||||
|
||||
void FFmpegVideoDecoder::signal_end_of_stream()
|
||||
{
|
||||
m_packet->data = nullptr;
|
||||
m_packet->size = 0;
|
||||
m_packet->pts = 0;
|
||||
m_packet->dts = 0;
|
||||
|
||||
auto result = avcodec_send_packet(m_codec_context, m_packet);
|
||||
VERIFY(result == 0 || result == AVERROR_EOF);
|
||||
}
|
||||
|
||||
DecoderErrorOr<NonnullOwnPtr<VideoFrame>> FFmpegVideoDecoder::get_decoded_frame()
|
||||
{
|
||||
auto result = avcodec_receive_frame(m_codec_context, m_frame);
|
||||
|
|
|
|||
|
|
@ -21,6 +21,7 @@ public:
|
|||
virtual ~FFmpegVideoDecoder() override;
|
||||
|
||||
virtual DecoderErrorOr<void> receive_coded_data(AK::Duration timestamp, ReadonlyBytes coded_data) override;
|
||||
virtual void signal_end_of_stream() override;
|
||||
virtual DecoderErrorOr<NonnullOwnPtr<VideoFrame>> get_decoded_frame() override;
|
||||
|
||||
virtual void flush() override;
|
||||
|
|
|
|||
|
|
@ -20,6 +20,7 @@ public:
|
|||
|
||||
virtual DecoderErrorOr<void> receive_coded_data(AK::Duration timestamp, ReadonlyBytes coded_data) = 0;
|
||||
DecoderErrorOr<void> receive_coded_data(AK::Duration timestamp, ByteBuffer const& coded_data) { return receive_coded_data(timestamp, coded_data.span()); }
|
||||
virtual void signal_end_of_stream() = 0;
|
||||
virtual DecoderErrorOr<NonnullOwnPtr<VideoFrame>> get_decoded_frame() = 0;
|
||||
|
||||
virtual void flush() = 0;
|
||||
|
|
|
|||
Loading…
Reference in a new issue