|
|
|
@ -151,51 +151,6 @@ static void libenc_setEncoderResolution(JNIEnv* env, jobject thiz, jint out_widt
|
|
|
|
|
x264_ctx.height = out_height;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// For COLOR_FormatYUV420Planar
|
|
|
|
|
static jbyteArray libenc_NV21ToI420(JNIEnv* env, jobject thiz, jbyteArray frame, jint src_width,
|
|
|
|
|
jint src_height, jboolean need_flip, jint rotate_degree) {
|
|
|
|
|
jbyte* nv21_frame = env->GetByteArrayElements(frame, NULL);
|
|
|
|
|
|
|
|
|
|
if (!convert_to_i420(nv21_frame, src_width, src_height, need_flip, rotate_degree, FOURCC_NV21)) {
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int y_size = i420_scaled_frame.width * i420_scaled_frame.height;
|
|
|
|
|
jbyteArray i420Frame = env->NewByteArray(y_size * 3 / 2);
|
|
|
|
|
env->SetByteArrayRegion(i420Frame, 0, y_size * 3 / 2, (jbyte *) i420_scaled_frame.data);
|
|
|
|
|
|
|
|
|
|
env->ReleaseByteArrayElements(frame, nv21_frame, JNI_ABORT);
|
|
|
|
|
return i420Frame;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// For COLOR_FormatYUV420SemiPlanar
|
|
|
|
|
static jbyteArray libenc_NV21ToNV12(JNIEnv* env, jobject thiz, jbyteArray frame, jint src_width,
|
|
|
|
|
jint src_height, jboolean need_flip, jint rotate_degree) {
|
|
|
|
|
jbyte* nv21_frame = env->GetByteArrayElements(frame, NULL);
|
|
|
|
|
|
|
|
|
|
if (!convert_to_i420(nv21_frame, src_width, src_height, need_flip, rotate_degree, FOURCC_NV21)) {
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int ret = ConvertFromI420(i420_scaled_frame.y, i420_scaled_frame.width,
|
|
|
|
|
i420_scaled_frame.u, i420_scaled_frame.width / 2,
|
|
|
|
|
i420_scaled_frame.v, i420_scaled_frame.width / 2,
|
|
|
|
|
nv12_frame.data, nv12_frame.width,
|
|
|
|
|
nv12_frame.width, nv12_frame.height,
|
|
|
|
|
FOURCC_NV12);
|
|
|
|
|
if (ret < 0) {
|
|
|
|
|
LIBENC_LOGE("ConvertFromI420 failure");
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int y_size = nv12_frame.width * nv12_frame.height;
|
|
|
|
|
jbyteArray nv12Frame = env->NewByteArray(y_size * 3 / 2);
|
|
|
|
|
env->SetByteArrayRegion(nv12Frame, 0, y_size * 3 / 2, (jbyte *) nv12_frame.data);
|
|
|
|
|
|
|
|
|
|
env->ReleaseByteArrayElements(frame, nv21_frame, JNI_ABORT);
|
|
|
|
|
return nv12Frame;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// For COLOR_FormatYUV420Planar
|
|
|
|
|
static jbyteArray libenc_RGBAToI420(JNIEnv* env, jobject thiz, jbyteArray frame, jint src_width,
|
|
|
|
|
jint src_height, jboolean need_flip, jint rotate_degree) {
|
|
|
|
@ -291,31 +246,6 @@ static int x264_encode(struct YuvFrame *i420_frame, int64_t pts) {
|
|
|
|
|
return encode_nals(nal, nnal);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static jint libenc_NV21SoftEncode(JNIEnv* env, jobject thiz, jbyteArray frame, jint src_width,
|
|
|
|
|
jint src_height, jboolean need_flip, jint rotate_degree, jlong pts) {
|
|
|
|
|
jbyte* nv21_frame = env->GetByteArrayElements(frame, NULL);
|
|
|
|
|
|
|
|
|
|
if (!convert_to_i420(nv21_frame, src_width, src_height, need_flip, rotate_degree, FOURCC_NV21)) {
|
|
|
|
|
return JNI_ERR;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int es_len = x264_ctx.global_nal_header ? encode_global_nal_header() : x264_encode(&i420_scaled_frame, pts);
|
|
|
|
|
if (es_len <= 0) {
|
|
|
|
|
LIBENC_LOGE("Fail to encode nalu");
|
|
|
|
|
return JNI_ERR;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
jbyteArray outputFrame = env->NewByteArray(es_len);
|
|
|
|
|
env->SetByteArrayRegion(outputFrame, 0, es_len, (jbyte *) h264_es);
|
|
|
|
|
|
|
|
|
|
jclass clz = env->GetObjectClass(thiz);
|
|
|
|
|
jmethodID mid = env->GetMethodID(clz, "onSoftEncodedData", "([BJZ)V");
|
|
|
|
|
env->CallVoidMethod(thiz, mid, outputFrame, x264_ctx.pts, x264_ctx.is_key_frame);
|
|
|
|
|
|
|
|
|
|
env->ReleaseByteArrayElements(frame, nv21_frame, JNI_ABORT);
|
|
|
|
|
return JNI_OK;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static jint libenc_RGBASoftEncode(JNIEnv* env, jobject thiz, jbyteArray frame, jint src_width,
|
|
|
|
|
jint src_height, jboolean need_flip, jint rotate_degree, jlong pts) {
|
|
|
|
|
jbyte* rgba_frame = env->GetByteArrayElements(frame, NULL);
|
|
|
|
@ -397,13 +327,10 @@ static JNINativeMethod libenc_methods[] = {
|
|
|
|
|
{ "setEncoderGop", "(I)V", (void *)libenc_setEncoderGop },
|
|
|
|
|
{ "setEncoderBitrate", "(I)V", (void *)libenc_setEncoderBitrate },
|
|
|
|
|
{ "setEncoderPreset", "(Ljava/lang/String;)V", (void *)libenc_setEncoderPreset },
|
|
|
|
|
{ "NV21ToI420", "([BIIZI)[B", (void *)libenc_NV21ToI420 },
|
|
|
|
|
{ "NV21ToNV12", "([BIIZI)[B", (void *)libenc_NV21ToNV12 },
|
|
|
|
|
{ "RGBAToI420", "([BIIZI)[B", (void *)libenc_RGBAToI420 },
|
|
|
|
|
{ "RGBAToNV12", "([BIIZI)[B", (void *)libenc_RGBAToNV12 },
|
|
|
|
|
{ "openSoftEncoder", "()Z", (void *)libenc_openSoftEncoder },
|
|
|
|
|
{ "closeSoftEncoder", "()V", (void *)libenc_closeSoftEncoder },
|
|
|
|
|
{ "NV21SoftEncode", "([BIIZIJ)I", (void *)libenc_NV21SoftEncode },
|
|
|
|
|
{ "RGBASoftEncode", "([BIIZIJ)I", (void *)libenc_RGBASoftEncode },
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|