Ejemplo n.º 1
0
/* play previous song */
void prev(pid_t g_pid, link_t head)
{
    link_t prevsong;

    printf("===============================PRIOR MP3=============================\n");
    memcpy(&prevsong, p_addr + sizeof(pid_t) + 1, 4);
    prevsong = prevsong->prev;
    if (prevsong == head)
    {
        prevsong = prevsong->prev;
    }
    kill(g_pid, SIGKILL);
    kill(pid, SIGKILL);
    wait(NULL);
    startplay(&pid, prevsong, head);
}
Ejemplo n.º 2
0
/* play next song */
void next(pid_t g_pid, link_t head)
{
    link_t nextsong;

    printf("===============================NEXT MP3=============================\n");
    memcpy(&nextsong, p_addr + sizeof(pid_t) + 1, 4);
    nextsong = nextsong->next;
    if (nextsong == head)
    {
        nextsong = nextsong->next;
    }
    kill(g_pid, SIGKILL);
    kill(pid, SIGKILL);
    wait(NULL);
    startplay(&pid, nextsong, head);
}
Ejemplo n.º 3
0
void
decproc(void*)
{
	Pmsg playstate, newstate;
	int fd;
	Pacbuf *pb;
	Alt a[3] = {
		{empty, &pb, CHANNOP},
		{playc, &newstate.m, CHANRCV},
		{nil, nil, CHANEND},
	};

	threadsetname("decproc");
	close(srvfd[1]);
	newstate.cmd = playstate.cmd = Stop;
	newstate.off = playstate.off = 0;
	fd = -1;
	for(;;){
		switch(alt(a)){
		case 0:
			/* Play out next buffer (pb points to one already) */
			assert(fd >= 0);	/* Because we must be in Play mode */
			pb->m = playstate.m;
			pb->len = read(fd, pb->data, sizeof pb->data);
			if(pb->len > 0){
				sendp(full, pb);
				break;
			}
			if(pb->len < 0){
				if(debug & DbgPlayer)
					fprint(2, "pac, error: %d\n", playstate.off);
				pb->cmd = Error;
				pb->len = snprint(pb->data, sizeof pb->data, "%s: %r", curfile);
				sendp(full, pb);
			}else{
				/* Simple end of file */
				sendp(empty, pb); /* Don't need buffer after all */
			}
			close(fd);
			fd = -1;
			if(debug & DbgPlayer)
				fprint(2, "pac, eof: %d\n", playstate.off);
			/* End of file, do next by falling through */
			newstate.cmd = playstate.cmd;
			newstate.off = playstate.off + 1;
		case 1:
			if((debug & DbgPac) && newstate.cmd)
				fprint(2, "Pacproc: newstate %s-%d, playstate %s-%d\n",
					statetxt[newstate.cmd], newstate.off,
					statetxt[playstate.cmd], playstate.off);
			/* Deal with an incoming command */
			if(newstate.cmd == Pause || newstate.cmd == Resume){
				/* Just pass them on, don't change local state */
				pb = recvp(spare);
				pb->m = newstate.m;
				sendp(full, pb);
				break;
			}
			/* Stop whatever we're doing */
			if(fd >= 0){
				if(debug & DbgPlayer)
					fprint(2, "pac, stop\n");
				/* Stop any active (pac) decoders */
				close(fd);
				fd = -1;
			}
			a[0].op = CHANNOP;
			switch(newstate.cmd){
			default:
				sysfatal("decproc: unexpected newstate %d", newstate.cmd);
			case Stop:
				/* Wait for state to change */
				break;
			case Skip:
			case Play:
				fd = startplay(newstate.off);
				if(fd >=0){
					playstate = newstate;
					a[0].op = CHANRCV;
					continue;	/* Start reading */
				}
				newstate.cmd = Stop;
			}
			pb = recvp(spare);
			pb->m = newstate.m;
			sendp(full, pb);
			playstate = newstate;
		}
	}
}
Ejemplo n.º 4
0
/* main */
int main(void)
{
    int buttons_fd;
    int key_value;
    link_t head;

    buttons_fd = open("/dev/key", 0);
    if (buttons_fd < 0) 
    {
        perror("open device buttons");
        exit(1);
    }
	
    head = create_song_list(SONG_DIRECTORY);
    if (is_empty_list(head) == 1)
    {
        printf("The song list is empty !\n");
        destroy_list(head);
        exit(1);
    }

    printf("===================================SONG LIST====================================\n");
    traverse_list(print_songname, head);
    printf("================================================================================\n");

	
    printf("===================================FUNTION======================================\n\n");
    printf("        K1:START/PAUSE     K2:STOP   K3:NEXT      K4:PRIOR\n\n");
    printf("================================================================================\n");

    if ((shmid = shmget(IPC_PRIVATE, 5, PERM)) == -1)
    {
        perror("shmget");
        exit(1);
    }
    p_addr = shmat(shmid, 0, 0);
    memset(p_addr, '\0', 1024);
		
    while (1) 
    {
        fd_set rds;
        int ret;

        FD_ZERO(&rds);
        FD_SET(buttons_fd, &rds);

        ret = select(buttons_fd + 1, &rds, NULL, NULL, NULL);
        if (ret < 0) 
        {
            perror("select");
            exit(1);
        }
        if (ret == 0) 
        {
            printf("Timeout.\n");
        }
        else if (FD_ISSET(buttons_fd, &rds))
        {
            ret = read(buttons_fd, &key_value, sizeof key_value);
            if (ret != sizeof key_value) 
            {
                if (errno != EAGAIN)
                    perror("read buttons\n");
                    continue;
            } 
            else
            {
                printf("buttons_value: %d\n", key_value + 1);
				
                if (first_key == 1)
                {
                    switch(key_value)
                    {	
                        case 0:
                            startplay(&pid, head->next, head);
                            first_key = 0;
                            break;

                        case 1:
                        case 2:
                        case 3:
                            printf("=======================PRESS K1 TO START PLAY===================\n");
                            break;

                        default:
                            printf("=======================PRESS K1 TO START PLAY===================\n");
                            break;

                    } //end switch
                }//end if(first_key)
                else if(first_key == 0)
                {
                    memcpy(&gradchild, p_addr, sizeof(pid_t));
                    switch(key_value)
                    {
                        case 0:
                            //printf("play_flag:%d\n",play_flag);
                            if(play_flag == 1)
                                {
                                my_pause(gradchild);
                                }
                            else
                                {
                                conti_play(gradchild);
                                }
                            break;

                        case 1:
                            my_stop(gradchild);
                            first_key = 1;
                            break;

                        case 2:
                            next(gradchild, head);
                            break;

                        case 3:
                            prev(gradchild, head);
                            break;

                        default:
                                break;

                    } //end switch
                }//end if(!first_key)
            }				
        }
    }

    destroy_list(head);
    close(buttons_fd);

    return 0;
}