您当前的位置: 首页 > 学无止境 > 心得笔记 网站首页心得笔记
9. FFDecode的Open打开解码器接口编写和Observer基类添加~1
发布时间:2021-06-09 15:53:34编辑:雪饮阅读()
解码器接口其实上篇就实现了,只是有个地方需要注意下cpp/FFDecode.cpp:
{
#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};
//errbuf_size:其长度为sizeof(buf)-1,因为最后一位不能用,万一它用来做\0
av_strerror(re,buf,sizeof(buf)-1);
XLOGE("%s",buf);
return false;
}
XLOGI("avcodec_open2 success!");
return true;
}
nia不管不管,只要魅族16T成功运行即可
#include <string>
#include "FFDemux.h"
#include "XLog.h"
#include "FFDecode.h"
class TestObs:public IObserver
{
public:
void Update(XData d)
{
XLOGI("TestObs Update data size is %d",d.size);
}
};
extern "C" JNIEXPORT jstring JNICALL
Java_com_example_xplay_MainActivity_stringFromJNI(
JNIEnv* env,
jobject /* this */) {
std::string hello = "Hello from C++";
TestObs *tobs = new TestObs();
IDemux *de = new FFDemux();
de->AddObs(tobs);
de->Open("/sdcard/1080.mp4");
IDecode *vdecode = new FFDecode();
de->Start();
XSleep(3000);
de->Stop();
return env->NewStringUTF(hello.c_str());
}
关键字词:Observer