80,361
社区成员
发帖
与我相关
我的任务
分享
package com.handlerun.view;
public class VView {
public native void LiveVideo(byte[] out);
public native int getSequence(byte[] out);
public native int InitDecoder();
public native int UninitDecoder();
public native int DecoderNal(byte[] in, int insize, byte[] out);
public native int Connectiondvs(String ip,int port);
public native int LoginCam(String username,String password);
public native int StopLive();
static {
System.loadLibrary("H264Android");
}
}
/* DO NOT EDIT THIS FILE - it is machine generated */
#include <jni.h>
/* Header for class com_handlerun_view_VView */
#ifndef _Included_com_handlerun_view_VView
#define _Included_com_handlerun_view_VView
#ifdef __cplusplus
extern "C" {
#endif
/*
* Class: com_handlerun_view_VView
* Method: LiveVideo
* Signature: (I[B)I
*/
JNIEXPORT jint JNICALL Java_com_handlerun_view_VView_LiveVideo
(JNIEnv *env, jobject obj, jbyteArray out);
/*
* Class: com_handlerun_view_VView
* Method: getSequence
* Signature: ([B)I
*/
JNIEXPORT jint JNICALL Java_com_handlerun_view_VView_getSequence
(JNIEnv *env, jobject obj, jbyteArray out);
/*
* Class: com_handlerun_view_VView
* Method: InitDecoder
* Signature: ()I
*/
JNIEXPORT jint JNICALL Java_com_handlerun_view_VView_InitDecoder
(JNIEnv *env, jobject obj);
/*
* Class: com_handlerun_view_VView
* Method: UninitDecoder
* Signature: ()I
*/
JNIEXPORT jint JNICALL Java_com_handlerun_view_VView_UninitDecoder
(JNIEnv *env, jobject obj);
/*
* Class: com_handlerun_view_VView
* Method: DecoderNal
* Signature: ([BI[B)I
*/
JNIEXPORT jint JNICALL Java_com_handlerun_view_VView_DecoderNal
(JNIEnv *env, jobject obj, jbyteArray in, jint nallen, jbyteArray out);
/*
* Class: com_handlerun_view_VView
* Method: Connectiondvs
* Signature: (Ljava/lang/String;I)I
*/
JNIEXPORT jint JNICALL Java_com_handlerun_view_VView_Connectiondvs
(JNIEnv *env, jobject obj, jstring ip, jint port);
/*
* Class: com_handlerun_view_VView
* Method: LoginCam
* Signature: (Ljava/lang/String;Ljava/lang/String;)I
*/
JNIEXPORT jint JNICALL Java_com_handlerun_view_VView_LoginCam
(JNIEnv *env, jobject obj, jstring username, jstring password);
/*
* Class: com_handlerun_view_VView
* Method: StopLive
* Signature: ()I
*/
JNIEXPORT jint JNICALL Java_com_handlerun_view_VView_StopLive
(JNIEnv *env, jobject obj);
#ifdef __cplusplus
}
#endif
#endif
int portNum=NULL;//端口
char ipAdress=NULL;//IP地址
char u_name=NULL;//摄像头用户名
char pwd=NULL;//密码
JNIEXPORT jint JNICALL Java_com_handlerun_view_VView_LoginCam
(JNIEnv *env,jobject obj,jstring username,jstring password)
{
pwd =(char*)(*env)->GetStringUTFChars(env,password, NULL);
u_name=(char*)(*env)->GetStringUTFChars(env,username, NULL);
char um="admin";
char pd="123456";
int a=strcmp(um,u_name);
int b=strcmp(pd,password);
if(a==0&&b==0)
{
return 0;
}else{
return 1;
}
}
int portNum=NULL;//端口
char ipAdress=NULL;//IP地址
char u_name=NULL;//摄像头用户名
char pwd=NULL;//密码
JNIEXPORT jint JNICALL Java_com_handlerun_view_VView_LoginCam
(JNIEnv *env,jobject obj,jstring username,jstring password)
{
pwd =(char*)(*env)->GetStringUTFChars(env,password, NULL);
u_name=(char*)(*env)->GetStringUTFChars(env,username, NULL);
char um="admin";
char pd="123456";
int a=strcmp(um,u_name);
int b=strcmp(pd,password);
if(a==0&&b==0)
{
return 0;
}else{
return 1;
}
int portNum=NULL;//端口
char *ipAdress=NULL;//IP地址
char *u_name=NULL;//摄像头用户名
char *pwd=NULL;//密码
u_name=(char*)(*env)->GetStringUTFChars(env,username, NULL);
pwd =(char*)(*env)->GetStringUTFChars(env,password, NULL);
char *pd="123456";
char *um="admin";
int a=strcmp(um,u_name);
int b=strcmp(pd,password);
if(a==0&&b==0)
{
return 0;
}else{
return 1;
}
JNIEXPORT jint JNICALL Java_com_handlerun_view_VView_Connectiondvs
(JNIEnv *env, jobject obj, jstring ip, jint port)
{
ipAdress=(char*)(*env)->GetStringUTFChars(env,ip, NULL);
portNum=++port;//HTTP端口加1是tcp端口
return 1;
}
package com.handlerun.view;
import java.nio.ByteBuffer;
import android.app.Activity;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Matrix;
import android.graphics.Paint;
import android.graphics.Bitmap.Config;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
public class H264Android extends Activity {
VView vv;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
vv = new VView(this);
setContentView(vv);
}
// Menu item Ids
public static final int PLAY_ID = Menu.FIRST;
public static final int EXIT_ID = Menu.FIRST + 1;
@Override
public boolean onCreateOptionsMenu(Menu menu) {
super.onCreateOptionsMenu(menu);
menu.add(0, PLAY_ID, 0, R.string.play);
menu.add(0, EXIT_ID, 1, R.string.exit);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case PLAY_ID:
{
String file = "/sdcard/free.264";
vv.PlayVideo(file);
return true;
}
case EXIT_ID:
{
finish();
return true;
}
}
return super.onOptionsItemSelected(item);
}
}
class VView extends View implements Runnable{
Bitmap mBitQQ = null;
Paint mPaint = null;
Bitmap mSCBitmap = null;
Matrix matrix = new Matrix();
byte [] mPixel = new byte[288*352*2];
ByteBuffer buffer = ByteBuffer.wrap( mPixel );
Bitmap VideoBit = Bitmap.createBitmap(352, 288, Config.RGB_565);
VView v = this;
int mTrans=0x0F0F0F0F;
public native int InitDecoder();
public native int UninitDecoder();
public native int DecoderNal(byte[] in, int insize, byte[] out);
public native void LiveVideo(byte[] out);
public native int getSequence(byte[] out);
public native int Connectiondvs(String ip,int port);
//public native int Login(String username,String password);
public native int LoginCam(String username,String password);
public native int StopLive();
static
{
System.loadLibrary("H264Android");
}
/**
* 构造函数
*/
public VView(Context context) {
super(context);
setFocusable(true);
int i = mPixel.length;
for(i=0; i<mPixel.length; i++)
{
mPixel[i]=(byte)0x00;
}
}
/**
* 播放视频
* @param file
*/
public void PlayVideo(String file)
{
String uName="admin";
String pWd="123456";
int connect=Connectiondvs("192.168.1.170",5014);
System.out.println("connect+++"+connect);
int lo=LoginCam(uName, pWd);
System.out.println("login+++"+lo);
if(lo==1&&connect==1){
new Thread(this).start();
new Thread(new Video()).start();
}
}
@Override protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
VideoBit.copyPixelsFromBuffer(buffer);//makeBuffer(data565, N));
canvas.drawBitmap(VideoBit, 0, 0, null);
}
public void updateUI()
{
postInvalidate();
}
public void run()
{
byte[] index ={0};
int getIndex = 0;
int beforeIndex = 0;
while (!Thread.currentThread().isInterrupted())
{
getIndex = getSequence(index);
//System.out.println("getIndex++++"+getIndex);
if(getIndex!=0&&getIndex!=beforeIndex)
{
System.out.println(" #################################### ");
//运行测试内容
long t1= System.currentTimeMillis();
updateUI();
long t2= System.currentTimeMillis();
// System.out.println("******** tiem " + (t2-t1));
beforeIndex = getIndex ;
}
}
}
public void sayHello()
{
System.out.println("****************#####################################################");
}
class Video implements Runnable{
public void run() {
// TODO Auto-generated method stub
LiveVideo(mPixel);
}
}
}
int lo=LoginCam(uName, pWd);
就会报错空指针。。。而和LoginCam这个函数很相似的函数Connectiondvs却不报错。而且可以输出connect+++1的结果。