• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2025-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 "OHAudioWorkgroup.h"
17 #include "audio_log.h"
18 #include <unistd.h>
19 #include <fcntl.h>
20 
21 namespace OHOS {
22 namespace AudioStandard {
23 
OHAudioWorkgroup(int id)24 OHAudioWorkgroup::OHAudioWorkgroup(int id) : workgroupId(id)
25 {
26     AUDIO_INFO_LOG("OHAudioWorkgroup Constructor is called\n");
27 }
28 
~OHAudioWorkgroup()29 OHAudioWorkgroup::~OHAudioWorkgroup()
30 {
31 }
32 
AddThread(int32_t tokenId)33 bool OHAudioWorkgroup::AddThread(int32_t tokenId)
34 {
35     if (AudioSystemManager::GetInstance()->AddThreadToGroup(workgroupId, tokenId) == AUDIO_OK) {
36         threads_[tokenId] = true;
37         SetNeedUpdatePrioFlag(true);
38         return true;
39     }
40     return false;
41 }
42 
RemoveThread(int32_t tokenId)43 bool OHAudioWorkgroup::RemoveThread(int32_t tokenId)
44 {
45     if (AudioSystemManager::GetInstance()->RemoveThreadFromGroup(workgroupId, tokenId) == AUDIO_OK) {
46         threads_.erase(tokenId);
47         return true;
48     }
49     return false;
50 }
51 
Start(uint64_t startTime,uint64_t deadlineTime)52 bool OHAudioWorkgroup::Start(uint64_t startTime, uint64_t deadlineTime)
53 {
54     bool isUpdatePrio = GetNeedUpdatePrioFlag();
55     if (AudioSystemManager::GetInstance()->StartGroup(workgroupId, startTime, deadlineTime,
56         threads_, isUpdatePrio) == AUDIO_OK) {
57         SetNeedUpdatePrioFlag(isUpdatePrio);
58         return true;
59     }
60     return false;
61 }
62 
Stop()63 bool OHAudioWorkgroup::Stop()
64 {
65     if (AudioSystemManager::GetInstance()->StopGroup(workgroupId) == AUDIO_OK) {
66         return true;
67     }
68     return false;
69 }
70 
GetNeedUpdatePrioFlag()71 bool OHAudioWorkgroup::GetNeedUpdatePrioFlag()
72 {
73     return isNeedUpdatePrio_;
74 }
75 
SetNeedUpdatePrioFlag(bool flag)76 void OHAudioWorkgroup::SetNeedUpdatePrioFlag(bool flag)
77 {
78     isNeedUpdatePrio_ = flag;
79 }
80 
81 }  // namespace AudioStandard
82 }  // namespace OHOS