[MPlayer-users] Reading MPlayer in slave mode with C using libevent

Steve Ricketts velocedge at hotmail.com
Sun Apr 17 19:21:45 CEST 2011


I'm trying to modify an existing c program to get the 
position of a video while mplayer is playing the video
 in slave mode.  The program does many other things
while the video is playing, including logging a significant
amount of information to stdout.  

So, I thought I'd use a libevent (already in the program) 
callback to tell me when mplayer has responded to a 
command (like get_time_pos).  I added a close callback,
which is working, but I don't get the read callback to fire.
I see the response to get_time_pos in stdout.  

So, how can I make this work?.. and if there is a better way
to do the same thing, that would be good to hear too.



static FILE *videoPipe;
static connection_t *video;

static int video_read_cb (connection_t *con, uint8_t *data, size_t length)
{
      DEBUG ("video_read_cb %3d input length:%d in: %s", length, HEXSTR(data,
length));
      return 0;
}      

static int video_close_cb (connection_t *con)
{
      DEBUG (LOGD"video_close_callback %s", con->name);  // this is being called
properly
      event_free (con);
      return 0;
}
...
strcpy(str, "mplayer -slave -quiet -geometry 1:1 -keepaspect");
videoPipe = popen(str, "w");

fd = fileno(videoPipe);
video = connection_new (fd, videoType);
video->read_cb = video_read_cb;
video->close_cb = video_close_cb;
event_register (video); 

connection_t *connection_new (int fd, char *name)
{
      connection_t *con = NULL;
      con = calloc (1, sizeof(connection_t));
      con->fd = fd;
      con->name = strdup (name);
      con->close_after_write = 0;
      return con;
}

void event_register (connection_t *con)
{
con->bufev = bufferevent_new (con->fd, bev_read_cb, bev_write_cb, bev_error_cb,
con);
if(con->idle_timeout > 0)
      bufferevent_settimeout(con->bufev, con->idle_timeout, con->idle_timeout);
bufferevent_enable (con->bufev, EV_READ);
bufferevent_base_set (base, con->bufev);
}



More information about the MPlayer-users mailing list