Skip to content

Commit

Permalink
Merge pull request #496 from vladyslav-arzhanov/reinit_hwmediacodec
Browse files Browse the repository at this point in the history
For each new MediaCodec should create a new AndroidSurfaceTexture
  • Loading branch information
valbok authored Dec 3, 2024
2 parents 73d4b95 + 455b280 commit e427293
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions src/QtAVPlayer/qavhwdevice_mediacodec.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,16 @@ extern "C" {

QT_BEGIN_NAMESPACE

Q_GLOBAL_STATIC(QAVAndroidSurfaceTexture, androidSurfaceTexture);

class QAVHWDevice_MediaCodecPrivate
{
public:
QAVHWDevice_MediaCodecPrivate()
{
androidSurfaceTexture = std::make_unique<QAVAndroidSurfaceTexture>();
}

GLuint texture = 0;
std::unique_ptr<QAVAndroidSurfaceTexture> androidSurfaceTexture;
};

QAVHWDevice_MediaCodec::QAVHWDevice_MediaCodec()
Expand All @@ -49,7 +53,7 @@ void QAVHWDevice_MediaCodec::init(AVCodecContext *avctx)
AVMediaCodecDeviceContext *mediaDeviceContext =
reinterpret_cast<AVMediaCodecDeviceContext *>(deviceContext->hwctx);
if (mediaDeviceContext)
mediaDeviceContext->surface = androidSurfaceTexture->surface();
mediaDeviceContext->surface = d_ptr->androidSurfaceTexture->surface();
}
}
#else
Expand Down Expand Up @@ -83,13 +87,13 @@ class VideoBuffer_MediaCodec : public QAVVideoBuffer_GPU

QVariant handle(QRhi */*rhi*/) const override
{
if (!androidSurfaceTexture->isValid())
if (!m_hw->androidSurfaceTexture->isValid())
return {};

if (!m_hw->texture) {
androidSurfaceTexture->detachFromGLContext();
m_hw->androidSurfaceTexture->detachFromGLContext();
glGenTextures(1, &m_hw->texture);
androidSurfaceTexture->attachToGLContext(m_hw->texture);
m_hw->androidSurfaceTexture->attachToGLContext(m_hw->texture);
}

AVMediaCodecBuffer *buffer = reinterpret_cast<AVMediaCodecBuffer *>(frame().frame()->data[3]);
Expand All @@ -100,7 +104,7 @@ class VideoBuffer_MediaCodec : public QAVVideoBuffer_GPU
return {};
}

androidSurfaceTexture->updateTexImage();
m_hw->androidSurfaceTexture->updateTexImage();
return m_hw->texture;
}

Expand Down

0 comments on commit e427293

Please sign in to comment.