RDK Documentation (Open Sourced RDK Components)
rmfAudioCaptureTestApp.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 <unistd.h>
20 #include <string.h>
21 #include "audio_capture_manager.h"
22 #include "music_id.h"
23 #include <sstream>
24 
25 void print_menu(void)
26 {
27  std::cout<<"\n--- audio capture test application menu ---\n";
28  std::cout<<"1. q_mgr start (non-essential step)\n";
29  std::cout<<"2. q_mgr stop (non-essential step)\n";
30  std::cout<<"3. dump precaptured sample\n";
31  std::cout<<"4. set precapture length\n";
32  std::cout<<"5. capture next N seconds\n";
33  std::cout<<"6. Start client\n";
34  std::cout<<"7. Stop client\n";
35  std::cout<<"9. Quit.\n";
36 }
37 
38 static std::string callback_payload = "Uninitialized";
39 static unsigned int ticker = 0;
40 static std::string get_suffix()
41 {
42  std::ostringstream stream;
43  stream << ticker++;
44  stream << ".wav";
45  std::string outstring = stream.str();
46  return outstring;
47 }
48 
49 void launcher()
50 {
51  bool keep_running = true;
52  q_mgr manager;
53  music_id_client client(&manager, music_id_client::FILE_OUTPUT);
54  client.enable_wav_header(true);
55 
56  while(keep_running)
57  {
58  int choice = 0;
59  std::string filename;
60  int duration = 0;
61  print_menu();
62  std::cout<<"Enter command:\n";
63  if(!(std::cin >> choice))
64  {
65  std::cout<<"Oops!\n";
66  std::cin.clear();
67  std::cin.ignore(10000, '\n');
68  continue;
69  }
70  switch(choice)
71  {
72  case 1:
73  manager.start();
74  break;
75  case 2:
76  manager.stop();
77  break;
78  case 3:
79  filename = "/tmp/precap-"+ get_suffix();
80  client.grab_precaptured_sample(filename);
81  std::cout<<"Output file "<<filename<<std::endl;
82  break;
83  case 4:
84  {
85  std::cout<<"Enter precapture duration in seconds:\n";
86  if(!(std::cin>>duration))
87  {
88  std::cout<<"Whoops! Bad input.\n";
89  std::cin.clear();
90  std::cin.ignore(10000, '\n');
91  }
92  else
93  {
94  client.set_precapture_duration(duration);
95  }
96  break;
97  }
98  case 5:
99  {
100  std::cout<<"Enter capture duration in seconds:\n";
101  if(!(std::cin>>duration))
102  {
103  std::cout<<"Whoops! Bad input.\n";
104  std::cin.clear();
105  std::cin.ignore(10000, '\n');
106  }
107  else
108  {
109  filename = "/tmp/freshcap-"+ get_suffix();
110  client.grab_fresh_sample(duration, filename);
111  std::cout<<"Output file "<<filename<<std::endl;
112  }
113  break;
114  }
115  case 6:
116  {
117  client.start();
118  break;
119  }
120  case 7:
121  {
122  client.stop();
123  break;
124  }
125  case 9:
126  {
127  keep_running = false;
128  std::cout<<"Quitting.\n";
129  break;
130  }
131  default:
132  std::cout<<"Unknown input!\n";
133  }
134  }
135 }
136 
137 
138 int main(int argc, char *argv[])
139 {
140  launcher();
141  return 0;
142 }
music_id_client
Definition: music_id.h:37
q_mgr::start
int start()
This function will start the Audio capture.
Definition: audio_capture_manager.cpp:482
q_mgr::stop
int stop()
This function will stop the audio capture.
Definition: audio_capture_manager.cpp:515
q_mgr
Definition: audio_capture_manager.h:70
print_menu
void print_menu()
This API prints the LED use-cases.
Definition: ledmgrmain.cpp:383