[dali_2.3.26] Merge branch 'devel/master'
[platform/core/uifw/dali-adaptor.git] / dali / internal / accessibility / tizen-wayland / tts-player-impl-tizen.h
1 #ifndef DALI_INTERNAL_ACCESSIBILITY_TIZEN_TTS_PLAYER_IMPL_TIZEN_H
2 #define DALI_INTERNAL_ACCESSIBILITY_TIZEN_TTS_PLAYER_IMPL_TIZEN_H
3
4 /*
5  * Copyright (c) 2021 Samsung Electronics Co., Ltd.
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  *
19  */
20
21 // EXTERNAL INCLUDES
22 #include <tts.h>
23 #include <memory>
24 #include <string>
25
26 #include <dali/integration-api/debug.h>
27 #include <dali/public-api/object/base-object.h>
28
29 // INTERNAL INCLUDES
30 #include <dali/internal/accessibility/common/tts-player-impl.h>
31 #include <dali/public-api/adaptor-framework/tts-player.h>
32
33 namespace Dali
34 {
35 namespace Internal
36 {
37 namespace Adaptor
38 {
39 /**
40  * Text-to-speech player
41  */
42 class TtsPlayerTizen : public Dali::Internal::Adaptor::TtsPlayer
43 {
44 public:
45   /**
46    * Create a TtsPlayer with the given mode.
47    * This should only be called once by the Adaptor class for each given mode.
48    * @param mode the mode of tts-player
49    * @return A newly created TtsPlayer.
50    */
51   static std::unique_ptr<TtsPlayerTizen> New(Dali::TtsPlayer::Mode mode);
52
53   /**
54    * @copydoc TtsPlayer::Play()
55    */
56   void Play(const std::string& text) override;
57
58   /**
59    * @copydoc TtsPlayer::Stop()
60    */
61   void Stop() override;
62
63   /**
64    * @copydoc TtsPlayer::Pause()
65    */
66   void Pause() override;
67
68   /**
69    * @copydoc TtsPlayer::Resume()
70    */
71   void Resume() override;
72
73   /**
74    * @copydoc TtsPlayer::GetState()
75    */
76   Dali::TtsPlayer::State GetState() override;
77
78   /**
79    * @copydoc TtsPlayer::StateChangedSignal()
80    */
81   Dali::TtsPlayer::StateChangedSignalType& StateChangedSignal() override;
82
83   /**
84    * Destructor
85    */
86   ~TtsPlayerTizen() override;
87
88 private:
89   /**
90    * Private Constructor; see also TtsPlayer::New()
91    * @param mode the mode of tts-player
92    */
93   TtsPlayerTizen(Dali::TtsPlayer::Mode mode);
94
95   /**
96    * Initializes the player.
97    */
98   void Initialize();
99
100   /**
101    * Logs the error code.
102    * @param[in] reason The error code
103    */
104   void LogErrorCode(tts_error_e reason);
105
106   /**
107    * Used to emit the state changed signal from outside the object (EG. A static function).
108    * @param[in] previous The previous state
109    * @param[in] current The current state
110    */
111   void EmitStateChangedSignal(tts_state_e previous, tts_state_e current);
112
113   /**
114    * Called when the state of TTS is changed.
115    *
116    * @param[in] tts The handle for TTS
117    * @param[in] previous A previous state
118    * @param[in] current A current state
119    * @param[in] userData The user data passed from the callback registration function.
120    */
121   static void StateChangedCallback(tts_h tts, tts_state_e previous, tts_state_e current, void* userData);
122
123   // Undefined
124   TtsPlayerTizen(const TtsPlayerTizen&);
125
126   // Undefined
127   TtsPlayerTizen& operator=(TtsPlayerTizen&);
128
129 private:
130   Dali::TtsPlayer::StateChangedSignalType mStateChangedSignal; ///< Signal emitted when the TTS state changes
131   bool                                    mInitialized;        ///< Whether the TTS player is initialised successfully or not
132   std::string                             mUnplayedString;     ///< The text that can not be played because tts engine is not yet initialized
133   tts_h                                   mTtsHandle;          ///< The handle of TTS
134   int                                     mUtteranceId;        ///< The utterance ID
135
136   Dali::TtsPlayer::Mode mTtsMode; ///< The current mode of tts engine
137
138 #if defined(DEBUG_ENABLED)
139 public:
140   static Debug::Filter* gLogFilter;
141 #endif
142 };
143
144 } // namespace Adaptor
145
146 } // namespace Internal
147
148 } // namespace Dali
149
150 #endif // DALI_INTERNAL_ACCESSIBILITY_TIZEN_TTS_PLAYER_IMPL_TIZEN_H