【esp32-adf】pipeline源码分析
admin
2024-04-14 12:25:53
0

文章目录

  • 一、pipeline介绍
    • 1.1 介绍
    • 1.2 代码结构
  • 二、pipleline源码分析
    • 2.1 audio_element
      • 2.1.1 数据结构
      • 2.1.2 api
        • 2.1.2.1 audio_element_init
        • 2.1.2.2 audio_element_setdata
        • 2.1.2.3 audio_element_run
        • 2.1.2.4 audio_element_task
        • 2.1.2.5 audio_element_input
        • 2.1.2.6 audio_element_output
        • 2.1.2.7 audio_element_cmd_send
    • 2.2 audio_pipeline
      • 2.2.1 数据结构
      • 2.2.2 api
        • 2.2.2.1 audio_pipeline_register
        • 2.2.2.2 audio_pipeline_link
        • 2.2.2.3 audio_pipeline_run
    • 2.3 audio_event_iface
      • 2.3.1 数据结构
      • 2.3.2 api
        • 2.3.2.1 audio_event_iface_waiting_cmd_msg
        • 2.3.2.2 audio_event_iface_cmd
    • 2.4 主要的数据处理流程
      • 2.4.1
    • 2.5 pipeline处理流程--以play_bt_music_example举例
  • 三、参考

一、pipeline介绍

1.1 介绍

1.2 代码结构

二、pipleline源码分析

2.1 audio_element

2.1.1 数据结构

struct audio_element {/* Functions/RingBuffers */el_io_func                  open;ctrl_func                   seek;process_func                process;el_io_func                  close;el_io_func                  destroy;io_type_t                   read_type;union {ringbuf_handle_t        input_rb;io_callback_t           read_cb;} in;io_type_t                   write_type;union {ringbuf_handle_t        output_rb;io_callback_t           write_cb;} out;audio_multi_rb_t            multi_in;audio_multi_rb_t            multi_out;/* Properties */volatile bool               is_open;audio_element_state_t       state;events_type_t               events_type;audio_event_iface_handle_t  iface_event;audio_callback_t            callback_event;int                         buf_size;char                        *buf;char                        *tag;int                         task_stack;int                         task_prio;int                         task_core;xSemaphoreHandle            lock;audio_element_info_t        info;audio_element_info_t        *report_info;bool                        stack_in_ext;audio_thread_t              audio_thread;/* PrivateData */void                        *data;EventGroupHandle_t          state_event;int                         input_wait_time;int                         output_wait_time;int                         out_buf_size_expect;int                         out_rb_size;volatile bool               is_running;volatile bool               task_run;volatile bool               stopping;
};

2.1.2 api

2.1.2.1 audio_element_init

audio_element_handle_t audio_element_init(audio_element_cfg_t *config)

audio_element_init用上层传入的audio_element_cfg_t去初始化audio_element的成员变量,包括audio_element的open、process、close、destroy、seek方法,audio_element任务的属性。

2.1.2.2 audio_element_setdata

esp_err_t audio_element_setdata(audio_element_handle_t el, void *data)

audio_element_setdata用于将对象存入audio_element的私有数据,用作对象的上下文。

2.1.2.3 audio_element_run

esp_err_t audio_element_run(audio_element_handle_t el)

audio_element_run创建一个Task用来处理audio_element的专有任务。

2.1.2.4 audio_element_task

void audio_element_task(void *pv)

audio_element_task是audio_element_run创建的audio_element的处理专有业务的专有任务。调用audio_event_iface_waiting_cmd_msg等待命令,接受到命令后通过audio_element_process_running调用注册的process做element的业务处理。

2.1.2.5 audio_element_input

audio_element_err_t audio_element_input(audio_element_handle_t el, char *buffer, int wanted_size)

2.1.2.6 audio_element_output

audio_element_err_t audio_element_output(audio_element_handle_t el, char *buffer, int write_size)

audio_element_output将audio_element的输出放入输出ringbuffer。

2.1.2.7 audio_element_cmd_send

esp_err_t audio_element_cmd_send(audio_element_handle_t el, audio_element_msg_cmd_t cmd)

audio_element_cmd_send通过audio_element的iface_event向audio_elment_task发送命令,支持的命令的如下:

typedef enum {AEL_MSG_CMD_NONE                = 0,// AEL_MSG_CMD_ERROR               = 1,AEL_MSG_CMD_FINISH              = 2,AEL_MSG_CMD_STOP                = 3,AEL_MSG_CMD_PAUSE               = 4,AEL_MSG_CMD_RESUME              = 5,AEL_MSG_CMD_DESTROY             = 6,// AEL_MSG_CMD_CHANGE_STATE        = 7,AEL_MSG_CMD_REPORT_STATUS       = 8,AEL_MSG_CMD_REPORT_MUSIC_INFO   = 9,AEL_MSG_CMD_REPORT_CODEC_FMT    = 10,AEL_MSG_CMD_REPORT_POSITION     = 11,
} audio_element_msg_cmd_t;

2.2 audio_pipeline

2.2.1 数据结构

2.2.2 api

2.2.2.1 audio_pipeline_register

esp_err_t audio_pipeline_register(audio_pipeline_handle_t pipeline, audio_element_handle_t el, const char *name)

audio_pipeline_register将audio_element注册到pipeline,底层通过STAILQ_INSERT_TAIL向el_list插入链表元素。

2.2.2.2 audio_pipeline_link

esp_err_t audio_pipeline_link(audio_pipeline_handle_t pipeline, const char *link_tag[], int link_num)

在audio_pipeline_link中,遍历pipeline的el_list链表,将el_list链表上的audio_element的输入和输出的ringbuffer连接在一起。

2.2.2.3 audio_pipeline_run

esp_err_t audio_pipeline_run(audio_pipeline_handle_t pipeline)

audio_pipeline_run调用audio_element_run将el_list链表上的audio_element运行起来,这些audio_element是在audio_pipeline_register时插入el_list链表的元素,audio_element_run的底层是创建freeRTOS的Task,各个audio_element独立的在自己的Task里处理业务。

2.3 audio_event_iface

2.3.1 数据结构

struct audio_event_iface {QueueHandle_t               internal_queue;QueueHandle_t               external_queue;QueueSetHandle_t            queue_set;int                         internal_queue_size;int                         external_queue_size;int                         queue_set_size;audio_event_iface_list_t    listening_queues;void                        *context;on_event_iface_func         on_cmd;int                         wait_time;int                         type;
};

2.3.2 api

2.3.2.1 audio_event_iface_waiting_cmd_msg

esp_err_t audio_event_iface_waiting_cmd_msg(audio_event_iface_handle_t evt)

audio_event_iface_waiting_cmd_msg通过等待audio_event_iface_handle_t的internal_queue来处理事件。

2.3.2.2 audio_event_iface_cmd

esp_err_t audio_event_iface_cmd(audio_event_iface_handle_t evt, audio_event_iface_msg_t *msg)

audio_event_iface_cmd通过发送internal_queue触发等待internal_queue的任务。

2.4 主要的数据处理流程

2.4.1

2.5 pipeline处理流程–以play_bt_music_example举例

三、参考

相关内容

热门资讯

四川5天4晚纯玩跟团游,本地团... 我一直对四川心心念念,那片神奇的土地就像一块巨大的磁石,吸引着我。四川,有“峨眉天下秀”的峨眉山,云...
和爸妈到重庆5天自由行花多少钱... 重庆,这座充满魔幻色彩的城市,以其独特的地形、丰富的美食和热情的人民吸引着无数游客。作为一名旅行爱好...
西安那里能滑雪 西安那里能滑雪楼上的 谢啦~~哇^_^
少年闰土课文里西瓜的危险经历指... 少年闰土课文里西瓜的危险经历指什么?……“不是。走路的人口渴了摘一个瓜吃,我们这里是不算偷的。要管的...
对你的思念是一天又一天是什么歌... 对你的思念是一天又一天是什么歌是谁唱的黄品源:你怎么舍得我难过歌曲:你怎么舍得我难过歌手:黄品源 专...
能告诉我我的美丽日记哪个面膜美... 能告诉我我的美丽日记哪个面膜美白效果好?有好多系列啊,不知道怎么选择了,真的有那么好用吗各位亲?注意...
北京过春节有什么习俗呢? 北京过春节有什么习俗呢?吃喝玩乐都有。春节还有一些习俗,比如吃饺子、贴春联。哇,你知道的还真多啊。
女孩是一个不会表达的人,男孩每... 女孩是一个不会表达的人,男孩每天晚上都会让女孩说我想你了,女孩就不愿意说,男孩会想尽办法让女孩说?这...
谁能帮我翻译一下。繁体字不认识 谁能帮我翻译一下。繁体字不认识谁能帮我翻译一下。繁体字不认识阳刚义德蹈星广自上而下:阳刚义德韬略广这...
引出和引出来意思完全一样吗? 引出和引出来意思完全一样吗?引出和引出来意思虽然说大体一样但是也不完全相同,引出可以说是引出其他的东...
如何安慰生病的闺蜜 如何安慰生病的闺蜜 任何安慰的话都没用,陪伴在身边才是最好的安慰
变形金刚4 MP3 变形金刚4 MP3有没有人把整个视频的声音都录下来了,或者精彩片段也很好,能分享下吗!O(∩_∩)O...
12岁文爱马拉丁舞比赛画面曝光... 12岁文爱马拉丁舞比赛画面曝光,女生练拉丁舞有何好处?好处:1.练拉丁的女孩子身材很好,气质也好;2...
父亲将废物儿子赶出家门,没想到... 父亲将废物儿子赶出家门,没想到几年后收购父亲房产?求电影名父亲将你废物的儿子赶出了家门口,没想到几年...
09年洛阳牡丹节从什么时候开始... 09年洛阳牡丹节从什么时候开始?09年洛阳牡丹节各公园都从几号开始收费啊?看牡丹还是要到国花圆
圆缺是什么 圆缺是什么表示任何事物都有号的时候也有坏的时候这个是数学题?那么应该是打错字了吧,是圆圈吧....如...
请帮忙起个男孩名吧 姓任 请帮忙起个男孩名吧 姓任任梓琪 任梓涵 任梓宣
我想知道一首老歌的歌名及演唱者... 我想知道一首老歌的歌名及演唱者,歌的开头是这样唱的:是《蒙娜丽莎的眼泪》么…歌曲:蒙娜丽莎 歌手:...
一个心一个患是什么成语? 一个心一个患是什么成语?1、一心形里边一个患字是成语心腹大患。2、心腹大患,汉语成语,拼音是xīn ...
谁有好看的小说来几本 谁有好看的小说来几本庶女有毒很好看啊