{"id":71100,"date":"2026-02-03T07:48:45","date_gmt":"2026-02-02T23:48:45","guid":{"rendered":"https:\/\/www.wsisp.com\/helps\/71100.html"},"modified":"2026-02-03T07:48:45","modified_gmt":"2026-02-02T23:48:45","slug":"android%e9%9f%b3%e9%a2%91%e7%b3%bb%e5%88%9710-audioflinger%e4%bb%a3%e7%a0%81%e8%a7%a3%e6%9e%90","status":"publish","type":"post","link":"https:\/\/www.wsisp.com\/helps\/71100.html","title":{"rendered":"Android\u97f3\u9891\u7cfb\u5217(10)-AudioFlinger\u4ee3\u7801\u89e3\u6790"},"content":{"rendered":"<p>\u76ee\u5f55<\/p>\n<p id=\"1.%20%E7%AE%80%E8%BF%B0-toc\" style=\"margin-left:40px\">1. \u7b80\u8ff0<\/p>\n<p id=\"2.%20%E5%88%9D%E5%A7%8B%E5%8C%96-toc\" style=\"margin-left:40px\">2. \u521d\u59cb\u5316<\/p>\n<p id=\"3.%E5%AF%B9%E5%A4%96%E6%8E%A5%E5%8F%A3-toc\" style=\"margin-left:40px\">3.\u5bf9\u5916\u63a5\u53e3<\/p>\n<p id=\"4.%20%E5%86%85%E9%83%A8%E6%A0%B8%E5%BF%83%E7%B1%BB-toc\" style=\"margin-left:40px\">4. \u5185\u90e8\u6838\u5fc3\u7c7b<\/p>\n<p id=\"%C2%A04.1%20AudioFlinger%20%E7%B1%BB-toc\" style=\"margin-left:80px\">\u00a04.1 AudioFlinger \u7c7b<\/p>\n<p id=\"%C2%A04.2%20Thread%20%E7%B1%BB%E4%BD%93%E7%B3%BB-toc\" style=\"margin-left:80px\">\u00a04.2 Thread \u7c7b\u4f53\u7cfb<\/p>\n<p id=\"%C2%A04.3%20Track%20%E7%B1%BB%E4%BD%93%E7%B3%BB-toc\" style=\"margin-left:80px\">\u00a04.3 Track \u7c7b\u4f53\u7cfb<\/p>\n<p id=\"%C2%A05.%20%E6%A0%B8%E5%BF%83%E6%B5%81%E7%A8%8B%E5%88%86%E6%9E%90-toc\" style=\"margin-left:40px\">\u00a05. \u6838\u5fc3\u6d41\u7a0b\u5206\u6790<\/p>\n<p id=\"%C2%A05.1%20%E5%88%9B%E5%BB%BA%20Track%20(createTrack)-toc\" style=\"margin-left:80px\">\u00a05.1 \u521b\u5efa Track (createTrack)<\/p>\n<p id=\"%C2%A05.2%20%E5%9B%9E%E6%94%BE%E7%BA%BF%E7%A8%8B%E5%BE%AA%E7%8E%AF%20(MixerThread%3A%3AthreadLoop)-toc\" style=\"margin-left:80px\">\u00a05.2 \u56de\u653e\u7ebf\u7a0b\u5faa\u73af (MixerThread::threadLoop)<\/p>\n<p id=\"%C2%A05.3%20%E5%BA%8F%E5%88%97%E5%9B%BE%20(UML)-toc\" style=\"margin-left:80px\">\u00a05.3 \u5e8f\u5217\u56fe (UML)<\/p>\n<p id=\"%C2%A06.%20%E6%80%BB%E7%BB%93-toc\" style=\"margin-left:40px\">\u00a06. \u603b\u7ed3<\/p>\n<hr id=\"hr-toc\" \/>\n<h3 id=\"1.%20%E7%AE%80%E8%BF%B0\" style=\"margin-left:0px;margin-right:0px\">1. \u7b80\u8ff0<\/h3>\n<p style=\"margin-left:0;margin-right:0\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 AudioFlinger&#xff0c;\u7b80\u79f0AF&#xff0c;\u5b83 \u662f Android \u97f3\u9891\u7cfb\u7edf\u7684\u6838\u5fc3\u670d\u52a1&#xff0c;\u627f\u8f7d\u7740\u97f3\u9891\u6df7&#xff08;Mixing&#xff09;\u3001 \u97f3\u9891\u8def\u7531&#xff08;Routing&#xff09;\u4ee5\u53ca\u7ba1\u7406\u97f3\u9891\u8f93\u51fa\u8f93\u5165\u6d41&#xff08;Stream&#xff09;\u7b49\u5173\u952e\u804c\u8d23&#xff0c;\u662f\u627f\u4e0a\u542f\u4e0b\u7684\u5173\u952e\u89d2\u8272\u3002\u5b83\u4f4d\u4e8e Native \u5c42&#xff0c;\u4f5c\u4e3a AudioSystem \u7684\u4e00\u90e8\u5206&#xff0c;\u5411\u4e0a\u63a5\u6536\u6765\u81ea Application\/ Framework (\u5982 AudioTrack, AudioRecord) \u7684\u8bf7\u6c42&#xff0c;\u5411\u4e0b\u901a\u8fc7 Audio HAL (Hardware Abstraction Layer) \u9a71\u52a8\u786c\u4ef6&#xff0c;\u5982\u56fe1\u6240\u793a&#xff1a;<\/p>\n<ul>\n<li>\u5411\u4e0a&#xff1a;\u4e3a\u5e94\u7528\u5c42&#xff08;\u5982\u00a0AudioTrack\/AudioRecord&#xff09;\u63d0\u4f9b\u7edf\u4e00\u7684\u97f3\u9891\u6570\u636e\u8bfb\u5199\u63a5\u53e3&#xff1b;<\/li>\n<li>\u5411\u4e0b&#xff1a;\u901a\u8fc7 HAL \u5c42&#xff08;Audio HAL&#xff09;\u4e0e\u5e95\u5c42\u786c\u4ef6&#xff08;\u58f0\u5361\u3001DSP\u3001Codec&#xff09;\u4ea4\u4e92&#xff1b;<\/li>\n<li>\u6a2a\u5411&#xff1a;\u4e0e\u00a0AudioPolicyService&#xff08;APS&#xff09;\u00a0\u534f\u540c\u5b8c\u6210\u8def\u7531\u51b3\u7b56\u3001\u8bbe\u5907\u5207\u6362\u3001\u97f3\u91cf\u7b56\u7565\u7b49\u3002<\/li>\n<\/ul>\n<p style=\"margin-left:0;margin-right:0\">\n<p style=\"margin-left:0;margin-right:0;text-align:center\"><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"246\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/02\/20260202234841-698137d9b0e1c.png\" width=\"371\" \/><\/p>\n<p style=\"margin-left:0;margin-right:0;text-align:center\">\u56fe1 AudioFlinger\u5728\u97f3\u9891\u7cfb\u7edf\u4e2d\u4f4d\u7f6e<\/p>\n<p style=\"margin-left:0;margin-right:0\">\n<h3 id=\"2.%20%E5%88%9D%E5%A7%8B%E5%8C%96\" style=\"margin-left:0px;margin-right:0px\">2. \u521d\u59cb\u5316<\/h3>\n<p style=\"margin-left:0;margin-right:0\">AudioFlinger\u4e0eAudioPolicyService\u540c\u5728main_audioserver.cpp\u88ab\u521d\u59cb\u5316&#xff0c;\u662faudioserver\u8fdb\u7a0b\u7684\u4e00\u90e8\u5206&#xff0c;\u4e0b\u9762\u662f\u521d\u59cb\u5316\u4ee3\u7801&#xff1a;<\/p>\n<p>int main(int argc __unused, char argv)<br \/>\n{<br \/>\n\u00a0\u00a0\u00a0\u00a0\u00a0 \u2026\u2026<br \/>\n\u00a0\u00a0\u00a0\u00a0sp&lt;ProcessState&gt; proc(ProcessState::self());<br \/>\n\u00a0\u00a0\u00a0\u00a0sp&lt;IServiceManager&gt; sm &#061; defaultServiceManager();<br \/>\n\u00a0\u00a0\u00a0\u00a0ALOGI(&#034;ServiceManager: %p&#034;, sm.get());<br \/>\n\u00a0\u00a0\u00a0\u00a0AudioFlinger::instantiate();<br \/>\n\u00a0\u00a0\u00a0\u00a0AudioPolicyService::instantiate();<br \/>\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \u2026\u2026<br \/>\n\u00a0\u00a0\u00a0\u00a0ProcessState::self()-&gt;startThreadPool();<br \/>\n\u00a0\u00a0\u00a0\u00a0IPCThreadState::self()-&gt;joinThreadPool();<br \/>\n} <\/p>\n<p style=\"margin-left:0;margin-right:0\">\n<h3 id=\"3.%E5%AF%B9%E5%A4%96%E6%8E%A5%E5%8F%A3\" style=\"margin-left:0px;margin-right:0px\">3.\u5bf9\u5916\u63a5\u53e3<\/h3>\n<p style=\"margin-left:0;margin-right:0\">AudioFlinger \u5c5e\u4e8e Server \u7aef&#xff0c;\u5bf9\u5916\u7684client\u548cHAL\u6709&#xff1a;<\/p>\n<p style=\"margin-left:0;margin-right:0\">Client: AudioTrack, AudioRecord, AudioSystem, AudioPolicyService<\/p>\n<p style=\"margin-left:0;margin-right:0\">Server: AudioFlinger (Binder Service)<\/p>\n<p style=\"margin-left:0;margin-right:0\">HAL: StreamHalInterface, AudioHwDevice<\/p>\n<p style=\"margin-left:0;margin-right:0\">\n<p style=\"margin-left:0;margin-right:0\">AF\u5bf9\u4e0a\u5c42\u63d0\u4f9bBinder\u670d\u52a1&#xff0c;\u4ece Android 12\/13 \u5f00\u59cb&#xff0c;\u4e3a\u4e86\u5c06Binder\u670d\u52a1\u4e0e\u5177\u4f53\u4e1a\u52a1\u5b9e\u73b0\u5206\u79bb&#xff0c;\u901a\u8fc7\u00a0Delegate\u00a0\u63a5\u53e3\u5b9a\u4e49\u6838\u5fc3\u529f\u80fd\u5951\u7ea6&#xff0c;\u6240\u4ee5AudioFlinger\u7ee7\u627f\u4e8eIAudioFlinger\u00a0 \u63a5\u53e3&#xff0c;\u800c\u4e0d\u662f\u76f4\u63a5\u7ee7\u627f\u4e8eBnAudioFlingerService&#xff0c;\u5982\u56fe2\u6240\u793a&#xff1a;<\/p>\n<p style=\"margin-left:0;margin-right:0;text-align:center\"><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"334\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/02\/20260202234842-698137da16131.png\" width=\"404\" \/><\/p>\n<p style=\"margin-left:0;margin-right:0;text-align:center\">\u56fe2 AudioFlinger\u4e2d\u589e\u52a0Delegate\u4ee3\u7406<\/p>\n<p style=\"margin-left:0;margin-right:0\">\n<p style=\"margin-left:0;margin-right:0\">\n<h3 id=\"4.%20%E5%86%85%E9%83%A8%E6%A0%B8%E5%BF%83%E7%B1%BB\" style=\"margin-left:0px;margin-right:0px\">4. \u5185\u90e8\u6838\u5fc3\u7c7b<\/h3>\n<p style=\"margin-left:0;margin-right:0\">\n<p style=\"margin-left:0;margin-right:0\">AudioFlinger \u5185\u90e8\u4e3b\u8981\u7531\u51e0\u79cd\u6838\u5fc3\u7ec4\u4ef6\u6784\u6210&#xff1a;<\/p>\n<ul>\n<li>Binder Interface: IAudioFlinger \u63a5\u53e3\u5b9e\u73b0&#xff0c;\u5904\u7406 IPC \u8c03\u7528\u3002<\/li>\n<li>Threads: \u7ba1\u7406\u4e0d\u540c\u8f93\u51fa\/\u8f93\u5165\u6d41\u7684\u7ebf\u7a0b (PlayBackThread, RecordThread)\u3002<\/li>\n<li>Tracks: \u4ee3\u8868\u4e00\u4e2a\u97f3\u9891\u6d41\u7684\u6570\u636e\u6e90 (Track, RecordTrack)\u3002<\/li>\n<li>Effects: \u97f3\u9891\u6548\u679c\u7ba1\u7406\u3002<\/li>\n<li>PatchPanel: \u5904\u7406\u97f3\u9891\u8865\u4e01&#xff08;Audio Patch&#xff09;&#xff0c;\u5b9e\u73b0\u590d\u6742\u7684\u8def\u7531\u529f\u80fd\u3002<\/li>\n<\/ul>\n<p style=\"margin-left:0;margin-right:0\">AudioFlinger \u7684\u4ee3\u7801\u7ed3\u6784\u4e3b\u8981\u56f4\u7ed5 AudioFlinger, Thread, Track \u4e09\u4e2a\u5c42\u7ea7\u5c55\u5f00\u3002<\/p>\n<p style=\"margin-left:0;margin-right:0\">\n<h4 id=\"%C2%A04.1%20AudioFlinger%20%E7%B1%BB\" style=\"margin-left:0px;margin-right:0px\">\u00a04.1 AudioFlinger \u7c7b<\/h4>\n<p style=\"margin-left:0;margin-right:0\">AudioFlinger \u662f\u6574\u4e2a\u670d\u52a1\u7684\u5165\u53e3&#xff0c;\u7ee7\u627f\u81ea BnAudioFlinger&#xff0c;\u5b9e\u73b0\u4e86 IAudioFlinger \u63a5\u53e3\u3002<\/p>\n<p style=\"margin-left:0;margin-right:0\">\u00a0 \u8d1f\u8d23\u521b\u5efa\u548c\u7ba1\u7406 PlaybackThread \u548c RecordThread\u3002<\/p>\n<p style=\"margin-left:0;margin-right:0\">\u00a0 \u8d1f\u8d23\u54cd\u5e94 createTrack\u3001openOutput \u7b49\u7cfb\u7edf\u8c03\u7528\u3002<\/p>\n<p style=\"margin-left:0;margin-right:0\"><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"915\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/02\/20260202234842-698137da255ae.png\" width=\"1723\" \/><\/p>\n<p style=\"margin-left:0;margin-right:0;text-align:center\">\u56fe3<\/p>\n<p style=\"margin-left:0;margin-right:0\">\n<h4 id=\"%C2%A04.2%20Thread%20%E7%B1%BB%E4%BD%93%E7%B3%BB\" style=\"margin-left:0px;margin-right:0px\">\u00a04.2 Thread \u7c7b\u4f53\u7cfb<\/h4>\n<p style=\"margin-left:0;margin-right:0\">\u5982\u56fe3\u6240\u793a&#xff0c;ThreadBase \u662f\u6240\u6709\u97f3\u9891\u5de5\u4f5c\u7ebf\u7a0b\u7684\u57fa\u7c7b\u3002<\/p>\n<p style=\"margin-left:0;margin-right:0\">\u00a0 PlaybackThread: \u8d1f\u8d23\u97f3\u9891\u64ad\u653e\u3002<\/p>\n<p style=\"margin-left:0;margin-right:0\">\u00a0\u00a0\u00a0\u00a0\u00a0 MixerThread: \u6700\u5e38\u7528\u7684\u56de\u653e\u7ebf\u7a0b&#xff0c;\u8d1f\u8d23\u5c06\u591a\u4e2a Track \u7684\u97f3\u9891\u6570\u636e\u6df7\u5408&#xff08;Mix&#xff09;\u540e\u5199\u5165 HAL\u3002\u652f\u6301 FastMixer \u4ee5\u5b9e\u73b0\u4f4e\u5ef6\u8fdf\u64ad\u653e\u3002<\/p>\n<p style=\"margin-left:0;margin-right:0\">\u00a0\u00a0\u00a0\u00a0\u00a0 DirectOutputThread: \u76f4\u63a5\u8f93\u51fa\u7ebf\u7a0b&#xff0c;\u4e0d\u7ecf\u8fc7\u8f6f\u4ef6\u6df7\u97f3&#xff0c;\u901a\u5e38\u7528\u4e8e HDMI \u900f\u4f20\u6216\u9ad8\u4fdd\u771f\u97f3\u4e50\u64ad\u653e\u3002<\/p>\n<p style=\"margin-left:0;margin-right:0\">\u00a0\u00a0\u00a0\u00a0\u00a0 OffloadThread: \u5378\u8f7d\u7ebf\u7a0b&#xff0c;\u5c06\u89e3\u7801\u548c\u6df7\u97f3\u5de5\u4f5c\u4ea4\u7ed9 DSP\/\u786c\u4ef6\u5904\u7406\u3002<\/p>\n<p style=\"margin-left:0;margin-right:0\">\u00a0\u00a0\u00a0\u00a0\u00a0 MmapThread: \u914d\u5408 AAudio \u4f7f\u7528&#xff0c;\u5b9e\u73b0 mmap \u65b9\u5f0f\u7684\u4f4e\u5ef6\u8fdf\u6570\u636e\u4f20\u8f93\u3002<\/p>\n<p style=\"margin-left:0;margin-right:0\">\u00a0 RecordThread: \u8d1f\u8d23\u97f3\u9891\u5f55\u5236&#xff0c;\u4ece HAL \u8bfb\u53d6\u6570\u636e\u5e76\u5206\u53d1\u7ed9 RecordTrack\u3002<\/p>\n<p style=\"margin-left:0;margin-right:0\">\n<h4 id=\"%C2%A04.3%20Track%20%E7%B1%BB%E4%BD%93%E7%B3%BB\" style=\"margin-left:0px;margin-right:0px\">\u00a04.3 Track \u7c7b\u4f53\u7cfb<\/h4>\n<p style=\"margin-left:0;margin-right:0\">TrackBase \u662f\u97f3\u9891\u6d41\u6570\u636e\u7684\u62bd\u8c61\u57fa\u7c7b\u3002<\/p>\n<p style=\"margin-left:0;margin-right:0\">\u00a0 Track: \u5bf9\u5e94 AudioTrack&#xff0c;\u5b58\u5728\u4e8e PlaybackThread \u4e2d\u3002\u5b83\u7ba1\u7406\u7740\u5171\u4eab\u5185\u5b58&#xff08;SharedBuffer&#xff09;&#xff0c;Client \u7aef\u5f80\u91cc\u5199\u6570\u636e&#xff0c;Thread \u4ece\u91cc\u8bfb\u6570\u636e\u3002<\/p>\n<p style=\"margin-left:0;margin-right:0\">\u00a0 RecordTrack: \u5bf9\u5e94 AudioRecord&#xff0c;\u5b58\u5728\u4e8e RecordThread \u4e2d\u3002<\/p>\n<p style=\"margin-left:0;margin-right:0\">\n<p style=\"margin-left:0;margin-right:0;text-align:center\"><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"368\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/02\/20260202234842-698137dacdc7a.png\" width=\"473\" \/><\/p>\n<p style=\"margin-left:0;margin-right:0;text-align:center\">\u56fe4 AudioTrack\u4e0eAudioFlinger\u91cc\u7684track<\/p>\n<p style=\"margin-left:0;margin-right:0\">\n<p style=\"margin-left:0;margin-right:0;text-align:center\"><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"395\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/02\/20260202234843-698137db3a7a2.png\" width=\"471\" \/><\/p>\n<p style=\"margin-left:0;margin-right:0;text-align:center\">\u56fe5 AudioRecord\u4e0eAudioFlinger\u91cc\u7684Track<\/p>\n<p style=\"margin-left:0;margin-right:0\">\n<p style=\"margin-left:0;margin-right:0\">\n<h3 id=\"%C2%A05.%20%E6%A0%B8%E5%BF%83%E6%B5%81%E7%A8%8B%E5%88%86%E6%9E%90\" style=\"margin-left:0px;margin-right:0px\">\u00a05. \u6838\u5fc3\u6d41\u7a0b\u5206\u6790<\/h3>\n<p style=\"margin-left:0;margin-right:0\">\n<h4 id=\"%C2%A05.1%20%E5%88%9B%E5%BB%BA%20Track%20(createTrack)\" style=\"margin-left:0px;margin-right:0px\">\u00a05.1 \u521b\u5efa Track (createTrack)<\/h4>\n<p style=\"margin-left:0;margin-right:0\">\n<p style=\"margin-left:0;margin-right:0\">\u8fd9\u662f\u64ad\u653e\u6d41\u7a0b\u7684\u8d77\u70b9\u3002<\/p>\n<p style=\"margin-left:0;margin-right:0\">1) \u5ba2\u6237\u7aef AudioTrack \u8c03\u7528 AudioSystem::getOutputForAttr\u3002<\/p>\n<p style=\"margin-left:0;margin-right:0\">2)\u00a0 AudioPolicyService \u6839\u636e\u7b56\u7565&#xff08;\u8def\u7531\u3001\u91c7\u6837\u7387\u7b49&#xff09;\u8fd4\u56de\u4e00\u4e2a Output Handle&#xff08;\u5bf9\u5e94 AudioFlinger \u4e2d\u7684\u4e00\u4e2a Thread ID&#xff09;\u3002<\/p>\n<p style=\"margin-left:0;margin-right:0\">3)\u00a0 \u5ba2\u6237\u7aef\u8c03\u7528 AudioFlinger::createTrack&#xff0c;\u4f20\u5165 Output Handle\u3002<\/p>\n<p style=\"margin-left:0;margin-right:0\">4)\u00a0 AudioFlinger \u6839\u636e Handle \u627e\u5230\u5bf9\u5e94\u7684 PlaybackThread\u3002<\/p>\n<p style=\"margin-left:0;margin-right:0\">5) \u8c03\u7528 PlaybackThread::createTrack_l \u521b\u5efa\u670d\u52a1\u7aef Track \u5bf9\u8c61\u3002<\/p>\n<p style=\"margin-left:0;margin-right:0\">6) \u8fd4\u56de IAudioTrack \u53e5\u67c4\u7ed9\u5ba2\u6237\u7aef\u3002<\/p>\n<p style=\"margin-left:0;margin-right:0\">\n<h4 id=\"%C2%A05.2%20%E5%9B%9E%E6%94%BE%E7%BA%BF%E7%A8%8B%E5%BE%AA%E7%8E%AF%20(MixerThread%3A%3AthreadLoop)\" style=\"margin-left:0px;margin-right:0px\">\u00a05.2 \u56de\u653e\u7ebf\u7a0b\u5faa\u73af (MixerThread::threadLoop)<\/h4>\n<p style=\"margin-left:0;margin-right:0\">\n<p style=\"margin-left:0;margin-right:0\">MixerThread \u8fd0\u884c\u4e00\u4e2a\u6b7b\u5faa\u73af threadLoop:<\/p>\n<p style=\"margin-left:0;margin-right:0\">1)\u00a0 processConfigEvents: \u5904\u7406\u914d\u7f6e\u53d8\u66f4&#xff08;\u5982\u91c7\u6837\u7387\u53d8\u5316\u3001\u8def\u7531\u53d8\u5316&#xff09;\u3002<\/p>\n<p style=\"margin-left:0;margin-right:0\">2) \u00a0prepareTracks_l: \u904d\u5386\u6240\u6709 Track\u3002<\/p>\n<p style=\"margin-left:0;margin-right:0\">\u00a0\u00a0\u00a0\u00a0\u00a0 \u68c0\u67e5 Track \u72b6\u6001&#xff08;Active\/Stopped\/Paused&#xff09;\u3002<\/p>\n<p style=\"margin-left:0;margin-right:0\">\u00a0\u00a0\u00a0\u00a0\u00a0 \u83b7\u53d6 Track \u7684 Buffer \u6570\u636e\u3002<\/p>\n<p style=\"margin-left:0;margin-right:0\">\u00a0\u00a0\u00a0\u00a0\u00a0 \u5224\u65ad\u662f\u5426\u9700\u8981\u6df7\u97f3\u3002<\/p>\n<p style=\"margin-left:0;margin-right:0\">3) threadLoop_mix: \u4f7f\u7528 AudioMixer \u5c06\u6240\u6709 Active Track \u7684\u6570\u636e\u6df7\u5408\u5230\u4e00\u4e2a\u4e34\u65f6\u7684 Sink Buffer \u4e2d\u3002<\/p>\n<p style=\"margin-left:0;margin-right:0\">4)\u00a0 threadLoop_write: \u5c06\u6df7\u5408\u540e\u7684\u6570\u636e\u5199\u5165 AudioStreamOut (HAL)\u3002<\/p>\n<p style=\"margin-left:0;margin-right:0\">\n<p style=\"margin-left:0;margin-right:0\">\u5bf9\u4e8e\u4f4e\u5ef6\u8fdf\u573a\u666f&#xff0c;MixerThread \u4f1a\u521b\u5efa FastMixer \u7ebf\u7a0b\u3002\u666e\u901a Track \u7531 MixerThread \u5904\u7406&#xff0c;\u8bbe\u7f6e\u4e86 FAST \u6807\u5fd7\u7684 Track \u4f1a\u88ab FastMixer \u62a2\u5360\u5f0f\u8c03\u5ea6\u5904\u7406&#xff0c;\u76f4\u63a5\u5199\u5165 HAL \u6216\u901a\u8fc7 Pipe \u5199\u5165\u3002<\/p>\n<p style=\"margin-left:0;margin-right:0\">\n<h4 id=\"%C2%A05.3%20%E5%BA%8F%E5%88%97%E5%9B%BE%20(UML)\" style=\"margin-left:0px;margin-right:0px\">\u00a05.3 \u5e8f\u5217\u56fe (UML)<\/h4>\n<p style=\"margin-left:0;margin-right:0\">\n<p style=\"margin-left:0;margin-right:0\">\u4ee5\u4e0b\u5c55\u793a\u4e86 createTrack \u548c write (\u64ad\u653e) \u7684\u7b80\u8981\u65f6\u5e8f\u3002<\/p>\n<p style=\"margin-left:0;margin-right:0\"><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"1384\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/02\/20260202234843-698137db9b217.png\" width=\"2321\" \/><\/p>\n<p style=\"margin-left:0;margin-right:0;text-align:center\">\u56fe6 createtrack\u65f6\u5e8f<\/p>\n<p style=\"margin-left:0;margin-right:0\">\n<h3 id=\"%C2%A06.%20%E6%80%BB%E7%BB%93\" style=\"margin-left:0px;margin-right:0px\">\u00a06. \u603b\u7ed3<\/h3>\n<p style=\"margin-left:0;margin-right:0\">\n<p style=\"margin-left:0;margin-right:0\">AudioFlinger \u662f Android \u97f3\u9891\u67b6\u6784\u4e2d\u627f\u4e0a\u542f\u4e0b\u7684\u67a2\u7ebd\u3002\u901a\u8fc7\u591a\u7ebf\u7a0b\u6a21\u578b&#xff08;Mixer, Direct, Record\u7b49&#xff09;&#xff0c;\u5b83\u9ad8\u6548\u5730\u7ba1\u7406\u7740\u7cfb\u7edf\u4e2d\u7684\u5e76\u53d1\u97f3\u9891\u6d41\u3002\u901a\u8fc7\u5171\u4eab\u5185\u5b58\u673a\u5236&#xff0c;\u5b83\u5b9e\u73b0\u4e86 Client \u4e0e Server \u95f4\u7684\u9ad8\u6548\u6570\u636e\u4f20\u8f93\u3002\u7406\u89e3 AudioFlinger \u7684\u5173\u952e\u5728\u4e8e\u638c\u63e1 ThreadLoop \u7684\u8c03\u5ea6\u673a\u5236\u4ee5\u53ca Track \u7684\u751f\u547d\u5468\u671f\u7ba1\u7406\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u76ee\u5f55<br \/>\n1. \u7b80\u8ff0<br \/>\n2. \u521d\u59cb\u5316<br \/>\n3.\u5bf9\u5916\u63a5\u53e3<br \/>\n4. \u5185\u90e8\u6838\u5fc3\u7c7b 4.1 AudioFlinger \u7c7b 4.2 Thread \u7c7b\u4f53\u7cfb 4.3 Track \u7c7b\u4f53\u7cfb 5. \u6838\u5fc3\u6d41\u7a0b\u5206\u6790 5.1 \u521b\u5efa Track (createTrack) 5.2 \u56de\u653e\u7ebf\u7a0b\u5faa\u73af (MixerThread::threadLoop) 5.3 \u5e8f\u5217\u56fe (UML) 6. \u603b\u7ed3 1. \u7b80\u8ff0 AudioFlinger&#xff0c;\u7b80\u79f0AF&#xff0c;\u5b83 \u662f Android \u97f3\u9891\u7cfb\u7edf\u7684\u6838\u5fc3\u670d\u52a1&amp;#x<\/p>\n","protected":false},"author":2,"featured_media":71094,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[7471,7474,7473,7475,7472],"topic":[],"class_list":["post-71100","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-server","tag-audioflinger","tag-audiopolicy","tag-audiotrack","tag-7475","tag-7472"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.3 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Android\u97f3\u9891\u7cfb\u5217(10)-AudioFlinger\u4ee3\u7801\u89e3\u6790 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.wsisp.com\/helps\/71100.html\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Android\u97f3\u9891\u7cfb\u5217(10)-AudioFlinger\u4ee3\u7801\u89e3\u6790 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"og:description\" content=\"\u76ee\u5f55 1. \u7b80\u8ff0 2. \u521d\u59cb\u5316 3.\u5bf9\u5916\u63a5\u53e3 4. \u5185\u90e8\u6838\u5fc3\u7c7b 4.1 AudioFlinger \u7c7b 4.2 Thread \u7c7b\u4f53\u7cfb 4.3 Track \u7c7b\u4f53\u7cfb 5. \u6838\u5fc3\u6d41\u7a0b\u5206\u6790 5.1 \u521b\u5efa Track (createTrack) 5.2 \u56de\u653e\u7ebf\u7a0b\u5faa\u73af (MixerThread::threadLoop) 5.3 \u5e8f\u5217\u56fe (UML) 6. \u603b\u7ed3 1. \u7b80\u8ff0 AudioFlinger&#xff0c;\u7b80\u79f0AF&#xff0c;\u5b83 \u662f Android \u97f3\u9891\u7cfb\u7edf\u7684\u6838\u5fc3\u670d\u52a1&amp;#x\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.wsisp.com\/helps\/71100.html\" \/>\n<meta property=\"og:site_name\" content=\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"article:published_time\" content=\"2026-02-02T23:48:45+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/02\/20260202234841-698137d9b0e1c.png\" \/>\n<meta name=\"author\" content=\"admin\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"\u4f5c\u8005\" \/>\n\t<meta name=\"twitter:data1\" content=\"admin\" \/>\n\t<meta name=\"twitter:label2\" content=\"\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/71100.html\",\"url\":\"https:\/\/www.wsisp.com\/helps\/71100.html\",\"name\":\"Android\u97f3\u9891\u7cfb\u5217(10)-AudioFlinger\u4ee3\u7801\u89e3\u6790 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"isPartOf\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\"},\"datePublished\":\"2026-02-02T23:48:45+00:00\",\"dateModified\":\"2026-02-02T23:48:45+00:00\",\"author\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/71100.html#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.wsisp.com\/helps\/71100.html\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/71100.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.wsisp.com\/helps\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Android\u97f3\u9891\u7cfb\u5217(10)-AudioFlinger\u4ee3\u7801\u89e3\u6790\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\",\"url\":\"https:\/\/www.wsisp.com\/helps\/\",\"name\":\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"description\":\"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"zh-Hans\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\",\"name\":\"admin\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"zh-Hans\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"contentUrl\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"caption\":\"admin\"},\"sameAs\":[\"http:\/\/wp.wsisp.com\"],\"url\":\"https:\/\/www.wsisp.com\/helps\/author\/admin\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Android\u97f3\u9891\u7cfb\u5217(10)-AudioFlinger\u4ee3\u7801\u89e3\u6790 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.wsisp.com\/helps\/71100.html","og_locale":"zh_CN","og_type":"article","og_title":"Android\u97f3\u9891\u7cfb\u5217(10)-AudioFlinger\u4ee3\u7801\u89e3\u6790 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","og_description":"\u76ee\u5f55 1. \u7b80\u8ff0 2. \u521d\u59cb\u5316 3.\u5bf9\u5916\u63a5\u53e3 4. \u5185\u90e8\u6838\u5fc3\u7c7b 4.1 AudioFlinger \u7c7b 4.2 Thread \u7c7b\u4f53\u7cfb 4.3 Track \u7c7b\u4f53\u7cfb 5. \u6838\u5fc3\u6d41\u7a0b\u5206\u6790 5.1 \u521b\u5efa Track (createTrack) 5.2 \u56de\u653e\u7ebf\u7a0b\u5faa\u73af (MixerThread::threadLoop) 5.3 \u5e8f\u5217\u56fe (UML) 6. \u603b\u7ed3 1. \u7b80\u8ff0 AudioFlinger&#xff0c;\u7b80\u79f0AF&#xff0c;\u5b83 \u662f Android \u97f3\u9891\u7cfb\u7edf\u7684\u6838\u5fc3\u670d\u52a1&amp;#x","og_url":"https:\/\/www.wsisp.com\/helps\/71100.html","og_site_name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","article_published_time":"2026-02-02T23:48:45+00:00","og_image":[{"url":"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/02\/20260202234841-698137d9b0e1c.png"}],"author":"admin","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"admin","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"2 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.wsisp.com\/helps\/71100.html","url":"https:\/\/www.wsisp.com\/helps\/71100.html","name":"Android\u97f3\u9891\u7cfb\u5217(10)-AudioFlinger\u4ee3\u7801\u89e3\u6790 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","isPartOf":{"@id":"https:\/\/www.wsisp.com\/helps\/#website"},"datePublished":"2026-02-02T23:48:45+00:00","dateModified":"2026-02-02T23:48:45+00:00","author":{"@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41"},"breadcrumb":{"@id":"https:\/\/www.wsisp.com\/helps\/71100.html#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.wsisp.com\/helps\/71100.html"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.wsisp.com\/helps\/71100.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.wsisp.com\/helps"},{"@type":"ListItem","position":2,"name":"Android\u97f3\u9891\u7cfb\u5217(10)-AudioFlinger\u4ee3\u7801\u89e3\u6790"}]},{"@type":"WebSite","@id":"https:\/\/www.wsisp.com\/helps\/#website","url":"https:\/\/www.wsisp.com\/helps\/","name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","description":"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"zh-Hans"},{"@type":"Person","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41","name":"admin","image":{"@type":"ImageObject","inLanguage":"zh-Hans","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/","url":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","contentUrl":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","caption":"admin"},"sameAs":["http:\/\/wp.wsisp.com"],"url":"https:\/\/www.wsisp.com\/helps\/author\/admin"}]}},"_links":{"self":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/71100","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/comments?post=71100"}],"version-history":[{"count":0,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/71100\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media\/71094"}],"wp:attachment":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media?parent=71100"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/categories?post=71100"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/tags?post=71100"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/topic?post=71100"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}