ตั้งแต่วันที่ 27 มีนาคม 2025 เป็นต้นไป เราขอแนะนำให้ใช้ android-latest-release
แทน aosp-main
เพื่อสร้างและมีส่วนร่วมใน AOSP โปรดดูข้อมูลเพิ่มเติมที่หัวข้อการเปลี่ยนแปลงใน AOSP
เสียง
จัดทุกอย่างให้เป็นระเบียบอยู่เสมอด้วยคอลเล็กชัน
บันทึกและจัดหมวดหมู่เนื้อหาตามค่ากำหนดของคุณ
เลเยอร์การแยกแยะฮาร์ดแวร์ (HAL) ของเสียงใน Android จะเชื่อมต่อ API ของเฟรมเวิร์กเฉพาะเสียงในระดับที่สูงขึ้นใน android.media กับไดรเวอร์และฮาร์ดแวร์เสียงที่อยู่เบื้องหลัง ส่วนนี้มีวิธีการติดตั้งใช้งานและเคล็ดลับในการปรับปรุงประสิทธิภาพ
สถาปัตยกรรมเสียงของ Android จะกำหนดวิธีใช้ฟังก์ชันเสียงและชี้ไปยังซอร์สโค้ดที่เกี่ยวข้องซึ่งเกี่ยวข้องกับการใช้งาน
รูปที่ 1 สถาปัตยกรรมเสียงของ Android
-
เฟรมเวิร์กแอปพลิเคชัน
-
เฟรมเวิร์กแอปพลิเคชันประกอบด้วยโค้ดแอป ซึ่งใช้ android.media API เพื่อโต้ตอบกับฮาร์ดแวร์เสียง โค้ดนี้จะเรียกใช้คลาส JNI Glue ที่เกี่ยวข้องภายในเพื่อเข้าถึงโค้ดเนทีฟที่โต้ตอบกับฮาร์ดแวร์เสียง
-
JNI
-
โค้ด JNI ที่เชื่อมโยงกับ android.media จะเรียกโค้ดเนทีฟระดับล่างเพื่อเข้าถึงฮาร์ดแวร์เสียง JNI อยู่ใน
frameworks/base/core/jni/
และ
frameworks/base/media/jni
-
เฟรมเวิร์กเนทีฟ
-
เฟรมเวิร์กแบบเนทีฟมีแพ็กเกจเนทีฟที่เทียบเท่ากับแพ็กเกจ android.media ซึ่งเรียกใช้พร็อกซี Binder IPC เพื่อเข้าถึงบริการเฉพาะเสียงของเซิร์ฟเวอร์สื่อ
โค้ดเฟรมเวิร์กแบบเนทีฟอยู่ใน
frameworks/av/media/libmedia
-
Binder IPC
-
พร็อกซี IPC ของ Binder ช่วยให้การสื่อสารข้ามขอบเขตโปรเซสง่ายขึ้น โดยจะอยู่ในส่วน
frameworks/av/media/libmedia
และขึ้นต้นด้วยตัวอักษร "I"
-
เซิร์ฟเวอร์สื่อ
-
เซิร์ฟเวอร์สื่อมีบริการเสียง ซึ่งเป็นโค้ดจริงที่โต้ตอบกับการใช้งาน HAL เซิร์ฟเวอร์สื่ออยู่ใน
frameworks/av/services/audioflinger
-
HAL
-
HAL จะกำหนดอินเทอร์เฟซมาตรฐานที่บริการเสียงเรียกใช้และคุณต้องนำมาใช้งานเพื่อให้ฮาร์ดแวร์เสียงทำงานได้อย่างถูกต้อง โปรดดูรายละเอียดเพิ่มเติมในอินเทอร์เฟซ HAL เสียงและความคิดเห็นในไฟล์
*.hal
ของไดเรกทอรีเวอร์ชัน HAL ที่เกี่ยวข้อง
-
โปรแกรมควบคุมเคอร์เนล
-
ไดรเวอร์เสียงจะโต้ตอบกับฮาร์ดแวร์และการใช้งาน HAL คุณใช้ Advanced Linux Sound Architecture (ALSA), Open Sound System (OSS) หรือไดรเวอร์ที่กำหนดเองได้ (HAL จะใช้ไดรเวอร์ใดก็ได้)
หมายเหตุ: หากคุณใช้ ALSA เราขอแนะนําให้ใช้ external/tinyalsa
สําหรับส่วนที่เป็นไดรฟ์เวอร์ของผู้ใช้เนื่องจากมีการอนุญาตให้ใช้สิทธิที่เข้ากันได้ (ไลบรารีโหมดผู้ใช้มาตรฐานได้รับอนุญาตภายใต้ GPL)
-
เสียงแบบเนทีฟของ Android อิงตาม Open SL ES (ไม่แสดง)
-
API นี้จะแสดงเป็นส่วนหนึ่งของ Android NDK และอยู่ในระดับสถาปัตยกรรมเดียวกับ android.media
ตัวอย่างเนื้อหาและโค้ดในหน้าเว็บนี้ขึ้นอยู่กับใบอนุญาตที่อธิบายไว้ในใบอนุญาตการใช้เนื้อหา Java และ OpenJDK เป็นเครื่องหมายการค้าหรือเครื่องหมายการค้าจดทะเบียนของ Oracle และ/หรือบริษัทในเครือ
อัปเดตล่าสุด 2025-07-27 UTC
[[["เข้าใจง่าย","easyToUnderstand","thumb-up"],["แก้ปัญหาของฉันได้","solvedMyProblem","thumb-up"],["อื่นๆ","otherUp","thumb-up"]],[["ไม่มีข้อมูลที่ฉันต้องการ","missingTheInformationINeed","thumb-down"],["ซับซ้อนเกินไป/มีหลายขั้นตอนมากเกินไป","tooComplicatedTooManySteps","thumb-down"],["ล้าสมัย","outOfDate","thumb-down"],["ปัญหาเกี่ยวกับการแปล","translationIssue","thumb-down"],["ตัวอย่าง/ปัญหาเกี่ยวกับโค้ด","samplesCodeIssue","thumb-down"],["อื่นๆ","otherDown","thumb-down"]],["อัปเดตล่าสุด 2025-07-27 UTC"],[],[],null,["# Audio\n\nAndroid's audio Hardware Abstraction Layer (HAL) connects the higher-level,\naudio-specific framework APIs in [android.media](http://developer.android.com/reference/android/media/package-summary.html) to the underlying audio driver and\nhardware. This section includes implementation instructions and tips for\nimproving performance.\n\n\nAndroid audio architecture defines how audio functionality is implemented and\npoints to the relevant source code involved in the implementation.\n\n\n**Figure 1.** Android audio architecture\n\n\nApplication framework\n:\n The application framework includes the app code, which uses the [android.media](http://developer.android.com/reference/android/media/package-summary.html) APIs to\n interact with audio hardware. Internally, this code calls corresponding JNI glue\n classes to access the native code that interacts with audio hardware.\n\n\nJNI\n:\n The JNI code associated with [android.media](http://developer.android.com/reference/android/media/package-summary.html) calls lower level native code to access audio\n hardware. JNI is located in `frameworks/base/core/jni/` and\n `frameworks/base/media/jni`.\n\n\nNative framework\n:\n The native framework provides a native equivalent to the [android.media](http://developer.android.com/reference/android/media/package-summary.html) package, calling\n Binder IPC proxies to access the audio-specific services of the media server.\n Native framework code is located in `frameworks/av/media/libmedia`.\n\n\nBinder IPC\n:\n Binder IPC proxies facilitate communication over process boundaries. Proxies are\n located in `frameworks/av/media/libmedia` and begin with the letter\n \"I\".\n\n\nMedia server\n:\n The media server contains audio services, which are the actual code that\n interacts with your HAL implementations. The media server is located in\n `frameworks/av/services/audioflinger`.\n\n\nHAL\n:\n The HAL defines the standard interface that audio services call into and that\n you must implement for your audio hardware to function correctly. For more details, refer to the [audio HAL\n interface](https://android.googlesource.com/platform/hardware/interfaces/+/refs/heads/android16-release/audio/) and comments in the `*.hal` files of the corresponding HAL version directory.\n\n\nKernel driver\n\n: The audio driver interacts with your hardware and HAL implementation. You can use Advanced Linux Sound Architecture (ALSA), Open Sound System (OSS), or a custom driver (HAL is driver-agnostic). **Note** : If you use ALSA, we recommend\n `external/tinyalsa` for the user portion of the driver because of its\n compatible licensing (the standard user-mode library is GPL-licensed).\n\n\nAndroid native audio based on Open SL ES *(not shown)*\n:\n This API is exposed as part of\n [Android NDK](https://developer.android.com/tools/sdk/ndk/index.html)\n and is at the same architecture level as\n [android.media](http://developer.android.com/reference/android/media/package-summary.html)."]]