summaryrefslogtreecommitdiff
path: root/mm-core/src/common/qc_omx_core.c
blob: 8edb7318ecc26ba360a307300a0a69ac9d8635ef (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
/*--------------------------------------------------------------------------
Copyright (c) 2009, 2015, 2018-2019, The Linux Foundation. All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
    * Redistributions of source code must retain the above copyright
      notice, this list of conditions and the following disclaimer.
    * Redistributions in binary form must reproduce the above copyright
      notice, this list of conditions and the following disclaimer in the
      documentation and/or other materials provided with the distribution.
    * Neither the name of The Linux Foundation nor
      the names of its contributors may be used to endorse or promote
      products derived from this software without specific prior written
      permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NON-INFRINGEMENT ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
--------------------------------------------------------------------------*/
/*============================================================================
                            O p e n M A X   w r a p p e r s
                             O p e n  M A X   C o r e

  This module contains the implementation of the OpenMAX core.

*//*========================================================================*/

//////////////////////////////////////////////////////////////////////////////
//                             Include Files
//////////////////////////////////////////////////////////////////////////////

#include <dlfcn.h>           // dynamic library
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <string.h>
#include <stdio.h>
#include <pthread.h>
#include <stdlib.h>

#include "qc_omx_core.h"
#include "omx_core_cmp.h"
#include <cutils/properties.h>

#include "ConfigStore.h"

extern omx_core_cb_type core[];
extern const unsigned int SIZE_OF_CORE;
static pthread_mutex_t lock_core = PTHREAD_MUTEX_INITIALIZER;
static int number_of_adec_nt_session;

extern omx_core_cb_type component[];
unsigned int num_components = 0;

#define MAX_AUDIO_NT_SESSION 2

/* ======================================================================
FUNCTION
  omx_core_load_cmp_library

DESCRIPTION
  Loads up the libary name mentioned in the argument

PARAMETERS
  None

RETURN VALUE
  Constructor for creating component instances.
========================================================================== */
static create_qc_omx_component
omx_core_load_cmp_library(char *libname, void **handle_ptr)
{
  create_qc_omx_component fn_ptr = NULL;
  if(handle_ptr)
  {
    DEBUG_PRINT("Dynamically Loading the library : %s\n",libname);
    if (!strcmp(libname, "libOmxVpp.so"))
        *handle_ptr = dlopen(libname, RTLD_NOW|RTLD_GLOBAL);
    else
        *handle_ptr = dlopen(libname, RTLD_NOW);

    if(*handle_ptr)
    {
      fn_ptr = dlsym(*handle_ptr, "get_omx_component_factory_fn");

      if(fn_ptr == NULL)
      {
        DEBUG_PRINT("Error: Library %s incompatible as QCOM OMX component loader - %s\n",
                  libname, dlerror());
        *handle_ptr = NULL;
      }
    }
    else
    {
      DEBUG_PRINT("Error: Couldn't load %s: %s\n",libname,dlerror());
    }
  }
  return fn_ptr;
}

/* ======================================================================
FUNCTION
  OMX_Init

DESCRIPTION
  This is the first function called by the application.
  There is nothing to do here since components shall be loaded
  whenever the get handle method is called.

PARAMETERS
  None

RETURN VALUE
  None.
========================================================================== */
OMX_API OMX_ERRORTYPE OMX_APIENTRY
OMX_Init()
{
    char platform_name[PROP_VALUE_MAX] = {0};
    char version[PROP_VALUE_MAX] = {0};
    property_get("ro.board.platform", platform_name, "0");

  DEBUG_PRINT("OMXCORE API - OMX_Init \n");

  // Use below method to generate list of components actually supported
  // on any given platform. Core list is considered as superset and does
  // not determine the actual supported codecs on a particular target.
  num_components = 0;
  for (int i = 0; i < SIZE_OF_CORE; i++) {
      if (!strcmp(platform_name, "sm6150")) {
          if (!strcmp("OMX.qti.video.decoder.vc1sw", core[i].name) || !strcmp("OMX.qcom.video.encoder.heic", core[i].name)) {
                //Talos (6150) both does not support vc1 and heic hence don't add them in list
              if (property_get("vendor.media.target.version", version, "0") && (atoi(version) == 0))
                  continue;
          } else if (!strcmp("OMX.qcom.video.encoder.tme", core[i].name) || !strcmp("OMX.qcom.video.encoder.tme.secure", core[i].name))
                    continue;
      } else if (!strcmp(platform_name, "atoll")) {
                //Atoll does not support vc1 and vpp hence don't add them in list
              if (!strcmp("OMX.qti.video.decoder.vc1sw", core[i].name) || !strcmp("OMX.qti.vdec.vpp", core[i].name))
                     continue;
      } else if (!strcmp(platform_name, "trinket")) {
                //Trinket does not support vc1,tme,tme-secure hence don't add them in list
              if (!strcmp("OMX.qti.video.decoder.vc1sw", core[i].name) || !strcmp("OMX.qcom.video.encoder.tme", core[i].name) ||
                  !strcmp("OMX.qcom.video.encoder.tme.secure", core[i].name) || !strcmp("OMX.qti.vdec.vpp", core[i].name))
                     continue;
      } else if (!strcmp(platform_name, "msmnile")) {
                //Hana does not support tme,tme secure hence donot add to list
                if (!strcmp("OMX.qcom.video.encoder.tme", core[i].name) || !strcmp("OMX.qcom.video.encoder.tme.secure", core[i].name))
                    continue;
      }

    memcpy(&component[num_components++],
           &core[i], sizeof(omx_core_cb_type));
  }
  return OMX_ErrorNone;
}

/* ======================================================================
FUNCTION
  get_cmp_index

DESCRIPTION
  Obtains the  index associated with the name.

PARAMETERS
  None

RETURN VALUE
  Error None.
========================================================================== */
static int get_cmp_index(char *cmp_name)
{
  int rc = -1,i=0;
  DEBUG_PRINT("before get_cmp_index **********%d\n", rc);

  for (i = 0; i < num_components; i++)
  {
    DEBUG_PRINT("get_cmp_index: cmp_name = %s , core[i].name = %s ,count = %d \n",
                cmp_name, component[i].name, i);

    if (!strcmp(cmp_name, component[i].name))
    {
        rc = i;
        break;
    }
  }
  DEBUG_PRINT("returning index %d\n", rc);
  return rc;
}

/* ======================================================================
FUNCTION
  clear_cmp_handle

DESCRIPTION
  Clears the component handle from the component table.

PARAMETERS
  None

RETURN VALUE
  None.
========================================================================== */
static void clear_cmp_handle(OMX_HANDLETYPE inst)
{
  unsigned i = 0,j=0;

  if(NULL == inst)
     return;

  for (i = 0; i < num_components; i++)
  {
    for(j=0; j< OMX_COMP_MAX_INST; j++)
    {
      if (inst == component[i].inst[j])
      {
        component[i].inst[j] = NULL;
        return;
      }
    }
  }
  return;
}
/* ======================================================================
FUNCTION
  is_cmp_handle_exists

DESCRIPTION
  Check if the component handle already exists or not.

PARAMETERS
  None

RETURN VALUE
  index pointer if the handle exists
  negative value otherwise
========================================================================== */
static int is_cmp_handle_exists(OMX_HANDLETYPE inst)
{
  unsigned i=0,j=0;
  int rc = -1;

  if(NULL == inst)
     return rc;

  pthread_mutex_lock(&lock_core);
  for (i = 0; i < num_components; i++)
  {
    for(j=0; j< OMX_COMP_MAX_INST; j++)
    {
      if (inst == component[i].inst[j])
      {
        rc = i;
        goto finish;
      }
    }
  }
finish:
  pthread_mutex_unlock(&lock_core);
  return rc;
}

/* ======================================================================
FUNCTION
  get_comp_handle_index

DESCRIPTION
  Gets the index to store the next handle for specified component name.

PARAMETERS
  cmp_name : Component Name

RETURN VALUE
  Index of next handle to be stored
========================================================================== */
static int get_comp_handle_index(char *cmp_name)
{
  unsigned i=0,j=0;
  int rc = -1;
  for (i = 0; i < num_components; i++)
  {
    if (!strcmp(cmp_name, component[i].name))
    {
      for(j=0; j< OMX_COMP_MAX_INST; j++)
      {
        if (NULL == component[i].inst[j])
        {
          rc = j;
          DEBUG_PRINT("free handle slot exists %d\n", rc);
          return rc;
        }
      }
      break;
    }
  }
  return rc;
}

/* ======================================================================
FUNCTION
  check_lib_unload

DESCRIPTION
  Check if any component instance is using the library

PARAMETERS
  index: Component Index in core array.

RETURN VALUE
  1: Library Unused and can be unloaded.
  0:  Library used and shouldnt be unloaded.
========================================================================== */
static int check_lib_unload(int index)
{
  unsigned i=0;
  int rc = 1;

  for(i=0; i< OMX_COMP_MAX_INST; i++)
  {
    if (component[index].inst[i])
    {
      rc = 0;
      DEBUG_PRINT("Library Used \n");
      break;
    }
  }
  return rc;
}

/* ======================================================================
FUNCTION
  get_cmp_handle

DESCRIPTION
  Get component handle.

PARAMETERS
  None

RETURN VALUE
  Error None.
========================================================================== */
void* get_cmp_handle(char *cmp_name)
{
  unsigned i    =0,j=0;

  DEBUG_PRINT("get_cmp_handle \n");
  for (i = 0; i < num_components; i++)
  {
    if (!strcmp(cmp_name, component[i].name))
    {
      for(j=0; j< OMX_COMP_MAX_INST; j++)
      {
        if (component[i].inst[j])
        {
          DEBUG_PRINT("get_cmp_handle match\n");
          return component[i].inst[j];
        }
      }
    }
  }
  DEBUG_PRINT("get_cmp_handle returning NULL \n");
  return NULL;
}

/* ======================================================================
FUNCTION
  OMX_DeInit

DESCRIPTION
  DeInitialize all the the relevant OMX components.

PARAMETERS
  None

RETURN VALUE
  Error None.
========================================================================== */
OMX_API OMX_ERRORTYPE OMX_APIENTRY
OMX_Deinit()
{
  return OMX_ErrorNone;
}

/* ======================================================================
FUNCTION
  OMX_GetHandle

DESCRIPTION
  Constructs requested component. Relevant library is loaded if needed.

PARAMETERS
  None

RETURN VALUE
  Error None  if everything goes fine.
========================================================================== */

 OMX_API OMX_ERRORTYPE OMX_APIENTRY
OMX_GetHandle(OMX_OUT OMX_HANDLETYPE*     handle,
              OMX_IN OMX_STRING    componentName,
              OMX_IN OMX_PTR             appData,
              OMX_IN OMX_CALLBACKTYPE* callBacks)
{
  OMX_ERRORTYPE  eRet = OMX_ErrorNone;
  int cmp_index = -1;
  int hnd_index = -1;
  int vpp_cmp_index = -1;

  DEBUG_PRINT("OMXCORE API :  GetHandle %p %s %p\n", handle,
                                                     componentName,
                                                     appData);
  pthread_mutex_lock(&lock_core);
  if(handle)
  {
    *handle = NULL;
    char optComponentName[OMX_MAX_STRINGNAME_SIZE];
    strlcpy(optComponentName, componentName, OMX_MAX_STRINGNAME_SIZE);

    if(strstr(componentName, "avc") && strstr(componentName, "decoder"))
    {
      void *libhandle = dlopen("libOmxVideoDSMode.so", RTLD_NOW);
      if(libhandle)
      {
        int (*fn_ptr)()  = dlsym(libhandle, "isDSModeActive");

        if(fn_ptr == NULL)
        {
          DEBUG_PRINT_ERROR("Error: isDSModeActive Not Found %s\n",
                    dlerror());
        }
        else
        {
          int isActive = fn_ptr();
          char *pSubString = strstr(componentName, ".dsmode");
          if(pSubString)
          {
            optComponentName[pSubString - componentName] = 0;
          }
          else if(isActive)
          {
            strlcat(optComponentName, ".dsmode", OMX_MAX_STRINGNAME_SIZE);
          }
          cmp_index = get_cmp_index(optComponentName);
        }
        dlclose(libhandle);
      }
      else
      {
        DEBUG_PRINT_ERROR("Failed to load dsmode library");
      }
    }

    if(cmp_index < 0)
    {
      cmp_index = get_cmp_index(componentName);
      strlcpy(optComponentName, componentName, OMX_MAX_STRINGNAME_SIZE);
    }
    if(cmp_index >= 0)
    {
      DEBUG_PRINT("getting fn pointer\n");

      // Load VPP omx component for decoder if vpp property is enabled
      const char *hwDecLib = "libOmxVdec.so";
      const char *swDecLib = "libOmxSwVdec.so";
      if (!strncmp(component[cmp_index].so_lib_name, hwDecLib, strlen(hwDecLib)) ||
          !strncmp(component[cmp_index].so_lib_name, swDecLib, strlen(swDecLib))) {
        bool isVppEnabled = false;
        if (isConfigStoreEnabled()) {
          getConfigStoreBool("vpp", "enable", &isVppEnabled, false);
        } else {
          char value[PROPERTY_VALUE_MAX];
          if ((property_get("vendor.media.vpp.enable", value, NULL))
               && (!strcmp("1", value) || !strcmp("true", value))) {
            isVppEnabled = true;
          }
        }
        if (isVppEnabled) {
          DEBUG_PRINT("VPP property is enabled");
          vpp_cmp_index = get_cmp_index("OMX.qti.vdec.vpp");
          if (vpp_cmp_index < 0) {
            DEBUG_PRINT_ERROR("Unable to find VPP OMX lib in registry ");
          } else {
            DEBUG_PRINT("Loading vpp for vdec");
            cmp_index = vpp_cmp_index;
          }
        }
      }

       // dynamically load the so
      component[cmp_index].fn_ptr =
        omx_core_load_cmp_library(component[cmp_index].so_lib_name,
                                  &component[cmp_index].so_lib_handle);


      if(component[cmp_index].fn_ptr)
      {
        //Do not allow more than MAX limit for DSP audio decoders
        if((!strcmp(component[cmp_index].so_lib_name,"libOmxWmaDec.so")  ||
            !strcmp(component[cmp_index].so_lib_name,"libOmxAacDec.so")  ||
            !strcmp(component[cmp_index].so_lib_name,"libOmxG711Dec.so")  ||
            !strcmp(component[cmp_index].so_lib_name,"libOmxAlacDec.so") ||
            !strcmp(component[cmp_index].so_lib_name,"libOmxApeDec.so")) &&
            (number_of_adec_nt_session+1 > MAX_AUDIO_NT_SESSION)) {
            DEBUG_PRINT_ERROR("Rejecting new session..Reached max limit for DSP audio decoder session");
            pthread_mutex_unlock(&lock_core);
            return OMX_ErrorInsufficientResources;
        }
        // Construct the component requested
        // Function returns the opaque handle
        void* pThis = (*(component[cmp_index].fn_ptr))();
        if(pThis)
        {
          void *hComp = NULL;
          hComp = qc_omx_create_component_wrapper((OMX_PTR)pThis);
          if((eRet = qc_omx_component_init(hComp, optComponentName)) !=
                           OMX_ErrorNone)
          {
              DEBUG_PRINT("Component not created succesfully\n");
              pthread_mutex_unlock(&lock_core);
              return eRet;

          }
          qc_omx_component_set_callbacks(hComp,callBacks,appData);

          if (vpp_cmp_index >= 0)
          {
            hnd_index = get_comp_handle_index("OMX.qti.vdec.vpp");
          }
          else
          {
            hnd_index = get_comp_handle_index(optComponentName);
          }

          if(hnd_index >= 0)
          {
            component[cmp_index].inst[hnd_index]= *handle = (OMX_HANDLETYPE) hComp;
          }
          else
          {
            DEBUG_PRINT("OMX_GetHandle:NO free slot available to store Component Handle\n");
            pthread_mutex_unlock(&lock_core);
            return OMX_ErrorInsufficientResources;
          }
          DEBUG_PRINT("Component %p Successfully created\n",*handle);
          if(!strcmp(component[cmp_index].so_lib_name,"libOmxWmaDec.so")  ||
             !strcmp(component[cmp_index].so_lib_name,"libOmxAacDec.so")  ||
             !strcmp(component[cmp_index].so_lib_name,"libOmxG711Dec.so")  ||
             !strcmp(component[cmp_index].so_lib_name,"libOmxAlacDec.so") ||
             !strcmp(component[cmp_index].so_lib_name,"libOmxApeDec.so")) {

             number_of_adec_nt_session++;
             DEBUG_PRINT("OMX_GetHandle: number_of_adec_nt_session : %d\n",
                             number_of_adec_nt_session);
          }
        }
        else
        {
          eRet = OMX_ErrorInsufficientResources;
          DEBUG_PRINT("Component Creation failed\n");
        }
      }
      else
      {
        eRet = OMX_ErrorNotImplemented;
        DEBUG_PRINT("library couldnt return create instance fn\n");
      }

    }
    else
    {
      eRet = OMX_ErrorNotImplemented;
      DEBUG_PRINT("ERROR: Already another instance active  ;rejecting \n");
    }
  }
  else
  {
    eRet =  OMX_ErrorBadParameter;
    DEBUG_PRINT("\n OMX_GetHandle: NULL handle \n");
  }
  pthread_mutex_unlock(&lock_core);
  return eRet;
}
/* ======================================================================
FUNCTION
  OMX_FreeHandle

DESCRIPTION
  Destructs the component handles.

PARAMETERS
  None

RETURN VALUE
  Error None.
========================================================================== */
OMX_API OMX_ERRORTYPE OMX_APIENTRY
OMX_FreeHandle(OMX_IN OMX_HANDLETYPE hComp)
{
  OMX_ERRORTYPE eRet = OMX_ErrorNone;
  int err = 0, i = 0;
  DEBUG_PRINT("OMXCORE API :  FreeHandle %p\n", hComp);

  // 0. Check that we have an active instance
  if((i=is_cmp_handle_exists(hComp)) >=0)
  {
    // 1. Delete the component
    if ((eRet = qc_omx_component_deinit(hComp)) == OMX_ErrorNone)
    {
        pthread_mutex_lock(&lock_core);
        clear_cmp_handle(hComp);
        /* Unload component library */
    if( (i < (int)num_components) && component[i].so_lib_handle)
    {
           if(check_lib_unload(i))
           {
              DEBUG_PRINT_ERROR(" Unloading the dynamic library for %s\n",
                                  component[i].name);
              err = dlclose(component[i].so_lib_handle);
              if(err)
              {
                  DEBUG_PRINT_ERROR("Error %d in dlclose of lib %s\n",
                                     err,component[i].name);
              }
              component[i].so_lib_handle = NULL;
           }
           if(!strcmp(component[i].so_lib_name,"libOmxWmaDec.so")  ||
              !strcmp(component[i].so_lib_name,"libOmxAacDec.so")  ||
              !strcmp(component[i].so_lib_name,"libOmxAlacDec.so") ||
              !strcmp(component[i].so_lib_name,"libOmxApeDec.so")) {
               if(number_of_adec_nt_session>0)
                   number_of_adec_nt_session--;
               DEBUG_PRINT_ERROR("OMX_FreeHandle: reduced number_of_adec_nt_session %d\n",
                                   number_of_adec_nt_session);
           }
    }
    pthread_mutex_unlock(&lock_core);
    }
    else
    {
        DEBUG_PRINT(" OMX_FreeHandle failed on %p\n", hComp);
        return eRet;
    }
  }
  else
  {
    DEBUG_PRINT_ERROR("OMXCORE Warning: Free Handle called with no active instances\n");
  }
  return OMX_ErrorNone;
}
/* ======================================================================
FUNCTION
  OMX_SetupTunnel

DESCRIPTION
  Not Implemented.

PARAMETERS
  None

RETURN VALUE
  None.
========================================================================== */
OMX_API OMX_ERRORTYPE OMX_APIENTRY
OMX_SetupTunnel(OMX_IN OMX_HANDLETYPE outputComponent,
                OMX_IN OMX_U32             outputPort,
                OMX_IN OMX_HANDLETYPE  inputComponent,
                OMX_IN OMX_U32              inputPort)
{
  (void) outputComponent, (void) outputPort, (void) inputComponent, (void) inputPort;
  /* Not supported right now */
  DEBUG_PRINT("OMXCORE API: OMX_SetupTunnel Not implemented \n");
  return OMX_ErrorNotImplemented;
}
/* ======================================================================
FUNCTION
  OMX_GetContentPipe

DESCRIPTION
  Not Implemented.

PARAMETERS
  None

RETURN VALUE
  None.
========================================================================== */
OMX_API OMX_ERRORTYPE
OMX_GetContentPipe(OMX_OUT OMX_HANDLETYPE* pipe,
                   OMX_IN OMX_STRING        uri)
{
  (void) pipe, (void) uri;
  /* Not supported right now */
  DEBUG_PRINT("OMXCORE API: OMX_GetContentPipe Not implemented \n");
  return OMX_ErrorNotImplemented;
}

/* ======================================================================
FUNCTION
  OMX_GetComponentNameEnum

DESCRIPTION
  Returns the component name associated with the index.

PARAMETERS
  None

RETURN VALUE
  None.
========================================================================== */
OMX_API OMX_ERRORTYPE OMX_APIENTRY
OMX_ComponentNameEnum(OMX_OUT OMX_STRING componentName,
                      OMX_IN  OMX_U32          nameLen,
                      OMX_IN  OMX_U32            index)
{
  OMX_ERRORTYPE eRet = OMX_ErrorNone;
  if (index < num_components &&
      strncmp(component[index].name, "OMX.QCOM.CUST.COMP.START",
              strlen("OMX.QCOM.CUST.COMP.START")))
  {
    #ifdef _ANDROID_
    strlcpy(componentName, component[index].name, nameLen);
    #else
    strlcpy(componentName, component[index].name, nameLen);
    #endif
    DEBUG_PRINT("OMXCORE API - OMX_ComponentNameEnum [%d] %s\n",
                (unsigned)index, componentName);
  }
  else
  {
    eRet = OMX_ErrorNoMore;
  }
  return eRet;
}

/* ======================================================================
FUNCTION
  OMX_GetComponentsOfRole

DESCRIPTION
  Returns the component name which can fulfill the roles passed in the
  argument.

PARAMETERS
  None

RETURN VALUE
  None.
========================================================================== */
OMX_API OMX_ERRORTYPE
OMX_GetComponentsOfRole(OMX_IN OMX_STRING      role,
                        OMX_INOUT OMX_U32* numComps,
                        OMX_INOUT OMX_U8** compNames)
{
  OMX_ERRORTYPE eRet = OMX_ErrorNone;
  unsigned i,j,namecount=0;

  printf(" Inside OMX_GetComponentsOfRole \n");

  /*If CompNames is NULL then return*/
  if (compNames == NULL)
  {
    if (numComps == NULL)
    {
      eRet = OMX_ErrorBadParameter;
    }
    else
    {
      *numComps = 0;
      for (i = 0; i < num_components; i++)
      {
        for (j = 0; j < OMX_CORE_MAX_CMP_ROLES && component[i].roles[j]; j++)
        {
          if (!strcmp(role,component[i].roles[j]))
          {
            (*numComps)++;
          }
        }
      }
    }
    return eRet;
  }

  if(numComps)
  {
      namecount = *numComps;

      if (namecount == 0)
      {
          return OMX_ErrorBadParameter;
      }

    *numComps          = 0;

    for (i = 0; i < num_components;i++)
    {
      for (j = 0; j < OMX_CORE_MAX_CMP_ROLES && component[i].roles[j]; j++)
      {
        if (!strcmp(role,component[i].roles[j]))
        {
          #ifdef _ANDROID_
          strlcpy((char *)compNames[*numComps],component[i].name, OMX_MAX_STRINGNAME_SIZE);
          #else
          strlcpy((char *)compNames[*numComps],component[i].name, OMX_MAX_STRINGNAME_SIZE);
          #endif
          (*numComps)++;
          break;
        }
      }
          if (*numComps == namecount)
          {
          break;
        }
    }
  }
  else
  {
    eRet = OMX_ErrorBadParameter;
  }

  printf(" Leaving OMX_GetComponentsOfRole \n");
  return eRet;
}
/* ======================================================================
FUNCTION
  OMX_GetRolesOfComponent

DESCRIPTION
  Returns the primary role of the components supported.

PARAMETERS
  None

RETURN VALUE
  None.
========================================================================== */
OMX_API OMX_ERRORTYPE
OMX_GetRolesOfComponent(OMX_IN OMX_STRING compName,
                        OMX_INOUT OMX_U32* numRoles,
                        OMX_OUT OMX_U8** roles)
{
  /* Not supported right now */
  OMX_ERRORTYPE eRet = OMX_ErrorNone;
  unsigned i,j,numofroles = 0;;
  DEBUG_PRINT("GetRolesOfComponent %s\n",compName);

  if (roles == NULL)
  {
    if (numRoles == NULL)
    {
      eRet = OMX_ErrorBadParameter;
    }
    else
    {
      *numRoles = 0;
      for (i = 0; i < num_components; i++)
      {
        if (!strcmp(compName,component[i].name))
        {
          for (j = 0; j < OMX_CORE_MAX_CMP_ROLES && component[i].roles[j]; j++)
          {
            (*numRoles)++;
          }
          break;
        }
      }
    }
    return eRet;
  }

  if(numRoles)
  {
    if (*numRoles == 0)
    {
        return OMX_ErrorBadParameter;
    }

    numofroles = *numRoles;
    *numRoles = 0;
    for (i = 0; i < num_components; i++)
    {
      if (!strcmp(compName, component[i].name))
      {
        for (j = 0; j < OMX_CORE_MAX_CMP_ROLES && component[i].roles[j]; j++)
        {
          if(roles && roles[*numRoles])
          {
            #ifdef _ANDROID_
            strlcpy((char *)roles[*numRoles],
                    component[i].roles[j], OMX_MAX_STRINGNAME_SIZE);
            #else
            strlcpy((char *)roles[*numRoles],
                    component[i].roles[j], OMX_MAX_STRINGNAME_SIZE);
            #endif
          }
          (*numRoles)++;
          if (numofroles == *numRoles)
          {
              break;
          }
        }
        break;
      }
    }
  }
  else
  {
    DEBUG_PRINT("ERROR: Both Roles and numRoles Invalid\n");
    eRet = OMX_ErrorBadParameter;
  }
  return eRet;
}

OMX_API OMX_BOOL
OMXConfigParser(
    OMX_PTR aInputParameters,
    OMX_PTR aOutputParameters)
{
    OMX_BOOL Status = OMX_TRUE;
    VideoOMXConfigParserOutputs *aOmxOutputParameters;
    OMXConfigParserInputs *aOmxInputParameters;
    aOmxOutputParameters = (VideoOMXConfigParserOutputs *)aOutputParameters;
    aOmxInputParameters = (OMXConfigParserInputs *)aInputParameters;

    aOmxOutputParameters->width = 176; //setting width to QCIF
    aOmxOutputParameters->height = 144; //setting height to QCIF

    //TODO
    //Qcom component do not use the level/profile from IL client .They are parsing the first buffer
    //sent in ETB so for now setting the defalut values . Going farward we can call
    //QC parser here.
    if (0 == strcmp(aOmxInputParameters->cComponentRole, (OMX_STRING)"video_decoder.avc"))
    {
       aOmxOutputParameters->profile = 66; //minimum supported h264 profile - setting to baseline profile
       aOmxOutputParameters->level = 0;  // minimum supported h264 level
    }
    else if ((0 == strcmp(aOmxInputParameters->cComponentRole, (OMX_STRING)"video_decoder.mpeg4")) || (0 == strcmp(aOmxInputParameters ->cComponentRole, (OMX_STRING)"video_decoder.h263")))
    {
       aOmxOutputParameters->profile = 8; //minimum supported h263/mpeg4 profile
       aOmxOutputParameters->level = 0; // minimum supported h263/mpeg4 level
    }

    return Status;
}