Home | History | Annotate | Download | only in examples
      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 #include <stdlib.h>
     18 #include <stdio.h>
     19 #include <string.h>
     20 #include <unistd.h>
     21 #include <sys/time.h>
     22 #include <fcntl.h>
     23 
     24 #include <OMXAL/OpenMAXAL.h>
     25 #include <OMXAL/OpenMAXAL_Android.h> // for VP8 definitions
     26 
     27 #define NUM_ENGINE_INTERFACES 1
     28 
     29 char unknown[50];
     30 
     31 //-----------------------------------------------------------------
     32 /* Exits the application if an error is encountered */
     33 #define ExitOnError(x) ExitOnErrorFunc(x,__LINE__)
     34 
     35 void ExitOnErrorFunc( XAresult result , int line)
     36 {
     37     if (XA_RESULT_SUCCESS != result) {
     38         fprintf(stderr, "Error %u encountered at line %d, exiting\n", result, line);
     39         exit(EXIT_FAILURE);
     40     }
     41 }
     42 
     43 const char* videoCodecIdToString(XAuint32 decoderId) {
     44     switch(decoderId) {
     45     case XA_VIDEOCODEC_MPEG2: return "XA_VIDEOCODEC_MPEG2"; break;
     46     case XA_VIDEOCODEC_H263: return "XA_VIDEOCODEC_H263"; break;
     47     case XA_VIDEOCODEC_MPEG4: return "XA_VIDEOCODEC_MPEG4"; break;
     48     case XA_VIDEOCODEC_AVC: return "XA_VIDEOCODEC_AVC"; break;
     49     case XA_VIDEOCODEC_VC1: return "XA_VIDEOCODEC_VC1"; break;
     50     case XA_ANDROID_VIDEOCODEC_VP8: return "XA_ANDROID_VIDEOCODEC_VP8"; break;
     51     default:
     52         sprintf(unknown, "Video codec %d unknown to OpenMAX AL", decoderId);
     53         return unknown;
     54     }
     55 }
     56 
     57 //-----------------------------------------------------------------
     58 void TestVideoDecoderCapabilities() {
     59 
     60     XAObjectItf xa;
     61     XAresult res;
     62 
     63     /* parameters for the OpenMAX AL engine creation */
     64     XAEngineOption EngineOption[] = {
     65             {(XAuint32) XA_ENGINEOPTION_THREADSAFE, (XAuint32) XA_BOOLEAN_TRUE}
     66     };
     67     XAInterfaceID itfIidArray[NUM_ENGINE_INTERFACES] = { XA_IID_VIDEODECODERCAPABILITIES };
     68     XAboolean     itfRequired[NUM_ENGINE_INTERFACES] = { XA_BOOLEAN_TRUE };
     69 
     70     /* create OpenMAX AL engine */
     71     res = xaCreateEngine( &xa, 1, EngineOption, NUM_ENGINE_INTERFACES, itfIidArray, itfRequired);
     72     ExitOnError(res);
     73 
     74     /* realize the engine in synchronous mode. */
     75     res = (*xa)->Realize(xa, XA_BOOLEAN_FALSE); ExitOnError(res);
     76 
     77     /* Get the video decoder capabilities interface which was explicitly requested */
     78     XAVideoDecoderCapabilitiesItf decItf;
     79     res = (*xa)->GetInterface(xa, XA_IID_VIDEODECODERCAPABILITIES, (void*)&decItf);
     80     ExitOnError(res);
     81 
     82     /* Query the platform capabilities */
     83     XAuint32 numDecoders = 0;
     84     XAuint32 *decoderIds = NULL;
     85 
     86     /* -> Number of decoders */
     87     res = (*decItf)->GetVideoDecoders(decItf, &numDecoders, NULL); ExitOnError(res);
     88     fprintf(stdout, "Found %d video decoders\n", numDecoders);
     89     if (0 == numDecoders) {
     90         fprintf(stderr, "0 video decoders is not an acceptable number, exiting\n");
     91         goto destroyRes;
     92     }
     93 
     94     /* -> Decoder list */
     95     decoderIds = (XAuint32 *) malloc(numDecoders * sizeof(XAuint32));
     96     res = (*decItf)->GetVideoDecoders(decItf, &numDecoders, decoderIds); ExitOnError(res);
     97     fprintf(stdout, "Decoders:\n");
     98     for(XAuint32 i = 0 ; i < numDecoders ; i++) {
     99         fprintf(stdout, "decoder %d is %s\n", i, videoCodecIdToString(decoderIds[i]));
    100     }
    101 
    102     /* -> Decoder capabilities */
    103     /*       for each decoder  */
    104     for(XAuint32 i = 0 ; i < numDecoders ; i++) {
    105         XAuint32 nbCombinations = 0;
    106         /* get the number of profile / level combinations */
    107         res = (*decItf)->GetVideoDecoderCapabilities(decItf, decoderIds[i], &nbCombinations, NULL);
    108         ExitOnError(res);
    109         fprintf(stdout, "decoder %s has %d profile/level combinations:\n\t",
    110                 videoCodecIdToString(decoderIds[i]), nbCombinations);
    111         /* display the profile / level combinations */
    112         for(XAuint32 pl = 0 ; pl < nbCombinations ; pl++) {
    113             XAVideoCodecDescriptor decDescriptor;
    114             res = (*decItf)->GetVideoDecoderCapabilities(decItf, decoderIds[i], &pl, &decDescriptor);
    115             ExitOnError(res);
    116             fprintf(stdout, "%u/%u ", decDescriptor.profileSetting, decDescriptor.levelSetting);
    117             ExitOnError(res);
    118         }
    119         fprintf(stdout, "\n");
    120     }
    121 
    122 destroyRes:
    123     free(decoderIds);
    124 
    125     /* shutdown OpenMAX AL */
    126     (*xa)->Destroy(xa);
    127 }
    128 
    129 
    130 //-----------------------------------------------------------------
    131 int main(int argc, char* const argv[])
    132 {
    133     XAresult    result;
    134     XAObjectItf sl;
    135 
    136     fprintf(stdout, "OpenMAX AL test %s: exercises SLAudioDecoderCapabiltiesItf ", argv[0]);
    137     fprintf(stdout, "and displays the list of supported video decoders, and for each, lists the ");
    138     fprintf(stdout, "profile / levels combinations, that map to the constants defined in ");
    139     fprintf(stdout, "\"XA_VIDEOPROFILE and XA_VIDEOLEVEL\" section of the specification\n\n");
    140 
    141     TestVideoDecoderCapabilities();
    142 
    143     return EXIT_SUCCESS;
    144 }
    145