【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举例

三、参考

相关内容

热门资讯

北京环球度假区携手乌镇 专属片... 本文转自:人民网-北京频道10月16日,第十二届乌镇戏剧节盛大启幕,北京环球度假区第三次走进这座充满...
旺酱酒业给您科普:金酱酒如何品... 酱香型白酒,作为中国白酒文化中的瑰宝,以其独特的风味和深厚的文化底蕴,深受众多酒友的喜爱。金酱酒作为...
东坡肉,我妈的秘制配方! 一、为什么要做东坡肉? 因为人生需要一点“罪恶感”的幸福!肥瘦相间的五花肉在锅里咕嘟咕嘟,冰糖炒出琥...
螺蛳粉店配菜供应首选企业 螺蛳粉店配菜供应首选企业:为何粉店宝小程序是理想选择 在当今竞争激烈的餐饮市场中,螺蛳粉店的成功不...
西津一桌菜,鱼生酸嘢最诱人 西津一桌菜,鱼生酸嘢最诱人。 录制:刘国雄。 过节去南宁西津生态鱼生馆吃饭,点了一桌菜,白切鸭、海鲜...
骑行太行,邂逅好山好水好生活 骑行太行,邂逅好山好水好生活 ——体验活力太行·邢台市信都区抗大路 9月27日,参加2025中国公...
原创 农... 在远离喧嚣的乡村角落,一位年迈的大爷正忙碌着。他手中拿着一根竹签,熟练地将糯米和红豆混合,再将其包裹...
原创 农... 标题:农村大姐卖“稀罕小吃”5元2个,很多人没见过,一出摊就遭哄抢! 在这个快节奏的时代,人们对于...
原创 农... 在广袤的田野间,有一种小吃以其独特的风味和亲民的价格,成为了农村餐桌上的常客。它就是——玉米饼。 ...
石台牯牛降景区闭园升级改造创5... 10月16日,池州石台牯牛降景区正式开启“闭园升级模式”。这场为期1-2个月的改造,是该景区冲刺国家...
原创 农... 标题:农村这种野菜,口感脆嫩清香,在古代是宫廷佳肴,你吃过吗? 在遥远的乡村角落,生长着一种不起眼...
原创 原... 标题:原来蘑菇和它才是天生一对,放在一起炒,简直能鲜掉眉毛! 在美食的世界里,每一种食材都有其独特...
原创 儿... 标题:儿子隔三差五要吃这早餐,五块钱做一锅他自己吃个精光,百吃不厌。 在这个快节奏的时代,我们总是...
原创 蒸... 导语:蒸包子时,到底蒸几分钟?牢记4个要点,包子个个油光白净,不塌馅不开裂,松软又筋道! 香喷喷的大...
原创 十... 在广东,美食不仅仅是味蕾的享受,更是文化的传承。粤菜,作为中国四大菜系之一,以其独特的烹饪技艺和深厚...
原创 去... 标题:去乡下吃酒席,乡亲们带锅上阵,我默默放下了筷子,网友:太霸气 在那个被岁月温柔包裹的小镇,每...
原创 农... 标题:农村宴席,看着不好看,吃着走不动! 在乡村的烟火气中,宴席不仅仅是一场味蕾的盛宴,更是一次文...
原创 8... 在城市的喧嚣中,有这样一位80岁的奶奶,她选择在街边摆摊,卖着一种“特别小吃”。每当她的小摊一开张,...
安徽全椒:采菊襄水畔 悠然见南... 本文转自:人民网-安徽频道各式菊花拼起绚丽的图片。人民网记者 张俊摄 人民网滁州10月19日电 (张...