ตั้งแต่วันที่ 27 มีนาคม 2025 เป็นต้นไป เราขอแนะนำให้ใช้ android-latest-release
แทน aosp-main
เพื่อสร้างและมีส่วนร่วมใน AOSP โปรดดูข้อมูลเพิ่มเติมที่หัวข้อการเปลี่ยนแปลงใน AOSP
สื่อ
จัดทุกอย่างให้เป็นระเบียบอยู่เสมอด้วยคอลเล็กชัน
บันทึกและจัดหมวดหมู่เนื้อหาตามค่ากำหนดของคุณ
Android มี Stagefright ซึ่งเป็นเครื่องมือเล่นสื่อในระดับเนทีฟที่มีตัวแปลงรหัสแบบซอฟต์แวร์ในตัวสำหรับรูปแบบสื่อยอดนิยม
ฟีเจอร์การเล่นเสียงและวิดีโอของ Stagefright ประกอบด้วยการผสานรวมกับตัวแปลงสัญญาณ OpenMAX, การจัดการเซสชัน, การแสดงผลที่ซิงค์ตามเวลา, การควบคุมการรับส่ง และ DRM
Stagefright ยังรองรับการผสานรวมกับตัวแปลงรหัสฮาร์ดแวร์ที่กำหนดเองซึ่งคุณระบุไว้ด้วย หากต้องการตั้งค่าเส้นทางของฮาร์ดแวร์เพื่อเข้ารหัสและถอดรหัสสื่อ คุณต้องติดตั้งใช้งานตัวแปลงรหัสที่อิงตามฮาร์ดแวร์เป็นคอมโพเนนต์ OpenMax IL (Integration Layer)
หมายเหตุ: การอัปเดต Stagefright อาจเกิดขึ้นผ่านกระบวนการการอัปเดตความปลอดภัยรายเดือนของ Android และเป็นส่วนหนึ่งของรุ่นระบบปฏิบัติการ Android
สถาปัตยกรรม
แอปพลิเคชันสื่อโต้ตอบกับเฟรมเวิร์กมัลติมีเดียเนทีฟของ Android ตามสถาปัตยกรรมต่อไปนี้

รูปที่ 1 สถาปัตยกรรมสื่อ
- เฟรมเวิร์กแอปพลิเคชัน
- ที่ระดับเฟรมเวิร์กแอปพลิเคชันคือโค้ดแอปพลิเคชันที่ใช้ android.media API เพื่อโต้ตอบกับฮาร์ดแวร์มัลติมีเดีย
- Binder IPC
- พร็อกซี Binder IPC ช่วยให้การสื่อสารข้ามขอบเขตโปรเซสง่ายขึ้น
โดยอยู่ในรูปแบบไฟล์ .CSV ในไดเรกทอรี
frameworks/av/media/libmedia
และขึ้นต้นด้วยตัวอักษร "I"
- เฟรมเวิร์กมัลติมีเดียเนทีฟ
- ที่ระดับเนทีฟ Android มีเฟรมเวิร์กมัลติมีเดียที่ใช้เครื่องมือ Stagefright ในการบันทึกและเล่นเสียงและวิดีโอ Stagefright มาพร้อมกับรายการตัวแปลงรหัสซอฟต์แวร์ที่รองรับโดยค่าเริ่มต้น และคุณสามารถใช้ตัวแปลงรหัสฮาร์ดแวร์ของคุณเองได้โดยใช้มาตรฐานเลเยอร์การผสานรวม OpenMax ดูรายละเอียดการใช้งานเพิ่มเติมได้ในคอมโพเนนต์ MediaPlayer และ Stagefright ซึ่งอยู่ใน
frameworks/av/media
- เลเยอร์การผสานรวม OpenMAX (IL)
- OpenMAX IL เป็นวิธีที่เป็นมาตรฐานสำหรับ Stagefright ในการจดจำและใช้ตัวแปลงรหัสมัลติมีเดียแบบฮาร์ดแวร์ที่กําหนดเองซึ่งเรียกว่าคอมโพเนนต์ คุณต้องระบุปลั๊กอิน OpenMAX ในรูปแบบไลบรารีที่ใช้ร่วมกันชื่อ
libstagefrighthw.so
ปลั๊กอินนี้จะลิงก์ Stagefright กับคอมโพเนนต์ตัวแปลงรหัสที่กำหนดเอง ซึ่งต้องติดตั้งใช้งานตามมาตรฐานคอมโพเนนต์ OpenMAX IL
ใช้ตัวแปลงรหัสที่กำหนดเอง
Stagefright มาพร้อมกับโปรแกรมเปลี่ยนรหัสซอฟต์แวร์ในตัวสำหรับรูปแบบสื่อทั่วไป แต่คุณยังเพิ่มโปรแกรมเปลี่ยนรหัสฮาร์ดแวร์ที่กำหนดเองเป็นคอมโพเนนต์ OpenMAX ได้ด้วย โดยคุณต้องสร้างคอมโพเนนต์ OMX และปลั๊กอิน OMX ที่เชื่อมโยงโปรแกรมเปลี่ยนรหัสที่กำหนดเองเข้ากับเฟรมเวิร์ก Stagefright ดูตัวอย่างคอมโพเนนต์ได้ที่ hardware/ti/omap4xxx/domx/
และดูตัวอย่างปลั๊กอินสำหรับ Galaxy Nexus ได้ที่ hardware/ti/omap4xx/libstagefrighthw
วิธีเพิ่มตัวแปลงรหัสของคุณเอง
- สร้างคอมโพเนนต์ตามมาตรฐานคอมโพเนนต์ OpenMAX IL อินเทอร์เฟซคอมโพเนนต์อยู่ในไฟล์
frameworks/native/include/media/OpenMAX/OMX_Component.h
ดูข้อมูลเพิ่มเติมเกี่ยวกับข้อกำหนด OpenMAX IL ได้ที่เว็บไซต์ OpenMAX
- สร้างปลั๊กอิน OpenMAX ที่ลิงก์คอมโพเนนต์กับบริการ Stagefright ดูอินเทอร์เฟซในการสร้างปลั๊กอินได้ที่ไฟล์ส่วนหัว
frameworks/native/include/media/hardware/OMXPluginBase.h
และ HardwareAPI.h
- สร้างปลั๊กอินเป็นไลบรารีที่แชร์โดยใช้ชื่อ
libstagefrighthw.so
ใน Makefile ของผลิตภัณฑ์ เช่น
LOCAL_MODULE := libstagefrighthw
ใน Makefile ของอุปกรณ์ โปรดตรวจสอบว่าคุณได้ประกาศโมดูลเป็นแพ็กเกจผลิตภัณฑ์แล้ว โดยทำดังนี้
PRODUCT_PACKAGES += \
libstagefrighthw \
...
แสดงตัวแปลงรหัสต่อเฟรมเวิร์ก
บริการ Stagefright จะแยกวิเคราะห์ system/etc/media_codecs.xml
และ system/etc/media_profiles.xml
เพื่อแสดงตัวแปลงรหัสและโปรไฟล์ที่รองรับในอุปกรณ์แก่นักพัฒนาแอปผ่านคลาส android.media.MediaCodecList
และ android.media.CamcorderProfile
คุณต้องสร้างไฟล์ทั้ง 2 ไฟล์ในไดเรกทอรี device/<company>/<device>/
และคัดลอกไฟล์นี้ไปยังไดเรกทอรี system/etc
ของอิมเมจระบบใน Makefile ของอุปกรณ์ เช่น
PRODUCT_COPY_FILES += \
device/samsung/tuna/media_profiles.xml:system/etc/media_profiles.xml \
device/samsung/tuna/media_codecs.xml:system/etc/media_codecs.xml \
ดูตัวอย่างทั้งหมดได้ที่ device/samsung/tuna/media_codecs.xml
และ device/samsung/tuna/media_profiles.xml
หมายเหตุ: ตั้งแต่ Android 4.1 ระบบจะไม่รองรับองค์ประกอบ <Quirk>
สำหรับตัวแปลงรหัสสื่ออีกต่อไป
ตัวอย่างเนื้อหาและโค้ดในหน้าเว็บนี้ขึ้นอยู่กับใบอนุญาตที่อธิบายไว้ในใบอนุญาตการใช้เนื้อหา 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,["# Media\n\nAndroid includes Stagefright, a media playback engine at the native level\nthat has built-in software-based codecs for popular media formats.\n\nStagefright audio and video playback features include integration with\nOpenMAX codecs, session management, time-synchronized rendering, transport\ncontrol, and DRM.\n\nStagefright also supports integration with custom hardware codecs provided by\nyou. To set a hardware path to encode and decode media, you must implement a\nhardware-based codec as an OpenMax IL (Integration Layer) component.\n\n**Note:** Stagefright updates can occur through the\nAndroid [monthly security\nupdate](/docs/security/bulletin) process and as part of an Android OS release.\n\nArchitecture\n------------\n\nMedia applications interact with the Android native multimedia framework\naccording to the following architecture.\n\n**Figure 1.** Media\narchitecture\n\nApplication Framework\n: At the application framework level is application code that utilizes\n [android.media](http://developer.android.com/reference/android/media/package-summary.html)\n APIs to interact with the multimedia hardware.\n\nBinder IPC\n: The Binder IPC proxies facilitate communication over process boundaries.\n They are located in the `frameworks/av/media/libmedia` directory and\n begin with the letter \"I\".\n\nNative Multimedia Framework\n: At the native level, Android provides a multimedia framework that utilizes\n the Stagefright engine for audio and video recording and playback. Stagefright\n comes with a default list of supported software codecs and you can implement\n your own hardware codec by using the OpenMax integration layer standard. For\n more implementation details, see the MediaPlayer and Stagefright components\n located in `frameworks/av/media`.\n\nOpenMAX Integration Layer (IL)\n: The OpenMAX IL provides a standardized way for Stagefright to recognize and\n use custom hardware-based multimedia codecs called components. You must provide\n an OpenMAX plugin in the form of a shared library named\n `libstagefrighthw.so`. This plugin links Stagefright with your custom\n codec components, which must be implemented according to the OpenMAX IL\n component standard.\n\nImplement custom codecs\n-----------------------\n\nStagefright comes with built-in software codecs for common media formats, but\nyou can also add your own custom hardware codecs as OpenMAX components. To do\nthis, you must create the OMX components and an OMX plugin that hooks together\nyour custom codecs with the Stagefright framework. For example components, see\nthe `hardware/ti/omap4xxx/domx/`; for an example plugin for the\nGalaxy Nexus, see `hardware/ti/omap4xx/libstagefrighthw`.\n\nTo add your own codecs:\n\n1. Create your components according to the OpenMAX IL component standard. The component interface is located in the `frameworks/native/include/media/OpenMAX/OMX_Component.h` file. To learn more about the OpenMAX IL specification, refer to the [OpenMAX website](http://www.khronos.org/openmax/).\n2. Create a OpenMAX plugin that links your components with the Stagefright service. For the interfaces to create the plugin, see `frameworks/native/include/media/hardware/OMXPluginBase.h` and `HardwareAPI.h` header files.\n3. Build your plugin as a shared library with the name `libstagefrighthw.so` in your product Makefile. For example: \n\n ```\n LOCAL_MODULE := libstagefrighthw\n ```\n\n In your device's Makefile, ensure you declare the module as a product\n package: \n\n ```\n PRODUCT_PACKAGES += \\\n libstagefrighthw \\\n ...\n ```\n\nExpose codecs to the framework\n------------------------------\n\nThe Stagefright service parses the `system/etc/media_codecs.xml`\nand `system/etc/media_profiles.xml` to expose the supported codecs\nand profiles on the device to app developers via the\n`android.media.MediaCodecList` and\n`android.media.CamcorderProfile` classes. You must create both files\nin the `device/\u003ccompany\u003e/\u003cdevice\u003e/` directory\nand copy this over to the system image's `system/etc` directory in\nyour device's Makefile. For example: \n\n```\nPRODUCT_COPY_FILES += \\\n device/samsung/tuna/media_profiles.xml:system/etc/media_profiles.xml \\\n device/samsung/tuna/media_codecs.xml:system/etc/media_codecs.xml \\\n```\n\nFor complete examples, see `device/samsung/tuna/media_codecs.xml`\nand `device/samsung/tuna/media_profiles.xml` .\n\n**Note:** As of Android 4.1, the\n`\u003cQuirk\u003e` element for media codecs is no longer supported."]]