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

三、参考

相关内容

热门资讯

带娃四川成都纯玩六日游花费多少... 家人们,四川一直以来就是旅游界的“顶流”,尤其是成都,这座“天府之国”,不仅有着深厚的历史文化底蕴,...
熊园|旅途中的故事 在回家的高铁上,遇到了两件事情,这节车厢太诡异了: 01 一个男人占了别人的座位,后来座位主人来了,...
恩施报团5日游具体花销,恩施旅... 前段时间我和朋友计划去恩施旅行时,最头疼的就是行程规划和预算控制。刷遍全网攻略后,突然刷到一篇游记里...
抓住新津这个秋天,去白鹤滩解锁... ️一场秋雨一场寒 你们的“天气情报员”已上线~ 本周天气主打 “阴晴不定+雨水随机播放” 重新开放的...
带小孩广西桂林五天游预算多少?... 桂林,这座被无数文人墨客赞美的山水之城,以其“山青、水秀、洞奇、石美”的独特魅力,成为了亲子游的绝佳...
四川成都旅游五天需要多少钱?省... 在快节奏生活的当下,旅游成了人们逃离喧嚣、放松身心的绝佳途径。四川,宛如一颗璀璨的明珠,镶嵌在中国的...
四川旅游5天景点推荐,成都五日... 四川旅游5天景点推荐,成都五日游人均需要多少费用 嘿,宝子们!是不是心里早就琢磨着去哪儿痛痛快快玩一...
祁连山下:张掖丹霞的调色盘与雪... 在祁连山巍峨雪峰的环抱下,张掖丹霞与雪山牧场共同谱写着一曲冰与火的自然交响诗。这片被《中国国家地理》...
重庆5日旅游攻略详细,国庆期间... 计划一场说走就走的旅行,目的地锁定为充满魔幻色彩的山城——重庆。作为一座融合了现代都市风貌与悠久历史...
和朋友到广东玩4天3晚大概多少... 宝子们,暑假到啦,是不是正愁去哪儿自驾游呢?那潮汕绝对是个超棒的选择!潮汕地区位于广东东部沿海,这里...
报团去广西桂林旅游5天要花多少... 桂林,这座风景如画的城市,以其独特的山水风光闻名于世。这里山清水秀,洞奇石美,被誉为“山水甲天下”。...
膜结构游客中心出入口造价 膜结构游客中心出入口价格根据具体工程要求和材料成本而有所不同。以下简要介绍了膜结构游客中心出入口的价...
国内旅行社行业的新篇章:在变与... 近年来,中国国内旅行社行业正在经历一次深刻的变革——由“量”的恢复迈向“质”的提升,由“传统模式”转...
“藏舞”快闪松花江畔 9月14日14时许,哈尔滨人民防洪胜利纪念塔广场出现了十余名身着藏族传统服装的年轻人,他们伴随着藏族...
山西·忻州“长城两边是故乡”文... 《山西日报》(2025年09月16日 第03版) 长城不语阅千载,黄河有声话故乡。9月11日,20...
北京4天3晚美食推荐,北京四日... 北京不仅有着雄伟壮观的皇家宫殿、历史悠久的文化古迹,还有着繁华的都市风貌和丰富的现代文化活动。从古老...
河北景区分账系统,智慧景区门票... 在京津冀协同发展的战略背景下,河北文旅产业正以“全域旅游”和“智慧化”为双轮驱动,加速构建现代化旅游...
五台山景区2025年国家网络安... 王丹 吕佳豪 五台山管委会 9月15日,以“网络安全为人民,网络安全靠人民”为主题的2025年国...
民航联盟:新疆机场集团吐鲁番机... 截至9月4日,新疆机场集团吐鲁番交河机场旅客吞吐量突破60万人次,这一数据不仅刷新了机场通航以来的年...
老年人旅游旺季将至,如何货比三... 暑期结束后,旅游市场有所降温。不过,旅游市场的淡季却是老年人旅游的旺季,很多老年人计划在秋高气爽、价...