/**
         * Write a media sample to the decoder.
         *
         * A "sample" here refers to a single atomic access unit in the media stream. The definition
         * of "access unit" is dependent on the type of encoding used, but it typically refers to
         * a single frame of video or a few seconds of audio. {@link android.media.MediaExtractor}
         * extracts data from a stream one sample at a time.
         *
         * @param extractor  Instance of {@link android.media.MediaExtractor} wrapping the media.
         *
         * @param presentationTimeUs The time, relative to the beginning of the media stream,
         * at which this buffer should be rendered.
         *
         * @param flags  Flags to pass to the decoder. See {@link MediaCodec#queueInputBuffer(int,
         * int, int, long, int)}
         *
         * @throws MediaCodec.CryptoException
         */
        public bool writeSample(MediaExtractor extractor,
                                bool isSecure,
                                long presentationTimeUs,
                                int flags)
        {
            bool result = false;

            if (mAvailableInputBuffers.Any())
            {
                int        index  = mAvailableInputBuffers.Dequeue();
                ByteBuffer buffer = mInputBuffers[index];

                // reads the sample from the file using extractor into the buffer
                int size = extractor.ReadSampleData(buffer, 0);
                if (size <= 0)
                {
                    flags |= (int)MediaCodec.BufferFlagEndOfStream;
                }

                // Submit the buffer to the codec for decoding. The presentationTimeUs
                // indicates the position (play time) for the current sample.
                if (!isSecure)
                {
                    mDecoder.QueueInputBuffer(index, 0, size, presentationTimeUs, (MediaCodecBufferFlags)flags);
                }
                else
                {
                    extractor.GetSampleCryptoInfo(sCryptoInfo);
                    mDecoder.QueueSecureInputBuffer(index, 0, sCryptoInfo, presentationTimeUs, (MediaCodecBufferFlags)flags);
                }

                result = true;
            }
            return(result);
        }