| 1 | /* |
| 2 | Copyright (c) 2012, Broadcom Europe Ltd |
| 3 | All rights reserved. |
| 4 | |
| 5 | Redistribution and use in source and binary forms, with or without |
| 6 | modification, are permitted provided that the following conditions are met: |
| 7 | * Redistributions of source code must retain the above copyright |
| 8 | notice, this list of conditions and the following disclaimer. |
| 9 | * Redistributions in binary form must reproduce the above copyright |
| 10 | notice, this list of conditions and the following disclaimer in the |
| 11 | documentation and/or other materials provided with the distribution. |
| 12 | * Neither the name of the copyright holder nor the |
| 13 | names of its contributors may be used to endorse or promote products |
| 14 | derived from this software without specific prior written permission. |
| 15 | |
| 16 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND |
| 17 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
| 18 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
| 19 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY |
| 20 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
| 21 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
| 22 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND |
| 23 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 24 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
| 25 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 26 | */ |
| 27 | |
| 28 | #include "mmalomx.h" |
| 29 | #include "mmalomx_roles.h" |
| 30 | #include "mmalomx_registry.h" |
| 31 | #include "mmalomx_logging.h" |
| 32 | #include <util/mmal_default_components.h> |
| 33 | |
| 34 | #ifndef ENABLE_MMALOMX_AUDIO_HW_DECODER |
| 35 | # define ENABLE_MMALOMX_AUDIO_HW_DECODER 0 |
| 36 | #endif |
| 37 | #ifndef ENABLE_MMALOMX_AUDIO_SPDIF |
| 38 | # define ENABLE_MMALOMX_AUDIO_SPDIF 1 |
| 39 | #endif |
| 40 | |
| 41 | static const struct { |
| 42 | const char *omx; |
| 43 | const char *omx_prefix; |
| 44 | const char *mmal; |
| 45 | MMALOMX_ROLE_T roles[MMALOMX_ROLE_MAX]; |
| 46 | } mmalomx_components[] = |
| 47 | { |
| 48 | {"video.hw.decoder" , 0, MMAL_COMPONENT_DEFAULT_VIDEO_DECODER, |
| 49 | {MMALOMX_ROLE_VIDEO_DECODER_H263, MMALOMX_ROLE_VIDEO_DECODER_MPEG2, |
| 50 | MMALOMX_ROLE_VIDEO_DECODER_MPEG4, MMALOMX_ROLE_VIDEO_DECODER_AVC, |
| 51 | MMALOMX_ROLE_VIDEO_DECODER_WMV, MMALOMX_ROLE_VIDEO_DECODER_VPX, |
| 52 | MMALOMX_ROLE_UNDEFINED}}, |
| 53 | {"video.hw.decoder.secure" , 0, "drm_alloc.video_decode" , |
| 54 | {MMALOMX_ROLE_VIDEO_DECODER_H263, MMALOMX_ROLE_VIDEO_DECODER_MPEG2, |
| 55 | MMALOMX_ROLE_VIDEO_DECODER_MPEG4, MMALOMX_ROLE_VIDEO_DECODER_AVC, |
| 56 | MMALOMX_ROLE_VIDEO_DECODER_WMV, MMALOMX_ROLE_VIDEO_DECODER_VPX, |
| 57 | MMALOMX_ROLE_UNDEFINED}}, |
| 58 | {"video.hw.decoder.divx_drm" , 0, "aggregator.pipeline:divx_drm:vc.video_decode" , |
| 59 | {MMALOMX_ROLE_VIDEO_DECODER_MPEG4, MMALOMX_ROLE_UNDEFINED}}, |
| 60 | {"video.vpx.decoder" , 0, "libvpx" , |
| 61 | {MMALOMX_ROLE_VIDEO_DECODER_VPX, MMALOMX_ROLE_UNDEFINED}}, |
| 62 | |
| 63 | {"video.hw.encoder" , 0, MMAL_COMPONENT_DEFAULT_VIDEO_ENCODER, |
| 64 | {MMALOMX_ROLE_VIDEO_ENCODER_H263, MMALOMX_ROLE_VIDEO_ENCODER_MPEG4, |
| 65 | MMALOMX_ROLE_VIDEO_ENCODER_AVC, MMALOMX_ROLE_UNDEFINED}}, |
| 66 | |
| 67 | {"AIV.play" , "" , "aivplay" , |
| 68 | {MMALOMX_ROLE_AIV_PLAY_101, MMALOMX_ROLE_AIV_PLAY_AVCDDP, MMALOMX_ROLE_UNDEFINED}}, |
| 69 | {"AIV.play.avcddp" , "" , "aivplay.ddp" , |
| 70 | {MMALOMX_ROLE_AIV_PLAY_AVCDDP, MMALOMX_ROLE_AIV_PLAY_101, MMALOMX_ROLE_UNDEFINED}}, |
| 71 | |
| 72 | #if ENABLE_MMALOMX_AUDIO_HW_DECODER |
| 73 | {"audio.hw.decoder" , 0, "vc.ril.audio_decode" , |
| 74 | {MMALOMX_ROLE_AUDIO_DECODER_AAC, MMALOMX_ROLE_AUDIO_DECODER_MPGA_L1, |
| 75 | MMALOMX_ROLE_AUDIO_DECODER_MPGA_L2, MMALOMX_ROLE_AUDIO_DECODER_MPGA_L3, |
| 76 | MMALOMX_ROLE_AUDIO_DECODER_DDP, MMALOMX_ROLE_UNDEFINED}}, |
| 77 | #endif |
| 78 | |
| 79 | #if ENABLE_MMALOMX_AUDIO_SPDIF |
| 80 | {"audio.spdif" , 0, "spdif" , |
| 81 | {MMALOMX_ROLE_AUDIO_DECODER_DDP, MMALOMX_ROLE_UNDEFINED}}, |
| 82 | #endif |
| 83 | |
| 84 | {0, 0, 0, {MMALOMX_ROLE_UNDEFINED}} |
| 85 | }; |
| 86 | |
| 87 | int mmalomx_registry_find_component(const char *name) |
| 88 | { |
| 89 | int i, prefix_size; |
| 90 | const char *prefix; |
| 91 | |
| 92 | for (i = 0; mmalomx_components[i].omx; i++) |
| 93 | { |
| 94 | /* Check the prefix first */ |
| 95 | prefix = mmalomx_components[i].omx_prefix; |
| 96 | if (!prefix) |
| 97 | prefix = MMALOMX_COMPONENT_PREFIX; |
| 98 | prefix_size = strlen(prefix); |
| 99 | if (strncmp(name, prefix, prefix_size)) |
| 100 | continue; |
| 101 | |
| 102 | /* Check the rest of the name */ |
| 103 | if (!strcmp(name + prefix_size, mmalomx_components[i].omx)) |
| 104 | break; |
| 105 | } |
| 106 | |
| 107 | return mmalomx_components[i].mmal ? i : -1; |
| 108 | } |
| 109 | |
| 110 | const char *mmalomx_registry_component_mmal(int id) |
| 111 | { |
| 112 | if (id >= (int)MMAL_COUNTOF(mmalomx_components) || id < 0) |
| 113 | id = MMAL_COUNTOF(mmalomx_components) - 1; |
| 114 | |
| 115 | return mmalomx_components[id].mmal; |
| 116 | } |
| 117 | |
| 118 | MMALOMX_ROLE_T mmalomx_registry_component_roles(int id, unsigned int index) |
| 119 | { |
| 120 | unsigned int i; |
| 121 | |
| 122 | if (id >= (int)MMAL_COUNTOF(mmalomx_components) || id < 0) |
| 123 | id = MMAL_COUNTOF(mmalomx_components) - 1; |
| 124 | |
| 125 | for (i = 0; i < index; i++) |
| 126 | if (mmalomx_components[id].roles[i] == MMALOMX_ROLE_UNDEFINED) |
| 127 | break; |
| 128 | |
| 129 | return mmalomx_components[id].roles[i]; |
| 130 | } |
| 131 | |
| 132 | MMAL_BOOL_T mmalomx_registry_component_supports_role(int id, MMALOMX_ROLE_T role) |
| 133 | { |
| 134 | unsigned int i; |
| 135 | |
| 136 | if (id >= (int)MMAL_COUNTOF(mmalomx_components) || id < 0) |
| 137 | id = MMAL_COUNTOF(mmalomx_components) - 1; |
| 138 | |
| 139 | for (i = 0; mmalomx_components[id].roles[i] != MMALOMX_ROLE_UNDEFINED; i++) |
| 140 | if (mmalomx_components[id].roles[i] == role) |
| 141 | return MMAL_TRUE; |
| 142 | |
| 143 | return MMAL_FALSE; |
| 144 | } |
| 145 | |
| 146 | const char *mmalomx_registry_component_name(int id, const char **prefix) |
| 147 | { |
| 148 | if (id >= (int)MMAL_COUNTOF(mmalomx_components) || id < 0) |
| 149 | id = MMAL_COUNTOF(mmalomx_components) - 1; |
| 150 | |
| 151 | if (prefix) |
| 152 | { |
| 153 | *prefix = mmalomx_components[id].omx_prefix; |
| 154 | if (!*prefix) |
| 155 | *prefix = MMALOMX_COMPONENT_PREFIX; |
| 156 | } |
| 157 | |
| 158 | return mmalomx_components[id].omx; |
| 159 | } |
| 160 | |