protected override void OpenMediaAsync()
        {
            //WaveFormatEx
            HeAacWaveFormat      aacf = new HeAacWaveFormat();
            WaveFormatExtensible wfx  = new WaveFormatExtensible();

            aacf.WaveFormatExtensible = wfx;

            aacf.WaveFormatExtensible.FormatTag             = 0x1610; //0xFF;//0x1610;
            aacf.WaveFormatExtensible.Channels              = 2;      //
            aacf.WaveFormatExtensible.BlockAlign            = 1;
            aacf.WaveFormatExtensible.BitsPerSample         = 0;      //16; //unkonw set to 0
            aacf.WaveFormatExtensible.SamplesPerSec         = 24000;  //  from 8000 to 96000 Hz
            aacf.WaveFormatExtensible.AverageBytesPerSecond = 0;      //wfx.SamplesPerSec * wfx.Channels * wfx.BitsPerSample / wfx.BlockAlign;
            aacf.WaveFormatExtensible.Size = 12;

            // Extra 3 words in WAVEFORMATEX
            // refer to http://msdn.microsoft.com/en-us/library/windows/desktop/dd757806(v=vs.85).aspx
            aacf.wPayloadType = 0x0; //Audio Data Transport Stream (ADTS). The stream contains an adts_sequence, as defined by MPEG-2.
            aacf.wAudioProfileLevelIndication = 0xFE;
            aacf.wStructType = 0;

            string codecPrivateData = aacf.ToHexString();

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

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


            m_vbuffer.WaitForWorkItem();

            m_curVideoBlk = m_vbuffer.Dequeue().CommandParameter as MSF.VideoBlock;

            if (m_curVideoBlk == null)
            {
                return;
            }
            vIdx = 0;
            fNum = (int)m_curVideoBlk.VideoFrameNum;


            H264NalFormat h264f = new H264NalFormat();

            h264f.sps = m_curVideoBlk.FirstIFrameInfo.sps;
            h264f.pps = m_curVideoBlk.FirstIFrameInfo.pps;
            string s = h264f.ToHexString();

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

            videoStreamAttributes[MediaStreamAttributeKeys.VideoFourCC]      = "H264";
            videoStreamAttributes[MediaStreamAttributeKeys.Height]           = "240";
            videoStreamAttributes[MediaStreamAttributeKeys.Width]            = "320";
            videoStreamAttributes[MediaStreamAttributeKeys.CodecPrivateData] = s;//"0000016742E00D96520283F40500000168CE388000";
            videoStreamDescription = new MediaStreamDescription(MediaStreamType.Video, videoStreamAttributes);

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

            mediaSourceAttributes[MediaSourceAttributesKeys.Duration] = TimeSpan.FromSeconds(6).Ticks.ToString(CultureInfo.InvariantCulture);
            mediaSourceAttributes[MediaSourceAttributesKeys.CanSeek]  = "0";

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

#if !DEBUG
            // Emulator does not support HE-AAC
            mediaStreamDescriptions.Add(audioStreamDescription);
#endif

            mediaStreamDescriptions.Add(videoStreamDescription);

            this.AudioBufferLength = 500;
            this.ReportOpenMediaCompleted(mediaSourceAttributes, mediaStreamDescriptions);
        }
Beispiel #2
0
        protected override void OpenMediaAsync()
        {
            //WaveFormatEx
            HeAacWaveFormat aacf = new HeAacWaveFormat();
            WaveFormatExtensible wfx = new WaveFormatExtensible();
            aacf.WaveFormatExtensible = wfx;

            aacf.WaveFormatExtensible.FormatTag = 0x1610; //0xFF;//0x1610;
            aacf.WaveFormatExtensible.Channels = 2; //
            aacf.WaveFormatExtensible.BlockAlign = 1;
            aacf.WaveFormatExtensible.BitsPerSample = 0;//16; //unkonw set to 0
            aacf.WaveFormatExtensible.SamplesPerSec = 24000; //  from 8000 to 96000 Hz
            aacf.WaveFormatExtensible.AverageBytesPerSecond = 0;//wfx.SamplesPerSec * wfx.Channels * wfx.BitsPerSample / wfx.BlockAlign;
            aacf.WaveFormatExtensible.Size = 12;

            // Extra 3 words in WAVEFORMATEX
            // refer to http://msdn.microsoft.com/en-us/library/windows/desktop/dd757806(v=vs.85).aspx
            aacf.wPayloadType = 0x0; //Audio Data Transport Stream (ADTS). The stream contains an adts_sequence, as defined by MPEG-2.
            aacf.wAudioProfileLevelIndication = 0xFE;
            aacf.wStructType = 0;

            string codecPrivateData = aacf.ToHexString();

            Dictionary<MediaStreamAttributeKeys, string> audioStreamAttributes = new Dictionary<MediaStreamAttributeKeys, string>();
            audioStreamAttributes[MediaStreamAttributeKeys.CodecPrivateData] = codecPrivateData;
            audioStreamDescription = new MediaStreamDescription(MediaStreamType.Audio, audioStreamAttributes);

            m_vbuffer.WaitForWorkItem();

            m_curVideoBlk = m_vbuffer.Dequeue().CommandParameter as MSF.VideoBlock;

            if (m_curVideoBlk == null)
                return;
            vIdx = 0;
            fNum = (int)m_curVideoBlk.VideoFrameNum;

            H264NalFormat h264f = new H264NalFormat();
            h264f.sps = m_curVideoBlk.FirstIFrameInfo.sps;
            h264f.pps = m_curVideoBlk.FirstIFrameInfo.pps;
            string s = h264f.ToHexString();

            //Video
            Dictionary<MediaStreamAttributeKeys, string> videoStreamAttributes = new Dictionary<MediaStreamAttributeKeys, string>();
            videoStreamAttributes[MediaStreamAttributeKeys.VideoFourCC] = "H264";
            videoStreamAttributes[MediaStreamAttributeKeys.Height] = "240";
            videoStreamAttributes[MediaStreamAttributeKeys.Width] = "320";
            videoStreamAttributes[MediaStreamAttributeKeys.CodecPrivateData] = s;//"0000016742E00D96520283F40500000168CE388000";
            videoStreamDescription = new MediaStreamDescription(MediaStreamType.Video, videoStreamAttributes);

            //Media
            Dictionary<MediaSourceAttributesKeys, string> mediaSourceAttributes = new Dictionary<MediaSourceAttributesKeys, string>();
            mediaSourceAttributes[MediaSourceAttributesKeys.Duration] = TimeSpan.FromSeconds(6).Ticks.ToString(CultureInfo.InvariantCulture);
            mediaSourceAttributes[MediaSourceAttributesKeys.CanSeek] = "0";

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

            #if !DEBUG
            // Emulator does not support HE-AAC
               mediaStreamDescriptions.Add(audioStreamDescription);
            #endif

            mediaStreamDescriptions.Add(videoStreamDescription);

            this.AudioBufferLength = 500;
            this.ReportOpenMediaCompleted(mediaSourceAttributes, mediaStreamDescriptions);
        }