示例#1
0
        /// <summary>
        /// Returns a string representing the structure in little-endian
        /// hexadecimal format.
        /// </summary>
        /// <remarks>
        /// The string generated here is intended to be passed as
        /// CodecPrivateData for Silverlight 2's MediaStreamSource
        /// </remarks>
        /// <returns>
        /// A string representing the structure in little-endia hexadecimal
        /// format.
        /// </returns>
        public string ToHexString()
        {
            string s = WaveFormatExtensible.ToHexString();

            char[] mpeglayer3Data = new char[6 * 4];
            BitTools.ToHexHelper(4, this.Id, 0, mpeglayer3Data);
            BitTools.ToHexHelper(8, this.BitratePaddingMode, 4, mpeglayer3Data);
            BitTools.ToHexHelper(4, this.BlockSize, 12, mpeglayer3Data);
            BitTools.ToHexHelper(4, this.FramesPerBlock, 16, mpeglayer3Data);
            BitTools.ToHexHelper(4, this.CodecDelay, 20, mpeglayer3Data);
            return(s + new string(mpeglayer3Data));
        }
示例#2
0
        protected override void OpenMediaAsync()
        {
            var flvFile = new FlvFile(this.mediaStream);

            this.audioSamples = flvFile.FlvFileBody.Tags.Where(tag => tag.TagType == TagType.Audio).ToList();
            this.videoSamples = flvFile.FlvFileBody.Tags.Where(tag => tag.TagType == TagType.Video).ToList();

            //Audio
            WaveFormatExtensible wfx = new WaveFormatExtensible();

            wfx.FormatTag             = 0x00FF;
            wfx.Channels              = 2;
            wfx.BlockAlign            = 8;
            wfx.BitsPerSample         = 16;
            wfx.SamplesPerSec         = 44100;
            wfx.AverageBytesPerSecond = wfx.SamplesPerSec * wfx.Channels * wfx.BitsPerSample / wfx.BlockAlign;
            wfx.Size = 0;
            string codecPrivateData = wfx.ToHexString();

            Dictionary <MediaStreamAttributeKeys, string> audioStreamAttributes = new Dictionary <MediaStreamAttributeKeys, string>();

            audioStreamAttributes[MediaStreamAttributeKeys.CodecPrivateData] = codecPrivateData;
            this.audioStreamDescription = new MediaStreamDescription(MediaStreamType.Audio, audioStreamAttributes);

            //Video
            Dictionary <MediaStreamAttributeKeys, string> videoStreamAttributes = new Dictionary <MediaStreamAttributeKeys, string>();

            videoStreamAttributes[MediaStreamAttributeKeys.VideoFourCC] = "H264";
            this.videoStreamDescription = new MediaStreamDescription(MediaStreamType.Video, videoStreamAttributes);

            //Media
            Dictionary <MediaSourceAttributesKeys, string> mediaSourceAttributes = new Dictionary <MediaSourceAttributesKeys, string>();

            mediaSourceAttributes[MediaSourceAttributesKeys.Duration] = audioSamples.Last().Timestamp.ToString(CultureInfo.InvariantCulture);
            mediaSourceAttributes[MediaSourceAttributesKeys.CanSeek]  = true.ToString();

            List <MediaStreamDescription> mediaStreamDescriptions = new List <MediaStreamDescription>();

            mediaStreamDescriptions.Add(this.audioStreamDescription);
            mediaStreamDescriptions.Add(this.videoStreamDescription);

            this.ReportOpenMediaCompleted(mediaSourceAttributes, mediaStreamDescriptions);
        }
示例#3
0
        protected override void OpenMediaAsync()
        {
            // Initialize data structures to pass to the Media pipeline via the MediaStreamSource
            Dictionary<MediaSourceAttributesKeys, string> mediaSourceAttributes = new Dictionary<MediaSourceAttributesKeys, string>();
            Dictionary<MediaStreamAttributeKeys, string> mediaStreamAttributes = new Dictionary<MediaStreamAttributeKeys, string>();
            List<MediaStreamDescription> mediaStreamDescriptions = new List<MediaStreamDescription>();

            // Initialize the Mp3 data structures used by the Media pipeline with state from the first frame.
            WaveFormatExtensible wfx = new WaveFormatExtensible();
            wfx.FormatTag = 1; // PCM
            wfx.Channels = 2;
            wfx.SamplesPerSec = 44100;
            wfx.AverageBytesPerSecond = 44100 * 2 * 2;
            wfx.BlockAlign = 4;
            wfx.BitsPerSample = 16;
            wfx.Size = 0;

            mediaStreamAttributes[MediaStreamAttributeKeys.CodecPrivateData] = wfx.ToHexString();
            this.audioStreamDescription = new MediaStreamDescription(MediaStreamType.Audio, mediaStreamAttributes);

            mediaStreamDescriptions.Add(this.audioStreamDescription);

            // <note>This part is mere copy of Mp3MediaStreamSource:
            // Setting a 0 duration to avoid the math to calcualte the Mp3 file length in minutes and seconds.
            // This was done just to simplify this initial version of the code for other people reading it.
            mediaSourceAttributes[MediaSourceAttributesKeys.Duration] = this.trackDuration.Ticks.ToString (CultureInfo.InvariantCulture);
            mediaSourceAttributes[MediaSourceAttributesKeys.CanSeek] = true.ToString ();
            // </note>

            sample_enumerator = this.DecodeSamples ().GetEnumerator ();
            this.ReportOpenMediaCompleted(mediaSourceAttributes, mediaStreamDescriptions);
        }