您当前的位置: 首页 > 学无止境 > 心得笔记 网站首页心得笔记
2. 完成Iplayer开始播放和窗口初始化接口~1
发布时间:2021-06-12 20:19:42编辑:雪饮阅读()
這次主要是改造IPlayer::Start()方法以實現門面的最大化,對用戶應該是最小化調用cpp/IPlayer.cpp:
#include "IDemux.h"
#include "IDecode.h"
#include "IAudioPlay.h"
#include "IVideoView.h"
#include "IResample.h"
#include "XLog.h"
IPlayer *IPlayer::Get(unsigned char index)
{
static IPlayer p[256];
return &p[index];
}
bool IPlayer::Open(const char *path)
{
//解封装
if(!demux || !demux->Open(path))
{
XLOGE("demux->Open %s failed!",path);
return false;
}
//解码 解码可能不需要,如果是解封之后就是原始数据
if(!vdecode || !vdecode->Open(demux->GetVPara(),isHardDecode))
{
XLOGE("vdecode->Open %s failed!",path);
//return false;
}
if(!adecode || !adecode->Open(demux->GetAPara()))
{
XLOGE("adecode->Open %s failed!",path);
//return false;
}
//重采样 有可能不需要,解码后或者解封后可能是直接能播放的数据
if(outPara.sample_rate <= 0)
outPara = demux->GetAPara();
if(!resample || !resample->Open(demux->GetAPara(),outPara))
{
XLOGE("resample->Open %s failed!",path);
}
return true;
}
bool IPlayer::Start()
{
if(!demux || !demux->Start())
{
XLOGE("demux->Start failed!");
return false;
}
if(adecode)
adecode->Start();
if(audioPlay)
audioPlay->StartPlay(outPara);
if(vdecode)
vdecode->Start();
return true;
}
void IPlayer::InitView(void *win)
{
if(videoView)
videoView->SetRender(win);
}
那麽接下來門面優化后的效果就顯而易見了,對於入口cpp/native-lib.cpp將是最小化的調用:
編譯運行v1080.mp4的解碼基本上是沒有什麽問題的
#define XPLAY_IPLAYER_H
#include "XThread.h"
#include "XParameter.h"
class IDemux;
class IAudioPlay;
class IVideoView;
class IResample;
class IDecode;
class IPlayer : public XThread
{
public:
static IPlayer *Get(unsigned char index=0);
virtual bool Open(const char *path);
virtual bool Start();
virtual void InitView(void *win);
//是否视频硬解码
bool isHardDecode = true;
//音频输出参数配置
XParameter outPara;
IDemux *demux = 0;
IDecode *vdecode = 0;
IDecode *adecode = 0;
IResample *resample = 0;
IVideoView *videoView = 0;
IAudioPlay *audioPlay = 0;
protected:
IPlayer(){};
};
#endif //XPLAY_IPLAYER_H
#include <string>
#include <android/native_window_jni.h>
#include "FFDemux.h"
#include "XLog.h"
#include "FFDecode.h"
#include "XEGL.h"
#include "XShader.h"
#include "IVideoView.h"
#include "GLVideoView.h"
#include "FFResample.h"
#include "IAudioPlay.h"
#include "SLAudioPlay.h"
#include "IPlayer.h"
IVideoView *view = NULL;
extern "C"
JNIEXPORT
jint JNI_OnLoad(JavaVM *vm,void *res)
{
FFDecode::InitHard(vm);
///////////////////////////////////
///测试用代码
IDemux *de = new FFDemux();
//de->AddObs(tobs);
//de->Open("/sdcard/1080.mp4");
IDecode *vdecode = new FFDecode();
//vdecode->Open(de->GetVPara(), true);
//vdecode->Open(de->GetVPara(), true);
IDecode *adecode = new FFDecode();
//adecode->Open(de->GetAPara());
de->AddObs(vdecode);
de->AddObs(adecode);
view = new GLVideoView();
vdecode->AddObs(view);
IResample *resample = new FFResample();
//XParameter outPara = de->GetAPara();
//resample->Open(de->GetAPara(),outPara);
adecode->AddObs(resample);
IAudioPlay *audioPlay = new SLAudioPlay();
//audioPlay->StartPlay(outPara);
resample->AddObs(audioPlay);
IPlayer::Get()->demux = de;
IPlayer::Get()->adecode = adecode;
IPlayer::Get()->vdecode = vdecode;
IPlayer::Get()->videoView = view;
IPlayer::Get()->resample = resample;
IPlayer::Get()->audioPlay = audioPlay;
IPlayer::Get()->Open("/sdcard/v1080.mp4");
IPlayer::Get()->Start();
//de->Start();
//vdecode->Start();
//adecode->Start();
return JNI_VERSION_1_4;
}
extern "C"
JNIEXPORT jstring
JNICALL
Java_com_example_xplay_MainActivity_stringFromJNI(
JNIEnv *env,
jobject /* this */) {
std::string hello = "Hello from C++";
//XLOGI("S begin!");
//XSleep(3000);
//XLOGI("S end!");
//return env->NewStringUTF(hello.c_str());
//XSleep(3000);
//de->Stop();
/*for(;;)
{
XData d = de->Read();
XLOGI("Read data size is %d",d.size);
}*/
return env->NewStringUTF(hello.c_str());
}
extern "C"
JNIEXPORT void JNICALL
Java_com_example_xplay_XPlay_InitView(JNIEnv *env, jobject instance, jobject surface) {
// TODO
ANativeWindow *win = ANativeWindow_fromSurface(env,surface);
view->SetRender(win);
IPlayer::Get()->InitView(win);
//XEGL::Get()->Init(win);
//XShader shader;
//shader.Init();
}
关键字词:Iplayer
相关文章
-
无相关信息