Commit 173d07f2 authored by Simon Morlat's avatar Simon Morlat Committed by Sylvain Berfini

Fix/opensles crash

parent fa67a07d
......@@ -72,7 +72,7 @@ typedef struct _MSTickerLateEvent MSTickerLateEvent;
struct _MSTicker
{
ms_mutex_t lock;
ms_mutex_t lock; /*main lock protecting the filter execution list */
ms_cond_t cond;
MSList *execution_list; /* the list of source filters to be executed.*/
MSList *task_list; /* list of tasks (see ms_filter_postpone_task())*/
......@@ -84,6 +84,7 @@ struct _MSTicker
uint64_t orig; /* a relative time to take in account difference between time base given by consecutive get_cur_time_ptr() functions.*/
MSTickerTimeFunc get_cur_time_ptr;
void *get_cur_time_data;
ms_mutex_t cur_time_lock; /*mutex protecting the get_cur_time_ptr/get_cur_time_data which can be changed at any time*/
char *name;
double av_load; /*average load of the ticker */
MSTickerPrio prio;
......
......@@ -940,14 +940,18 @@ static void android_snd_write_postprocess(MSFilter *obj) {
SLresult result;
OpenSLESOutputContext *octx = (OpenSLESOutputContext*)obj->data;
result = (*octx->playerPlay)->SetPlayState(octx->playerPlay, SL_PLAYSTATE_STOPPED);
if (result != SL_RESULT_SUCCESS) {
ms_error("OpenSLES Error %u while stopping player", result);
if (octx->playerPlay){
result = (*octx->playerPlay)->SetPlayState(octx->playerPlay, SL_PLAYSTATE_STOPPED);
if (result != SL_RESULT_SUCCESS) {
ms_error("OpenSLES Error %u while stopping player", result);
}
}
result = (*octx->playerBufferQueue)->Clear(octx->playerBufferQueue);
if (result != SL_RESULT_SUCCESS) {
ms_error("OpenSLES Error %u while clearing player buffer queue", result);
if (octx->playerBufferQueue){
result = (*octx->playerBufferQueue)->Clear(octx->playerBufferQueue);
if (result != SL_RESULT_SUCCESS) {
ms_error("OpenSLES Error %u while clearing player buffer queue", result);
}
}
if (octx->playerObject != NULL) {
......
......@@ -55,6 +55,7 @@ static void ms_ticker_start(MSTicker *s){
static void ms_ticker_init(MSTicker *ticker, const MSTickerParams *params)
{
ms_mutex_init(&ticker->lock,NULL);
ms_mutex_init(&ticker->cur_time_lock, NULL);
ticker->execution_list=NULL;
ticker->task_list=NULL;
ticker->ticks=1;
......@@ -112,6 +113,7 @@ static void ms_ticker_uninit(MSTicker *ticker)
ms_ticker_stop(ticker);
ms_free(ticker->name);
ms_mutex_destroy(&ticker->lock);
ms_mutex_destroy(&ticker->cur_time_lock);
}
void ms_ticker_destroy(MSTicker *ticker){
......@@ -394,7 +396,10 @@ static int wait_next_tick(void *data, uint64_t virt_ticker_time){
int late;
while(1){
ms_mutex_lock(&s->cur_time_lock);
realtime=s->get_cur_time_ptr(s->get_cur_time_data)-s->orig;
ms_mutex_unlock(&s->cur_time_lock);
diff=s->time-realtime;
if (diff>0){
/* sleep until next tick */
......@@ -420,7 +425,9 @@ void * ms_ticker_run(void *arg)
precision = set_high_prio(s);
s->thread_id = ms_thread_self();
s->ticks=1;
ms_mutex_lock(&s->cur_time_lock);
s->orig=s->get_cur_time_ptr(s->get_cur_time_data);
ms_mutex_unlock(&s->cur_time_lock);
while(s->run){
uint64_t late_tick_time=0;
......@@ -469,12 +476,14 @@ void * ms_ticker_run(void *arg)
void ms_ticker_set_time_func(MSTicker *ticker, MSTickerTimeFunc func, void *user_data){
if (func==NULL) func=get_cur_time_ms;
ms_mutex_lock(&ticker->cur_time_lock);
ticker->get_cur_time_ptr=func;
ticker->get_cur_time_data=user_data;
/*re-set the origin to take in account that previous function ptr and the
new one may return different times*/
ticker->orig=func(user_data)-ticker->time;
ms_mutex_unlock(&ticker->cur_time_lock);
ms_message("ms_ticker_set_time_func: ticker's time method updated.");
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment