Пример #1
0
        public static CMBlockBuffer CreateContiguous(CMBlockBuffer sourceBuffer, CMCustomBlockAllocator customBlockSource, nuint offsetToData, nuint dataLength, CMBlockBufferFlags flags, out CMBlockBufferError error)
        {
            if (sourceBuffer == null)
            {
                throw new ArgumentNullException("sourceBuffer");
            }

            IntPtr buffer;

            if (customBlockSource == null)
            {
                error = CMBlockBufferCreateContiguous(IntPtr.Zero, sourceBuffer.handle, IntPtr.Zero, IntPtr.Zero, offsetToData, dataLength, flags, out buffer);
            }
            else
            {
                error = CMBlockBufferCreateContiguous(IntPtr.Zero, sourceBuffer.handle, IntPtr.Zero, ref customBlockSource.Cblock, offsetToData, dataLength, flags, out buffer);
            }

            if (error != CMBlockBufferError.None)
            {
                return(null);
            }

            var block = new CMBlockBuffer(buffer, true);

            block.customAllocator = customBlockSource;
            return(block);
        }
Пример #2
0
        public static CMSampleBuffer CreateReadyWithPacketDescriptions(CMBlockBuffer dataBuffer, CMFormatDescription formatDescription, int samplesCount,
                                                                       CMTime sampleTimestamp, AudioStreamPacketDescription[] packetDescriptions, out CMSampleBufferError error)
        {
            if (dataBuffer == null)
            {
                throw new ArgumentNullException("dataBuffer");
            }
            if (formatDescription == null)
            {
                throw new ArgumentNullException("formatDescription");
            }
            if (samplesCount <= 0)
            {
                throw new ArgumentOutOfRangeException("samplesCount");
            }

            IntPtr buffer;

            error = CMAudioSampleBufferCreateReadyWithPacketDescriptions(IntPtr.Zero, dataBuffer.handle,
                                                                         formatDescription.handle, samplesCount, sampleTimestamp, packetDescriptions, out buffer);

            if (error != CMSampleBufferError.None)
            {
                return(null);
            }

            return(new CMSampleBuffer(buffer, true));
        }
Пример #3
0
        public static CMBlockBuffer FromMemoryBlock(IntPtr memoryBlock, nuint blockLength, CMCustomBlockAllocator customBlockSource, nuint offsetToData, nuint dataLength, CMBlockBufferFlags flags, out CMBlockBufferError error)
        {
            var blockAllocator = memoryBlock == IntPtr.Zero ? IntPtr.Zero : CFAllocator.Null.Handle;

            IntPtr buffer;

            if (customBlockSource == null)
            {
                error = CMBlockBufferCreateWithMemoryBlock(IntPtr.Zero, memoryBlock, blockLength, blockAllocator, IntPtr.Zero, offsetToData, dataLength, flags, out buffer);
            }
            else
            {
                error = CMBlockBufferCreateWithMemoryBlock(IntPtr.Zero, memoryBlock, blockLength, blockAllocator, ref customBlockSource.Cblock, offsetToData, dataLength, flags, out buffer);
            }

            if (error != CMBlockBufferError.None)
            {
                return(null);
            }

            var block = new CMBlockBuffer(buffer, true);

            block.customAllocator = customBlockSource;
            return(block);
        }
Пример #4
0
        public static CMSampleBuffer CreateReady(CMBlockBuffer dataBuffer, CMFormatDescription formatDescription,
                                                 int samplesCount, CMSampleTimingInfo[] sampleTimingArray, nuint[] sampleSizeArray,
                                                 out CMSampleBufferError error)
        {
            if (dataBuffer == null)
            {
                throw new ArgumentNullException("dataBuffer");
            }
            if (samplesCount < 0)
            {
                throw new ArgumentOutOfRangeException("samplesCount");
            }

            IntPtr buffer;
            var    fdh         = formatDescription == null ? IntPtr.Zero : formatDescription.Handle;
            var    timingCount = sampleTimingArray == null ? 0 : sampleTimingArray.Length;
            var    sizeCount   = sampleSizeArray == null ? 0 : sampleSizeArray.Length;

            error = CMSampleBufferCreateReady(IntPtr.Zero, dataBuffer.handle, fdh, samplesCount, timingCount,
                                              sampleTimingArray, sizeCount, sampleSizeArray, out buffer);

            if (error != CMSampleBufferError.None)
            {
                return(null);
            }

            return(new CMSampleBuffer(buffer, true));
        }
Пример #5
0
        public static CMSampleBuffer?CreateReady(CMBlockBuffer dataBuffer, CMFormatDescription?formatDescription,
                                                 int samplesCount, CMSampleTimingInfo[]?sampleTimingArray, nuint[]?sampleSizeArray,
                                                 out CMSampleBufferError error)
        {
            if (dataBuffer is null)
            {
                ObjCRuntime.ThrowHelper.ThrowArgumentNullException(nameof(dataBuffer));
            }
            if (samplesCount < 0)
            {
                ObjCRuntime.ThrowHelper.ThrowArgumentOutOfRangeException(nameof(samplesCount), "Negative");
            }

            IntPtr buffer;
            var    fdh         = formatDescription.GetHandle();
            var    timingCount = sampleTimingArray is null ? 0 : sampleTimingArray.Length;
            var    sizeCount   = sampleSizeArray is null ? 0 : sampleSizeArray.Length;

            error = CMSampleBufferCreateReady(IntPtr.Zero, dataBuffer.Handle, fdh, samplesCount, timingCount,
                                              sampleTimingArray, sizeCount, sampleSizeArray, out buffer);

            if (error != CMSampleBufferError.None)
            {
                return(null);
            }

            return(new CMSampleBuffer(buffer, true));
        }
Пример #6
0
        public static CMSampleBuffer?CreateReadyWithPacketDescriptions(CMBlockBuffer dataBuffer, CMFormatDescription formatDescription, int samplesCount,
                                                                       CMTime sampleTimestamp, AudioStreamPacketDescription[]?packetDescriptions, out CMSampleBufferError error)
        {
            if (dataBuffer is null)
            {
                ObjCRuntime.ThrowHelper.ThrowArgumentNullException(nameof(dataBuffer));
            }
            if (formatDescription is null)
            {
                ObjCRuntime.ThrowHelper.ThrowArgumentNullException(nameof(formatDescription));
            }
            if (samplesCount <= 0)
            {
                ObjCRuntime.ThrowHelper.ThrowArgumentOutOfRangeException(nameof(samplesCount), "smaller than 0");
            }

            error = CMAudioSampleBufferCreateReadyWithPacketDescriptions(IntPtr.Zero, dataBuffer.Handle,
                                                                         formatDescription.Handle, samplesCount, sampleTimestamp, packetDescriptions, out var buffer);

            if (error != CMSampleBufferError.None)
            {
                return(null);
            }

            return(new CMSampleBuffer(buffer, true));
        }
Пример #7
0
        public int /*CMSampleBufferError*/ SetDataBuffer(CMBlockBuffer dataBuffer)
        {
            var dataBufferHandle = IntPtr.Zero;

            if (dataBuffer != null)
            {
                dataBufferHandle = dataBuffer.handle;
            }
            return((int)CMSampleBufferSetDataBuffer(handle, dataBufferHandle));
        }
Пример #8
0
        public CMBlockBufferError AppendBuffer(CMBlockBuffer targetBuffer, nuint offsetToData, nuint dataLength, CMBlockBufferFlags flags)
        {
            if (Handle == IntPtr.Zero)
            {
                throw new ObjectDisposedException("BlockBuffer");
            }

            // From docs targetBuffer must not be null unless the PermitEmptyReference flag is set
            if (!flags.HasFlag(CMBlockBufferFlags.PermitEmptyReference))
            {
                if (targetBuffer == null)
                {
                    throw new ArgumentNullException("targetBuffer");
                }
            }

            return(CMBlockBufferAppendBufferReference(Handle, targetBuffer == null ? IntPtr.Zero : targetBuffer.handle, offsetToData, dataLength, flags));
        }
Пример #9
0
        public static CMBlockBuffer FromBuffer(CMBlockBuffer targetBuffer, nuint offsetToData, nuint dataLength, CMBlockBufferFlags flags, out CMBlockBufferError error)
        {
            // From docs targetBuffer must not be null unless the PermitEmptyReference flag is set
            if (!flags.HasFlag(CMBlockBufferFlags.PermitEmptyReference))
            {
                if (targetBuffer == null)
                {
                    throw new ArgumentNullException("targetBuffer");
                }
            }

            IntPtr buffer;

            error = CMBlockBufferCreateWithBufferReference(IntPtr.Zero, targetBuffer == null ? IntPtr.Zero : targetBuffer.handle, offsetToData, dataLength, flags, out buffer);
            if (error != CMBlockBufferError.None)
            {
                return(null);
            }

            return(new CMBlockBuffer(buffer, true));
        }
Пример #10
0
        public CMSampleBufferError SetDataBuffer(CMBlockBuffer dataBuffer)
        {
            var dataBufferHandle = dataBuffer == null ? IntPtr.Zero : dataBuffer.handle;

            return(CMSampleBufferSetDataBuffer(handle, dataBufferHandle));
        }
Пример #11
0
 public CMSampleBufferError SetDataBuffer(CMBlockBuffer dataBuffer)
 {
     return(CMSampleBufferSetDataBuffer(Handle, dataBuffer.GetHandle()));
 }