Overte C++ Documentation
Recorder.h
1 //
2 // Created by Bradley Austin Davis 2015/11/05
3 // Copyright 2015 High Fidelity, Inc.
4 //
5 // Distributed under the Apache License, Version 2.0.
6 // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
7 //
8 
9 #pragma once
10 #ifndef hifi_Recording_Recorder_h
11 #define hifi_Recording_Recorder_h
12 
13 #include <mutex>
14 
15 #include <QtCore/QObject>
16 #include <QtCore/QElapsedTimer>
17 
18 #include <DependencyManager.h>
19 
20 #include "Forward.h"
21 
22 namespace recording {
23 
24 // An interface for interacting with clips, creating them by recording or
25 // playing them back. Also serialization to and from files / network sources
26 class Recorder : public QObject, public Dependency {
27  Q_OBJECT
28 public:
29  Recorder(QObject* parent = nullptr);
30 
31  float position();
32 
33  // Start recording frames
34  void start();
35  // Stop recording
36  void stop();
37 
38  // Test if recording is active
39  bool isRecording();
40 
41  // Erase the currently recorded content
42  void clear();
43 
44  void recordFrame(FrameType type, QByteArray frameData);
45 
46  // Return the currently recorded content
47  ClipPointer getClip();
48 
49 signals:
50  void recordingStateChanged();
51 
52 private:
53  using Mutex = std::recursive_mutex;
54  using Locker = std::unique_lock<Mutex>;
55 
56  Mutex _mutex;
57  QElapsedTimer _timer;
58  ClipPointer _clip;
59  quint64 _elapsed { 0 };
60  quint64 _startEpoch { 0 };
61  bool _recording { false };
62 };
63 
64 }
65 
66 #endif