コード例 #1
0
ファイル: StreamingHelper.cs プロジェクト: hungmol/c4fbook
        /// <summary>
        /// Implements the ShareStreamedAudio function specified in the IPeerChannel service contract above.
        /// </summary>
        /// <param name="mdp">the audio packet to send</param>
        public void ShareStream(StreamedPacket mdp)
        {
            //The audio can be in one of two states: Initial, meaning it is ready to receive a new audio stream,
            //or communicating meaning it is either receiving or transmitting.
            switch (streamedState)
            {
            case StreamedStateType.Initial:
                //Initialize the data packet;
                streamedState = StreamedStateType.Communicating;
                mLastChunk    = -1;

                ////write in the textbox that someone is sending us an audio file.
                //ShareTextMessage(mdp.senderNodeName, String.Format(" is Sending you an audio file"));
                break;

            case StreamedStateType.Communicating:

                //update the most recent packet received so we know that the sender hasn't
                //disappeared from the network, or suddenly stopped sending.
                mChunk = mdp.packetNumber;

                //found the end of the stream, reset.
                if (mdp.endOfStream)
                {
                    streamedState = StreamedStateType.Initial;
                }
                break;
            }

            //notify anyone registered for the event.
            if (null != StreamChanged)
            {
                StreamChanged(this, new StreamedChangedEventArgs(mdp));
            }
        }
コード例 #2
0
ファイル: Peer2PeerLibrary.cs プロジェクト: hungmol/c4fbook
 /// <summary>
 /// Implements the ShareStreamedAudio function specified in the IPeerChannel service contract above.
 /// </summary>
 /// <param name="mdp">the audio packet to send</param>
 public void ShareStreamedAudio(StreamedPacket packet)
 {
     CheckDisposed();
     if (mStreamedAudio.StreamedState == StreamedStateType.Initial)
     {
         ShareTextMessage(packet.senderNodeName, String.Format(" is Sending you an audio file"));
     }
     mStreamedAudio.ShareStream(packet);
 }
コード例 #3
0
        protected void UpdateAudioStream(StreamedPacket packet)
        {
            //ok we found the chunk we're looking for lets process it and fire off any others we also may need to.
            lock (Lock)
            {
                mSyncStream.Position = mSyncStreamLastWrittenPos;
                StreamingHelper.CopyStream(packet.stream, mSyncStream);
                mSyncStreamLastWrittenPos = mSyncStream.Position;
                mIncommingStream          = !packet.endOfStream;

                if (mIncommingStream == false)
                {
                    mLogMessage("Finished Receiving Media File\r\n");
                }
            }
        }
コード例 #4
0
ファイル: StreamingHelper.cs プロジェクト: hungmol/c4fbook
        /// <summary>
        /// This function actually sends a packet out. Continue to call this function until it returns true.
        /// </summary>
        /// <returns>true when the entire file is sent</returns>
        public bool SendStream()
        {
            StreamedPacket packet = new StreamedPacket();

            Byte[] b   = new Byte[12000];
            int    len = 0; //the number of bytes read so far.
            bool   finished;

            //only send the meta data on the first packet to conserve bandwidth
            //I'm sure there is still some overhead of sending null strings for the rest of the data.
            if (mSendingPacketNo == 0)
            {
                packet.fileName = System.IO.Path.GetFileName(mCurrentFileName);
                MetadataFileInfo metaData = new MetadataFileInfo();
                metaData.ReadMetaData(mCurrentFileName);
                packet.album  = metaData.AlbumName;
                packet.artist = metaData.ArtistName;
                packet.title  = metaData.Title;
            }
            //debug put it in each packet...
            packet.fileName = System.IO.Path.GetFileName(mCurrentFileName);

            //read from the file
            len = mCurrentStream.Read(b, 0, 12000);
            //write it to the packet's stream.
            packet.stream.Write(b, 0, len);
            packet.stream.Position = 0;            //set the stream back to the initial position.
            packet.guid            = mCurrentGuid; //set the guid.

            if (mCurrentStream.Length != mCurrentStream.Position && false == mStopStream)
            {
                finished           = false;
                packet.endOfStream = false;
            }
            else
            {
                //we are at the end of the file, or someone canceled the file via mStopAudioStream
                //set the file to be finished and send out a endOfStream packet.
                finished           = true;
                mStopStream        = false;
                packet.endOfStream = true; //either reached the end or we canceled the stream.
                mCurrentStream.Close();
            }

            //include the node name
            packet.senderNodeName = mNodeName;
            //set the packet number, and increment the sending packet number.
            packet.packetNumber = mSendingPacketNo++;

            try
            {
                if (del != null)
                {
                    del(packet);
                }
            }
            catch (Exception)
            {
                mStopStream = false;
            }
            return(finished);
        }
コード例 #5
0
ファイル: EventArgs.cs プロジェクト: hungmol/c4fbook
 internal StreamedArgs(StreamedPacket mdp)
 {
     this.mdp = mdp;
 }
コード例 #6
0
ファイル: EventArgs.cs プロジェクト: hungmol/c4fbook
 internal StreamedChangedEventArgs(StreamedPacket mdp)
 {
     this.mStreamedPacket = mdp;
 }