提交 6e09bf98 authored 作者: autulin's avatar autulin

1.新增前置摄像头接口

2.新增队列清理机制
上级 494dae45
......@@ -84,7 +84,8 @@ public class DemoActivity extends AppCompatActivity implements
// 设置视频的宽高,比特率等
// MediaRecorderBase.SMALL_VIDEO_HEIGHT = mediaRecorderConfig.getSmallVideoHeight();
// MediaRecorderBase.SMALL_VIDEO_WIDTH = mediaRecorderConfig.getSmallVideoWidth();
// MediaRecorderBase.mVideoBitrate = mediaRecorderConfig.getVideoBitrate();
// MediaRecorderBase. = mediaRecorderConfig.getVideoBitrate();
MediaRecorderBase.QUEUE_MAX_SIZE = 20;
Log.i("debug", "SMALL_VIDEO_HEIGHT: " + MediaRecorderBase.SMALL_VIDEO_HEIGHT + ", SMALL_VIDEO_WIDTH:" + MediaRecorderBase.SMALL_VIDEO_WIDTH );
}
......@@ -101,13 +102,14 @@ public class DemoActivity extends AppCompatActivity implements
mMediaRecorder.setOnErrorListener(this);
mMediaRecorder.setOnPreparedListener(this);
// mMediaRecorder.setCameraFront();
// 设置输出
// String fileName = String.valueOf(System.currentTimeMillis());
// String fileName = "tttttt";
// mediaOutput = mMediaRecorder.setFileOutPut(fileName); //输出到文件,这里demo是/sdcard/pstest/tttttt.ps
int ssrc = 1;
mediaOutput = mMediaRecorder.setTcpOutPut("10.112.154.194", 8888, ssrc);
mediaOutput = mMediaRecorder.setUdpOutPut("10.210.100.76", 8888, ssrc);
mMediaRecorder.setSurfaceHolder(mSurfaceView.getHolder());
mMediaRecorder.prepare();
......
......@@ -171,9 +171,21 @@ void *GB28181Muxer::startEncode(void *obj) {
avpicture_fill((AVPicture *) pNewFrame, buf, gb28181Muxer->pCodecCtx->pix_fmt, gb28181Muxer->pCodecCtx->width,
gb28181Muxer->pCodecCtx->height);
int skipNum = 10;
while (!gb28181Muxer->is_end) {
uint8_t * new_buf;
//队列帧数过多直接跳过skipNum帧
if (gb28181Muxer->video_queue.size() > gb28181Muxer->arguments->queue_max) {
LOGW("[muxer][encode]queue is too big, clearing...")
for (int i = 0; i < skipNum; ++i) {
new_buf = *gb28181Muxer->video_queue.wait_and_pop();
delete new_buf;
}
continue;
}
int64_t st = getCurrentTime();
uint8_t * new_buf = *gb28181Muxer->video_queue.wait_and_pop();
new_buf = *gb28181Muxer->video_queue.wait_and_pop();
gb28181Muxer->custom_filter(gb28181Muxer, new_buf, pNewFrame);
delete new_buf;
......@@ -190,7 +202,7 @@ void *GB28181Muxer::startEncode(void *obj) {
ret = avcodec_send_frame(gb28181Muxer->pCodecCtx, pNewFrame);
}
int64_t et2 = getCurrentTime();
LOGI("fetch raw frame from queue time:%lld (video frame queue left:%d),in FFmpeg time:%lld.", et1 - st, gb28181Muxer->video_queue.size(), et2 - et1);
LOGI("[muxer][encode]fetch raw frame from queue time:%lld (video frame queue left:%d),in FFmpeg time:%lld.", et1 - st, gb28181Muxer->video_queue.size(), et2 - et1);
if (ret < 0) {
LOGE("send FFmpeg error:%d.", ret);
}
......
......@@ -32,7 +32,7 @@ Java_com_autulin_gb28181library_JNIBridge_initMuxer(JNIEnv *env, jclass type, js
jstring mediaBasePath_, jstring mediaName_,
jint filter, jint in_width, jint in_height,
jint out_width, jint out_height, jint frameRate,
jlong bit_rate, jint audioFrameLen, jint ssrc) {
jlong bit_rate, jint audioFrameLen, jint ssrc, jint queue_max) {
const char *ip = env->GetStringUTFChars(ip_, 0);
const char *mediaBasePath = env->GetStringUTFChars(mediaBasePath_, 0);
const char *mediaName = env->GetStringUTFChars(mediaName_, 0);
......@@ -45,6 +45,7 @@ Java_com_autulin_gb28181library_JNIBridge_initMuxer(JNIEnv *env, jclass type, js
arguments->port = port;
arguments->outType = outType;
arguments->ssrc = ssrc;
arguments->queue_max = queue_max;
size_t m_path_size = strlen(mediaBasePath) + strlen(mediaName) + strlen(MEDIA_FORMAT) + 1;
arguments->media_path = (char *) malloc(m_path_size + 1);
......
......@@ -19,6 +19,7 @@ typedef struct UserArguments {
int v_custom_format; //一些滤镜操作控制
int a_frame_len;
int ssrc;
int queue_max; //队列最大长度
JNIEnv *env; //env全局指针
JavaVM *javaVM; //jvm指针
jclass java_class; //java接口类的calss对象
......
......@@ -65,7 +65,8 @@ public class JNIBridge {
int frameRate,
long bit_rate,
int audioFrameLen,
int ssrc
int ssrc,
int queue_max
);
public static native int sendOneVideoFrame(byte[] data);
......
......@@ -161,6 +161,8 @@ public abstract class MediaRecorderBase implements Callback, PreviewCallback, IM
*/
protected static int mVideoBitrate = 580000;
public static int QUEUE_MAX_SIZE = 20;
public static int mSupportedPreviewWidth = 0;
/**
* 状态标记
......@@ -183,6 +185,19 @@ public abstract class MediaRecorderBase implements Callback, PreviewCallback, IM
}
/**
* 设置为后置摄像头
*/
public void setCameraBack() {
mCameraId = Camera.CameraInfo.CAMERA_FACING_BACK;
}
/**
* 设置为前置摄像头
*/
public void setCameraFront() {
mCameraId = Camera.CameraInfo.CAMERA_FACING_FRONT;
}
/**
* 设置预览输出SurfaceHolder
*
......
......@@ -86,7 +86,8 @@ public class MediaRecorderNative extends MediaRecorderBase implements MediaRecor
mFrameRate,
mVideoBitrate,
mAudioCollector.getFrameLen(),
mediaOutput.getSsrc()
mediaOutput.getSsrc(),
QUEUE_MAX_SIZE
);
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论