libpromeki 1.0.0-alpha
PROfessional MEdia toolKIt
 
Loading...
Searching...
No Matches
audiodecodermediaio.h
Go to the documentation of this file.
1
8#pragma once
9
10
11#include <promeki/config.h>
12#if PROMEKI_ENABLE_PROAV
13#include <promeki/namespace.h>
16#include <promeki/mediaconfig.h>
18#include <promeki/audiocodec.h>
19#include <promeki/audioformat.h>
20#include <promeki/string.h>
21
22PROMEKI_NAMESPACE_BEGIN
23
92class AudioDecoderMediaIO : public SharedThreadMediaIO {
93 PROMEKI_OBJECT(AudioDecoderMediaIO, SharedThreadMediaIO)
94 public:
96 static inline const MediaIOStats::ID StatsPacketsDecoded{"PacketsDecoded"};
97
99 static inline const MediaIOStats::ID StatsFramesOut{"FramesOut"};
100
101 AudioDecoderMediaIO(ObjectBase *parent = nullptr);
102 ~AudioDecoderMediaIO() override;
103
104 Error describe(MediaIODescription *out) const override;
105 Error proposeInput(const MediaDesc &offered, MediaDesc *preferred) const override;
106 Error proposeOutput(const MediaDesc &requested, MediaDesc *achievable,
107 MediaConfig *configDelta = nullptr) const override;
108 int pendingInternalWrites() const override;
109
110 protected:
111 Error executeCmd(MediaIOCommandOpen &cmd) override;
112 Error executeCmd(MediaIOCommandClose &cmd) override;
113 Error executeCmd(MediaIOCommandRead &cmd) override;
114 Error executeCmd(MediaIOCommandWrite &cmd) override;
115 Error executeCmd(MediaIOCommandStats &cmd) override;
116 void configChanged(const MediaConfig &delta) override;
117
118 private:
119 // Drains every currently-available output Frame out of
120 // the underlying decoder and pushes them onto
121 // @c _outputQueue. The decoder is responsible for
122 // echoing the source Frame's video / metadata through
123 // onto each emitted Frame via the base
124 // @ref AudioDecoder::buildOutputFrame helper.
125 void drainDecoderInto();
126 // Converts any decoded PCM audio payload on @p in to the
127 // advertised @c _outputAudioDataType when the codec emitted a
128 // different native format. Returns @p in untouched when no
129 // conversion is needed.
130 Frame coerceOutputFormat(Frame in);
131 Error createDecoder(const AudioCodec &codec);
132
133 MediaConfig _config;
134 AudioCodec _codec;
135 AudioDecoder::UPtr _decoder;
136 AudioFormat::ID _outputAudioDataType = AudioFormat::Invalid;
137 bool _outputAudioDataTypeSet = false;
138 int _capacity = 8;
139 Frame::List _outputQueue;
140 FrameCount _frameCount{0};
141 int64_t _readCount = 0;
142 int64_t _packetsDecoded = 0;
143 int64_t _framesOut = 0;
144 bool _capacityWarned = false;
145 bool _closed = false;
146};
147
152class AudioDecoderFactory : public MediaIOFactory {
153 public:
154 AudioDecoderFactory() = default;
155
156 String name() const override { return String("AudioDecoder"); }
157 String displayName() const override { return String("Audio Decoder"); }
158 String description() const override {
159 return String("Decodes compressed audio bitstreams into PCM frames");
160 }
161 bool canBeTransform() const override { return true; }
162
163 Config::SpecMap configSpecs() const override;
164 bool bridge(const MediaDesc &from, const MediaDesc &to, Config *outConfig,
165 int *outCost) const override;
166 MediaIO *create(const Config &config, ObjectBase *parent = nullptr) const override;
167};
168
169PROMEKI_NAMESPACE_END
170
171#endif // PROMEKI_ENABLE_PROAV