ffmpeg: fix crash at end of video stream

Mixing new and old style decoding APIs won't work. And we were still
using the old API for managing the end of videos.

Change-Id: Ic194ab98721455658ecefde4f951c3f1e43ae1be
Reviewed-on: https://review.haiku-os.org/679
Reviewed-by: waddlesplash <[email protected]>
This commit is contained in:
Adrien Destugues
2018-11-08 20:09:08 +00:00
committed by waddlesplash
parent 2e8be594e7
commit 4c8208af52
@@ -1524,19 +1524,15 @@ AVCodecDecoder::_HandleNewVideoFrameAndUpdateSystemState()
status_t status_t
AVCodecDecoder::_FlushOneVideoFrameFromDecoderBuffer() AVCodecDecoder::_FlushOneVideoFrameFromDecoderBuffer()
{ {
// Create empty fTempPacket to tell the video decoder it is time to flush // Tell the decoder there is nothing to send anymore
fTempPacket.data = NULL; avcodec_send_packet(fCodecContext, NULL);
fTempPacket.size = 0;
int gotVideoFrame = 0; // Get any remaining frame
avcodec_decode_video2(fCodecContext, fRawDecodedPicture, &gotVideoFrame, int error = avcodec_receive_frame(fCodecContext, fRawDecodedPicture);
&fTempPacket);
// We are only interested in complete frames now, so ignore the return
// value.
bool gotNoVideoFrame = gotVideoFrame == 0; if (error != 0 && error != AVERROR(EAGAIN)) {
if (gotNoVideoFrame) {
// video buffer is flushed successfully // video buffer is flushed successfully
// (or there is an error, not much we can do about it)
return B_LAST_BUFFER_ERROR; return B_LAST_BUFFER_ERROR;
} }
@@ -1565,10 +1561,15 @@ AVCodecDecoder::_FlushOneVideoFrameFromDecoderBuffer()
void void
AVCodecDecoder::_UpdateMediaHeaderForVideoFrame() AVCodecDecoder::_UpdateMediaHeaderForVideoFrame()
{ {
AVRational rationalTimestamp = av_make_q(
fRawDecodedPicture->pkt_dts, 1);
AVRational seconds = av_mul_q(rationalTimestamp, fCodecContext->time_base);
AVRational microseconds = av_mul_q(seconds, av_make_q(1000000, 1));
fHeader.type = B_MEDIA_RAW_VIDEO; fHeader.type = B_MEDIA_RAW_VIDEO;
fHeader.file_pos = 0; fHeader.file_pos = 0;
fHeader.orig_size = 0; fHeader.orig_size = 0;
fHeader.start_time = fRawDecodedPicture->pkt_dts; fHeader.start_time = (bigtime_t)(av_q2d(microseconds));
fHeader.size_used = av_image_get_buffer_size( fHeader.size_used = av_image_get_buffer_size(
colorspace_to_pixfmt(fOutputColorSpace), fRawDecodedPicture->width, colorspace_to_pixfmt(fOutputColorSpace), fRawDecodedPicture->width,
fRawDecodedPicture->height, 1); fRawDecodedPicture->height, 1);