示例#1
0
 private void SendRtpData()
 {
     // Only send data once per minute
     if (DateTime.Now.Subtract(lastSend).Minutes >= 1)
     {
         rtpSender.Send((BufferChunk)name);
         lastSend = DateTime.Now;
     }
 }
示例#2
0
        private void _SendObject(object o, RtpSender rtpSender, MemoryStream ms, BinaryFormatter bf)
        {
            if (disposed)
            {
                throw new ObjectDisposedException(name);
            }

            if(!isSending)
            {
                throw new ApplicationException(string.Format(CultureInfo.CurrentCulture, 
                    Strings.CallSendBeforeSendObject, name));
            }

            ms.Position = 0; // set the "useful bytes" "pointer" back to 0
            bf.Serialize(ms, o); // serialize, which puts the "useful bytes pointer" at the end of hte useful data

            // Get a byte[] of the serialized object
            int numBytes = (int)ms.Position; // record the number of "useful bytes"
            byte[] byteObj = new Byte[numBytes];
            ms.Position = 0; // set the pointer back to 0, so we can read from that point
            ms.Read(byteObj, 0, numBytes); // read all the useful bytes

            rtpSender.Send(byteObj);
        }        
示例#3
0
        /// <summary>
        /// Send all the frames that should be sent up to this point in time.
        /// </summary>
        /// <param name="bytesSent">Number of bytes sent.</param>
        /// <param name="cumulativeLateness">Sum of temporal disparities over all frames sent.</param>
        /// <param name="firstStoredTick">The 'start' time on the first index in this whole stream.</param>
        /// <param name="sender">The RtpSender to send data on.</param>
        /// <param name="startTimeTicks">The start time of sending, in ticks.</param>
        /// <param name="timeUntilFrame">The temporal distance between the current frame and the next one to be sent, in ticks.</param>
        /// <returns>Number of frames sent.</returns>
        public int SendFrames( RtpSender sender, long timeBoundary, out long timeUntilFrame, ref long totalBytesSent, ref long cumulativeLateness )
        {
            if( this.populating )
                throw new InvalidOperationException(Strings.BufferplayerSendframesError);

            int framesSent = 0;

            try
            {
                while ( currentIndex < indexCount && indices[currentIndex].timestamp <= timeBoundary )
                {
                    long startTimer = DateTime.Now.Ticks;

                    int frameLength = 1 + indices[currentIndex].end - indices[currentIndex].start;

                    if ( frameLength > 0)
                    {
                        // Calculate how late the frame will be
                        long lateness = (timeBoundary - indices[currentIndex].timestamp) / Constants.TicksPerMs;
                        if( lateness > Constants.TicksSpent )
                            Trace.WriteLine(String.Format(CultureInfo.InvariantCulture,
                                "--- FRAME LATENESS OF: {0} ms", lateness));
                        cumulativeLateness += lateness;

                        // Send Frame
                        buffer.Reset( indices[currentIndex].start - indices[0].start, frameLength );
                        sender.Send( buffer );
                    }
                    else
                    {
                        // (pbristow) Why would this happen???
                        Debug.Fail("Frame of length zero found.");
                    }

                    totalBytesSent += frameLength;
                    ++framesSent;
                    ++currentIndex;

                    long takenTime = DateTime.Now.Ticks - startTimer;
                    if( takenTime > Constants.TicksSpent )
                        Trace.WriteLine(String.Format(CultureInfo.InvariantCulture,
                            "TIME WASTED TO SEND A FRAME: {0} ms, ID: {1}, bytes: {2}",
                            (takenTime / Constants.TicksPerMs), streamID, frameLength));
                }

                if ( currentIndex == indexCount )
                {
                    timeUntilFrame = 0;
                }
                else
                {
                    timeUntilFrame = (indices[currentIndex].timestamp - timeBoundary);
                }
            }
            catch(ObjectDisposedException)
            {
                // Sender is disposed by Stop being called
                timeUntilFrame = long.MaxValue;
            }

            return framesSent;
        }