diff options
Diffstat (limited to 'src/codecs/include')
| -rw-r--r-- | src/codecs/include/codec.hpp | 90 | ||||
| -rw-r--r-- | src/codecs/include/mad.hpp | 32 | ||||
| -rw-r--r-- | src/codecs/include/types.hpp | 12 |
3 files changed, 69 insertions, 65 deletions
diff --git a/src/codecs/include/codec.hpp b/src/codecs/include/codec.hpp index 99e786d5..8e82bd71 100644 --- a/src/codecs/include/codec.hpp +++ b/src/codecs/include/codec.hpp @@ -8,51 +8,53 @@ namespace codecs { - enum CreateCodecError { - UNKNOWN_EXTENSION +enum CreateCodecError { UNKNOWN_EXTENSION }; + +auto CreateCodecForFile(const std::string& extension) + -> cpp::result<std::unique_ptr<ICodec>, CreateCodecError>; + +class ICodec { + public: + virtual ~ICodec() {} + + virtual auto CanHandleFile(const std::string& path) -> bool = 0; + + struct OutputFormat { + uint8_t num_channels; + uint8_t bits_per_sample; + int sample_rate_hz; }; - auto CreateCodecForExtension(std::string extension) -> cpp::result<std::unique_ptr<ICodec>, CreateCodecError>; - - class ICodec { - public: - virtual ~ICodec() {} - - virtual auto CanHandleExtension(std::string extension) -> bool = 0; - - struct OutputFormat { - uint8_t num_channels; - uint8_t bits_per_sample; - int sample_rate_hz; - }; - - virtual auto GetOutputFormat() -> OutputFormat = 0; - - enum Error {}; - - struct Result { - bool need_more_input; - /* - * For need_more_input, this is how far we got in the input buffer - * before we were unable to process more data. Any remaining data in the - * buffer should be moved to the start before the next call. - */ - std::size_t input_processed; - - bool flush_output; - /* - * For flush_output, this is how far we got in the output buffer before - * we ran out of space for samples. The caller should flush this many - * bytes downstream. - */ - std::size_t output_written; - }; - - virtual auto Process( - uint8_t *input, - std::size_t input_len, - uint8_t *output, - std::size_t output_length) -> cpp::result<Result, Error> = 0; + virtual auto GetOutputFormat() -> OutputFormat = 0; + + enum ProcessingError {}; + + struct Result { + bool need_more_input; + /* + * For need_more_input, this is how far we got in the input buffer + * before we were unable to process more data. Any remaining data in the + * buffer should be moved to the start before the next call. + */ + std::size_t input_processed; + + bool flush_output; + /* + * For flush_output, this is how far we got in the output buffer before + * we ran out of space for samples. The caller should flush this many + * bytes downstream. + */ + std::size_t output_written; }; -} // namespace codecs + virtual auto ResetForNewStream() -> void = 0; + + virtual auto SetInput(uint8_t* buffer, std::size_t length) = 0; + virtual auto Process(uint8_t* output, std::size_t output_length) + -> cpp::result<size_t, Error> = 0; + + virtual auto GetOutputProcessed() -> std::size_t; + = 0; +}; + +} // namespace codecs diff --git a/src/codecs/include/mad.hpp b/src/codecs/include/mad.hpp index cfe4eab7..241ea6c3 100644 --- a/src/codecs/include/mad.hpp +++ b/src/codecs/include/mad.hpp @@ -4,23 +4,25 @@ namespace codecs { - class MadMp3Decoder : public ICodec { - public: - MadMp3Decoder(); - ~MadMp3Decoder(); +class MadMp3Decoder : public ICodec { + public: + MadMp3Decoder(); + ~MadMp3Decoder(); - auto ProcessInput(Result *res, uint8_t *input, std::size_t input_len) -> void; - auto WriteOutputSamples(Result *res, uint8_t *output, std::size_t output_length) -> void; + auto ProcessInput(Result* res, uint8_t* input, std::size_t input_len) -> void; + auto WriteOutputSamples(Result* res, + uint8_t* output, + std::size_t output_length) -> void; - private: - mad_stream stream_; - mad_frame frame_; - mad_synth synth_; + private: + mad_stream stream_; + mad_frame frame_; + mad_synth synth_; - mad_header header_; - bool has_decoded_header_; + mad_header header_; + bool has_decoded_header_; - int current_sample_ = -1; - }; + int current_sample_ = -1; +}; -} // namespace codecs +} // namespace codecs diff --git a/src/codecs/include/types.hpp b/src/codecs/include/types.hpp index 8525a136..a962cf68 100644 --- a/src/codecs/include/types.hpp +++ b/src/codecs/include/types.hpp @@ -2,11 +2,11 @@ #include <string> -namespace codecs { +namespace codecs { - enum StreamType { - STREAM_MP3, - }; +enum StreamType { + STREAM_MP3, +}; - auto GetStreamTypeFromFilename(std::string filename); -} +auto GetStreamTypeFromFilename(std::string filename); +} // namespace codecs |
