inline void CBTAudioStreamSender::SwitchToNewSendPacket()
    {
    BT_AUDIO_STREAMER_TRACE_OPT( KPRINTFTRACE, FLOG(_L("[BTAudioStreamer]\t CBTAudioStreamSender::SwitchToNewSendPacket() ->")));

		// Make the iCurrentSendPacket point to the spare packet opened when the frame length change came. 
    RRtpSendPacket* oldSendPacket; 
    oldSendPacket = iCurrentSendPacket; 
    iCurrentSendPacket = iSpareSendPacket; 
		iSpareSendPacket = oldSendPacket; 
		
    // The previously used send packet (which has now become the spare send packet) can be closed. 
		oldSendPacket->Close(); 

		// The rest of the initializations: 
    InitSender(*iCurrentSendPacket, iPayloadDesC, iTargetBitrate); 

		iChangingFrameLength = EFalse; 

    BT_AUDIO_STREAMER_TRACE_OPT( KPRINTFTRACE, FLOG(_L("[BTAudioStreamer]\t CBTAudioStreamSender::SwitchToNewSendPacket() <-")));
	  }
// ---------------------------------------------------------------------------
// This method is for setting the sender up. 
// ---------------------------------------------------------------------------
//
void CBTAudioStreamSender::StartL(TUint aOutboundMTUSize, const TUint aFrameLength, const TUint aTargetBitrate)
    {
    BT_AUDIO_STREAMER_TRACE_OPT( KPRINTFTRACE, FLOG(_L("[BTAudioStreamer]\t CBTAudioStreamSender::StartL() ->")));
    if(iCurrentSendPacket) 
        {
        __ASSERT_DEBUG(!iCurrentSendPacket->IsOpen(),User::Invariant());
        }
    TInt requiredPacketLength = CalculatePacketLength(aOutboundMTUSize, aFrameLength); 

    if(requiredPacketLength > 0) 
        {
		__ASSERT_DEBUG(iCurrentSendPacket, User::Invariant());
        *iCurrentSendPacket = iSendSrc.NewSendPacketL(requiredPacketLength); 
        iTargetBitrate = aTargetBitrate; 
        InitSender(*iCurrentSendPacket, iPayloadDesC, iTargetBitrate); 
        iStreamerState = EBuffering; 
        BT_AUDIO_STREAMER_TRACE_OPT( KPRINTSTATE, FLOG(_L("[BTAudioStreamer]\t State changed to: EBuffering")));
      }
    else 
        {
        BT_AUDIO_STREAMER_TRACE_OPT( KPRINTSTATE, FLOG(_L("[BTAudioStreamer]\t Error! Packet length must be greater than zero!")));
        User::Leave(KErrArgument); 
        }

    // Streaming started, optimise the ACL link if optimiser service is available. 
    if(iLinkOptimiserAvailable)
        {
        // The below code is to get the connected device's BT Address.
        TBTSockAddr addr; 
        iRtpSession.RtpSocket()->RemoteName(addr); 
        TUint accessLatency = MaxFramesPerPacket() * CalculateFrameDuration(aFrameLength, aTargetBitrate); 
        // Not checking the return code, because it doesn't matter if it fails. 
        iA2DPOptimiser.OptimiseAclForAudioStreaming(addr.BTAddr(), aTargetBitrate, accessLatency);
        }
    BT_AUDIO_STREAMER_TRACE_OPT( KPRINTFTRACE, FLOG(_L("[BTAudioStreamer]\t CBTAudioStreamSender::StartL() <-")));
    }
Esempio n. 3
0
File: main.c Progetto: bochf/testing
/* ========================================================================= */
int run_as_sender(struct optbase *ob)
{
   /* This used to be char junkbuf[0]; but the compiler complained. junkbuf
      is a pointer to the top of the auto variables. The point is to have
      a pointer to some data - but nothing of particular value. */
   int junk;
   char *junkbuf = (char *)&junk;


   struct roundtrip *rt;

   struct pc_comm *pcomm = NULL;
   int go; /* Used multiple times for "event loops" */
   char child_message[80];

   char mirror_address[MAX_VALUE_SIZE];
   char mirror_protocol[MAX_VALUE_SIZE];
   char mirror_port[MAX_VALUE_SIZE];

   unsigned long multiplier;
   unsigned short optimal_block;

   unsigned long run_seconds;

   char sink_address[MAX_VALUE_SIZE];
   char sink_protocol[MAX_VALUE_SIZE];
   char sink_port[MAX_VALUE_SIZE];

   time_t time_started;  /* Really about reporting. */
   time_t time_now;      /* The most recent time.   */
   time_t time_stop;


   /* Do some basic validation of the expected values */
   if ( IsInvalidOption(ob, "MIRROR_ADDRESS", IVO_EXISTS) )
   {
      ErrorMessage("ERROR: MIRROR_ADDRESS option is missing or invalid.\n");
      return(1);
   }
      
   if ( IsInvalidOption(ob, "MIRROR_PROTOCOL", IVO_EXISTS) )
   {
      ErrorMessage("ERROR: MIRROR_PROTOCOL option is missing or invalid.\n");
      return(1);
   }

   if ( IsInvalidOption(ob, "MIRROR_PORT", IVO_EXISTS) )
   {
      ErrorMessage("ERROR: MIRROR_PORT option is missing or invalid.\n");
      return(1);
   }

   if ( IsInvalidOption(ob, "RETURN_MULTIPLIER", IVO_NNNUMERIC) )
   {
      ErrorMessage("ERROR: RETURN_MULTIPLIER option is missing or invalid.\n");
      return(1);
   }

   if ( IsInvalidOption(ob, "OPTIMAL_BLOCK", IVO_EXISTS) )
   {
      optimal_block = DEFAULT_OPTIMAL_BLOCK;
   }
   else
   {
      if ( GetUSValue(ob, &optimal_block, "OPTIMAL_BLOCK", 0, 65535) )
      {
         ErrorMessage("ERROR: Problems parsing OPTIMAL_BLOCK value.\n");
         return(1);
      }
   }

   if ( IsInvalidOption(ob, "RUN_FOR", IVO_EXISTS) )
   {
      run_seconds = 0;
   }
   else
   {
      if ( GetTimeValue(ob, &run_seconds, "RUN_FOR", 0, ULONG_MAX) )
      {
         ErrorMessage("ERROR: Problems parsing RUN_FOR value.\n");
         return(1);
      }
   }

   if ( GetULValue(ob, &multiplier, "RETURN_MULTIPLIER", 0, ULONG_MAX) )
   {
      ErrorMessage("ERROR: Problems parsing RETURN_MULTIPLIER value.\n");
      return(1);
   }

   if ( multiplier > 0 )
   {
      /* This *could* be derived - it should not be *required* */
      if ( IsInvalidOption(ob, "SINK_ADDRESS", IVO_EXISTS) )
      {
         ErrorMessage("ERROR: SINK_ADDRESS option is missing or invalid.\n");
         return(1);
      }

      if ( IsInvalidOption(ob, "SINK_PORT", IVO_EXISTS) )
      {
         ErrorMessage("ERROR: SINK_PORT option is missing or invalid.\n");
         return(1);
      }
         
      if ( IsInvalidOption(ob, "SINK_PROTOCOL", IVO_EXISTS) )
      {
         ErrorMessage("ERROR: SINK_PROTOCOL option is missing or invalid.\n");
         return(1);
      }
   }
      
   if ( GetStrValue(ob, mirror_address, "MIRROR_ADDRESS", 4, MAX_VALUE_SIZE) )
   {
      ErrorMessage("ERROR: Problems parsing MIRROR_ADDRESS value.\n");
      return(1);
   }

   if ( GetSTRValue(ob, mirror_protocol, "MIRROR_PROTOCOL", 2, 4) )
   {
      ErrorMessage("ERROR: Problems parsing MIRROR_PROTOCOL value.\n");
      return(1);
   }

   if ( GetStrValue(ob, mirror_port, "MIRROR_PORT", 2, 5) )
   {
      ErrorMessage("ERROR: Problems parsing MIRROR_PORT value.\n");
      return(1);
   }

   if ( multiplier > 0 )
   {
      if ( GetStrValue(ob, sink_address, "SINK_ADDRESS", 4, MAX_VALUE_SIZE) )
      {
         ErrorMessage("ERROR: Problems parsing SINK_ADDRESS value.\n");
         return(1);
      }
      
      if ( GetSTRValue(ob, sink_protocol, "SINK_PROTOCOL", 2, 4) )
      {
         ErrorMessage("ERROR: Problems parsing SINK_PROTOCOL value.\n");
         return(1);
      }
         
      if ( GetStrValue(ob, sink_port, "SINK_PORT", 2, 5) )
      {
         ErrorMessage("ERROR: Problems parsing SINK_PORT value.\n");
         return(1);
      }
   }

   ReportStart("netmirror", NULL, "A module to bounce packets across the network.");

   /* Register signal handlers */
   /*
   signal(SIGTERM, capture_signal);
   signal(SIGQUIT, capture_signal);
   signal(SIGINT, capture_signal);
   signal(SIGHUP, NULL);
   */

   if ( NULL == ( rt = InitRoundTrip() ) )
      return(1);

   if ( InitSender(rt, mirror_address, mirror_protocol, mirror_port) )
      return(1);
   
   if ( InitReceiver(rt, sink_address, sink_protocol, sink_port, multiplier) )
      return(1);

   DebugMessage("Round trip multiplier is %lu.\n", multiplier);
   DebugMessage("Run time (in seconds) is: %lu.\n", run_seconds);

   if ( multiplier > 0 )
   {
      if (NULL == (pcomm = LaunchAsSink("ADDR", "PROTO", "PORT")))
         return(1);
   }
   
   /* Check for message from the sink (if we started it). */
   if (pcomm)
   {
      if(CheckForChildMessages(pcomm->outof, 250, child_message) > 0)
         VerboseMessage("Sink: %s\n", child_message);
      /* A sink is present */
   }


   rt->opt_block = optimal_block;
   rt->run_seconds = run_seconds;

   /* Start up the sender and send the opening packets */
   if(StartSender(rt))
      return(1);


   /* Take time here - use it or not */
   time(&time_started);
   time_stop = time_started + run_seconds;

   /* Send packets - handle sink messages */
   go = 1;
   while(go)
   {
      //DebugMessage("Sending data...");
      send(rt->sd, junkbuf, optimal_block, 0);
      //DebugMessage("Done.\n");

      /* NOTE: This is an oppurtunity to put a delay in the sender. It
               can be done here with the CheckForChildMessages() API.
               In cases where there is no sink, then that code will not
               run, so some other blocking mechanisim might be required
               to insert the (optional) delay. */
      if (pcomm)
      {
         /* A sink is present */
         if(CheckForChildMessages(pcomm->outof, 0, child_message) > 0)
            VerboseMessage("Sink: %s\n", child_message);
      }
      
      /* Now time becomes conditional */
      if ( run_seconds > 0 )
      {
         time(&time_now);

         if ( time_now >= time_stop )
            go = 0;
      }
   }

   DebugMessage("Shutting down the connection...");
   close(rt->sd); /* An actual shutdown() is not relevant. */
   DebugMessage("Done.\n");

   /* There should be a several second pause between shutting down
      outbound traffic and sending the stop to the sink. */

   DebugMessage("Sending stop to sink process");
   go = 3;
   while(go)
   {
      DebugMessage(".");
      sleep(1);
      go--;
   }
   SendStopSink(pcomm->into);
   DebugMessage("Done.\n");
      
   go = 10; 
   while ( go )
   {
      if(CheckForChildMessages(pcomm->outof, 500, child_message) > 0)
      {
         if ( child_message[0] == '.' )
         {
            VerboseMessage("Sink exited. Sender exiting now.\n");
            return(0);
         }
      }

      go--;
   }

   ErrorMessage("ERROR: Sink process never exited. Sender exiting.\n");
   return(1);
}
Esempio n. 4
0
int main(int argc, char **argv) {
    const char *addr = "127.0.0.1";
    int port = 7766;

    if (argc != 2) {
        cout
            << "Please call with 0 if acting as server or 1 if acting as client"
            << endl;
        return 0;
    }

    // Determines whether the program is executed in the sender or receiver role
    m_nPID = atoi(argv[1]);
    cout << "Playing as role: " << m_nPID << endl;
    assert(m_nPID >= 0 && m_nPID <= 1);

    // The symmetric security parameter (80, 112, 128)
    uint32_t m_nSecParam = 128;

    crypto *crypt = new crypto(m_nSecParam, (uint8_t *)m_cConstSeed[m_nPID]);

    uint32_t m_nBaseOTs = 190;
    uint32_t m_nChecks = 380;

    ot_ext_prot lastprot = PROT_LAST;
    field_type lastfield = FIELD_LAST;

    if (m_nPID == SERVER_ID) // Play as OT sender
    {
        InitSender(addr, port);

        OTExtSnd *sender = NULL;
        for (uint32_t i = 0; i < m_nTests; i++) {
            if (lastprot != tests[i].prot || lastfield != tests[i].ftype) {
                // if(sender) delete sender;
                sender = InitOTExtSnd(tests[i].prot, m_nBaseOTs, m_nChecks,
                                      tests[i].usemecr, tests[i].ftype, crypt);
                lastprot = tests[i].prot;
                lastfield = tests[i].ftype;
            }

            cout << "Test " << i << ": " << getProt(tests[i].prot) << " Sender "
                 << tests[i].numots << " " << getSndFlavor(tests[i].sflavor)
                 << " / " << getRecFlavor(tests[i].rflavor) << " on "
                 << tests[i].bitlen << " bits with " << tests[i].nthreads
                 << " threads, " << getFieldType(tests[i].ftype) << " and"
                 << (tests[i].usemecr ? "" : " no") << " MECR" << endl;

            run_test_sender(tests[i].numots, tests[i].bitlen, tests[i].sflavor,
                            tests[i].rflavor, tests[i].nthreads, crypt, sender);
        }
        delete sender;
    } else // Play as OT receiver
    {
        InitReceiver(addr, port);

        OTExtRec *receiver = NULL;
        for (uint32_t i = 0; i < m_nTests; i++) {
            if (lastprot != tests[i].prot || lastfield != tests[i].ftype) {
                // if(receiver) delete receiver;
                receiver =
                    InitOTExtRec(tests[i].prot, m_nBaseOTs, m_nChecks,
                                 tests[i].usemecr, tests[i].ftype, crypt);
                lastprot = tests[i].prot;
                lastfield = tests[i].ftype;
            }

            cout << "Test " << i << ": " << getProt(tests[i].prot)
                 << " Receiver " << tests[i].numots << " "
                 << getSndFlavor(tests[i].sflavor) << " / "
                 << getRecFlavor(tests[i].rflavor) << " on " << tests[i].bitlen
                 << " bits with " << tests[i].nthreads << " threads, "
                 << getFieldType(tests[i].ftype) << " and"
                 << (tests[i].usemecr ? "" : " no") << " MECR" << endl;

            run_test_receiver(tests[i].numots, tests[i].bitlen,
                              tests[i].sflavor, tests[i].rflavor,
                              tests[i].nthreads, crypt, receiver);
        }
        delete receiver;
    }

    Cleanup();
    delete crypt;

    return 1;
}