summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPraveen Chavan <pchavan@codeaurora.org>2015-12-17 11:42:40 -0800
committerPraveen Chavan <pchavan@codeaurora.org>2015-12-19 06:08:18 -0800
commit3ac841034ae0db886a6fb45dd63be5ad7fffcbfd (patch)
tree245f1cbb1658be228b4bea3652cba85b7c199080
parentc2d7f08ed9383caf6b2b864c59768ce8ff09d611 (diff)
downloadandroid_hardware_qcom_media-3ac841034ae0db886a6fb45dd63be5ad7fffcbfd.tar.gz
android_hardware_qcom_media-3ac841034ae0db886a6fb45dd63be5ad7fffcbfd.tar.bz2
android_hardware_qcom_media-3ac841034ae0db886a6fb45dd63be5ad7fffcbfd.zip
mm-video: vidc: Reliably stop the message thread
Message thread blocked on a read(), may never wake if the joining thread fails to write the stop command. Instead, monitor the input pipe with timed-wait, and bail-out in case stop is signaled. CRs-Fixed: 952668 Change-Id: I35409034f66281b8acaa216171d85f1dfd868906
-rw-r--r--mm-video-v4l2/vidc/vdec/inc/omx_vdec.h7
-rw-r--r--mm-video-v4l2/vidc/vdec/src/omx_vdec_v4l2.cpp40
-rw-r--r--mm-video-v4l2/vidc/venc/inc/omx_video_base.h5
-rw-r--r--mm-video-v4l2/vidc/venc/src/omx_video_base.cpp42
4 files changed, 66 insertions, 28 deletions
diff --git a/mm-video-v4l2/vidc/vdec/inc/omx_vdec.h b/mm-video-v4l2/vidc/vdec/inc/omx_vdec.h
index 2351ca15..a0305454 100644
--- a/mm-video-v4l2/vidc/vdec/inc/omx_vdec.h
+++ b/mm-video-v4l2/vidc/vdec/inc/omx_vdec.h
@@ -459,6 +459,7 @@ class omx_vdec: public qc_omx_component
void request_perf_level(enum vidc_perf_level perf_level);
int dpb_bit_depth;
bool async_thread_force_stop;
+ volatile bool message_thread_stop;
private:
// Bit Positions
@@ -779,12 +780,6 @@ class omx_vdec: public qc_omx_component
nativebuffer native_buffer[MAX_NUM_INPUT_OUTPUT_BUFFERS];
#endif
-public:
- inline bool omx_close_msg_thread(unsigned char id) {
- return (id == OMX_COMPONENT_CLOSE_MSG);
- }
-
-private:
//*************************************************************
//*******************MEMBER VARIABLES *************************
//*************************************************************
diff --git a/mm-video-v4l2/vidc/vdec/src/omx_vdec_v4l2.cpp b/mm-video-v4l2/vidc/vdec/src/omx_vdec_v4l2.cpp
index ee53e10d..974d5b53 100644
--- a/mm-video-v4l2/vidc/vdec/src/omx_vdec_v4l2.cpp
+++ b/mm-video-v4l2/vidc/vdec/src/omx_vdec_v4l2.cpp
@@ -337,9 +337,27 @@ void* message_thread(void *input)
unsigned char id;
int n;
+ fd_set readFds;
+ int res = 0;
+ struct timeval tv;
+
DEBUG_PRINT_HIGH("omx_vdec: message thread start");
prctl(PR_SET_NAME, (unsigned long)"VideoDecMsgThread", 0, 0, 0);
- while (1) {
+ while (!omx->message_thread_stop) {
+
+ tv.tv_sec = 2;
+ tv.tv_usec = 0;
+
+ FD_ZERO(&readFds);
+ FD_SET(omx->m_pipe_in, &readFds);
+
+ res = select(omx->m_pipe_in + 1, &readFds, NULL, NULL, &tv);
+ if (res < 0) {
+ DEBUG_PRINT_ERROR("select() ERROR: %s", strerror(errno));
+ continue;
+ } else if (res == 0 /*timeout*/ || omx->message_thread_stop) {
+ continue;
+ }
n = read(omx->m_pipe_in, &id, 1);
@@ -348,9 +366,6 @@ void* message_thread(void *input)
}
if (1 == n) {
- if (omx->omx_close_msg_thread(id)) {
- break;
- }
omx->process_event_cb(omx, id);
}
@@ -368,7 +383,11 @@ void post_message(omx_vdec *omx, unsigned char id)
int ret_value;
DEBUG_PRINT_LOW("omx_vdec: post_message %d pipe out%d", id,omx->m_pipe_out);
ret_value = write(omx->m_pipe_out, &id, 1);
- DEBUG_PRINT_LOW("post_message to pipe done %d",ret_value);
+ if (ret_value <= 0) {
+ DEBUG_PRINT_ERROR("post_message to pipe failed : %s", strerror(errno));
+ } else {
+ DEBUG_PRINT_LOW("post_message to pipe done %d",ret_value);
+ }
}
// omx_cmd_queue destructor
@@ -729,6 +748,7 @@ omx_vdec::omx_vdec(): m_error_propogated(false),
msg_thread_created = false;
async_thread_created = false;
async_thread_force_stop = false;
+ message_thread_stop = false;
#ifdef _ANDROID_ICS_
memset(&native_buffer, 0 ,(sizeof(struct nativebuffer) * MAX_NUM_INPUT_OUTPUT_BUFFERS));
#endif
@@ -856,11 +876,13 @@ omx_vdec::~omx_vdec()
{
m_pmem_info = NULL;
DEBUG_PRINT_HIGH("In OMX vdec Destructor");
- DEBUG_PRINT_HIGH("Signalling close to OMX Msg Thread");
- post_message(this, OMX_COMPONENT_CLOSE_MSG);
- DEBUG_PRINT_HIGH("Waiting on OMX Msg Thread exit");
- if (msg_thread_created)
+ if (msg_thread_created) {
+ DEBUG_PRINT_HIGH("Signalling close to OMX Msg Thread");
+ message_thread_stop = true;
+ post_message(this, OMX_COMPONENT_CLOSE_MSG);
+ DEBUG_PRINT_HIGH("Waiting on OMX Msg Thread exit");
pthread_join(msg_thread_id,NULL);
+ }
close(m_pipe_in);
close(m_pipe_out);
m_pipe_in = -1;
diff --git a/mm-video-v4l2/vidc/venc/inc/omx_video_base.h b/mm-video-v4l2/vidc/venc/inc/omx_video_base.h
index 40ff5916..eb403090 100644
--- a/mm-video-v4l2/vidc/venc/inc/omx_video_base.h
+++ b/mm-video-v4l2/vidc/venc/inc/omx_video_base.h
@@ -355,6 +355,7 @@ class omx_video: public qc_omx_component
pthread_t async_thread_id;
bool async_thread_created;
bool msg_thread_created;
+ volatile bool msg_thread_stop;
OMX_U8 m_nkind[128];
@@ -567,10 +568,6 @@ class omx_video: public qc_omx_component
void free_ion_memory(struct venc_ion *buf_ion_info);
#endif
- inline bool omx_close_msg_thread(unsigned char id) {
- return (id == OMX_COMPONENT_CLOSE_MSG);
- }
-
//*************************************************************
//*******************MEMBER VARIABLES *************************
//*************************************************************
diff --git a/mm-video-v4l2/vidc/venc/src/omx_video_base.cpp b/mm-video-v4l2/vidc/venc/src/omx_video_base.cpp
index 9e5b3e04..6c1d6a5a 100644
--- a/mm-video-v4l2/vidc/venc/src/omx_video_base.cpp
+++ b/mm-video-v4l2/vidc/venc/src/omx_video_base.cpp
@@ -128,18 +128,34 @@ void* message_thread(void *input)
unsigned char id;
int n;
+ fd_set readFds;
+ int res = 0;
+ struct timeval tv;
+
DEBUG_PRINT_HIGH("omx_venc: message thread start");
prctl(PR_SET_NAME, (unsigned long)"VideoEncMsgThread", 0, 0, 0);
- while (1) {
+ while (!omx->msg_thread_stop) {
+
+ tv.tv_sec = 2;
+ tv.tv_usec = 0;
+
+ FD_ZERO(&readFds);
+ FD_SET(omx->m_pipe_in, &readFds);
+
+ res = select(omx->m_pipe_in + 1, &readFds, NULL, NULL, &tv);
+ if (res < 0) {
+ DEBUG_PRINT_ERROR("select() ERROR: %s", strerror(errno));
+ continue;
+ } else if (res == 0 /*timeout*/ || omx->msg_thread_stop) {
+ continue;
+ }
+
n = read(omx->m_pipe_in, &id, 1);
if (0 == n) {
break;
}
if (1 == n) {
- if (omx->omx_close_msg_thread(id)) {
- break;
- }
omx->process_event_cb(omx, id);
}
#ifdef QLE_BUILD
@@ -158,7 +174,13 @@ void* message_thread(void *input)
void post_message(omx_video *omx, unsigned char id)
{
DEBUG_PRINT_LOW("omx_venc: post_message %d", id);
- write(omx->m_pipe_out, &id, 1);
+ int ret_value;
+ ret_value = write(omx->m_pipe_out, &id, 1);
+ if (ret_value <= 0) {
+ DEBUG_PRINT_ERROR("post_message to pipe failed : %s", strerror(errno));
+ } else {
+ DEBUG_PRINT_LOW("post_message to pipe done %d",ret_value);
+ }
}
// omx_cmd_queue destructor
@@ -285,6 +307,7 @@ omx_video::omx_video():
memset(&m_pCallbacks,0,sizeof(m_pCallbacks));
async_thread_created = false;
msg_thread_created = false;
+ msg_thread_stop = false;
mUsesColorConversion = false;
pthread_mutex_init(&m_lock, NULL);
@@ -309,11 +332,12 @@ omx_video::omx_video():
omx_video::~omx_video()
{
DEBUG_PRINT_HIGH("~omx_video(): Inside Destructor()");
- DEBUG_PRINT_HIGH("Signalling close to OMX Msg Thread");
- post_message(this, OMX_COMPONENT_CLOSE_MSG);
- DEBUG_PRINT_HIGH("omx_video: Waiting on Msg Thread exit");
- if (msg_thread_created)
+ if (msg_thread_created) {
+ msg_thread_stop = true;
+ post_message(this, OMX_COMPONENT_CLOSE_MSG);
+ DEBUG_PRINT_HIGH("omx_video: Waiting on Msg Thread exit");
pthread_join(msg_thread_id,NULL);
+ }
close(m_pipe_in);
close(m_pipe_out);
m_pipe_in = -1;