示例#1
0
        public void StartRecording(IStreamSettings streamSettings, int take)
        {
            var playbackBuffer = new PlaybackBuffer(streamSettings)
            {
                name = string.Format("{0:yyyy_MM_dd_HH_mm}-Take{1:00}", DateTime.Now, take)
            };

            Debug.Log(string.Format("Starting take: {0}", playbackBuffer.name));

            m_ActivePlaybackBuffer = playbackBuffer;

            var bufferSize = streamSettings.bufferSize;

            if (bufferSize != m_CurrentBufferSize)
            {
                m_BufferQueue.Clear();
            }

            m_CurrentBufferSize = bufferSize;
            new Thread(() =>
            {
                while (m_ActivePlaybackBuffer != null)
                {
                    if (m_BufferQueue.Count < k_MinBufferAmount)
                    {
                        for (var i = 0; i < k_BufferCreateAmount; i++)
                        {
                            m_BufferQueue.Enqueue(new byte[m_CurrentBufferSize]);
                        }
                    }

                    Thread.Sleep(1);
                }
            }).Start();
        }
示例#2
0
        public void SetPlaybackBuffer(PlaybackBuffer buffer)
        {
            if (active)
            {
                StopPlayback();
            }

            m_ActivePlaybackBuffer = buffer;
        }
示例#3
0
        public void FinishRecording()
        {
            if (m_ActivePlaybackBuffer == null)
            {
                RecycleRecordedBuffers();
                return;
            }

            var bufferCount = m_RecordedBuffers.Count;

            if (string.IsNullOrEmpty(m_ActivePlaybackBuffer.name) || bufferCount == 0)
            {
                RecycleRecordedBuffers();
                m_ActivePlaybackBuffer = null;
                return;
            }

            var recordStream = new byte[bufferCount * m_CurrentBufferSize];

            m_ActivePlaybackBuffer.recordStream = recordStream;
            for (var i = 0; i < bufferCount; i++)
            {
                var buffer = m_RecordedBuffers[i];
                Buffer.BlockCopy(buffer, 0, recordStream, i * m_CurrentBufferSize, m_CurrentBufferSize);
                m_BufferQueue.Enqueue(buffer);
            }

            var length  = m_PlaybackBuffers.Length;
            var buffers = new PlaybackBuffer[length + 1];

            for (var i = 0; i < length; i++)
            {
                buffers[i] = m_PlaybackBuffers[i];
            }

            buffers[length]   = m_ActivePlaybackBuffer;
            m_PlaybackBuffers = buffers;

            m_ActivePlaybackBuffer = null;

#if UNITY_EDITOR
            EditorUtility.SetDirty(this);
#endif
        }