Exemplo n.º 1
0
        internal override void AsNativeHandle(IntPtr handle)
        {
            Debug.Assert(Type == MediaFormatType.Audio);

            int ret = Native.SetAudioMimeType(handle, MimeType);

            MultimediaDebug.AssertNoError(ret);

            ret = Native.SetAudioChannel(handle, Channel);
            MultimediaDebug.AssertNoError(ret);

            ret = Native.SetAudioSampleRate(handle, SampleRate);
            MultimediaDebug.AssertNoError(ret);

            ret = Native.SetAudioBit(handle, Bit);
            MultimediaDebug.AssertNoError(ret);

            ret = Native.SetAudioAverageBps(handle, BitRate);
            MultimediaDebug.AssertNoError(ret);

            ret = Native.SetAudioAacType(handle, AacType);
            MultimediaDebug.AssertNoError(ret);

            if (AudioChannelMap != null)
            {
                ret = Native.SetAudioChannelMask(handle, GetAudioChannelMask(handle, AudioChannelMap));
                MultimediaDebug.AssertNoError(ret);
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Creates a media format from a native handle.
        /// </summary>
        /// <param name="handle">A native handle.</param>
        /// <returns>An object of one of the subclasses of <see cref="MediaFormat"/>.</returns>
        internal static MediaFormat FromHandle(IntPtr handle)
        {
            if (handle == IntPtr.Zero)
            {
                throw new ArgumentException("The handle value is invalid.");
            }

            int type = 0;
            int ret  = Interop.MediaFormat.GetType(handle, out type);

            if (ret != (int)ErrorCode.InvalidOperation)
            {
                MultimediaDebug.AssertNoError(ret);

                switch ((MediaFormatType)type)
                {
                case MediaFormatType.Container:
                    return(new ContainerMediaFormat(handle));

                case MediaFormatType.Video:
                    return(new VideoMediaFormat(handle));

                case MediaFormatType.Audio:
                    return(new AudioMediaFormat(handle));

                case MediaFormatType.Text:
                    return(new TextMediaFormat(handle));
                }
            }

            throw new ArgumentException("looks like handle is corrupted.");
        }
Exemplo n.º 3
0
        internal MediaPacketVideoPlane(MediaPacket packet, int index)
        {
            Debug.Assert(packet != null, "The packet is null!");
            Debug.Assert(!packet.IsDisposed, "Packet is already disposed!");
            Debug.Assert(index >= 0, "Video plane index must not be negative!");

            _packet = packet;

            int ret = Interop.MediaPacket.GetVideoStrideWidth(packet.GetHandle(), index, out _strideWidth);

            MultimediaDebug.AssertNoError(ret);

            ret = Interop.MediaPacket.GetVideoStrideHeight(packet.GetHandle(), index, out _strideHeight);
            MultimediaDebug.AssertNoError(ret);

            Debug.Assert(_strideWidth >= 0 && _strideHeight >= 0, "size must not be negative!");

            IntPtr dataHandle;

            ret = Interop.MediaPacket.GetVideoPlaneData(packet.GetHandle(), index, out dataHandle);
            MultimediaDebug.AssertNoError(ret);

            Debug.Assert(dataHandle != IntPtr.Zero, "Data handle is invalid!");

            _buffer = new DependentMediaBuffer(packet, dataHandle, _strideWidth * _strideHeight);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Retrieves frame rate from a native handle.
        /// </summary>
        /// <param name="handle">A native handle that the properties are retrieved from.</param>
        /// <param name="frameRate">An out parameter for the frame rate.</param>
        private static void GetFrameRate(IntPtr handle, out int frameRate)
        {
            Debug.Assert(handle != IntPtr.Zero, "The handle is invalid!");

            int ret = Interop.MediaFormat.GetVideoFrameRate(handle, out frameRate);

            MultimediaDebug.AssertNoError(ret);
        }
Exemplo n.º 5
0
        /// <summary>
        /// Drains the buffered audio data from the output stream.
        /// It blocks the calling thread until the drain of the stream buffer is complete, for example, at the end of playback.
        /// </summary>
        /// <exception cref="ObjectDisposedException">The AudioPlayback has already been disposed of.</exception>
        /// <exception cref="InvalidOperationException">The current state is <see cref="AudioIOState.Idle"/>.</exception>
        /// <since_tizen> 3 </since_tizen>
        public void Drain()
        {
            ValidateState(AudioIOState.Running, AudioIOState.Paused);

            int ret = AudioOutput.Drain(_handle);

            MultimediaDebug.AssertNoError(ret);
        }
Exemplo n.º 6
0
        private AudioStreamFocusState GetFocusState(bool playback)
        {
            int ret = Interop.AudioStreamPolicy.GetFocusState(Handle, out var stateForPlayback, out var stateForRecording);

            MultimediaDebug.AssertNoError(ret);

            return(playback ? stateForPlayback : stateForRecording);
        }
Exemplo n.º 7
0
        /// <summary>
        /// Flushes and discards buffered audio data from the input stream.
        /// </summary>
        /// <exception cref="InvalidOperationException">The current state is <see cref="AudioIOState.Idle"/>.</exception>
        /// <exception cref="ObjectDisposedException">The AudioCaptureBase has already been disposed of.</exception>
        /// <since_tizen> 3 </since_tizen>
        public void Flush()
        {
            ValidateState(AudioIOState.Running, AudioIOState.Paused);

            int ret = AudioInput.Flush(_handle);

            MultimediaDebug.AssertNoError(ret);
        }
Exemplo n.º 8
0
        internal override void AsNativeHandle(IntPtr handle)
        {
            Debug.Assert(Type == MediaFormatType.Container);

            int ret = Interop.MediaFormat.SetContainerMimeType(handle, MimeType);

            MultimediaDebug.AssertNoError(ret);
        }
Exemplo n.º 9
0
            private static IntPtr GetExtra(IntPtr handle)
            {
                int ret = Interop.MediaPacket.GetExtra(handle, out var value);

                MultimediaDebug.AssertNoError(ret);

                return(value);
            }
Exemplo n.º 10
0
        private static ulong GetAudioChannelMask(IntPtr handle, IList <MediaFormatAudioChannelPosition> audioChannelMap)
        {
            int ret = Native.GetMaskFromChannelPosition(handle, audioChannelMap.ToArray(),
                                                        out ulong mask);

            MultimediaDebug.AssertNoError(ret);

            return(mask);
        }
Exemplo n.º 11
0
        /// <summary>
        /// Creates a native media format from this object.
        /// </summary>
        /// <returns>A converted native handle.</returns>
        /// <remarks>The returned handle must be destroyed using <see cref="Interop.MediaFormat.Unref(IntPtr)"/>.</remarks>
        internal IntPtr AsNativeHandle()
        {
            int ret = Interop.MediaFormat.Create(out var handle);

            MultimediaDebug.AssertNoError(ret);

            AsNativeHandle(handle);

            return(handle);
        }
Exemplo n.º 12
0
        internal override void AsNativeHandle(IntPtr handle)
        {
            Debug.Assert(Type == MediaFormatType.Text);

            int ret = Interop.MediaFormat.SetTextMimeType(handle, (int)MimeType);

            MultimediaDebug.AssertNoError(ret);

            ret = Interop.MediaFormat.SetTextType(handle, (int)TextType);
            MultimediaDebug.AssertNoError(ret);
        }
Exemplo n.º 13
0
        /// <summary>
        /// Retrieves the AAC type value from a native handle.
        /// </summary>
        /// <param name="handle">A native handle that the properties are retrieved from.</param>
        private static MediaFormatAacType GetAacType(IntPtr handle)
        {
            Debug.Assert(handle != IntPtr.Zero, "The handle is invalid!");

            int ret = Native.GetAudioAacType(handle, out var aacType);

            MultimediaDebug.AssertNoError(ret);

            Debug.Assert(Enum.IsDefined(typeof(MediaFormatAacType), aacType), "Invalid aac type!");

            return(aacType);
        }
Exemplo n.º 14
0
        private static ReadOnlyCollection <MediaFormatAudioChannelPosition> GetAudioChannelMap(IntPtr handle)
        {
            var ret = Native.GetAudioChannelMask(handle, out ulong mask);

            MultimediaDebug.AssertNoError(ret);

            ret = Native.GetChannelPositionFromMask(handle, mask, out MediaFormatAudioChannelPosition[] positions);
            MultimediaDebug.AssertNoError(ret);

            return(positions == null ? null :
                   new ReadOnlyCollection <MediaFormatAudioChannelPosition>(positions.Distinct().OrderBy(p => p).ToList()));
        }
Exemplo n.º 15
0
        /// <summary>
        /// Retrieves audio properties of the media format from a native handle.
        /// </summary>
        /// <param name="handle">A native handle that the properties are retrieved from.</param>
        /// <param name="mimeType">An out parameter for the mime type.</param>
        /// <param name="channel">An out parameter for the channel.</param>
        /// <param name="sampleRate">An out parameter for the sample rate.</param>
        /// <param name="bit">An out parameter for the bit.</param>
        /// <param name="bitRate">An out parameter for the bit rate.</param>
        private static void GetInfo(IntPtr handle, out MediaFormatAudioMimeType mimeType,
                                    out int channel, out int sampleRate, out int bit, out int bitRate)
        {
            Debug.Assert(handle != IntPtr.Zero, "The handle is invalid!");

            int ret = Native.GetAudioInfo(handle,
                                          out mimeType, out channel, out sampleRate, out bit, out bitRate);

            MultimediaDebug.AssertNoError(ret);

            Debug.Assert(Enum.IsDefined(typeof(MediaFormatAudioMimeType), mimeType),
                         "Invalid audio mime type!");
        }
Exemplo n.º 16
0
        /// <summary>
        /// Retrieves the AAC type value from a native handle.
        /// </summary>
        /// <param name="handle">A native handle that the properties are retrieved from.</param>
        /// <param name="aacType">An out parameter for tha AAC type.</param>
        private static void GetAacType(IntPtr handle, out MediaFormatAacType aacType)
        {
            Debug.Assert(handle != IntPtr.Zero, "The handle is invalid!");

            int aacTypeValue = 0;

            int ret = Interop.MediaFormat.GetAudioAacType(handle, out aacTypeValue);

            MultimediaDebug.AssertNoError(ret);

            aacType = (MediaFormatAacType)aacTypeValue;

            Debug.Assert(Enum.IsDefined(typeof(MediaFormatAacType), aacType), "Invalid aac type!");
        }
Exemplo n.º 17
0
        /// <summary>
        /// Initializes a new instance of the ContainerMediaFormat class from a native handle.
        /// </summary>
        /// <param name="handle">A native media format handle.</param>
        internal ContainerMediaFormat(IntPtr handle)
            : base(MediaFormatType.Container)
        {
            Debug.Assert(handle != IntPtr.Zero, "The handle is invalid!");

            int ret = Interop.MediaFormat.GetContainerMimeType(handle, out var mimeType);

            MultimediaDebug.AssertNoError(ret);

            Debug.Assert(Enum.IsDefined(typeof(MediaFormatContainerMimeType), mimeType),
                         "Invalid container mime type!");

            MimeType = mimeType;
        }
Exemplo n.º 18
0
        internal AudioDevice(IntPtr deviceHandle)
        {
            int ret = Interop.AudioDevice.GetDeviceId(deviceHandle, out _id);

            MultimediaDebug.AssertNoError(ret);

            ret = Interop.AudioDevice.GetDeviceName(deviceHandle, out var name);
            MultimediaDebug.AssertNoError(ret);

            Name = Marshal.PtrToStringAnsi(name);

            ret = Interop.AudioDevice.GetDeviceType(deviceHandle, out _type);
            MultimediaDebug.AssertNoError(ret);

            ret = Interop.AudioDevice.GetDeviceIoDirection(deviceHandle, out _ioDirection);
            MultimediaDebug.AssertNoError(ret);
        }
Exemplo n.º 19
0
        /// <summary>
        /// Initializes a new instance of the TextMediaFormat class from a native handle.
        /// </summary>
        /// <param name="handle">A native handle.</param>
        internal TextMediaFormat(IntPtr handle)
            : base(MediaFormatType.Text)
        {
            Debug.Assert(handle != IntPtr.Zero, "The handle is invalid!");

            int ret = Interop.MediaFormat.GetTextInfo(handle, out var mimeType, out var textType);

            MultimediaDebug.AssertNoError(ret);

            Debug.Assert(Enum.IsDefined(typeof(MediaFormatTextMimeType), mimeType),
                         "Invalid text mime type!");
            Debug.Assert(Enum.IsDefined(typeof(MediaFormatTextType), textType),
                         "Invalid text type!");

            MimeType = mimeType;
            TextType = textType;
        }
Exemplo n.º 20
0
        /// <summary>
        /// Retrieves video planes of the current packet.
        /// </summary>
        /// <returns>The <see cref="MediaPacketVideoPlane"/>s allocated to the current MediaPacket.</returns>
        private MediaPacketVideoPlane[] GetVideoPlanes()
        {
            Debug.Assert(_handle != IntPtr.Zero, "The handle is invalid!");

            int ret = Native.GetNumberOfVideoPlanes(_handle, out var numberOfPlanes);

            MultimediaDebug.AssertNoError(ret);

            MediaPacketVideoPlane[] planes = new MediaPacketVideoPlane[numberOfPlanes];

            for (int i = 0; i < numberOfPlanes; ++i)
            {
                planes[i] = new MediaPacketVideoPlane(this, i);
            }

            return(planes);
        }
Exemplo n.º 21
0
        /// <summary>
        /// Retrieves video properties of the media format from a native handle.
        /// </summary>
        /// <param name="handle">A native handle that the properties are retrieved from.</param>
        /// <param name="width">An out parameter for the width.</param>
        /// <param name="height">An out parameter for the height.</param>
        /// <param name="bitRate">An out parameter for the bit rate.</param>
        /// <param name="mimeType">An out parameter for the mime type.</param>
        private static void GetInfo(IntPtr handle, out int width, out int height, out int bitRate,
                                    out MediaFormatVideoMimeType mimeType)
        {
            Debug.Assert(handle != IntPtr.Zero, "The handle is invalid!");

            int mimeTypeValue = 0;
            int maxBps        = 0;

            int ret = Interop.MediaFormat.GetVideoInfo(handle,
                                                       out mimeTypeValue, out width, out height, out bitRate, out maxBps);

            MultimediaDebug.AssertNoError(ret);

            mimeType = (MediaFormatVideoMimeType)mimeTypeValue;

            Debug.Assert(Enum.IsDefined(typeof(MediaFormatVideoMimeType), mimeType),
                         "Invalid video mime type!");
        }
Exemplo n.º 22
0
        /// <summary>
        /// Retrieves text properties of the media format from a native handle.
        /// </summary>
        /// <param name="handle">A native handle that the properties are retrieved from.</param>
        /// <param name="mimeType">An out parameter for the mime type.</param>
        /// <param name="textType">An out parameter for the text type.</param>
        private static void GetInfo(IntPtr handle, out MediaFormatTextMimeType mimeType,
                                    out MediaFormatTextType textType)
        {
            int mimeTypeValue = 0;
            int textTypeValue = 0;

            int ret = Interop.MediaFormat.GetTextInfo(handle, out mimeTypeValue, out textTypeValue);

            MultimediaDebug.AssertNoError(ret);

            mimeType = (MediaFormatTextMimeType)mimeTypeValue;
            textType = (MediaFormatTextType)textTypeValue;

            Debug.Assert(Enum.IsDefined(typeof(MediaFormatTextMimeType), mimeType),
                         "Invalid text mime type!");
            Debug.Assert(Enum.IsDefined(typeof(MediaFormatTextType), textType),
                         "Invalid text type!");
        }
Exemplo n.º 23
0
        /// <summary>
        /// Retrieves the buffer of the current packet.
        /// </summary>
        /// <returns>The <see cref="IMediaBuffer"/> allocated to the current MediaPacket.</returns>
        private IMediaBuffer GetBuffer()
        {
            Debug.Assert(!IsDisposed, "Packet is already disposed!");

            Debug.Assert(_handle != IntPtr.Zero, "The handle is invalid!");

            int ret = Native.GetBufferData(_handle, out var dataHandle);

            MultimediaDebug.AssertNoError(ret);

            Debug.Assert(dataHandle != IntPtr.Zero, "Data handle is invalid!");

            ret = Native.GetAllocatedBufferSize(_handle, out var size);
            MultimediaDebug.AssertNoError(ret);

            Debug.Assert(size >= 0, "size must not be negative!");

            return(new DependentMediaBuffer(this, dataHandle, size));
        }
Exemplo n.º 24
0
        internal override void AsNativeHandle(IntPtr handle)
        {
            Debug.Assert(Type == MediaFormatType.Video);

            int ret = Interop.MediaFormat.SetVideoMimeType(handle, (int)MimeType);

            MultimediaDebug.AssertNoError(ret);

            ret = Interop.MediaFormat.SetVideoWidth(handle, Size.Width);
            MultimediaDebug.AssertNoError(ret);

            ret = Interop.MediaFormat.SetVideoHeight(handle, Size.Height);
            MultimediaDebug.AssertNoError(ret);

            ret = Interop.MediaFormat.SetVideoAverageBps(handle, BitRate);
            MultimediaDebug.AssertNoError(ret);

            ret = Interop.MediaFormat.SetVideoFrameRate(handle, FrameRate);
            MultimediaDebug.AssertNoError(ret);
        }
Exemplo n.º 25
0
        /// <summary>
        /// Initializes a new instance of the MediaPacket class from a native handle.
        /// </summary>
        /// <param name="handle">The native handle to be used.</param>
        internal MediaPacket(IntPtr handle)
        {
            _handle = handle;

            int ret = Native.GetFormat(handle, out IntPtr formatHandle);

            MultimediaDebug.AssertNoError(ret);

            try
            {
                if (formatHandle != IntPtr.Zero)
                {
                    _format = MediaFormat.FromHandle(formatHandle);
                }
            }
            finally
            {
                NativeFormat.Unref(formatHandle);
            }
        }
Exemplo n.º 26
0
        /// <summary>
        /// Creates and initializes a native handle for the current object.
        /// </summary>
        /// <param name="format">The format to be set to the media format.</param>
        /// <exception cref="InvalidOperationException">Operation failed.</exception>
        private void Initialize(MediaFormat format)
        {
            if (format.Type == MediaFormatType.Container)
            {
                throw new ArgumentException("Container format can't be used to create a new packet.",
                                            nameof(format));
            }

            IntPtr formatHandle = IntPtr.Zero;

            try
            {
                formatHandle = format.AsNativeHandle();

                int ret = Native.Create(formatHandle, IntPtr.Zero, IntPtr.Zero, out _handle);
                MultimediaDebug.AssertNoError(ret);

                Debug.Assert(_handle != IntPtr.Zero, "Created handle must not be null");

                Alloc();
            }
            catch (Exception)
            {
                if (_handle != IntPtr.Zero)
                {
                    Native.Destroy(_handle);
                    _handle = IntPtr.Zero;
                }

                throw;
            }
            finally
            {
                if (formatHandle != IntPtr.Zero)
                {
                    NativeFormat.Unref(formatHandle);
                }
            }
        }
Exemplo n.º 27
0
        /// <summary>
        /// Initializes a new instance of the VideoMediaForma class from a native handle.
        /// </summary>
        /// <param name="handle">A native handle.</param>
        internal VideoMediaFormat(IntPtr handle)
            : base(MediaFormatType.Video)
        {
            Debug.Assert(handle != IntPtr.Zero, "The handle is invalid!");

            int ret = Interop.MediaFormat.GetVideoInfo(handle,
                                                       out var mimeType, out var width, out var height, out var bitRate, out var maxBps);

            MultimediaDebug.AssertNoError(ret);

            Debug.Assert(Enum.IsDefined(typeof(MediaFormatVideoMimeType), mimeType),
                         "Invalid video mime type!");

            ret = Interop.MediaFormat.GetVideoFrameRate(handle, out var frameRate);

            MultimediaDebug.AssertNoError(ret);

            MimeType  = mimeType;
            Size      = new Size(width, height);
            FrameRate = frameRate;
            BitRate   = bitRate;
        }
Exemplo n.º 28
0
        /// <summary>
        /// Creates and initializes a native handle for the current object.
        /// </summary>
        /// <param name="format">The format to be set to the media format.</param>
        /// <exception cref="InvalidOperationException">Operation failed.</exception>
        private void Initialize(MediaFormat format)
        {
            if (format.Type == MediaFormatType.Container)
            {
                throw new ArgumentException("Creating a packet for container is not supported.");
            }

            IntPtr formatHandle = IntPtr.Zero;

            try
            {
                formatHandle = format.AsNativeHandle();

                int ret = Interop.MediaPacket.Create(formatHandle, IntPtr.Zero, IntPtr.Zero, out _handle);
                MultimediaDebug.AssertNoError(ret);

                Debug.Assert(_handle != IntPtr.Zero, "Created handle must not be null");

                Alloc();
            }
            catch (Exception)
            {
                if (_handle != IntPtr.Zero)
                {
                    Interop.MediaPacket.Destroy(_handle);
                    _handle = IntPtr.Zero;
                }

                throw;
            }
            finally
            {
                if (formatHandle != IntPtr.Zero)
                {
                    Interop.MediaFormat.Unref(formatHandle);
                }
            }
        }
Exemplo n.º 29
0
        internal override void AsNativeHandle(IntPtr handle)
        {
            Debug.Assert(Type == MediaFormatType.Audio);

            int ret = Interop.MediaFormat.SetAudioMimeType(handle, (int)MimeType);

            MultimediaDebug.AssertNoError(ret);

            ret = Interop.MediaFormat.SetAudioChannel(handle, Channel);
            MultimediaDebug.AssertNoError(ret);

            ret = Interop.MediaFormat.SetAudioSampleRate(handle, SampleRate);
            MultimediaDebug.AssertNoError(ret);

            ret = Interop.MediaFormat.SetAudioBit(handle, Bit);
            MultimediaDebug.AssertNoError(ret);

            ret = Interop.MediaFormat.SetAudioAverageBps(handle, BitRate);
            MultimediaDebug.AssertNoError(ret);

            ret = Interop.MediaFormat.SetAudioAacType(handle, (int)AacType);
            MultimediaDebug.AssertNoError(ret);
        }
Exemplo n.º 30
0
            private void SetExtra(IntPtr ptr)
            {
                int ret = Interop.MediaPacket.SetExtra(_packet._handle, ptr);

                MultimediaDebug.AssertNoError(ret);
            }