57 std::unique_ptr<AndroidSurfaceTexture> androidSurfaceTexture(
new AndroidSurfaceTexture(0));
58 AVMediaCodecContext *mediacodecContext = av_mediacodec_alloc_context();
59 av_mediacodec_default_init(avCodecContext, mediacodecContext, androidSurfaceTexture->surface());
61 if (!avCodecContext->hw_device_ctx || !avCodecContext->hw_device_ctx->data)
64 AVHWDeviceContext *deviceContext =
65 reinterpret_cast<AVHWDeviceContext *>(avCodecContext->hw_device_ctx->data);
67 if (!deviceContext->hwctx)
70 AVMediaCodecDeviceContext *mediaDeviceContext =
71 reinterpret_cast<AVMediaCodecDeviceContext *>(deviceContext->hwctx);
73 if (!mediaDeviceContext)
76 mediaDeviceContext->surface = androidSurfaceTexture->surface();
78 Q_ASSERT(deviceContext->user_opaque ==
nullptr);
79 deviceContext->user_opaque = androidSurfaceTexture.release();
80 deviceContext->free = deleteSurface;
87 if (!androidSurfaceTexture || !androidSurfaceTexture
->isValid())
90 if (!externalTexture || m_currentSurfaceIndex != androidSurfaceTexture->index()) {
91 m_currentSurfaceIndex = androidSurfaceTexture->index();
93 externalTexture = std::unique_ptr<QRhiTexture>(
94 rhi->newTexture(QRhiTexture::Format::RGBA8, { frame->width, frame->height }, 1,
95 QRhiTexture::ExternalOES));
97 if (!externalTexture->create()) {
98 qWarning() <<
"Failed to create the external texture!";
102 quint64 textureHandle = externalTexture->nativeTexture().object;
103 androidSurfaceTexture->attachToGLContext(textureHandle);
107 AVMediaCodecBuffer *buffer = (AVMediaCodecBuffer *)frame->data[3];
110 qWarning() <<
"Received a frame without AVMediaCodecBuffer.";
111 }
else if (av_mediacodec_release_buffer(buffer, 1) < 0) {
112 qWarning() <<
"Failed to render buffer to surface.";
118 return new MediaCodecTextureSet(externalTexture->nativeTexture().object);
void detachFromGLContext()