From dc2a013b9bf296d1554b86763d052442ff591f90 Mon Sep 17 00:00:00 2001 From: "Christopher R. Palmer" Date: Mon, 31 Aug 2015 08:07:19 -0400 Subject: [PATCH] ffmpeg-extractor: Fix deadlock when stopping the reader thread You cannot hold the lock used by the reader thread when trying to join to the reader thread! For example, if we start and then stop the reader thread before it gets a chance to execute, one thread will be in stopReaderThread calling pthread_thread_join (and holding mLock). Then the reader thread will execute and immediately block on mLock (it gets the lock immediately on startup). Instead, release the lock while we wait for the thread to exit and then reacquire the lock. Change-Id: I9247ae48586c18f4eb7a4f74e188b9d4f88824e2 --- extractor/FFmpegExtractor.cpp | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/extractor/FFmpegExtractor.cpp b/extractor/FFmpegExtractor.cpp index df9044a..0b39032 100644 --- a/extractor/FFmpegExtractor.cpp +++ b/extractor/FFmpegExtractor.cpp @@ -144,10 +144,10 @@ FFmpegExtractor::FFmpegExtractor(const sp &source, const sp= 0) stream_component_close(mVideoStreamIdx); + mLock.unlock(); pthread_join(mReaderThread, NULL); + mLock.lock(); if (mFormatCtx) { avformat_close_input(&mFormatCtx); @@ -1050,6 +1055,8 @@ void FFmpegExtractor::stopReaderThread() { mReaderThreadStarted = false; ALOGD("Reader thread stopped"); + + mLock.unlock(); } // static -- 2.11.0