Hi everybody,

I'm currently working on a media player based on emotion and I noticed a
problem that happens randomly. If I'm playing a media and if I want to
play the next one, emotion is sometimes blocked on the instruction
"while (ev->get_poslen);" (l:403 from emotion_xine.c). So it can't close
the current media and freezes the application.
It seems to be related to get_pos_len thread that is not correcty
deleted sometimes.
I have done some fixes to emotion_xine.c that seems to solve the problem
but I'm not sure it's the best way to do that (I don't know very well
pthread).
So here is the patch.

The same fix certainly must be done for the seek thread but I never meet
the problem with this thread (certainly because I less often call the
seek function than the get_pos function).

MoOm

--- emotion_xine.c.orig	2005-04-02 11:45:20.129665184 +0200
+++ emotion_xine.c	2005-04-02 11:44:55.939342672 +0200
@@ -304,6 +304,7 @@
    v = xine_get_stream_info(ev->stream, XINE_STREAM_INFO_VIDEO_RATIO);
    ev->ratio = (double)v / 10000.0;
    ev->just_loaded = 1;
+   ev->get_poslen = 0;
    
      {
 	pthread_attr_t thattr;
@@ -320,6 +321,8 @@
 	pthread_attr_init(&thattr);
 	pthread_create(&ev->get_pos_len_th, NULL, _em_get_pos_len_th, ev);
 	pthread_attr_destroy(&thattr);
+
+   ev->get_pos_thread_deleted = 0;
      }
 //   em_debug(ev);
    return ev;
@@ -334,10 +337,15 @@
    ev->delete_me = 1;
 //   pthread_mutex_lock(&(ev->seek_mutex));
    pthread_cond_broadcast(&(ev->seek_cond));
-//   pthread_mutex_lock(&(ev->get_pos_len_mutex));
-   pthread_cond_broadcast(&(ev->get_pos_len_cond));
    while (ev->seek_to);
-   while (ev->get_poslen);
+
+//   pthread_mutex_lock(&(ev->get_pos_len_mutex));
+   if (!ev->get_pos_thread_deleted)
+   {
+      pthread_cond_broadcast(&(ev->get_pos_len_cond));
+      while (ev->get_poslen);
+   }
+
    printf("EX pause end...\n");
    if (!emotion_object_play_get(ev->obj))
 //   if (xine_get_param(ev->stream, XINE_PARAM_SPEED) == XINE_SPEED_PAUSE)
@@ -1269,7 +1277,7 @@
    for (;;)
      {
 	pthread_cond_wait(&(ev->get_pos_len_cond), &(ev->get_pos_len_mutex));
-	while (ev->get_poslen > 0)
+	while (ev->get_poslen > 0 || ev->delete_me)
 	  {
 	     int pos_stream = 0;
 	     int pos_time = 0;
@@ -1296,6 +1304,7 @@
 	     if (ev->delete_me)
 	       {
 		  ev->get_poslen = 0;
+        ev->get_pos_thread_deleted = 1;
 		  return NULL;
 	       }
 	     ev->get_poslen = 0;
--- emotion_xine.h.orig	2005-04-02 11:45:38.580860176 +0200
+++ emotion_xine.h	2005-04-02 11:41:11.669436880 +0200
@@ -49,6 +49,7 @@
    pthread_cond_t            get_pos_len_cond;
    pthread_mutex_t           seek_mutex;
    pthread_mutex_t           get_pos_len_mutex;
+   unsigned char             get_pos_thread_deleted : 1;
 };
 
 struct _Emotion_Xine_Video_Frame

Reply via email to