• 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 #ifndef LOG_TAG
17 #define LOG_TAG "AudioWorkgroup"
18 #endif
19 
20 #include "audio_workgroup.h"
21 #include "audio_common_log.h"
22 #include "rtg_interface.h"
23 #include "audio_utils.h"
24 #include "concurrent_task_client.h"
25 
26 using namespace OHOS::RME;
27 
28 namespace OHOS {
29 namespace AudioStandard {
30 constexpr unsigned int MS_PER_SECOND = 1000;
31 
AudioWorkgroup(int32_t id)32 AudioWorkgroup::AudioWorkgroup(int32_t id) : workgroupId(id)
33 {
34     AUDIO_INFO_LOG("OHAudioWorkgroup Constructor is called\n");
35 }
36 
GetWorkgroupId()37 int32_t AudioWorkgroup::GetWorkgroupId()
38 {
39     return workgroupId;
40 }
41 
GetThreadsNums()42 uint32_t AudioWorkgroup::GetThreadsNums()
43 {
44     return threads.size();
45 }
46 
AddThread(int32_t tid)47 int32_t AudioWorkgroup::AddThread(int32_t tid)
48 {
49     ConcurrentTask::IntervalReply reply;
50     OHOS::ConcurrentTask::ConcurrentTaskClient::GetInstance().SetAudioDeadline(
51         ConcurrentTask::AUDIO_DDL_ADD_THREAD, tid, workgroupId, reply);
52     if (reply.paramA < 0) {
53         AUDIO_INFO_LOG("AudioWorkgroup AddThread Failed!\n");
54         return AUDIO_ERR;
55     }
56     threads[tid] = true;
57     return AUDIO_OK;
58 }
59 
RemoveThread(int32_t tid)60 int32_t AudioWorkgroup::RemoveThread(int32_t tid)
61 {
62     ConcurrentTask::IntervalReply reply;
63     OHOS::ConcurrentTask::ConcurrentTaskClient::GetInstance().SetAudioDeadline(
64         ConcurrentTask::AUDIO_DDL_REMOVE_THREAD, tid, workgroupId, reply);
65     if (reply.paramA < 0) {
66         AUDIO_INFO_LOG("AudioWorkgroup RemoveThread Failed!\n");
67         return AUDIO_ERR;
68     }
69     threads.erase(tid);
70     return AUDIO_OK;
71 }
72 
Start(uint64_t startTime,uint64_t deadlineTime)73 int32_t AudioWorkgroup::Start(uint64_t startTime, uint64_t deadlineTime)
74 {
75     if (deadlineTime <= startTime) {
76         AUDIO_ERR_LOG("[WorkgroupInServer] Invalid params When Start!");
77         return AUDIO_ERR;
78     }
79     SetFrameRateAndPrioType(workgroupId, MS_PER_SECOND/(deadlineTime - startTime), 0);
80     if (BeginFrameFreq(0) != 0) {
81         AUDIO_ERR_LOG("[WorkgroupInServer] Audio Deadline BeginFrame Failed!");
82         return AUDIO_ERR;
83     }
84     return AUDIO_OK;
85 }
86 
Stop()87 int32_t AudioWorkgroup::Stop()
88 {
89     if (EndFrameFreq(0) != 0) {
90         AUDIO_ERR_LOG("[WorkgroupInServer] Audio Deadline EndFrame Failed!");
91         return AUDIO_ERR;
92     }
93     return AUDIO_OK;
94 }
95 } // namespace AudioStandard
96 } // namespace OHOS