From cdf0ec6b79f8cb8ba8341fa4532919c917f70fb4 Mon Sep 17 00:00:00 2001
From: SeeLook <945374+SeeLook@users.noreply.github.com>
Date: Fri, 20 Nov 2015 22:53:28 +0100
Subject: [PATCH] Android: Fixed hang on, when app was exiting and audio input
 was active

---
 src/libs/sound/tqtaudioin.cpp | 21 +++++++++++----------
 1 file changed, 11 insertions(+), 10 deletions(-)

diff --git a/src/libs/sound/tqtaudioin.cpp b/src/libs/sound/tqtaudioin.cpp
index a259f414b..50eb48cd2 100644
--- a/src/libs/sound/tqtaudioin.cpp
+++ b/src/libs/sound/tqtaudioin.cpp
@@ -55,7 +55,7 @@ TaudioIN::TaudioIN(TaudioParams* params, QObject *parent) :
   m_instance = this;
   finder()->setCopyInThread(false);
   finder()->setNrChunksToReset(500); // Less memory usage
-  
+
   createInputDevice();
 
   moveToThread(m_thread);
@@ -68,13 +68,14 @@ TaudioIN::~TaudioIN() {
   stopListening();
   m_audioIN->stop();
   finder()->blockSignals(true);
-  if (m_thread->isRunning()) {
-      m_thread->wait(10);
+  if (m_thread->isRunning()) { // In fact, it never goes here
+      qDebug() << "Terminating audio input thread";
       m_thread->terminate();
       m_thread->quit();
+      stopThread();
   }
   m_audioParams->INdevName = m_deviceName; // store device name at the app exit
-  m_thread->deleteLater();
+  delete m_thread;
   m_instance = 0;
 }
 
@@ -153,14 +154,14 @@ void TaudioIN::startThread() {
 
 
 void TaudioIN::stopThread() {
-//   if (detectingState() != e_stopped) {
-    m_audioIN->stop();
+  m_audioIN->stop();
+  if (m_buffer) {
     delete m_buffer;
     m_buffer = 0;
-    resetVolume();
-    resetChunkPitch();
-    finder()->resetFinder();
-//   }
+  }
+  resetVolume();
+  resetChunkPitch();
+  finder()->resetFinder();
 }
 
 
-- 
GitLab