/// <summary>
        /// Initialize the attributes of the capture session and start capture.
        /// </summary>
        public override void StartCapture()
        {
            if (status != StatusType.NOT_START &&
                status != StatusType.FINISH)
            {
                Debug.LogWarning("[VideoCaptureCtrl::StartCapture] Previous " +
                                 " capture not finish yet!");
                return;
            }
            // Filter out disabled capture component.
            List <VideoCapture> validCaptures = new List <VideoCapture>();

            if (videoCaptures != null && videoCaptures.Length > 0)
            {
                foreach (VideoCapture videoCapture in videoCaptures)
                {
                    if (videoCapture != null && videoCapture.gameObject.activeSelf)
                    {
                        validCaptures.Add(videoCapture);
                    }
                }
            }
            videoCaptures = validCaptures.ToArray();
            // Cache those value, thread cannot access unity's object.
            isCaptureAudio = false;
            if (audioCapture != null && audioCapture.gameObject.activeSelf)
            {
                isCaptureAudio = true;
            }
            // Check if can start a capture session.
            if (!isCaptureAudio && videoCaptures.Length == 0)
            {
                Debug.LogError(
                    "[VideoCaptureCtrl::StartCapture] StartCapture called " +
                    "but no attached VideoRecorder or AudioRecorder were found!"
                    );
                return;
            }
            if (!File.Exists(PathConfig.ffmpegPath))
            {
                Debug.LogError(
                    "[VideoCaptureCtrl::StartCapture] FFmpeg not found, please add " +
                    "ffmpeg executable before start capture!"
                    );
                return;
            }
            // Loop through each of the video capture component, initialize
            // and start recording session.
            videoCaptureRequiredCount = 0;
            for (int i = 0; i < videoCaptures.Length; i++)
            {
                VideoCapture videoCapture = (VideoCapture)videoCaptures[i];
                if (videoCapture == null || !videoCapture.gameObject.activeSelf)
                {
                    continue;
                }
                videoCaptureRequiredCount++;
                if (videoCapture.status != StatusType.NOT_START &&
                    videoCapture.status != StatusType.FINISH)
                {
                    return;
                }
                if (videoCapture.offlineRender)
                {
                    isOfflineRender = true;
                }
                videoCapture.StartCapture();
                videoCapture.eventDelegate.OnComplete += OnVideoCaptureComplete;
            }
            // Check if record audio.
            if (IsCaptureAudio())
            {
                audioCapture.StartCapture();
                audioCapture.eventDelegate.OnComplete += OnAudioCaptureComplete;
            }
            // Reset record session count.
            videoCaptureFinishCount = 0;
            // Start garbage collect thread.
            garbageCollectionThread              = new Thread(GarbageCollectionThreadFunction);
            garbageCollectionThread.Priority     = System.Threading.ThreadPriority.Lowest;
            garbageCollectionThread.IsBackground = true;
            garbageCollectionThread.Start();
            // Update current status.
            status = StatusType.STARTED;
        }
Example #2
0
 /// <summary>
 /// Initializes a new instance of the <see cref="T:RockVR.Video.VideoMuxing"/> class.
 /// </summary>
 /// <param name="videoCapture">Video capture.</param>
 /// <param name="audioCapture">Audio capture.</param>
 public VideoMuxing(VideoCapture videoCapture, AudioCapture audioCapture)
 {
     this.videoCapture = videoCapture;
     this.audioCapture = audioCapture;
 }