libpromeki 1.0.0-alpha
PROfessional MEdia toolKIt
 
Loading...
Searching...
No Matches
audiofilemediaio.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/audiodesc.h>
14#include <promeki/audiofile.h>
16#include <promeki/framenumber.h>
17#include <promeki/framerate.h>
19#include <promeki/namespace.h>
20
21PROMEKI_NAMESPACE_BEGIN
22
51class AudioFileMediaIO : public DedicatedThreadMediaIO {
52 PROMEKI_OBJECT(AudioFileMediaIO, DedicatedThreadMediaIO)
53 public:
55 AudioFileMediaIO(ObjectBase *parent = nullptr);
56
58 ~AudioFileMediaIO() override;
59
60 Error proposeInput(const MediaDesc &offered, MediaDesc *preferred) const override;
61
62 protected:
63 Error executeCmd(MediaIOCommandOpen &cmd) override;
64 Error executeCmd(MediaIOCommandClose &cmd) override;
65 Error executeCmd(MediaIOCommandRead &cmd) override;
66 Error executeCmd(MediaIOCommandWrite &cmd) override;
67 Error executeCmd(MediaIOCommandSeek &cmd) override;
68
69 private:
70 // Returns the AudioFormat::ID libsndfile prefers for
71 // @p filename's extension, picking the closest form to
72 // @p source so the inserted SRC bridge does not drop bit
73 // depth (e.g. 24-bit source stays 24-bit through a BWF
74 // write).
75 AudioFormat::ID preferredWriterDataType(const String &filename, AudioFormat::ID source) const;
76
77 AudioFile _audioFile;
78 FrameRate _frameRate;
79 AudioDesc _audioDesc;
80 bool _isOpen = false;
81 bool _isWrite = false;
82 size_t _samplesPerFrame = 0;
83 FrameNumber _currentFrame{0};
84 FrameCount _totalFrames{0};
85};
86
91class AudioFileFactory : public MediaIOFactory {
92 public:
93 AudioFileFactory() = default;
94
95 String name() const override { return String("AudioFile"); }
96 String displayName() const override { return String("Audio File"); }
97 String description() const override {
98 return String("Audio file formats via libsndfile (WAV, BWF, AIFF"
99#if PROMEKI_ENABLE_VORBIS
100 ", OGG"
101#endif
102#if PROMEKI_ENABLE_FLAC
103 ", FLAC"
104#endif
105#if PROMEKI_ENABLE_MP3
106 ", MP3"
107#endif
108 ")");
109 }
110 StringList extensions() const override {
111 // The factory advertises every extension the
112 // libsndfile backend can probe at this build
113 // configuration; runtime feature gating (the
114 // vendored libsndfile's own MPEG/Vorbis/FLAC
115 // toggles) is handled inside
116 // @ref AudioFileFactory_LibSndFile, which
117 // intersects this list against libsndfile's
118 // reported major-format set. Keeping this
119 // header gated on the @c PROMEKI_ENABLE_*
120 // flags matches the same flags that compile
121 // the codec wiring in.
122 StringList exts{String("wav"), String("bwf"), String("aiff"), String("aif")};
123#if PROMEKI_ENABLE_VORBIS
124 exts.pushToBack(String("ogg"));
125 exts.pushToBack(String("oga"));
126#endif
127#if PROMEKI_ENABLE_FLAC
128 exts.pushToBack(String("flac"));
129#endif
130#if PROMEKI_ENABLE_MP3
131 exts.pushToBack(String("mp3"));
132 exts.pushToBack(String("mpeg"));
133#endif
134 return exts;
135 }
136
137 bool canBeSource() const override { return true; }
138 bool canBeSink() const override { return true; }
139
140 bool canHandleDevice(IODevice *device) const override;
141 Config::SpecMap configSpecs() const override;
142 Metadata defaultMetadata() const override;
143
144 MediaIO *create(const Config &config, ObjectBase *parent = nullptr) const override;
145};
146
147PROMEKI_NAMESPACE_END
148
149#endif // PROMEKI_ENABLE_PROAV