summaryrefslogtreecommitdiff
path: root/Audio/AudioStreamDescriptor.hpp
blob: 9193c321ca89dc9ce14bc44d8cde72e2bedb806b (plain)
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
92
93
94
95
96
97
98
// -*- Mode: C++ -*-
#ifndef AUDIO_STREAM_DESCRIPTOR_HPP__
#define AUDIO_STREAM_DESCRIPTOR_HPP__

#include <QMetaType>

class QAudioFormat;

struct AudioStreamDescriptor
{
  enum class SampleEncoding
  {
    Unknown,
    SignedInteger,
    UnsignedInteger,
    FloatingPoint
  };

  enum class ByteOrder
  {
    Unknown,
    LittleEndian,
    BigEndian
  };

  enum class ChannelLayout
  {
    Unknown,
    Mono,
    Stereo
  };

  enum class ClockDomain
  {
    Unknown,
    DeviceClock,
    SystemClock
  };

  enum class TimingEvidence
  {
    Unavailable,
    PositionCountable,
    CaptureTimeAnchored
  };

  int sample_rate_hz {0};
  SampleEncoding sample_encoding {SampleEncoding::Unknown};
  int sample_size_bits {0};
  ByteOrder byte_order {ByteOrder::Unknown};
  int channel_count {0};
  ChannelLayout channel_layout {ChannelLayout::Unknown};
  ClockDomain clock_domain {ClockDomain::Unknown};
  TimingEvidence timing_evidence {TimingEvidence::Unavailable};

  // UTC timestamp for the first frame in this descriptor epoch, when anchored.
  qint64 capture_anchor_utc_ms {0};

  // True only when the source has a mechanism for reporting discontinuities.
  bool can_report_discontinuities {false};

  bool isValid () const noexcept
  {
    return sample_rate_hz > 0
      && SampleEncoding::Unknown != sample_encoding
      && sample_size_bits > 0
      && (sample_size_bits <= 8 || ByteOrder::Unknown != byte_order)
      && channel_count > 0;
  }
};

inline bool operator== (AudioStreamDescriptor const& lhs,
                        AudioStreamDescriptor const& rhs) noexcept
{
  return lhs.sample_rate_hz == rhs.sample_rate_hz
    && lhs.sample_encoding == rhs.sample_encoding
    && lhs.sample_size_bits == rhs.sample_size_bits
    && lhs.byte_order == rhs.byte_order
    && lhs.channel_count == rhs.channel_count
    && lhs.channel_layout == rhs.channel_layout
    && lhs.clock_domain == rhs.clock_domain
    && lhs.timing_evidence == rhs.timing_evidence
    && lhs.capture_anchor_utc_ms == rhs.capture_anchor_utc_ms
    && lhs.can_report_discontinuities == rhs.can_report_discontinuities;
}

inline bool operator!= (AudioStreamDescriptor const& lhs,
                        AudioStreamDescriptor const& rhs) noexcept
{
  return !(lhs == rhs);
}

AudioStreamDescriptor audioStreamDescriptorFromQAudioFormat (
  QAudioFormat const& format);

Q_DECLARE_METATYPE (AudioStreamDescriptor)

#endif