RDK Documentation (Open Sourced RDK Components)
acm_session_mgr.h
1 /*
2  * If not stated otherwise in this file or this component's Licenses.txt file the
3  * following copyright and licenses apply:
4  *
5  * Copyright 2016 RDK Management
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 #include "audio_capture_manager.h"
20 #include "music_id.h"
21 #include "ip_out.h"
22 #include "audiocapturemgr_iarm.h"
23 #include <vector>
24 #include <list>
25 
26 /**
27  * @addtogroup AUDIO_CAPTURE_MANAGER_API
28  * @{
29  */
30 
31 typedef struct
32 {
33  int session_id;
34  audio_capture_client * client;
35  q_mgr * source;
36  bool enable;
37  audiocapturemgr::iarmbus_output_type_t output_type;
39 
41 {
42  private:
43  std::list <acm_session_t *> m_sessions;
44  std::vector <q_mgr *> m_sources;
45  pthread_mutex_t m_mutex;
46  int m_session_counter;
47 
48  public:
50  ~acm_session_mgr();
51  static acm_session_mgr * get_instance();
52 
53  /**
54  * @brief This API initializes the message bus, registers event, RPC methods to be used
55  * by other applications.
56  *
57  * RPC methods like
58  * - request audiocapture sample
59  * - open
60  * - close
61  * - start
62  * - stop
63  * - get default audio properties
64  * - get audio properties
65  * - get output properties
66  * - set audio properties
67  * - set output properties
68  *
69  * @return Returns 0 on success, appropriate error code otherwise.
70  */
71  int activate();
72 
73  /**
74  * @brief This API disconnects application from the message bus, releases memory.
75  *
76  * Also, unregisters the client from the application.
77  *
78  * @return Returns 0 on success, appropriate error code otherwise.
79  */
80  int deactivate();
81 
82  /**
83  * @brief This API grabs the precaptured sample, if the requested data has precapture flag true.
84  * Otherwise, capture fresh sample.
85  *
86  * @param[in] arg Payload data
87  *
88  * @return Returns ACM_RESULT_GENERAL_FAILURE on failure, 0 on success.
89  *
90  */
91  int get_sample_handler(void * arg);
92 
93  int generic_handler(void * arg);
94 
95  /**
96  * @brief This API creates the music id session. It's also used by bluetooth manager as an audio source.
97  *
98  * Accepts only one instance of music id client per source type.
99  *
100  * @param[in] arg Structure variable that holds the details like audio source, output types etc.
101  *
102  * @return Returns 0 on success, appropriate error code otherwise.
103  */
104  int open_handler(void * arg);
105 
106  /**
107  * @brief This API destroys the music id session, bluetooth manager session.
108  *
109  * @param[in] arg Structure variable that holds the details like audio source, output types etc.
110  *
111  * @return Returns 0 on success, appropriate error code otherwise.
112  */
113  int close_handler(void * arg);
114 
115  /**
116  * @brief This API returns default capture settings.
117  *
118  * Settings like format, sampling frequency, FIFO size, threshold etc.
119  *
120  * @param[in] arg Indicates the audio properties.
121  *
122  * @return Returns 0 on success, appropriate error code otherwise.
123  */
124  int get_default_audio_props_handler(void * arg);
125 
126  /**
127  * @brief This API returns the audio properties of a current session.
128  *
129  * @param[in] arg Indicates the audio properties.
130  *
131  * @return Returns 0 on success, appropriate error code otherwise.
132  */
133  int get_audio_props_handler(void * arg);
134 
135  /**
136  * @brief This API returns the output properties of a current session.
137  *
138  * Depending on the output type socket or file output.
139  *
140  * @param[in] arg Indicates the output properties.
141  *
142  * @return Returns 0 on success, appropriate error code otherwise.
143  */
144  int get_output_props_handler(void * arg);
145 
146  /**
147  * @brief This API is used to set the audio properties of a current session.
148  *
149  * Properties like Format, Frequency, FIFO size, threshold, delay etc.
150  *
151  * @param[in] arg Indicates the audio properties to set.
152  *
153  * @return Returns 0 on success, appropriate error code otherwise.
154  */
155  int set_audio_props_handler(void * arg);
156 
157  /**
158  * @brief This API is to set precapture duration of a client device.
159  *
160  * @param[in] arg Indicates the output type.
161  *
162  * @return Returns 0 on success, appropriate error code otherwise.
163  */
164  int set_output_props_handler(void * arg);
165 
166  /**
167  * @brief This API starts the client session.
168  *
169  * @param[in] arg IARM bus arguments.
170  *
171  * @return Returns 0 on success, appropriate error code otherwise.
172  */
173  int start_handler(void * arg);
174 
175  /**
176  * @brief This API stops the current session.
177  *
178  * @param[in] arg IARM bus arguments.
179  *
180  * @return Returns 0 on success, appropriate error code otherwise.
181  */
182  int stop_handler(void * arg);
183 
184  /**
185  * @brief Function to add prefix to the audio filename.
186  *
187  * @param[in] prefix Prefix to be added.
188  */
189  void set_filename_prefix(std::string &prefix);
190 
191  private:
192  q_mgr * get_source(int source);
193  void lock();
194  void unlock();
195  acm_session_t * get_session(int session_id);
196 };
197 
198 /**
199  * @}
200  */
201 
202 
acm_session_mgr::set_audio_props_handler
int set_audio_props_handler(void *arg)
This API is used to set the audio properties of a current session.
Definition: acm_session_mgr.cpp:572
acm_session_t
Definition: acm_session_mgr.h:31
audio_capture_client
Definition: audio_capture_manager.h:219
acm_session_mgr::get_audio_props_handler
int get_audio_props_handler(void *arg)
This API returns the audio properties of a current session.
Definition: acm_session_mgr.cpp:456
acm_session_mgr::open_handler
int open_handler(void *arg)
This API creates the music id session. It's also used by bluetooth manager as an audio source.
Definition: acm_session_mgr.cpp:205
acm_session_mgr::activate
int activate()
This API initializes the message bus, registers event, RPC methods to be used by other applications.
Definition: acm_session_mgr.cpp:152
acm_session_mgr::get_sample_handler
int get_sample_handler(void *arg)
This API grabs the precaptured sample, if the requested data has precapture flag true....
Definition: acm_session_mgr.cpp:684
acm_session_mgr::stop_handler
int stop_handler(void *arg)
This API stops the current session.
Definition: acm_session_mgr.cpp:358
acm_session_mgr
Definition: acm_session_mgr.h:40
acm_session_mgr::get_default_audio_props_handler
int get_default_audio_props_handler(void *arg)
This API returns default capture settings.
Definition: acm_session_mgr.cpp:383
q_mgr
Definition: audio_capture_manager.h:70
acm_session_mgr::deactivate
int deactivate()
This API disconnects application from the message bus, releases memory.
Definition: acm_session_mgr.cpp:179
acm_session_mgr::start_handler
int start_handler(void *arg)
This API starts the client session.
Definition: acm_session_mgr.cpp:333
acm_session_mgr::close_handler
int close_handler(void *arg)
This API destroys the music id session, bluetooth manager session.
Definition: acm_session_mgr.cpp:275
acm_session_mgr::get_output_props_handler
int get_output_props_handler(void *arg)
This API returns the output properties of a current session.
Definition: acm_session_mgr.cpp:530
acm_session_mgr::set_output_props_handler
int set_output_props_handler(void *arg)
This API is to set precapture duration of a client device.
Definition: acm_session_mgr.cpp:649
acm_session_mgr::set_filename_prefix
void set_filename_prefix(std::string &prefix)
Function to add prefix to the audio filename.
Definition: acm_session_mgr.cpp:751