1 /*
2 * Copyright (C) 2025 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16 #include "soundpool_xcollie.h"
17 #include <unistd.h>
18 #include "media_errors.h"
19 #include "media_log.h"
20 #include "xcollie/xcollie.h"
21 #include "xcollie/xcollie_define.h"
22
23 namespace {
24 constexpr OHOS::HiviewDFX::HiLogLabel LABEL = {LOG_CORE, LOG_DOMAIN_PLAYER, "SoundPoolXCollie"};
25 }
26
27 namespace OHOS {
28 namespace Media {
29
SoundPoolXCollie(const std::string & tag,std::function<void (void *)> func,uint32_t timeoutSeconds,void * arg,uint32_t flag)30 SoundPoolXCollie::SoundPoolXCollie(const std::string &tag, std::function<void(void *)> func,
31 uint32_t timeoutSeconds, void *arg, uint32_t flag)
32 {
33 id_ = HiviewDFX::XCollie::GetInstance().SetTimer(tag, timeoutSeconds, func, arg, flag);
34 tag_ = tag;
35 }
36
~SoundPoolXCollie()37 SoundPoolXCollie::~SoundPoolXCollie()
38 {
39 CancelXCollieTimer();
40 }
41
CancelXCollieTimer()42 void SoundPoolXCollie::CancelXCollieTimer()
43 {
44 if (!isCanceled_ && id_ != HiviewDFX::INVALID_ID) {
45 HiviewDFX::XCollie::GetInstance().CancelTimer(id_);
46 isCanceled_ = true;
47 }
48 }
49
50 } // namespace Media
51 } // namespace OHOS