提交 5a50a250 编写于 作者: jinlong0603's avatar jinlong0603

修复sps、pps错误、重复问题

上级 2032abc3
...@@ -64,7 +64,7 @@ public class RecordService extends Service implements EasyIPCamera.IPCameraCallB ...@@ -64,7 +64,7 @@ public class RecordService extends Service implements EasyIPCamera.IPCameraCallB
private int mChannelId = 1; private int mChannelId = 1;
private int mChannelState = 0; private int mChannelState = 0;
private int mFrameRate = 25; private int mFrameRate = 20;
private int mBitRate; private int mBitRate;
private Context mApplicationContext; private Context mApplicationContext;
private boolean codecAvailable = false; private boolean codecAvailable = false;
...@@ -109,7 +109,7 @@ public class RecordService extends Service implements EasyIPCamera.IPCameraCallB ...@@ -109,7 +109,7 @@ public class RecordService extends Service implements EasyIPCamera.IPCameraCallB
Log.d(TAG, String.format("kim createEnvironment Size=%dx%d", windowWidth, windowHeight)); Log.d(TAG, String.format("kim createEnvironment Size=%dx%d", windowWidth, windowHeight));
EncoderDebugger debugger = EncoderDebugger.debug(mApplicationContext, windowWidth, windowHeight); EncoderDebugger debugger = EncoderDebugger.debug(mApplicationContext, windowWidth, windowHeight, mFrameRate);
mSps = Base64.decode(debugger.getB64SPS(), Base64.NO_WRAP); mSps = Base64.decode(debugger.getB64SPS(), Base64.NO_WRAP);
mPps = Base64.decode(debugger.getB64PPS(), Base64.NO_WRAP); mPps = Base64.decode(debugger.getB64PPS(), Base64.NO_WRAP);
mH264Buffer = new byte[(int) (windowWidth*windowHeight*1.5)]; mH264Buffer = new byte[(int) (windowWidth*windowHeight*1.5)];
...@@ -119,9 +119,9 @@ public class RecordService extends Service implements EasyIPCamera.IPCameraCallB ...@@ -119,9 +119,9 @@ public class RecordService extends Service implements EasyIPCamera.IPCameraCallB
* 初始化编码器 * 初始化编码器
*/ */
private void initMediaCodec() { private void initMediaCodec() {
mFrameRate = 25; mFrameRate = 20;
mBitRate = 1200000; mBitRate = 1200000;
EncoderDebugger debugger = EncoderDebugger.debug(mApplicationContext, windowWidth, windowHeight); EncoderDebugger debugger = EncoderDebugger.debug(mApplicationContext, windowWidth, windowHeight, mFrameRate);
mSps = Base64.decode(debugger.getB64SPS(), Base64.NO_WRAP); mSps = Base64.decode(debugger.getB64SPS(), Base64.NO_WRAP);
mPps = Base64.decode(debugger.getB64PPS(), Base64.NO_WRAP); mPps = Base64.decode(debugger.getB64PPS(), Base64.NO_WRAP);
} }
...@@ -195,11 +195,8 @@ public class RecordService extends Service implements EasyIPCamera.IPCameraCallB ...@@ -195,11 +195,8 @@ public class RecordService extends Service implements EasyIPCamera.IPCameraCallB
outputBuffer.get(outData); outputBuffer.get(outData);
mPpsSps = outData; mPpsSps = outData;
} else if (type == 5) { } else if (type == 5) {
//在关键帧前面加上pps和sps数据 outputBuffer.get(mH264Buffer, 0, mBufferInfo.size);
//在关键帧前面加上pps和sps数据 mEasyIPCamera.pushFrame(mChannelId, EasyIPCamera.FrameFlag.EASY_SDK_VIDEO_FRAME_FLAG, System.currentTimeMillis(), mH264Buffer, 0, mBufferInfo.size);
System.arraycopy(mPpsSps, 0, mH264Buffer, 0, mPpsSps.length);
outputBuffer.get(mH264Buffer, mPpsSps.length, mBufferInfo.size);
mEasyIPCamera.pushFrame(mChannelId, EasyIPCamera.FrameFlag.EASY_SDK_VIDEO_FRAME_FLAG, System.currentTimeMillis(), mH264Buffer, 0,mPpsSps.length+mBufferInfo.size);
} else { } else {
outputBuffer.get(mH264Buffer, 0, mBufferInfo.size); outputBuffer.get(mH264Buffer, 0, mBufferInfo.size);
if (System.currentTimeMillis() - timeStamp >= 3000) { if (System.currentTimeMillis() - timeStamp >= 3000) {
......
...@@ -109,7 +109,7 @@ public class EasyIPCamera { ...@@ -109,7 +109,7 @@ public class EasyIPCamera {
} }
public int active(Context context){ public int active(Context context){
String key = "6D72754B7A4A36526D343041344B68597031636670655276636D63755A57467A65575268636E64706269356C59584E356158426A5957316C636D4658444661672F365867523246326157346D516D466962334E68514449774D545A4659584E355247467964326C75564756686257566863336B3D"; String key = "6D72754B7A4A36526D34324142665259707776364A655276636D63755A57467A65575268636E64706269356C59584E356158426A5957316C636D4658444661672F365867523246326157346D516D466962334E68514449774D545A4659584E355247467964326C75564756686257566863336B3D";
int iRet = active(key, context); int iRet = active(key, context);
if(iRet != 0){ if(iRet != 0){
Log.e(TAG, "Key invalid! active failed!!! return : " + iRet); Log.e(TAG, "Key invalid! active failed!!! return : " + iRet);
......
...@@ -44,7 +44,7 @@ public class MediaStream implements EasyIPCamera.IPCameraCallBack { ...@@ -44,7 +44,7 @@ public class MediaStream implements EasyIPCamera.IPCameraCallBack {
EasyIPCamera mEasyIPCamera; EasyIPCamera mEasyIPCamera;
static final String TAG = "MediaStream"; static final String TAG = "MediaStream";
int width = 640, height = 480; int width = 640, height = 480;
int framerate = 25; int framerate = 20;
int bitrate; int bitrate;
int mCameraId = Camera.CameraInfo.CAMERA_FACING_BACK; int mCameraId = Camera.CameraInfo.CAMERA_FACING_BACK;
MediaCodec mMediaCodec; MediaCodec mMediaCodec;
...@@ -279,11 +279,9 @@ public class MediaStream implements EasyIPCamera.IPCameraCallBack { ...@@ -279,11 +279,9 @@ public class MediaStream implements EasyIPCamera.IPCameraCallBack {
outputBuffer.get(outData, 0, bufferInfo.size); outputBuffer.get(outData, 0, bufferInfo.size);
mPpsSps = outData; mPpsSps = outData;
} else if (type == 5) { } else if (type == 5) {
//在关键帧前面加上pps和sps数据 outputBuffer.get(h264, 0, bufferInfo.size);
System.arraycopy(mPpsSps, 0, h264, 0, mPpsSps.length);
outputBuffer.get(h264, mPpsSps.length, bufferInfo.size);
if(mChannelState == EasyIPCamera.ChannelState.EASY_IPCAMERA_STATE_REQUEST_PLAY_STREAM) { if(mChannelState == EasyIPCamera.ChannelState.EASY_IPCAMERA_STATE_REQUEST_PLAY_STREAM) {
mEasyIPCamera.pushFrame(mChannelId, EasyIPCamera.FrameFlag.EASY_SDK_VIDEO_FRAME_FLAG, bufferInfo.presentationTimeUs / 1000, h264, 0, mPpsSps.length + bufferInfo.size); mEasyIPCamera.pushFrame(mChannelId, EasyIPCamera.FrameFlag.EASY_SDK_VIDEO_FRAME_FLAG, bufferInfo.presentationTimeUs / 1000, h264, 0, bufferInfo.size);
} }
} else { } else {
outputBuffer.get(h264, 0, bufferInfo.size); outputBuffer.get(h264, 0, bufferInfo.size);
...@@ -508,9 +506,9 @@ public class MediaStream implements EasyIPCamera.IPCameraCallBack { ...@@ -508,9 +506,9 @@ public class MediaStream implements EasyIPCamera.IPCameraCallBack {
* 初始化编码器 * 初始化编码器
*/ */
private void initMediaCodec() { private void initMediaCodec() {
framerate = 25; framerate = 20;
bitrate = 2 * width * height * framerate / 20; bitrate = 2 * width * height * framerate / 20;
EncoderDebugger debugger = EncoderDebugger.debug(mApplicationContext, width, height); EncoderDebugger debugger = EncoderDebugger.debug(mApplicationContext, height, width, framerate);
mConvertor = debugger.getNV21Convertor(); mConvertor = debugger.getNV21Convertor();
mSps = Base64.decode(debugger.getB64SPS(), Base64.NO_WRAP); mSps = Base64.decode(debugger.getB64SPS(), Base64.NO_WRAP);
...@@ -518,7 +516,7 @@ public class MediaStream implements EasyIPCamera.IPCameraCallBack { ...@@ -518,7 +516,7 @@ public class MediaStream implements EasyIPCamera.IPCameraCallBack {
} }
private void startMediaCodec() { private void startMediaCodec() {
EncoderDebugger debugger = EncoderDebugger.debug(mApplicationContext, width, height); EncoderDebugger debugger = EncoderDebugger.debug(mApplicationContext, height, width, framerate);
try { try {
mMediaCodec = MediaCodec.createByCodecName(debugger.getEncoderName()); mMediaCodec = MediaCodec.createByCodecName(debugger.getEncoderName());
MediaFormat mediaFormat; MediaFormat mediaFormat;
...@@ -672,6 +670,7 @@ public class MediaStream implements EasyIPCamera.IPCameraCallBack { ...@@ -672,6 +670,7 @@ public class MediaStream implements EasyIPCamera.IPCameraCallBack {
buffer.putInt(mSps.length); buffer.putInt(mSps.length);
buffer.putInt(mPps.length); buffer.putInt(mPps.length);
buffer.putInt(0); buffer.putInt(0);
buffer.put(mVps); buffer.put(mVps);
buffer.put(mSps,0,mSps.length); buffer.put(mSps,0,mSps.length);
......
...@@ -82,12 +82,12 @@ public class EncoderDebugger { ...@@ -82,12 +82,12 @@ public class EncoderDebugger {
/** /**
* Bitrate that will be used with the encoder. * Bitrate that will be used with the encoder.
*/ */
private final static int BITRATE = 1000000; private static int BITRATE = 1000000;
/** /**
* Framerate that will be used to test the encoder. * Framerate that will be used to test the encoder.
*/ */
private final static int FRAMERATE = 20; private static int FRAMERATE = 20;
private final static String MIME_TYPE = "video/avc"; private final static String MIME_TYPE = "video/avc";
...@@ -121,9 +121,11 @@ public class EncoderDebugger { ...@@ -121,9 +121,11 @@ public class EncoderDebugger {
}).start(); }).start();
} }
public synchronized static EncoderDebugger debug(Context context, int width, int height) { public synchronized static EncoderDebugger debug(Context context, int width, int height, int framerate) {
SharedPreferences prefs = PreferenceManager SharedPreferences prefs = PreferenceManager
.getDefaultSharedPreferences(context); .getDefaultSharedPreferences(context);
FRAMERATE = framerate;
BITRATE = 2* width*height*FRAMERATE/20;
return debug(prefs, width, height); return debug(prefs, width, height);
} }
...@@ -240,6 +242,12 @@ public class EncoderDebugger { ...@@ -240,6 +242,12 @@ public class EncoderDebugger {
reset(); reset();
mEncoderName = encoders[i].name; mEncoderName = encoders[i].name;
//2017.02.20
// fix: ignore sw encoder
if (mEncoderName.contains("google.h264.encoder"))
continue;
mEncoderColorFormat = encoders[i].formats[j]; mEncoderColorFormat = encoders[i].formats[j];
if (VERBOSE) if (VERBOSE)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册