C2ComponentStore
1. C2ComponentStore
这是 Codec 2.0 HAL 的抽象接口(frameworks/av/media/codec2/core/include/C2ComponentStore.h
)。
代表一个「组件工厂」,负责:
枚举当前可用的 Codec2 组件(解码器、编码器)。
创建组件(
createComponent()
)。创建接口对象(
createInterface()
)。
它本身只是一个 纯虚基类 (abstract class),并没有具体实现。
AOSP 里有个默认实现
C2PlatformComponentStore
,用于加载 Google 自带的软件 codec (比如 C2SoftAvcDec, C2SoftHevcEnc 等)。
所以 C2ComponentStore
是一个 标准定义,Android 框架通过它来访问 codec,而不会关心具体厂商的实现。
2. QC2ComponentStore
这是 高通(Qualcomm)在 AOSP 基础上实现的厂商版本。
位于 QTI 的源码中(通常在
vendor/qcom/opensource
或者hardware/qcom/media
里)。继承自
C2ComponentStore
,并实现了其中的接口,比如:createComponent()
→ 创建一个 Qualcomm 硬件加速 codec 对象。queryComponents()
→ 返回 Qualcomm 支持的编解码器列表。
QC2ComponentStore
通过 binderized Codec2.0 HAL(IComponentStore AIDL/HIDL) 暴露给 Android Framework。
也就是说,QC2ComponentStore
就是 Qualcomm 的 组件工厂实现,背后调用的是硬件驱动/NPU/DSP 的 codec。
3. 二者关系总结
C2ComponentStore:接口定义(Google AOSP,抽象类)。
QC2ComponentStore:厂商实现(Qualcomm,继承并实现 C2ComponentStore,用于硬件 codec)。
其他厂商(联发科 MTK、三星 Exynos 等)也会有自己的
MC2ComponentStore
或ExynosC2ComponentStore
,逻辑类似。
4. 常见误区澄清
C2ComponentStore
本身没有具体实现。
AOSP 默认实现是 C2PlatformComponentStore
,但这只是 Google 提供的软件 codec。
真正跑在手机硬件上的 codec,一般都来自厂商,比如 Qualcomm 的 QC2ComponentStore
。
C2Component
和 QC2Component
的关系,跟 C2ComponentStore
和 QC2ComponentStore
的关系基本一致:
1. C2Component
这是 Codec 2.0 的抽象接口(定义在 C2Component.h
)。
表示一个 实际的编解码器实例(而不是工厂)。
定义了组件的核心行为,比如:
queue_nb()
/queue()
→ 提交工作 (work item)。flush_sm()
→ 刷新队列。reset_sm()
→ 重置。release_sm()
→ 释放资源。
这些方法全部是 纯虚函数,没有具体实现。
所以,C2Component
只是一个统一的接口规范。
2. QC2Component
这是 Qualcomm 的 具体实现类,继承自 C2Component
。
封装了对 Qualcomm DSP/NPU/硬件 Codec 的调用。
会和 Qualcomm 自己的 codec driver / firmware 打交道。
例如:
QC2Component::queue_nb()
→ 实际会把 buffer/work 通过 Qualcomm 的 HAL 层下发到 DSP。QC2Component::release_sm()
→ 释放 Qualcomm 硬件资源。
3. 对照关系
C2ComponentStore
→ 抽象工厂接口。QC2ComponentStore
→ Qualcomm 的工厂实现。C2Component
→ 抽象组件接口。QC2Component
→ Qualcomm 的组件实现(由QC2ComponentStore
创建)。
4. 实际调用链
当 App 使用 MediaCodec
播放视频时,大概是这样:
MediaCodec (Java) ↓
Codec2Client (C++) ↓
IComponentStore (AIDL/HIDL) ↓
QC2ComponentStore::createComponent() ↓
QC2Component (具体硬件解码器实例) ↓
Qualcomm DSP/driver
1. Codec2Client
位置:frameworks/av/media/codec2/hidl/client/Codec2Client.cpp
(Android 14 已经迁移到 AIDL)。
它是 framework 与 Codec2.0 HAL(IComponentStore / IComponent)交互的客户端封装。
主要功能:
负责连接到
IComponentStore
(binderized HAL 服务)。调用
createComponent()
来实例化一个硬件/软件 codec(比如 QC2Component)。提供
Component
、Configurable
等子类,封装了 HAL 的 AIDL/HIDL 接口。
👉 简单说:Codec2Client 就是 HAL 客户端,直接和厂商的 C2ComponentStore / C2Component 打交道。
2. CCodec
位置:frameworks/av/media/codec2/sfplugin/CCodec.cpp
。
它是 Stagefright 层的一个 Adapter,让
MediaCodec
可以驱动Codec2.0
backend。继承自
MediaCodec
的基类CodecBase
。内部持有一个
Codec2Client::Component
对象,用来真正调用 HAL。功能:
在
MediaCodec
创建 codec 时,如果走 Codec2.0 路径,就会用CCodec
作为实现类。负责生命周期管理(init、start、stop、reset)。
负责 buffer queue 的组织,把
MediaCodec
层的 buffer 请求映射到 Codec2 HAL 的工作单元。
👉 简单说:CCodec 是 Stagefright 插件,实现了 MediaCodec 的统一接口;它内部通过 Codec2Client 来访问 HAL。
3. 两者关系总结
Codec2Client:
面向 HAL,封装 AIDL/HIDL,提供 API 给 framework 使用。
就像「钥匙」,能打开 HAL 的 codec 工厂和组件。
CCodec:
面向 Stagefright/MediaCodec 层,是 Codec2.0 的插件。
内部依赖
Codec2Client
去真正调用 HAL。就像「驾驶员」,通过 Codec2Client 去开车(HAL codec)。
4. 调用链示意
App↓ (Java)
MediaCodec↓ (native 层选择 CCodec 作为实现类)
CCodec↓ (创建 Codec2Client)
Codec2Client↓ (调用 AIDL/HIDL)
IComponentStore / IComponent (HAL)↓
QC2ComponentStore / QC2Component (厂商实现)↓
DSP / Driver / Hardware