system/media: replace sem lock with pthread_mutex
Signed-off-by: ligd <liguiding1@xiaomi.com>
This commit is contained in:
parent
44d0642334
commit
0e06cfeaec
@ -29,7 +29,6 @@
|
|||||||
|
|
||||||
#include <mqueue.h>
|
#include <mqueue.h>
|
||||||
#include <pthread.h>
|
#include <pthread.h>
|
||||||
#include <semaphore.h>
|
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* Pre-processor Definitions
|
* Pre-processor Definitions
|
||||||
@ -43,30 +42,30 @@
|
|||||||
|
|
||||||
struct nxlooper_s
|
struct nxlooper_s
|
||||||
{
|
{
|
||||||
int loopstate; /* Current looper test state */
|
int loopstate; /* Current looper test state */
|
||||||
int recorddev_fd; /* File descriptor of active
|
int recorddev_fd; /* File descriptor of active
|
||||||
* record device */
|
* record device */
|
||||||
char recorddev[CONFIG_NAME_MAX]; /* Preferred record device */
|
char recorddev[CONFIG_NAME_MAX]; /* Preferred record device */
|
||||||
int playdev_fd; /* File descriptor of active
|
int playdev_fd; /* File descriptor of active
|
||||||
* play device */
|
* play device */
|
||||||
char playdev[CONFIG_NAME_MAX]; /* Preferred loopback device */
|
char playdev[CONFIG_NAME_MAX]; /* Preferred loopback device */
|
||||||
int crefs; /* Number of references */
|
int crefs; /* Number of references */
|
||||||
sem_t sem; /* Thread sync semaphore */
|
pthread_mutex_t mutex; /* Thread sync mutex */
|
||||||
char mqname[16]; /* Name of play message queue */
|
char mqname[16]; /* Name of play message queue */
|
||||||
mqd_t mq; /* Message queue for the
|
mqd_t mq; /* Message queue for the
|
||||||
* loopthread */
|
* loopthread */
|
||||||
pthread_t loop_id; /* Thread ID of the loopthread */
|
pthread_t loop_id; /* Thread ID of the loopthread */
|
||||||
|
|
||||||
#ifdef CONFIG_AUDIO_MULTI_SESSION
|
#ifdef CONFIG_AUDIO_MULTI_SESSION
|
||||||
FAR void *pplayses; /* Session assignment from device */
|
FAR void *pplayses; /* Session assignment from device */
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef CONFIG_AUDIO_MULTI_SESSION
|
#ifdef CONFIG_AUDIO_MULTI_SESSION
|
||||||
FAR void *precordses; /* Session assignment from device */
|
FAR void *precordses; /* Session assignment from device */
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef CONFIG_AUDIO_EXCLUDE_VOLUME
|
#ifndef CONFIG_AUDIO_EXCLUDE_VOLUME
|
||||||
uint16_t volume; /* Volume as a whole percentage (0-100) */
|
uint16_t volume; /* Volume as a whole percentage (0-100) */
|
||||||
#endif
|
#endif
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -29,7 +29,6 @@
|
|||||||
|
|
||||||
#include <mqueue.h>
|
#include <mqueue.h>
|
||||||
#include <pthread.h>
|
#include <pthread.h>
|
||||||
#include <semaphore.h>
|
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* Pre-processor Definitions
|
* Pre-processor Definitions
|
||||||
@ -51,34 +50,34 @@ struct nxplayer_dec_ops_s
|
|||||||
|
|
||||||
struct nxplayer_s
|
struct nxplayer_s
|
||||||
{
|
{
|
||||||
int state; /* Current player state */
|
int state; /* Current player state */
|
||||||
int dev_fd; /* File descriptor of active device */
|
int dev_fd; /* File descriptor of active device */
|
||||||
mqd_t mq; /* Message queue for the playthread */
|
mqd_t mq; /* Message queue for the playthread */
|
||||||
char mqname[16]; /* Name of our message queue */
|
char mqname[16]; /* Name of our message queue */
|
||||||
pthread_t play_id; /* Thread ID of the playthread */
|
pthread_t play_id; /* Thread ID of the playthread */
|
||||||
int crefs; /* Number of references to the player */
|
int crefs; /* Number of references to the player */
|
||||||
sem_t sem; /* Thread sync semaphore */
|
pthread_mutex_t mutex; /* Thread sync mutex */
|
||||||
int fd; /* File descriptor of open file */
|
int fd; /* File descriptor of open file */
|
||||||
#ifdef CONFIG_NXPLAYER_INCLUDE_PREFERRED_DEVICE
|
#ifdef CONFIG_NXPLAYER_INCLUDE_PREFERRED_DEVICE
|
||||||
char prefdevice[CONFIG_NAME_MAX]; /* Preferred audio device */
|
char prefdevice[CONFIG_NAME_MAX]; /* Preferred audio device */
|
||||||
int prefformat; /* Formats supported by preferred device */
|
int prefformat; /* Formats supported by preferred device */
|
||||||
int preftype; /* Types supported by preferred device */
|
int preftype; /* Types supported by preferred device */
|
||||||
#endif
|
#endif
|
||||||
#ifdef CONFIG_NXPLAYER_INCLUDE_MEDIADIR
|
#ifdef CONFIG_NXPLAYER_INCLUDE_MEDIADIR
|
||||||
char mediadir[CONFIG_NAME_MAX]; /* Root media directory where media is located */
|
char mediadir[CONFIG_NAME_MAX]; /* Root media directory where media is located */
|
||||||
#endif
|
#endif
|
||||||
#ifdef CONFIG_AUDIO_MULTI_SESSION
|
#ifdef CONFIG_AUDIO_MULTI_SESSION
|
||||||
FAR void *session; /* Session assignment from device */
|
FAR void *session; /* Session assignment from device */
|
||||||
#endif
|
#endif
|
||||||
#ifndef CONFIG_AUDIO_EXCLUDE_VOLUME
|
#ifndef CONFIG_AUDIO_EXCLUDE_VOLUME
|
||||||
uint16_t volume; /* Volume as a whole percentage (0-100) */
|
uint16_t volume; /* Volume as a whole percentage (0-100) */
|
||||||
#ifndef CONFIG_AUDIO_EXCLUDE_BALANCE
|
#ifndef CONFIG_AUDIO_EXCLUDE_BALANCE
|
||||||
uint16_t balance; /* Balance as a whole % (0=left off, 100=right off) */
|
uint16_t balance; /* Balance as a whole % (0=left off, 100=right off) */
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
#ifndef CONFIG_AUDIO_EXCLUDE_TONE
|
#ifndef CONFIG_AUDIO_EXCLUDE_TONE
|
||||||
uint16_t treble; /* Treble as a whole % */
|
uint16_t treble; /* Treble as a whole % */
|
||||||
uint16_t bass; /* Bass as a whole % */
|
uint16_t bass; /* Bass as a whole % */
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
FAR const struct nxplayer_dec_ops_s *ops;
|
FAR const struct nxplayer_dec_ops_s *ops;
|
||||||
|
@ -29,7 +29,6 @@
|
|||||||
|
|
||||||
#include <mqueue.h>
|
#include <mqueue.h>
|
||||||
#include <pthread.h>
|
#include <pthread.h>
|
||||||
#include <semaphore.h>
|
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* Pre-processor Definitions
|
* Pre-processor Definitions
|
||||||
@ -43,17 +42,17 @@
|
|||||||
|
|
||||||
struct nxrecorder_s
|
struct nxrecorder_s
|
||||||
{
|
{
|
||||||
int state; /* Current recorder state */
|
int state; /* Current recorder state */
|
||||||
int dev_fd; /* File descriptor of active device */
|
int dev_fd; /* File descriptor of active device */
|
||||||
mqd_t mq; /* Message queue for the recordthread */
|
mqd_t mq; /* Message queue for the recordthread */
|
||||||
char mqname[16]; /* Name of our message queue */
|
char mqname[16]; /* Name of our message queue */
|
||||||
pthread_t record_id; /* Thread ID of the recordthread */
|
pthread_t record_id; /* Thread ID of the recordthread */
|
||||||
int crefs; /* Number of references to the recorder */
|
int crefs; /* Number of references to the recorder */
|
||||||
sem_t sem; /* Thread sync semaphore */
|
pthread_mutex_t mutex; /* Thread sync mutex */
|
||||||
int fd; /* File descriptor of open file */
|
int fd; /* File descriptor of open file */
|
||||||
char device[CONFIG_NAME_MAX]; /* Preferred audio device */
|
char device[CONFIG_NAME_MAX]; /* Preferred audio device */
|
||||||
#ifdef CONFIG_AUDIO_MULTI_SESSION
|
#ifdef CONFIG_AUDIO_MULTI_SESSION
|
||||||
FAR void *session; /* Session assignment from device */
|
FAR void *session; /* Session assignment from device */
|
||||||
#endif
|
#endif
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -670,9 +670,7 @@ err_out:
|
|||||||
|
|
||||||
/* Cleanup */
|
/* Cleanup */
|
||||||
|
|
||||||
while (sem_wait(&plooper->sem) < 0)
|
pthread_mutex_lock(&plooper->mutex);
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
close(plooper->playdev_fd); /* Close the play device */
|
close(plooper->playdev_fd); /* Close the play device */
|
||||||
close(plooper->recorddev_fd); /* Close the record device */
|
close(plooper->recorddev_fd); /* Close the record device */
|
||||||
@ -682,7 +680,7 @@ err_out:
|
|||||||
mq_unlink(plooper->mqname); /* Unlink the message queue */
|
mq_unlink(plooper->mqname); /* Unlink the message queue */
|
||||||
plooper->loopstate = NXLOOPER_STATE_IDLE;
|
plooper->loopstate = NXLOOPER_STATE_IDLE;
|
||||||
|
|
||||||
sem_post(&plooper->sem); /* Release the semaphore */
|
pthread_mutex_unlock(&plooper->mutex);
|
||||||
|
|
||||||
audinfo("Exit\n");
|
audinfo("Exit\n");
|
||||||
|
|
||||||
@ -706,10 +704,7 @@ int nxlooper_setvolume(FAR struct nxlooper_s *plooper, uint16_t volume)
|
|||||||
struct audio_caps_desc_s cap_desc;
|
struct audio_caps_desc_s cap_desc;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
/* Thread sync using the semaphore */
|
pthread_mutex_lock(&plooper->mutex);
|
||||||
|
|
||||||
while (sem_wait(&plooper->sem) < 0)
|
|
||||||
;
|
|
||||||
|
|
||||||
/* If we are currently looping, then we need to post a message to
|
/* If we are currently looping, then we need to post a message to
|
||||||
* the loopthread to perform the volume change operation. If we
|
* the loopthread to perform the volume change operation. If we
|
||||||
@ -735,7 +730,7 @@ int nxlooper_setvolume(FAR struct nxlooper_s *plooper, uint16_t volume)
|
|||||||
DEBUGASSERT(errcode > 0);
|
DEBUGASSERT(errcode > 0);
|
||||||
|
|
||||||
auderr("ERROR: AUDIOIOC_CONFIGURE ioctl failed: %d\n", errcode);
|
auderr("ERROR: AUDIOIOC_CONFIGURE ioctl failed: %d\n", errcode);
|
||||||
sem_post(&plooper->sem);
|
pthread_mutex_unlock(&plooper->mutex);
|
||||||
return -errcode;
|
return -errcode;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -743,7 +738,7 @@ int nxlooper_setvolume(FAR struct nxlooper_s *plooper, uint16_t volume)
|
|||||||
/* Store the volume setting */
|
/* Store the volume setting */
|
||||||
|
|
||||||
plooper->volume = volume;
|
plooper->volume = volume;
|
||||||
sem_post(&plooper->sem);
|
pthread_mutex_unlock(&plooper->mutex);
|
||||||
|
|
||||||
return OK;
|
return OK;
|
||||||
}
|
}
|
||||||
@ -915,14 +910,14 @@ int nxlooper_stop(FAR struct nxlooper_s *plooper)
|
|||||||
|
|
||||||
/* Validate we are not in IDLE state */
|
/* Validate we are not in IDLE state */
|
||||||
|
|
||||||
sem_wait(&plooper->sem); /* Get the semaphore */
|
pthread_mutex_lock(&plooper->mutex);
|
||||||
if (plooper->loopstate == NXLOOPER_STATE_IDLE)
|
if (plooper->loopstate == NXLOOPER_STATE_IDLE)
|
||||||
{
|
{
|
||||||
sem_post(&plooper->sem); /* Release the semaphore */
|
pthread_mutex_unlock(&plooper->mutex);
|
||||||
return OK;
|
return OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
sem_post(&plooper->sem);
|
pthread_mutex_unlock(&plooper->mutex);
|
||||||
|
|
||||||
/* Notify the loopback thread that it needs to cancel the loopback */
|
/* Notify the loopback thread that it needs to cancel the loopback */
|
||||||
|
|
||||||
@ -1207,7 +1202,7 @@ FAR struct nxlooper_s *nxlooper_create(void)
|
|||||||
plooper->precordses = NULL;
|
plooper->precordses = NULL;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
sem_init(&plooper->sem, 0, 1);
|
pthread_mutex_init(&plooper->mutex, NULL);
|
||||||
|
|
||||||
return plooper;
|
return plooper;
|
||||||
}
|
}
|
||||||
@ -1230,45 +1225,23 @@ void nxlooper_release(FAR struct nxlooper_s *plooper)
|
|||||||
int refcount;
|
int refcount;
|
||||||
FAR void *value;
|
FAR void *value;
|
||||||
|
|
||||||
/* Grab the semaphore */
|
pthread_mutex_lock(&plooper->mutex);
|
||||||
|
|
||||||
while (sem_wait(&plooper->sem) < 0)
|
|
||||||
{
|
|
||||||
int errcode = errno;
|
|
||||||
DEBUGASSERT(errcode > 0);
|
|
||||||
|
|
||||||
if (errcode != EINTR)
|
|
||||||
{
|
|
||||||
auderr("ERROR: sem_wait failed: %d\n", errcode);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Check if there was a previous thread and join it if there was */
|
/* Check if there was a previous thread and join it if there was */
|
||||||
|
|
||||||
if (plooper->loop_id != 0)
|
if (plooper->loop_id != 0)
|
||||||
{
|
{
|
||||||
sem_post(&plooper->sem);
|
pthread_mutex_unlock(&plooper->mutex);
|
||||||
pthread_join(plooper->loop_id, &value);
|
pthread_join(plooper->loop_id, &value);
|
||||||
plooper->loop_id = 0;
|
plooper->loop_id = 0;
|
||||||
|
|
||||||
while (sem_wait(&plooper->sem) < 0)
|
pthread_mutex_lock(&plooper->mutex);
|
||||||
{
|
|
||||||
int errcode = errno;
|
|
||||||
DEBUGASSERT(errcode > 0);
|
|
||||||
|
|
||||||
if (errcode != EINTR)
|
|
||||||
{
|
|
||||||
auderr("ERROR: sem_wait failed: %d\n", errcode);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Reduce the reference count */
|
/* Reduce the reference count */
|
||||||
|
|
||||||
refcount = plooper->crefs--;
|
refcount = plooper->crefs--;
|
||||||
sem_post(&plooper->sem);
|
pthread_mutex_unlock(&plooper->mutex);
|
||||||
|
|
||||||
/* If the ref count *was* one, then free the context */
|
/* If the ref count *was* one, then free the context */
|
||||||
|
|
||||||
@ -1292,24 +1265,12 @@ void nxlooper_release(FAR struct nxlooper_s *plooper)
|
|||||||
|
|
||||||
void nxlooper_reference(FAR struct nxlooper_s *plooper)
|
void nxlooper_reference(FAR struct nxlooper_s *plooper)
|
||||||
{
|
{
|
||||||
/* Grab the semaphore */
|
pthread_mutex_lock(&plooper->mutex);
|
||||||
|
|
||||||
while (sem_wait(&plooper->sem) < 0)
|
|
||||||
{
|
|
||||||
int errcode = errno;
|
|
||||||
DEBUGASSERT(errcode > 0);
|
|
||||||
|
|
||||||
if (errcode != EINTR)
|
|
||||||
{
|
|
||||||
auderr("ERROR: sem_wait failed: %d\n", errcode);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Increment the reference count */
|
/* Increment the reference count */
|
||||||
|
|
||||||
plooper->crefs++;
|
plooper->crefs++;
|
||||||
sem_post(&plooper->sem);
|
pthread_mutex_unlock(&plooper->mutex);
|
||||||
}
|
}
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
|
@ -1113,8 +1113,7 @@ err_out:
|
|||||||
|
|
||||||
/* Cleanup */
|
/* Cleanup */
|
||||||
|
|
||||||
while (sem_wait(&pplayer->sem) < 0)
|
pthread_mutex_lock(&pplayer->mutex);
|
||||||
;
|
|
||||||
|
|
||||||
/* Close the files */
|
/* Close the files */
|
||||||
|
|
||||||
@ -1131,7 +1130,7 @@ err_out:
|
|||||||
pplayer->ops = NULL; /* Clear offload parser */
|
pplayer->ops = NULL; /* Clear offload parser */
|
||||||
pplayer->state = NXPLAYER_STATE_IDLE; /* Go to IDLE */
|
pplayer->state = NXPLAYER_STATE_IDLE; /* Go to IDLE */
|
||||||
|
|
||||||
sem_post(&pplayer->sem); /* Release the semaphore */
|
pthread_mutex_unlock(&pplayer->mutex);
|
||||||
|
|
||||||
/* The playthread is done with the context. Release it, which may
|
/* The playthread is done with the context. Release it, which may
|
||||||
* actually cause the context to be freed if the creator has already
|
* actually cause the context to be freed if the creator has already
|
||||||
@ -1162,10 +1161,7 @@ int nxplayer_setvolume(FAR struct nxplayer_s *pplayer, uint16_t volume)
|
|||||||
struct audio_caps_desc_s cap_desc;
|
struct audio_caps_desc_s cap_desc;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
/* Thread sync using the semaphore */
|
pthread_mutex_lock(&pplayer->mutex);
|
||||||
|
|
||||||
while (sem_wait(&pplayer->sem) < 0)
|
|
||||||
;
|
|
||||||
|
|
||||||
/* If we are currently playing, then we need to post a message to
|
/* If we are currently playing, then we need to post a message to
|
||||||
* the playthread to perform the volume change operation. If we
|
* the playthread to perform the volume change operation. If we
|
||||||
@ -1192,7 +1188,7 @@ int nxplayer_setvolume(FAR struct nxplayer_s *pplayer, uint16_t volume)
|
|||||||
DEBUGASSERT(errcode > 0);
|
DEBUGASSERT(errcode > 0);
|
||||||
|
|
||||||
auderr("ERROR: AUDIOIOC_CONFIGURE ioctl failed: %d\n", errcode);
|
auderr("ERROR: AUDIOIOC_CONFIGURE ioctl failed: %d\n", errcode);
|
||||||
sem_post(&pplayer->sem);
|
pthread_mutex_unlock(&pplayer->mutex);
|
||||||
return -errcode;
|
return -errcode;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1200,7 +1196,7 @@ int nxplayer_setvolume(FAR struct nxplayer_s *pplayer, uint16_t volume)
|
|||||||
/* Store the volume setting */
|
/* Store the volume setting */
|
||||||
|
|
||||||
pplayer->volume = volume;
|
pplayer->volume = volume;
|
||||||
sem_post(&pplayer->sem);
|
pthread_mutex_unlock(&pplayer->mutex);
|
||||||
|
|
||||||
return OK;
|
return OK;
|
||||||
}
|
}
|
||||||
@ -1250,10 +1246,7 @@ int nxplayer_setbass(FAR struct nxplayer_s *pplayer, uint8_t level)
|
|||||||
{
|
{
|
||||||
struct audio_caps_desc_s cap_desc;
|
struct audio_caps_desc_s cap_desc;
|
||||||
|
|
||||||
/* Thread sync using the semaphore */
|
pthread_mutex_lock(&pplayer->mutex);
|
||||||
|
|
||||||
while (sem_wait(&pplayer->sem) < 0)
|
|
||||||
;
|
|
||||||
|
|
||||||
/* If we are currently playing, then we need to post a message to
|
/* If we are currently playing, then we need to post a message to
|
||||||
* the playthread to perform the volume change operation. If we
|
* the playthread to perform the volume change operation. If we
|
||||||
@ -1279,7 +1272,7 @@ int nxplayer_setbass(FAR struct nxplayer_s *pplayer, uint8_t level)
|
|||||||
|
|
||||||
pplayer->bass = level;
|
pplayer->bass = level;
|
||||||
|
|
||||||
sem_post(&pplayer->sem);
|
pthread_mutex_unlock(&pplayer->mutex);
|
||||||
|
|
||||||
return -ENOENT;
|
return -ENOENT;
|
||||||
}
|
}
|
||||||
@ -1302,10 +1295,7 @@ int nxplayer_settreble(FAR struct nxplayer_s *pplayer, uint8_t level)
|
|||||||
{
|
{
|
||||||
struct audio_caps_desc_s cap_desc;
|
struct audio_caps_desc_s cap_desc;
|
||||||
|
|
||||||
/* Thread sync using the semaphore */
|
pthread_mutex_lock(&pplayer->mutex);
|
||||||
|
|
||||||
while (sem_wait(&pplayer->sem) < 0)
|
|
||||||
;
|
|
||||||
|
|
||||||
/* If we are currently playing, then we need to post a message to
|
/* If we are currently playing, then we need to post a message to
|
||||||
* the playthread to perform the volume change operation. If we
|
* the playthread to perform the volume change operation. If we
|
||||||
@ -1331,7 +1321,7 @@ int nxplayer_settreble(FAR struct nxplayer_s *pplayer, uint8_t level)
|
|||||||
|
|
||||||
pplayer->treble = level;
|
pplayer->treble = level;
|
||||||
|
|
||||||
sem_post(&pplayer->sem);
|
pthread_mutex_unlock(&pplayer->mutex);
|
||||||
|
|
||||||
return -ENOENT;
|
return -ENOENT;
|
||||||
}
|
}
|
||||||
@ -1350,10 +1340,7 @@ int nxplayer_setbalance(FAR struct nxplayer_s *pplayer, uint16_t balance)
|
|||||||
{
|
{
|
||||||
struct audio_caps_desc_s cap_desc;
|
struct audio_caps_desc_s cap_desc;
|
||||||
|
|
||||||
/* Thread sync using the semaphore */
|
pthread_mutex_lock(&pplayer->mutex);
|
||||||
|
|
||||||
while (sem_wait(&pplayer->sem) < 0)
|
|
||||||
;
|
|
||||||
|
|
||||||
/* If we are currently playing, then we need to post a message to
|
/* If we are currently playing, then we need to post a message to
|
||||||
* the playthread to perform the volume change operation. If we
|
* the playthread to perform the volume change operation. If we
|
||||||
@ -1379,7 +1366,7 @@ int nxplayer_setbalance(FAR struct nxplayer_s *pplayer, uint16_t balance)
|
|||||||
|
|
||||||
pplayer->balance = balance;
|
pplayer->balance = balance;
|
||||||
|
|
||||||
sem_post(&pplayer->sem);
|
pthread_mutex_unlock(&pplayer->mutex);
|
||||||
|
|
||||||
return -ENOENT;
|
return -ENOENT;
|
||||||
}
|
}
|
||||||
@ -1689,14 +1676,14 @@ int nxplayer_stop(FAR struct nxplayer_s *pplayer)
|
|||||||
|
|
||||||
/* Validate we are not in IDLE state */
|
/* Validate we are not in IDLE state */
|
||||||
|
|
||||||
sem_wait(&pplayer->sem); /* Get the semaphore */
|
pthread_mutex_lock(&pplayer->mutex);
|
||||||
if (pplayer->state == NXPLAYER_STATE_IDLE)
|
if (pplayer->state == NXPLAYER_STATE_IDLE)
|
||||||
{
|
{
|
||||||
sem_post(&pplayer->sem); /* Release the semaphore */
|
pthread_mutex_unlock(&pplayer->mutex);
|
||||||
return OK;
|
return OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
sem_post(&pplayer->sem);
|
pthread_mutex_unlock(&pplayer->mutex);
|
||||||
|
|
||||||
/* Notify the playback thread that it needs to cancel the playback */
|
/* Notify the playback thread that it needs to cancel the playback */
|
||||||
|
|
||||||
@ -2150,7 +2137,8 @@ FAR struct nxplayer_s *nxplayer_create(void)
|
|||||||
strncpy(pplayer->mediadir, CONFIG_NXPLAYER_DEFAULT_MEDIADIR,
|
strncpy(pplayer->mediadir, CONFIG_NXPLAYER_DEFAULT_MEDIADIR,
|
||||||
sizeof(pplayer->mediadir));
|
sizeof(pplayer->mediadir));
|
||||||
#endif
|
#endif
|
||||||
sem_init(&pplayer->sem, 0, 1);
|
|
||||||
|
pthread_mutex_init(&pplayer->mutex, NULL);
|
||||||
|
|
||||||
return pplayer;
|
return pplayer;
|
||||||
}
|
}
|
||||||
@ -2173,45 +2161,23 @@ void nxplayer_release(FAR struct nxplayer_s *pplayer)
|
|||||||
int refcount;
|
int refcount;
|
||||||
FAR void *value;
|
FAR void *value;
|
||||||
|
|
||||||
/* Grab the semaphore */
|
pthread_mutex_lock(&pplayer->mutex);
|
||||||
|
|
||||||
while (sem_wait(&pplayer->sem) < 0)
|
|
||||||
{
|
|
||||||
int errcode = errno;
|
|
||||||
DEBUGASSERT(errcode > 0);
|
|
||||||
|
|
||||||
if (errcode != EINTR)
|
|
||||||
{
|
|
||||||
auderr("ERROR: sem_wait failed: %d\n", errcode);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Check if there was a previous thread and join it if there was */
|
/* Check if there was a previous thread and join it if there was */
|
||||||
|
|
||||||
if (pplayer->play_id != 0)
|
if (pplayer->play_id != 0)
|
||||||
{
|
{
|
||||||
sem_post(&pplayer->sem);
|
pthread_mutex_unlock(&pplayer->mutex);
|
||||||
pthread_join(pplayer->play_id, &value);
|
pthread_join(pplayer->play_id, &value);
|
||||||
pplayer->play_id = 0;
|
pplayer->play_id = 0;
|
||||||
|
|
||||||
while (sem_wait(&pplayer->sem) < 0)
|
pthread_mutex_lock(&pplayer->mutex);
|
||||||
{
|
|
||||||
int errcode = errno;
|
|
||||||
DEBUGASSERT(errcode > 0);
|
|
||||||
|
|
||||||
if (errcode != -EINTR)
|
|
||||||
{
|
|
||||||
auderr("ERROR: sem_wait failed: %d\n", errcode);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Reduce the reference count */
|
/* Reduce the reference count */
|
||||||
|
|
||||||
refcount = pplayer->crefs--;
|
refcount = pplayer->crefs--;
|
||||||
sem_post(&pplayer->sem);
|
pthread_mutex_unlock(&pplayer->mutex);
|
||||||
|
|
||||||
/* If the ref count *was* one, then free the context */
|
/* If the ref count *was* one, then free the context */
|
||||||
|
|
||||||
@ -2235,67 +2201,12 @@ void nxplayer_release(FAR struct nxplayer_s *pplayer)
|
|||||||
|
|
||||||
void nxplayer_reference(FAR struct nxplayer_s *pplayer)
|
void nxplayer_reference(FAR struct nxplayer_s *pplayer)
|
||||||
{
|
{
|
||||||
/* Grab the semaphore */
|
pthread_mutex_lock(&pplayer->mutex);
|
||||||
|
|
||||||
while (sem_wait(&pplayer->sem) < 0)
|
|
||||||
{
|
|
||||||
int errcode = errno;
|
|
||||||
DEBUGASSERT(errcode > 0);
|
|
||||||
|
|
||||||
if (errcode != -EINTR)
|
|
||||||
{
|
|
||||||
auderr("ERROR: sem_wait failed: %d\n", errcode);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Increment the reference count */
|
/* Increment the reference count */
|
||||||
|
|
||||||
pplayer->crefs++;
|
pplayer->crefs++;
|
||||||
sem_post(&pplayer->sem);
|
pthread_mutex_unlock(&pplayer->mutex);
|
||||||
}
|
|
||||||
|
|
||||||
/****************************************************************************
|
|
||||||
* Name: nxplayer_detach
|
|
||||||
*
|
|
||||||
* nxplayer_detach() detaches from the playthread to make it independent
|
|
||||||
* so the caller can abandon the context while the file is still
|
|
||||||
* being played.
|
|
||||||
*
|
|
||||||
* Input Parameters:
|
|
||||||
* pplayer Pointer to the NxPlayer context
|
|
||||||
*
|
|
||||||
* Returned values: None
|
|
||||||
*
|
|
||||||
****************************************************************************/
|
|
||||||
|
|
||||||
void nxplayer_detach(FAR struct nxplayer_s *pplayer)
|
|
||||||
{
|
|
||||||
#if 0
|
|
||||||
/* Grab the semaphore */
|
|
||||||
|
|
||||||
while (sem_wait(&pplayer->sem) < 0)
|
|
||||||
{
|
|
||||||
int errcode = errno;
|
|
||||||
DEBUGASSERT(errcode > 0);
|
|
||||||
|
|
||||||
if (errcode != -EINTR)
|
|
||||||
{
|
|
||||||
auderr("ERROR: sem_wait failed: %d\n", errcode);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (pplayer->play_id != NULL)
|
|
||||||
{
|
|
||||||
/* Do a pthread detach */
|
|
||||||
|
|
||||||
pthread_detach(pplayer->play_id);
|
|
||||||
pplayer->play_id = NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
sem_post(&pplayer->sem);
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
|
@ -837,8 +837,6 @@ int main(int argc, FAR char *argv[])
|
|||||||
|
|
||||||
/* Release the NxPlayer context */
|
/* Release the NxPlayer context */
|
||||||
|
|
||||||
/* nxplayer_detach(pplayer); */
|
|
||||||
|
|
||||||
nxplayer_release(pplayer);
|
nxplayer_release(pplayer);
|
||||||
|
|
||||||
return OK;
|
return OK;
|
||||||
|
@ -566,9 +566,7 @@ err_out:
|
|||||||
|
|
||||||
/* Cleanup */
|
/* Cleanup */
|
||||||
|
|
||||||
while (sem_wait(&precorder->sem) < 0)
|
pthread_mutex_lock(&precorder->mutex);
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Close the files */
|
/* Close the files */
|
||||||
|
|
||||||
@ -584,7 +582,7 @@ err_out:
|
|||||||
mq_unlink(precorder->mqname); /* Unlink the message queue */
|
mq_unlink(precorder->mqname); /* Unlink the message queue */
|
||||||
precorder->state = NXRECORDER_STATE_IDLE; /* Go to IDLE */
|
precorder->state = NXRECORDER_STATE_IDLE; /* Go to IDLE */
|
||||||
|
|
||||||
sem_post(&precorder->sem); /* Release the semaphore */
|
pthread_mutex_unlock(&precorder->mutex);
|
||||||
|
|
||||||
/* The record thread is done with the context. Release it, which may
|
/* The record thread is done with the context. Release it, which may
|
||||||
* actually cause the context to be freed if the creator has already
|
* actually cause the context to be freed if the creator has already
|
||||||
@ -718,14 +716,14 @@ int nxrecorder_stop(FAR struct nxrecorder_s *precorder)
|
|||||||
|
|
||||||
/* Validate we are not in IDLE state */
|
/* Validate we are not in IDLE state */
|
||||||
|
|
||||||
sem_wait(&precorder->sem); /* Get the semaphore */
|
pthread_mutex_lock(&precorder->mutex);
|
||||||
if (precorder->state == NXRECORDER_STATE_IDLE)
|
if (precorder->state == NXRECORDER_STATE_IDLE)
|
||||||
{
|
{
|
||||||
sem_post(&precorder->sem); /* Release the semaphore */
|
pthread_mutex_unlock(&precorder->mutex);
|
||||||
return OK;
|
return OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
sem_post(&precorder->sem);
|
pthread_mutex_unlock(&precorder->mutex);
|
||||||
|
|
||||||
/* Notify the recordback thread that it needs to cancel the recordback */
|
/* Notify the recordback thread that it needs to cancel the recordback */
|
||||||
|
|
||||||
@ -976,7 +974,7 @@ FAR struct nxrecorder_s *nxrecorder_create(void)
|
|||||||
precorder->session = NULL;
|
precorder->session = NULL;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
sem_init(&precorder->sem, 0, 1);
|
pthread_mutex_init(&precorder->mutex, NULL);
|
||||||
|
|
||||||
return precorder;
|
return precorder;
|
||||||
}
|
}
|
||||||
@ -999,50 +997,29 @@ void nxrecorder_release(FAR struct nxrecorder_s *precorder)
|
|||||||
int refcount;
|
int refcount;
|
||||||
FAR void *value;
|
FAR void *value;
|
||||||
|
|
||||||
/* Grab the semaphore */
|
pthread_mutex_lock(&precorder->mutex);
|
||||||
|
|
||||||
while (sem_wait(&precorder->sem) < 0)
|
|
||||||
{
|
|
||||||
int errcode = errno;
|
|
||||||
DEBUGASSERT(errcode > 0);
|
|
||||||
|
|
||||||
if (errcode != EINTR)
|
|
||||||
{
|
|
||||||
auderr("ERROR: sem_wait failed: %d\n", errcode);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Check if there was a previous thread and join it if there was */
|
/* Check if there was a previous thread and join it if there was */
|
||||||
|
|
||||||
if (precorder->record_id != 0)
|
if (precorder->record_id != 0)
|
||||||
{
|
{
|
||||||
sem_post(&precorder->sem);
|
pthread_mutex_unlock(&precorder->mutex);
|
||||||
pthread_join(precorder->record_id, &value);
|
pthread_join(precorder->record_id, &value);
|
||||||
precorder->record_id = 0;
|
precorder->record_id = 0;
|
||||||
|
|
||||||
while (sem_wait(&precorder->sem) < 0)
|
pthread_mutex_lock(&precorder->mutex);
|
||||||
{
|
|
||||||
int errcode = errno;
|
|
||||||
DEBUGASSERT(errcode > 0);
|
|
||||||
|
|
||||||
if (errcode != EINTR)
|
|
||||||
{
|
|
||||||
auderr("ERROR: sem_wait failed: %d\n", errcode);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Reduce the reference count */
|
/* Reduce the reference count */
|
||||||
|
|
||||||
refcount = precorder->crefs--;
|
refcount = precorder->crefs--;
|
||||||
sem_post(&precorder->sem);
|
pthread_mutex_unlock(&precorder->mutex);
|
||||||
|
|
||||||
/* If the ref count *was* one, then free the context */
|
/* If the ref count *was* one, then free the context */
|
||||||
|
|
||||||
if (refcount == 1)
|
if (refcount == 1)
|
||||||
{
|
{
|
||||||
|
pthread_mutex_destroy(&precorder->mutex);
|
||||||
free(precorder);
|
free(precorder);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1061,22 +1038,10 @@ void nxrecorder_release(FAR struct nxrecorder_s *precorder)
|
|||||||
|
|
||||||
void nxrecorder_reference(FAR struct nxrecorder_s *precorder)
|
void nxrecorder_reference(FAR struct nxrecorder_s *precorder)
|
||||||
{
|
{
|
||||||
/* Grab the semaphore */
|
pthread_mutex_lock(&precorder->mutex);
|
||||||
|
|
||||||
while (sem_wait(&precorder->sem) < 0)
|
|
||||||
{
|
|
||||||
int errcode = errno;
|
|
||||||
DEBUGASSERT(errcode > 0);
|
|
||||||
|
|
||||||
if (errcode != EINTR)
|
|
||||||
{
|
|
||||||
auderr("ERROR: sem_wait failed: %d\n", errcode);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Increment the reference count */
|
/* Increment the reference count */
|
||||||
|
|
||||||
precorder->crefs++;
|
precorder->crefs++;
|
||||||
sem_post(&precorder->sem);
|
pthread_mutex_unlock(&precorder->mutex);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user