[英]How can I get the roles of codec information in Android NDK?
在Android 4.0(API級別15)中,沒有API可以獲取編解碼器列表。 新的API僅支持API級別16和更高版本。 但是我必須支持API級別15。因此,我必須使用JNI編寫一些引用此處的本機代碼。
struct OMXPluginBase {
OMXPluginBase() {}
virtual ~OMXPluginBase() {}
virtual void dummy1() = 0;
virtual void dummy2() = 0;
virtual OMX_ERRORTYPE enumerateComponents(
OMX_STRING name,
size_t size,
OMX_U32 index) = 0;
virtual OMX_ERRORTYPE getRolesOfComponent(
const char *name,
Vector<String8> *roles) = 0;
private:
OMXPluginBase(const OMXPluginBase &);
OMXPluginBase &operator=(const OMXPluginBase &);
};
獲取編解碼器信息名稱的代碼:
void *handle = dlopen("libstagefrighthw.so", RTLD_NOW);
if (handle == NULL) {
return -1;
}
typedef OMXPluginBase *(*CreateOMXPluginFunc)();
CreateOMXPluginFunc createOMXPlugin =
(CreateOMXPluginFunc)dlsym(handle, "createOMXPlugin");
if (!createOMXPlugin) {
createOMXPlugin = (CreateOMXPluginFunc)dlsym(
handle, "_ZN7android15createOMXPluginEv");
}
OMXPluginBase *plugin = (*createOMXPlugin)();
if (plugin) {
OMX_U32 index = -1;
char name[128];
OMX_ERRORTYPE err;
while ((err = plugin->enumerateComponents(name, sizeof(name),
++index)) == OMX_ErrorNone) {
printf("%s\n", name);
}
if (err != OMX_ErrorNoMore) {
printf("0x%x\n", err);
}
}
我可以得到編解碼器信息的名稱,因為名稱只是char *
類型。 但是,現在我想使用函數OMX_ERRORTYPE getRolesOfComponent(const char *name, Vector<String8> *roles)
獲取編解碼器信息的角色,但是我不能這樣做,因為roles
的類型為Vector<String8>
並且我沒有有這兩個班。 更嚴重的是,Android似乎未在某些共享庫(如libutils.so
提供這兩個類的實現。 那么,如何調用此函數並獲取所需的信息? 請幫我。 我整天都為此感到頭痛!
更新
感謝@Alex,終於解決了我的問題。 我把代碼放在這里 。 希望這對遇到同樣問題的人有所幫助。
android::Vector
和android::String8
都在libutils.so
中實現。
因此,如果可以鏈接到該庫,則可以編寫如下內容:
Vector<String8> roles;
err = plugin->getRolesOfComponent(name, &roles);
if (err == OMX_ErrorNone) {
for (int i=0; i<roles.size(); i++) {
printf(" %s\n", roles.array()[0].string());
}
}
不幸的是,我的實驗表明, getRolesOfComponent()
需要對Vector進行完全正確初始化的引用,因此,如果要保留所有通過dlopen()
對Android私有類的訪問,則需要手動調用構造函數(在libutils.so
dlopen()
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.