summaryrefslogtreecommitdiff
path: root/src/tangara/audio/fatfs_source.hpp
blob: 3265088084e8440369019e2e5af4273b72acf7f7 (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
/*
 * Copyright 2023 jacqueline <me@jacqueline.id.au>
 *
 * SPDX-License-Identifier: GPL-3.0-only
 */

#pragma once

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

#include "codec.hpp"
#include "ff.h"

#include "audio/audio_source.hpp"

namespace audio {

/*
 * Handles coordination with a persistent background task to asynchronously
 * read files from disk into a StreamBuffer.
 */
class FatfsSource : public codecs::IStream {
 public:
  FatfsSource(codecs::StreamType, std::unique_ptr<FIL> file);
  ~FatfsSource();

  auto Read(std::span<std::byte> dest) -> ssize_t override;

  auto CanSeek() -> bool override;

  auto SeekTo(int64_t destination, SeekFrom from) -> void override;

  auto CurrentPosition() -> int64_t override;

  auto Size() -> std::optional<int64_t> override;

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

 private:
  std::unique_ptr<FIL> file_;
};

}  // namespace audio