Android 安卓NDK-fread

Android 安卓NDK-fread,android,android-ndk,Android,Android Ndk,我写这个问题,因为我在任何ForoO助手的寻呼机中都没有看到,我有一个应用程序,它有两个基本功能,我一步一步地登录c和在控制台中编写 我在我的应用程序中有两个案例,我称这一行为“死线”,它是一行代码使所有功能都失败,当尝试调用时,不终止这一行 案例1:(“死线”是指评论。) 第五个函数(“setArrayByteYUV”)在文件中写入一个缓冲区(这使得pefect没有问题),它很简单,epp可以将字节的反数组传递给c,并写入文件: 此函数在4.2-5.0-6.0 android(板条箱文件和

我写这个问题,因为我在任何ForoO助手的寻呼机中都没有看到,我有一个应用程序,它有两个基本功能,我一步一步地登录c和在控制台中编写

我在我的应用程序中有两个案例,我称这一行为“死线”,它是一行代码使所有功能都失败,当尝试调用时,不终止这一行

案例1:(“死线”是指评论。)

  • 第五个函数(“setArrayByteYUV”)在文件中写入一个缓冲区(这使得pefect没有问题),它很简单,epp可以将字节的反数组传递给c,并写入文件:

    • 此函数在4.2-5.0-6.0 android(板条箱文件和写入缓冲区)中运行
    • 在控制台中写入所有日志
  • 第二个函数(“RenderProcessor”)按文件读取缓冲区,以前写入,请注意:

    • 此函数在4.2-5.0-6.0 android(打开文件)中运行
    • 在控制台中写入所有日志
案例2:(“死线”不是评论。)

  • 第五个函数(setArrayByteYUV)在文件中写入一个缓冲区(这使pefect没有问题),它很简单,我可以将字节的反数组传递给c,并写入文件:

    • 此函数在4.2-5.0-6.0 android(板条箱文件)中运行
    • 在控制台中写入所有日志
  • 第二个函数(RenderProcessor)按文件读取缓冲区,以前写入,但请注意:

    • 此函数在4.2 android中运行,通过文件读取缓冲区并查找进程,但在5.0-6.0 android中,调用此函数时失败(Dosen not fial在“LINE DEAD”中调用函数失败)
    • 在控制台4.2android中写入所有日志,但在5.0-6.0android中,当调用此函数时失败,并且不会从该函数写入任何日志。PD:失败时,不从函数RenderProcessOther写入任何日志,就像函数不退出一样
在所有编译情况下,在ndk构建的复杂过程中永远不要失败(案例注释为“死线”或非注释为“死线”)

我尝试使用fgets和fread,但在所有方面都是一样的:在4.2运行并读取文件中,在5.0-6.0中,如果setArrayByteYUV中的“死线”不是commet,则会失败

注:该进程是写和读的,它没有问题,运行时出错,并且编译良好

如果我的代码需要“try”或“catch”,那么在5.0-6.0中验证“If”或“u”其他东西以使其工作“fread”“deadline”

代码C:

#include <jni.h>
#include <stdlib.h>
#include <android/log.h>
#include <pthread.h>
#include <stdio.h>
#include<string.h>
#include <stdlib.h>
#define APPNAME "MyApp"
#define EMPTY (0)




static jint *c_arrayPrincipal;
static jint **c_arrayMain;
static jint *rgbDataGlobal;

int startThread = 0;
int in = 0;
int inByte = 0;
int lengthglobal =0;
int rgbDataFinal[15000000];
jint lenVector = 0;




JNIEXPORT jint
Java_com_example_android_camera2basic_utils_Utils_setArrayByteYUV(JNIEnv* env, jobject thiz, jbyteArray arrY, jbyteArray arrU, jbyteArray arrV, jint indexP, jint width, jint height, jstring javaString){
 const char *nativeString = (*env)->GetStringUTFChars(env, javaString, 0);
    int w = width;
    int h = height;
    int sz = w * h;
    int             i;
    int             j;
    int             Y;
    int             Cr = 0;
    int             Cb = 0;
    int             pixPtr = 0;
    int             jDiv2 = 0;
    int             R = 0;
    int             G = 0;
    int             B = 0;
    int             cOff;
    int ind = 0;
    int nind = lenVector;
    int p = 0;
    jsize lenY = (*env)->GetArrayLength(env, arrY);
    jsize lenU = (*env)->GetArrayLength(env, arrU);
    jsize lenV = (*env)->GetArrayLength(env, arrV);
    char arr[lenY];
    int rgbData2[sz];
    int counter =0;

    __android_log_print(ANDROID_LOG_VERBOSE, APPNAME, "lenY: number: = %d",lenY);
    __android_log_print(ANDROID_LOG_VERBOSE, APPNAME, "lenU: number: = %d",lenU);
    __android_log_print(ANDROID_LOG_VERBOSE, APPNAME, "lenV: number: = %d",lenV);

    //file/
    int lstr = 0;
    int mychar = 0;
    FILE *pfileY = NULL;
    FILE *pfileU = NULL;
    FILE *pfileV = NULL;

    char filenameconY[sizeof  "/data/data/com.example.android.camera2basic/ls/myfile%04d-y.txt"];
    char filenameconU[sizeof  "/data/data/com.example.android.camera2basic/ls/myfile%04d-y.txt"];
    char filenameconV[sizeof  "/data/data/com.example.android.camera2basic/ls/myfile%04d-y.txt"];
    //sprintf(filenamecon, "/storage/emulated/legacy/ls/myfile%04d.txt", indexP);
    sprintf(filenameconY, "/data/data/com.example.android.camera2basic/ls/myfile%04d-y.txt", indexP);
    sprintf(filenameconU, "/data/data/com.example.android.camera2basic/ls/myfile%04d-u.txt", indexP);
    sprintf(filenameconV, "/data/data/com.example.android.camera2basic/ls/myfile%04d-v.txt", indexP);
    __android_log_print(ANDROID_LOG_VERBOSE, APPNAME, "setArrayByte: number: = %d",1);
    __android_log_print(ANDROID_LOG_VERBOSE, APPNAME, "setArrayByte: number: = %s",filenameconY);
    __android_log_print(ANDROID_LOG_VERBOSE, APPNAME, "setArrayByte: number: = %s",filenameconU);
    __android_log_print(ANDROID_LOG_VERBOSE, APPNAME, "setArrayByte: number: = %s",filenameconV);
            //pfilecon = fopen(filenamecon, "a");

    jboolean isCopy;
    jbyte* c_arrayY = (*env)->GetByteArrayElements(env, arrY, &isCopy);
    jbyte* c_arrayU = (*env)->GetByteArrayElements(env, arrU, &isCopy);
    jbyte* c_arrayV = (*env)->GetByteArrayElements(env, arrV, &isCopy);

            //File
    pfileY = fopen(filenameconY, "w");
    pfileU = fopen(filenameconU, "w");
    pfileV = fopen(filenameconV, "w");
    if(pfileY == NULL)
    {
       __android_log_print(ANDROID_LOG_VERBOSE, APPNAME, "Error null file: = %d",2);
    }
    __android_log_print(ANDROID_LOG_VERBOSE, APPNAME, "setArrayByte: number: = %d",2);

    fwrite(c_arrayY , 1 , lenY+1 , pfileY );
    fwrite(c_arrayU , 1 , lenU+1 , pfileU );
    fwrite(c_arrayV , 1 , lenV+1 , pfileV );
    __android_log_print(ANDROID_LOG_VERBOSE, APPNAME, "setArrayByte: number: = %d",3);
    (*env)->ReleaseStringUTFChars(env, javaString, nativeString);
    (*env)->DeleteLocalRef(env,javaString);
    __android_log_print(ANDROID_LOG_VERBOSE, APPNAME, "setArrayByte: number: = %d",4);
    fclose(pfileY);
    fclose(pfileU);
    fclose(pfileV);
    (*env)->ReleaseByteArrayElements(env, arrY, c_arrayY, 0);
    (*env)->DeleteLocalRef(env,arrY);
    (*env)->ReleaseByteArrayElements(env, arrU, c_arrayU, 0);
    (*env)->DeleteLocalRef(env,arrU);
    (*env)->ReleaseByteArrayElements(env, arrV, c_arrayV, 0);
    (*env)->DeleteLocalRef(env,arrV);
    __android_log_print(ANDROID_LOG_VERBOSE, APPNAME, "setArrayByte: number: = %d",5);

    return 0;
}




JNIEXPORT jintArray JNICALL
                    Java_com_example_android_camera2basic_utils_Utils_RenderProcessOther(JNIEnv * env, jobject obj, jint number, jint width, jint height, jint api)
{
    __android_log_print(ANDROID_LOG_VERBOSE, APPNAME, "RenderProcessOtherYUV: api: = %d",api);
    const char *nativeString = "";

    int w = width;
    int h = height;
    int sz = w * h;
    int             i;
    int             j;
    int             Y;
    int             Cr = 0;
    int             Cb = 0;
    int             pixPtr = 0;
    int             jDiv2 = 0;
    int             R = 0;
    int             G = 0;
    int             B = 0;
    int             cOff;
    int ind = 0;
    int nind = lenVector;
    int p = 0;
    char arr[15000000];
    int rgbData2[sz];
    int counter =0;
    int indexP =0;
    char arrY[15000000];
    char arrU[15000000];
    char arrV[15000000];
    int rgbDataFinalR[15000000];

    if(api!=0) {
        __android_log_print(ANDROID_LOG_VERBOSE, APPNAME, "RenderProcessOtherYUV: api IF: = %d",sz);
        __android_log_print(ANDROID_LOG_VERBOSE, APPNAME, "RenderProcessOther2: number: = %d",1);
        __android_log_print(ANDROID_LOG_VERBOSE, APPNAME, "RenderProcessOther: number: = %d",2);
        rgbDataGlobal = (jint*)calloc(lenVector, sizeof(jint));
        int lstr = 0;
        int mychar = 0;
        __android_log_print(ANDROID_LOG_VERBOSE, APPNAME, "RenderProcessOther: number: = %d",3);
        int nnumber = (int)number;
        __android_log_print(ANDROID_LOG_VERBOSE, APPNAME, "RenderProcessOther: nnumber: = %d",4);
        for(indexP=1; indexP<nnumber;indexP++){
            //filename =
            //printf(filename, "/storage/emulated/legacy/ls/myfile%d.txt", (int)indexP);
            pixPtr = 0;
            char filenameconY[sizeof  "/data/data/com.example.android.camera2basic/ls/myfile%04d-y.txt"];
            char filenameconU[sizeof  "/data/data/com.example.android.camera2basic/ls/myfile%04d-y.txt"];
            char filenameconV[sizeof  "/data/data/com.example.android.camera2basic/ls/myfile%04d-y.txt"];
            //sprintf(filenamecon, "/storage/emulated/legacy/ls/myfile%04d.txt", indexP);
            sprintf(filenameconY, "/data/data/com.example.android.camera2basic/ls/myfile%04d-y.txt", indexP);
            sprintf(filenameconU, "/data/data/com.example.android.camera2basic/ls/myfile%04d-u.txt", indexP);
            sprintf(filenameconV, "/data/data/com.example.android.camera2basic/ls/myfile%04d-v.txt", indexP);
            __android_log_print(ANDROID_LOG_VERBOSE, APPNAME, "setArrayByte: number: = %d",1);
            __android_log_print(ANDROID_LOG_VERBOSE, APPNAME, "setArrayByte: number: = %s",filenameconY);
            __android_log_print(ANDROID_LOG_VERBOSE, APPNAME, "setArrayByte: number: = %s",filenameconU);
            __android_log_print(ANDROID_LOG_VERBOSE, APPNAME, "setArrayByte: number: = %s",filenameconV);

            FILE* fileY = fopen(filenameconY, "r");
            FILE* fileU = fopen(filenameconU, "r");
            FILE* fileV = fopen(filenameconV, "r");
            __android_log_print(ANDROID_LOG_VERBOSE, APPNAME, "RenderProcessOther: indexP 4: = %d",indexP);
            int n = sizeof(arrY);
            __android_log_print(ANDROID_LOG_VERBOSE, APPNAME, "sizeof: sizeof 4: = %d",n);
            if(n !=0){
                n = sizeof(arrY)/sizeof(arrY[0]);
                int step = (int)api;
                int size = w * h;
                for (i = 0; i<h; i++)
                {
                    for (j=0; j<w; j++)
                    {
                        float Y = arrY[i*step + j];
                        float U = arrU[ (int)(size + (i/2)*(step/2)  + j/2) ];
                        float V = arrV[ (int)(size*1.25 + (i/2)*(step/2) + j/2)];
                        float R = Y + (int)(1.772f*V);
                        float G = Y - (int)(0.344f*V + 0.714f*U);
                        float B = Y + (int)(1.402f*U);

                        if (R < 0){
                            R = 0;
                        }
                        if (G < 0){
                            G = 0;
                        } if (B < 0){
                            B = 0;
                        }
                        if (R > 255 ){
                            R = 255;
                        }
                        if (G > 255) {
                            G = 255;
                        } if (B > 255) {
                            B = 255;
                        }
                        int rint = (int)R;
                        int gint = (int)G;
                        int bint = (int)B;
                        int rgbDataPixel = 0xff000000 + (bint << 16) + (gint << 8) + rint;
                        rgbDataFinalR[pixPtr] = (int)rgbDataPixel;
                        pixPtr++;
                    }
                }

                fclose(fileY);
                fclose(fileU);
                fclose(fileV);
                __android_log_print(ANDROID_LOG_VERBOSE, APPNAME, "RenderProcessOther2: nnumber for close: = %d",indexP);
                remove(filenameconY);
                remove(filenameconU);
                remove(filenameconV);
                __android_log_print(ANDROID_LOG_VERBOSE, APPNAME, "RenderProcessOther2: nnumber for remove: = %d",4);

            }

        }

    }else{

        __android_log_print(ANDROID_LOG_VERBOSE, APPNAME, "RenderProcessOtherYUV: api ELSE: = %d",sz);
        __android_log_print(ANDROID_LOG_VERBOSE, APPNAME, "RenderProcessOther: number: = %d",1);
        rgbDataGlobal = (jint*)calloc(lenVector, sizeof(jint));
        int lstr = 0;
        int mychar = 0;
        char *filename = NULL;
        __android_log_print(ANDROID_LOG_VERBOSE, APPNAME, "RenderProcessOther: number: = %d",1);
        int nnumber = (int)number;
        __android_log_print(ANDROID_LOG_VERBOSE, APPNAME, "RenderProcessOther: nnumber: = %d",1);
        for(indexP=1; indexP<nnumber;indexP++){
            char filenamecon[sizeof "/storage/emulated/legacy/ls/myfile0000.txt"];
            sprintf(filenamecon, "/data/data/com.example.android.camera2basic/ls/myfile%04d-y.txt", indexP);
            __android_log_print(ANDROID_LOG_VERBOSE, APPNAME, "RenderProcessOther: number: = %s",filenamecon);
            FILE* file = fopen(filenamecon, "r");
            if(file ==NULL){
                __android_log_print(ANDROID_LOG_VERBOSE, APPNAME, "no existe RenderProcessOther: number: = %s",filenamecon);
            }

            /* DEAD LINE   */
            /* DEAD LINE  */
            /* DEAD LINE  */


            fread(arr, lenVector,0 , file); // <------- DEAD LINE 
            ///fgets(arr, lenVector, file) 

            /* DEAD LINE  */
            /* DEAD LINE  */
            /* DEAD LINE  */


            __android_log_print(ANDROID_LOG_VERBOSE, APPNAME, "RenderProcessOther: indexP 4: = %d",indexP);
            int n = sizeof(arr);
            __android_log_print(ANDROID_LOG_VERBOSE, APPNAME, "sizeof: sizeof 4: = %d",n);
             if(n !=0){
                n = sizeof(arr)/sizeof(arr[0]);
                for(j = 0; j < h; j++) {
                    pixPtr = j * w;
                    jDiv2 = j >> 1;
                    for(i = 0; i < w; i++) {
                        counter++;
                        Y = arr[pixPtr];
                        if(Y < 0) Y += 255;
                        if((i & 0x1) != 1) {
                            cOff = sz + jDiv2 * w + (i >> 1) * 2;
                            Cb = arr[cOff];
                            if(Cb < 0) Cb += 127; else Cb -= 128;
                            Cr = arr[cOff + 1];
                            if(Cr < 0) Cr += 127; else Cr -= 128;
                        }
                        R = Y + Cr + (Cr >> 2) + (Cr >> 3) + (Cr >> 5);//1.406*~1.403
                        if(R < 0) R = 0; else if(R > 255) R = 255;
                        G = Y - (Cb >> 2) + (Cb >> 4) + (Cb >> 5) - (Cr >> 1) + (Cr >> 3) + (Cr >> 4) + (Cr >> 5);//
                        if(G < 0) G = 0; else if(G > 255) G = 255;
                        B = Y + Cb + (Cb >> 1) + (Cb >> 2) + (Cb >> 6);//1.765~1.770
                        if(B < 0) B = 0; else if(B > 255) B = 255;
                        if(indexP==0){
                            rgbDataFinal[pixPtr++] = 0xff000000 + (B << 16) + (G << 8) + R;
                        }else{
                            int pixPtrIndex = pixPtr++;
                            int rgbDataPixel = 0xff000000 + (B << 16) + (G << 8) + R;
                            int  color = rgbDataPixel;
                            int r = color & 0xff;
                            int g = (color >> 8) & 0xff;
                            int b = (color >> 16) & 0xff;
                            int a = (color >> 24) & 0xff;
                            int  color2 = rgbDataFinal[pixPtrIndex];
                            int r2 = color2 & 0xff;
                            int g2 = (color2 >> 8) & 0xff;
                            int b2 = (color2 >> 16) & 0xff;
                            int a2 = (color2 >> 24) & 0xff;
                            double ad = a - a2;
                            double rd = r - r2;
                            double gd = g - g2;
                            double bd = b- b2;
                            double ar = a2/a;
                            double rr = r2/r;
                            double gr = g2/g;
                            double br = b2/b;
                            if(a2<a|| r2<r|| g2<g || b2<b) {
                                double coeficiente = 0.5;
                                double d =(r - ((r - r2)*coeficiente));
                                int red1 = (int) d;
                                d =(g - ((g - g2)*coeficiente));
                                int green1 =  (int)d;
                                d =(b - ((b - b2)*coeficiente));
                                int blue1 =  (int)d;
                                int renderRGBDataPixel = 0xff000000 + (blue1 << 16) + (green1 << 8) + red1;
                                rgbDataFinal[pixPtrIndex] = renderRGBDataPixel;
                            }
                        }
                    }
                }
                fclose(file);
                remove(filenamecon);
            }

        }


    };


    for (i = 0; i < sz; ++i) {
        rgbDataGlobal[i]= rgbDataFinal[i];
    }
    jintArray jArray = (*env)->NewIntArray(env, sz);
    if (jArray != NULL) {
        jint u;
        u =0;
        (*env)->SetIntArrayRegion(env, jArray, 0, sz,rgbDataGlobal);
    }

    return jArray;
}
Application.mk

APP_ABI := armeabi armeabi-v7a mips x86
APP_PLATFORM := android-21
格雷德尔先生

android {
    compileSdkVersion 23
    buildToolsVersion "24.0.0 rc3"

    defaultConfig {
        minSdkVersion 17
        targetSdkVersion 23
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_7
        targetCompatibility JavaVersion.VERSION_1_7
    }

}
android {
    compileSdkVersion 23
    buildToolsVersion "24.0.0 rc3"

    defaultConfig {
        minSdkVersion 17
        targetSdkVersion 23
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_7
        targetCompatibility JavaVersion.VERSION_1_7
    }

}