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