Example #1
0
        public Bitmap GetBitmapFromSample(INSSBuffer sample, Guid videoSubType, VideoInfoHeader outputVideoInfoHeader, VideoInfoHeader inputVideoInfoHeader)
        {
            IntPtr      sampleBuffer;
            PixelFormat pixelFormat = PixelFormat.DontCare;
            uint        length      = 0;

            sample.GetBufferAndLength(out sampleBuffer, out length);

            if (videoSubType == MediaSubTypes.WMMEDIASUBTYPE_RGB32)
            {
                pixelFormat = PixelFormat.Format32bppRgb;
            }
            else if (videoSubType == MediaSubTypes.WMMEDIASUBTYPE_RGB555)
            {
                pixelFormat = PixelFormat.Format16bppRgb555;
            }
            else if (videoSubType == MediaSubTypes.WMMEDIASUBTYPE_RGB24)
            {
                pixelFormat = PixelFormat.Format24bppRgb;
            }
            else
            {
                throw new ArgumentException("videoSubType", "Unsupported video subtype [" + videoSubType + "].");
            }

#if DEBUG && DEBUG_SAMPLES
            Logger.WriteLogMessage("Grabbed sample buffer, length [" + length + "], pixelFormat [" + pixelFormat + "].");
#endif

            uint stride = outputVideoInfoHeader.bmiHeader.biWidth * outputVideoInfoHeader.bmiHeader.biPlanes * outputVideoInfoHeader.bmiHeader.biBitCount / 8;

#if DEBUG && DEBUG_SAMPLES
            Logger.WriteLogMessage("Creating bitmap [" + outputVideoInfoHeader.bmiHeader.biWidth + "x" + outputVideoInfoHeader.bmiHeader.biHeight + "], stride [" + stride + "], pixelFormat [" + pixelFormat + "].");
#endif

            Bitmap outputBitmap = new Bitmap((int)outputVideoInfoHeader.bmiHeader.biWidth, (int)outputVideoInfoHeader.bmiHeader.biHeight, (int)stride, pixelFormat, sampleBuffer);
            Bitmap inputBitmap  = new Bitmap((int)inputVideoInfoHeader.bmiHeader.biWidth, (int)inputVideoInfoHeader.bmiHeader.biHeight, outputBitmap.PixelFormat);

            using (Graphics g = Graphics.FromImage(inputBitmap))
            {
                g.InterpolationMode  = InterpolationMode.HighQualityBicubic;
                g.CompositingQuality = CompositingQuality.HighQuality;

                g.SmoothingMode   = SmoothingMode.HighQuality;
                g.PixelOffsetMode = PixelOffsetMode.HighQuality;

                g.DrawImage(outputBitmap, 0, 0, inputBitmap.Width, inputBitmap.Height);

#if DEBUG && DEBUG_SAMPLES
                Logger.WriteLogMessage("Copied output bitmap [" + outputBitmap.Width + "x" + outputBitmap.Height + "] to input bitmap [" + inputBitmap.Width + "x" + inputBitmap.Height + "].");
#endif
            }

            //
            // make bitmap was screen-oriented
            //
            inputBitmap.RotateFlip(RotateFlipType.RotateNoneFlipY);

            return(inputBitmap);
        }
Example #2
0
 public void Reset(INSSBuffer buff)
 {
     ReleaseBuffer();
     _position = 0;
     _buffer   = buff;
     _buffer.GetBufferAndLength(out _bufferPtr, out _length);
     _buffer.GetMaxLength(out _maxLength);
 }
        /// <summary>
        /// NSSBuffer constructor
        /// </summary>
        /// <param name="buff">INSSBuffer to wrap</param>
        public NSSBuffer(INSSBuffer buff)

        {
            m_Buffer = buff;

            m_Buffer.GetBufferAndLength(out m_BufferPtr, out m_Length);

            m_Buffer.GetMaxLength(out m_MaxLength);
        }
Example #4
0
    /// <summary>
    /// NSSBuffer constructor
    /// </summary>
    /// <param name="buff">INSSBuffer to wrap</param>
    public NSSBuffer(INSSBuffer buff)

    {
      m_Buffer = buff;

      m_Buffer.GetBufferAndLength(out m_BufferPtr, out m_Length);

      m_Buffer.GetMaxLength(out m_MaxLength);
    }
Example #5
0
		public NSSBuffer(INSSBuffer buff)
		{
			if (buff == null)
				throw new ArgumentNullException("buff", "Invalid INSSBuffer parameter.");

			_buffer = buff;

			_buffer.GetBufferAndLength(out _bufferPtr, out _length);
			_buffer.GetMaxLength(out _maxLength);
		}
Example #6
0
        public NSSBuffer(INSSBuffer buff)
        {
            if (buff == null)
            {
                throw new ArgumentNullException("buff", "Invalid INSSBuffer parameter.");
            }

            _buffer = buff;

            _buffer.GetBufferAndLength(out _bufferPtr, out _length);
            _buffer.GetMaxLength(out _maxLength);
        }
        private void ExtractSampleData(INSSBuffer buffer, long duration)
        {
            IntPtr source;
            int    dataLength;

            buffer.GetBufferAndLength(out source, out dataLength);
            var array = new byte[dataLength];

            Marshal.Copy(source, array, 0, dataLength);
            SaveBytesToLastData(array);
            timeToNextImage += duration / 100000f;
        }
Example #8
0
        private void TestBuffer()
        {
            IntPtr ip, ip2;
            int    l;

            m_pSample.GetBuffer(out ip);
            Debug.Assert(ip != IntPtr.Zero);

            m_pSample.GetBufferAndLength(out ip2, out l);

            Debug.Assert(ip == ip2);
            Debug.Assert(l == 12);
        }
Example #9
0
        public Bitmap GetBitmapFromSample(INSSBuffer sample, Guid videoSubType, VideoInfoHeader outputVideoInfoHeader, VideoInfoHeader inputVideoInfoHeader)
        {
            IntPtr sampleBuffer;
        	PixelFormat pixelFormat = PixelFormat.DontCare;
            uint length = 0;

            sample.GetBufferAndLength(out sampleBuffer, out length);

            if (videoSubType == MediaSubTypes.WMMEDIASUBTYPE_RGB32)
            {
                pixelFormat = PixelFormat.Format32bppRgb;
            }
            else if (videoSubType == MediaSubTypes.WMMEDIASUBTYPE_RGB555)
            {
                pixelFormat = PixelFormat.Format16bppRgb555;
            }
            else if (videoSubType == MediaSubTypes.WMMEDIASUBTYPE_RGB24)
            {
                pixelFormat = PixelFormat.Format24bppRgb;
            }
            else
            {
                throw new ArgumentException("videoSubType", "Unsupported video subtype [" + videoSubType + "].");
            }

#if DEBUG && DEBUG_SAMPLES
            Logger.WriteLogMessage("Grabbed sample buffer, length [" + length + "], pixelFormat [" + pixelFormat + "].");
#endif

            uint stride = outputVideoInfoHeader.bmiHeader.biWidth * outputVideoInfoHeader.bmiHeader.biPlanes * outputVideoInfoHeader.bmiHeader.biBitCount / 8;

#if DEBUG && DEBUG_SAMPLES
            Logger.WriteLogMessage("Creating bitmap [" + outputVideoInfoHeader.bmiHeader.biWidth + "x" + outputVideoInfoHeader.bmiHeader.biHeight + "], stride [" + stride + "], pixelFormat [" + pixelFormat + "].");
#endif

            Bitmap outputBitmap = new Bitmap((int)outputVideoInfoHeader.bmiHeader.biWidth, (int)outputVideoInfoHeader.bmiHeader.biHeight, (int)stride, pixelFormat, sampleBuffer);
            Bitmap inputBitmap = new Bitmap((int)inputVideoInfoHeader.bmiHeader.biWidth, (int)inputVideoInfoHeader.bmiHeader.biHeight, outputBitmap.PixelFormat);

            using (Graphics g = Graphics.FromImage(inputBitmap))
            {
                g.InterpolationMode = InterpolationMode.HighQualityBicubic;
                g.CompositingQuality = CompositingQuality.HighQuality;

                g.SmoothingMode = SmoothingMode.HighQuality;
                g.PixelOffsetMode = PixelOffsetMode.HighQuality;

                g.DrawImage(outputBitmap, 0, 0, inputBitmap.Width, inputBitmap.Height);

#if DEBUG && DEBUG_SAMPLES
                Logger.WriteLogMessage("Copied output bitmap [" + outputBitmap.Width + "x" + outputBitmap.Height + "] to input bitmap [" + inputBitmap.Width + "x" + inputBitmap.Height + "].");
#endif
            }

            //
            // make bitmap was screen-oriented
            // 
            inputBitmap.RotateFlip(RotateFlipType.RotateNoneFlipY);

            return inputBitmap;
        }
Example #10
0
        public INSSBuffer GetSampleFromBitmap(Bitmap bitmap)
        {
            INSSBuffer sample = null;
            IntPtr     sampleBuffer;
            uint       length = 0;

#if DEBUG && DEBUG_SAMPLES
            Logger.WriteLogMessage("Grabbing sample from bitmap.");
#endif

            BitmapData bitmapData   = null;
            uint       actualLength = 0;

            try
            {
                //
                // assume incoming bitmap was screen-oriented
                //
                bitmap.RotateFlip(RotateFlipType.RotateNoneFlipY);

                Rectangle rect = new Rectangle(0, 0, bitmap.Width, bitmap.Height);

                bitmapData = bitmap.LockBits(rect, ImageLockMode.ReadOnly, bitmap.PixelFormat);

                length = (uint)(bitmapData.Height * bitmapData.Stride);

#if DEBUG && DEBUG_SAMPLES
                Logger.WriteLogMessage("Locked bits on bitmap, rect [" + rect + "], length [" + length + "], width [" + bitmapData.Width + "], height [" + bitmapData.Height + "], stride [" + bitmapData.Stride + "], pixelFormat [" + bitmap.PixelFormat + "].");
#endif

#if DEBUG_BITMAP_IMAGE
                //       SaveBitmapAsImage(bitmap, bitmapData);
#endif

                //
                // allocate new sample and grab sample buffer
                //
                _writer.AllocateSample(length, out sample);

#if DEBUG && DEBUG_SAMPLES
                Logger.WriteLogMessage("Allocated sample, [" + length + "] bytes.");
#endif

                sample.GetBufferAndLength(out sampleBuffer, out actualLength);

#if DEBUG && DEBUG_SAMPLES
                Logger.WriteLogMessage("Grabbed buffer from sample, [" + actualLength + "] bytes.");
#endif

                Helpers.CopyMemory(sampleBuffer, bitmapData.Scan0, length);

#if DEBUG && DEBUG_SAMPLES
                Logger.WriteLogMessage("Copied [" + length + "] bytes from bitmap to sample buffer.");
#endif
            }
            catch (Exception)
            {
                // error handle
                throw;
                //Logger.WriteLogError("Failed converting bitmap to sample.", e);
            }
            finally
            {
                if (bitmapData != null)
                {
                    bitmap.UnlockBits(bitmapData);

#if DEBUG && DEBUG_SAMPLES
                    Logger.WriteLogMessage("Unlocked bits on bitmap.");
#endif
                }
            }

            return(sample);
        }
Example #11
0
 static string GetStringFromNSSBuffer( INSSBuffer NsBuffer)
 {
     Debug.WriteLine("CacheProxyPlugin::GetStringFromNSSBuffer entered");
     uint bufSize;
     IntPtr pBuf = IntPtr.Zero;
     NsBuffer.GetBufferAndLength(  pBuf, out bufSize );
     byte[] Buf = new byte[bufSize];
     Marshal.Copy(pBuf,Buf,0,(int)bufSize);
     /*
     string s = Marshal.PtrToStringUni( pBuf, (int) bufSize / 2 );
     return s;
     */
     return Convert.ToBase64String(Buf,0,(int)bufSize);
 }
Example #12
0
        //------------------------------------------------------------------------------
        // Name: CWMVCopy::OnStreamSample()
        // Desc: Implementation of IWMReaderCallbackAdvanced::OnStreamSample.
        //------------------------------------------------------------------------------
        public void OnStreamSample(
            short wStreamNum,
            long cnsSampleTime,
            long cnsSampleDuration,
            SampleFlag dwFlags,
            INSSBuffer pSample,
            IntPtr pvContext)
        {
            bool fMoveScript = false;

            while (m_dwProgress <= cnsSampleTime * 50 / m_qwDuration)
            {
                m_dwProgress++;
                Console.Write("*");
            }

            if (m_qwMaxDuration > 0 && cnsSampleTime > m_qwMaxDuration)
            {
                m_hEvent.Set();
                return;
            }

            if (m_fMoveScriptStream)
            {
                //
                // We may have multiple script streams in this file.
                //
                for (int i = 0; i < m_dwStreamCount; i++)
                {
                    if (m_pwStreamNumber[i] == wStreamNum)
                    {
                        if (MediaType.ScriptCommand == m_pguidStreamType[i])
                        {
                            fMoveScript = true;
                        }

                        break;
                    }
                }
            }

            try
            {
                if (fMoveScript)
                {
                    int           dwBufferLength;
                    int           nStringLength;
                    IntPtr        pwszTypeIP  = IntPtr.Zero;
                    StringBuilder pwszType    = null;
                    StringBuilder pwszCommand = null;

                    //
                    // Read the buffer and length of the script stream sample
                    //
                    pSample.GetBufferAndLength(out pwszTypeIP, out dwBufferLength);
                    pwszType = new StringBuilder(Marshal.PtrToStringUni(pwszTypeIP)); //todo - this won't work if the string doesn't have a final \0

                    nStringLength = dwBufferLength / 2;
                    if (nStringLength > 0)
                    {
                        //
                        // Get the command string of this script
                        //

                        // Todo - maybe the format of pwszTypeIP is Type\0Command\0 ???

#if false
                        pwszCommand = wcschr(pwszType, null);
                        if (pwszCommand - pwszType < nStringLength - 1)
                        {
                            pwszCommand++;
                        }
                        else
                        {
                            pwszCommand = " ";
                        }
#else
                        pwszCommand = new StringBuilder(" ");
#endif

                        //
                        // Add the script to the script list. We cannot write scripts
                        // directly to the writer after writing has begun.
                        //
                        m_ScriptList.Add(new CScript(pwszType.ToString(), pwszCommand.ToString(), cnsSampleTime));
                    }
                }
                else
                {
                    m_pWriterAdvanced.WriteStreamSample(wStreamNum,
                                                        cnsSampleTime,
                                                        0,
                                                        cnsSampleDuration,
                                                        dwFlags,
                                                        pSample);
                }
            }
            catch (Exception e)
            {
                int hr = Marshal.GetHRForException(e);
                m_hr = hr;
                m_hEvent.Set();
            }
            finally
            {
                Marshal.ReleaseComObject(pSample);
            }
        }
Example #13
0
 public void Reset(INSSBuffer buff)
 {
     ReleaseBuffer();
     _position = 0;
     _buffer = buff;
     _buffer.GetBufferAndLength(out _bufferPtr, out _length);
     _buffer.GetMaxLength(out _maxLength);
 }
Example #14
0
		private void ExtractSampleData(INSSBuffer buffer, long duration)
		{
			IntPtr source;
			int dataLength;
			buffer.GetBufferAndLength(out source, out dataLength);
			var array = new byte[dataLength];
			Marshal.Copy(source, array, 0, dataLength);
			SaveBytesToLastData(array);
			timeToNextImage += duration / 100000f;
		}