forked from adamrehn/MediaIPC
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathControlBlock.h
91 lines (62 loc) · 2.42 KB
/
ControlBlock.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#ifndef _MEDIA_IPC_CONTROL_BLOCK
#define _MEDIA_IPC_CONTROL_BLOCK
#include "Formats.h"
#include <stdint.h>
#include <chrono>
namespace MediaIPC {
enum class VideoBuffer : uint8_t
{
FrontBuffer = 0,
BackBuffer = 1
};
class ControlBlock
{
public:
//Creates a blank control block
//(Note that the relevant video and/or audio parameters will need to be set before the control block can be used)
ControlBlock();
//Determines the number of bytes required to hold the video framebuffer, based on our video parameters
uint64_t calculateVideoBufsize() const;
//Determines the number of bytes required to hold the audio sample buffer, based on our audio parameters
uint64_t calculateAudioBufsize() const;
//Determines the interval in microseconds for sampling the video framebuffer, based on our video parameters
std::chrono::microseconds calculateVideoInterval() const;
//Determines the interval in microseconds for sampling the audio sample buffer, based on our audio parameters
std::chrono::microseconds calculateAudioInterval() const;
//---- VIDEO PARAMETERS ----
//The width of the video in pixels
uint32_t width;
//The height of the video in pixels
uint32_t height;
//The number of video frames per second
uint32_t frameRate;
//The pixel format of the video
VideoFormat videoFormat;
//---- AUDIO PARAMETERS ----
//The number of audio channels
uint32_t channels;
//The number of audio samples per second
uint32_t sampleRate;
//The number of samples we want to process together in a batch
//(A value of 1 means we don't perform any batching at all)
uint32_t samplesPerBuffer;
//The format of the audio samples
AudioFormat audioFormat;
private:
//---- CONTROL FLAGS ----
//(These are used internally by the MediaProducer and MediaConsumer classes)
friend class MediaConsumer;
friend class MediaProducer;
//Is the producer currently producing data?
//(Access to this flag is protected by the "status" mutex)
//(The "status" mutex also controls the initial access to the entire control block)
bool active;
//Was the front framebuffer or the back framebuffer most recently updated?
//(Access to this flag is protected by the "video" mutex)
VideoBuffer lastBuffer;
//The current head position of the audio ring buffer
//(Access to this flag is protected by the "audio" mutex)
uint32_t ringHead;
};
} //End MediaIPC
#endif