大大们好
我最近在做ffmpeg解码h.264视频相关的东西,目前要实现的是用ffmpeg播放h.264的流,播放一路已经实现了,但我想播放多路时,就会出现FATAL SIGNAL的错误,然后程序挂掉。
VView是JNI接口类,我把它设计成一个单例模式的东东,然后开几个线程调用VView.getDecoder.decoderNal()方法来解码数据,并用这些数据来播放。
不知道我的思路是否正确,请大大们帮忙看下 :)
我最近在做ffmpeg解码h.264视频相关的东西,目前要实现的是用ffmpeg播放h.264的流,播放一路已经实现了,但我想播放多路时,就会出现FATAL SIGNAL的错误,然后程序挂掉。
VView是JNI接口类,我把它设计成一个单例模式的东东,然后开几个线程调用VView.getDecoder.decoderNal()方法来解码数据,并用这些数据来播放。
不知道我的思路是否正确,请大大们帮忙看下 :)
public class VView {
private static final String TAG = "UERY";
private static VView mDecoder;
private int mWidth = 352;
private int mHeight = 288;
private boolean mReady = false;
// JNI methods h264.com.VView
static {
System.loadLibrary("H264Android");
}
public static VView getDecoder() {
if (mDecoder == null) {
mDecoder = new VView();
}
return mDecoder;
}
public void setVideoWidthAndHeight(int width, int height) {
if (width > 0 && height > 0 && width != mWidth && height != mHeight) {
mWidth = width;
mHeight = height;
Log.i(TAG, "Decoder -> set width:" + width + " height:" + height);
}
}
public int getVideoWidth() {
return mWidth;
}
public int getVideoHeight() {
return mHeight;
}
public boolean isReady() {
return mReady;
}
public synchronized int initDecoder() {
int result = 0;
if (!mReady) {
result = InitDecoder(mWidth, mHeight);
mReady = true;
}
return result;
}
public synchronized int decoderNal(byte[] in, int insize, byte[] out) {
return DecoderNal(in, insize, out);
}
public synchronized int uninitDecoder() {
int result = 0;
if (mReady) {
result = UninitDecoder();
mReady = false;
}
return result;
}
/*
* JNI methods
*/
private native int InitDecoder(int width, int height);
private native int UninitDecoder();
private native int DecoderNal(byte[] in, int insize, byte[] out);
}