From d0e69d35d55cf465b62fea1c96b3674ce1db7104 Mon Sep 17 00:00:00 2001 From: kevingpqi Date: Mon, 30 Dec 2024 17:09:42 +0800 Subject: [PATCH] Add a release method to PAGViewController and PAGImageViewController to support immediate memory release when called externally. --- ohos/libpag/src/main/ets/PAGImageView.ets | 8 ++++++++ ohos/libpag/src/main/ets/PAGView.ets | 8 ++++++++ src/platform/ohos/OHOSVideoDecoder.cpp | 3 ++- 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/ohos/libpag/src/main/ets/PAGImageView.ets b/ohos/libpag/src/main/ets/PAGImageView.ets index 5420f23981..03323857da 100644 --- a/ohos/libpag/src/main/ets/PAGImageView.ets +++ b/ohos/libpag/src/main/ets/PAGImageView.ets @@ -325,6 +325,14 @@ export class PAGImageViewController { this.view = null; } + /** + * Free up resources used by the PAGImageViewController instance immediately instead of relying on the + * garbage collector to do this for you at some point in the future. + */ + release() { + this.jImageView.release(); + } + private composition: PAGComposition | null = null; private filePath: string | null = null; private listeners: Array> = []; diff --git a/ohos/libpag/src/main/ets/PAGView.ets b/ohos/libpag/src/main/ets/PAGView.ets index 3163093f03..b23315ac65 100644 --- a/ohos/libpag/src/main/ets/PAGView.ets +++ b/ohos/libpag/src/main/ets/PAGView.ets @@ -375,6 +375,14 @@ export class PAGViewController { this.view = null; } + /** + * Free up resources used by the PAGViewController instance immediately instead of relying on the + * garbage collector to do this for you at some point in the future. + */ + release() { + this.jView.release(); + } + uniqueID() { return this.jView.uniqueID(); } diff --git a/src/platform/ohos/OHOSVideoDecoder.cpp b/src/platform/ohos/OHOSVideoDecoder.cpp index e68c62bc37..3c4ef28360 100644 --- a/src/platform/ohos/OHOSVideoDecoder.cpp +++ b/src/platform/ohos/OHOSVideoDecoder.cpp @@ -106,6 +106,7 @@ OHOSVideoDecoder::~OHOSVideoDecoder() { videoCodec = nullptr; } if (codecUserData) { + codecUserData->clearQueue(); delete codecUserData; } } @@ -271,6 +272,7 @@ std::shared_ptr OHOSVideoDecoder::onRenderFrame() { if (format) { OH_AVFormat_GetIntValue(format, OH_MD_KEY_VIDEO_STRIDE, &videoStride); OH_AVFormat_GetIntValue(format, OH_MD_KEY_VIDEO_SLICE_HEIGHT, &videoSliceHeight); + OH_AVFormat_Destroy(format); } if (videoStride == 0 || videoSliceHeight == 0) { return nullptr; @@ -291,7 +293,6 @@ std::shared_ptr OHOSVideoDecoder::onRenderFrame() { } yuvBuffer->lineSize[0] = videoStride; yuvBuffer->lineSize[1] = videoStride; - OH_AVFormat_Destroy(format); } auto capacity = OH_AVBuffer_GetCapacity(codecBufferInfo.buffer); if (capacity <= 0) {