audio.c
Go to the documentation of this file.
1 /*
2  * File: audio.c
3  * Desc: Test program for use of audio through an opaque interface to player
4  * Author: Pooya Karimian
5  * License: GPL v2
6  * CVS info:
7  * $Source: /home/tcollett/stagecvs/playerstage-cvs/code/stage/examples/libplayerc/audio.c,v $
8  * $Author: pooya $
9  * $Revision: 1.1 $
10  */
11 
12 #include <stdio.h>
13 #include <string.h>
14 #include <libplayerc/playerc.h>
15 
16 int main(int argc, const char **argv)
17 {
18  const char *host;
19  int port;
20  playerc_client_t *client;
21 
22  host = "localhost";
23  port = 6665;
24 
25  printf( "Attempting to connect to a Player server on %s:%d\n",
26  host, port );
27 
28  // Create a client and connect it to the server.
29  client = playerc_client_create(NULL, host, port);
30  if (playerc_client_connect(client) != 0)
31  {
32  puts( "Failed. Quitting." );
33  return -1;
34  }
35 
36  puts( "Connected. Running tests." );
37 
38  // Create and subscribe to an audio device.
39  playerc_opaque_t *audio = playerc_opaque_create(client, 0);
40  if (playerc_opaque_subscribe(audio, PLAYER_OPEN_MODE))
41  return -1;
42 
43  int i;
44  for( i = 0; i < 1000; i++)
45  {
46  // Wait/Read for new data from server, or continue after 100ms
47  if (playerc_client_peek(client, 100) > 0)
48  playerc_client_read(client);
49 
50  // If there's new data
51  if (audio->data_count>0)
52  {
53  // print it
54  printf("%s\n", audio->data);
55 
56  // clear read data
57  audio->data_count=0;
58  }
59 
60  // send a message approximately every two seconds
61  if ( i % 20 == 0 )
62  {
63  // clear a new data packet
64  player_opaque_data_t audio_msg;
65  char *temp_str="Hello World!";
66  sprintf((char *) audio_msg.data, "%s", temp_str);
67  audio_msg.data_count=strlen(temp_str)+1;
68 
69  playerc_opaque_cmd(audio, &audio_msg);
70  }
71 
72  }
73 
74  playerc_opaque_unsubscribe(audio);
75  playerc_opaque_destroy(audio);
76 
77  return 0;
78 
79 
80  puts( "Disconnecting" );
81  // Shutdown
82  playerc_client_disconnect(client);
83  playerc_client_destroy(client);
84 
85  puts( "Done." );
86  return 0;
87 }
static int argc
static char * argv
int main(int argc, const char **argv)
Definition: audio.c:16


stage
Author(s): Richard Vaughan , Brian Gerkey , Reed Hedges , Andrew Howard , Toby Collett , Pooya Karimian , Jeremy Asher , Alex Couture-Beil , Geoff Biggs , Rich Mattes , Abbas Sadat
autogenerated on Mon Jun 10 2019 15:06:09