• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_omx_enc_port.h"
19 #include "pvmf_omx_enc_node.h"
20 
21 
PVMFOMXEncPort(int32 aTag,PVMFNodeInterface * aNode,const char * name)22 PVMFOMXEncPort::PVMFOMXEncPort(int32 aTag, PVMFNodeInterface* aNode, const char*name)
23         : PvmfPortBaseImpl(aTag, aNode, name)
24 {
25     iOMXNode = (PVMFOMXEncNode *) aNode;
26     Construct();
27 }
28 
29 ////////////////////////////////////////////////////////////////////////////
Construct()30 void PVMFOMXEncPort::Construct()
31 {
32     iLogger = PVLogger::GetLoggerObject("PVMFOMXEncPort");
33     oscl_memset(&iStats, 0, sizeof(PvmfPortBaseImplStats));
34     iNumFramesGenerated = 0;
35     iNumFramesConsumed = 0;
36     iTrackConfig = NULL;
37     iTrackConfigSize = 0;
38     iTimescale = 0;
39 
40 }
41 
42 
~PVMFOMXEncPort()43 PVMFOMXEncPort::~PVMFOMXEncPort()
44 {
45     if (iTrackConfig != NULL)
46     {
47         OSCL_FREE(iTrackConfig);
48         iTrackConfigSize = 0;
49     }
50 
51     Disconnect();
52     ClearMsgQueues();
53 }
54 
55 ////////////////////////////////////////////////////////////////////////////
IsFormatSupported(PVMFFormatType aFmt)56 bool PVMFOMXEncPort::IsFormatSupported(PVMFFormatType aFmt)
57 {
58     Oscl_Vector<PVMFFormatType, OsclMemAllocator>::iterator it;
59     for (it = iOMXNode->iCapability.iInputFormatCapability.begin();
60             it != iOMXNode->iCapability.iInputFormatCapability.end(); it++)
61     {
62         if (aFmt == *it)
63         {
64             return true;
65         }
66     }
67     for (it = iOMXNode->iCapability.iOutputFormatCapability.begin();
68             it != iOMXNode->iCapability.iOutputFormatCapability.end(); it++)
69     {
70         if (aFmt == *it)
71         {
72             return true;
73         }
74     }
75     // Not found in the input or output format capability lists
76     return false;
77 }
78 
79 ////////////////////////////////////////////////////////////////////////////
FormatUpdated()80 void PVMFOMXEncPort::FormatUpdated()
81 {
82     PVLOGGER_LOGMSG(PVLOGMSG_INST_MLDBG, iLogger, PVLOGMSG_INFO
83                     , (0, "PVMFOMXEncPort::FormatUpdated %s", iFormat.getMIMEStrPtr()));
84 }
85 
86 bool
pvmiSetPortFormatSpecificInfoSync(OsclRefCounterMemFrag & aMemFrag)87 PVMFOMXEncPort::pvmiSetPortFormatSpecificInfoSync(OsclRefCounterMemFrag& aMemFrag)
88 {
89     if ((iConnectedPort) &&
90             (iTag == PVMF_OMX_ENC_NODE_PORT_TYPE_OUTPUT))
91     {
92         OsclAny* temp = NULL;
93         iConnectedPort->QueryInterface(PVMI_CAPABILITY_AND_CONFIG_PVUUID, temp);
94         PvmiCapabilityAndConfig *config = (PvmiCapabilityAndConfig*) temp;
95 
96         /*
97          * Create PvmiKvp for capability settings
98          */
99         if ((config) && (aMemFrag.getMemFragSize() > 0))
100         {
101             OsclMemAllocator alloc;
102             PvmiKvp kvp;
103             kvp.key = NULL;
104             kvp.length = oscl_strlen(PVMF_FORMAT_SPECIFIC_INFO_KEY) + 1; // +1 for \0
105             kvp.key = (PvmiKeyType)alloc.ALLOCATE(kvp.length);
106             if (kvp.key == NULL)
107             {
108                 return false;
109             }
110             oscl_strncpy(kvp.key, PVMF_FORMAT_SPECIFIC_INFO_KEY, kvp.length);
111 
112             kvp.value.key_specific_value = (OsclAny*)(aMemFrag.getMemFragPtr());
113             kvp.capacity = aMemFrag.getMemFragSize();
114             kvp.length = aMemFrag.getMemFragSize();
115             PvmiKvp* retKvp = NULL; // for return value
116             int32 err;
117             OSCL_TRY(err, config->setParametersSync(NULL, &kvp, 1, retKvp););
118             /* ignore the error for now */
119             alloc.deallocate((OsclAny*)(kvp.key));
120         }
121         return true;
122     }
123     return false;
124 }
125 
Connect(PVMFPortInterface * aPort)126 PVMFStatus PVMFOMXEncPort::Connect(PVMFPortInterface* aPort)
127 {
128     if (!aPort)
129     {
130         return PVMFErrArgument;
131     }
132 
133     if (iConnectedPort)
134     {
135         return PVMFFailure;
136     }
137 
138     OsclAny* temp = NULL;
139     aPort->QueryInterface(PVMI_CAPABILITY_AND_CONFIG_PVUUID, temp);
140     PvmiCapabilityAndConfig* config = (PvmiCapabilityAndConfig*) temp;
141     if (!config)
142     {
143         PVLOGGER_LOGMSG(PVLOGMSG_INST_LLDBG, iLogger, PVLOGMSG_ERR, (0, "PVMFOMXEncPort::Connect: Error - Peer port does not support capability interface"));
144         return PVMFFailure;
145     }
146 
147     PVMFStatus status = PVMFSuccess;
148     switch (iTag)
149     {
150         case PVMF_OMX_ENC_NODE_PORT_TYPE_INPUT:
151             status = NegotiateInputSettings(config);
152             break;
153         case PVMF_OMX_ENC_NODE_PORT_TYPE_OUTPUT:
154             status = NegotiateOutputSettings(config);
155             break;
156         default:
157             PVLOGGER_LOGMSG(PVLOGMSG_INST_LLDBG, iLogger, PVLOGMSG_ERR, (0, "PVMFOMXEncPort::Connect: Error - Invalid port tag"));
158             status = PVMFFailure;
159     }
160 
161     if (status != PVMFSuccess)
162     {
163         PVLOGGER_LOGMSG(PVLOGMSG_INST_LLDBG, iLogger, PVLOGMSG_ERR, (0, "PVMFOMXEncPort::Connect: Error - Settings negotiation failed. status=%d", status));
164         return status;
165     }
166 
167 
168 
169     // Automatically connect the peer.
170 
171     if (aPort->PeerConnect(this) != PVMFSuccess)
172     {
173         return PVMFFailure;
174     }
175 
176     iConnectedPort = aPort;
177     PortActivity(PVMF_PORT_ACTIVITY_CONNECT);
178     return PVMFSuccess;
179 }
180 
181 // needed for WMV port exchange
setParametersSync(PvmiMIOSession aSession,PvmiKvp * aParameters,int num_elements,PvmiKvp * & aRet_kvp)182 void PVMFOMXEncPort::setParametersSync(PvmiMIOSession aSession,
183                                        PvmiKvp* aParameters,
184                                        int num_elements,
185                                        PvmiKvp * & aRet_kvp)
186 {
187 
188     OSCL_UNUSED_ARG(aSession);
189     PVMFStatus status = PVMFSuccess;
190     aRet_kvp = NULL;
191 
192     for (int32 i = 0; i < num_elements; i++)
193     {
194         status = VerifyAndSetParameter(&(aParameters[i]), true);
195         if (status != PVMFSuccess)
196         {
197             PVLOGGER_LOGMSG(PVLOGMSG_INST_LLDBG, iLogger, PVLOGMSG_ERR,
198                             (0, "PVMFOMXEncPort::setParametersSync: Error - VerifiyAndSetParameter failed on parameter #%d", i));
199             aRet_kvp = &(aParameters[i]);
200             OSCL_LEAVE(OsclErrArgument);
201         }
202     }
203 
204 
205 }
206 
207 
208 
209 
verifyParametersSync(PvmiMIOSession aSession,PvmiKvp * aParameters,int num_elements)210 PVMFStatus PVMFOMXEncPort::verifyParametersSync(PvmiMIOSession aSession, PvmiKvp* aParameters, int num_elements)
211 {
212 
213     OSCL_UNUSED_ARG(aSession);
214 
215     PVMFStatus status = PVMFSuccess;
216     for (int32 i = 0; (i < num_elements) && (status == PVMFSuccess); i++)
217         status = VerifyAndSetParameter(&(aParameters[i]));
218 
219     return status;
220 
221 
222 }
223 
verifyConnectedPortParametersSync(const char * aFormatValType,OsclAny * aConfig)224 PVMFStatus PVMFOMXEncPort::verifyConnectedPortParametersSync(const char* aFormatValType,
225         OsclAny* aConfig)
226 {
227     PVMFStatus status = PVMFErrNotSupported;
228     PvmiCapabilityAndConfig *capConfig;
229     if (iConnectedPort)
230     {
231         OsclAny* temp = NULL;
232         iConnectedPort->QueryInterface(PVMI_CAPABILITY_AND_CONFIG_PVUUID, temp);
233         capConfig = (PvmiCapabilityAndConfig*) temp;
234     }
235     else
236         return PVMFFailure;
237 
238     if (capConfig != NULL)
239     {
240         if (pv_mime_strcmp(aFormatValType, PVMF_FORMAT_SPECIFIC_INFO_KEY) == 0)
241         {
242             OsclRefCounterMemFrag* aFormatValue = (OsclRefCounterMemFrag*)aConfig;
243             if (aFormatValue->getMemFragSize() > 0)
244             {
245                 OsclMemAllocator alloc;
246                 PvmiKvp kvp;
247                 kvp.key = NULL;
248                 kvp.length = oscl_strlen(aFormatValType) + 1; // +1 for \0
249                 kvp.key = (PvmiKeyType)alloc.ALLOCATE(kvp.length);
250                 if (kvp.key == NULL)
251                 {
252                     return PVMFErrNoMemory;
253                 }
254                 oscl_strncpy(kvp.key, aFormatValType, kvp.length);
255 
256                 kvp.value.key_specific_value = (OsclAny*)(aFormatValue->getMemFragPtr());
257                 kvp.length = aFormatValue->getMemFragSize();
258                 kvp.capacity = aFormatValue->getMemFragSize();
259                 int32 err;
260                 OSCL_TRY(err, status = capConfig->verifyParametersSync(NULL, &kvp, 1););
261                 /* ignore the error for now */
262                 alloc.deallocate((OsclAny*)(kvp.key));
263 
264                 return status;
265             }
266         }
267         else if (pv_mime_strcmp(aFormatValType, PVMF_BITRATE_VALUE_KEY) == 0 ||
268                  pv_mime_strcmp(aFormatValType, PVMF_FRAMERATE_VALUE_KEY) == 0)
269         {
270             if (aConfig != NULL)
271             {
272                 OsclMemAllocator alloc;
273                 PvmiKvp kvp;
274                 kvp.key = NULL;
275                 kvp.length = oscl_strlen(aFormatValType) + 1; // +1 for \0
276                 kvp.key = (PvmiKeyType)alloc.ALLOCATE(kvp.length);
277                 if (kvp.key == NULL)
278                 {
279                     return PVMFErrNoMemory;
280                 }
281                 oscl_strncpy(kvp.key, aFormatValType, kvp.length);
282                 uint32* bitrate = (uint32*)aConfig;
283                 kvp.value.uint32_value = *bitrate;
284 
285                 int32 err;
286                 OSCL_TRY(err, status = capConfig->verifyParametersSync(NULL, &kvp, 1););
287                 /* ignore the error for now */
288                 alloc.deallocate((OsclAny*)(kvp.key));
289 
290                 return status;
291             }
292         }
293         return PVMFErrArgument;
294     }
295     return PVMFFailure;
296 }
297 
298 /////////////////////////////////////////////////////////////////////////////////////
299 /////////////////////////////////////////////////////////////////////////////////////
300 /////////////////// ENCODER SPECIFIC EXCHANGE TO SET PARAMETERS
301 ////////////////////////////////////////////////////////////////////////////
GetInputParametersSync(PvmiKeyType identifier,PvmiKvp * & parameters,int & num_parameter_elements)302 PVMFStatus PVMFOMXEncPort::GetInputParametersSync(PvmiKeyType identifier, PvmiKvp*& parameters,
303         int& num_parameter_elements)
304 {
305     if (iTag != PVMF_OMX_ENC_NODE_PORT_TYPE_INPUT)
306         return PVMFFailure;
307 
308     PVMFStatus status = PVMFSuccess;
309 
310     // this comparison only goes up to delimiter (i.e. ; or /)
311     if (pv_mime_strcmp(identifier, INPUT_FORMATS_CAP_QUERY) == 0)
312     {
313         // get the first parameter as well to compare
314         char *param1 = NULL;
315         char *param2 = NULL;
316         pv_mime_string_extract_param(0, identifier, param1);
317         pv_mime_string_extract_param(0, (char*)INPUT_FORMATS_CAP_QUERY, param2);
318 
319         if (pv_mime_strcmp(param1, param2) == 0)
320         {
321             num_parameter_elements = iOMXNode->iCapability.iInputFormatCapability.size();
322             status = AllocateKvp(parameters, (OMX_STRING)INPUT_FORMATS_VALTYPE, num_parameter_elements);
323             if (status != PVMFSuccess)
324             {
325                 PVLOGGER_LOGMSG(PVLOGMSG_INST_LLDBG, iLogger, PVLOGMSG_ERR, (0, "PVMFOMXEncPort::GetInputParametersSync: Error - AllocateKvp failed. status=%d", status));
326                 return status;
327             }
328 
329             uint32 ii = 0;
330             Oscl_Vector<PVMFFormatType, OsclMemAllocator>::iterator it;
331             for (it = iOMXNode->iCapability.iInputFormatCapability.begin();
332                     it != iOMXNode->iCapability.iInputFormatCapability.end(); it++)
333             {
334                 parameters[ii++].value.pChar_value = OSCL_STATIC_CAST(char*, it->getMIMEStrPtr());
335             }
336         }
337     }
338 
339     if (pv_mime_strcmp(identifier, INPUT_FORMATS_CUR_QUERY) == 0)
340     {
341         // get the first parameter as well to compare
342         char *param1 = NULL;
343         char *param2 = NULL;
344         pv_mime_string_extract_param(0, identifier, param1);
345         pv_mime_string_extract_param(0, (char*)INPUT_FORMATS_CUR_QUERY, param2);
346 
347         if (pv_mime_strcmp(param1, param2) == 0)
348         {
349             num_parameter_elements = 1;
350             status = AllocateKvp(parameters, (PvmiKeyType)INPUT_FORMATS_VALTYPE, num_parameter_elements);
351             if (status != PVMFSuccess)
352             {
353                 PVLOGGER_LOGMSG(PVLOGMSG_INST_LLDBG, iLogger, PVLOGMSG_ERR, (0, "PVMFOMXEncPort::GetInputParametersSync: Error - AllocateKvp failed. status=%d", status));
354                 return status;
355             }
356             parameters[0].value.pChar_value = (char*)iFormat.getMIMEStrPtr();
357         }
358     }
359     return status;
360 }
361 
362 ////////////////////////////////////////////////////////////////////////////
GetOutputParametersSync(PvmiKeyType identifier,PvmiKvp * & parameters,int & num_parameter_elements)363 PVMFStatus PVMFOMXEncPort::GetOutputParametersSync(PvmiKeyType identifier, PvmiKvp*& parameters,
364         int& num_parameter_elements)
365 {
366     if (iTag != PVMF_OMX_ENC_NODE_PORT_TYPE_OUTPUT)
367         return PVMFFailure;
368 
369     PVMFStatus status = PVMFSuccess;
370 
371     // this comparison only goes up to the first delimiter i.e. ; or /
372     if (pv_mime_strcmp(identifier, (OMX_STRING)OUTPUT_FORMATS_CAP_QUERY) == 0)
373     {
374         // get the first parameter as well to compare
375         char *param1 = NULL;
376         char *param2 = NULL;
377         pv_mime_string_extract_param(0, identifier, param1);
378         pv_mime_string_extract_param(0, (char*)OUTPUT_FORMATS_CAP_QUERY, param2);
379 
380         if (pv_mime_strcmp(param1, param2) == 0)
381         {
382             num_parameter_elements = iOMXNode->iCapability.iOutputFormatCapability.size();
383             status = AllocateKvp(parameters, (OMX_STRING)OUTPUT_FORMATS_VALTYPE, num_parameter_elements);
384             if (status != PVMFSuccess)
385             {
386                 PVLOGGER_LOGMSG(PVLOGMSG_INST_LLDBG, iLogger, PVLOGMSG_ERR, (0, "PVMFOMXEncPort::GetOutputParametersSync: Error - AllocateKvp failed. status=%d", status));
387                 return status;
388             }
389 
390             uint32 ii = 0;
391             Oscl_Vector<PVMFFormatType, OsclMemAllocator>::iterator it;
392             for (it = iOMXNode->iCapability.iOutputFormatCapability.begin();
393                     it != iOMXNode->iCapability.iOutputFormatCapability.end(); it++)
394             {
395                 parameters[ii++].value.pChar_value = OSCL_STATIC_CAST(char*, it->getMIMEStrPtr());
396             }
397         }
398     }
399 
400     if (pv_mime_strcmp(identifier, OUTPUT_FORMATS_CUR_QUERY) == 0)
401     {
402         // get the first parameter as well to compare
403         char *param1 = NULL;
404         char *param2 = NULL;
405         pv_mime_string_extract_param(0, identifier, param1);
406         pv_mime_string_extract_param(0, (char*)OUTPUT_FORMATS_CUR_QUERY, param2);
407 
408         if (pv_mime_strcmp(param1, param2) == 0)
409         {
410             num_parameter_elements = 1;
411             status = AllocateKvp(parameters, (OMX_STRING)OUTPUT_FORMATS_VALTYPE, num_parameter_elements);
412             if (status != PVMFSuccess)
413             {
414                 PVLOGGER_LOGMSG(PVLOGMSG_INST_LLDBG, iLogger, PVLOGMSG_ERR, (0, "PVMFOMXEncPort::GetOutputParametersSync: Error - AllocateKvp failed. status=%d", status));
415             }
416             else
417             {
418                 parameters[0].value.pChar_value = (char*)iOMXNode->GetCodecType().getMIMEStrPtr();
419             }
420         }
421     }
422     else if (pv_mime_strcmp(identifier, VIDEO_OUTPUT_WIDTH_CUR_QUERY) == 0)
423     {
424         num_parameter_elements = 1;
425         status = AllocateKvp(parameters, (OMX_STRING)VIDEO_OUTPUT_WIDTH_CUR_VALUE, num_parameter_elements);
426         if (status != PVMFSuccess)
427         {
428             PVLOGGER_LOGMSG(PVLOGMSG_INST_LLDBG, iLogger, PVLOGMSG_ERR, (0, "PVMFOMXEncPort::GetOutputParametersSync: Error - AllocateKvp failed. status=%d", status));
429             return status;
430         }
431 
432         uint32 width, height;
433         status = iOMXNode->GetOutputFrameSize(0, width, height);
434         if (status != PVMFSuccess)
435         {
436             PVLOGGER_LOGMSG(PVLOGMSG_INST_LLDBG, iLogger, PVLOGMSG_ERR, (0, "PVMFOMXEncPort::GetOutputParametersSync: Error -iOMXNode->GetOutputFrameSize failed. status=%d", status));
437         }
438         else
439         {
440             parameters[0].value.uint32_value = width;
441         }
442     }
443     else if (pv_mime_strcmp(identifier, VIDEO_OUTPUT_HEIGHT_CUR_QUERY) == 0)
444     {
445         num_parameter_elements = 1;
446         status = AllocateKvp(parameters, (OMX_STRING)VIDEO_OUTPUT_HEIGHT_CUR_VALUE, num_parameter_elements);
447         if (status != PVMFSuccess)
448         {
449             PVLOGGER_LOGMSG(PVLOGMSG_INST_LLDBG, iLogger, PVLOGMSG_ERR, (0, "PVMFOMXEncPort::GetOutputParametersSync: Error - AllocateKvp failed. status=%d", status));
450             return status;
451         }
452         else
453         {
454             uint32 width, height;
455             status = iOMXNode->GetOutputFrameSize(0, width, height);
456             if (status != PVMFSuccess)
457             {
458                 PVLOGGER_LOGMSG(PVLOGMSG_INST_LLDBG, iLogger, PVLOGMSG_ERR, (0, "PVMFOMXEncPort::GetOutputParametersSync: Error - iOMXNode->GetOutputFrameSize failed. status=%d", status));
459             }
460             else
461             {
462                 parameters[0].value.uint32_value = height;
463             }
464         }
465     }
466     else if (pv_mime_strcmp(identifier, VIDEO_OUTPUT_FRAME_RATE_CUR_QUERY) == 0)
467     {
468         num_parameter_elements = 1;
469         status = AllocateKvp(parameters, (OMX_STRING)VIDEO_OUTPUT_FRAME_RATE_CUR_VALUE, num_parameter_elements);
470         if (status != PVMFSuccess)
471         {
472             PVLOGGER_LOGMSG(PVLOGMSG_INST_LLDBG, iLogger, PVLOGMSG_ERR, (0, "PVMFOMXEncPort::GetOutputParametersSync: Error - AllocateKvp failed. status=%d", status));
473             return status;
474         }
475         else
476         {
477             parameters[0].value.float_value = iOMXNode->GetOutputFrameRate(0);
478         }
479     }
480     else if (pv_mime_strcmp(identifier, OUTPUT_BITRATE_CUR_QUERY) == 0)
481     {
482         num_parameter_elements = 1;
483         status = AllocateKvp(parameters, (OMX_STRING)OUTPUT_BITRATE_CUR_VALUE, num_parameter_elements);
484         if (status != PVMFSuccess)
485         {
486             PVLOGGER_LOGMSG(PVLOGMSG_INST_LLDBG, iLogger, PVLOGMSG_ERR, (0, "PVMFOMXEncPort::GetOutputParametersSync: Error - AllocateKvp failed. status=%d", status));
487             return status;
488         }
489         else
490         {
491 
492             // NOTE: we assume that port format will be set before this call
493             if ((iFormat == PVMF_MIME_AMR_IETF) || (iFormat == PVMF_MIME_AMRWB_IETF) || (iFormat == PVMF_MIME_AMR_IF2) ||
494                     (iFormat == PVMF_MIME_ADTS) || (iFormat == PVMF_MIME_ADIF) || (iFormat == PVMF_MIME_MPEG4_AUDIO))
495             {
496                 parameters[0].value.uint32_value = iOMXNode->GetOutputBitRate(); // use audio version - void arg
497             }
498             else if (iFormat == PVMF_MIME_H2631998 ||
499                      iFormat == PVMF_MIME_H2632000 ||
500                      iFormat == PVMF_MIME_M4V ||
501                      iFormat == PVMF_MIME_H264_VIDEO_RAW ||
502                      iFormat == PVMF_MIME_H264_VIDEO_MP4
503                     )
504 
505             {
506                 // use the video version
507                 parameters[0].value.uint32_value = iOMXNode->GetOutputBitRate(0);
508             }
509             else
510             {
511                 status = PVMFFailure;
512                 PVLOGGER_LOGMSG(PVLOGMSG_INST_LLDBG, iLogger, PVLOGMSG_ERR, (0, "PVMFOMXEncPort::GetOutputParametersSync: Error - status=%d", status));
513                 return status;
514             }
515 
516         }
517     }
518     else if (pv_mime_strcmp(identifier, VIDEO_OUTPUT_IFRAME_INTERVAL_CUR_QUERY) == 0)
519     {
520         num_parameter_elements = 1;
521         status = AllocateKvp(parameters, (OMX_STRING)VIDEO_OUTPUT_IFRAME_INTERVAL_CUR_VALUE, num_parameter_elements);
522         if (status != PVMFSuccess)
523         {
524             PVLOGGER_LOGMSG(PVLOGMSG_INST_LLDBG, iLogger, PVLOGMSG_ERR, (0, "PVMFOMXEncPort::GetOutputParametersSync: Error - AllocateKvp failed. status=%d", status));
525             return status;
526         }
527         else
528         {
529             parameters[0].value.uint32_value = iOMXNode->GetIFrameInterval();
530         }
531     }
532     else if (pv_mime_strcmp(identifier, AUDIO_OUTPUT_SAMPLING_RATE_CUR_QUERY) == 0)
533     {
534         num_parameter_elements = 1;
535         status = AllocateKvp(parameters, (PvmiKeyType)AUDIO_OUTPUT_SAMPLING_RATE_CUR_VALUE, num_parameter_elements);
536         if (status != PVMFSuccess)
537         {
538             PVLOGGER_LOGMSG(PVLOGMSG_INST_LLDBG, iLogger, PVLOGMSG_ERR, (0, "PVMFOMXEncPort::GetOutputParametersSync: Error - AllocateKvp failed. status=%d", status));
539             return status;
540         }
541 
542         parameters[0].value.uint32_value = (uint32) iOMXNode->GetOutputSamplingRate();
543 
544     }
545     else if (pv_mime_strcmp(identifier, AUDIO_OUTPUT_NUM_CHANNELS_CUR_QUERY) == 0)
546     {
547         num_parameter_elements = 1;
548         status = AllocateKvp(parameters, (PvmiKeyType)AUDIO_OUTPUT_NUM_CHANNELS_CUR_VALUE, num_parameter_elements);
549         if (status != PVMFSuccess)
550         {
551             PVLOGGER_LOGMSG(PVLOGMSG_INST_LLDBG, iLogger, PVLOGMSG_ERR, (0, "PVMFOMXEncPort::GetOutputParametersSync: Error - AllocateKvp failed. status=%d", status));
552             return status;
553         }
554 
555         parameters[0].value.uint32_value = (uint32) iOMXNode->GetOutputNumChannels();
556     }
557     else if (pv_mime_strcmp(identifier, AUDIO_OUTPUT_BITS_PER_SAMPLE_CUR_QUERY) == 0)
558     {
559         num_parameter_elements = 1;
560         status = AllocateKvp(parameters, (PvmiKeyType)AUDIO_OUTPUT_BITS_PER_SAMPLE_CUR_VALUE, num_parameter_elements);
561         if (status != PVMFSuccess)
562         {
563             PVLOGGER_LOGMSG(PVLOGMSG_INST_LLDBG, iLogger, PVLOGMSG_ERR, (0, "PVMFOMXEncPort::GetOutputParametersSync: Error - AllocateKvp failed. status=%d", status));
564             return status;
565         }
566 
567         parameters[0].value.uint32_value = (uint32) iOMXNode->iAudioInputFormat.iInputBitsPerSample;
568     }
569     else if ((pv_mime_strcmp(identifier, OUTPUT_TIMESCALE_CUR_QUERY) == 0) &&
570              ((iFormat == PVMF_MIME_AMR_IETF) ||
571               (iFormat == PVMF_MIME_AMRWB_IETF) ||
572               (iFormat == PVMF_MIME_AMR_IF2) ||
573               (iFormat == PVMF_MIME_ADTS) ||
574               (iFormat == PVMF_MIME_ADIF) ||
575               (iFormat == PVMF_MIME_MPEG4_AUDIO)
576              ))
577     {
578         num_parameter_elements = 1;
579         status = AllocateKvp(parameters, (PvmiKeyType)OUTPUT_TIMESCALE_CUR_VALUE, num_parameter_elements);
580         if (status != PVMFSuccess)
581         {
582             PVLOGGER_LOGMSG(PVLOGMSG_INST_LLDBG, iLogger, PVLOGMSG_ERR, (0, "PVMFOMXEncPort::GetOutputParametersSync: Error - AllocateKvp failed. status=%d", status));
583             return status;
584         }
585         else
586         {
587 
588             parameters[0].value.uint32_value = (uint32) iOMXNode->GetOutputSamplingRate();
589 
590         }
591     }
592     else if (pv_mime_strcmp(identifier, PVMF_FORMAT_SPECIFIC_INFO_KEY) == 0)
593     {
594         num_parameter_elements = 1;
595         status = AllocateKvp(parameters, (PvmiKeyType)PVMF_FORMAT_SPECIFIC_INFO_KEY, num_parameter_elements);
596         if (status != PVMFSuccess)
597         {
598             PVLOGGER_LOGMSG(PVLOGMSG_INST_LLDBG, iLogger, PVLOGMSG_ERR, (0, "PVMFOMXEncPort::GetOutputParametersSync: Error - AllocateKvp failed. status=%d", status));
599             return status;
600         }
601         else
602         {
603             OsclRefCounterMemFrag refMemFrag;
604             if (iOMXNode->GetVolHeader(refMemFrag))
605             {
606                 parameters[0].value.key_specific_value = refMemFrag.getMemFragPtr();
607                 parameters[0].capacity = refMemFrag.getMemFragSize();
608                 parameters[0].length = refMemFrag.getMemFragSize();
609             }
610             else
611             {
612                 return PVMFFailure;
613             }
614         }
615     }
616 
617     return status;
618 }
619 
620 ////////////////////////////////////////////////////////////////////////////
AllocateKvp(PvmiKvp * & aKvp,PvmiKeyType aKey,int32 aNumParams)621 PVMFStatus PVMFOMXEncPort::AllocateKvp(PvmiKvp*& aKvp, PvmiKeyType aKey, int32 aNumParams)
622 {
623     PVLOGGER_LOGMSG(PVLOGMSG_INST_LLDBG, iLogger, PVLOGMSG_STACK_TRACE, (0, "PVMFOMXEncPort::AllocateKvp"));
624     uint8* buf = NULL;
625     uint32 keyLen = oscl_strlen(aKey) + 1;
626     int32 err = 0;
627 
628     OSCL_TRY(err,
629              buf = (uint8*)iAlloc.allocate(aNumParams * (sizeof(PvmiKvp) + keyLen));
630              if (!buf)
631              OSCL_LEAVE(OsclErrNoMemory);
632             );
633     OSCL_FIRST_CATCH_ANY(err,
634                          PVLOGGER_LOGMSG(PVLOGMSG_INST_LLDBG, iLogger, PVLOGMSG_ERR, (0, "PVMFOMXEncPort::AllocateKvp: Error - kvp allocation failed"));
635                          return PVMFErrNoMemory;
636                         );
637 
638     int32 i = 0;
639     PvmiKvp* curKvp = aKvp = new(buf) PvmiKvp;
640     buf += sizeof(PvmiKvp);
641     for (i = 1; i < aNumParams; i++)
642     {
643         curKvp += i;
644         curKvp = new(buf) PvmiKvp;
645         buf += sizeof(PvmiKvp);
646     }
647 
648     for (i = 0; i < aNumParams; i++)
649     {
650         aKvp[i].key = (char*)buf;
651         oscl_strncpy(aKvp[i].key, aKey, keyLen);
652         buf += keyLen;
653     }
654 
655     return PVMFSuccess;
656 }
657 
658 ////////////////////////////////////////////////////////////////////////////
VerifyAndSetParameter(PvmiKvp * aKvp,bool aSetParam)659 PVMFStatus PVMFOMXEncPort::VerifyAndSetParameter(PvmiKvp* aKvp, bool aSetParam)
660 {
661     PVLOGGER_LOGMSG(PVLOGMSG_INST_LLDBG, iLogger, PVLOGMSG_STACK_TRACE, (0, "PVMFOMXEncPort::VerifyAndSetParameter: aKvp=0x%x, aSetParam=%d", aKvp, aSetParam));
662 
663     if (!aKvp)
664     {
665         PVLOGGER_LOGMSG(PVLOGMSG_INST_LLDBG, iLogger, PVLOGMSG_ERR, (0, "PVMFOMXEncPort::VerifyAndSetParameter: Error - Invalid key-value pair"));
666         return PVMFFailure;
667     }
668 
669     if (pv_mime_strcmp(aKvp->key, INPUT_FORMATS_VALTYPE) == 0 &&
670             iTag == PVMF_OMX_ENC_NODE_PORT_TYPE_INPUT)
671     {
672         Oscl_Vector<PVMFFormatType, OsclMemAllocator>::iterator it;
673         for (it = iOMXNode->iCapability.iInputFormatCapability.begin();
674                 it != iOMXNode->iCapability.iInputFormatCapability.end(); it++)
675         {
676             if (pv_mime_strcmp(aKvp->value.pChar_value, it->getMIMEStrPtr()) == 0)
677             {
678                 if (aSetParam)
679                 {
680                     iFormat = aKvp->value.pChar_value;
681                     if (iOMXNode->SetInputFormat(iFormat) != PVMFSuccess)
682                         return PVMFFailure;
683                 }
684                 return PVMFSuccess;
685             }
686         }
687         PVLOGGER_LOGMSG(PVLOGMSG_INST_LLDBG, iLogger, PVLOGMSG_ERR, (0, "PVMFOMXEncPort::VerifyAndSetParameter: Error - Input format %s not supported",
688                         aKvp->value.pChar_value));
689         return PVMFFailure;
690     }
691     else if (pv_mime_strcmp(aKvp->key, OUTPUT_FORMATS_VALTYPE) == 0 &&
692              iTag == PVMF_OMX_ENC_NODE_PORT_TYPE_OUTPUT)
693     {
694 
695         Oscl_Vector<PVMFFormatType, OsclMemAllocator>::iterator it;
696         for (it = iOMXNode->iCapability.iInputFormatCapability.begin();
697                 it != iOMXNode->iCapability.iInputFormatCapability.end(); it++)
698         {
699             if (pv_mime_strcmp(aKvp->value.pChar_value, it->getMIMEStrPtr()) == 0)
700             {
701                 if (aSetParam)
702                 {
703                     iFormat = aKvp->value.pChar_value;
704                     if (iOMXNode->SetCodecType(iFormat) != PVMFSuccess)
705                         return PVMFFailure;
706                 }
707             }
708             return PVMFSuccess;
709         }
710         PVLOGGER_LOGMSG(PVLOGMSG_INST_LLDBG, iLogger, PVLOGMSG_ERR, (0, "PVMFOMXEncPort::VerifyAndSetParameter: Error - Output format %s not supported",
711                         aKvp->value.pChar_value));
712         return PVMFFailure;
713     }
714 
715     PVLOGGER_LOGMSG(PVLOGMSG_INST_LLDBG, iLogger, PVLOGMSG_ERR, (0, "PVMFOMXEncPort::VerifyAndSetParameter: Error - Unsupported parameter"));
716     return PVMFFailure;
717 }
718 
719 
720 ////////////////////////////////////////////////////////////////////////////
NegotiateInputSettings(PvmiCapabilityAndConfig * aConfig)721 PVMFStatus PVMFOMXEncPort::NegotiateInputSettings(PvmiCapabilityAndConfig* aConfig)
722 {
723     PVLOGGER_LOGMSG(PVLOGMSG_INST_LLDBG, iLogger, PVLOGMSG_STACK_TRACE, (0, "PVMFOMXEncPort::NegotiateInputSettings: aConfig=0x%x", aConfig));
724     if (!aConfig)
725     {
726         PVLOGGER_LOGMSG(PVLOGMSG_INST_LLDBG, iLogger, PVLOGMSG_ERR, (0, "PVMFOMXEncPort::NegotiateInputSettings: Error - Invalid config object"));
727         return PVMFFailure;
728     }
729 
730     PvmiKvp* kvp = NULL;
731     int numParams = 0;
732     int32 err = 0;
733     PVMFFormatType videoFormat = 0;
734     // Get supported output formats from peer
735     PVMFStatus status = aConfig->getParametersSync(NULL, (OMX_STRING)OUTPUT_FORMATS_CAP_QUERY, kvp, numParams, NULL);
736     if (status != PVMFSuccess || numParams == 0)
737     {
738         PVLOGGER_LOGMSG(PVLOGMSG_INST_LLDBG, iLogger, PVLOGMSG_ERR, (0, "PVMFOMXEncPort::NegotiateInputSettings: Error - config->getParametersSync(output_formats) failed"));
739         return status;
740     }
741 
742     OsclPriorityQueue < PvmiKvp*, OsclMemAllocator,
743     Oscl_Vector<PvmiKvp*, OsclMemAllocator>,
744     PVMFOMXEncInputFormatCompareLess > sortedKvp;
745 
746     // Using a priority queue, sort the kvp's returned from aConfig->getParametersSync
747     // according to the preference of this port. Formats that are not supported are
748     // not pushed to the priority queue and hence dropped from consideration.
749     PvmiKvp* selectedAudioKvp = NULL;
750     for (int32 i = 0; i < numParams; i++)
751     {
752         Oscl_Vector<PVMFFormatType, OsclMemAllocator>::iterator it;
753         for (it = iOMXNode->iCapability.iInputFormatCapability.begin(); it != iOMXNode->iCapability.iInputFormatCapability.end(); it++)
754         {
755             // Is the format on the input list?
756             if (pv_mime_strcmp(kvp->value.pChar_value, it->getMIMEStrPtr()) == 0)
757             {
758                 // Found.  Is it audio or video?
759                 if (it->isAudio())
760                 {
761                     // WARNING there should be only one entry for audio!
762                     selectedAudioKvp = &kvp[i];
763                 }
764                 else // Must be video
765                 {
766                     videoFormat = kvp[i].value.pChar_value;
767                     err = PushKVP(sortedKvp, &(kvp[i]));
768                     OSCL_FIRST_CATCH_ANY(err,
769                                          PVLOGGER_LOGMSG(PVLOGMSG_INST_LLDBG, iLogger, PVLOGMSG_ERR, (0, "PVMFOMXEncPort::NegotiateInputSettings: Error - sortedKvp.push failed"));
770                                          return PVMFErrNoMemory;
771                                         );
772                 }
773             }
774         }
775     }
776 
777     if (sortedKvp.size() == 0 && (selectedAudioKvp == NULL))
778     {
779         PVLOGGER_LOGMSG(PVLOGMSG_INST_LLDBG, iLogger, PVLOGMSG_ERR, (0, "PVMFOMXEncPort::NegotiateInputSettings: Error - No matching supported input format"));
780         // Release parameters back to peer
781         aConfig->releaseParameters(NULL, kvp, numParams);
782         kvp = NULL;
783         numParams = 0;
784         return PVMFFailure;
785     }
786 
787     PvmiKvp* selectedKvp = NULL;
788     if (sortedKvp.size() != 0)
789     {
790         selectedKvp = sortedKvp.top();
791     }
792     else
793     {
794         selectedKvp = selectedAudioKvp;
795     }
796     PvmiKvp* retKvp = NULL;
797 
798     // Set format of this port, peer port and container node
799     iFormat = selectedKvp->value.pChar_value;
800     if (iOMXNode->SetInputFormat(iFormat) != PVMFSuccess)
801         return PVMFFailure;
802 
803     err = Config_ParametersSync(aConfig, selectedKvp, retKvp);
804     OSCL_FIRST_CATCH_ANY(err,
805                          PVLOGGER_LOGMSG(PVLOGMSG_INST_LLDBG, iLogger, PVLOGMSG_ERR, (0, "PVMFOMXEncPort::NegotiateInputSettings: Error - aConfig->setParametersSync failed. err=%d", err));
806                          return PVMFFailure;
807                         );
808 
809     // Release parameters back to peer and reset for the next query
810     aConfig->releaseParameters(NULL, kvp, numParams);
811     kvp = NULL;
812     numParams = 0;
813 
814     // audio/video negotiation differ
815     if (iFormat == PVMF_MIME_PCM16)
816     {
817         // audio i.e. AMR for now
818 
819         // first set bitspersample to 16
820         status = iOMXNode->SetInputBitsPerSample(PVMF_AMRENC_DEFAULT_BITSPERSAMPLE);
821         if (status != PVMFSuccess)
822             return status;
823 
824 
825         status = aConfig->getParametersSync(NULL, (PvmiKeyType)AUDIO_OUTPUT_SAMPLING_RATE_CUR_QUERY, kvp, numParams, NULL);
826         uint32 samplingRate = 0;
827         if (status != PVMFSuccess || !kvp || numParams != 1)
828         {
829             PVLOGGER_LOGMSG(PVLOGMSG_INST_LLDBG, iLogger, PVLOGMSG_ERR, (0, "PVMFOMXEncPort::NegotiateInputSettings: config->getParametersSync(sampling rate) not supported. Use default."));
830             samplingRate = PVMF_AMRENC_DEFAULT_SAMPLING_RATE;
831         }
832         else
833         {
834             samplingRate = kvp[0].value.uint32_value;
835 
836             aConfig->releaseParameters(NULL, kvp, numParams);
837         }
838 
839 
840         // Forward settings to encoder
841         status = iOMXNode->SetInputSamplingRate(samplingRate);
842         if (status != PVMFSuccess)
843             return status;
844 
845         kvp = NULL;
846         numParams = 0;
847 
848         status = aConfig->getParametersSync(NULL, (PvmiKeyType)AUDIO_OUTPUT_NUM_CHANNELS_CUR_QUERY, kvp, numParams, NULL);
849         uint32 numChannels = 0;
850         if (status != PVMFSuccess || !kvp || numParams != 1)
851         {
852             PVLOGGER_LOGMSG(PVLOGMSG_INST_LLDBG, iLogger, PVLOGMSG_ERR, (0, "PVMFOMXEncPort::NegotiateInputSettings: config->getParametersSync(num channels) not supported. Use default"));
853             numChannels = PVMF_AMRENC_DEFAULT_NUM_CHANNELS;
854         }
855         else
856         {
857             numChannels = kvp[0].value.uint32_value;
858 
859             aConfig->releaseParameters(NULL, kvp, numParams);
860         }
861 
862         // Forward settings to encoder
863         status = iOMXNode->SetInputNumChannels(numChannels);
864         if (status != PVMFSuccess)
865             return status;
866 
867         kvp = NULL;
868         numParams = 0;
869 
870         // do the "TIMESCALE" query
871         status = aConfig->getParametersSync(NULL, (PvmiKeyType)OUTPUT_TIMESCALE_CUR_QUERY, kvp, numParams, NULL);
872         iTimescale = 0;
873         if (status != PVMFSuccess || !kvp || numParams != 1)
874         {
875             PVLOGGER_LOGMSG(PVLOGMSG_INST_LLDBG, iLogger, PVLOGMSG_ERR, (0, "PVMFOMXEncPort::NegotiateInputSettings: config->getParametersSync(sampling rate) not supported. Use default."));
876             iTimescale = PVMF_AMRENC_DEFAULT_SAMPLING_RATE;
877         }
878         else
879         {
880             iTimescale = kvp[0].value.uint32_value;
881 
882             aConfig->releaseParameters(NULL, kvp, numParams);
883         }
884 
885         kvp = NULL;
886         numParams = 0;
887 
888         return PVMFSuccess;
889 
890     }
891     else
892     {
893         // video
894         // Get size (in pixels) of video data from peer
895         uint32 width = 0;
896         uint32 height = 0;
897         uint8 orientation = 0;
898         status = aConfig->getParametersSync(NULL, (OMX_STRING)VIDEO_OUTPUT_WIDTH_CUR_QUERY, kvp, numParams, NULL);
899         if (status != PVMFSuccess || numParams != 1)
900         {
901             PVLOGGER_LOGMSG(PVLOGMSG_INST_LLDBG, iLogger, PVLOGMSG_ERR, (0, "PVMFOMXEncPort::Connect: Error - config->getParametersSync(current width) failed"));
902             return status;
903         }
904         width = kvp[0].value.uint32_value;
905         aConfig->releaseParameters(NULL, kvp, numParams);
906         kvp = NULL;
907         numParams = 0;
908 
909         status = aConfig->getParametersSync(NULL, (OMX_STRING)VIDEO_OUTPUT_HEIGHT_CUR_QUERY, kvp, numParams, NULL);
910         if (status != PVMFSuccess || numParams != 1)
911         {
912             PVLOGGER_LOGMSG(PVLOGMSG_INST_LLDBG, iLogger, PVLOGMSG_ERR, (0, "PVMFOMXEncPort::Connect: Error - config->getParametersSync(current height) failed"));
913             return status;
914         }
915         height = kvp[0].value.uint32_value;
916         aConfig->releaseParameters(NULL, kvp, numParams);
917         kvp = NULL;
918         numParams = 0;
919 
920         if ((videoFormat == PVMF_MIME_RGB12) || (videoFormat == PVMF_MIME_RGB24))
921         {
922             status = aConfig->getParametersSync(NULL, (OMX_STRING)VIDEO_FRAME_ORIENTATION_CUR_QUERY, kvp, numParams, NULL);
923             if (status != PVMFSuccess || numParams != 1)
924             {
925                 PVLOGGER_LOGMSG(PVLOGMSG_INST_LLDBG, iLogger, PVLOGMSG_ERR, (0, "PVMFOMXEncPort::Connect: Error - config->getParametersSync(current height) failed"));
926                 return status;
927             }
928 
929             orientation = kvp[0].value.uint8_value;
930             aConfig->releaseParameters(NULL, kvp, numParams);
931             kvp = NULL;
932             numParams = 0;
933 
934         }
935         // Set input frame size of container node
936         status = iOMXNode->SetInputFrameSize(width, height, orientation);
937         if (status != PVMFSuccess)
938             return status;
939 
940 
941         // Get video frame rate from peer
942         status = aConfig->getParametersSync(NULL, (OMX_STRING)VIDEO_OUTPUT_FRAME_RATE_CUR_QUERY, kvp, numParams, NULL);
943         if (status != PVMFSuccess || numParams != 1)
944         {
945             PVLOGGER_LOGMSG(PVLOGMSG_INST_LLDBG, iLogger, PVLOGMSG_ERR, (0, "PVMFOMXEncPort::Connect: Error - config->getParametersSync(current frame rate) failed"));
946             return status;
947         }
948 
949         // Set input frame rate of container node
950         status = iOMXNode->SetInputFrameRate(kvp[0].value.float_value);
951         aConfig->releaseParameters(NULL, kvp, numParams);
952         kvp = NULL;
953         numParams = 0;
954         return status;
955     }
956 }
957 
958 ////////////////////////////////////////////////////////////////////////////
NegotiateOutputSettings(PvmiCapabilityAndConfig * aConfig)959 PVMFStatus PVMFOMXEncPort::NegotiateOutputSettings(PvmiCapabilityAndConfig* aConfig)
960 {
961     PVLOGGER_LOGMSG(PVLOGMSG_INST_LLDBG, iLogger, PVLOGMSG_STACK_TRACE, (0, "PVMFOMXEncPort::NegotiateOutputSettings: aConfig=0x%x", aConfig));
962     if (!aConfig)
963     {
964         PVLOGGER_LOGMSG(PVLOGMSG_INST_LLDBG, iLogger, PVLOGMSG_ERR, (0, "PVMFOMXEncPort::NegotiateOutputSettings: Error - Invalid config object"));
965         return PVMFFailure;
966     }
967 
968     PvmiKvp* kvp = NULL;
969     int numParams = 0;
970     int32 i = 0;
971     int32 err = 0;
972 
973     // Get supported input formats from peer
974     PVMFStatus status = aConfig->getParametersSync(NULL, (OMX_STRING)INPUT_FORMATS_CAP_QUERY, kvp, numParams, NULL);
975     if (status != PVMFSuccess || numParams == 0)
976     {
977         PVLOGGER_LOGMSG(PVLOGMSG_INST_LLDBG, iLogger, PVLOGMSG_ERR, (0, "PVMFOMXEncPort::NegotiateOutputSettings: Error - config->getParametersSync(input_formats) failed"));
978         return status;
979     }
980 
981     PvmiKvp* selectedKvp = NULL;
982     PvmiKvp* retKvp = NULL;
983     for (i = 0; i < numParams && !selectedKvp; i++)
984     {
985         if (pv_mime_strcmp(kvp[i].value.pChar_value, (char*)iFormat.getMIMEStrPtr()) == 0)
986             selectedKvp = &(kvp[i]);
987     }
988 
989     if (!selectedKvp)
990     {
991         PVLOGGER_LOGMSG(PVLOGMSG_INST_LLDBG, iLogger, PVLOGMSG_ERR, (0, "PVMFOMXEncPort::NegotiateOutputSettings: Error - Output format not supported by peer"));
992         return PVMFFailure;
993     }
994 
995     err = Config_ParametersSync(aConfig, selectedKvp, retKvp);
996     OSCL_FIRST_CATCH_ANY(err,
997                          PVLOGGER_LOGMSG(PVLOGMSG_INST_LLDBG, iLogger, PVLOGMSG_ERR, (0, "PVMFOMXEncPort::NegotiateOutputSettings: Error - aConfig->setParametersSync failed. err=%d", err));
998                          return PVMFFailure;
999                         );
1000 
1001     aConfig->releaseParameters(NULL, kvp, numParams);
1002     kvp = NULL;
1003     numParams = 0;
1004 
1005     return PVMFSuccess;
1006 }
1007 ////////////////////////////////////////////////////////////////////////////
getParametersSync(PvmiMIOSession session,PvmiKeyType identifier,PvmiKvp * & parameters,int & num_parameter_elements,PvmiCapabilityContext context)1008 OSCL_EXPORT_REF PVMFStatus PVMFOMXEncPort::getParametersSync(PvmiMIOSession session,
1009         PvmiKeyType identifier,
1010         PvmiKvp*& parameters,
1011         int& num_parameter_elements,
1012         PvmiCapabilityContext context)
1013 {
1014     PVLOGGER_LOGMSG(PVLOGMSG_INST_LLDBG, iLogger, PVLOGMSG_STACK_TRACE, (0, "PVMFOMXEncPort::getParametersSync"));
1015     OSCL_UNUSED_ARG(session);
1016     OSCL_UNUSED_ARG(context);
1017 
1018     parameters = NULL;
1019     num_parameter_elements = 0;
1020     PVMFStatus status = PVMFFailure;
1021 
1022     switch (iTag)
1023     {
1024         case PVMF_OMX_ENC_NODE_PORT_TYPE_INPUT:
1025             return GetInputParametersSync(identifier, parameters, num_parameter_elements);
1026         case PVMF_OMX_ENC_NODE_PORT_TYPE_OUTPUT:
1027             return GetOutputParametersSync(identifier, parameters, num_parameter_elements);
1028         default:
1029             PVLOGGER_LOGMSG(PVLOGMSG_INST_LLDBG, iLogger, PVLOGMSG_ERR, (0, "PVMFOMXEncPort::getParametersSync: Error - Invalid port tag"));
1030             break;
1031     }
1032 
1033     return status;
1034 }
1035 ////////////////////////////////////////////////////////////////////////////
releaseParameters(PvmiMIOSession session,PvmiKvp * parameters,int num_elements)1036 OSCL_EXPORT_REF PVMFStatus PVMFOMXEncPort::releaseParameters(PvmiMIOSession session,
1037         PvmiKvp* parameters,
1038         int num_elements)
1039 {
1040     OSCL_UNUSED_ARG(session);
1041     OSCL_UNUSED_ARG(num_elements);
1042 
1043     if (parameters)
1044     {
1045         iAlloc.deallocate((OsclAny*)parameters);
1046         return PVMFSuccess;
1047     }
1048     else
1049     {
1050         return PVMFFailure;
1051     }
1052 }
1053 
1054 
1055 // AVC Encoder specific call to send set of SPS and PPS nals to the composer
SendSPS_PPS(OsclMemoryFragment * aSPSs,int aNumSPSs,OsclMemoryFragment * aPPSs,int aNumPPSs)1056 void PVMFOMXEncPort::SendSPS_PPS(OsclMemoryFragment *aSPSs, int aNumSPSs, OsclMemoryFragment *aPPSs, int aNumPPSs)
1057 {
1058     int ii;
1059 
1060     OsclAny* temp = NULL;
1061     iConnectedPort->QueryInterface(PVMI_CAPABILITY_AND_CONFIG_PVUUID, temp);
1062     PvmiCapabilityAndConfig* config = (PvmiCapabilityAndConfig*) temp;
1063     if (config)
1064     {
1065         for (ii = 0; ii < aNumSPSs; ii++)
1066         {
1067             // send SPS
1068             PvmiKvp* sps, *ret;
1069             AllocateKvp(sps, (OMX_STRING)VIDEO_AVC_OUTPUT_SPS_CUR_VALUE, 1);
1070 
1071             sps->value.key_specific_value = aSPSs[ii].ptr;
1072             sps->capacity = aSPSs[ii].len;
1073             sps->length = aSPSs[ii].len;
1074             config->setParametersSync(NULL, sps, 1, ret);
1075             if (ret)
1076             {
1077                 PVLOGGER_LOGMSG(PVLOGMSG_INST_LLDBG, iLogger, PVLOGMSG_ERR,
1078                                 (0, "PVMFOmxEncPort::SendSPS_PPS: Error returned Kvp is not null."));
1079             }
1080             // Release parameters back to peer and reset for the next query
1081             config->releaseParameters(NULL, sps, 1);
1082         }
1083         for (ii = 0; ii < aNumPPSs; ii++)
1084         {
1085             // send PPS
1086             PvmiKvp* pps, *ret;
1087             AllocateKvp(pps, (OMX_STRING)VIDEO_AVC_OUTPUT_PPS_CUR_VALUE, 1);
1088 
1089             pps->value.key_specific_value = aPPSs[ii].ptr;
1090             pps->capacity = aPPSs[ii].len;
1091             pps->length = aPPSs[ii].len;
1092             config->setParametersSync(NULL, pps, 1, ret);
1093             if (ret)
1094             {
1095                 PVLOGGER_LOGMSG(PVLOGMSG_INST_LLDBG, iLogger, PVLOGMSG_ERR,
1096                                 (0, "PVMFOmxEncPort::SendSPS_PPS: Error returned Kvp is not null."));
1097             }
1098             // Release parameters back to peer and reset for the next query
1099             config->releaseParameters(NULL, pps, 1);
1100         }
1101     }
1102 
1103     return ;
1104 }
1105 
Config_ParametersSync(PvmiCapabilityAndConfig * & aConfig,PvmiKvp * & aSelectedKvp,PvmiKvp * & aRetKvp)1106 int32 PVMFOMXEncPort::Config_ParametersSync(PvmiCapabilityAndConfig *&aConfig, PvmiKvp *&aSelectedKvp, PvmiKvp *&aRetKvp)
1107 {
1108     int32 err = 0;
1109     OSCL_TRY(err, aConfig->setParametersSync(NULL, aSelectedKvp, 1, aRetKvp););
1110     return err;
1111 }
1112 
PushKVP(OsclPriorityQueue<PvmiKvp *,OsclMemAllocator,Oscl_Vector<PvmiKvp *,OsclMemAllocator>,PVMFOMXEncInputFormatCompareLess> & aSortedKvp,PvmiKvp * aKvp)1113 int32 PVMFOMXEncPort::PushKVP(OsclPriorityQueue<PvmiKvp*, OsclMemAllocator, Oscl_Vector<PvmiKvp*, OsclMemAllocator>, PVMFOMXEncInputFormatCompareLess> &aSortedKvp, PvmiKvp *aKvp)
1114 {
1115     int32 err = 0;
1116     OSCL_TRY(err, aSortedKvp.push(aKvp););
1117     return err;
1118 }
1119 
pvmiGetBufferAllocatorSpecificInfoSync(PvmiKeyType aIdentifier,PvmiKvp * & aParameters,int & aNumParamElements)1120 bool PVMFOMXEncPort::pvmiGetBufferAllocatorSpecificInfoSync(PvmiKeyType aIdentifier, PvmiKvp*& aParameters, int& aNumParamElements)
1121 {
1122     if ((iConnectedPort) && (iTag == PVMF_OMX_ENC_NODE_PORT_TYPE_INPUT))
1123     {
1124         OsclAny* temp = NULL;
1125         iConnectedPort->QueryInterface(PVMI_CAPABILITY_AND_CONFIG_PVUUID, temp);
1126 
1127         if (temp != NULL)
1128         {
1129             PvmiCapabilityAndConfig *config = (PvmiCapabilityAndConfig*)temp;
1130 
1131             PVMFStatus status =
1132                 config->getParametersSync(NULL, (PvmiKeyType)aIdentifier, aParameters, aNumParamElements, NULL);
1133 
1134             if (PVMFSuccess == status)
1135             {
1136                 return true;
1137             }
1138         }
1139     }
1140     return false;
1141 }
1142 
releaseParametersSync(PvmiKvp * & aParameters,int & aNumParamElements)1143 bool PVMFOMXEncPort::releaseParametersSync(PvmiKvp*& aParameters, int& aNumParamElements)
1144 {
1145     if ((iConnectedPort) && (iTag == PVMF_OMX_ENC_NODE_PORT_TYPE_INPUT))
1146     {
1147         OsclAny* temp = NULL;
1148         iConnectedPort->QueryInterface(PVMI_CAPABILITY_AND_CONFIG_PVUUID, temp);
1149 
1150         if (temp != NULL)
1151         {
1152             PvmiCapabilityAndConfig *config = (PvmiCapabilityAndConfig*)temp;
1153 
1154             if (PVMFSuccess == config->releaseParameters(NULL, aParameters, aNumParamElements) )
1155             {
1156                 return true;
1157             }
1158         }
1159     }
1160     return false;
1161 }
1162