Define class for managing audio stream
[platform/core/uifw/tts.git] / server / AudioStream.h
1 /*
2 *  Copyright (c) 2021 Samsung Electronics Co., Ltd All Rights Reserved
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 *  http://www.apache.org/licenses/LICENSE-2.0
7 *  Unless required by applicable law or agreed to in writing, software
8 *  distributed under the License is distributed on an "AS IS" BASIS,
9 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10 *  See the License for the specific language governing permissions and
11 *  limitations under the License.
12 */
13
14
15 #ifndef __TTSD_AUDIO_OUT_H_
16 #define __TTSD_AUDIO_OUT_H_
17
18
19 #include <string>
20 #include <audio_io.h>
21 #include <sound_manager.h>
22
23 #include "ttse.h"
24
25 class AudioStream {
26 public:
27         enum AudioState{
28                 AUDIO_STATE_NONE = 0,
29                 AUDIO_STATE_READY,
30                 AUDIO_STATE_WAIT_FOR_PLAYING,
31                 AUDIO_STATE_PLAY
32         };
33
34         typedef void (*focusReleaseCallback)();
35
36         AudioStream(focusReleaseCallback focusReleaseCb);
37         ~AudioStream();
38
39         int setAudioFormat(ttse_audio_type_e type, int rate);
40         int acquireSoundFocus(const char* extra_info);
41         int releaseSoundFocus();
42         int prepareAudioOut();
43         int unprepareAudioOut();
44         void waitForPlay();
45         AudioState getState();
46         int playAudioData(char* buffer, unsigned int length);
47
48 private:
49         static void __focusStateChangedCallback(sound_stream_info_h stream_info, sound_stream_focus_mask_e focus_mask,
50                         sound_stream_focus_state_e focus_state, sound_stream_focus_change_reason_e reason_for_change, int sound_behavior, const char *extra_info,
51                         void *user_data);
52
53         int createAudioHandle(ttse_audio_type_e type, int rate);
54         void destroyAudioHandle();
55
56         void createSoundStreamInfo();
57         void destroySoundStreamInfo();
58
59 private:
60         audio_out_h __audioHandle;
61         ttse_audio_type_e __audioType;
62         int __audioRate;
63         bool __prepared;
64
65         sound_stream_info_h __streamInfo;
66         focusReleaseCallback __focusReleaseCallback;
67         std::string __currentExtraInfo;
68         bool __focusAquired;
69
70         AudioState __state;
71 };
72
73
74 #endif /* __TTSD_AUDIO_OUT_H_ */