Example #1
0
        /// <summary>
        /// Decodes an encoded frame.
        /// </summary>
        /// <param name="encodedFrame">The encoded frame.</param>
        /// <returns></returns>
        public override VideoBuffer Decode(byte[] encodedFrame)
        {
            if (_Decoder == null)
            {
                _Decoder = new CocoaVp8Decoder();
            }

            if (_Padep.SequenceNumberingViolated)
            {
                _Decoder.NeedsKeyFrame = true;
                return(null);
            }

            using (var pool = new NSAutoreleasePool())
            {
                GCHandle encodedFrameHandle = GCHandle.Alloc(encodedFrame, GCHandleType.Pinned);
                try
                {
                    IntPtr encodedFramePointer = encodedFrameHandle.AddrOfPinnedObject();

                    using (var encodedFrameData = NSData.FromBytesNoCopy(encodedFramePointer, (uint)encodedFrame.Length, false))
                    {
                        using (var buffer = new CocoaVp8Buffer())
                        {
                            if (_Decoder.DecodeFrame(encodedFrameData, buffer))
                            {
                                var planeYData = new byte[buffer.PlaneY.Length];
                                var planeUData = new byte[buffer.PlaneU.Length];
                                var planeVData = new byte[buffer.PlaneV.Length];
                                Marshal.Copy(buffer.PlaneY.Bytes, planeYData, 0, (int)buffer.PlaneY.Length);
                                Marshal.Copy(buffer.PlaneU.Bytes, planeUData, 0, (int)buffer.PlaneU.Length);
                                Marshal.Copy(buffer.PlaneV.Bytes, planeVData, 0, (int)buffer.PlaneV.Length);
                                return(new VideoBuffer(buffer.Width, buffer.Height, new[] {
                                    new VideoPlane(planeYData, buffer.StrideY),
                                    new VideoPlane(planeUData, buffer.StrideU),
                                    new VideoPlane(planeVData, buffer.StrideV)
                                }, VideoFormat.I420));
                            }
                            return(null);
                        }
                    }
                }
                finally
                {
                    encodedFrameHandle.Free();
                }
            }
        }
Example #2
0
        /// <summary>
        /// Destroys the codec.
        /// </summary>
        public override void Destroy()
        {
            if (_Encoder != null)
            {
                _Encoder.Destroy();
                _Encoder.Dispose();
                _Encoder = null;
            }

            if (_Decoder != null)
            {
                _Decoder.Destroy();
                _Decoder.Dispose();
                _Decoder = null;
            }
        }
        /// <summary>
        /// Destroys the codec.
        /// </summary>
        public override void Destroy()
        {
            if (_Encoder != null)
            {
                _Encoder.Destroy();
                _Encoder.Dispose();
                _Encoder = null;
            }

            if (_Decoder != null)
            {
                _Decoder.Destroy();
                _Decoder.Dispose();
                _Decoder = null;
            }
        }
        /// <summary>
        /// Decodes an encoded frame.
        /// </summary>
        /// <param name="encodedFrame">The encoded frame.</param>
        /// <returns></returns>
        public override VideoBuffer Decode(byte[] encodedFrame)
		{
			if (_Decoder == null)
			{
				_Decoder = new CocoaVp8Decoder();
			}

			if (_Padep.SequenceNumberingViolated)
			{
				_Decoder.NeedsKeyFrame = true;
				return null;
			}

			using (var pool = new NSAutoreleasePool())
			{
				GCHandle encodedFrameHandle = GCHandle.Alloc(encodedFrame, GCHandleType.Pinned);
				try
				{
					IntPtr encodedFramePointer = encodedFrameHandle.AddrOfPinnedObject();

					using (var encodedFrameData = NSData.FromBytesNoCopy(encodedFramePointer, (uint)encodedFrame.Length, false))
					{
						using (var buffer = new CocoaVp8Buffer())
						{
							if (_Decoder.DecodeFrame(encodedFrameData, buffer))
							{
								var planeYData = new byte[buffer.PlaneY.Length];
								var planeUData = new byte[buffer.PlaneU.Length];
								var planeVData = new byte[buffer.PlaneV.Length];
								Marshal.Copy(buffer.PlaneY.Bytes, planeYData, 0, (int)buffer.PlaneY.Length);
								Marshal.Copy(buffer.PlaneU.Bytes, planeUData, 0, (int)buffer.PlaneU.Length);
								Marshal.Copy(buffer.PlaneV.Bytes, planeVData, 0, (int)buffer.PlaneV.Length);
								return new VideoBuffer(buffer.Width, buffer.Height, new[] {
									new VideoPlane(planeYData, buffer.StrideY),
									new VideoPlane(planeUData, buffer.StrideU),
									new VideoPlane(planeVData, buffer.StrideV)
								}, VideoFormat.I420);
							}
							return null;
						}
					}
				}
				finally
				{
					encodedFrameHandle.Free();
				}
			}
		}