summaryrefslogtreecommitdiff
path: root/src/audio/include/audio_decoder.hpp
blob: e8da415ed0ec23e252b52abbc1d6c851f8281704 (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
41
42
43
44
45
46
47
48
49
50
51
/*
 * Copyright 2023 jacqueline <me@jacqueline.id.au>
 *
 * SPDX-License-Identifier: GPL-3.0-only
 */

#pragma once

#include <cstddef>
#include <cstdint>
#include <memory>
#include <vector>

#include "chunk.hpp"
#include "ff.h"
#include "span.hpp"

#include "audio_element.hpp"
#include "codec.hpp"
#include "stream_info.hpp"

namespace audio {

/*
 * An audio element that accepts various kinds of encoded audio streams as
 * input, and converts them to uncompressed PCM output.
 */
class AudioDecoder {
 public:
  AudioDecoder();
  ~AudioDecoder();

  auto Process(const InputStream& input, OutputStream* output) -> void;

  AudioDecoder(const AudioDecoder&) = delete;
  AudioDecoder& operator=(const AudioDecoder&) = delete;

 private:
  std::unique_ptr<codecs::ICodec> current_codec_;
  std::optional<StreamInfo::Encoded> current_input_format_;
  std::optional<StreamInfo::Format> current_output_format_;
  std::optional<std::size_t> duration_seconds_from_decoder_;
  std::optional<std::size_t> seek_to_sample_;
  bool has_prepared_output_;
  bool has_samples_to_send_;
  bool has_input_remaining_;

  auto ProcessStreamInfo(const StreamInfo& info) -> bool;
};

}  // namespace audio