diff --git a/libeplayer3/container/container_ffmpeg.c b/libeplayer3/container/container_ffmpeg.c index 00ecde8..8747074 100644 --- a/libeplayer3/container/container_ffmpeg.c +++ b/libeplayer3/container/container_ffmpeg.c @@ -131,15 +131,29 @@ static int container_ffmpeg_seek_rel(Context_t *context, off_t pos, long long in /* MISC Functions */ /* ***************************** */ -void getMutex(const char *filename __attribute__((unused)), const char *function __attribute__((unused)), int line) { +static int mutexInitialized = 0; + +static void initMutex(void) +{ + pthread_mutexattr_t attr; + pthread_mutexattr_init(&attr); + pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_ERRORCHECK_NP); + pthread_mutex_init(&mutex, &attr); + mutexInitialized = 1; +} + +static void getMutex(const char *filename __attribute__((unused)), const char *function __attribute__((unused)), int line) { ffmpeg_printf(100, "::%d requesting mutex\n", line); + if (!mutexInitialized) + initMutex(); + pthread_mutex_lock(&mutex); ffmpeg_printf(100, "::%d received mutex\n", line); } -void releaseMutex(const char *filename __attribute__((unused)), const const char *function __attribute__((unused)), int line) { +static void releaseMutex(const char *filename __attribute__((unused)), const const char *function __attribute__((unused)), int line) { pthread_mutex_unlock(&mutex); ffmpeg_printf(100, "::%d released mutex\n", line); @@ -400,9 +414,10 @@ static void FFMPEGThread(Context_t *context) { bofcount = 1; } } - } + getMutex(FILENAME, __FUNCTION__,__LINE__); + if (do_seek_target_seconds || do_seek_target_bytes) { if (do_seek_target_seconds) { float seek_target_seconds_min = seek_target_seconds - 15 * AV_TIME_BASE; @@ -422,8 +437,6 @@ static void FFMPEGThread(Context_t *context) { context->output->Command(context, OUTPUT_AUDIOMUTE, "0"); } - getMutex(FILENAME, __FUNCTION__,__LINE__); - if (av_read_frame(avContext, &packet) == 0 ) { long long int pts; diff --git a/libeplayer3/output/linuxdvb.c b/libeplayer3/output/linuxdvb.c index 4eda7ec..b7be970 100644 --- a/libeplayer3/output/linuxdvb.c +++ b/libeplayer3/output/linuxdvb.c @@ -712,10 +712,12 @@ int LinuxDvbPts(Context_t *context __attribute__((unused)), unsigned long long else linuxdvb_err("VIDEO_GET_PTS: %d (%s)\n", errno, strerror(errno)); - if (audiofd > -1 && ret != cERR_LINUXDVB_NO_ERROR && !ioctl(audiofd, AUDIO_GET_PTS, (void*)&sCURRENT_PTS)) - ret = cERR_LINUXDVB_NO_ERROR; - else - linuxdvb_err("AUDIO_GET_PTS: %d (%s)\n", errno, strerror(errno)); + if (ret != cERR_LINUXDVB_NO_ERROR) { + if (audiofd > -1 && !ioctl(audiofd, AUDIO_GET_PTS, (void*)&sCURRENT_PTS)) + ret = cERR_LINUXDVB_NO_ERROR; + else + linuxdvb_err("AUDIO_GET_PTS: %d (%s)\n", errno, strerror(errno)); + } if (ret != cERR_LINUXDVB_NO_ERROR) sCURRENT_PTS = 0;