Пример #1
0
        public int GetAllocatorProperties(AllocatorProperties pprop)
        {
            AMMediaType mt = Pins[0].CurrentMediaType;

            if (mt.majorType == MediaType.Video)
            {
                int lSize             = mt.sampleSize;
                BitmapInfoHeader _bmi = mt;
                if (_bmi != null)
                {
                    if (lSize < _bmi.GetBitmapSize())
                    {
                        lSize = _bmi.GetBitmapSize();
                    }
                    if (lSize < _bmi.ImageSize)
                    {
                        lSize = _bmi.ImageSize;
                    }
                }
                pprop.cbBuffer = lSize;
                pprop.cBuffers = 1;
                pprop.cbAlign  = 1;
                pprop.cbPrefix = 0;
            }
            return(NOERROR);
        }
Пример #2
0
        public int GetAllocatorProperties(AllocatorProperties pprop)
        {
#if HAMED_LOG_METHOD_INFO
            MethodBase method = new StackTrace().GetFrame(0).GetMethod();
            Console.WriteLine(this.GetType().FullName + " - " + method.Name + " - " + method.ToString());
#endif

            AMMediaType mt = Pins[0].CurrentMediaType;
            if (mt.majorType == MediaType.Video)
            {
                int lSize             = mt.sampleSize;
                BitmapInfoHeader _bmi = mt;
                if (_bmi != null)
                {
                    if (lSize < _bmi.GetBitmapSize())
                    {
                        lSize = _bmi.GetBitmapSize();
                    }
                    if (lSize < _bmi.ImageSize)
                    {
                        lSize = _bmi.ImageSize;
                    }
                }
                pprop.cbBuffer = lSize;
                pprop.cBuffers = 1;
                pprop.cbAlign  = 1;
                pprop.cbPrefix = 0;
            }
            return(NOERROR);
        }
Пример #3
0
        public override int DecideBufferSize(ref IMemAllocatorImpl pAlloc, ref AllocatorProperties prop)
        {
            Console.WriteLine("DecideBufferSize");

            if (!Output.IsConnected)
            {
                return(VFW_E_NOT_CONNECTED);
            }
            if (Output.CurrentMediaType.majorType != MediaType.Video)
            {
                return(VFW_E_INVALIDMEDIATYPE);
            }
            AllocatorProperties _actual = new AllocatorProperties();
            BitmapInfoHeader    _bmi    = (BitmapInfoHeader)Output.CurrentMediaType;

            if (_bmi == null)
            {
                return(VFW_E_INVALIDMEDIATYPE);
            }
            prop.cbBuffer = _bmi.GetBitmapSize();
            if (prop.cbBuffer < _bmi.ImageSize)
            {
                prop.cbBuffer = _bmi.ImageSize;
            }
            prop.cBuffers = 1;
            int hr = pAlloc.SetProperties(prop, _actual);

            return(hr);
        }
Пример #4
0
        public int DecideBufferSize(ref IMemAllocatorImpl pAlloc, ref AllocatorProperties prop)
        {
#if HAMED_LOG_METHOD_INFO
            MethodBase method = new StackTrace().GetFrame(0).GetMethod();
            Console.WriteLine(this.GetType().FullName + " - " + method.Name + " - " + method.ToString());
#endif

            AllocatorProperties _actual = new AllocatorProperties();

            BitmapInfoHeader _bmi = (BitmapInfoHeader)Pins[0].CurrentMediaType;
            prop.cbBuffer = _bmi.GetBitmapSize();

            if (prop.cbBuffer < _bmi.ImageSize)
            {
                prop.cbBuffer = _bmi.ImageSize;
            }
            if (prop.cbBuffer < m_bmi.bmiHeader.ImageSize)
            {
                prop.cbBuffer = m_bmi.bmiHeader.ImageSize;
            }

            prop.cBuffers = 1;
            prop.cbAlign  = 1;
            prop.cbPrefix = 0;
            int hr = pAlloc.SetProperties(prop, _actual);
            return(hr);
        }
Пример #5
0
        /// <summary>
        /// Decides the size of the buffer.
        /// </summary>
        /// <param name="pAlloc">The p alloc.</param>
        /// <param name="prop">The property.</param>
        /// <returns></returns>
        public override int DecideBufferSize(ref IMemAllocatorImpl pAlloc, ref AllocatorProperties prop)
        {
            AllocatorProperties _actual = new AllocatorProperties();

            BitmapInfoHeader _bmi = CurrentMediaType;

            prop.cbBuffer = _bmi.GetBitmapSize();
            if (prop.cbBuffer < _bmi.ImageSize)
            {
                prop.cbBuffer = _bmi.ImageSize;
            }
            prop.cBuffers = 1;

            int hr = pAlloc.SetProperties(prop, _actual);

            return(hr);
        }
Пример #6
0
        public int DecideBufferSize(ref IMemAllocatorImpl pAlloc, ref AllocatorProperties prop)
        {
            AllocatorProperties _actual = new AllocatorProperties();

            BitmapInfoHeader _bmi = (BitmapInfoHeader)Pins[0].CurrentMediaType;

            prop.cbBuffer = _bmi.GetBitmapSize();

            if (prop.cbBuffer < _bmi.ImageSize)
            {
                prop.cbBuffer = _bmi.ImageSize;
            }
            if (prop.cbBuffer < m_bmi.bmiHeader.ImageSize)
            {
                prop.cbBuffer = m_bmi.bmiHeader.ImageSize;
            }

            prop.cBuffers = 1;
            prop.cbAlign  = 1;
            prop.cbPrefix = 0;
            int hr = pAlloc.SetProperties(prop, _actual);

            return(hr);
        }
Пример #7
0
        public override int Transform(ref IMediaSampleImpl _input, ref IMediaSampleImpl _sample)
        {
            Console.WriteLine("Transform " + DateTime.Now.Millisecond);

            DateTime starttime = DateTime.Now;

            int    lDataLength = _input.GetActualDataLength();
            IntPtr _ptrIn;
            IntPtr _ptrOut;

            BitmapInfoHeader _bmiIn  = (BitmapInfoHeader)Input.CurrentMediaType;
            BitmapInfoHeader _bmiOut = (BitmapInfoHeader)Output.CurrentMediaType;

            _sample.SetActualDataLength(_bmiOut.GetBitmapSize());

            Console.WriteLine("inlen " + lDataLength + " outlen" + (_bmiIn.Width * _bmiIn.Height * 3) + " " + DateTime.Now.Millisecond);

            _input.GetPointer(out _ptrIn);
            _sample.GetPointer(out _ptrOut);

            Bitmap _bmpOut = converttobitmap(_ptrIn, _ptrOut, lDataLength, _bmiIn.Height, _bmiIn.Width);

            Console.WriteLine("gotbitmap " + DateTime.Now.Millisecond);

            datain += _bmiIn.Height * _bmiIn.Width * 3;
            frames++;
            // Application.DoEvents();

            secondstaken1 += (DateTime.Now - starttime).TotalSeconds;

            long start, end;

            _input.GetTime(out start, out end);

            {
                //_bmpIn.RotateFlip(RotateFlipType.RotateNoneFlipY);
                Graphics _graphics = Graphics.FromImage(_bmpOut);

                _graphics.SmoothingMode     = System.Drawing.Drawing2D.SmoothingMode.HighSpeed;
                _graphics.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.Low;

                secondstaken2 += (DateTime.Now - starttime).TotalSeconds;

                try
                {
                    double videotime = (start / 10000000.0);

                    DateTime temp = vid.videopos;

                    vid.videopos = temp.AddSeconds(videotime);

                    Bitmap img;

                    // 10 hz
                    if (videotime > (lasthudtime + 0.1))
                    {
                        // get hud
                        img          = vid.gethud(_bmpOut, videotime);
                        lasthudcache = (Bitmap)img.Clone();

                        lasthudtime = videotime;
                        hudframes++;
                    }
                    else
                    {
                        img = (Bitmap)lasthudcache.Clone();
                    }

                    secondstaken3 += (DateTime.Now - starttime).TotalSeconds;

                    //_graphics.DrawImage(_bmpOut, 0, 0);

                    img.RotateFlip(RotateFlipType.RotateNoneFlipY);

                    //img.MakeTransparent();
                    secondstaken4 += (DateTime.Now - starttime).TotalSeconds;

                    _graphics.DrawImage(img, 0, 0, _bmpOut.Width, _bmpOut.Height);

                    secondstaken5 += (DateTime.Now - starttime).TotalSeconds;

                    img.Dispose();
                }
                catch (Exception ex) { Console.WriteLine(ex.ToString()); }

                _graphics.Dispose();
                //  _bmpIn.RotateFlip(RotateFlipType.RotateNoneFlipY);
            }
            secondstaken6 += (DateTime.Now - starttime).TotalSeconds;


            dataout += _bmpOut.Height * _bmpOut.Width * 3;

            _bmpOut.Dispose();

            secondstaken += (DateTime.Now - starttime).TotalSeconds;

            if (time.Second != DateTime.Now.Second)
            {
                vid.textbox = string.Format(
                    @"input: {0}
output: {1}
frames: {2}
hudframes: {3}
pos: {4}
start: {5}
end: {6}
seconds {7}
seconds1 {8}
seconds2 {9}
seconds3 {10}
seconds4 {11}
seconds5 {12}
seconds6 {13}", datain, dataout, frames, hudframes, vid.videopos, start / 10000000.0, end / 10000000.0, secondstaken, secondstaken1, secondstaken2, secondstaken3, secondstaken4, secondstaken5, secondstaken6);

                datain = dataout = frames = hudframes = 0;


                secondstaken = secondstaken1 = secondstaken2 = secondstaken3 = secondstaken4 = secondstaken5 = secondstaken6 = 0;
                time         = DateTime.Now;
            }

            Console.WriteLine("Transform Done " + DateTime.Now.Millisecond);

            return(S_OK);
        }