Пример #1
0
        void ComputeHistogram(VarArrayBuffer buffer)
        {
            var bufferSize = buffer.ByteLength;

            if (bufferSize == 0)
            {
                return;
            }

            var bufferData = buffer.Map();

            var max = double.MinValue;

            for (uint i = 0; i < bufferSize; i++)
            {
                var index = bufferData[i];
                histogram[index] += 1.0;

                if (histogram[index] > max)
                {
                    max = histogram[index];
                }
            }

            //Normalize
            for (uint i = 0; i < HISTOGRAM_SIZE; i++)
            {
                histogram[i] /= max;
            }
        }
Пример #2
0
        void PostDataMessage(byte[] buffer, uint size)
        {
            var dictionary = new VarDictionary();

            dictionary.Set("name", "data");

            VarArrayBuffer array_buffer = null;

            byte[] dataPtr    = null;
            uint   dataOffset = 0;

            if (videoProfile == VideoProfile.Vp8Any ||
                videoProfile == VideoProfile.Vp9Any)
            {
                uint frameOffset = 0;
                if (encodedFrames == 1)
                {
                    array_buffer = new VarArrayBuffer(size + ivfWriter.GetFileHeaderSize() + ivfWriter.GetFrameHeaderSize());
                    dataPtr      = array_buffer.Map();
                    frameOffset  = ivfWriter.WriteFileHeader(dataPtr, VideoProfileToString(videoProfile).ToUpper(),
                                                             frameSize.Width, frameSize.Height);
                }
                else
                {
                    array_buffer = new VarArrayBuffer(size + ivfWriter.GetFrameHeaderSize());
                    dataPtr      = array_buffer.Map();
                }
                var timestamp = frameTimeStampQueue.Peek();
                frameTimeStampQueue.Dequeue();
                dataOffset =
                    frameOffset +
                    ivfWriter.WriteFrameHeader(dataPtr, frameOffset, timestamp, size);
            }

            Array.Copy(buffer, 0, dataPtr, dataOffset, size);

            // Make sure we flush the buffer data back to unmanaged memeory.
            array_buffer.Flush();
            array_buffer.Unmap();
            dictionary.Set("data", array_buffer);

            PostMessage(dictionary);
        }