Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qffmpeghwaccel_mediacodec.cpp
Go to the documentation of this file.
1// Copyright (C) 2021 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4#include <QtFFmpegMediaPluginImpl/private/qffmpeghwaccel_mediacodec_p.h>
5
6#include <QtGui/rhi/qrhi.h>
7
8// TODO: This class is reused from the native Android media backend and breaks ODR.
10
11extern "C" {
12#include <libavcodec/mediacodec.h>
13#include <libavutil/hwcontext_mediacodec.h>
14}
15
16#if !defined(Q_OS_ANDROID)
17# error "Configuration error"
18#endif
19
20namespace QFFmpeg {
21
22namespace {
23
24class MediaCodecTextureHandles : public QVideoFrameTexturesHandles
25{
26public:
27 MediaCodecTextureHandles(TextureConverterBackendPtr &&converterBackend, quint64 textureHandle)
28 : m_parentConverterBackend(std::move(converterBackend)), m_handle(textureHandle)
29 {
30 }
31
32 quint64 textureHandle(QRhi &, int plane) override { return (plane == 0) ? m_handle : 0; }
33
34private:
35 TextureConverterBackendPtr m_parentConverterBackend; // ensures the backend is kept
36 quint64 m_handle;
37};
38
39void deleteSurface(AVHWDeviceContext *ctx)
40{
41 AndroidSurfaceTexture* s = reinterpret_cast<AndroidSurfaceTexture *>(ctx->user_opaque);
42 delete s;
43}
44
45AndroidSurfaceTexture* getTextureSurface(AVFrame *frame)
46{
47 if (!frame || !frame->hw_frames_ctx)
48 return nullptr;
49
50 auto *frameContext = reinterpret_cast<AVHWFramesContext *>(frame->hw_frames_ctx->data);
51
52 if (!frameContext || !frameContext->device_ctx)
53 return nullptr;
54
55 AVHWDeviceContext *deviceContext = frameContext->device_ctx;
56
57 return reinterpret_cast<AndroidSurfaceTexture *>(deviceContext->user_opaque);
58}
59} // namespace
60
88
91 QVideoFrameTexturesUPtr & /*oldTextures*/)
92{
93 // Most likely, this method should be used instead of createTextureHandles, QRhiTexture is
94 // already created, and we don't need to convert it to handle and back. This work should be done
95 // in the scope of QTBUG-132174
96 return nullptr;
97}
98
101 QVideoFrameTexturesHandlesUPtr /*oldHandles*/)
102{
103 // TODO: reuse oldHandles: the underlying QRhiTexture must be taken from it instead of
104 // keeping it in AndroidTextureConverter. See QTBUG-132174
106
108 return {};
109
116
117 if (!externalTexture->create()) {
118 qWarning() << "Failed to create the external texture!";
119 return {};
120 }
121
124 }
125
126 // release a MediaCodec buffer and render it to the surface
128
129 if (!buffer) {
130 qWarning() << "Received a frame without AVMediaCodecBuffer.";
131 } else if (av_mediacodec_release_buffer(buffer, 1) < 0) {
132 qWarning() << "Failed to render buffer to surface.";
133 return {};
134 }
135
137
140}
141}
std::conditional_t< QT_FFMPEG_AVIO_WRITE_CONST, const uint8_t *, uint8_t * > AvioWriteBufferType