已合并
5.1.0 修复条件竞争导致的服务crash #6495
lzm创建于 2025年9月18日
5.1.0 修复条件竞争导致的服务crash #6495
已合并
共 1 个文件变更+3-3
| @@ -243,6 +243,7 @@ int32_t CodecServiceStub::Init(AVCodecType type, bool isMimeType, const std::str | |||
| 243 | this->SetTag(tag); | 243 | this->SetTag(tag); |
| 244 | codecServer_->SetTag(tag); | 244 | codecServer_->SetTag(tag); |
| 245 | static_cast<CodecListenerProxy *>(listener_.GetRefPtr())->SetTag(tag); | 245 | static_cast<CodecListenerProxy *>(listener_.GetRefPtr())->SetTag(tag); |
| 246 | + static_cast<CodecListenerProxy *>(listener_.GetRefPtr())->Init(); | ||
| 246 | AVCODEC_LOGI_WITH_TAG("%{public}s", AVCSErrorToString(static_cast<AVCodecServiceErrCode>(ret)).c_str()); | 247 | AVCODEC_LOGI_WITH_TAG("%{public}s", AVCSErrorToString(static_cast<AVCodecServiceErrCode>(ret)).c_str()); |
| 247 | return ret; | 248 | return ret; |
| 248 | } | 249 | } |
| @@ -361,7 +362,6 @@ int32_t CodecServiceStub::SetOutputSurface(sptr<OHOS::Surface> surface) | |||
| 361 | 362 | ||
| 362 | int32_t CodecServiceStub::QueueInputBuffer(uint32_t index, AVCodecBufferInfo info, AVCodecBufferFlag flag) | 363 | int32_t CodecServiceStub::QueueInputBuffer(uint32_t index, AVCodecBufferInfo info, AVCodecBufferFlag flag) |
| 363 | { | 364 | { |
| 364 | - std::shared_lock<std::shared_mutex> lock(mutex_); | ||
| 365 | CHECK_AND_RETURN_RET_LOG_WITH_TAG(codecServer_ != nullptr, AVCS_ERR_NO_MEMORY, "Codec server is nullptr"); | 365 | CHECK_AND_RETURN_RET_LOG_WITH_TAG(codecServer_ != nullptr, AVCS_ERR_NO_MEMORY, "Codec server is nullptr"); |
| 366 | return codecServer_->QueueInputBuffer(index, info, flag); | 366 | return codecServer_->QueueInputBuffer(index, info, flag); |
| 367 | } | 367 | } |
| @@ -394,7 +394,6 @@ int32_t CodecServiceStub::ReleaseOutputBuffer(uint32_t index, bool render) | |||
| 394 | 394 | ||
| 395 | int32_t CodecServiceStub::RenderOutputBufferAtTime(uint32_t index, int64_t renderTimestampNs) | 395 | int32_t CodecServiceStub::RenderOutputBufferAtTime(uint32_t index, int64_t renderTimestampNs) |
| 396 | { | 396 | { |
| 397 | - std::shared_lock<std::shared_mutex> lock(mutex_); | ||
| 398 | CHECK_AND_RETURN_RET_LOG_WITH_TAG(codecServer_ != nullptr, AVCS_ERR_NO_MEMORY, "Codec server is nullptr"); | 397 | CHECK_AND_RETURN_RET_LOG_WITH_TAG(codecServer_ != nullptr, AVCS_ERR_NO_MEMORY, "Codec server is nullptr"); |
| 399 | return codecServer_->RenderOutputBufferAtTime(index, renderTimestampNs); | 398 | return codecServer_->RenderOutputBufferAtTime(index, renderTimestampNs); |
| 400 | } | 399 | } |
| @@ -485,7 +484,6 @@ int32_t CodecServiceStub::Init(MessageParcel &data, MessageParcel &reply) | |||
| 485 | callerInfo.Remove(EventInfoExtentedKey::CODEC_TYPE.data()); | 484 | callerInfo.Remove(EventInfoExtentedKey::CODEC_TYPE.data()); |
| 486 | parcelRet = parcelRet && callerInfo.ToParcel(reply); | 485 | parcelRet = parcelRet && callerInfo.ToParcel(reply); |
| 487 | CHECK_AND_RETURN_RET_LOG_WITH_TAG(parcelRet, AVCS_ERR_INVALID_OPERATION, "Reply write failed"); | 486 | CHECK_AND_RETURN_RET_LOG_WITH_TAG(parcelRet, AVCS_ERR_INVALID_OPERATION, "Reply write failed"); |
| 488 | - static_cast<CodecListenerProxy *>(listener_.GetRefPtr())->Init(); | ||
| 489 | return AVCS_ERR_OK; | 487 | return AVCS_ERR_OK; |
| 490 | } | 488 | } |
| 491 | 489 | ||
| @@ -611,6 +609,7 @@ int32_t CodecServiceStub::QueueInputBuffer(MessageParcel &data, MessageParcel &r | |||
| 611 | { | 609 | { |
| 612 | AVCODEC_SYNC_TRACE_WITH_TAG; | 610 | AVCODEC_SYNC_TRACE_WITH_TAG; |
| 613 | 611 | ||
| 612 | + std::shared_lock<std::shared_mutex> lock(mutex_); | ||
| 614 | uint32_t index = data.ReadUint32(); | 613 | uint32_t index = data.ReadUint32(); |
| 615 | AVCodecBufferInfo info; | 614 | AVCodecBufferInfo info; |
| 616 | AVCodecBufferFlag flag; | 615 | AVCodecBufferFlag flag; |
| @@ -651,6 +650,7 @@ int32_t CodecServiceStub::RenderOutputBufferAtTime(MessageParcel &data, MessageP | |||
| 651 | { | 650 | { |
| 652 | AVCODEC_SYNC_TRACE_WITH_TAG; | 651 | AVCODEC_SYNC_TRACE_WITH_TAG; |
| 653 | 652 | ||
| 653 | + std::shared_lock<std::shared_mutex> lock(mutex_); | ||
| 654 | uint32_t index = data.ReadUint32(); | 654 | uint32_t index = data.ReadUint32(); |
| 655 | int64_t renderTimestampNs = data.ReadInt64(); | 655 | int64_t renderTimestampNs = data.ReadInt64(); |
| 656 | CHECK_AND_RETURN_RET_LOG_WITH_TAG(listener_ != nullptr, AVCS_ERR_INVALID_OPERATION, "Codec listener is nullptr"); | 656 | CHECK_AND_RETURN_RET_LOG_WITH_TAG(listener_ != nullptr, AVCS_ERR_INVALID_OPERATION, "Codec listener is nullptr"); |