system/media: replace sem lock with pthread_mutex

Signed-off-by: ligd <liguiding1@xiaomi.com>
This commit is contained in:
ligd 2023-01-03 19:28:25 +08:00 • committed by Xiang Xiao
parent 44d0642334
commit 0e06cfeaec
7 changed files with 93 additions and 261 deletions

View file

@ -29,7 +29,6 @@
#include <mqueue.h>
#include <pthread.h>
#include <semaphore.h>
/****************************************************************************
* Pre-processor Definitions
@ -43,30 +42,30 @@
struct nxlooper_s
{
int loopstate; /* Current looper test state */
int recorddev_fd; /* File descriptor of active
* record device */
char recorddev[CONFIG_NAME_MAX]; /* Preferred record device */
int playdev_fd; /* File descriptor of active
* play device */
char playdev[CONFIG_NAME_MAX]; /* Preferred loopback device */
int crefs; /* Number of references */
sem_t sem; /* Thread sync semaphore */
char mqname[16]; /* Name of play message queue */
mqd_t mq; /* Message queue for the
* loopthread */
pthread_t loop_id; /* Thread ID of the loopthread */
int loopstate; /* Current looper test state */
int recorddev_fd; /* File descriptor of active
* record device */
char recorddev[CONFIG_NAME_MAX]; /* Preferred record device */
int playdev_fd; /* File descriptor of active
* play device */
char playdev[CONFIG_NAME_MAX]; /* Preferred loopback device */
int crefs; /* Number of references */
pthread_mutex_t mutex; /* Thread sync mutex */
char mqname[16]; /* Name of play message queue */
mqd_t mq; /* Message queue for the
* loopthread */
pthread_t loop_id; /* Thread ID of the loopthread */
#ifdef CONFIG_AUDIO_MULTI_SESSION
FAR void *pplayses; /* Session assignment from device */
FAR void *pplayses; /* Session assignment from device */
#endif
#ifdef CONFIG_AUDIO_MULTI_SESSION
FAR void *precordses; /* Session assignment from device */
FAR void *precordses; /* Session assignment from device */
#endif
#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
};

View file

@ -29,7 +29,6 @@
#include <mqueue.h>
#include <pthread.h>
#include <semaphore.h>
/****************************************************************************
* Pre-processor Definitions
@ -51,34 +50,34 @@ struct nxplayer_dec_ops_s
struct nxplayer_s
{
int state; /* Current player state */
int dev_fd; /* File descriptor of active device */
mqd_t mq; /* Message queue for the playthread */
char mqname[16]; /* Name of our message queue */
pthread_t play_id; /* Thread ID of the playthread */
int crefs; /* Number of references to the player */
sem_t sem; /* Thread sync semaphore */
int fd; /* File descriptor of open file */
int state; /* Current player state */
int dev_fd; /* File descriptor of active device */
mqd_t mq; /* Message queue for the playthread */
char mqname[16]; /* Name of our message queue */
pthread_t play_id; /* Thread ID of the playthread */
int crefs; /* Number of references to the player */
pthread_mutex_t mutex; /* Thread sync mutex */
int fd; /* File descriptor of open file */
#ifdef CONFIG_NXPLAYER_INCLUDE_PREFERRED_DEVICE
char prefdevice[CONFIG_NAME_MAX]; /* Preferred audio device */
int prefformat; /* Formats supported by preferred device */
int preftype; /* Types supported by preferred device */
char prefdevice[CONFIG_NAME_MAX]; /* Preferred audio device */
int prefformat; /* Formats supported by preferred device */
int preftype; /* Types supported by preferred device */
#endif
#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
#ifdef CONFIG_AUDIO_MULTI_SESSION
FAR void *session; /* Session assignment from device */
FAR void *session; /* Session assignment from device */
#endif
#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
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
#ifndef CONFIG_AUDIO_EXCLUDE_TONE
uint16_t treble; /* Treble as a whole % */
uint16_t bass; /* Bass as a whole % */
uint16_t treble; /* Treble as a whole % */
uint16_t bass; /* Bass as a whole % */
#endif
FAR const struct nxplayer_dec_ops_s *ops;

View file

@ -29,7 +29,6 @@
#include <mqueue.h>
#include <pthread.h>
#include <semaphore.h>
/****************************************************************************
* Pre-processor Definitions
@ -43,17 +42,17 @@
struct nxrecorder_s
{
int state; /* Current recorder state */
int dev_fd; /* File descriptor of active device */
mqd_t mq; /* Message queue for the recordthread */
char mqname[16]; /* Name of our message queue */
pthread_t record_id; /* Thread ID of the recordthread */
int crefs; /* Number of references to the recorder */
sem_t sem; /* Thread sync semaphore */
int fd; /* File descriptor of open file */
char device[CONFIG_NAME_MAX]; /* Preferred audio device */
int state; /* Current recorder state */
int dev_fd; /* File descriptor of active device */
mqd_t mq; /* Message queue for the recordthread */
char mqname[16]; /* Name of our message queue */
pthread_t record_id; /* Thread ID of the recordthread */
int crefs; /* Number of references to the recorder */
pthread_mutex_t mutex; /* Thread sync mutex */
int fd; /* File descriptor of open file */
char device[CONFIG_NAME_MAX]; /* Preferred audio device */
#ifdef CONFIG_AUDIO_MULTI_SESSION
FAR void *session; /* Session assignment from device */
FAR void *session; /* Session assignment from device */
#endif
};