Home | History | Annotate | Download | only in mediaeditor
      1 /*
      2  * Copyright (C) 2011 The Android Open Source Project
      3  *
      4  * Licensed under the Apache License, Version 2.0 (the "License");
      5  * you may not use this file except in compliance with the License.
      6  * You may obtain a copy of the License at
      7  *
      8  *      http://www.apache.org/licenses/LICENSE-2.0
      9  *
     10  * Unless required by applicable law or agreed to in writing, software
     11  * distributed under the License is distributed on an "AS IS" BASIS,
     12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13  * See the License for the specific language governing permissions and
     14  * limitations under the License.
     15  */
     16 
     17 #define LOG_TAG "VideoEditorJava"
     18 
     19 #include <VideoEditorClasses.h>
     20 #include <VideoEditorJava.h>
     21 #include <VideoEditorLogging.h>
     22 #include <VideoEditorOsal.h>
     23 
     24 extern "C" {
     25 #include <M4OSA_CharStar.h>
     26 };
     27 
     28 
     29 void
     30 videoEditJava_checkAndThrowIllegalArgumentExceptionFunc(
     31                 bool*                               pResult,
     32                 JNIEnv*                             pEnv,
     33                 bool                                condition,
     34                 const char*                         pMessage,
     35                 const char*                         pFile,
     36                 int                                 lineNo)
     37 {
     38     // Check if the previous action succeeded.
     39     if (*pResult)
     40     {
     41         // Check if the condition is true.
     42         if (condition)
     43         {
     44             // Log the exception.
     45             VIDEOEDIT_LOG_EXCEPTION(ANDROID_LOG_ERROR, "VIDEO_EDITOR_JAVA",\
     46                     "videoEditJava_checkAndThrowIllegalArgumentException, %s (%s:%d)",
     47                     pMessage, pFile, lineNo);
     48 
     49             // Reset the result flag.
     50             (*pResult) = false;
     51 
     52             // Throw an exception.
     53             jniThrowException(pEnv, "java/lang/IllegalArgumentException", pMessage);
     54         }
     55     }
     56 }
     57 
     58 void
     59 videoEditJava_checkAndThrowRuntimeExceptionFunc(
     60                 bool*                               pResult,
     61                 JNIEnv*                             pEnv,
     62                 bool                                condition,
     63                 M4OSA_ERR                           result,
     64                 const char*                         pFile,
     65                 int                                 lineNo
     66                 )
     67 {
     68     const char* pMessage = NULL;
     69 
     70     // Check if the previous action succeeded.
     71     if (*pResult)
     72     {
     73         // Check if the condition is true.
     74         if (condition)
     75         {
     76             // Get the error string.
     77             pMessage = videoEditJava_getErrorName(result);
     78 
     79             // Log the exception.
     80             VIDEOEDIT_LOG_EXCEPTION(ANDROID_LOG_ERROR, "VIDEO_EDITOR_JAVA",
     81                     "videoEditJava_checkAndThrowRuntimeException, %s (%s:%d)",
     82                     pMessage, pFile, lineNo);
     83 
     84             // Reset the result flag.
     85             (*pResult) = false;
     86 
     87             // Throw an exception.
     88             jniThrowException(pEnv, "java/lang/RuntimeException", pMessage);
     89         }
     90     }
     91 }
     92 
     93 void
     94 videoEditJava_checkAndThrowIllegalStateExceptionFunc(
     95                 bool*                               pResult,
     96                 JNIEnv*                             pEnv,
     97                 bool                                condition,
     98                 const char*                         pMessage,
     99                 const char*                         pFile,
    100                 int                                 lineNo
    101                 )
    102 {
    103     // Check if the previous action succeeded.
    104     if (*pResult)
    105     {
    106         // Check if the condition is true.
    107         if (condition)
    108         {
    109             // Log the exception.
    110             VIDEOEDIT_LOG_EXCEPTION(ANDROID_LOG_ERROR, "VIDEO_EDITOR_JAVA",
    111                     "videoEditJava_checkAndThrowIllegalStateException, %s (%s:%d)",
    112                     pMessage, pFile, lineNo);
    113 
    114             // Reset the result flag.
    115             (*pResult) = false;
    116 
    117             // Throw an exception.
    118             jniThrowException(pEnv, "java/lang/IllegalStateException", pMessage);
    119         }
    120     }
    121 }
    122 
    123 void
    124 videoEditJava_getClass(
    125                 bool*                               pResult,
    126                 JNIEnv*                             pEnv,
    127                 const char*                         pName,
    128                 jclass*                             pClazz)
    129 {
    130     // Only look for the class if locating the previous action succeeded.
    131     if (*pResult)
    132     {
    133         // Log the function call.
    134         VIDEOEDIT_LOG_FUNCTION(ANDROID_LOG_INFO, "VIDEO_EDITOR_JAVA",
    135                 "videoEditJava_getClass(%s)", pName);
    136 
    137         // Look up the class.
    138         jclass clazz = pEnv->FindClass(pName);
    139 
    140         // Clear any resulting exceptions.
    141         pEnv->ExceptionClear();
    142 
    143         // Check if the class could be located.
    144         if (NULL != clazz)
    145         {
    146             // Return the class.
    147             (*pClazz) = clazz;
    148         }
    149         else
    150         {
    151             // Reset the result flag.
    152             (*pResult) = false;
    153 
    154             // Log the error.
    155             VIDEOEDIT_LOG_EXCEPTION(ANDROID_LOG_ERROR, "VIDEO_EDITOR_JAVA",
    156                     "videoEditJava_getClass, error: unable to locate class %s", pName);
    157 
    158             // Throw an exception.
    159             jniThrowException(pEnv, "java/lang/ClassNotFoundException",
    160                     "unable to locate class");
    161         }
    162     }
    163 }
    164 
    165 void
    166 videoEditJava_getMethodId(
    167                 bool*                               pResult,
    168                 JNIEnv*                             pEnv,
    169                 jclass                              clazz,
    170                 const char*                         pName,
    171                 const char*                         pType,
    172                 jmethodID*                          pMethodId)
    173 {
    174     // Only look for the class if locating the previous action succeeded.
    175     if (*pResult)
    176     {
    177         // Log the function call.
    178         VIDEOEDIT_LOG_FUNCTION(ANDROID_LOG_INFO, "VIDEO_EDITOR_JAVA",
    179                 "videoEditJava_getMethodId(%s,%s)", pName, pType);
    180 
    181         // Look up the method id.
    182         jmethodID methodId = pEnv->GetMethodID(clazz, pName, pType);
    183 
    184         // Clear any resulting exceptions.
    185         pEnv->ExceptionClear();
    186 
    187         // Check if the method could be located.
    188         if (NULL != methodId)
    189         {
    190             // Return the method id.
    191             (*pMethodId) = methodId;
    192         }
    193         else
    194         {
    195             // Reset the result flag.
    196             (*pResult) = false;
    197 
    198             // Log the error.
    199             VIDEOEDIT_LOG_EXCEPTION(ANDROID_LOG_ERROR, "VIDEO_EDITOR_JAVA",
    200                     "videoEditJava_getMethodId, error: unable to locate method %s with type %s",
    201                     pName, pType);
    202 
    203             // Throw an exception.
    204             jniThrowException(pEnv, "java/lang/NoSuchMethodException", "unable to locate method");
    205         }
    206     }
    207 }
    208 
    209 void
    210 videoEditJava_getFieldId(
    211                 bool*                               pResult,
    212                 JNIEnv*                             pEnv,
    213                 jclass                              clazz,
    214                 const char*                         pName,
    215                 const char*                         pType,
    216                 jfieldID*                           pFieldId)
    217 {
    218     // Only look for the class if locating the previous action succeeded.
    219     if (*pResult)
    220     {
    221         // Log the function call.
    222         VIDEOEDIT_LOG_FUNCTION(ANDROID_LOG_INFO, "VIDEO_EDITOR_JAVA",
    223                 "videoEditJava_getFieldId(%s,%s)", pName, pType);
    224 
    225         // Look up the field id.
    226         jfieldID fieldId = pEnv->GetFieldID(clazz, pName, pType);
    227 
    228         // Clear any resulting exceptions.
    229         pEnv->ExceptionClear();
    230 
    231         // Check if the field could be located.
    232         if (NULL != fieldId)
    233         {
    234             // Return the field id.
    235             (*pFieldId) = fieldId;
    236         }
    237         else
    238         {
    239             // Reset the result flag.
    240             (*pResult) = false;
    241 
    242             // Log the error.
    243             VIDEOEDIT_LOG_EXCEPTION(ANDROID_LOG_ERROR, "VIDEO_EDITOR_JAVA",
    244                     "videoEditJava_getFieldId, error: unable to locate field %s with type %s",
    245                     pName, pType);
    246 
    247             // Throw an exception.
    248             jniThrowException(pEnv, "java/lang/NoSuchFieldException", "unable to locate field");
    249         }
    250     }
    251 }
    252 
    253 void
    254 videoEditJava_getObject(
    255                 bool*                               pResult,
    256                 JNIEnv*                             pEnv,
    257                 jobject                             object,
    258                 jfieldID                            objectFieldId,
    259                 jobject*                            pObject)
    260 {
    261     // Only retrieve the array object and size if the previous action succeeded.
    262     if (*pResult)
    263     {
    264         // Log the function call.
    265         VIDEOEDIT_LOG_FUNCTION(ANDROID_LOG_INFO, "VIDEO_EDITOR_JAVA",
    266             "videoEditJava_getObject()");
    267 
    268         // Retrieve the object.
    269         (*pObject) = pEnv->GetObjectField(object, objectFieldId);
    270 
    271         // Clear any resulting exceptions.
    272         pEnv->ExceptionClear();
    273     }
    274 }
    275 
    276 void
    277 videoEditJava_getArray(
    278                 bool*                               pResult,
    279                 JNIEnv*                             pEnv,
    280                 jobject                             object,
    281                 jfieldID                            arrayFieldId,
    282                 jobjectArray*                       pArray,
    283                 jsize*                              pArraySize)
    284 {
    285     // Only retrieve the array object and size if the previous action succeeded.
    286     if (*pResult)
    287     {
    288         // Log the function call.
    289         VIDEOEDIT_LOG_FUNCTION(ANDROID_LOG_INFO, "VIDEO_EDITOR_JAVA", "videoEditJava_getArray()");
    290 
    291         // Retrieve the array object.
    292         jobjectArray array     = (jobjectArray)pEnv->GetObjectField(object, arrayFieldId);
    293         jsize        arraySize = 0;
    294 
    295         // Clear any resulting exceptions.
    296         pEnv->ExceptionClear();
    297 
    298         // Check if the array could be retrieved.
    299         if (NULL != array)
    300         {
    301             // Retrieve the array size.
    302             arraySize = pEnv->GetArrayLength(array);
    303         }
    304 
    305         // Return the array and its size.
    306         (*pArray)     = array;
    307         (*pArraySize) = arraySize;
    308     }
    309 }
    310 
    311 void*
    312 videoEditJava_getString(
    313                 bool*                               pResult,
    314                 JNIEnv*                             pEnv,
    315                 jobject                             object,
    316                 jfieldID                            stringFieldId,
    317                 M4OSA_UInt32*                       pLength)
    318 {
    319     void*        pString = M4OSA_NULL;
    320     jstring      string  = NULL;
    321     M4OSA_UInt32 length  = 0;
    322     M4OSA_Char*  pLocal  = M4OSA_NULL;
    323     M4OSA_ERR    result  = M4NO_ERROR;
    324 
    325     // Check if the previous action succeeded.
    326     if (*pResult)
    327     {
    328         // Log the function call.
    329         VIDEOEDIT_LOG_FUNCTION(ANDROID_LOG_INFO, "VIDEO_EDITOR_JAVA", "videoEditJava_getString()");
    330 
    331         // Check if an object containing a string was specified.
    332         if (NULL != stringFieldId)
    333         {
    334             // Retrieve the string object.
    335             string = (jstring)pEnv->GetObjectField(object, stringFieldId);
    336 
    337             // Clear any resulting exceptions.
    338             pEnv->ExceptionClear();
    339         }
    340         else
    341         {
    342             // The string itself was specified.
    343             string = (jstring)object;
    344         }
    345 
    346         // Check if the string could be retrieved.
    347         if (NULL != string)
    348         {
    349             // Get a local copy of the string.
    350             pLocal = (M4OSA_Char*)pEnv->GetStringUTFChars(string, M4OSA_NULL);
    351             if (M4OSA_NULL != pLocal)
    352             {
    353                 // Determine the length of the path
    354                 // (add one extra character for the zero terminator).
    355                 length = strlen((const char *)pLocal) + 1;
    356 
    357                 // Allocate memory for the string.
    358                 pString = videoEditOsal_alloc(pResult, pEnv, length, "String");
    359                 if (*pResult)
    360                 {
    361                     // Copy the string.
    362                     result = M4OSA_chrNCopy((M4OSA_Char*)pString, pLocal, length);
    363 
    364                     // Check if the copy succeeded.
    365                     videoEditJava_checkAndThrowRuntimeException(pResult, pEnv,
    366                      (M4NO_ERROR != result), result);
    367 
    368                     // Check if the string could not be copied.
    369                     if (!(*pResult))
    370                     {
    371                         // Free the allocated memory.
    372                         videoEditOsal_free(pString);
    373                         pString = M4OSA_NULL;
    374                     }
    375                 }
    376 
    377                 // Release the local copy of the string.
    378                 pEnv->ReleaseStringUTFChars(string, (const char *)pLocal);
    379             }
    380         }
    381 
    382         // Check if the string was empty or could be copied.
    383         if (*pResult)
    384         {
    385             // Check if the length was requested.
    386             if (M4OSA_NULL != pLength)
    387             {
    388                 // Return the length.
    389                 (*pLength) = length;
    390             }
    391         }
    392 
    393         // Delete local references to avoid memory leaks
    394         pEnv->DeleteLocalRef(string);
    395     }
    396 
    397     // Return the string.
    398     return(pString);
    399 }
    400 
    401 void
    402 videoEditJava_getStaticIntField(
    403                 bool*                               pResult,
    404                 JNIEnv*                             pEnv,
    405                 jclass                              clazz,
    406                 const char*                         pName,
    407                 int*                                pValue)
    408 {
    409     // Only look for the class if locating the previous action succeeded.
    410     if (*pResult)
    411     {
    412         // Log the function call.
    413         VIDEOEDIT_LOG_FUNCTION(ANDROID_LOG_INFO, "VIDEO_EDITOR_JAVA",
    414                 "videoEditJava_getStaticIntField(%s)", pName);
    415 
    416         // Look up the field id.
    417         jfieldID fieldId = pEnv->GetStaticFieldID(clazz, pName, "I");
    418 
    419         // Clear any resulting exceptions.
    420         pEnv->ExceptionClear();
    421 
    422         // Check if the field could be located.
    423         if (NULL != fieldId)
    424         {
    425             // Retrieve the field value.
    426             (*pValue) = pEnv->GetStaticIntField(clazz, fieldId);
    427 
    428             // Log the value.
    429             VIDEOEDIT_LOG_FUNCTION(ANDROID_LOG_INFO, "VIDEO_EDITOR_JAVA",
    430                     "videoEditJava_getStaticIntField, %s = %d", pName, (*pValue));
    431         }
    432         else
    433         {
    434             // Reset the result flag.
    435             (*pResult) = false;
    436 
    437             // Log the error.
    438             VIDEOEDIT_LOG_EXCEPTION(ANDROID_LOG_ERROR, "VIDEO_EDITOR_JAVA",
    439                     "videoEditJava_getStaticIntField, error: unable to locate field %s", pName);
    440 
    441             // Throw an exception.
    442             jniThrowException(pEnv, "java/lang/NoSuchFieldException",
    443                     "unable to locate static field");
    444         }
    445     }
    446 }
    447 
    448 void
    449 videoEditJava_initConstantClass(
    450                 bool*                               pResult,
    451                 JNIEnv*                             pEnv,
    452                 VideoEditJava_ConstantsClass*               pClass)
    453 {
    454     bool   gotten = true;
    455     jclass clazz  = NULL;
    456     int    index  = 0;
    457 
    458     // Check if the previous action succeeded.
    459     if (*pResult)
    460     {
    461         // Log the function call.
    462         VIDEOEDIT_LOG_FUNCTION(ANDROID_LOG_INFO, "VIDEO_EDITOR_JAVA",
    463                 "videoEditJava_initConstantClass(%s)", pClass->pName);
    464 
    465         // Only initialize the class once.
    466         if (!pClass->initialized)
    467         {
    468             // Look up the class.
    469             videoEditJava_getClass(pResult, pEnv, pClass->pName, &clazz);
    470 
    471             // Loop over the constants.
    472             for (index = 0; index < pClass->count; index++)
    473             {
    474                 // Look up the constant.
    475                 videoEditJava_getStaticIntField(pResult, pEnv, clazz,
    476                                         pClass->pConstants[index].pName,
    477                                         &pClass->pConstants[index].java);
    478             }
    479 
    480             // Check if all constants could be located.
    481             if (*pResult)
    482             {
    483                 // Set the initialized flag.
    484                 pClass->initialized = true;
    485             }
    486         }
    487     }
    488 }
    489 
    490 const char*
    491 videoEditJava_getConstantClassName(
    492                 const VideoEditJava_ConstantsClass*         pClass,
    493                 int                                 value,
    494                 VideoEditJava_UnknownConstant               unknown)
    495 {
    496     const char* pName = M4OSA_NULL;
    497     int         index = 0;
    498 
    499     // Loop over the list with constants.
    500     for (index = 0;
    501          ((M4OSA_NULL == pName) && (index < pClass->count));
    502          index++)
    503     {
    504         // Check if the specified value matches the c value of the constant.
    505         if (value == pClass->pConstants[index].c)
    506         {
    507             // Set the name.
    508             pName = pClass->pConstants[index].pName;
    509         }
    510     }
    511 
    512     // Check if no constant was found.
    513     if (M4OSA_NULL == pName)
    514     {
    515         // Check if a function was specified to handle this case.
    516         if (M4OSA_NULL != unknown)
    517         {
    518             // Pass the constant to the specified unknown function.
    519             pName = unknown(value);
    520         }
    521         else
    522         {
    523             // Set the description to a default value.
    524             pName = "<unknown>";
    525         }
    526     }
    527 
    528     // Return the result.
    529     return(pName);
    530 }
    531 
    532 const char*
    533 videoEditJava_getConstantClassString(
    534                 const VideoEditJava_ConstantsClass*         pClass,
    535                 int                                 value,
    536                 VideoEditJava_UnknownConstant               unknown)
    537 {
    538     const char* pString = M4OSA_NULL;
    539     int         index   = 0;
    540 
    541     // Loop over the list with constants.
    542     for (index = 0;
    543          ((M4OSA_NULL == pString) && (index < pClass->count));
    544          index++)
    545     {
    546         // Check if the specified value matches the c value of the constant.
    547         if (value == pClass->pConstants[index].c)
    548         {
    549             // Set the description.
    550             pString = pClass->pConstants[index].pDescription;
    551         }
    552     }
    553 
    554     // Check if no constant was found.
    555     if (M4OSA_NULL == pString)
    556     {
    557         // Check if a function was specified to handle this case.
    558         if (M4OSA_NULL != unknown)
    559         {
    560             // Pass the constant to the specified unknown function.
    561             pString = unknown(value);
    562         }
    563         else
    564         {
    565             // Set the description to a default value.
    566             pString = "<unknown>";
    567         }
    568     }
    569 
    570     // Return the result.
    571     return(pString);
    572 }
    573 
    574 int
    575 videoEditJava_getConstantClassJavaToC(
    576                 bool*                               pResult,
    577                 const VideoEditJava_ConstantsClass*         pClass,
    578                 int                                 value)
    579 {
    580     bool gotten = false;
    581     int  index  = 0;
    582 
    583     // Check if the previous action succeeded.
    584     if (*pResult)
    585     {
    586         // Loop over the list with constants.
    587         for (index = 0; ((!gotten) && (index < pClass->count)); index++)
    588         {
    589             // Check if the specified value matches the java value of the constant.
    590             if (value == pClass->pConstants[index].java)
    591             {
    592                 // Set the value to the c value.
    593                 value = pClass->pConstants[index].c;
    594 
    595                 // Set the gotten flag.
    596                 gotten = true;
    597             }
    598         }
    599 
    600         // Check if the value was not found.
    601         if (!gotten)
    602         {
    603             (*pResult) = false;
    604         }
    605     }
    606 
    607     // Return the translated value.
    608     return(value);
    609 }
    610 
    611 int
    612 videoEditJava_getConstantClassJavaToC(
    613                 bool*                               pResult,
    614                 const VideoEditJava_ConstantsClass*         pClass,
    615                 int                                 value,
    616                 int                                 unknown)
    617 {
    618     bool gotten = false;
    619     int  index  = 0;
    620 
    621     // Check if the previous action succeeded.
    622     if (*pResult)
    623     {
    624         // Loop over the list with constants.
    625         for (index = 0; ((!gotten) && (index < pClass->count)); index++)
    626         {
    627             // Check if the specified value matches the java value of the constant.
    628             if (value == pClass->pConstants[index].java)
    629             {
    630                 // Set the value to the c value.
    631                 value = pClass->pConstants[index].c;
    632 
    633                 // Set the gotten flag.
    634                 gotten = true;
    635             }
    636         }
    637 
    638         // If the constant was not found, look for the specified unknown.
    639         if (!gotten)
    640         {
    641             // Set the value to the c value.
    642             value = unknown;
    643         }
    644     }
    645 
    646     // Return the translated value.
    647     return(value);
    648 }
    649 
    650 int
    651 videoEditJava_getConstantClassCToJava(
    652                 const VideoEditJava_ConstantsClass*         pClass,
    653                 int                                 value)
    654 {
    655     bool gotten = false;
    656     int  index  = 0;
    657 
    658     // Loop over the list with constants.
    659     for (index = 0; ((!gotten) && (index < pClass->count)); index++)
    660     {
    661         // Check if the specified value matches the c value of the constant.
    662         if (value == pClass->pConstants[index].c)
    663         {
    664             // Set the value to the java value.
    665             value = pClass->pConstants[index].java;
    666 
    667             // Set the gotten flag.
    668             gotten = true;
    669         }
    670     }
    671 
    672     // Return the translated value.
    673     return(value);
    674 }
    675 
    676 int
    677 videoEditJava_getConstantClassCToJava(
    678                 const VideoEditJava_ConstantsClass*         pClass,
    679                 int                                 value,
    680                 int                                 unknown)
    681 {
    682     bool gotten = false;
    683     int  index  = 0;
    684 
    685     // Loop over the list with constants.
    686     for (index = 0; ((!gotten) && (index < pClass->count)); index++)
    687     {
    688         // Check if the specified value matches the c value of the constant.
    689         if (value == pClass->pConstants[index].c)
    690         {
    691             // Set the value to the java value.
    692             value = pClass->pConstants[index].java;
    693 
    694             // Set the gotten flag.
    695             gotten = true;
    696         }
    697     }
    698 
    699     // If the constant was not found, look for the specified unknown.
    700     if (!gotten)
    701     {
    702         // Loop over the list with constants.
    703         for (index = 0; ((!gotten) && (index < pClass->count)); index++)
    704         {
    705             // Check if the specified value matches the java value of the constant.
    706             if (unknown == pClass->pConstants[index].c)
    707             {
    708                 // Set the value to the c value.
    709                 value = pClass->pConstants[index].java;
    710 
    711                 // Set the gotten flag.
    712                 gotten = true;
    713             }
    714         }
    715     }
    716 
    717     // Return the translated value.
    718     return(value);
    719 }
    720 
    721 void
    722 videoEditJava_initFieldClass(
    723                 bool*                               pResult,
    724                 JNIEnv*                             pEnv,
    725                 VideoEditJava_FieldsClass*                  pClass)
    726 {
    727     bool   gotten = true;
    728     jclass clazz  = NULL;
    729     int    index  = 0;
    730 
    731     // Check if the previous action succeeded.
    732     if (*pResult)
    733     {
    734         // Log the function call.
    735         VIDEOEDIT_LOG_FUNCTION(ANDROID_LOG_INFO, "VIDEO_EDITOR_JAVA",
    736                 "videoEditJava_initFieldClass(%s)", pClass->pName);
    737 
    738         // Only initialize the class once.
    739         if (!pClass->initialized)
    740         {
    741             // Look up the class.
    742             videoEditJava_getClass(pResult, pEnv, pClass->pName, &clazz);
    743 
    744             // Loop over the fields.
    745             for (index = 0; index < pClass->count; index++)
    746             {
    747                 // Look up the field id.
    748                 videoEditJava_getFieldId(
    749                         pResult,
    750                         pEnv,
    751                         clazz,
    752                         pClass->pFields[index].pName,
    753                         pClass->pFields[index].pType,
    754                         &pClass->pFields[index].fieldId);
    755             }
    756 
    757             // Check if all fields could be located.
    758             if (*pResult)
    759             {
    760                 // Set the initialized flag.
    761                 pClass->initialized = true;
    762             }
    763         }
    764     }
    765 }
    766 
    767 void
    768 videoEditJava_fieldClassClass(
    769                 bool*                               pResult,
    770                 JNIEnv*                             pEnv,
    771                 const VideoEditJava_FieldsClass*            pClass,
    772                 jclass*                             pClazz)
    773 {
    774     // Check if the previous action succeeded.
    775     if (*pResult)
    776     {
    777         // Check if the class is initialized.
    778         videoEditJava_checkAndThrowIllegalArgumentException(pResult, pEnv, (!pClass->initialized),
    779                 "field class not initialized");
    780 
    781         // Get the class.
    782         videoEditJava_getClass(pResult, pEnv, pClass->pName, pClazz);
    783     }
    784 }
    785 
    786 void
    787 videoEditJava_fieldClassFieldIds(
    788                 bool*                               pResult,
    789                 JNIEnv*                             pEnv,
    790                 const VideoEditJava_FieldsClass*            pClass,
    791                 int                                 count,
    792                 VideoEditJava_FieldIds*                     pIds)
    793 {
    794     int index = 0;
    795 
    796     // Check if the previous action succeeded.
    797     if (*pResult)
    798     {
    799         // Check if the class is initialized.
    800         videoEditJava_checkAndThrowIllegalArgumentException(pResult, pEnv, (!pClass->initialized),
    801                 "field class not initialized");
    802 
    803         // Check if the number of fields matches.
    804         videoEditJava_checkAndThrowIllegalArgumentException(pResult, pEnv,
    805                 (pClass->count != count),
    806                 "field class type mismatch");
    807 
    808         // Check if the class and object are valid.
    809         if (*pResult)
    810         {
    811             // Loop over the class fields.
    812             for (index = 0; index < count; index++)
    813             {
    814                 // Copy the field ids.
    815                 pIds->fieldIds[index] = pClass->pFields[index].fieldId;
    816             }
    817         }
    818     }
    819 }
    820 
    821 void
    822 videoEditJava_initMethodClass(
    823                 bool*                               pResult,
    824                 JNIEnv*                             pEnv,
    825                 VideoEditJava_MethodsClass*                 pClass)
    826 {
    827     bool   gotten = true;
    828     jclass clazz  = NULL;
    829     int    index  = 0;
    830 
    831     // Check if the previous action succeeded.
    832     if (*pResult)
    833     {
    834         // Log the function call.
    835         VIDEOEDIT_LOG_FUNCTION(ANDROID_LOG_INFO, "VIDEO_EDITOR_JAVA",
    836                 "videoEditJava_initMethodClass(%s)", pClass->pName);
    837 
    838         // Only initialize the class once.
    839         if (!pClass->initialized)
    840         {
    841             // Look up the class.
    842             videoEditJava_getClass(pResult, pEnv, pClass->pName, &clazz);
    843 
    844             // Loop over the methods.
    845             for (index = 0; index < pClass->count; index++)
    846             {
    847                 // Look up the method id.
    848                 videoEditJava_getMethodId(
    849                         pResult,
    850                         pEnv,
    851                         clazz,
    852                         pClass->pMethods[index].pName,
    853                         pClass->pMethods[index].pType,
    854                         &pClass->pMethods[index].methodId);
    855             }
    856 
    857             // Check if all methods could be located.
    858             if (*pResult)
    859             {
    860                 // Set the initialized flag.
    861                 pClass->initialized = true;
    862             }
    863         }
    864     }
    865 }
    866 
    867 void
    868 videoEditJava_methodClassMethodIds(
    869                 bool*                               pResult,
    870                 JNIEnv*                             pEnv,
    871                 const VideoEditJava_MethodsClass*   pClass,
    872                 int                                 count,
    873                 VideoEditJava_MethodIds*            pIds)
    874 {
    875     int index = 0;
    876 
    877     // Check if the previous action succeeded.
    878     if (*pResult)
    879     {
    880         // Check if the class is initialized.
    881         videoEditJava_checkAndThrowIllegalArgumentException(pResult, pEnv, (!pClass->initialized),
    882                     "method class not initialized");
    883 
    884         // Check if the number of methods matches.
    885         videoEditJava_checkAndThrowIllegalArgumentException(pResult, pEnv,\
    886                     (pClass->count != count),
    887                     "method class type mismatch");
    888 
    889         // Check if the class and object are valid.
    890         if (*pResult)
    891         {
    892             // Loop over the class methods.
    893             for (index = 0; index < count; index++)
    894             {
    895                 // Copy the method ids.
    896                 pIds->methodIds[index] = pClass->pMethods[index].methodId;
    897             }
    898         }
    899     }
    900 }
    901 
    902