Merge "Add logs to measure xRT for synthesizing from tts engine" into tizen
[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         AudioStream();
35         ~AudioStream();
36
37         int setAudioFormat(ttse_audio_type_e type, int rate);
38         int acquireSoundFocus();
39         int releaseSoundFocus();
40         int prepareAudioOut();
41         int unprepareAudioOut();
42         void waitForPlay();
43         AudioState getState();
44         int playAudioData(char* buffer, unsigned int length);
45
46 private:
47         static void focusStateChangedCallback(sound_stream_info_h stream_info, sound_stream_focus_mask_e focus_mask,
48                         sound_stream_focus_state_e focus_state, sound_stream_focus_change_reason_e reason_for_change, int sound_behavior, const char *extra_info,
49                         void *user_data);
50
51         bool isAudioHandleValid();
52         bool isStreamInfoValid();
53
54         int createAudioHandle(ttse_audio_type_e type, int rate);
55         void destroyAudioHandle();
56
57         int createSoundStreamInfo();
58         void destroySoundStreamInfo();
59
60 private:
61         audio_out_h mAudioHandle;
62         ttse_audio_type_e mAudioType;
63         int mAudioRate;
64         bool mPrepared;
65
66         sound_stream_info_h mStreamInfo;
67         bool mFocusAquired;
68
69         AudioState mState;
70 };
71
72
73 #endif /* __TTSD_AUDIO_OUT_H_ */