summaryrefslogtreecommitdiff
path: root/src/codecs/include/mad.hpp
blob: 074784fb3d3f5a438a6a4a90a88c5fe3f4c90f48 (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
#pragma once

#include <cstddef>
#include <cstdint>
#include <string>
#include <utility>

#include "mad.h"
#include "span.hpp"

#include "codec.hpp"

namespace codecs {

class MadMp3Decoder : public ICodec {
 public:
  MadMp3Decoder();
  ~MadMp3Decoder();

  auto CanHandleType(StreamType type) -> bool override;
  auto GetOutputFormat() -> OutputFormat override;
  auto ResetForNewStream() -> void override;
  auto SetInput(cpp::span<const std::byte> input) -> void override;
  auto GetInputPosition() -> std::size_t override;
  auto ProcessNextFrame() -> cpp::result<bool, ProcessingError> override;
  auto WriteOutputSamples(cpp::span<std::byte> output)
      -> std::pair<std::size_t, bool> override;

 private:
  mad_stream stream_;
  mad_frame frame_;
  mad_synth synth_;

  mad_header header_;
  bool has_decoded_header_;

  int current_sample_;
};

}  // namespace codecs