移植到OPhone(2)
时间:2011-01-08 BlogJava 银河使者
4.开发环境(请参考: http://www.ophonesdn.com/documentation/)
5.移植过程
5.1 移植流程
5.2 封装Java接口
在“假定前提”中提到了要移植的函数,接下来会编写这些 函数的Java Native Interface。
package ophone.streaming.video.h264;
import java.nio.ByteBuffer;
public class H264decode {
//H264解码库指针,因为Java没有指针一说,所以这里用一个32位的数来存放指针的值
private long H264decode = 0;
static{
System.loadLibrary("H264Decode");
}
public H264decode() {
this.H264decode = Initialize();
}
public void Cleanup() {
Destroy(H264decode);
}
public int DecodeOneFrame(ByteBuffer pInBuffer,ByteBuffer pOutBuffer) {
return DecodeOneFrame(H264decode, pInBuffer, pOutBuffer);
}
private native static int DecodeOneFrame(long H264decode,ByteBuffer pInBuffer,ByteBuffer pOutBuffer);
private native static long Initialize();
private native static void Destroy(long H264decode);
}
这块没什么好说的,就是按照H264解码库的函数,封装的一层接口,如果你熟悉Java JNI,会发现原来是这么类似。这里插入一句:我一直认为技术都是相通的,底层的技术就那么几种,学懂了,其它技术都是一通百通。
送箪悶殻會蝕窟岻H264盾鷹匂卞峅欺OPhone(3)
扮寂:2011-01-08 BlogJava 咢采聞宀
5.3 聞喘C糞?云仇圭隈
5.3.1伏撹遊猟周
聞喘javah凋綜伏撹JNI遊猟周?宸戦俶勣廣吭頁class揃抄音頁坿旗鷹議揃抄?旺拝勣紗貧淫兆?
宸戦伏撹阻匯倖ophone_streaming_video_h264_H264decode.h?厘断嬉蝕栖心心?
#include <jni.h>
#ifndef _Included_ophone_streaming_video_h264_H264decode
#define _Included_ophone_streaming_video_h264_H264decode
#ifdef __cplusplus
extern "C" {
#endif
JNIEXPORT jint JNICALL Java_ophone_streaming_video_h264_H264decode_DecodeOneFrame
(JNIEnv *, jclass, jlong, jobject, jobject);
JNIEXPORT jlong JNICALL Java_ophone_streaming_video_h264_H264decode_Initialize
(JNIEnv *, jclass);
JNIEXPORT void JNICALL Java_ophone_streaming_video_h264_H264decode_Destroy
(JNIEnv *, jclass, jlong);
#ifdef __cplusplus
}
#endif
#endif
5.3.2 糞?云仇圭隈
岻念厮将伏撹阻JNI遊猟周?俊和栖峪俶勣糞?宸倖遊猟周議叱倖擬竃痕方?宸戦參H264盾鷹匂議糞?葎箭?
#include "ophone_streaming_video_h264_H264decode.h"
#include "H264Decode.h"
JNIEXPORT jint JNICALL Java_ophone_streaming_video_h264_H264decode_DecodeOneFrame
(JNIEnv * env, jclass obj, jlong decode, jobject pInBuffer, jobject pOutBuffer) {
H264Decode *pDecode = (H264Decode *)decode;
unsigned char *In = NULL;unsigned char *Out = NULL;
unsigned int InPosition = 0;unsigned int InRemaining = 0;unsigned int InSize = 0;
unsigned int OutSize = 0;
jint DecodeSize = -1;
jbyte *InJbyte = 0;
jbyte *OutJbyte = 0;
|