audio.c
Go to the documentation of this file.
00001 /*
00002  * File: audio.c
00003  * Desc: Test program for use of audio through an opaque interface to player
00004  * Author: Pooya Karimian
00005  * License: GPL v2
00006  * CVS info:
00007  *  $Source: /home/tcollett/stagecvs/playerstage-cvs/code/stage/examples/libplayerc/audio.c,v $
00008  *  $Author: pooya $
00009  *  $Revision: 1.1 $
00010  */
00011 
00012 #include <stdio.h>
00013 #include <string.h>
00014 #include <libplayerc/playerc.h>
00015 
00016 int main(int argc, const char **argv)
00017 {
00018   const char *host;
00019   int port;
00020   playerc_client_t *client;
00021 
00022   host = "localhost";
00023   port = 6665;
00024   
00025   printf( "Attempting to connect to a Player server on %s:%d\n",
00026               host, port );
00027 
00028   // Create a client and connect it to the server.
00029   client = playerc_client_create(NULL, host, port);
00030   if (playerc_client_connect(client) != 0)
00031     {
00032       puts( "Failed. Quitting." );
00033       return -1;
00034     }
00035   
00036   puts( "Connected. Running tests." );
00037 
00038   // Create and subscribe to an audio device.
00039   playerc_opaque_t *audio = playerc_opaque_create(client, 0);
00040   if (playerc_opaque_subscribe(audio, PLAYER_OPEN_MODE))
00041     return -1;
00042 
00043   int i;
00044   for( i = 0; i < 1000; i++)
00045     {
00046       // Wait/Read for new data from server, or continue after 100ms
00047       if (playerc_client_peek(client, 100) > 0) 
00048         playerc_client_read(client);
00049 
00050       // If there's new data
00051       if (audio->data_count>0) 
00052       {
00053         // print it
00054         printf("%s\n", audio->data);
00055 
00056         // clear read data
00057         audio->data_count=0;
00058       }
00059 
00060       // send a message approximately every two seconds
00061       if ( i % 20 == 0 ) 
00062       {   
00063         // clear a new data packet
00064         player_opaque_data_t audio_msg;
00065         char *temp_str="Hello World!";
00066         sprintf((char *) audio_msg.data, "%s", temp_str);
00067         audio_msg.data_count=strlen(temp_str)+1;
00068       
00069         playerc_opaque_cmd(audio, &audio_msg);
00070       }
00071       
00072     } 
00073   
00074   playerc_opaque_unsubscribe(audio);
00075   playerc_opaque_destroy(audio);
00076 
00077   return 0;
00078 
00079 
00080   puts( "Disconnecting" );
00081   // Shutdown
00082   playerc_client_disconnect(client);
00083   playerc_client_destroy(client);
00084 
00085   puts( "Done." );
00086   return 0;
00087 }


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 Thu Aug 27 2015 15:20:57