This source file includes following definitions.
- Java_com_enst_mp4box_mp4terminal_run
- ConvertCommandLine
#ifdef __cplusplus
extern "C" {
#endif
#include <android/log.h>
#include <jni.h>
#include "stdlib.h"
#include "stdio.h"
#include "string.h"
#define jniTAG "WRAPPER_JNI"
#define jniLOGV(X) __android_log_print(ANDROID_LOG_VERBOSE, jniTAG, X)
#define jniLOGI(X) __android_log_print(ANDROID_LOG_INFO, jniTAG, X)
#define jniLOGE(X) __android_log_print(ANDROID_LOG_ERROR, jniTAG, X)
char ** ConvertCommandLine( const char* sCommand, int* iNbArg );
JNIEXPORT void JNICALL Java_com_enst_mp4box_mp4terminal_run(JNIEnv * env, jobject obj, jstring sCommand)
{
jniLOGV("mp4terminal::start");
jboolean isCopy;
const char * sOriginalCommand = (*env)->GetStringUTFChars(env, sCommand, &isCopy);
jniLOGV("mp4terminal::command get back ok");
jniLOGV(sOriginalCommand);
int iNbArg = 0;
int i = 0;
char** sConvertedCommandLine;
sConvertedCommandLine = ConvertCommandLine( sOriginalCommand, &i );
jniLOGV("Convert command line done");
FILE* ferr = freopen( "/mnt/sdcard/stderrout.txt", "w", stderr );
FILE* fout = freopen( "/mnt/sdcard/stdout.txt", "w", stdout );
mp4boxMain(i, sConvertedCommandLine);
(*env)->ReleaseStringUTFChars(env, sCommand, sOriginalCommand);
jniLOGV("mp4terminal::end");
gf_fclose(ferr);
gf_fclose(fout);
}
char ** ConvertCommandLine( const char* sCommand, int* iNbArg )
{
int iLength = strlen( sCommand );
int iArgNumber = 1;
int i = 0;
char** pReturn;
int iPreviousPos = 0;
int k = 1;
int l = 0;
for ( i = 0; i < iLength ; i++ )
{
if( sCommand[i] == ' ' )
{
iArgNumber++;
}
}
iArgNumber++;;
pReturn = (char**)malloc(sizeof(char*)*iArgNumber);
pReturn[0] = (char*)malloc(sizeof( char) * ( 7 ));
strcpy( pReturn[0], "MP4Box" );
pReturn[0][6] = '\0';
for ( l = 0; l <= iLength ; l++ )
{
if( sCommand[l] == ' ' || l == ( iLength ) )
{
pReturn[k] = (char*)malloc(sizeof( char) * ( l - iPreviousPos + 1));
strncpy( pReturn[k], sCommand + iPreviousPos, l - iPreviousPos );
pReturn[k][l-iPreviousPos] = '\0';
iPreviousPos = l + 1;
k++;
}
}
*iNbArg = iArgNumber;
return pReturn;
}
#ifdef __cplusplus
}
#endif