本文主要记录阅读源码的部分心得
源码地址 : https://github.com/google/grafika
我的:https://github.com/CL-window/openGL_learn.git
这个代码虽然有一段时间了,但是其中的关于相机部分 还是很值得看一下的
1. mp4播放:PlayMovieActivity TextureView
PlayMovieSurfaceActivity in SurfaceView
MediaExtractor 分解音视频
MediaCodec 播放,需要设置输出的 Surface
decoder.configure(format, mOutputSurface, null, 0);
// 对输入的数据流进行编码或者解码处理
decoder.dequeueInputBuffer // 获得这个用来作为媒体文件源码的ByteBuffer(从输入的buffers的数组中)的索引位置
decoder.queueInputBuffer // 使用带有媒体文件源码的ByteBuffer之后,通过调用此方法来释放缓存区的所有权
decoder.dequeueOutputBuffer // 获得你接收到结果的ByteBuffer的索引位置
decoder.releaseOutputBuffer // 释放所有权
1.1 需要在 UI线程执行的代码 可以 通过 Handler.sendMessage 实现
// Send message through Handler so it runs on the right thread.
mLocalHandler.sendMessage(mLocalHandler.obtainMessage(MSG_PLAY_STOPPED, mFeedback));
private static class LocalHandler extends Handler {
@Override
public void handleMessage(Message msg) {
int what = msg.what;
switch (what) {
case MSG_PLAY_STOPPED:
PlayerFeedback fb = (PlayerFeedback) msg.obj;
fb.playbackStopped();
break;
default:
throw new RuntimeException("Unknown msg " + what);
}
}
}
3. TextureFromCameraActivity
支持 缩放 大小 旋转 改变
主要是 Sprite2d 这个类 Matrix 提供的方法,通过 translateM ,rotateM,scaleM变化一个 4*4 的矩阵
这个类使用的是Matrix
float[] modelView = mModelViewMatrix;
Matrix.setIdentityM(modelView, 0);
Matrix.translateM(modelView, 0, mPosX, mPosY, 0.0f);
if (mAngle != 0.0f) {
Matrix.rotateM(modelView, 0, mAngle, 0.0f, 0.0f, 1.0f);
}
Matrix.scaleM(modelView, 0, mScaleX, mScaleY, 1.0f);