/// <summary>
        /// Reads the next packet from this file and sends it to the packet queue.
        /// </summary>
        /// <returns>Type of the readed packet.</returns>
        public MediaType ReadPacket()
        {
            var packet = MediaPacket.AllocateEmpty(0);
            var result = ffmpeg.av_read_frame(Pointer, packet.Pointer);

            if (result == ffmpeg.AVERROR_EOF)
            {
                IsAtEndOfFile = true;
                return(MediaType.None);
            }
            else
            {
                result.ThrowIfError("Cannot read next packet from the file");
            }

            IsAtEndOfFile = false;
            return(EnqueuePacket(packet));
        }
示例#2
0
        /// <summary>
        /// Reads the next packet from this file and sends it to the packet queue.
        /// </summary>
        /// <returns>Type of the readed packet.</returns>
        public MediaType ReadPacket()
        {
            var packet = MediaPacket.AllocateEmpty(0);
            var result = ffmpeg.av_read_frame(Pointer, packet.Pointer); // Gets the next packet from the file.

            // Check if the end of file error ocurred
            if (result == ffmpeg.AVERROR_EOF)
            {
                IsAtEndOfFile = true;
                return(MediaType.None);
            }
            else
            {
                result.ThrowIfError("Cannot read next packet from the file");
            }

            IsAtEndOfFile = false;
            return(EnqueuePacket(packet)); // Sends packet to the internal decoder queue.
        }
示例#3
0
        /// <summary>
        /// Adds the packet to the internal queue of the codec.
        /// </summary>
        /// <param name="packet">The packet to be encoded or decoded.</param>
        /// <exception cref="ArgumentNullException"><paramref name="packet"/> is null.</exception>
        /// <exception cref="InvalidOperationException">The current codec is not prepared yet.</exception>
        /// <remarks>Any attempts to modify the packet will fail until the <see cref="InputProcessed"/> event for the packet is invoked.</remarks>
        /// <since_tizen> 3 </since_tizen>
        public void ProcessInput(MediaPacket packet)
        {
            ValidateNotDisposed();

            if (packet == null)
            {
                throw new ArgumentNullException(nameof(packet));
            }

            MediaPacket.Lock packetLock = MediaPacket.Lock.Get(packet);

            int ret = Interop.MediaCodec.Process(_handle, packetLock.GetHandle(), 0);

            if (ret == (int)MediaCodecErrorCode.InvalidState)
            {
                throw new InvalidOperationException("The codec is in invalid state.");
            }

            MultimediaDebug.AssertNoError(ret);
        }
示例#4
0
        internal async Task <MediaPacket> RunAsync(TransformHandle handle, MediaPacket source)
        {
            Debug.Assert(source.Format is VideoMediaFormat);
            ValidateFormat(source.Format as VideoMediaFormat);

            var tcs = new TaskCompletionSource <MediaPacket>();

            using (var cbKeeper = ObjectKeeper.Get(GetCallback(tcs, source)))
            {
                var result = NativeTransform.Run(handle, source.GetHandle(), cbKeeper.Target);

                if (result == ImageUtilError.NotSupportedFormat)
                {
                    throw new NotSupportedException(
                              GenerateNotSupportedErrorMessage(source.Format as VideoMediaFormat));
                }
                result.ThrowIfFailed("Failed to transform given packet with " + GetType());

                return(await tcs.Task);
            }
        }
示例#5
0
        internal override async Task <MediaPacket> ApplyAsync(MediaPacket source)
        {
            using (TransformHandle handle = CreateHandle())
            {
                if (Flip.HasFlag(Flips.Vertical | Flips.Horizontal))
                {
                    var flipped = await ApplyAsync(handle, source, ImageRotation.FlipHorizontal);

                    try
                    {
                        return(await ApplyAsync(handle, flipped, ImageRotation.FlipVertical));
                    }
                    finally
                    {
                        flipped.Dispose();
                    }
                }

                return(await ApplyAsync(handle, source, Flip.HasFlag(Flips.Horizontal)?
                                        ImageRotation.FlipHorizontal : ImageRotation.FlipVertical));
            }
        }
示例#6
0
        private void RegisterInputProcessed()
        {
            _inputBufferUsedCb = (lockedPacketHandle, _) =>
            {
                MediaPacket packet = null;

                // Lock must be disposed here, note that the packet won't be disposed.
                using (MediaPacket.Lock packetLock =
                           MediaPacket.Lock.FromHandle(lockedPacketHandle))
                {
                    Debug.Assert(packetLock != null);

                    packet = packetLock.MediaPacket;
                }
                Debug.Assert(packet != null);

                InputProcessed?.Invoke(this, new InputProcessedEventArgs(packet));
            };

            Native.SetInputBufferUsedCb(_handle, _inputBufferUsedCb).
            ThrowIfFailed("Failed to set input buffer used callback.");
        }
示例#7
0
        private void RegisterInputProcessed()
        {
            _inputBufferUsedCb = (lockedPacketHandle, _) =>
            {
                MediaPacket packet = null;

                // Lock must be disposed here, note that the packet won't be disposed.
                using (MediaPacket.Lock packetLock =
                           MediaPacket.Lock.FromHandle(lockedPacketHandle))
                {
                    Debug.Assert(packetLock != null);

                    packet = packetLock.MediaPacket;
                }
                Debug.Assert(packet != null);

                InputProcessed?.Invoke(this, new InputProcessedEventArgs(packet));
            };

            int ret = Interop.MediaCodec.SetInputBufferUsedCb(_handle, _inputBufferUsedCb);

            MultimediaDebug.AssertNoError(ret);
        }
示例#8
0
        /// <summary>
        /// Transforms an image with <see cref="ImageTransform"/>.
        /// </summary>
        /// <param name="source"><see cref="MediaPacket"/> to transform. The <see cref="MediaPacket.Format"/> of this <paramref name="source"/> must be <see cref="VideoMediaFormat"/>.</param>
        /// <param name="item"><see cref="ImageTransform"/> to apply.</param>
        /// <returns>A task that represents the asynchronous transforming operation.</returns>
        /// <exception cref="ArgumentNullException">
        ///     <paramref name="source"/> is null.<br/>
        ///     -or-<br/>
        ///     <paramref name="item"/> is null.
        /// </exception>
        /// <exception cref="ArgumentException"><paramref name="source"/> is not video format.</exception>
        /// <exception cref="ObjectDisposedException">The <see cref="ImageTransformer"/> has already been disposed of.</exception>
        /// <exception cref="InvalidOperationException">Failed to apply <see cref="ImageTransform"/>.</exception>
        /// <exception cref="NotSupportedException">Specified transformation is not supported.</exception>
        /// <since_tizen> 4 </since_tizen>
        public Task <MediaPacket> TransformAsync(MediaPacket source, ImageTransform item)
        {
            if (_disposed)
            {
                throw new ObjectDisposedException(nameof(ImageTransformer));
            }

            if (source == null)
            {
                throw new ArgumentNullException(nameof(source));
            }

            if (item == null)
            {
                throw new ArgumentNullException(nameof(item));
            }

            if (source.Format is VideoMediaFormat == false)
            {
                throw new ArgumentException("source is not video format.", nameof(source));
            }

            return(item.ApplyAsync(source));
        }
示例#9
0
 private async Task <MediaPacket> ApplyAsync(TransformHandle handle, MediaPacket source,
                                             ImageRotation rotation)
 {
     SetRotation(handle, rotation);
     return(await RunAsync(handle, source));
 }
示例#10
0
 internal OutputAvailableEventArgs(IntPtr packetHandle)
 {
     Packet = MediaPacket.From(packetHandle);
 }
示例#11
0
 /// <summary>
 /// Initializes a new instance of the <see cref="OutputStream{TFrame}"/> class.
 /// </summary>
 /// <param name="stream">The multimedia stream.</param>
 /// <param name="owner">The container that owns the stream.</param>
 public OutputStream(AVStream *stream, OutputContainer owner)
     : base(stream)
 {
     OwnerFile = owner;
     packet    = MediaPacket.AllocateEmpty();
 }
示例#12
0
 internal WebRTCFrameEncodedEventArgs(MediaStreamTrack track, MediaPacket packet)
 {
     MediaStreamTrack = track;
     Packet           = packet;
 }
示例#13
0
        private void RegisterVideoFrameEncodedCallback()
        {
            _webRtcVideoFrameEncodedCallback = (handle, type, id, packet, _) =>
            {
                Log.Info(WebRTCLog.Tag, $"Track type[{type}], id[{id}]");

                _videoFrameEncoded?.Invoke(this,
                                           new WebRTCFrameEncodedEventArgs(new MediaStreamTrack(this, type, id), MediaPacket.From(packet)));
            };

            NativeWebRTC.SetVideoFrameEncodedCb(Handle, _webRtcVideoFrameEncodedCallback).
            ThrowIfFailed("Failed to set video frame encoded callback.");
        }
示例#14
0
 /// <summary>
 /// Adds the specified packet to the codec buffer.
 /// </summary>
 /// <param name="packet">The packet to be buffered.</param>
 public void BufferPacket(MediaPacket packet)
 {
     BufferedPackets.Enqueue(packet);
 }
示例#15
0
 private InputContainer(AVFormatContext *formatContext, bool useCustomAvioContext)
     : base(formatContext)
 {
     packet = MediaPacket.AllocateEmpty(0);
     avioContextDisposingRequired = useCustomAvioContext;
 }
示例#16
0
 /// <summary>
 /// Initializes a new instance of the <see cref="MediaVisionSource"/> class based on the <see cref="MediaPacket"/>.
 /// </summary>
 /// <param name="mediaPacket">The <see cref="MediaPacket"/> from which the source will be filled.</param>
 /// <exception cref="NotSupportedException">None of the related features are not supported.</exception>
 /// <exception cref="ArgumentNullException"><paramref name="mediaPacket"/> is null.</exception>
 /// <exception cref="ObjectDisposedException"><paramref name="mediaPacket"/> has already been disposed of.</exception>
 /// <since_tizen> 4 </since_tizen>
 public MediaVisionSource(MediaPacket mediaPacket)
     : this(handle => FillMediaPacket(handle, mediaPacket))
 {
 }
示例#17
0
        /// <summary>
        /// Initializes a new instance of the InputProcessedEventArgs class.
        /// </summary>
        /// <param name="packet">The packet that the codec has processed.</param>
        internal InputProcessedEventArgs(MediaPacket packet)
        {
            Debug.Assert(packet != null);

            Packet = packet;
        }