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 19 #include "oscl_error.h" 20 #include "oscl_defalloc.h" 21 #include "pvmf_format_type.h" 22 #include "pvmi_config_and_capability_utils.h" 23 #include "pv_mime_string_utils.h" 24 25 26 //////////////////////////////////////////////////////////////////////////// 27 OSCL_EXPORT_REF PVMFStatus PvmiCapabilityAndConfigPortFormatImpl::getParametersSync(PvmiMIOSession aSession, PvmiKeyType aIdentifier, 28 PvmiKvp*& aParameters, int& num_parameter_elements, 29 PvmiCapabilityContext aContext) 30 { 31 OSCL_UNUSED_ARG(aContext); 32 OSCL_UNUSED_ARG(aSession); 33 34 num_parameter_elements = 0; 35 36 if (pv_mime_strcmp(aIdentifier, iFormatTypeString.get_str()) != 0) 37 { 38 if (pv_mime_strstr(aIdentifier, iFormatTypeString.get_str())) 39 { 40 // if we have a 'cap' or 'cur' parameter we can return 41 // ok 42 char *param; 43 if (pv_mime_string_extract_param(0, aIdentifier, param)) 44 { 45 if (oscl_strncmp(param, "attr=cap", oscl_strlen("attr=cap")) && 46 oscl_strncmp(param, "attr=cur", oscl_strlen("attr=cur"))) 47 return PVMFErrNotSupported; 48 } 49 } 50 } 51 52 uint32 strLen = iFormatValTypeString.get_size() + 1; 53 OsclMemAllocator alloc; 54 uint8* ptr = (uint8*)alloc.ALLOCATE(sizeof(PvmiKvp) + strLen); 55 if (!ptr) 56 { 57 return PVMFErrNoMemory; 58 } 59 60 num_parameter_elements = 1; 61 62 aParameters = new(ptr) PvmiKvp; 63 ptr += sizeof(PvmiKvp); 64 aParameters->key = (PvmiKeyType)ptr; 65 oscl_strncpy(aParameters->key, iFormatValTypeString.get_cstr(), strLen); 66 aParameters->value.pChar_value = (char*)iFormat.getMIMEStrPtr(); 67 aParameters->length = aParameters->capacity = strLen; 68 69 return PVMFSuccess; 70 } 71 72 73 //////////////////////////////////////////////////////////////////////////// 74 OSCL_EXPORT_REF PVMFStatus PvmiCapabilityAndConfigPortFormatImpl::releaseParameters(PvmiMIOSession aSession, PvmiKvp* aParameters, int num_elements) 75 { 76 OSCL_UNUSED_ARG(aSession); 77 if ((num_elements != 1) || 78 (pv_mime_strcmp(aParameters->key, iFormatValTypeString.get_str()) != 0)) 79 { 80 return PVMFFailure; 81 } 82 OsclMemAllocator alloc; 83 alloc.deallocate((OsclAny*)aParameters); 84 return PVMFSuccess; 85 } 86 87 //////////////////////////////////////////////////////////////////////////// 88 OSCL_EXPORT_REF void PvmiCapabilityAndConfigPortFormatImpl::setParametersSync(PvmiMIOSession aSession, PvmiKvp* aParameters, 89 int num_elements, PvmiKvp * & aRet_kvp) 90 { 91 OSCL_UNUSED_ARG(aSession); 92 if (!aParameters || (num_elements != 1) || 93 (pv_mime_strcmp(aParameters->key, iFormatValTypeString.get_str()) != 0)) 94 { 95 aRet_kvp = aParameters; 96 OSCL_LEAVE(OsclErrArgument); 97 } 98 else if (IsFormatSupported(aParameters->value.pChar_value)) 99 { 100 aRet_kvp = NULL; 101 iFormat = (PVMFFormatType)aParameters->value.pChar_value; 102 //notify derived class of format update. 103 //This function may leave. 104 FormatUpdated(); 105 } 106 else 107 { 108 aRet_kvp = aParameters; 109 OSCL_LEAVE(OsclErrArgument); 110 } 111 } 112 113 //////////////////////////////////////////////////////////////////////////// 114 OSCL_EXPORT_REF PVMFStatus PvmiCapabilityAndConfigPortFormatImpl::verifyParametersSync(PvmiMIOSession aSession, PvmiKvp* aParameters, int num_elements) 115 { 116 OSCL_UNUSED_ARG(aSession); 117 118 if ((num_elements != 1) || 119 (pv_mime_strcmp(aParameters->key, iFormatValTypeString.get_str()) != 0)) 120 { 121 return PVMFErrNotSupported; 122 } 123 124 if (IsFormatSupported(aParameters->value.pChar_value)) 125 { 126 return PVMFSuccess; 127 } 128 return PVMFErrNotSupported; 129 } 130 131 132 OSCL_EXPORT_REF void pvmiSetPortFormatSync(PvmiCapabilityAndConfig *aPort, const char* aFormatValType, PVMFFormatType aFormat) 133 { 134 // Create PvmiKvp for capability settings 135 OsclMemAllocator alloc; 136 PvmiKvp kvp; 137 kvp.key = NULL; 138 kvp.length = oscl_strlen(aFormatValType) + 1; // +1 for \0 139 kvp.capacity = kvp.length; 140 kvp.key = (PvmiKeyType)alloc.ALLOCATE(kvp.length); 141 OsclError::LeaveIfNull(kvp.key); 142 oscl_strncpy(kvp.key, aFormatValType, kvp.length); 143 kvp.value.pChar_value = (char*)aFormat.getMIMEStrPtr(); 144 145 PvmiKvp* retKvp = NULL; // for return value 146 aPort->setParametersSync(NULL, &kvp, 1, retKvp); 147 148 alloc.deallocate(kvp.key); 149 } 150 151 OSCL_EXPORT_REF PVMFStatus AllocateKvp(OsclMemAllocator& aAlloc, PvmiKvp*& aKvp, PvmiKeyType aKey, int32 aNumParams) 152 { 153 uint8* buf = NULL; 154 uint32 keyLen = oscl_strlen(aKey) + 1; 155 int32 err = 0; 156 157 OSCL_TRY(err, 158 buf = (uint8*)aAlloc.ALLOCATE(aNumParams * (sizeof(PvmiKvp) + keyLen)); 159 if (!buf) 160 OSCL_LEAVE(OsclErrNoMemory); 161 ); 162 OSCL_FIRST_CATCH_ANY(err, 163 return PVMFErrNoMemory; 164 ); 165 166 int32 i = 0; 167 PvmiKvp* curKvp = aKvp = new(buf) PvmiKvp; 168 buf += sizeof(PvmiKvp); 169 for (i = 1; i < aNumParams; i++) 170 { 171 curKvp += i; 172 curKvp = new(buf) PvmiKvp; 173 buf += sizeof(PvmiKvp); 174 } 175 176 for (i = 0; i < aNumParams; i++) 177 { 178 aKvp[i].key = (char*)buf; 179 oscl_strncpy(aKvp[i].key, aKey, keyLen); 180 buf += keyLen; 181 } 182 183 return PVMFSuccess; 184 } 185 186