Pass peer PvmiCapabilityAndConfig interface to MIOs using Capability Exchange
diff --git a/nodes/pvmediainputnode/src/pvmf_media_input_node.cpp b/nodes/pvmediainputnode/src/pvmf_media_input_node.cpp
index 3691f37..eb232d9 100644
--- a/nodes/pvmediainputnode/src/pvmf_media_input_node.cpp
+++ b/nodes/pvmediainputnode/src/pvmf_media_input_node.cpp
@@ -132,10 +132,31 @@
 
     if (iMediaIOControl)
     {
+        //notify the media input component that peer cap-config is no longer usable
+        //we do this by calling setParameterSync with NULL
+        OsclMemAllocator alloc;
+        PvmiKvp kvp;
+        kvp.key = NULL;
+        uint32 keylen = oscl_strlen(PVMF_MEDIA_INPUT_NODE_CAP_CONFIG_INTERFACE_KEY) + 1; // +1 for \0
+        kvp.key = (PvmiKeyType)alloc.ALLOCATE(keylen);
+        if (kvp.key != NULL)
+        {
+            oscl_memset(kvp.key, 0, keylen);
+            oscl_strncpy(kvp.key,
+                         PVMF_MEDIA_INPUT_NODE_CAP_CONFIG_INTERFACE_KEY,
+                         keylen-1);
+            kvp.value.key_specific_value = NULL;
+            kvp.length = 1; //since we are just passing one pointer
+            kvp.capacity = kvp.length;
+            PvmiKvp* retKvp = NULL; // for return value
+            int32 err;
+            OSCL_TRY(err, iMediaIOConfig->setParametersSync(NULL, &kvp, 1, retKvp););
+            /* ignore the error for now */
+            alloc.deallocate((OsclAny*)(kvp.key));
+        }
         iMediaIOControl->ThreadLogoff();
         iMediaIOControl->disconnect(iMediaIOSession);
         //ignore any returned error.
-
         iMediaIOState = PvmfMediaInputNode::MIO_STATE_IDLE;
     }
 
@@ -412,9 +433,30 @@
                 {
                     if (iMediaIOConfigPVI)
                     {
-
                         iMediaIOConfig = OSCL_STATIC_CAST(PvmiCapabilityAndConfig*, iMediaIOConfigPVI);
                         iMediaIOConfigPVI = NULL;
+                        //now attempt to provide the media input comp with the capconfig interface of the node
+                        OsclMemAllocator alloc;
+                        PvmiKvp kvp;
+                        kvp.key = NULL;
+                        uint32 keylen = oscl_strlen(PVMF_MEDIA_INPUT_NODE_CAP_CONFIG_INTERFACE_KEY) + 1; // +1 for \0
+                        kvp.key = (PvmiKeyType)alloc.ALLOCATE(keylen);
+                        if (kvp.key != NULL)
+                        {
+                            oscl_memset(kvp.key, 0, keylen);
+                            oscl_strncpy(kvp.key,
+                                         PVMF_MEDIA_INPUT_NODE_CAP_CONFIG_INTERFACE_KEY,
+                                         keylen-1);
+                            PvmiCapabilityAndConfig* capconfig = OSCL_STATIC_CAST(PvmiCapabilityAndConfig*, this);
+                            kvp.value.key_specific_value = (OsclAny*)(capconfig);
+                            kvp.length = 1; //since we are just passing one pointer
+                            kvp.capacity = kvp.length;
+                            PvmiKvp* retKvp = NULL; // for return value
+                            int32 err;
+                            OSCL_TRY(err, iMediaIOConfig->setParametersSync(NULL, &kvp, 1, retKvp););
+                            /* ignore the error for now */
+                            alloc.deallocate((OsclAny*)(kvp.key));
+                        }
                     }
                     else
                     {
diff --git a/nodes/pvmediainputnode/src/pvmf_media_input_node_cap_config.cpp b/nodes/pvmediainputnode/src/pvmf_media_input_node_cap_config.cpp
index a19e50d..c1e980d 100644
--- a/nodes/pvmediainputnode/src/pvmf_media_input_node_cap_config.cpp
+++ b/nodes/pvmediainputnode/src/pvmf_media_input_node_cap_config.cpp
@@ -362,17 +362,11 @@
         char* compstr = NULL;
         pv_mime_string_extract_type(0, aParameters[paramind].key, compstr);
 
-        if ((pv_mime_strcmp(compstr, _STRLIT_CHAR("x-pvmf/datasource")) < 0) || compcount < 2)
+        if ((pv_mime_strcmp(compstr, _STRLIT_CHAR("x-pvmf/datasource")) == 0) &&
+                (compcount == 3))
         {
             // First 2 components should be "x-pvmf/datasource" and there must
-            // be at least four components
-            aRetKVP = &aParameters[paramind];
-            PVLOGGER_LOGMSG(PVLOGMSG_INST_HLDBG, iLogger, PVLOGMSG_ERR, (0, "PvmfMediaInputNode::setParametersSync() Unsupported key"));
-            return;
-        }
-
-        if (3 == compcount)
-        {
+            // be exactly 3 components
             // Verify and set the passed-in media input setting
             PVMFStatus retval = VerifyAndSetConfigParameter(aParameters[paramind], true);
             if (PVMFSuccess != retval)
@@ -384,14 +378,31 @@
         }
         else
         {
-            // Do not support more than 3 components right now
-            aRetKVP = &aParameters[paramind];
-            PVLOGGER_LOGMSG(PVLOGMSG_INST_HLDBG, iLogger, PVLOGMSG_ERR, (0, "PvmfMediaInputNode::setParametersSync() Unsupported key"));
-            return;
+            //pass it on to port to be sent upstream
+            //assume just one output port for now
+            if (iOutPortVector.size() == 1)
+            {
+                PvmfMediaInputNodeOutPort* outPort = iOutPortVector[0];
+                if (outPort != NULL)
+                {
+                    PVMFPortInterface* connectedPort = outPort->getConnectedPort();
+                    if (connectedPort != NULL)
+                    {
+                        OsclAny* temp = NULL;
+                        connectedPort->QueryInterface(PVMI_CAPABILITY_AND_CONFIG_PVUUID, temp);
+                        PvmiCapabilityAndConfig *config = OSCL_STATIC_CAST(PvmiCapabilityAndConfig*, temp);
+                        config->setParametersSync(aSession, aParameters, aNumElements, aRetKVP);
+                        return;
+                    }
+                }
+            }
+            //no parameters were accepted
+            aRetKVP = aParameters;
+            PVLOGGER_LOGMSG(PVLOGMSG_INST_HLDBG, iLogger, PVLOGMSG_ERR, (0, "PvmfMediaInputNode::setParametersSync() Setting parameters failed"));
         }
     }
-
     PVLOGGER_LOGMSG(PVLOGMSG_INST_LLDBG, iLogger, PVLOGMSG_STACK_TRACE, (0, "PvmfMediaInputNode::setParametersSync() Out"));
+    return;
 }
 
 
diff --git a/nodes/pvmediainputnode/src/pvmf_media_input_node_outport.cpp b/nodes/pvmediainputnode/src/pvmf_media_input_node_outport.cpp
index ef4f56f..628cd1e 100644
--- a/nodes/pvmediainputnode/src/pvmf_media_input_node_outport.cpp
+++ b/nodes/pvmediainputnode/src/pvmf_media_input_node_outport.cpp
@@ -30,12 +30,6 @@
 #include "pvmf_format_type.h"
 #endif
 
-#ifdef TEXT_TRACK_DESC_INFO
-#ifndef TEXTSAMPLEDESCINFO_H
-#include "textsampledescinfo.h"
-#endif
-#endif
-
 #ifndef PVMF_MEDIA_MSG_FORMAT_IDS_H_INCLUDED
 #include "pvmf_media_msg_format_ids.h"
 #endif
@@ -275,34 +269,11 @@
 
                 case PVMI_MEDIAXFER_FMT_INDEX_FMT_SPECIFIC_INFO:
                 {
-#ifdef TEXT_TRACK_DESC_INFO
-
-                    if (iFormatType == PVMF_MIME_3GPP_TIMEDTEXT)
-                    {
-                        //get indexing info to map text data with config info
-                        PvmiKvp* textKvp = OSCL_STATIC_CAST(PvmiKvp*, data);
-                        PVA_FF_TextSampleDescInfo* pDecoderinfo;
-                        pDecoderinfo = OSCL_STATIC_CAST(PVA_FF_TextSampleDescInfo*, textKvp->value.key_specific_value);
-
-                        itext_sample_index.push_back(pDecoderinfo->sdindex);
-                        istart_text_sample.push_back(pDecoderinfo->start_sample_num);
-                        iend_text_sample.push_back(pDecoderinfo->end_sample_num);
-                        imax_num_sample = pDecoderinfo->end_sample_num + 1;
-                    }
-
-                    uint32 cmdId = *(OSCL_STATIC_CAST(uint32*, context));
-
-                    OsclAny* temp = NULL;
-                    iConnectedPort->QueryInterface(PVMI_CAPABILITY_AND_CONFIG_PVUUID, temp);
-                    PvmiCapabilityAndConfig *config = OSCL_STATIC_CAST(PvmiCapabilityAndConfig*, temp);
-
-                    PvmiKvp* mioKvp = OSCL_STATIC_CAST(PvmiKvp*, data);
-                    PvmiKvp* ret_kvp = NULL;
-                    config->setParametersSync(NULL, mioKvp, 1, ret_kvp);
-                    iMediaInput->writeComplete(PVMFSuccess, cmdId, NULL);
-                    return 0;
-
-#endif
+                    //we expect media input components to use cap-config to provide
+                    //fmt specific info
+                    LOG_ERR((0, "Fmt Specific Info over WriteAsync Not Supported"));
+                    iNode->ReportErrorEvent(PVMFErrPortProcessing, (OsclAny*)NULL);
+                    OsclError::Leave(OsclErrGeneral);
                 }
                 break;
                 case PVMI_MEDIAXFER_FMT_INDEX_END_OF_STREAM:
@@ -316,13 +287,13 @@
                 break;
                 default:
                 {
-                    LOG_DEBUG((0, "Ignoring Format Index :%d since not supported\n", format_index));
+                    LOG_ERR((0, "Ignoring Format Index :%d since not supported\n", format_index));
 
                     iNode->ReportErrorEvent(PVMFErrPortProcessing, (OsclAny*)NULL);
                     OsclError::Leave(OsclErrGeneral);
 
                 }
-
+                break;
             }
 
         }
@@ -438,48 +409,6 @@
                             "StreamID=%d, TS=%d, Len=%d, SN=%d, MimeType=%s",
                             data_header_info.stream_id,  data_header_info.timestamp, data_len,
                             data_header_info.seq_num, iMimeType.get_cstr()));
-            if (itext_sample_index.size())
-            {
-                bool found = false;
-                OsclMemAllocDestructDealloc<uint8> my_alloc;
-                OsclRefCounter* my_refcnt;
-                uint aligned_refcnt_size = oscl_mem_aligned_size(sizeof(OsclRefCounterSA< OsclMemAllocDestructDealloc<uint8> >));
-                uint8* my_ptr = (uint8*) my_alloc.allocate(aligned_refcnt_size + sizeof(int32));
-                my_refcnt = OSCL_PLACEMENT_NEW(my_ptr, OsclRefCounterSA< OsclMemAllocDestructDealloc<uint8> >(my_ptr));
-                my_ptr += aligned_refcnt_size;
-
-                OsclMemoryFragment memfrag;
-                memfrag.len = 0;
-                memfrag.ptr = my_ptr;
-
-                memfrag.len = sizeof(int32);
-
-                if (inum_text_sample >= imax_num_sample)
-                {
-                    while (inum_text_sample >= imax_num_sample)
-                    {
-                        inum_text_sample = inum_text_sample - imax_num_sample;
-                    }
-                }
-                for (uint32 ii = 0; ii < itext_sample_index.size(); ii++)
-                {
-                    if (inum_text_sample >= istart_text_sample[ii] && inum_text_sample <= iend_text_sample[ii])
-                    {
-                        found = true;
-                        memfrag.ptr = &(itext_sample_index[ii]);//vector stores the sample index no.
-                    }//this index no. gives the sample description index information
-                    if (found)
-                    {
-                        break;
-                    }
-                }
-
-                inum_text_sample += 1;
-                // Save format specific info
-                OsclRefCounterMemFrag configinfo(memfrag, my_refcnt, sizeof(int32));
-                iFormatSpecificInfo = configinfo;
-                mediaData->setFormatSpecificInfo(iFormatSpecificInfo);
-            }
             // Convert media data to MediaMsg
             PVMFSharedMediaMsgPtr mediaMsg;
             convertToPVMFMediaMsg(mediaMsg, mediaData);
diff --git a/nodes/pvmediainputnode/src/pvmf_media_input_node_outport.h b/nodes/pvmediainputnode/src/pvmf_media_input_node_outport.h
index 47d0d65..ca1ddad 100644
--- a/nodes/pvmediainputnode/src/pvmf_media_input_node_outport.h
+++ b/nodes/pvmediainputnode/src/pvmf_media_input_node_outport.h
@@ -131,6 +131,11 @@
         OSCL_IMPORT_REF uint32 getCapabilityMetric(PvmiMIOSession aSession);
         OSCL_IMPORT_REF PVMFStatus verifyParametersSync(PvmiMIOSession aSession, PvmiKvp* aParameters, int num_elements);
         void SendEndOfTrackCommand(const PvmiMediaXferHeader& data_header_info);
+
+        PVMFPortInterface* getConnectedPort() {
+            return iConnectedPort;
+       }
+
     private:
 
         void Run();
@@ -167,9 +172,6 @@
         PvmiMediaTransfer* iPeer;
 
 
-        Oscl_Vector<int32, OsclMemAllocator> itext_sample_index;
-        Oscl_Vector<uint32, OsclMemAllocator> istart_text_sample;
-        Oscl_Vector<uint32, OsclMemAllocator> iend_text_sample;
 
         // Format specific info
         OsclRefCounterMemFrag iFormatSpecificInfo;
diff --git a/nodes/pvmp4ffcomposernode/src/pvmp4ffcn_node.cpp b/nodes/pvmp4ffcomposernode/src/pvmp4ffcn_node.cpp
index 33782bc..8989d75 100644
--- a/nodes/pvmp4ffcomposernode/src/pvmp4ffcn_node.cpp
+++ b/nodes/pvmp4ffcomposernode/src/pvmp4ffcn_node.cpp
@@ -2343,17 +2343,7 @@
             {
                 iTrackId_Text = port->GetTrackId();
                 iformat_text = port->GetFormat();
-                OsclRefCounterMemFrag textconfiginfo;
-
-                if (mediaDataPtr->getFormatSpecificInfo(textconfiginfo) == false ||
-                        textconfiginfo.getMemFragSize() == 0)
-                {
-                    PVLOGGER_LOGMSG(PVLOGMSG_INST_REL, iLogger, PVLOGMSG_ERR,
-                                    (0, "PVMp4FFComposerNode::ProcessIncomingMsg: Error - VOL Header not available"));
-                    return PVMFFailure;
-                }
-                int32* pVal = (int32*)textconfiginfo.getMemFragPtr();
-                iText_sdIndex = *pVal;
+                GetTextSDIndex(mediaDataPtr->getSeqNum(), iText_sdIndex);
             }
             if (((port->GetFormat() == PVMF_MIME_AMR_IETF) ||
                     (port->GetFormat() == PVMF_MIME_AMRWB_IETF)) && mediaDataPtr->getErrorsFlag())
@@ -3150,3 +3140,22 @@
                         );
     return err;
 }
+
+void PVMp4FFComposerNode::GetTextSDIndex(uint32 aSampleNum, int32& aIndex)
+{
+    //default index is zero
+    aIndex = 0;
+    Oscl_Vector<PVA_FF_TextSampleDescInfo*, OsclMemAllocator>::iterator it;
+    for (it = textdecodervector.begin(); it != textdecodervector.end(); it++)
+    {
+        if ((aSampleNum >= (*it)->start_sample_num) &&
+                (aSampleNum <= (*it)->end_sample_num))
+        {
+            aIndex = (*it)->sdindex;
+            break;
+        }
+    }
+}
+
+
+
diff --git a/nodes/pvmp4ffcomposernode/src/pvmp4ffcn_node.h b/nodes/pvmp4ffcomposernode/src/pvmp4ffcn_node.h
index 4468af0..034a80c 100644
--- a/nodes/pvmp4ffcomposernode/src/pvmp4ffcn_node.h
+++ b/nodes/pvmp4ffcomposernode/src/pvmp4ffcn_node.h
@@ -488,6 +488,8 @@
         uint32 iFileDuration;
         uint32 iErrorDataPathStall;
 #endif
+
+        void GetTextSDIndex(uint32 aSampleNum, int32& aIndex);
 };
 
 #endif // PVMP4FFC_NODE_H_INCLUDED
diff --git a/pvmi/media_io/pvmi_mio_fileinput/src/pvmi_mio_fileinput.cpp b/pvmi/media_io/pvmi_mio_fileinput/src/pvmi_mio_fileinput.cpp
index 74f7c19..0b15f53 100644
--- a/pvmi/media_io/pvmi_mio_fileinput/src/pvmi_mio_fileinput.cpp
+++ b/pvmi/media_io/pvmi_mio_fileinput/src/pvmi_mio_fileinput.cpp
@@ -725,7 +725,8 @@
         iAuthoringDuration(0),
         iStreamDuration(0),
         iFormatSpecificInfoSize(0),
-        iFSIKvp(NULL)
+        iFSIKvp(NULL),
+        iPeerCapConfig(NULL)
 {
 
 }
@@ -1866,6 +1867,12 @@
             return PVMFFailure;
         }
     }
+    else if (pv_mime_strcmp(aKvp->key, PVMF_MEDIA_INPUT_NODE_CAP_CONFIG_INTERFACE_KEY) == 0)
+    {
+        iPeerCapConfig = OSCL_STATIC_CAST(PvmiCapabilityAndConfig*, aKvp->value.key_specific_value);
+        LOG_DEBUG((0, "PvmiMIOFileInput::VerifyAndSetParameter: PVMF_MEDIA_INPUT_NODE_CAP_CONFIG_INTERFACE_KEY - Ptr=0x%x", iPeerCapConfig));
+        return PVMFSuccess;
+    }
 
     LOG_ERR((0, "PvmiMIOFileInput::VerifyAndSetParameter: Error - Unsupported parameter"));
     return PVMFFailure;
@@ -1963,7 +1970,6 @@
 
 
     char* buff = iptextfiledata;
-    char* tempbuff = iptextfiledata;
     uint32 valsize = 10;
     char* val = (char*)OSCL_MALLOC(valsize * sizeof(char));
     uint32 temp = 0;
@@ -2219,46 +2225,78 @@
             break;
         }
         PV_atoi(val, 'd', (uint32&)ipDecoderinfo->end_sample_num);
-
         uint32 length = sizeof(ipDecoderinfo) + 2 * DEFAULT_RGB_ARRAY_SIZE + ipDecoderinfo->font_length;
-
-        PvmiMediaXferHeader data_hdr;
-
-
         //allocate KVP
         PvmiKvp* aKvp = NULL;
         PVMFStatus status = PVMFSuccess;
         status = AllocateKvp(aKvp, (PvmiKeyType)TIMED_TEXT_OUTPUT_CONFIG_INFO_CUR_VALUE, 1);
-
         if (status != PVMFSuccess)
         {
             OSCL_DELETE(ipDecoderinfo);
             ipDecoderinfo = NULL;
-            return 0;
-        }
+            OSCL_FREE(val);
+            val = NULL;
+            //closing text file
+            if (iFileOpened_text)
+            {
+                iTextFile.Close();
+                iFileOpened_text = false;
+            }
 
+            if (iFsOpened_text)
+            {
+                iFs_text.Close();
+                iFsOpened_text = false;
+            }
+            return PVMFFailure;
+        }
         aKvp->value.key_specific_value = ipDecoderinfo;
         aKvp->capacity = length;
-
-        PvmiMIOFileInputMediaData textConfInfo;
-        textConfInfo.iData = aKvp;
-        textConfInfo.iId = ++iNotificationID;
-        textConfInfo.iNotification = true;
-
-        iSentMediaData.push_back(textConfInfo);
-
-        int32 err = 0;
-        //typecast to pass in writeAsync
-        uint8* notifData = OSCL_STATIC_CAST(uint8*, aKvp);
-        OSCL_TRY(err, iPeer->writeAsync(PVMI_MEDIAXFER_FMT_TYPE_NOTIFICATION,
-                                        PVMI_MEDIAXFER_FMT_INDEX_FMT_SPECIFIC_INFO,
-                                        notifData, length, data_hdr, &iNotificationID););
-        if (!err)
+        if (iPeerCapConfig != NULL)
         {
-            tempbuff = iptextfiledata; //to calculate the one decoderinfo size
+            PvmiKvp* retKvp = NULL; // for return value
+            int32 err;
+            OSCL_TRY(err, iPeerCapConfig->setParametersSync(NULL, aKvp, 1, retKvp););
+            PVA_FF_TextSampleDescInfo* textInfo =
+                OSCL_STATIC_CAST(PVA_FF_TextSampleDescInfo*, aKvp->value.key_specific_value);
+            OSCL_DELETE(textInfo);
+            iAlloc.deallocate(aKvp);
+            if (err != 0)
+            {
+                OSCL_FREE(val);
+                val = NULL;
+                //closing text file
+                if (iFileOpened_text)
+                {
+                    iTextFile.Close();
+                    iFileOpened_text = false;
+                }
+
+                if (iFsOpened_text)
+                {
+                    iFs_text.Close();
+                    iFsOpened_text = false;
+                }
+                return PVMFFailure;
+            }
         }
         else
         {
+            iAlloc.deallocate(aKvp);
+            OSCL_FREE(val);
+            val = NULL;
+            //closing text file
+            if (iFileOpened_text)
+            {
+                iTextFile.Close();
+                iFileOpened_text = false;
+            }
+
+            if (iFsOpened_text)
+            {
+                iFs_text.Close();
+                iFsOpened_text = false;
+            }
             return PVMFFailure;
         }
     }
diff --git a/pvmi/media_io/pvmi_mio_fileinput/src/pvmi_mio_fileinput.h b/pvmi/media_io/pvmi_mio_fileinput/src/pvmi_mio_fileinput.h
index 03e20ae..244fa42 100644
--- a/pvmi/media_io/pvmi_mio_fileinput/src/pvmi_mio_fileinput.h
+++ b/pvmi/media_io/pvmi_mio_fileinput/src/pvmi_mio_fileinput.h
@@ -370,6 +370,9 @@
         uint32 iFormatSpecificInfoSize;
         bool iSetFormatSpecificInfo;
         PvmiKvp* iFSIKvp;
+
+        //Peer's cap-config interface ptr
+        PvmiCapabilityAndConfig* iPeerCapConfig;
 };
 
 #endif // PVMI_MIO_FILEINPUT_H_INCLUDED
diff --git a/pvmi/pvmf/include/pvmi_kvp.h b/pvmi/pvmf/include/pvmi_kvp.h
index 632151e..2f87198 100644
--- a/pvmi/pvmf/include/pvmi_kvp.h
+++ b/pvmi/pvmf/include/pvmi_kvp.h
@@ -453,6 +453,11 @@
 // Key for signalling max number of outstanding media msgs
 #define PVMF_DATAPATH_PORT_MAX_NUM_MEDIA_MSGS_KEY "x-pvmf/datapath/port/max-num-media-msgs;valtype=uint32"
 
+// Key for media input node to provide its cap-config interface to media input compnent
+#define PVMF_MEDIA_INPUT_NODE_CAP_CONFIG_INTERFACE_KEY "x-pvmf/media-input-node/cap-config-interface;valtype=key_specific_value"
+
+// Key for media output node to provide its cap-config interface to media output compnent
+#define PVMF_MEDIA_OUTPUT_NODE_CAP_CONFIG_INTERFACE_KEY "x-pvmf/media-output-node/cap-config-interface;valtype=key_specific_value"
 
 // Keys for media output components -- Audio
 //