您当前的位置: 首页 > 学无止境 > 心得笔记 网站首页心得笔记
8. IDecode和FFDecode模块代码创建~1
发布时间:2021-06-09 15:27:15编辑:雪饮阅读()
封装解码器获取与具体的解码以及对于下一步的考量,对于FFDecode、Idecode、Xparameter的cpp或者头文件的完善。
# documentation: https://d.android.com/studio/projects/add-native-code.html
# Sets the minimum version of CMake required to build the native library.
cmake_minimum_required(VERSION 3.10.2)
# Declares and names the project.
project("xplay")
# Creates and names a library, sets it as either STATIC
# or SHARED, and provides the relative paths to its source code.
# You can define multiple libraries, and CMake builds them for you.
# Gradle automatically packages shared libraries with your APK.
#添加頭文件路徑(括號中的include是相對於本文件路徑)
include_directories(../../../include)
#設置ffmpeg庫所在路徑的變量,這裏的FF是自定義的一個名字
set(FF ${CMAKE_CURRENT_SOURCE_DIR}/../../../libs/${ANDROID_ABI})
#avcodec這個是自定義的一個名字
add_library(avcodec SHARED IMPORTED)
set_target_properties(avcodec PROPERTIES IMPORTED_LOCATION ${FF}/libavcodec.so)
add_library(avformat SHARED IMPORTED)
set_target_properties(avformat PROPERTIES IMPORTED_LOCATION ${FF}/libavformat.so)
add_library(avutil SHARED IMPORTED)
set_target_properties(avutil PROPERTIES IMPORTED_LOCATION ${FF}/libavutil.so)
add_library(swscale SHARED IMPORTED)
set_target_properties(swscale PROPERTIES IMPORTED_LOCATION ${FF}/libswscale.so)
add_library(swresample SHARED IMPORTED)
set_target_properties(swresample PROPERTIES IMPORTED_LOCATION ${FF}/libswresample.so)
add_library( # Sets the name of the library.
native-lib
# Sets the library as a shared library.
SHARED
# Provides a relative path to your source file(s).
#src/main/cpp/native-lib.cpp
IDemux
FFDemux
XData
XLog
native-lib.cpp
XThread
IObserver
FFDecode
IDecode
XParameter
)
# Searches for a specified prebuilt library and stores the path as a
# variable. Because CMake includes system libraries in the search path by
# default, you only need to specify the name of the public NDK library
# you want to add. CMake verifies that the library exists before
# completing its build.
find_library( # Sets the name of the path variable.
log-lib
# Specifies the name of the NDK library that
# you want CMake to locate.
log )
# Specifies libraries CMake should link to your target library. You
# can link multiple libraries, such as libraries you define in this
# build script, prebuilt third-party libraries, or system libraries.
target_link_libraries( # Specifies the target library.
native-lib
GLESv2 EGL
OpenSLES
android
avcodec avformat avutil swscale swresample
# Links the target library to the log library
# included in the NDK.
${log-lib} )
cpp/IDecode.h:
cpp/FFDecode.cpp:
cpp/FFDecode.h:
cpp/XParameter.h:
cpp/XParameter.cpp:
魅族16T编译运行没有问题:
#define XPLAY_IDECODE_H
#include "XParameter.h"
#include "IObserver.h"
//解码接口,支持硬解码
class IDecode:public IObserver
{
public:
//打开解码器
virtual bool Open(XParameter para) = 0;
};
#endif //XPLAY_IDECODE_H
{
#include <libavcodec/avcodec.h>
}
#include "FFDecode.h"
#include "XLog.h"
bool FFDecode::Open(XParameter para)
{
if(!para.para) return false;
AVCodecParameters *p = para.para;
//1 查找解码器
AVCodec *cd = avcodec_find_decoder(p->codec_id);
if(!cd)
{
XLOGE("avcodec_find_decoder %d failed!",p->codec_id);
return false;
}
XLOGI("avcodec_find_decoder success!");
//2 创建解码上下文,并复制参数
codec = avcodec_alloc_context3(cd);
avcodec_parameters_to_context(codec,p);
//3 打开解码器
int re = avcodec_open2(codec,0,0);
if(re != 0)
{
char buf[1024] = {0};
av_strerror(re,buf,sizeof(buf)-1);
XLOGE("%s",buf);
return false;
}
XLOGI("avcodec_open2 success!");
return true;
}
#define XPLAY_FFDECODE_H
#include "XParameter.h"
#include "IDecode.h"
struct AVCodecContext;
class FFDecode:public IDecode
{
public:
virtual bool Open(XParameter para);
protected:
AVCodecContext *codec = 0;
};
#endif //XPLAY_FFDECODE_H
#define XPLAY_XPARAMETER_H
struct AVCodecParameters;
class XParameter
{
public:
AVCodecParameters *para = 0;
};
#endif //XPLAY_XPARAMETER_H
关键字词:FFDecode
相关文章
-
无相关信息