protected override HRESULT LoadTracks()
        {
            uint size      = 0;
            int  trackSize = _cdrom.ReadTrack(_track, null, ref size, null);

            if (size > 0)
            {
                WaveFormatEx wfex = WaveFormatEx.Cdda;
                AMMediaType  mt   = new AMMediaType();

                mt.majorType        = MediaType.Audio;
                mt.subType          = MediaSubType.PCM;
                mt.sampleSize       = wfex.nBlockAlign;
                mt.fixedSizeSamples = true;
                mt.SetFormat(wfex);
                m_Tracks.Add(new CdTrack(this, mt));

                m_llDataOffset = 0;
                m_rtDuration   = (UNITS * (size - m_llDataOffset)) / wfex.nAvgBytesPerSec;

                return(S_OK);
            }

            _buffer = new byte[size];

            return(S_FALSE);
        }
        //Can't get this to work!!
        AMMediaType getAlacMediaType()
        {
            byte[] extraInfo = new byte[] { 0x00, 0x00, 0x00, 0x24, 0x61, 0x6C, 0x61, 0x63, 0x00, 0x00, 0x00, 0x00,
                                            0x00, 0x00, 0x01, 0x60, 0x00, 0x10, 0x28, 0x0E, 0x0A, 0x02, 0x00, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xAC, 0x44 };

            WaveFormatEx w = new WaveFormatEx();

            w.wBitsPerSample  = 16;
            w.cbSize          = (ushort)extraInfo.Length;
            w.nChannels       = 2;
            w.nSamplesPerSec  = 44100;
            w.wFormatTag      = 27745;
            w.nAvgBytesPerSec = 87765;
            w.nBlockAlign     = 4;

            AMMediaType amt = new AMMediaType();

            amt.majorType  = MediaType.Audio;
            amt.subType    = new Guid("63616C61-0000-0010-8000-00AA00389B71"); //ALAC
            amt.formatType = FormatType.WaveEx;
            amt.SetFormat(w);
            amt.AddFormatExtraData(extraInfo);
            amt.fixedSizeSamples = true;
            amt.sampleSize       = 4;
            return(amt);
        }
Esempio n. 3
0
        /// <summary>
        /// Gets the type of the media.
        /// </summary>
        /// <param name="pMediaType">Type of the p media.</param>
        /// <returns></returns>
        public override int GetMediaType(ref AMMediaType pMediaType)
        {
            pMediaType.majorType  = MediaType.Video;
            pMediaType.subType    = MediaSubType.RGB32;
            pMediaType.formatType = FormatType.VideoInfo;

            VideoInfoHeader vih = new VideoInfoHeader();

            vih.AvgTimePerFrame       = m_nAvgTimePerFrame;
            vih.BmiHeader             = new BitmapInfoHeader();
            vih.BmiHeader.Size        = Marshal.SizeOf(typeof(BitmapInfoHeader));
            vih.BmiHeader.Compression = 0;
            vih.BmiHeader.BitCount    = 32;
            vih.BmiHeader.Width       = m_nWidth;
            vih.BmiHeader.Height      = m_nHeight;
            vih.BmiHeader.Planes      = 1;
            vih.BmiHeader.ImageSize   = vih.BmiHeader.Width * vih.BmiHeader.Height * vih.BmiHeader.BitCount / 8;
            vih.SrcRect    = new DsRect();
            vih.TargetRect = new DsRect();

            AMMediaType.SetFormat(ref pMediaType, ref vih);
            pMediaType.fixedSizeSamples = true;
            pMediaType.sampleSize       = vih.BmiHeader.ImageSize;

            return(NOERROR);
        }
        protected override HRESULT LoadTracks()
        {
            string contentType = _stream.ContentType;

            Logger.LogTrace("ShoutCast::LoadTracks contentType={0}", contentType);

            AMMediaType mt = new AMMediaType();

            switch (contentType)
            {
            case "audio/mpg":
            case "audio/mpeg":
            {
                BaseClasses.Mp3WaveFormat wfex = new BaseClasses.Mp3WaveFormat();
                wfex.cbSize   = 12;       // MPEGLAYER3_WFX_EXTRA_BYTES
                wfex.fdwFlags = 0;        // MPEGLAYER3_FLAG_PADDING_ISO

                wfex.nAvgBytesPerSec = (_stream.Bitrate * 1024 / 8);

                wfex.nBlockAlign     = 1;   // must be 1 for streamed MP3
                wfex.nBlockSize      = 522; // MP3_BLOCK_SIZE magic number
                wfex.nChannels       = 2;   // Stereo
                wfex.nCodecDelay     = 0;   // must be 0
                wfex.nFramesPerBlock = 1;   // must be 1

                wfex.nSamplesPerSec = _stream.SampleRate;

                wfex.wBitsPerSample = 0;      // must be 0
                wfex.wFormatTag     = 0x0055; // WAVE_FORMAT_MPEGLAYER3
                wfex.wID            = 1;      // MPEGLAYER3_ID_MPEG

                mt.majorType        = MediaType.Audio;
                mt.subType          = MediaSubType.MPEG1Audio;
                mt.sampleSize       = 0;
                mt.fixedSizeSamples = false;
                mt.SetFormat(wfex);
            }
            break;

                //case "audio/aac":
                //case "audio/aacp":
                //    {
                //        WaveFormatEx wfex = WaveFormatEx.Cdda;

                //        mt.majorType = MediaType.Audio;
                //        mt.subType = MediaSubType.PCM;
                //        mt.sampleSize = wfex.nBlockAlign;
                //        mt.fixedSizeSamples = true;
                //        mt.SetFormat(wfex);
                //    }
                //    break;
            }

            m_Tracks.Add(new ShoutcastStreamTrack(this, mt));

            return(S_OK);
        }
        public static AMMediaType E_AC3(InputstreamInfo streamInfo)
        {
            WaveFormatEx wf = new WaveFormatEx();

            wf.wFormatTag     = 8192;
            wf.nBlockAlign    = 24;
            wf.wBitsPerSample = 32;
            wf.cbSize         = 0;

            AMMediaType amt = new AMMediaType();

            AssignStreamInfoFields(streamInfo, ref wf, ref amt);
            amt.majorType           = MediaType.Audio;
            amt.subType             = MEDIASUBTYPE_DOLBY_DDPLUS;
            amt.temporalCompression = false;
            amt.fixedSizeSamples    = true;
            amt.SetFormat(wf);
            return(amt);
        }
        public static AMMediaType AAC_LC(InputstreamInfo streamInfo)
        {
            WaveFormatEx wf = new WaveFormatEx();

            wf.wFormatTag     = 255;
            wf.nBlockAlign    = 1;
            wf.wBitsPerSample = 16;
            wf.cbSize         = 0;

            AMMediaType amt = new AMMediaType();

            AssignStreamInfoFields(streamInfo, ref wf, ref amt);
            amt.majorType           = MediaType.Audio;
            amt.subType             = MEDIASUBTYPE_ADTS; // Works better than RAW_AAC1 (tested with Amazon Prime and 7TV)
            amt.temporalCompression = false;
            amt.fixedSizeSamples    = true;
            amt.SetFormat(wf);
            return(amt);
        }
        /// <summary>
        /// AnnexB formatted h264 bitstream
        /// </summary>
        /// <param name="streamInfo"></param>
        /// <returns></returns>
        public static AMMediaType H264_AnnexB(InputstreamInfo streamInfo)
        {
            int width  = (int)streamInfo.Width;
            int height = (int)streamInfo.Height;

            if (streamInfo.ExtraData.Length > 0)
            {
                var codecData = new H264CodecData(streamInfo.ExtraData);

                SPSUnit spsUnit = new SPSUnit(codecData.SPS);
                width  = spsUnit.Width();
                height = spsUnit.Height();
            }

            VideoInfoHeader2 vi = new VideoInfoHeader2();

            vi.SrcRect.right     = width;
            vi.SrcRect.bottom    = height;
            vi.TargetRect.right  = width;
            vi.TargetRect.bottom = height;

            int hcf = HCF(width, height);

            vi.PictAspectRatioX = width / hcf;
            vi.PictAspectRatioY = height / hcf;

            vi.BmiHeader.Width       = width;
            vi.BmiHeader.Height      = height;
            vi.BmiHeader.Planes      = 1;
            vi.BmiHeader.Compression = FOURCC_H264;

            AMMediaType amt = new AMMediaType();

            amt.majorType           = MediaType.Video;
            amt.subType             = MediaSubType.H264;
            amt.temporalCompression = true;
            amt.fixedSizeSamples    = false;
            amt.sampleSize          = 1;
            amt.SetFormat(vi);
            return(amt);
        }
        /// <summary>
        /// Sets AMMediaType format data with Mpeg2VideoInfo and optional extra data.
        /// </summary>
        /// <param name="vi"></param>
        /// <param name="extraData"></param>
        /// <param name="amt"></param>
        static void SetFormat(Mpeg2VideoInfo vi, byte[] extraData, AMMediaType amt)
        {
            int    cb  = Marshal.SizeOf(vi);
            int    add = extraData == null || extraData.Length < 4 ? 0 : extraData.Length - 4;
            IntPtr ptr = Marshal.AllocCoTaskMem(cb + add);

            try
            {
                Marshal.StructureToPtr(vi, ptr, false);
                if (extraData != null)
                {
                    Marshal.Copy(extraData, 0, ptr + cb - 4, extraData.Length);
                }
                amt.SetFormat(ptr, cb + add);
                amt.formatType = FormatType.Mpeg2Video;
            }
            finally
            {
                Marshal.FreeCoTaskMem(ptr);
            }
        }
        AMMediaType getWaveMediaType(WaveStream stream)
        {
            WaveFormatEx w = new WaveFormatEx();

            w.wBitsPerSample = (ushort)stream.Header.BitsPerSample;
            w.cbSize         = 0;
            w.nChannels      = (ushort)stream.Header.Channels;
            w.nSamplesPerSec = stream.Header.SampleRate;
            w.wFormatTag     = 1;
            int bytesPerSample = stream.Header.Channels * (stream.Header.BitsPerSample / 8);

            w.nAvgBytesPerSec = w.nSamplesPerSec * bytesPerSample;
            w.nBlockAlign     = (ushort)bytesPerSample;

            AMMediaType amt = new AMMediaType();

            amt.majorType  = MediaType.Audio;
            amt.subType    = MediaSubType.PCM;
            amt.formatType = FormatType.WaveEx;
            amt.SetFormat(w);
            amt.fixedSizeSamples = true;
            amt.sampleSize       = 4;
            return(amt);
        }
Esempio n. 10
0
        public int GetMediaType(int iPosition, ref AMMediaType pMediaType)
        {
            if (iPosition < 0)
            {
                return(E_INVALIDARG);
            }
            VideoStreamConfigCaps _caps;

            GetDefaultCaps(0, out _caps);

            int nWidth  = 0;
            int nHeight = 0;

            if (iPosition == 0)
            {
                if (Pins.Count > 0 && Pins[0].CurrentMediaType.majorType == MediaType.Video)
                {
                    pMediaType.Set(Pins[0].CurrentMediaType);
                    return(NOERROR);
                }
                nWidth  = _caps.InputSize.Width;
                nHeight = _caps.InputSize.Height;
            }
            else
            {
                iPosition--;
                nWidth  = _caps.MinOutputSize.Width + _caps.OutputGranularityX * iPosition;
                nHeight = _caps.MinOutputSize.Height + _caps.OutputGranularityY * iPosition;
                if (nWidth > _caps.MaxOutputSize.Width || nHeight > _caps.MaxOutputSize.Height)
                {
                    return(VFW_S_NO_MORE_ITEMS);
                }
            }

            pMediaType.majorType  = DirectShow.MediaType.Video;
            pMediaType.formatType = DirectShow.FormatType.VideoInfo;

            VideoInfoHeader vih = new VideoInfoHeader();

            vih.AvgTimePerFrame       = m_nAvgTimePerFrame;
            vih.BmiHeader.Compression = BI_RGB;
            vih.BmiHeader.BitCount    = (short)m_nBitCount;
            vih.BmiHeader.Width       = nWidth;
            vih.BmiHeader.Height      = nHeight;
            vih.BmiHeader.Planes      = 1;
            vih.BmiHeader.ImageSize   = vih.BmiHeader.Width * Math.Abs(vih.BmiHeader.Height) * vih.BmiHeader.BitCount / 8;

            if (vih.BmiHeader.BitCount == 32)
            {
                pMediaType.subType = DirectShow.MediaSubType.RGB32;
            }
            if (vih.BmiHeader.BitCount == 24)
            {
                pMediaType.subType = DirectShow.MediaSubType.RGB24;
            }
            AMMediaType.SetFormat(ref pMediaType, ref vih);
            pMediaType.fixedSizeSamples = true;
            pMediaType.sampleSize       = vih.BmiHeader.ImageSize;

            return(NOERROR);
        }