private Ffmpeg ffmpeg = Ffmpeg.getInstance();
private Boolean isRunning = false;
- //private FfmpegRunnable runnable;
private Camera mCamera = null;
IBinder mBinder = new LocalBinder();
private String rtmpUrl;
- //private WindowManager mWindowManager;
- //private SurfaceView mOutComeVideoView;
private long frameCount = 0;
gLogger.error("Preview Format: " + paras.getPreviewFormat() + ". Size: " + paras.getPreviewSize().width + "x" + paras.getPreviewSize().height);
gLogger.error("Picture Format: " + paras.getPictureFormat() + ". Size: " + paras.getPictureSize().width + "x" + paras.getPictureSize().height);
camera.setPreviewCallback(this);
- //camera.startPreview();
}
}
-
-// private class FfmpegRunnable implements Runnable {
-// private String url;
-// private Camera.PreviewCallback cb;
-// public FfmpegRunnable(String _url, Camera.PreviewCallback _cb){
-// this.url = _url;
-// this.cb = _cb;
-// }
-// @Override
-// public void run(){
-// gLogger.error("Run Ffmpeg url: " + url);
-// isRunning = true;
-// gLogger.error("Open camera");
-// mCamera = getCameraInstance();
-// if(mCamera == null) {
-// gLogger.error("Open camera, camera is null");
-// }
-// configCamera(mCamera);
-// mCamera.setPreviewCallback(this.cb);
-// }
-// }
AVPacket enc_pkt;
AVFrame *pFrameYUV;
+void javaPrint(JNIEnv *env, jobject obj, const char* str)
+{
+ jclass clazz = (*env).GetObjectClass(obj);
+ jobject mobj = env->NewGlobalRef(obj);
+ jmethodID mmid = env->GetMethodID(clazz, "print", "(Ljava/lang/String;)V");
+ jstring jstr = env->NewStringUTF(str);
+ env->CallVoidMethod(mobj, mmid, jstr);
+ env->DeleteLocalRef(jstr);
+}
+
+JNIEnv *g_env;
+jobject g_obj;
+
+void custom_log222 (void *ptr, int level, const char* fmt, va_list vl){
+ static int print_prefix = 1;
+ char line[1024];
+ av_log_format_line(ptr, level, fmt, vl, line, sizeof(line), &print_prefix);
+ if (level <= AV_LOG_WARNING){
+ LOGE("%s", line);
+ javaPrint(g_env, g_obj, line);
+ } else {
+ //LOGE("%s", line);
+ //javaPrint(g_env, g_obj, line);
+ }
+}
void custom_log(void *ptr, int level, const char* fmt, va_list vl){
//To TXT file
if (level <= AV_LOG_WARNING){
LOGE("%s", line);
+
+
} else {
- LOGE("%s", line);
+// LOGE("%s", line);
}
}
//out_path = env->GetStringUTFChars(url, 0);
}
+
+
+
+//#defind JLOGE(s) javaPrint(env, obj, (s));
+
+
JNIEXPORT jint JNICALL Java_ai_suanzi_rtmpclient_Ffmpeg_initnew (JNIEnv *env, jobject obj, jint width, jint height, jstring url)
{
const char * out_path= env->GetStringUTFChars(url, 0);
LOGE("Ffmpeg init, width=%d, heigh=%d, url=%s", width, height, out_path);
+ javaPrint(env, obj, "Ffmpeg init");
yuv_width=width;
yuv_height=height;
av_register_all();
+ avformat_network_init();
+ g_env = env;
+ g_obj = obj;
+ av_log_set_callback(custom_log222);
+
//output initialize
avformat_alloc_output_context2(&ofmt_ctx, NULL, "flv", out_path);
pCodec = avcodec_find_encoder(AV_CODEC_ID_H264);
if (!pCodec){
LOGE("Can not find encoder!\n");
+ javaPrint(env, obj, "Can not find encoder!");
return -1;
}
pCodecCtx = avcodec_alloc_context3(pCodec);
if (avcodec_open2(pCodecCtx, pCodec, ¶m) < 0){
LOGE("Failed to open encoder!\n");
+ javaPrint(env, obj, "Failed to open encoder!");
return -1;
}
jint ret = 0;
if (( ret = avio_open(&ofmt_ctx->pb, out_path, AVIO_FLAG_READ_WRITE)) < 0){
LOGE("Failed to open output file! return :%s(%d)\n", av_err2str(ret),ret);
+ javaPrint(env, obj, "Failed to open output file! return!");
return -1;
}
if (enc_got_frame == 1){
if (framecnt % (15 * 60) == 0){
LOGE("Succeed to encode frame: %5d\tsize:%5d\n", framecnt, enc_pkt.size);
+ javaPrint(env, obj, "Succeed to encode frame:");
+
}
framecnt++;
enc_pkt.stream_index = video_st->index;