Пример #1
0
int raopcl_small_silent(raopcl_t *p)
{
	raopcl_data_t *raopcld=(raopcl_data_t *)p;
	raopcl_send_sample(p,raopcld->min_sdata,raopcld->min_sdata_size);
	//DBGMSG("sent a small silent data\n");
	return 0;
}
Пример #2
0
int main(int argc, char *argv[])
{
	char *host=NULL;
	char *fname=NULL;
	int port=SERVER_PORT;
	int rval=-1,i;
	int size;
	int volume=100;
	__u8 *buf;
	int iact=0;
	struct sigaction act;

	/* Assign sig_term as our SIGTERM handler */
	act.sa_sigaction = sig_action;
	sigemptyset(&act.sa_mask); // no other signals are blocked
	act.sa_flags = SA_SIGINFO; // use sa_sigaction instead of sa_handler
	sigaction(SIGTERM, &act, NULL);
	sigaction(SIGINT, &act, NULL);
	sigaction(SIGCHLD, &act, NULL);

	for(i=1;i<argc;i++){
		if(!strcmp(argv[i],"-i")){
			iact=1;
			continue;
		}
		if(!strcmp(argv[i],"--port")){
			port=atoi(argv[++i]);
			continue;
		}
		if(!strcmp(argv[i],"--vol")){
			volume=atoi(argv[++i]);
			continue;
		}
		if(!strcmp(argv[i],"--help") || !strcmp(argv[i],"-h"))
			return print_usage(argv);
		if(!host) {host=argv[i]; continue;}
		if(!fname) {fname=argv[i]; continue;}
	}
	if(!host) return print_usage(argv);
	if(!iact && !fname) return print_usage(argv);

	raopld=(raopld_t*)malloc(sizeof(raopld_t));
	if(!raopld) goto erexit;
	memset(raopld,0,sizeof(raopld_t));
	for(i=0;i<MAX_NUM_OF_FDS;i++) raopld->fds[i].fd=-1;

	raopld->raopcl=raopcl_open();
	if(!raopld->raopcl) goto erexit;
	if(raopcl_connect(raopld->raopcl,host,port)) goto erexit;
	if(raopcl_update_volume(raopld->raopcl,volume)) goto erexit;
	printf("%s\n",RAOP_CONNECTED);
	fflush(stdout);
	if(fname && !(raopld->auds=auds_open(fname,0))) goto erexit;
	set_fd_event(0,RAOP_FD_READ,console_read,NULL);
	rval=0;
	while(!rval){
		if(!raopld->auds){
			// if audio data is not opened, just check events
			rval=main_event_handler(raopld);
			continue;
		}
		switch(raopcl_get_pause(raopld->raopcl)){
		case OP_PAUSE:
			rval=main_event_handler();
			continue;
		case NODATA_PAUSE:
			if(auds_poll_next_sample(raopld->auds)){
				raopcl_set_pause(raopld->raopcl,NO_PAUSE);
			}else{
				rval=main_event_handler();
				continue;
			}
		case NO_PAUSE:
			if(!auds_poll_next_sample(raopld->auds)){
				// no next data, turn into pause status
				raopcl_set_pause(raopld->raopcl,NODATA_PAUSE);
				continue;
			}
			if(auds_get_next_sample(raopld->auds, &buf, &size)){
				auds_close(raopld->auds);
				raopld->auds=NULL;
				raopcl_wait_songdone(raopld->raopcl,1);
			}
			if(raopcl_send_sample(raopld->raopcl,buf,size)) break;
			do{
				if((rval=main_event_handler())) break;
			}while(raopld->auds && raopcl_sample_remsize(raopld->raopcl));
			break;
		default:
			rval=-1;
			break;
		}
	}
	rval=raopcl_close(raopld->raopcl);
 erexit:	
	if(raopld->auds) auds_close(raopld->auds);
	if(raopld) free(raopld);
	return rval;
}