下图是整个MediaExtractor需要实现的方法和类,在后续的篇章会逐渐解释这些方法和类
下图是整个MediaExtractor需要实现的方法和类,在后续的篇章会逐渐解释这些方法和类

extractor.drawio
前提
通过 MediaExtractor启动流程 可以知道, 当系统服务加载MediaExtractor插件时,会找到so库中的GETEXTRACTORDEF方法获得Extractor的定义接口指针.因此用FFmpeg实现Android中的MediaExtractor,先得实现一个GETEXTRACTORDEF,再回顾下GETEXTRACTORDEF的定义
// // frameworks/av/include/media/MediaExtractorPluginApi.h
typedef ExtractorDef (*GetExtractorDef)();
先介绍下**ExtractorDef**. ExtractorDef 是MediaExtractor 插件体系里的一个结构体定义,用来描述一个“抽取器插件”的元信息和能力。它告诉系统 : 我这个 extractor 是谁、版本是多少、叫什么名字、怎么探测文件、支持哪些类型。
// frameworks/av/include/media/MediaExtractorPluginApi.h
struct ExtractorDef {
// version number of this structure
const uint32_t def_version;
// A unique identifier for this extractor.
// See below for a convenience macro to create this from a string.
media_uuid_t extractor_uuid;
// Version number of this extractor. When two extractors with the same
// uuid are encountered, the one with the largest version number will
// be used.
const uint32_t extractor_version;
// a human readable name
const char *extractor_name;
union {
struct {
SnifferFunc sniff;
} v2;
struct {
SnifferFunc sniff;
// a NULL terminated list of container mime types and/or file extensions
// that this extractor supports
const char **supported_types;
} v3;
} u;
};
-
def_version:这个 ExtractorDef 结构体自身的版本号,不是 extractor 插件内容版本,比如// the C++ based API which first shipped in P and is no longer supported // 该版本已不在收到支持 const uint32_t EXTRACTORDEF_VERSION_LEGACY = 1; // the first C/NDK based API // 这里对应的其实就是ExtractorDef中union中的v2 const uint32_t EXTRACTORDEF_VERSION_NDK_V1 = 2; // the second C/NDK based API // 这里对应的其实就是ExtractorDef中union中的v3 const uint32_t EXTRACTORDEF_VERSION_NDK_V2 = 3; // 默认是EXTRACTORDEF_VERSION_NDK_V2,即默认使用union中的v3 const uint32_t EXTRACTORDEF_VERSION = EXTRACTORDEF_VERSION_NDK_V2; -
extractor_uuid: 可以使用uuidgen直接生成一个,用以extractor的唯一标识符astro@Server:~/Ford/vendor/zlsmart/proprietary/media$ uuidgen f6292d66-7e3e-4a25-9506-269b5f629180 -
extractor_version:代表了插件实现的版本号(区别于 def_version 结构体格式版本)。
当系统加载到两个 extractor_uuid 相同的插件时,会选择
extractor_version更大的那个,因此插件升级时只需保持 UUID 不变并递增版本号即可 -
extractor_name: 人类可读的插件名称 -
一个
union:sniffer: 方法指针,用以读取文件开头或特征数据, 判断这个文件是不是该 extractor 支持的格式kExtensions: 这是一个以 NULL 结尾的字符串数组,表示该 extractor 支持的类型列表
再看下SnifferFunc的定义:
// The sniffer can optionally fill in an opaque object, "meta", that helps
// the corresponding extractor initialize its state without duplicating
// effort already exerted by the sniffer. If "freeMeta" is given, it will be
// called against the opaque object when it is no longer used.
// 插件用来探测文件类型的函数签名
typedef CreatorFunc (*SnifferFunc)(
CDataSource *source, float *confidence,
void **meta, FreeMetaFunc *freeMeta);
参数:
-
CDataSource *source: 输入参数, 表示待探测的数据源。// 框架提供给插件的“文件/流读取接口” struct
293



被折叠的 条评论
为什么被折叠?



