RDK Documentation (Open Sourced RDK Components)
acm_session_mgr.cpp
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 "acm_session_mgr.h"
20 #include "audiocapturemgr_iarm.h"
21 #include <string>
22 #include <string.h>
23 #include <sstream>
24 #include <stdlib.h>
25 #include "libIARM.h"
26 #include "libIBus.h"
27 #include "safec_lib.h"
28 
29 using namespace audiocapturemgr;
30 
31 static const unsigned int MAX_SUPPORTED_SOURCES = 1; //Primary only at the moment
32 static acm_session_mgr g_singleton;
33 
34 static unsigned int ticker = 0;
35 std::string audio_filename_prefix = AUDIOCAPTUREMGR_FILENAME_PREFIX;
36 std::string audio_file_path = AUDIOCAPTUREMGR_FILE_PATH;
37 
38 static void request_callback(void * data, std::string &file, int result)
39 {
40  errno_t rc = -1;
41  if(0 != result)
42  {
43  ERROR("Failed to grab sample.\n");
44  }
45  else
46  {
48  rc = strcpy_s(payload.dataLocator, sizeof(payload.dataLocator), file.c_str());
49  if(rc == EOK)
50  {
51  int ret = IARM_Bus_BroadcastEvent(IARMBUS_AUDIOCAPTUREMGR_NAME, DATA_CAPTURE_IARM_EVENT_AUDIO_CLIP_READY, &payload, sizeof(payload));
52  REPORT_IF_UNEQUAL(IARM_RESULT_SUCCESS, ret);
53  }
54  else
55  {
56  ERR_CHK(rc);
57  WARN("Incoming filename is too big for payload buffer.\n");
58  }
59  }
60 }
61 
62 static IARM_Result_t request_sample(void * arg)
63 {
64  g_singleton.get_sample_handler(arg);
65  return IARM_RESULT_SUCCESS;
66 }
67 
68 static IARM_Result_t open(void * arg)
69 {
70  g_singleton.open_handler(arg);
71  return IARM_RESULT_SUCCESS;
72 }
73 static IARM_Result_t close(void * arg)
74 {
75  g_singleton.close_handler(arg);
76  return IARM_RESULT_SUCCESS;
77 }
78 static IARM_Result_t start(void * arg)
79 {
80  g_singleton.start_handler(arg);
81  return IARM_RESULT_SUCCESS;
82 }
83 static IARM_Result_t stop(void * arg)
84 {
85  g_singleton.stop_handler(arg);
86  return IARM_RESULT_SUCCESS;
87 }
88 static IARM_Result_t get_audio_props(void * arg)
89 {
90  g_singleton.get_audio_props_handler(arg);
91  return IARM_RESULT_SUCCESS;
92 }
93 static IARM_Result_t get_default_audio_props(void * arg)
94 {
95  g_singleton.get_default_audio_props_handler(arg);
96  return IARM_RESULT_SUCCESS;
97 }
98 static IARM_Result_t get_output_props(void * arg)
99 {
100  g_singleton.get_output_props_handler(arg);
101  return IARM_RESULT_SUCCESS;
102 }
103 static IARM_Result_t set_output_props(void * arg)
104 {
105  g_singleton.set_output_props_handler(arg);
106  return IARM_RESULT_SUCCESS;
107 }
108 static IARM_Result_t set_audio_props(void * arg)
109 {
110  g_singleton.set_audio_props_handler(arg);
111  return IARM_RESULT_SUCCESS;
112 }
113 acm_session_mgr::acm_session_mgr() : m_session_counter(0)
114 {
115  INFO("Enter\n");
116 
117  for(unsigned int i = 0; i < MAX_SUPPORTED_SOURCES; i++)
118  {
119  m_sources.push_back((q_mgr *)NULL);
120  }
121 
122  /*Add primary audio to the list of sources*/
123  m_sources[0] = new q_mgr;
124 
125  pthread_mutexattr_t mutex_attribute;
126  REPORT_IF_UNEQUAL(0, pthread_mutexattr_init(&mutex_attribute));
127  REPORT_IF_UNEQUAL(0, pthread_mutexattr_settype(&mutex_attribute, PTHREAD_MUTEX_ERRORCHECK));
128  REPORT_IF_UNEQUAL(0, pthread_mutex_init(&m_mutex, &mutex_attribute));
129 }
130 
131 acm_session_mgr::~acm_session_mgr()
132 {
133  INFO("Enter\n");
134  REPORT_IF_UNEQUAL(0, pthread_mutex_destroy(&m_mutex));
135 }
136 
137 void acm_session_mgr::lock()
138 {
139  REPORT_IF_UNEQUAL(0, pthread_mutex_lock(&m_mutex));
140 }
141 
142 void acm_session_mgr::unlock()
143 {
144  REPORT_IF_UNEQUAL(0, pthread_mutex_unlock(&m_mutex));
145 }
146 
147 acm_session_mgr * acm_session_mgr::get_instance()
148 {
149  return &g_singleton;
150 }
151 
153 {
154  int ret;
155  INFO("Enter\n");
156 
157  //TODO: add early exit for each of the failures below
158  ret = IARM_Bus_Init(IARMBUS_AUDIOCAPTUREMGR_NAME);
159  REPORT_IF_UNEQUAL(IARM_RESULT_SUCCESS, ret);
160 
161  ret = IARM_Bus_Connect();
162  REPORT_IF_UNEQUAL(IARM_RESULT_SUCCESS, ret);
163 
164  ret = IARM_Bus_RegisterEvent(IARMBUS_MAX_ACM_EVENT);
165  REPORT_IF_UNEQUAL(IARM_RESULT_SUCCESS, ret);
166 
167  ret = IARM_Bus_RegisterCall(IARMBUS_AUDIOCAPTUREMGR_REQUEST_SAMPLE, request_sample); REPORT_IF_UNEQUAL(IARM_RESULT_SUCCESS, ret);
168  ret = IARM_Bus_RegisterCall(IARMBUS_AUDIOCAPTUREMGR_OPEN, open); REPORT_IF_UNEQUAL(IARM_RESULT_SUCCESS, ret);
169  ret = IARM_Bus_RegisterCall(IARMBUS_AUDIOCAPTUREMGR_CLOSE, close); REPORT_IF_UNEQUAL(IARM_RESULT_SUCCESS, ret);
170  ret = IARM_Bus_RegisterCall(IARMBUS_AUDIOCAPTUREMGR_START, start); REPORT_IF_UNEQUAL(IARM_RESULT_SUCCESS, ret);
171  ret = IARM_Bus_RegisterCall(IARMBUS_AUDIOCAPTUREMGR_STOP, stop); REPORT_IF_UNEQUAL(IARM_RESULT_SUCCESS, ret);
172  ret = IARM_Bus_RegisterCall(IARMBUS_AUDIOCAPTUREMGR_GET_DEFAULT_AUDIO_PROPS, get_default_audio_props); REPORT_IF_UNEQUAL(IARM_RESULT_SUCCESS, ret);
173  ret = IARM_Bus_RegisterCall(IARMBUS_AUDIOCAPTUREMGR_GET_AUDIO_PROPS, get_audio_props); REPORT_IF_UNEQUAL(IARM_RESULT_SUCCESS, ret);
174  ret = IARM_Bus_RegisterCall(IARMBUS_AUDIOCAPTUREMGR_GET_OUTPUT_PROPS, get_output_props); REPORT_IF_UNEQUAL(IARM_RESULT_SUCCESS, ret);
175  ret = IARM_Bus_RegisterCall(IARMBUS_AUDIOCAPTUREMGR_SET_AUDIO_PROPERTIES, set_audio_props); REPORT_IF_UNEQUAL(IARM_RESULT_SUCCESS, ret);
176  ret = IARM_Bus_RegisterCall(IARMBUS_AUDIOCAPTUREMGR_SET_OUTPUT_PROPERTIES, set_output_props); REPORT_IF_UNEQUAL(IARM_RESULT_SUCCESS, ret);
177  return ret;
178 }
180 {
181  int ret;
182  INFO("Enter\n");
183  ret = IARM_Bus_Disconnect();
184  REPORT_IF_UNEQUAL(IARM_RESULT_SUCCESS, ret);
185  ret = IARM_Bus_Term();
186  REPORT_IF_UNEQUAL(IARM_RESULT_SUCCESS, ret);
187  return ret;
188 }
189 
190 static bool get_rfc_output_conversion_config()
191 {
192  int ret = system(". /lib/rdk/isFeatureEnabled.sh AcmEnableOpConv");
193  if((true == WEXITSTATUS(ret)) && (true == WIFEXITED(ret)))
194  {
195  INFO("RFC: enable song-id output conversion\n");
196  return true;
197  }
198  else
199  {
200  INFO("RFC: disable song-id output conversion.\n");
201  return false;
202  }
203 }
204 
206 {
207  iarmbus_acm_arg_t *param = static_cast <iarmbus_acm_arg_t *> (arg);
208  INFO("source: 0x%x, output type: 0x%x\n", param->details.arg_open.source, param->details.arg_open.output_type);
209  if( (MAX_SUPPORTED_SOURCES <= param->details.arg_open.source) || (MAX_SUPPORTED_OUTPUT_TYPES <= param->details.arg_open.output_type))
210  {
211  ERROR("Unsupported paramters.\n");
212  param->result = ACM_RESULT_INVALID_ARGUMENTS;
213  return param->result;
214  }
215 
216  acm_session_t *new_session = new acm_session_t;
217  new_session->source = m_sources[param->details.arg_open.source];
218  switch(param->details.arg_open.output_type)
219  {
220  case BUFFERED_FILE_OUTPUT:
221  new_session->client = new music_id_client(new_session->source, music_id_client::SOCKET_OUTPUT);
222  static_cast <music_id_client *> (new_session->client)->enable_output_conversion(get_rfc_output_conversion_config());
223  param->result = 0;
224  break;
225 
226  case REALTIME_SOCKET:
227  new_session->client = new ip_out_client(new_session->source);
228  param->result = 0;
229  break;
230 
231  default:
232  ERROR("Unrecognized output type.\n");
233  }
234  new_session->enable = false;
235  new_session->output_type = param->details.arg_open.output_type;
236 
237  acm_session_t *duplicate_session = NULL;
238 
239  lock();
240  new_session->session_id = m_session_counter++;
241  /*Special handling to deal with Receiver restarts. We accept only one instance of
242  * music id client per source type. If a new open request is made, this indicates the app
243  * that called for it has probably lost track (Receiver restart, maybe). Reuse the previous
244  * session*/
245  if(BUFFERED_FILE_OUTPUT == new_session->output_type)
246  {
247  std::list <acm_session_t *>::iterator iter;
248  for(iter = m_sessions.begin(); iter != m_sessions.end(); iter++)
249  {
250  if((BUFFERED_FILE_OUTPUT == (*iter)->output_type) && (new_session->source == (*iter)->source))
251  {
252  duplicate_session = *iter;
253  m_sessions.erase(iter);
254  break;
255  }
256  }
257  }
258  m_sessions.push_back(new_session);
259  unlock();
260 
261  if(duplicate_session)
262  {
263  WARN("Detroying existing music id session (id %d) for the same source.\n", duplicate_session->session_id);
264  duplicate_session->client->stop();
265  delete duplicate_session->client;
266  delete duplicate_session;
267  }
268  param->result = 0;
269  INFO("Created session 0x%x\n", new_session->session_id);
270  param->session_id = new_session->session_id;
271 
272  return param->result;
273 }
274 
276 {
277  iarmbus_acm_arg_t *param = static_cast <iarmbus_acm_arg_t *> (arg);
278  INFO("session_id 0x%x\n", param->session_id);
279 
280  acm_session_t * ptr = NULL;
281 
282  lock();
283  std::list <acm_session_t *>::iterator iter;
284  for(iter = m_sessions.begin(); iter != m_sessions.end(); iter++)
285  {
286  if(param->session_id == (*iter)->session_id)
287  {
288  ptr = *iter;
289  m_sessions.erase(iter);
290  break;
291  }
292  }
293  unlock();
294 
295  if(ptr)
296  {
297  if(ptr->enable)
298  {
299  ptr->client->stop();
300  ptr->enable = false;
301  INFO("Stopped session 0x%x.\n", param->session_id);
302  }
303  delete ptr->client;
304  delete ptr;
305  param->result = 0;
306  INFO("Session destroyed.\n");
307  }
308  else
309  {
310  WARN("Session not found!\n");
311  param->result = ACM_RESULT_BAD_SESSION_ID;
312  }
313  return param->result;
314 }
315 
316 acm_session_t * acm_session_mgr::get_session(int session_id)
317 {
318  acm_session_t * ptr = NULL;
319  lock();
320  std::list<acm_session_t *>::iterator iter;
321  for(iter = m_sessions.begin(); iter != m_sessions.end(); iter++)
322  {
323  if(session_id == (*iter)->session_id)
324  {
325  ptr = *iter;
326  break;
327  }
328  }
329  unlock();
330  return ptr;
331 }
332 
334 {
335  iarmbus_acm_arg_t *param = static_cast <iarmbus_acm_arg_t *> (arg);
336  INFO("session_id 0x%x\n", param->session_id);
337 
338  acm_session_t * ptr = get_session(param->session_id);
339  if(ptr)
340  {
341  if(!ptr->enable)
342  {
343  ptr->client->start();
344  ptr->enable = true;
345  INFO("Started session 0x%x.\n", param->session_id);
346  }
347  param->result = 0;
348  }
349  else
350  {
351  ERROR("Session not found!\n")
352  param->result = ACM_RESULT_BAD_SESSION_ID;
353  }
354 
355  return param->result;
356 }
357 
359 {
360  iarmbus_acm_arg_t *param = static_cast <iarmbus_acm_arg_t *> (arg);
361  INFO("session_id 0x%x\n", param->session_id);
362 
363  acm_session_t * ptr = get_session(param->session_id);
364  if(ptr)
365  {
366  if(ptr->enable)
367  {
368  ptr->client->stop();
369  ptr->enable = false;
370  INFO("Stopped session 0x%x.\n", param->session_id);
371  }
372  param->result = 0;
373  }
374  else
375  {
376  ERROR("Session not found!\n")
377  param->result = ACM_RESULT_BAD_SESSION_ID;
378  }
379 
380  return param->result;
381 }
382 
384 {
385  iarmbus_acm_arg_t *param = static_cast <iarmbus_acm_arg_t *> (arg);
386  INFO("session_id 0x%x\n", param->session_id);
387  acm_session_t * ptr = get_session(param->session_id);
388  if(ptr)
389  {
390  audio_properties_t props;
391  ptr->client->get_default_audio_properties(props);
392 
393  switch (props.format) {
395  param->details.arg_audio_properties.format = acmFormate16BitStereo;
396  break;
398  param->details.arg_audio_properties.format = acmFormate24BitStereo;
399  break;
401  param->details.arg_audio_properties.format = acmFormate16BitMonoLeft;
402  break;
404  param->details.arg_audio_properties.format = acmFormate16BitMonoRight;
405  break;
407  param->details.arg_audio_properties.format = acmFormate16BitMono;
408  break;
409  case racFormat_e24Bit5_1:
410  param->details.arg_audio_properties.format = acmFormate24Bit5_1;
411  break;
412  case racFormat_eMax:
413  param->details.arg_audio_properties.format = acmFormateMax;
414  break;
415  default:
416  param->details.arg_audio_properties.format = acmFormate16BitStereo;
417  break;
418  }
419 
420  switch (props.sampling_frequency) {
421  case racFreq_e16000:
422  param->details.arg_audio_properties.sampling_frequency = acmFreqe16000;
423  break;
424  case racFreq_e32000:
425  param->details.arg_audio_properties.sampling_frequency = acmFreqe32000;
426  break;
427  case racFreq_e44100:
428  param->details.arg_audio_properties.sampling_frequency = acmFreqe44100;
429  break;
430  case racFreq_e48000:
431  param->details.arg_audio_properties.sampling_frequency = acmFreqe48000;
432  break;
433  case racFreq_eMax:
434  param->details.arg_audio_properties.sampling_frequency = acmFreqeMax;
435  break;
436  default:
437  param->details.arg_audio_properties.sampling_frequency = acmFreqe48000;
438  break;
439  }
440 
441  param->details.arg_audio_properties.fifo_size = props.fifo_size;
442  param->details.arg_audio_properties.threshold = props.threshold;
443  param->details.arg_audio_properties.delay_compensation_ms = props.delay_compensation_ms;
444 
445  param->result = 0;
446  }
447  else
448  {
449  ERROR("Session not found!\n")
450  param->result = ACM_RESULT_BAD_SESSION_ID;
451  }
452  return param->result;
453 }
454 
455 
457 {
458  iarmbus_acm_arg_t *param = static_cast <iarmbus_acm_arg_t *> (arg);
459  INFO("session_id 0x%x\n", param->session_id);
460  acm_session_t * ptr = get_session(param->session_id);
461  if(ptr)
462  {
463  audio_properties_t props;
464  ptr->client->get_audio_properties(props);
465 
466  switch (props.format) {
468  param->details.arg_audio_properties.format = acmFormate16BitStereo;
469  break;
471  param->details.arg_audio_properties.format = acmFormate24BitStereo;
472  break;
474  param->details.arg_audio_properties.format = acmFormate16BitMonoLeft;
475  break;
477  param->details.arg_audio_properties.format = acmFormate16BitMonoRight;
478  break;
480  param->details.arg_audio_properties.format = acmFormate16BitMono;
481  break;
482  case racFormat_e24Bit5_1:
483  param->details.arg_audio_properties.format = acmFormate24Bit5_1;
484  break;
485  case racFormat_eMax:
486  param->details.arg_audio_properties.format = acmFormateMax;
487  break;
488  default:
489  param->details.arg_audio_properties.format = acmFormate16BitStereo;
490  break;
491  }
492 
493  switch (props.sampling_frequency) {
494  case racFreq_e16000:
495  param->details.arg_audio_properties.sampling_frequency = acmFreqe16000;
496  break;
497  case racFreq_e24000:
498  param->details.arg_audio_properties.sampling_frequency = acmFreqe24000;
499  break;
500  case racFreq_e32000:
501  param->details.arg_audio_properties.sampling_frequency = acmFreqe32000;
502  break;
503  case racFreq_e44100:
504  param->details.arg_audio_properties.sampling_frequency = acmFreqe44100;
505  break;
506  case racFreq_e48000:
507  param->details.arg_audio_properties.sampling_frequency = acmFreqe48000;
508  break;
509  case racFreq_eMax:
510  param->details.arg_audio_properties.sampling_frequency = acmFreqeMax;
511  break;
512  default:
513  param->details.arg_audio_properties.sampling_frequency = acmFreqe48000;
514  break;
515  }
516 
517  param->details.arg_audio_properties.fifo_size = props.fifo_size;
518  param->details.arg_audio_properties.threshold = props.threshold;
519  param->details.arg_audio_properties.delay_compensation_ms = props.delay_compensation_ms;
520 
521  param->result = 0;
522  }
523  else
524  {
525  ERROR("Session not found!\n")
526  param->result = ACM_RESULT_BAD_SESSION_ID;
527  }
528  return param->result;
529 }
531 {
532  errno_t rc = -1;
533  iarmbus_acm_arg_t *param = static_cast <iarmbus_acm_arg_t *> (arg);
534  INFO("session_id 0x%x\n", param->session_id);
535  acm_session_t * ptr = get_session(param->session_id);
536  if(ptr)
537  {
538  if(REALTIME_SOCKET == ptr->output_type)
539  {
540  ip_out_client * client = static_cast <ip_out_client *> (ptr->client);
541  std::string sock_path = client->get_data_path();
542  if(sock_path.empty())
543  {
544  param->result = ACM_RESULT_GENERAL_FAILURE;
545  }
546  else
547  {
548  int i32FilePathLen = sizeof(param->details.arg_output_props.output.file_path);
549  rc = strcpy_s(param->details.arg_output_props.output.file_path, i32FilePathLen, sock_path.c_str());
550  if(rc != EOK)
551  {
552  ERR_CHK(rc);
553  }
554  param->result = 0;
555  }
556  }
557  else if(BUFFERED_FILE_OUTPUT == ptr->output_type)
558  {
559  music_id_client * client = static_cast <music_id_client *> (ptr->client);
560  param->details.arg_output_props.output.max_buffer_duration = client->get_max_supported_duration();
561  param->result = 0;
562  }
563  }
564  else
565  {
566  ERROR("Session not found!\n")
567  param->result = ACM_RESULT_BAD_SESSION_ID;
568  }
569  return param->result;
570 }
571 
573 {
574  iarmbus_acm_arg_t *param = static_cast <iarmbus_acm_arg_t *> (arg);
575  INFO("session_id 0x%x\n", param->session_id);
576  acm_session_t * ptr = get_session(param->session_id);
577  if(ptr)
578  {
579  audio_properties_t props;
580 
581 
582  switch (param->details.arg_audio_properties.format) {
583  case acmFormate16BitStereo:
584  props.format = racFormat_e16BitStereo;
585  break;
586  case acmFormate24BitStereo:
587  props.format = racFormat_e24BitStereo;
588  break;
589  case acmFormate16BitMonoLeft:
590  props.format = racFormat_e16BitMonoLeft;
591  break;
592  case acmFormate16BitMonoRight:
593  props.format = racFormat_e16BitMonoRight;
594  break;
595  case acmFormate16BitMono:
596  props.format = racFormat_e16BitMono;
597  break;
598  case acmFormate24Bit5_1:
599  props.format = racFormat_e24Bit5_1;
600  break;
601  case acmFormateMax:
602  props.format = racFormat_eMax;
603  break;
604  default:
605  props.format = racFormat_e16BitStereo;
606  break;
607  }
608 
609  switch (param->details.arg_audio_properties.sampling_frequency) {
610  case acmFreqe16000:
611  props.sampling_frequency = racFreq_e16000;
612  break;
613  case acmFreqe24000:
614  props.sampling_frequency = racFreq_e24000;
615  break;
616  case acmFreqe32000:
617  props.sampling_frequency = racFreq_e32000;
618  break;
619  case acmFreqe44100:
620  props.sampling_frequency = racFreq_e44100;
621  break;
622  case acmFreqe48000:
623  props.sampling_frequency = racFreq_e48000;
624  break;
625  case acmFreqeMax:
626  props.sampling_frequency = racFreq_eMax;
627  break;
628  default:
629  props.sampling_frequency = racFreq_e48000;
630  break;
631  }
632 
633 
634  props.fifo_size = param->details.arg_audio_properties.fifo_size;
635  props.threshold = param->details.arg_audio_properties.threshold;
636  props.delay_compensation_ms = param->details.arg_audio_properties.delay_compensation_ms;
637 
638  param->result = ptr->client->set_audio_properties(props);
639  }
640  else
641  {
642  ERROR("Session not found!\n")
643  param->result = ACM_RESULT_BAD_SESSION_ID;
644  }
645  return param->result;
646 }
647 
648 
650 {
651  iarmbus_acm_arg_t *param = static_cast <iarmbus_acm_arg_t *> (arg);
652  INFO("session_id 0x%x\n", param->session_id);
653  acm_session_t * ptr = get_session(param->session_id);
654  if(ptr)
655  {
656  if(BUFFERED_FILE_OUTPUT == ptr->output_type)
657  {
658  music_id_client * client = static_cast <music_id_client *> (ptr->client);
659  unsigned int duration = param->details.arg_output_props.output.buffer_duration;
660  if(duration < client->get_max_supported_duration())
661  {
662  param->result = client->set_precapture_duration(duration);
663  }
664  else
665  {
666  ERROR("Duration out of bounds!\n");
667  param->result = ACM_RESULT_DURATION_OUT_OF_BOUNDS;
668  }
669  }
670  else
671  {
672  WARN("Not implemented for this type of output.\n");
673  param->result = ACM_RESULT_UNSUPPORTED_API;
674  }
675  }
676  else
677  {
678  ERROR("Session not found!\n")
679  param->result = ACM_RESULT_BAD_SESSION_ID;
680  }
681  return param->result;
682 }
683 
685 {
686  iarmbus_acm_arg_t *param = static_cast <iarmbus_acm_arg_t *> (arg);
687  INFO("session_id 0x%x\n", param->session_id);
688  acm_session_t * ptr = get_session(param->session_id);
689  if(ptr)
690  {
691  if(BUFFERED_FILE_OUTPUT == ptr->output_type)
692  {
693  music_id_client * client = static_cast <music_id_client *> (ptr->client);
694 
695  if(false == ptr->enable)
696  {
697  ERROR("Audio capture is currently disabled!\n");
698  param->result = ACM_RESULT_DURATION_OUT_OF_BOUNDS;
699  }
700  else
701  {
702  int ret = 0;
703  param->result = ACM_RESULT_SUCCESS;
704  std::string filename = client->get_sock_path();
705 
706  if(param->details.arg_sample_request.is_precapture)
707  {
708  ret = client->grab_precaptured_sample(filename);
709  if(0 == ret)
710  {
711  /* Precapture is immediate. Notify now.*/
712  request_callback(NULL, filename, 0);
713  }
714  }
715  else
716  {
717  unsigned int duration = param->details.arg_sample_request.duration;
718  if(duration <= client->get_max_supported_duration())
719  {
720  ret = client->grab_fresh_sample(duration, filename, &request_callback, NULL);
721  }
722  else
723  {
724  ERROR("Duration out of bounds!\n");
725  param->result = ACM_RESULT_DURATION_OUT_OF_BOUNDS;
726  }
727  }
728  /*Note: tricky condition check. ret is also zero if it's an out-of-bounds error,
729  * but in that case, result is already updated.*/
730  if(0 != ret)
731  {
732  param->result = ACM_RESULT_GENERAL_FAILURE;
733  }
734 
735  }
736  }
737  else
738  {
739  WARN("Not supported with this output type.\n");
740  param->result = ACM_RESULT_UNSUPPORTED_API;
741  }
742  }
743  else
744  {
745  ERROR("Session not found!\n")
746  param->result = ACM_RESULT_BAD_SESSION_ID;
747  }
748  return param->result;
749 }
750 
751 void acm_session_mgr::set_filename_prefix(std::string &prefix)
752 {
753  audio_filename_prefix = prefix;
754 }
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
racFormat_e24Bit5_1
@ racFormat_e24Bit5_1
Definition: rmfAudioCapture.h:75
music_id_client::grab_fresh_sample
request_id_t grab_fresh_sample(unsigned int seconds, const std::string &filename=nullptr, request_complete_callback_t cb=nullptr, void *cb_data=nullptr)
This API requests for new sample.
Definition: music_id.cpp:285
racFreq_e24000
@ racFreq_e24000
Definition: rmfAudioCapture.h:85
music_id_client
Definition: music_id.h:37
IARM_Bus_Term
IARM_Result_t IARM_Bus_Term(void)
This API is used to terminate the IARM-Bus library.
racFreq_e48000
@ racFreq_e48000
Definition: rmfAudioCapture.h:88
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
music_id_client::set_precapture_duration
int set_precapture_duration(unsigned int seconds)
This API is used to set the precapture duration.
Definition: music_id.cpp:100
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
audiocapturemgr::audio_properties_t
Definition: audio_capture_manager.h:56
music_id_client::grab_precaptured_sample
int grab_precaptured_sample(const std::string &filename=nullptr)
This API writes the precaptured sample to a file for file mode and in socket mode,...
Definition: music_id.cpp:185
racFreq_e32000
@ racFreq_e32000
Definition: rmfAudioCapture.h:86
IARM_Bus_RegisterEvent
IARM_Result_t IARM_Bus_RegisterEvent(IARM_EventId_t maxEventId)
This API is used to register all the events that are published by the application.
acmFreqe44100
@ acmFreqe44100
Definition: audiocapturemgr_iarm.h:101
IARM_Bus_RegisterCall
IARM_Result_t IARM_Bus_RegisterCall(const char *methodName, IARM_BusCall_t handler)
This API is used to register an RPC method that can be invoked by other applications.
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
racFormat_e16BitMonoRight
@ racFormat_e16BitMonoRight
Definition: rmfAudioCapture.h:73
IARM_Bus_Disconnect
IARM_Result_t IARM_Bus_Disconnect(void)
This API disconnect Application from IARM Bus so the application will not receive any IARM event or R...
racFormat_e24BitStereo
@ racFormat_e24BitStereo
Definition: rmfAudioCapture.h:69
racFormat_e16BitMono
@ racFormat_e16BitMono
Definition: rmfAudioCapture.h:74
IARM_Bus_BroadcastEvent
IARM_Result_t IARM_Bus_BroadcastEvent(const char *ownerName, IARM_EventId_t eventId, void *data, size_t len)
This API is used to publish an Asynchronous event to all IARM client registered for this perticular e...
libIBus.h
RDK IARM-Bus API Declarations.
acmFreqe32000
@ acmFreqe32000
Definition: audiocapturemgr_iarm.h:100
iarmbus_notification_payload_t
Definition: audiocapturemgr_iarm.h:130
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
acmFreqe16000
@ acmFreqe16000
Definition: audiocapturemgr_iarm.h:98
racFreq_e44100
@ racFreq_e44100
Definition: rmfAudioCapture.h:87
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
acmFreqe24000
@ acmFreqe24000
Definition: audiocapturemgr_iarm.h:99
acm_session_mgr::start_handler
int start_handler(void *arg)
This API starts the client session.
Definition: acm_session_mgr.cpp:333
music_id_client::get_max_supported_duration
unsigned int get_max_supported_duration()
This API returns maximum precaptured length.
Definition: music_id.cpp:490
ip_out_client
Definition: ip_out.h:28
IARM_Bus_Connect
IARM_Result_t IARM_Bus_Connect(void)
This API is used to connect application to the IARM bus daemon. After connected, the application can ...
Definition: iarmMgrMocks.cpp:33
acmFreqe48000
@ acmFreqe48000
Definition: audiocapturemgr_iarm.h:102
iarmbus_acm_arg_t
Definition: audiocapturemgr_iarm.h:152
racFreq_e16000
@ racFreq_e16000
Definition: rmfAudioCapture.h:83
racFormat_e16BitStereo
@ racFormat_e16BitStereo
Definition: rmfAudioCapture.h:68
IARM_Bus_Init
IARM_Result_t IARM_Bus_Init(const char *name)
This API is used to initialize the IARM-Bus library.
Definition: iarmMgrMocks.cpp:38
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
racFormat_e16BitMonoLeft
@ racFormat_e16BitMonoLeft
Definition: rmfAudioCapture.h:72
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