Веб-сайт самохостера Lotigara

summaryrefslogtreecommitdiff
path: root/source/core/StarIODeviceCallbacks.cpp
blob: ca8b692a2333db509e6075813670e5f3907ed4ef (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
#include "StarIODeviceCallbacks.hpp"
#include "vorbis/vorbisfile.h"

namespace Star {

IODeviceCallbacks::IODeviceCallbacks(IODevicePtr device) 
  : m_device(std::move(device)) {
  if (!m_device->isOpen())
    m_device->open(IOMode::Read);
}

IODevicePtr const& IODeviceCallbacks::device() const {
  return m_device;
}

size_t IODeviceCallbacks::readFunc(void* ptr, size_t size, size_t nmemb, void* datasource) {
  auto* callbacks = static_cast<IODeviceCallbacks*>(datasource);
  return callbacks->m_device->read((char*)ptr, size * nmemb) / size;
}

int IODeviceCallbacks::seekFunc(void* datasource, ogg_int64_t offset, int whence) {
  auto* callbacks = static_cast<IODeviceCallbacks*>(datasource);
  callbacks->m_device->seek(offset, (IOSeek)whence);
  return 0;
}

long int IODeviceCallbacks::tellFunc(void* datasource) {
  auto* callbacks = static_cast<IODeviceCallbacks*>(datasource);
  return (long int)callbacks->m_device->pos();
}

void IODeviceCallbacks::setupOggCallbacks(ov_callbacks& callbacks) {
  callbacks.read_func = readFunc;
  callbacks.seek_func = seekFunc;
  callbacks.tell_func = tellFunc;
  callbacks.close_func = nullptr;
}

}