Beispiel #1
0
// Inserts "rResource" into the flow graph downstream of the
// designated "rUpstreamResource" resource.
// The new resource will be inserted on the "outPortIdx" output
// link of "rUpstreamResource".
// If the flow graph is not "started", this call takes effect
// immediately.  Otherwise, the call takes effect at the start of the
// next frame processing interval.
// Returns OS_SUCCESS if the resource was successfully inserted. Returns
// OS_INVALID_ARGUMENT if the caller specified an invalid port index.
OsStatus MpFlowGraphBase::insertResourceAfter(MpResource& rResource,
                                 MpResource& rUpstreamResource,
                                 int outPortIdx)
{
   MpResource *pDownstreamResource;
   int         downstreamInPortIdx;
   OsStatus    res;

   // Get information about the downstream end of the link
   rUpstreamResource.getOutputInfo(outPortIdx, pDownstreamResource,
                                   downstreamInPortIdx);

   // Add the new resource to the flow graph
   res = addResource(rResource);
   if (res != OS_SUCCESS)
      return res;

   if (pDownstreamResource != NULL)
   {
      // Remove the link between the upstream and downstream resources
      res = removeLink(rUpstreamResource, outPortIdx);
      if (res != OS_SUCCESS)
      {                              // recover from remove link failure
         removeResource(rResource);
         return res;
      }

      // Add the link between output port 0 the new resource and the
      // downstream resource
      res = addLink(rResource, 0, *pDownstreamResource, downstreamInPortIdx);
      if (res != OS_SUCCESS)
      {                              // recover from add link failure
         removeResource(rResource);
         addLink(rUpstreamResource, outPortIdx,
                 *pDownstreamResource, downstreamInPortIdx);
         return res;
      }
   }

   // Add the link between the upstream resource and input port 0 of
   // the new resource
   res = addLink(rUpstreamResource, outPortIdx, rResource, 0);
   if (res != OS_SUCCESS)
   {                              // recover from add link failure
      removeResource(rResource);
      if (pDownstreamResource != NULL)
      {
         addLink(rUpstreamResource, outPortIdx,
                 *pDownstreamResource, downstreamInPortIdx);
      }
   }

   return res;
}