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 Error createDecoder(const AudioCodec &codec);
127
128 MediaConfig _config;
129 AudioCodec _codec;
130 AudioDecoder::UPtr _decoder;
131 AudioFormat::ID _outputAudioDataType = AudioFormat::Invalid;
132 bool _outputAudioDataTypeSet = false;
133 int _capacity = 8;
134 Frame::List _outputQueue;
135 FrameCount _frameCount{0};
136 int64_t _readCount = 0;
137 int64_t _packetsDecoded = 0;
138 int64_t _framesOut = 0;
139 bool _capacityWarned = false;
140 bool _closed = false;
141};
142
147class AudioDecoderFactory : public MediaIOFactory {
148 public:
149 AudioDecoderFactory() = default;
150
151 String name() const override { return String("AudioDecoder"); }
152 String displayName() const override { return String("Audio Decoder"); }
153 String description() const override {
154 return String("Decodes compressed audio bitstreams into PCM frames");
155 }
156 bool canBeTransform() const override { return true; }
157
158 Config::SpecMap configSpecs() const override;
159 bool bridge(const MediaDesc &from, const MediaDesc &to, Config *outConfig,
160 int *outCost) const override;
161 MediaIO *create(const Config &config, ObjectBase *parent = nullptr) const override;
162};
163
164PROMEKI_NAMESPACE_END
165
166#endif // PROMEKI_ENABLE_PROAV