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
20QT_BEGIN_NAMESPACE
21
22namespace QFFmpeg {
23
24namespace {
25
26class MediaCodecTextureHandles : public QVideoFrameTexturesHandles
27{
28public:
29 MediaCodecTextureHandles(TextureConverterBackendPtr &&converterBackend, quint64 textureHandle)
30 : m_parentConverterBackend(std::move(converterBackend)), m_handle(textureHandle)
31 {
32 }
33
34 quint64 textureHandle(QRhi &, int plane) override { return (plane == 0) ? m_handle : 0; }
35
36private:
37 TextureConverterBackendPtr m_parentConverterBackend; // ensures the backend is kept
38 quint64 m_handle;
39};
40
41void deleteSurface(AVHWDeviceContext *ctx)
42{
43 AndroidSurfaceTexture* s = reinterpret_cast<AndroidSurfaceTexture *>(ctx->user_opaque);
44 delete s;
45}
46
47AndroidSurfaceTexture* getTextureSurface(AVFrame *frame)
48{
49 if (!frame || !frame->hw_frames_ctx)
50 return nullptr;
51
52 auto *frameContext = reinterpret_cast<AVHWFramesContext *>(frame->hw_frames_ctx->data);
53
54 if (!frameContext || !frameContext->device_ctx)
55 return nullptr;
56
57 AVHWDeviceContext *deviceContext = frameContext->device_ctx;
58
59 return reinterpret_cast<AndroidSurfaceTexture *>(deviceContext->user_opaque);
60}
61} // namespace
62
90
93 QVideoFrameTexturesUPtr & /*oldTextures*/)
94{
95 // Most likely, this method should be used instead of createTextureHandles, QRhiTexture is
96 // already created, and we don't need to convert it to handle and back. This work should be done
97 // in the scope of QTBUG-132174
98 return nullptr;
99}
100
103 QVideoFrameTexturesHandlesUPtr /*oldHandles*/)
104{
105 // TODO: reuse oldHandles: the underlying QRhiTexture must be taken from it instead of
106 // keeping it in AndroidTextureConverter. See QTBUG-132174
108
110 return {};
111
118
119 if (!externalTexture->create()) {
120 qWarning() << "Failed to create the external texture!";
121 return {};
122 }
123
126 }
127
128 // release a MediaCodec buffer and render it to the surface
130
131 if (!buffer) {
132 qWarning() << "Received a frame without AVMediaCodecBuffer.";
133 } else if (av_mediacodec_release_buffer(buffer, 1) < 0) {
134 qWarning() << "Failed to render buffer to surface.";
135 return {};
136 }
137
139
142}
143}
144
145QT_END_NAMESPACE
std::conditional_t< QT_FFMPEG_AVIO_WRITE_CONST, const uint8_t *, uint8_t * > AvioWriteBufferType