예제 #1
0
        public byte[] GetH264ParameterSet(nuint index, out nuint parameterSetCount, out int nalUnitHeaderLength, out CMFormatDescriptionError error)
        {
            if (Handle == IntPtr.Zero)
                throw new ObjectDisposedException ("VideoFormatDescription");

            IntPtr ret;
            nuint parameterSetSizeOut;
            error = CMVideoFormatDescriptionGetH264ParameterSetAtIndex (Handle, index, out ret, out parameterSetSizeOut, out parameterSetCount, out nalUnitHeaderLength);
            if (error != CMFormatDescriptionError.None)
                return null;

            var arr = new byte[(int)parameterSetSizeOut];
            Marshal.Copy (ret, arr, 0, (int)parameterSetSizeOut);

            return arr;
        }
예제 #2
0
        public static CMVideoFormatDescription CreateForImageBuffer(CVImageBuffer imageBuffer, out CMFormatDescriptionError error)
        {
            if (imageBuffer == null)
                throw new ArgumentNullException ("imageBuffer");

            IntPtr desc;
            error = CMVideoFormatDescriptionCreateForImageBuffer (IntPtr.Zero, imageBuffer.handle, out desc);
            if (error != CMFormatDescriptionError.None)
                return null;

            return new CMVideoFormatDescription (desc, true);
        }
예제 #3
0
        public static CMVideoFormatDescription FromH264ParameterSets(List<byte[]> parameterSets, int nalUnitHeaderLength, out CMFormatDescriptionError error)
        {
            if (parameterSets == null)
                throw new ArgumentNullException ("parameterSets");

            if (parameterSets.Count < 2)
                throw new ArgumentException ("parameterSets must contain at least two elements");

            if (nalUnitHeaderLength != 1 && nalUnitHeaderLength != 2 && nalUnitHeaderLength != 4)
                throw new ArgumentOutOfRangeException ("nalUnitHeaderLength", "must be 1, 2 or 4");

            var handles = new GCHandle [parameterSets.Count];
            try {
                var parameterSetSizes = new nuint [parameterSets.Count];
                var parameterSetPtrs = new IntPtr [parameterSets.Count];

                for (int i = 0; i < parameterSets.Count; i++) {
                    handles [i] = GCHandle.Alloc (parameterSets [i], GCHandleType.Pinned);
                    parameterSetPtrs [i] = handles [i].AddrOfPinnedObject ();
                    parameterSetSizes [i] = (nuint)parameterSets [i].Length;
                }

                IntPtr desc;
                error = CMVideoFormatDescriptionCreateFromH264ParameterSets (IntPtr.Zero, (nuint)parameterSets.Count, parameterSetPtrs, parameterSetSizes, nalUnitHeaderLength, out desc);
                if (error != CMFormatDescriptionError.None)
                    return null;

                return new CMVideoFormatDescription (desc, true);
            } finally {
                for (int i = 0; i < parameterSets.Count; i++) {
                    if (handles [i].IsAllocated)
                        handles [i].Free ();
                }
            }
        }
        public static CMVideoFormatDescription CreateForImageBuffer(CVImageBuffer imageBuffer, out CMFormatDescriptionError error)
        {
            if (imageBuffer == null)
            {
                throw new ArgumentNullException("imageBuffer");
            }

            IntPtr desc;

            error = CMVideoFormatDescriptionCreateForImageBuffer(IntPtr.Zero, imageBuffer.handle, out desc);
            if (error != CMFormatDescriptionError.None)
            {
                return(null);
            }

            return(new CMVideoFormatDescription(desc, true));
        }
예제 #5
0
        public static CMFormatDescription Create(CMMediaType mediaType, uint mediaSubtype, out CMFormatDescriptionError error)
        {
            IntPtr handle;
            error = CMFormatDescriptionCreate (IntPtr.Zero, mediaType, mediaSubtype, IntPtr.Zero, out handle);
            if (error != CMFormatDescriptionError.None)
                return null;

            return Create (mediaType, handle, true);
        }
        public static CMFormatDescription Create(CMMediaType mediaType, uint mediaSubtype, out CMFormatDescriptionError error)
        {
            IntPtr handle;

            error = CMFormatDescriptionCreate(IntPtr.Zero, mediaType, mediaSubtype, IntPtr.Zero, out handle);
            if (error != CMFormatDescriptionError.None)
            {
                return(null);
            }

            return(Create(mediaType, handle, true));
        }
예제 #7
0
        public byte [] GetHevcParameterSet(nuint index, out nuint parameterSetCount, out int nalUnitHeaderLength, out CMFormatDescriptionError error)
        {
            if (Handle == IntPtr.Zero)
            {
                throw new ObjectDisposedException("VideoFormatDescription");
            }

            IntPtr ret;
            nuint  parameterSetSizeOut;

            error = CMVideoFormatDescriptionGetHEVCParameterSetAtIndex(Handle, index, out ret, out parameterSetSizeOut, out parameterSetCount, out nalUnitHeaderLength);
            if (error != CMFormatDescriptionError.None)
            {
                return(null);
            }

            var arr = new byte [(int)parameterSetSizeOut];

            Marshal.Copy(ret, arr, 0, (int)parameterSetSizeOut);

            return(arr);
        }
예제 #8
0
        public static CMVideoFormatDescription FromHevcParameterSets(List <byte[]> parameterSets, int nalUnitHeaderLength, NSDictionary extensions, out CMFormatDescriptionError error)
        {
            if (parameterSets == null)
            {
                throw new ArgumentNullException(nameof(parameterSets));
            }

            if (parameterSets.Count < 3)
            {
                throw new ArgumentException($"{nameof (parameterSets)} must contain at least three elements");
            }

            if (nalUnitHeaderLength != 1 && nalUnitHeaderLength != 2 && nalUnitHeaderLength != 4)
            {
                throw new ArgumentOutOfRangeException(nameof(nalUnitHeaderLength), "must be 1, 2 or 4");
            }

            var handles = new GCHandle [parameterSets.Count];

            try {
                var parameterSetSizes = new nuint [parameterSets.Count];
                var parameterSetPtrs  = new IntPtr [parameterSets.Count];

                for (int i = 0; i < parameterSets.Count; i++)
                {
                    handles [i]           = GCHandle.Alloc(parameterSets [i], GCHandleType.Pinned);            // This can't use unsafe code because we need to get the pointer for an unbound number of objects.
                    parameterSetPtrs [i]  = handles [i].AddrOfPinnedObject();
                    parameterSetSizes [i] = (nuint)parameterSets [i].Length;
                }

                IntPtr desc;
                error = CMVideoFormatDescriptionCreateFromHEVCParameterSets(IntPtr.Zero, (nuint)parameterSets.Count, parameterSetPtrs, parameterSetSizes, nalUnitHeaderLength, extensions.GetHandle(), out desc);
                if (error != CMFormatDescriptionError.None || desc == IntPtr.Zero)
                {
                    return(null);
                }

                return(new CMVideoFormatDescription(desc, true));
            } finally {
                for (int i = 0; i < handles.Length; i++)
                {
                    if (handles [i].IsAllocated)
                    {
                        handles [i].Free();
                    }
                }
            }
        }
예제 #9
0
        public byte []? GetHevcParameterSet(nuint index, out nuint parameterSetCount, out int nalUnitHeaderLength, out CMFormatDescriptionError error)
        {
            IntPtr ret;
            nuint  parameterSetSizeOut;

            error = CMVideoFormatDescriptionGetHEVCParameterSetAtIndex(GetCheckedHandle(), index, out ret, out parameterSetSizeOut, out parameterSetCount, out nalUnitHeaderLength);
            if (error != CMFormatDescriptionError.None)
            {
                return(null);
            }

            var arr = new byte [(int)parameterSetSizeOut];

            Marshal.Copy(ret, arr, 0, (int)parameterSetSizeOut);

            return(arr);
        }
예제 #10
0
        public static CMVideoFormatDescription?CreateForImageBuffer(CVImageBuffer imageBuffer, out CMFormatDescriptionError error)
        {
            if (imageBuffer is null)
            {
                ObjCRuntime.ThrowHelper.ThrowArgumentNullException(nameof(imageBuffer));
            }

            IntPtr desc;

            error = CMVideoFormatDescriptionCreateForImageBuffer(IntPtr.Zero, imageBuffer.Handle, out desc);
            if (error != CMFormatDescriptionError.None)
            {
                return(null);
            }

            return(new CMVideoFormatDescription(desc, true));
        }