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 #ifndef VIDEO_EDiTOR_JAVA_H
     18 #define VIDEO_EDiTOR_JAVA_H
     19 
     20 #include <jni.h>
     21 #include <JNIHelp.h>
     22 
     23 /**
     24  ************************************************************************
     25  * @file        VideoEditorJava.h
     26  * @brief       Interface for JNI methods that have specific access to
     27  *              class, objects and method Ids defined in Java layer
     28  ************************************************************************
     29 */
     30 
     31 extern "C" {
     32 #include <M4OSA_Types.h>
     33 #include <M4OSA_Error.h>
     34 }
     35 
     36 #define VIDEOEDIT_JAVA_CONSTANT_INIT(m_name, m_c)                           \
     37             { m_name,                                                       \
     38               0,                                                            \
     39               m_c,                                                          \
     40               #m_c }
     41 
     42 #define VIDEOEDIT_JAVA_DEFINE_CONSTANTS(m_class)                            \
     43 static                                                                      \
     44 VideoEditJava_Constant g##m_class##Constants [] =
     45 
     46 #define VIDEOEDIT_JAVA_DEFINE_CONSTANT_CLASS(                               \
     47                 m_class,                                                    \
     48                 m_name,                                                     \
     49                 m_unknownName,                                              \
     50                 m_unknownString)                                            \
     51                                                                             \
     52 static VideoEditJava_ConstantsClass g##m_class##ConstantsClass =            \
     53 {       m_name,                                                             \
     54         &g##m_class##Constants[0],                                          \
     55         (sizeof(g##m_class##Constants) / sizeof(VideoEditJava_Constant)),   \
     56         false                                                               \
     57 };                                                                          \
     58                                                                             \
     59                                                                             \
     60 void videoEditJava_init##m_class##Constants(                                \
     61                 bool*                               pResult,                \
     62                 JNIEnv*                             pEnv)                   \
     63 {                                                                           \
     64     videoEditJava_initConstantClass(                                        \
     65                 pResult,                                                    \
     66                 pEnv,                                                       \
     67                 &g##m_class##ConstantsClass);                               \
     68 }                                                                           \
     69                                                                             \
     70 const char* videoEditJava_get##m_class##Name(                               \
     71                 int                                 value)                  \
     72 {                                                                           \
     73     return(videoEditJava_getConstantClassName(                              \
     74                 &g##m_class##ConstantsClass,                                \
     75                 value,                                                      \
     76                 m_unknownName));                                            \
     77 }                                                                           \
     78                                                                             \
     79 const char* videoEditJava_get##m_class##String(                             \
     80                 int                                 value)                  \
     81 {                                                                           \
     82     return(videoEditJava_getConstantClassString(                            \
     83                 &g##m_class##ConstantsClass,                                \
     84                 value,                                                      \
     85                 m_unknownString));                                          \
     86 }                                                                           \
     87                                                                             \
     88 int                                                                         \
     89 videoEditJava_get##m_class##JavaToC(                                        \
     90                 bool*                               pResult,                \
     91                 int                                 value)                  \
     92 {                                                                           \
     93     return(videoEditJava_getConstantClassJavaToC(                           \
     94                 pResult,                                                    \
     95                 &g##m_class##ConstantsClass,                                \
     96                 value));                                                    \
     97 }                                                                           \
     98                                                                             \
     99 int                                                                         \
    100 videoEditJava_get##m_class##JavaToC(                                        \
    101                 bool*                               pResult,                \
    102                 int                                 value,                  \
    103                 int                                 unknown)                \
    104 {                                                                           \
    105     return(videoEditJava_getConstantClassJavaToC(                           \
    106                 pResult,                                                    \
    107                 &g##m_class##ConstantsClass,                                \
    108                 value,                                                      \
    109                 unknown));                                                  \
    110 }                                                                           \
    111                                                                             \
    112 int                                                                         \
    113 videoEditJava_get##m_class##CToJava(                                        \
    114                         int                                 value)          \
    115 {                                                                           \
    116     return(videoEditJava_getConstantClassCToJava(                           \
    117                 &g##m_class##ConstantsClass,                                \
    118                 value));                                                    \
    119 }                                                                           \
    120                                                                             \
    121 int                                                                         \
    122 videoEditJava_get##m_class##CToJava(                                        \
    123                 int                                 value,                  \
    124                 int                                 unknown)                \
    125 {                                                                           \
    126     return(videoEditJava_getConstantClassCToJava(                           \
    127                 &g##m_class##ConstantsClass,                                \
    128                 value,                                                      \
    129                 unknown));                                                  \
    130 }
    131 
    132 
    133 #define VIDEOEDIT_JAVA_DECLARE_CONSTANT_CLASS(m_class)                       \
    134 void                                                                        \
    135 videoEditJava_init##m_class##Constants(                                     \
    136                 bool*                               pResult,                \
    137                 JNIEnv*                             pEnv);                  \
    138                                                                             \
    139 const char*                                                                 \
    140 videoEditJava_get##m_class##Name(                                           \
    141                 int                                 value);                 \
    142                                                                             \
    143 const char*                                                                 \
    144 videoEditJava_get##m_class##String(                                         \
    145                 int                                 value);                 \
    146                                                                             \
    147 int                                                                         \
    148 videoEditJava_get##m_class##JavaToC(                                        \
    149                 bool*                               pResult,                \
    150                 int                                 value,                  \
    151                 int                                 unknown);               \
    152                                                                             \
    153 int                                                                         \
    154 videoEditJava_get##m_class##JavaToC(                                        \
    155                 bool*                               pResult,                \
    156                 int                                 value);                 \
    157                                                                             \
    158 int                                                                         \
    159 videoEditJava_get##m_class##CToJava(                                        \
    160                 int                                 value);                 \
    161                                                                             \
    162 int                                                                         \
    163 videoEditJava_get##m_class##CToJava(                                        \
    164                 int                                 value,                  \
    165                 int                                 unknown);
    166 
    167 #define VIDEOEDIT_JAVA_FIELD_INIT(m_name, m_type)                           \
    168     { m_name,                                                               \
    169       m_type,                                                               \
    170       NULL }
    171 
    172 #define VIDEOEDIT_JAVA_DEFINE_FIELDS(m_class)                               \
    173 static                                                                      \
    174 VideoEditJava_Field g##m_class##Fields [] =
    175 
    176 #define VIDEOEDIT_JAVA_DEFINE_FIELD_CLASS(m_class, m_name)                  \
    177 static VideoEditJava_FieldsClass g##m_class##FieldsClass =                  \
    178     { m_name,                                                               \
    179       &g##m_class##Fields[0],                                               \
    180       (sizeof(g##m_class##Fields) / sizeof(VideoEditJava_Field)),           \
    181       false };                                                              \
    182                                                                             \
    183 void                                                                        \
    184 videoEditJava_init##m_class##Fields(                                        \
    185                 bool*                               pResult,                \
    186                 JNIEnv*                             pEnv)                   \
    187 {                                                                           \
    188     videoEditJava_initFieldClass(                                           \
    189                 pResult,                                                    \
    190                 pEnv,                                                       \
    191                 &g##m_class##FieldsClass);                                  \
    192 }                                                                           \
    193                                                                             \
    194 void                                                                        \
    195 videoEditJava_get##m_class##Class(                                          \
    196                 bool*                               pResult,                \
    197                 JNIEnv*                             pEnv,                   \
    198                 jclass*                             pClazz)                 \
    199 {                                                                           \
    200     videoEditJava_fieldClassClass(                                          \
    201                 pResult,                                                    \
    202                 pEnv,                                                       \
    203                 &g##m_class##FieldsClass,                                   \
    204                 pClazz);                                                    \
    205 }                                                                           \
    206                                                                             \
    207 void                                                                        \
    208 videoEditJava_get##m_class##FieldIds(                                       \
    209                 bool*                               pResult,                \
    210                 JNIEnv*                             pEnv,                   \
    211                 VideoEditJava_##m_class##FieldIds*          pIds)           \
    212 {                                                                           \
    213     videoEditJava_fieldClassFieldIds(                                       \
    214                 pResult,                                                    \
    215                 pEnv,                                                       \
    216                 &g##m_class##FieldsClass,                                   \
    217                 (sizeof(VideoEditJava_##m_class##FieldIds) /                \
    218                  sizeof(jfieldID)),                                         \
    219                 (VideoEditJava_FieldIds*)pIds);                             \
    220 }
    221 
    222 #define VIDEOEDIT_JAVA_DECLARE_FIELD_CLASS(m_class)                         \
    223 void                                                                        \
    224 videoEditJava_init##m_class##Fields(                                        \
    225                 bool*                               pResult,                \
    226                 JNIEnv*                             pEnv);                  \
    227                                                                             \
    228 void                                                                        \
    229 videoEditJava_get##m_class##Class(                                          \
    230                 bool*                               pResult,                \
    231                 JNIEnv*                             pEnv,                   \
    232                 jclass*                             pClazz);                \
    233                                                                             \
    234 void                                                                        \
    235 videoEditJava_get##m_class##FieldIds(                                       \
    236                 bool*                               pResult,                \
    237                 JNIEnv*                             pEnv,                   \
    238                 VideoEditJava_##m_class##FieldIds*          pIds);
    239 
    240 
    241 #define VIDEOEDIT_JAVA_METHOD_INIT(m_name, m_type)                          \
    242     { m_name,                                                               \
    243       m_type,                                                               \
    244       NULL }
    245 
    246 #define VIDEOEDIT_JAVA_DEFINE_METHODS(m_class)                              \
    247 static                                                                      \
    248 VideoEditJava_Method g##m_class##Methods [] =
    249 
    250 #define VIDEOEDIT_JAVA_DEFINE_METHOD_CLASS(m_class, m_name)                 \
    251 static VideoEditJava_MethodsClass g##m_class##MethodsClass =                \
    252     { m_name,                                                               \
    253       &g##m_class##Methods[0],                                              \
    254       (sizeof(g##m_class##Methods) / sizeof(VideoEditJava_Method)),         \
    255       false };                                                              \
    256                                                                             \
    257 void                                                                        \
    258 videoEditJava_init##m_class##Methods(                                       \
    259                 bool*                               pResult,                \
    260                 JNIEnv*                             pEnv)                   \
    261 {                                                                           \
    262     videoEditJava_initMethodClass(                                          \
    263                 pResult,                                                    \
    264                 pEnv,                                                       \
    265                 &g##m_class##MethodsClass);                                 \
    266 }                                                                           \
    267                                                                             \
    268 void                                                                        \
    269 videoEditJava_get##m_class##MethodIds(                                      \
    270                 bool*                               pResult,                \
    271                 JNIEnv*                             pEnv,                   \
    272                 VideoEditJava_##m_class##MethodIds*         pIds)           \
    273 {                                                                           \
    274     videoEditJava_methodClassMethodIds(                                     \
    275                 pResult,                                                    \
    276                 pEnv,                                                       \
    277                 &g##m_class##MethodsClass,                                  \
    278                 (sizeof(VideoEditJava_##m_class##MethodIds) /               \
    279                  sizeof(jmethodID)),                                        \
    280                 (VideoEditJava_MethodIds*)pIds);                            \
    281 }
    282 
    283 #define VIDEOEDIT_JAVA_DECLARE_METHOD_CLASS(m_class)                        \
    284 void                                                                        \
    285 videoEditJava_init##m_class##Methods(                                       \
    286                 bool*                               pResult,                \
    287                 JNIEnv*                             pEnv);                  \
    288                                                                             \
    289 void                                                                        \
    290 videoEditJava_get##m_class##MethodIds(                                      \
    291                 bool*                               pResult,                \
    292                 JNIEnv*                             pEnv,                   \
    293                 VideoEditJava_##m_class##MethodIds*         pIds);
    294 
    295 
    296 typedef struct
    297 {
    298     const char*     pName;
    299     int             java;
    300     int             c;
    301     const char*     pDescription;
    302 } VideoEditJava_Constant;
    303 
    304 typedef struct
    305 {
    306     const char*             pName;
    307     VideoEditJava_Constant* pConstants;
    308     int                     count;
    309     bool                    initialized;
    310 } VideoEditJava_ConstantsClass;
    311 
    312 typedef const char* (*VideoEditJava_UnknownConstant)(int constant);
    313 
    314 typedef struct
    315 {
    316     const char*             pName;
    317     const char*             pType;
    318     jfieldID                fieldId;
    319 } VideoEditJava_Field;
    320 
    321 typedef struct
    322 {
    323     const char*             pName;
    324     VideoEditJava_Field*    pFields;
    325     int                     count;
    326     bool                    initialized;
    327 } VideoEditJava_FieldsClass;
    328 
    329 typedef struct
    330 {
    331     jfieldID fieldIds[];
    332 } VideoEditJava_FieldIds;
    333 
    334 typedef struct
    335 {
    336     const char*             pName;
    337     const char*             pType;
    338     jmethodID               methodId;
    339 } VideoEditJava_Method;
    340 
    341 typedef struct
    342 {
    343     const char*             pName;
    344     VideoEditJava_Method*   pMethods;
    345     int                     count;
    346     bool                    initialized;
    347 } VideoEditJava_MethodsClass;
    348 
    349 typedef struct
    350 {
    351     jmethodID methodIds[];
    352 } VideoEditJava_MethodIds;
    353 
    354 #define videoEditJava_checkAndThrowIllegalArgumentException(\
    355     a, b, c, d) videoEditJava_checkAndThrowIllegalArgumentExceptionFunc(\
    356     a, b, c, d, __FILE__, __LINE__)
    357 
    358 #define videoEditJava_checkAndThrowRuntimeException(\
    359     a, b, c, d) videoEditJava_checkAndThrowRuntimeExceptionFunc(\
    360     a, b, c, d, __FILE__, __LINE__)
    361 
    362 #define videoEditJava_checkAndThrowIllegalStateException(\
    363     a, b, c, d) videoEditJava_checkAndThrowIllegalStateExceptionFunc(\
    364     a, b, c, d, __FILE__, __LINE__)
    365 
    366 void
    367 videoEditJava_checkAndThrowIllegalArgumentExceptionFunc(
    368                 bool*                               pResult,
    369                 JNIEnv*                             pEnv,
    370                 bool                                condition,
    371                 const char*                         pMessage,
    372                 const char*                         pFile,
    373                 int                                 lineNo
    374                 );
    375 
    376 void
    377 videoEditJava_checkAndThrowRuntimeExceptionFunc(
    378                 bool*                               pResult,
    379                 JNIEnv*                             pEnv,
    380                 bool                                condition,
    381                 M4OSA_ERR                           result,
    382                 const char*                         pFile,
    383                 int                                 lineNo
    384                 );
    385 
    386 void
    387 videoEditJava_checkAndThrowIllegalStateExceptionFunc(
    388                 bool*                               pResult,
    389                 JNIEnv*                             pEnv,
    390                 bool                                condition,
    391                 const char*                         pMessage,
    392                 const char*                         pFile,
    393                 int                                 lineNo
    394                 );
    395 
    396 void
    397 videoEditJava_getClass(
    398                 bool*                               pResult,
    399                 JNIEnv*                             pEnv,
    400                 const char*                         pName,
    401                 jclass*                             pClazz);
    402 
    403 void
    404 videoEditJava_getMethodId(
    405                 bool*                               pResult,
    406                 JNIEnv*                             pEnv,
    407                 jclass                              clazz,
    408                 const char*                         pName,
    409                 const char*                         pType,
    410                 jmethodID*                          pMethodId);
    411 
    412 void videoEditJava_getFieldId(
    413                 bool*                               pResult,
    414                 JNIEnv*                             pEnv,
    415                 jclass                              clazz,
    416                 const char*                         pName,
    417                 const char*                         pType,
    418                 jfieldID*                           pFieldId);
    419 
    420 void videoEditJava_getObject(
    421                 bool*                               pResult,
    422                 JNIEnv*                             pEnv,
    423                 jobject                             object,
    424                 jfieldID                            objectFieldId,
    425                 jobject*                            pObject);
    426 
    427 void videoEditJava_getArray(
    428                 bool*                               pResult,
    429                 JNIEnv*                             pEnv,
    430                 jobject                             object,
    431                 jfieldID                            arrayFieldId,
    432                 jobjectArray*                       pArray,
    433                 jsize*                              pArraySize);
    434 
    435 void* videoEditJava_getString(
    436                 bool*                               pResult,
    437                 JNIEnv*                             pEnv,
    438                 jobject                             object,
    439                 jfieldID                            stringFieldId,
    440                 M4OSA_UInt32*                       pLength);
    441 
    442 void videoEditJava_getStaticIntField(
    443                 bool*                               pResult,
    444                 JNIEnv*                             env,
    445                 jclass                              clazz,
    446                 const char*                         pName,
    447                 int*                                pValue);
    448 
    449 void
    450 videoEditJava_initConstantClass(
    451                 bool*                               pResult,
    452                 JNIEnv*                             pEnv,
    453                 VideoEditJava_ConstantsClass*               pClass);
    454 
    455 const char*
    456 videoEditJava_getConstantClassName(
    457                 const VideoEditJava_ConstantsClass*         pClass,
    458                 int                                 value,
    459                 VideoEditJava_UnknownConstant               unknown);
    460 
    461 const char*
    462 videoEditJava_getConstantClassString(
    463                 const VideoEditJava_ConstantsClass*         pClass,
    464                 int                                 value,
    465                 VideoEditJava_UnknownConstant               unknown);
    466 
    467 int
    468 videoEditJava_getConstantClassJavaToC(
    469                 bool*                               pResult,
    470                 const VideoEditJava_ConstantsClass*         pClass,
    471                 int                                 value);
    472 
    473 int
    474 videoEditJava_getConstantClassJavaToC(
    475                 bool*                               pResult,
    476                 const VideoEditJava_ConstantsClass*         pClass,
    477                 int                                 value,
    478                 int                                 unknown);
    479 
    480 int
    481 videoEditJava_getConstantClassCToJava(
    482                 const VideoEditJava_ConstantsClass*         pClass,
    483                 int                                 value);
    484 
    485 int
    486 videoEditJava_getConstantClassCToJava(
    487                 const VideoEditJava_ConstantsClass*         pClass,
    488                 int                                 value,
    489                 int                                 unknown);
    490 
    491 void
    492 videoEditJava_initFieldClass(
    493                 bool*                               pResult,
    494                 JNIEnv*                             pEnv,
    495                 VideoEditJava_FieldsClass*                  pClass);
    496 
    497 void
    498 videoEditJava_fieldClassClass(
    499                 bool*                               pResult,
    500                 JNIEnv*                             pEnv,
    501                 const VideoEditJava_FieldsClass*            pClass,
    502                 jclass*                             pClazz);
    503 
    504 void
    505 videoEditJava_fieldClassFieldIds(
    506                 bool*                               pResult,
    507                 JNIEnv*                             pEnv,
    508                 const VideoEditJava_FieldsClass*            pClass,
    509                 int                                 count,
    510                 VideoEditJava_FieldIds*                     pIds);
    511 
    512 void
    513 videoEditJava_initMethodClass(
    514                 bool*                               pResult,
    515                 JNIEnv*                             pEnv,
    516                 VideoEditJava_MethodsClass*                 pClass);
    517 
    518 void
    519 videoEditJava_methodClassMethodIds(
    520                 bool*                               pResult,
    521                 JNIEnv*                             pEnv,
    522                 const VideoEditJava_MethodsClass*           pClass,
    523                 int                                 count,
    524                 VideoEditJava_MethodIds*                    pIds);
    525 
    526 #endif // VIDEO_EDiTOR_JAVA_H
    527 
    528