/// <summary>
        /// Starts to record the current stream. The stream must have been
        /// initialized when calling this method by using the method
        /// <see cref="StartGenerating"/>.
        /// </summary>
        /// <param name="captureFolder">The folder to create to recording in.</param>
        /// <param name="SaveUserPosition">Whether to record the user position
        /// in a separate file.</param>
        /// <exception cref="Exception">Thrown if initialization of the recording
        /// fails.</exception>
        internal void StartRecording(DirectoryInfo captureFolder, bool SaveUserPosition)
        {
            lock (RUN_CONTROL_LOCK)
            {
                if (!shouldRun || recording)
                {
                    return;
                }
                else
                {
                    // Change display options to get possibly smooth
                    // recording.W
                    shouldDrawBackground = true;
                    shouldDrawHighlight  = false;
                    shouldDrawPixels     = false;
                    shouldDrawSkeleton   = true;

                    // Setup datastructures for recording.
                    movementData = new ImageDictionary(true);
                    if (SaveUserPosition)
                    {
                        Stream file_stream = new FileStream(
                            Path.Combine(captureFolder.FullName, MAP_FILE_NAME), FileMode.Create);
                        Stream write_stream;
                        if (COMPRESS_USER_DATA)
                        {
                            write_stream = file_stream;
                        }
                        else
                        {
                            write_stream = file_stream;
                        }
                        // A writer for the user data file.
                        userInformationWriter = new BinaryWriter(write_stream);
                    }


                    lock (HARDWARELOCK)
                    {
                        recorder = new Recorder(context);
                        recorder.SetDestination(RecordMedium.File,
                                                Path.Combine(captureFolder.FullName, ONI_FILE_NAME));
                        recorder.AddNodeToRecording(imageGenerator);
                        recorder.AddNodeToRecording(depthGenerator);
                    }

                    FileInfo movementDataFileInfo = new FileInfo(
                        Path.Combine(captureFolder.FullName,
                                     USER_ANNOTATION_FILENAME));
                    movementDataFileName = movementDataFileInfo.FullName;
                }
                recording = true;
                onStartedRecording();
            }
        }