Skip to content

Commit

Permalink
Pipeline: move struct definition and inline function to header file
Browse files Browse the repository at this point in the history
This is a clean up, purpose is declutter headers, toml files,
Readme.md etc per module basis, since today everything is scattered
in current code base.

Signed-off-by: Baofeng Tian <baofeng.tian@intel.com>
  • Loading branch information
btian1 committed Dec 21, 2023
1 parent 60212cf commit 96d5068
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 64 deletions.
64 changes: 0 additions & 64 deletions src/audio/pipeline/pipeline-graph.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,73 +34,9 @@ DECLARE_SOF_RT_UUID("pipe", pipe_uuid, 0x4e934adb, 0xb0ec, 0x4d33,

DECLARE_TR_CTX(pipe_tr, SOF_UUID(pipe_uuid), LOG_LEVEL_INFO);

/* number of pipeline stream metadata objects we export in mailbox */
#define PPL_POSN_OFFSETS \
(MAILBOX_STREAM_SIZE / sizeof(struct sof_ipc_stream_posn))

/* lookup table to determine busy/free pipeline metadata objects */
struct pipeline_posn {
bool posn_offset[PPL_POSN_OFFSETS]; /**< available offsets */
struct k_spinlock lock; /**< lock mechanism */
};
/* the pipeline position lookup table */
static SHARED_DATA struct pipeline_posn pipeline_posn_shared;

/**
* \brief Retrieves pipeline position structure.
* \return Pointer to pipeline position structure.
*/
static inline struct pipeline_posn *pipeline_posn_get(void)
{
return sof_get()->pipeline_posn;
}

/**
* \brief Retrieves first free pipeline position offset.
* \param[in,out] posn_offset Pipeline position offset to be set.
* \return Error code.
*/
static inline int pipeline_posn_offset_get(uint32_t *posn_offset)
{
struct pipeline_posn *pipeline_posn = pipeline_posn_get();
int ret = -EINVAL;
uint32_t i;
k_spinlock_key_t key;

key = k_spin_lock(&pipeline_posn->lock);

for (i = 0; i < PPL_POSN_OFFSETS; ++i) {
if (!pipeline_posn->posn_offset[i]) {
*posn_offset = i * sizeof(struct sof_ipc_stream_posn);
pipeline_posn->posn_offset[i] = true;
ret = 0;
break;
}
}


k_spin_unlock(&pipeline_posn->lock, key);

return ret;
}

/**
* \brief Frees pipeline position offset.
* \param[in] posn_offset Pipeline position offset to be freed.
*/
static inline void pipeline_posn_offset_put(uint32_t posn_offset)
{
struct pipeline_posn *pipeline_posn = pipeline_posn_get();
int i = posn_offset / sizeof(struct sof_ipc_stream_posn);
k_spinlock_key_t key;

key = k_spin_lock(&pipeline_posn->lock);

pipeline_posn->posn_offset[i] = false;

k_spin_unlock(&pipeline_posn->lock, key);
}

void pipeline_posn_init(struct sof *sof)
{
sof->pipeline_posn = platform_shared_get(&pipeline_posn_shared,
Expand Down
65 changes: 65 additions & 0 deletions src/include/sof/audio/pipeline.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include <rtos/spinlock.h>
#include <sof/audio/pipeline-trace.h>
#include <ipc/topology.h>
#include <ipc/stream.h>
#include <user/trace.h>
#include <errno.h>
#include <stdbool.h>
Expand Down Expand Up @@ -49,6 +50,16 @@ struct ipc_msg;
#define PPL_DIR_DOWNSTREAM 0
#define PPL_DIR_UPSTREAM 1

/* number of pipeline stream metadata objects we export in mailbox */
#define PPL_POSN_OFFSETS \
(MAILBOX_STREAM_SIZE / sizeof(struct sof_ipc_stream_posn))

/* lookup table to determine busy/free pipeline metadata objects */
struct pipeline_posn {
bool posn_offset[PPL_POSN_OFFSETS]; /**< available offsets */
struct k_spinlock lock; /**< lock mechanism */
};

/*
* Audio pipeline.
*/
Expand Down Expand Up @@ -429,4 +440,58 @@ void pipeline_xrun(struct pipeline *p, struct comp_dev *dev, int32_t bytes);
*/
int pipeline_xrun_set_limit(struct pipeline *p, uint32_t xrun_limit_usecs);

/**
* \brief Retrieves pipeline position structure.
* \return Pointer to pipeline position structure.
*/
static inline struct pipeline_posn *pipeline_posn_get(void)
{
return sof_get()->pipeline_posn;
}

/**
* \brief Retrieves first free pipeline position offset.
* \param[in,out] posn_offset Pipeline position offset to be set.
* \return Error code.
*/
static inline int pipeline_posn_offset_get(uint32_t *posn_offset)
{
struct pipeline_posn *pipeline_posn = pipeline_posn_get();
int ret = -EINVAL;
uint32_t i;
k_spinlock_key_t key;

key = k_spin_lock(&pipeline_posn->lock);

for (i = 0; i < PPL_POSN_OFFSETS; ++i) {
if (!pipeline_posn->posn_offset[i]) {
*posn_offset = i * sizeof(struct sof_ipc_stream_posn);
pipeline_posn->posn_offset[i] = true;
ret = 0;
break;
}
}

k_spin_unlock(&pipeline_posn->lock, key);

return ret;
}

/**
* \brief Frees pipeline position offset.
* \param[in] posn_offset Pipeline position offset to be freed.
*/
static inline void pipeline_posn_offset_put(uint32_t posn_offset)
{
struct pipeline_posn *pipeline_posn = pipeline_posn_get();
int i = posn_offset / sizeof(struct sof_ipc_stream_posn);
k_spinlock_key_t key;

key = k_spin_lock(&pipeline_posn->lock);

pipeline_posn->posn_offset[i] = false;

k_spin_unlock(&pipeline_posn->lock, key);
}

#endif /* __SOF_AUDIO_PIPELINE_H__ */

0 comments on commit 96d5068

Please sign in to comment.