• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021 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 "audio_transport_pause_status.h"
17 
18 #include "daudio_errorcode.h"
19 #include "daudio_log.h"
20 
21 #undef DH_LOG_TAG
22 #define DH_LOG_TAG "AudioTransportPauseStatus"
23 
24 namespace OHOS {
25 namespace DistributedHardware {
AudioTransportPauseStatus(std::shared_ptr<AudioTransportContext> & stateContext)26 AudioTransportPauseStatus::AudioTransportPauseStatus(std::shared_ptr<AudioTransportContext>& stateContext)
27     : stateContext_(stateContext)
28 {
29     DHLOGD("AudioTransportPauseStatus contruct.");
30 }
31 
Start(std::shared_ptr<IAudioChannel> audioChannel,std::shared_ptr<IAudioProcessor> processor)32 int32_t AudioTransportPauseStatus::Start(std::shared_ptr<IAudioChannel> audioChannel,
33     std::shared_ptr<IAudioProcessor> processor)
34 {
35     (void)audioChannel;
36     (void)processor;
37     DHLOGE("Audiotransportstatus is pause, can not start.");
38     return ERR_DH_AUDIO_TRANS_ILLEGAL_OPERATION;
39 }
40 
Stop(std::shared_ptr<IAudioChannel> audioChannel,std::shared_ptr<IAudioProcessor> processor)41 int32_t AudioTransportPauseStatus::Stop(std::shared_ptr<IAudioChannel> audioChannel,
42     std::shared_ptr<IAudioProcessor> processor)
43 {
44     (void)processor;
45     DHLOGI("Audiotransport status is pause.");
46     if (audioChannel == nullptr) {
47         DHLOGE("audioChannel is null.");
48         return ERR_DH_AUDIO_NULLPTR;
49     }
50     int32_t ret = audioChannel->CloseSession();
51     if (ret != DH_SUCCESS) {
52         DHLOGE("Close session failed, ret: %d.", ret);
53         return ret;
54     }
55     std::shared_ptr<AudioTransportContext> stateContext = stateContext_.lock();
56     if (stateContext == nullptr) {
57         DHLOGE("AudioTransport start can not get context");
58         return ERR_DH_AUDIO_NULLPTR;
59     }
60     stateContext->SetTransportStatus(TRANSPORT_STATE_STOP);
61     return DH_SUCCESS;
62 }
63 
Pause(std::shared_ptr<IAudioProcessor> processor)64 int32_t AudioTransportPauseStatus::Pause(std::shared_ptr<IAudioProcessor> processor)
65 {
66     (void)processor;
67     DHLOGI("Audiotransport status is pasue.");
68     return DH_SUCCESS;
69 }
70 
Restart(const AudioParam & localParam,const AudioParam & remoteParam,std::shared_ptr<IAudioProcessor> processor)71 int32_t AudioTransportPauseStatus::Restart(const AudioParam &localParam, const AudioParam &remoteParam,
72     std::shared_ptr<IAudioProcessor> processor)
73 {
74     DHLOGI("Restart.");
75     if (processor == nullptr) {
76         DHLOGE("processor is null.");
77         return ERR_DH_AUDIO_NULLPTR;
78     }
79     auto ret = processor->StartAudioProcessor();
80     if (ret != DH_SUCCESS) {
81         DHLOGE("Restart processor_ failed, ret: %d.", ret);
82         return ret;
83     }
84     std::shared_ptr<AudioTransportContext> stateContext = stateContext_.lock();
85     if (stateContext == nullptr) {
86         DHLOGE("AudioTransport start can not get context");
87         return ERR_DH_AUDIO_NULLPTR;
88     }
89     stateContext->SetTransportStatus(TRANSPORT_STATE_START);
90     DHLOGI("Restart success.");
91     return DH_SUCCESS;
92 }
93 
GetStateType()94 TransportStateType AudioTransportPauseStatus::GetStateType()
95 {
96     DHLOGI("Audiotransport get state stype.");
97     return TRANSPORT_STATE_PAUSE;
98 }
99 } // namespace DistributedHardware
100 } // namespace OHOS
101