Skip to content

Commit

Permalink
Handle video decoding failures on the OHOS platform. (#2598)
Browse files Browse the repository at this point in the history
  • Loading branch information
kevingpqi123 authored Nov 25, 2024
1 parent 7d78a48 commit 7c0d346
Showing 1 changed file with 19 additions and 4 deletions.
23 changes: 19 additions & 4 deletions src/platform/ohos/OHOSVideoDecoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,15 @@
namespace pag {
#define NV12_PLANE_COUNT 2

void OH_AVCodecOnError(OH_AVCodec*, int32_t, void*) {
void OH_AVCodecOnError(OH_AVCodec*, int32_t index, void* userData) {
if (userData == nullptr) {
return;
}
LOGE("video decoder error, index:%d \n", index);
CodecUserData* codecUserData = static_cast<CodecUserData*>(userData);
std::unique_lock<std::mutex> lock(codecUserData->outputMutex);
codecUserData->outputBufferInfoQueue.emplace(index, nullptr);
codecUserData->outputCondition.notify_all();
}

void OH_AVCodecOnStreamChanged(OH_AVCodec*, OH_AVFormat*, void*) {
Expand Down Expand Up @@ -84,9 +92,13 @@ OHOSVideoDecoder::OHOSVideoDecoder(const VideoFormat& format, bool hardware) {

OHOSVideoDecoder::~OHOSVideoDecoder() {
if (codecCategory == SOFTWARE) {
if (yuvBuffer->data[0] != nullptr) {
delete[] yuvBuffer->data[0];
delete[] yuvBuffer->data[1];
if (yuvBuffer) {
if (yuvBuffer->data[0]) {
delete[] yuvBuffer->data[0];
}
if (yuvBuffer->data[1]) {
delete[] yuvBuffer->data[1];
}
}
}
if (videoCodec != nullptr) {
Expand Down Expand Up @@ -196,6 +208,9 @@ DecodingResult OHOSVideoDecoder::onDecodeFrame() {
codecUserData->outputBufferInfoQueue.pop();
lock.unlock();
pendingFrames.remove(codecBufferInfo.attr.pts);
if (codecBufferInfo.buffer == nullptr) {
return DecodingResult::Error;
}
} else {
lock.unlock();
return DecodingResult::Success;
Expand Down

0 comments on commit 7c0d346

Please sign in to comment.