Home | History | Annotate | Download | only in src
      1 /* ------------------------------------------------------------------
      2  * Copyright (C) 1998-2009 PacketVideo
      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
     13  * express or implied.
     14  * See the License for the specific language governing permissions
     15  * and limitations under the License.
     16  * -------------------------------------------------------------------
     17  */
     18 #include "pvmf_videoparser_port.h"
     19 #include "pvmf_videoparser_node.h"
     20 #include "pv_mime_string_utils.h"
     21 
     22 
     23 PVMFVideoParserPort::PVMFVideoParserPort(int32 aTag,
     24         PVMFFormatType format,
     25         PVMFNodeInterface* aNode,
     26         uint8* aFormatSpecificInfo, uint32 aFormatSpecificInfoLen,
     27         char*name)
     28         : PvmfPortBaseImpl(aTag, aNode, name),
     29         iFormatSpecificInfo(NULL),
     30         iFormatSpecificInfoLen(0)
     31 {
     32     Construct(aTag, format, aFormatSpecificInfo, aFormatSpecificInfoLen);
     33 }
     34 
     35 ////////////////////////////////////////////////////////////////////////////
     36 void PVMFVideoParserPort::Construct(int32 aTag, PVMFFormatType format, uint8* aFormatSpecificInfo, uint32 aFormatSpecificInfoLen)
     37 {
     38     if (aTag == PVMF_VIDEOPARSER_NODE_PORT_TYPE_SINK)
     39     {
     40         iLogger = PVLogger::GetLoggerObject("PVMFVideoParserPort(Input)");
     41         PvmiCapabilityAndConfigPortFormatImpl::Construct(INPUT_FORMATS_CAP_QUERY , INPUT_FORMATS_VALTYPE);
     42     }
     43     else
     44     {
     45         iLogger = PVLogger::GetLoggerObject("PVMFVideoParserPort(Output)");
     46         PvmiCapabilityAndConfigPortFormatImpl::Construct(OUTPUT_FORMATS_CAP_QUERY , OUTPUT_FORMATS_VALTYPE);
     47     }
     48     oscl_memset(&iStats, 0, sizeof(PvmfPortBaseImplStats));
     49     iFormat = format;
     50 
     51     if (aFormatSpecificInfo && aFormatSpecificInfoLen)
     52     {
     53         iFormatSpecificInfo = (uint8*)OSCL_MALLOC(aFormatSpecificInfoLen);
     54         if (iFormatSpecificInfo == NULL)
     55         {
     56             OSCL_LEAVE(PVMFErrNoMemory);
     57         }
     58         oscl_memcpy(iFormatSpecificInfo, aFormatSpecificInfo, aFormatSpecificInfoLen);
     59         iFormatSpecificInfoLen = aFormatSpecificInfoLen;
     60     }
     61 }
     62 
     63 
     64 PVMFVideoParserPort::~PVMFVideoParserPort()
     65 {
     66     if (iFormatSpecificInfo) delete iFormatSpecificInfo;
     67 
     68     Disconnect();
     69     ClearMsgQueues();
     70 }
     71 
     72 ////////////////////////////////////////////////////////////////////////////
     73 bool PVMFVideoParserPort::IsFormatSupported(PVMFFormatType aFmt)
     74 {
     75     return ((aFmt == PVMF_MIME_M4V) || (aFmt == PVMF_MIME_H2631998) || (aFmt == PVMF_MIME_H2632000));
     76 }
     77 
     78 ////////////////////////////////////////////////////////////////////////////
     79 void PVMFVideoParserPort::FormatUpdated()
     80 {
     81     PVLOGGER_LOGMSG(PVLOGMSG_INST_MLDBG, iLogger, PVLOGMSG_INFO
     82                     , (0, "PVMFVideoParserPort::FormatUpdated %s", iFormat.getMIMEStrPtr()));
     83 }
     84 
     85 
     86 PVMFStatus PVMFVideoParserPort::Connect(PVMFPortInterface* aPort)
     87 {
     88     PVLOGGER_LOGMSG(PVLOGMSG_INST_MLDBG, iLogger, PVLOGMSG_INFO
     89                     , (0, "PVMFVideoParserPort::Connect: aPort=0x%x", aPort));
     90     if (!aPort)
     91     {
     92         PVLOGGER_LOGMSG(PVLOGMSG_INST_MLDBG, iLogger, PVLOGMSG_INFO
     93                         , (0, "PVMFVideoParserPort::Connect: Error - Connecting to invalid port"));
     94         return PVMFErrArgument;
     95     }
     96 
     97     if (iConnectedPort)
     98     {
     99         PVLOGGER_LOGMSG(PVLOGMSG_INST_MLDBG, iLogger, PVLOGMSG_INFO
    100                         , (0, "PVMFVideoParserPort::Connect: Error - Already connected"));
    101         return PVMFFailure;
    102     }
    103 
    104     OsclAny* config = NULL;
    105 
    106     aPort->QueryInterface(PVMI_CAPABILITY_AND_CONFIG_PVUUID, config);
    107 
    108     if (config != NULL)
    109     {
    110         if (!(pvmiSetPortFormatSpecificInfoSync(OSCL_STATIC_CAST(PvmiCapabilityAndConfig*, config),
    111                                                 PVMF_FORMAT_SPECIFIC_INFO_KEY)))
    112         {
    113             PVLOGGER_LOGMSG(PVLOGMSG_INST_MLDBG, iLogger, PVLOGMSG_INFO
    114                             , (0, "PVMFVideoParserPort::Connect: Error - Unable To Send Format Specific Info To Peer"));
    115             return PVMFFailure;
    116         }
    117     }
    118 
    119     /*
    120      * Automatically connect the peer.
    121      */
    122     if (aPort->PeerConnect(this) != PVMFSuccess)
    123     {
    124         PVLOGGER_LOGMSG(PVLOGMSG_INST_MLDBG, iLogger, PVLOGMSG_INFO
    125                         , (0, "PVMFVideoParserPort::Connect: Error - Peer Connect failed"));
    126         return PVMFFailure;
    127     }
    128 
    129     iConnectedPort = aPort;
    130 
    131     PortActivity(PVMF_PORT_ACTIVITY_CONNECT);
    132     return PVMFSuccess;
    133 }
    134 
    135 PVMFStatus PVMFVideoParserPort::PeerConnect(PVMFPortInterface* aPort)
    136 {
    137     PVLOGGER_LOGMSG(PVLOGMSG_INST_LLDBG, iLogger, PVLOGMSG_STACK_TRACE,
    138                     (0, "0x%x PVMFVideoParserPort::PeerConnect: aPort=0x%x", this, aPort));
    139 
    140     if (!aPort)
    141     {
    142         PVLOGGER_LOGMSG(PVLOGMSG_INST_REL, iLogger, PVLOGMSG_ERR,
    143                         (0, "0x%x PVMFVideoParserPort::PeerConnect: Error - Connecting to invalid port", this));
    144         return PVMFErrArgument;
    145     }
    146 
    147     if (iConnectedPort)
    148     {
    149         PVLOGGER_LOGMSG(PVLOGMSG_INST_REL, iLogger, PVLOGMSG_ERR,
    150                         (0, "0x%x PVMFVideoParserPort::PeerConnect: Error - Already connected", this));
    151         return PVMFFailure;
    152     }
    153 
    154     iConnectedPort = aPort;
    155 
    156     OsclAny *config = NULL;
    157 
    158     aPort->QueryInterface(PVMI_CAPABILITY_AND_CONFIG_PVUUID, config);
    159 
    160     if (config != NULL)
    161     {
    162         if (!(pvmiSetPortFormatSpecificInfoSync(OSCL_STATIC_CAST(PvmiCapabilityAndConfig*, config), PVMF_FORMAT_SPECIFIC_INFO_KEY)))
    163         {
    164             PVLOGGER_LOGMSG(PVLOGMSG_INST_MLDBG, iLogger, PVLOGMSG_INFO
    165                             , (0, "PVMFVideoParserPort::PeerConnect: Error - Unable To Send Format Specific Info To Peer"));
    166             return PVMFFailure;
    167         }
    168     }
    169 
    170     PortActivity(PVMF_PORT_ACTIVITY_CONNECT);
    171     return PVMFSuccess;
    172 }
    173 
    174 PVMFStatus PVMFVideoParserPort::getParametersSync(PvmiMIOSession aSession,
    175         PvmiKeyType aIdentifier,
    176         PvmiKvp*& aParameters,
    177         int& num_parameter_elements,
    178         PvmiCapabilityContext aContext)
    179 {
    180     OSCL_UNUSED_ARG(aSession);
    181     OSCL_UNUSED_ARG(aIdentifier);
    182     OSCL_UNUSED_ARG(aContext);
    183     PVLOGGER_LOGMSG(PVLOGMSG_INST_MLDBG, iLogger, PVLOGMSG_INFO
    184                     , (0, "PVMFVideoParserPort::getParametersSync: aSession=0x%x, aIdentifier=%s, aParameters=0x%x, num_parameters_elements=%d, aContext=0x%x",
    185                        aSession, aIdentifier, aParameters, num_parameter_elements, aContext));
    186 
    187     num_parameter_elements = 0;
    188 
    189     if (pv_mime_strcmp(aIdentifier, PVMF_FORMAT_SPECIFIC_INFO_KEY) == 0)
    190     {
    191         if (!pvmiGetPortFormatSpecificInfoSync(PVMF_FORMAT_SPECIFIC_INFO_KEY, aParameters))
    192         {
    193             return PVMFFailure;
    194         }
    195         num_parameter_elements = 1;
    196         return PVMFSuccess;
    197     }
    198     return PvmiCapabilityAndConfigPortFormatImpl::getParametersSync(aSession, aIdentifier, aParameters, num_parameter_elements, aContext);
    199 }
    200 
    201 
    202 PVMFStatus PVMFVideoParserPort::releaseParameters(PvmiMIOSession aSession,
    203         PvmiKvp* aParameters,
    204         int num_elements)
    205 {
    206     OSCL_UNUSED_ARG(aSession);
    207     OSCL_UNUSED_ARG(num_elements);
    208     PVLOGGER_LOGMSG(PVLOGMSG_INST_MLDBG, iLogger, PVLOGMSG_INFO
    209                     , (0, "PVMFVideoParserPort::releaseParameters: aSession=0x%x, aParameters=0x%x, num_elements=%d",
    210                        aSession, aParameters, num_elements));
    211 
    212     if (pv_mime_strcmp(aParameters->key, PVMF_FORMAT_SPECIFIC_INFO_KEY) == 0)
    213     {
    214         OsclMemAllocator alloc;
    215         alloc.deallocate((OsclAny*)(aParameters->key));
    216         return PVMFSuccess;
    217     }
    218 
    219     return PvmiCapabilityAndConfigPortFormatImpl::releaseParameters(aSession, aParameters, num_elements);
    220 }
    221 
    222 void PVMFVideoParserPort::setParametersSync(PvmiMIOSession aSession,
    223         PvmiKvp* aParameters,
    224         int num_elements,
    225         PvmiKvp * & aRet_kvp)
    226 {
    227     OSCL_UNUSED_ARG(aSession);
    228     OSCL_UNUSED_ARG(aParameters);
    229     OSCL_UNUSED_ARG(aRet_kvp);
    230     OSCL_UNUSED_ARG(num_elements);
    231 
    232     PVLOGGER_LOGMSG(PVLOGMSG_INST_MLDBG, iLogger, PVLOGMSG_INFO
    233                     , (0, "PVMFVideoParserPort::getParametersSync: aSession=0x%x, aParameters=0x%x, num_elements=%d, aRet_kvp=0x%x",
    234                        aSession, aParameters, num_elements, aRet_kvp));
    235 }
    236 
    237 PVMFStatus PVMFVideoParserPort::verifyParametersSync(PvmiMIOSession aSession,
    238         PvmiKvp* aParameters,
    239         int num_elements)
    240 {
    241     OSCL_UNUSED_ARG(aSession);
    242     OSCL_UNUSED_ARG(aParameters);
    243     OSCL_UNUSED_ARG(num_elements);
    244     PVLOGGER_LOGMSG(PVLOGMSG_INST_MLDBG, iLogger, PVLOGMSG_INFO
    245                     , (0, "PVMFVideoParserPort::verifyParametersSync: aSession=0x%x, aParameters=0x%x, num_elements=%d",
    246                        aSession, aParameters, num_elements));
    247     return PVMFErrNotSupported;
    248 }
    249 
    250 
    251 bool
    252 PVMFVideoParserPort::pvmiSetPortFormatSpecificInfoSync(PvmiCapabilityAndConfig *aPort,
    253         const char* aFormatValType)
    254 {
    255     /*
    256      * Create PvmiKvp for capability settings
    257      */
    258     if (pv_mime_strcmp(aFormatValType, PVMF_FORMAT_SPECIFIC_INFO_KEY) == 0)
    259     {
    260         OsclMemAllocator alloc;
    261         PvmiKvp kvp;
    262         kvp.key = NULL;
    263         kvp.length = oscl_strlen(aFormatValType) + 1; // +1 for \0
    264         kvp.key = (PvmiKeyType)alloc.ALLOCATE(kvp.length);
    265         if (kvp.key == NULL)
    266         {
    267             return false;
    268         }
    269         oscl_strncpy(kvp.key, aFormatValType, kvp.length);
    270         if (iFormatSpecificInfoLen == 0)
    271         {
    272             kvp.value.key_specific_value = 0;
    273             kvp.capacity = 0;
    274         }
    275         else
    276         {
    277             kvp.value.key_specific_value = (OsclAny*)iFormatSpecificInfo;
    278             kvp.capacity = iFormatSpecificInfoLen;
    279         }
    280 
    281         PvmiKvp* retKvp = NULL; // for return value
    282         int32 err;
    283         OSCL_TRY(err, aPort->setParametersSync(NULL, &kvp, 1, retKvp););
    284         /* ignore the error for now */
    285         alloc.deallocate((OsclAny*)(kvp.key));
    286         return true;
    287     }
    288     return false;
    289 }
    290 
    291 bool
    292 PVMFVideoParserPort::pvmiGetPortFormatSpecificInfoSync(const char* aFormatValType,
    293         PvmiKvp*& aKvp)
    294 {
    295     /*
    296      * Create PvmiKvp for capability settings
    297      */
    298 
    299     if (pv_mime_strcmp(aFormatValType, PVMF_FORMAT_SPECIFIC_INFO_KEY) == 0)
    300     {
    301         OsclMemAllocator alloc;
    302         aKvp->key = NULL;
    303         aKvp->length = oscl_strlen(aFormatValType) + 1; // +1 for \0
    304         aKvp->key = (PvmiKeyType)alloc.ALLOCATE(aKvp->length);
    305         if (aKvp->key == NULL)
    306         {
    307             return false;
    308         }
    309         oscl_strncpy(aKvp->key, aFormatValType, aKvp->length);
    310         if (iFormatSpecificInfoLen == 0)
    311         {
    312             aKvp->value.key_specific_value = 0;
    313             aKvp->capacity = 0;
    314         }
    315         else
    316         {
    317             aKvp->value.key_specific_value = (OsclAny*)iFormatSpecificInfo;
    318             aKvp->capacity = iFormatSpecificInfoLen;
    319         }
    320         return true;
    321     }
    322     return false;
    323 }
    324