diff -c esound-0.2.22/esdlib.c esound-0.2.22.add_kill/esdlib.c *** esound-0.2.22/esdlib.c Wed Nov 29 04:27:30 2000 --- esound-0.2.22.add_kill/esdlib.c Tue Jan 23 01:31:16 2001 *************** *** 1412,1417 **** --- 1412,1459 ---- } /*******************************************************************/ + /* kill a looping sample in the server */ + int esd_sample_kill( int esd, int sample ) + { + int is_ok; + int proto = ESD_PROTO_SAMPLE_KILL; + void (*phandler)(int); + + /* printf( "stopping sample (%d) - <%d>\n", esd, sample ); */ + + /* this is unavoidable - incase ESD "disappears" (ie the socket conn dies) */ + /* we need to catch SIGPIPE to avoid the default handler form giving us */ + /* a bad day - ignore the SIGPIPE, then make sure to catch all errors */ + phandler = signal( SIGPIPE, dummy_signal ); /* for closed esd conns */ + /* send the necessary information */ + if ( write( esd, &proto, sizeof(proto) ) != sizeof(proto) ) { + signal( SIGPIPE, phandler ); + return -1; + } + if ( write( esd, &sample, sizeof(sample) ) != sizeof(sample) ) { + signal( SIGPIPE, phandler ); + return -1; + } + /* fsync( esd ); */ + + /* get the sample id back from the server */ + if ( read( esd, &is_ok, sizeof(is_ok) ) != sizeof(is_ok) ) { + signal( SIGPIPE, phandler ); + return -1; + } + + /* diagnostic info */ + /* + if ( getenv( "ESDBG" ) ) + printf( "esound stopping sample\n" ); + */ + + /* return the id to the client (0 = error, 1 = ok) */ + signal( SIGPIPE, phandler ); + return is_ok; + } + + /*******************************************************************/ /* closes fd, previously obtained by esd_open */ int esd_close( int esd ) { diff -c esound-0.2.22/esound.spec esound-0.2.22.add_kill/esound.spec *** esound-0.2.22/esound.spec Fri Dec 1 03:45:20 2000 --- esound-0.2.22.add_kill/esound.spec Mon Dec 11 23:08:47 2000 *************** *** 63,69 **** %files %defattr(-, root, root) ! %doc AUTHORS COPYING ChangeLog docs/esound.sgml docs/html docs/esound.ps %doc INSTALL NEWS README TIPS TODO %config /etc/* %{_prefix}/bin/esd --- 63,69 ---- %files %defattr(-, root, root) ! %doc AUTHORS COPYING ChangeLog docs/esound.sgml %doc INSTALL NEWS README TIPS TODO %config /etc/* %{_prefix}/bin/esd diff -c esound-0.2.22/proto.c esound-0.2.22.add_kill/proto.c *** esound-0.2.22/proto.c Wed Nov 29 04:27:30 2000 --- esound-0.2.22.add_kill/proto.c Tue Jan 23 01:31:40 2001 *************** *** 28,33 **** --- 28,34 ---- int esd_proto_sample_play( esd_client_t *client ); int esd_proto_sample_loop( esd_client_t *client ); int esd_proto_sample_stop( esd_client_t *client ); + int esd_proto_sample_kill( esd_client_t *client ); int esd_proto_server_info( esd_client_t *client ); int esd_proto_all_info( esd_client_t *client ); int esd_proto_stream_pan( esd_client_t *client ); *************** *** 63,69 **** --- 64,74 ---- { sizeof(int), &esd_proto_sample_play, "sample play" }, { sizeof(int), &esd_proto_sample_loop, "sample loop" }, { sizeof(int), &esd_proto_sample_stop, "sample stop" }, + #if 0 { -1, &esd_proto_unimplemented, "TODO: sample kill" }, + #else + { sizeof(int), &esd_proto_sample_kill, "sample kill" }, + #endif { ESD_KEY_LEN + sizeof(int), &esd_proto_standby, "standby" }, { ESD_KEY_LEN + sizeof(int), &esd_proto_resume, "resume" }, *************** *** 583,588 **** --- 588,616 ---- ESD_WRITE_INT( client->fd, &client_id, sizeof(client_id), actual, "smp stop" ); + if ( sizeof( client_id ) != actual ) + return 0; + + return 1; + } + + /*******************************************************************/ + /* play a sample cached by the client, return boolean ok */ + int esd_proto_sample_kill( esd_client_t *client ) + { + int sample_id, client_id, actual; + + client_id = *(int*)(client->proto_data); + sample_id = maybe_swap_32( client->swap_byte_order, client_id ); + + ESDBG_TRACE( printf( "(%02d) proto: killing sample <%d>\n", + client->fd, sample_id ); ); + + if ( !kill_sample( sample_id ) ) + sample_id = 0; + + ESD_WRITE_INT( client->fd, &client_id, sizeof(client_id), + actual, "smp kill" ); if ( sizeof( client_id ) != actual ) return 0; diff -c esound-0.2.22/samples.c esound-0.2.22.add_kill/samples.c *** esound-0.2.22/samples.c Fri Nov 5 07:44:15 1999 --- esound-0.2.22.add_kill/samples.c Tue Jan 23 01:31:17 2001 *************** *** 291,293 **** --- 291,327 ---- return 0; } + /*******************************************************************/ + /* kill a sample from the sample list */ + int kill_sample( int id ) + { + int is_ok = 0; + esd_player_t *player = esd_players_list; + + ESDBG_TRACE( printf( "{ss} stopping sample <%02d>\n", id ); ); + + /* iterate until we hit a NULL */ + while ( player != NULL ) + { + /* printf( "checking player [0x%p], format = 0x%08x, id = %d\n", + player, player->format, player->source_id ); */ + + /* see if we hit the target sample, and it's really a sample */ + if ( ( ( (player->format) & ESD_MASK_MODE ) == ESD_SAMPLE ) + && ( player->source_id == id ) ) { + + erase_player( player); + is_ok = 1; + } + + /* iterate through the list */ + player = player->next; + } + + if( !is_ok) + { + /* hmm, we didn't find the desired sample, just get on with life */ + printf( "{ss} player for sample <%02d> not found\n", id ); + } + return is_ok; + }