psebcopathe | Je m'explique mieux , MOn application lance un programme (mplayer pour lire les fichiers audios) avec fork et communique avec ceui ci par des pipes , le pb , c'est quand je récupère les données de e programmes, des fois , il en zappe certaines .
Hors je veux abolument les récupérér car ca me permet de détecter au niveua de mon appli quand il ya eu un changement de chanson .
voila le code , svp aidez moi .
Code :
- #include "mplayer_backend.h"
- #include "select_unselect_utility.h"
- //variables globales ,oulala tout ca :-) !
- static int pipe_in[2], pipe_out[2];
- pid_t mplayer_pid; //processus enfant
- static pthread_mutex_t mplayer_mutex;
- int firsttime=1;
- char *song_ref="none";
- void write_mplayer_cmd (char *buff)
- {
- write(pipe_in[1],buff,strlen(buff));
- write(pipe_in[1],"\n",1);
- }
- int mplayer_get_media_change(void)
- {
- char buff[1024];
- char *data="none";
- while(1){
- fcntl(pipe_out[0],F_SETFL,O_NONBLOCK);
- pthread_mutex_lock (&mplayer_mutex);
- read(pipe_out[0],buff,sizeof(buff));
-
- if (sscanf(buff,"%a[^\f\r]\n",&data)==1){
- // fprintf(stdout,"data: %s\n",data);
- if(strstr(data,"Starting playback" )!=NULL){
- //je recupere cette ligne pour savoir qu'une chanson est jouée
- if(!firsttime) {
- next_playlist_element();
- }
- firsttime=0;
-
- }
- }
- pthread_mutex_unlock (&mplayer_mutex);
- *buff='\n';
- usleep(100000);
- }
- return 0;
- }
- void mplayer_stop ()
- {
- pthread_mutex_lock (&mplayer_mutex);
- write_mplayer_cmd ("seek 0 1\npause" );
- pthread_mutex_unlock (&mplayer_mutex);
- }
- void mplayer_pause ()
- {
- pthread_mutex_lock (&mplayer_mutex);
- write_mplayer_cmd ("p" );
- pthread_mutex_unlock (&mplayer_mutex);
- }
- void mplayer_foreward ()
- {
- pthread_mutex_lock (&mplayer_mutex);
- write_mplayer_cmd ("seek 10" );
- pthread_mutex_unlock (&mplayer_mutex);
- }
- void mplayer_backward()
- {
- pthread_mutex_lock (&mplayer_mutex);
- write_mplayer_cmd ("seek -10" );
- pthread_mutex_unlock (&mplayer_mutex);
- }
- void mplayer_pl_next ()
- {
- pthread_mutex_lock (&mplayer_mutex);
- write_mplayer_cmd ("pt_step 1" );
- pthread_mutex_unlock (&mplayer_mutex);
- }
- void mplayer_pl_previous ()
- {
- pthread_mutex_lock (&mplayer_mutex);
- write_mplayer_cmd ("pt_step -1" );
- pthread_mutex_unlock (&mplayer_mutex);
- }
- void mplayer_play (char* pathname)
- {
- char cmd[64+PATH_MAXI*2];
- char *MPlayerCmd = " mplayer -ao oss -slave -playlist" ;
- if (pipe (pipe_in) < 0) {
- fprintf (stdout,"pipe_in: %s", cmd);
- exit (1);
- }
- if (pipe (pipe_out) < 0) {
- fprintf (stdout,"pipe_out: %s",cmd);
- exit (1);
- }
- if ((mplayer_pid = fork ())==0) //créer un nouveau processus enfant , test = 0 pour savoir si enfant démarré
- {
- close(pipe_in[1]);
- close(pipe_out[0]);
- dup2(pipe_in[0],STDIN_FILENO);
- dup2(pipe_out[1],STDOUT_FILENO);
- dup2(pipe_out[1],STDERR_FILENO);
- close(pipe_in[0]);
- close(pipe_out[1]);
- fcntl(pipe_out[0],F_SETFL,O_NONBLOCK);
-
- snprintf(cmd,sizeof(cmd),"%s \"%s\" ",MPlayerCmd,pathname);
- launch_player(cmd); -
- pthread_mutex_init (&mplayer_mutex, NULL);
- pthread_mutex_init (&track_mutex, NULL);
- }
- }
- void mplayer_quit ()
- {
- pthread_mutex_lock (&mplayer_mutex);
- write_mplayer_cmd ("q" );
- pthread_mutex_unlock (&mplayer_mutex);
- }
|
Message édité par psebcopathe le 02-04-2003 à 17:20:27
|