summaryrefslogtreecommitdiffstats
path: root/src/plugins/multimedia/ffmpeg/qffmpegdecoder.cpp
diff options
context:
space:
mode:
authorSamuel Mira <samuel.mira@qt.io>2022-05-16 20:16:22 +0300
committerSamuel Mira <samuel.mira@qt.io>2022-05-23 13:08:31 +0000
commit4b8b5ad1bd74fd107f034d72c6d44faa386f01f5 (patch)
tree93994192bc3a99d4345e51d34854c57665e48a3f /src/plugins/multimedia/ffmpeg/qffmpegdecoder.cpp
parent2835377e2b0be50e4ed13876869c008340feac11 (diff)
Android: Enable FFmpeg playback - HW rendering
This patch enables video playback on Android using Hardware rendering with FFmpeg backend. Task-number: QTBUG-102233 Change-Id: Ib9af89ef78e53846d0742a828a3ec5430a8a9f80 Reviewed-by: Lars Knoll <lars.knoll@qt.io>
Diffstat (limited to 'src/plugins/multimedia/ffmpeg/qffmpegdecoder.cpp')
-rw-r--r--src/plugins/multimedia/ffmpeg/qffmpegdecoder.cpp16
1 files changed, 15 insertions, 1 deletions
diff --git a/src/plugins/multimedia/ffmpeg/qffmpegdecoder.cpp b/src/plugins/multimedia/ffmpeg/qffmpegdecoder.cpp
index 31b334fbc..3aaf1f781 100644
--- a/src/plugins/multimedia/ffmpeg/qffmpegdecoder.cpp
+++ b/src/plugins/multimedia/ffmpeg/qffmpegdecoder.cpp
@@ -90,7 +90,9 @@ Codec::Codec(AVFormatContext *format, int streamIndex)
Q_ASSERT(streamIndex >= 0 && streamIndex < (int)format->nb_streams);
AVStream *stream = format->streams[streamIndex];
- const AVCodec *decoder = avcodec_find_decoder(stream->codecpar->codec_id);
+ const AVCodec *decoder =
+ QFFmpeg::HWAccel::hardwareDecoderForCodecId(stream->codecpar->codec_id);
+
if (!decoder) {
qCDebug(qLcDecoder) << "Failed to find a valid FFmpeg decoder";
return;
@@ -705,6 +707,18 @@ void VideoRenderer::loop()
if (sink) {
qint64 startTime = frame.pts();
// qDebug() << "RHI:" << accel.isNull() << accel.rhi() << sink->rhi();
+
+ // in practice this only happens with mediacodec
+ if (!frame.codec()->hwAccel().isNull() && !frame.avFrame()->hw_frames_ctx) {
+ HWAccel hwaccel = frame.codec()->hwAccel();
+ AVFrame *avframe = frame.avFrame();
+ if (!hwaccel.hwFramesContext())
+ hwaccel.createFramesContext(AVPixelFormat(avframe->format),
+ { avframe->width, avframe->height });
+
+ avframe->hw_frames_ctx = av_buffer_ref(hwaccel.hwFramesContextAsBuffer());
+ }
+
QFFmpegVideoBuffer *buffer = new QFFmpegVideoBuffer(frame.takeAVFrame());
QVideoFrameFormat format(buffer->size(), buffer->pixelFormat());
format.setColorSpace(buffer->colorSpace());