Loading...
Searching...
No Matches
AudioDecoder.hpp
1#pragma once
2#include <Process/TimeValue.hpp>
3
4#include <Media/AudioArray.hpp>
5
6#include <ossia/detail/flicks.hpp>
7#include <ossia/detail/optional.hpp>
8
9#include <QThread>
10
11#include <score_plugin_media_export.h>
12
13#include <atomic>
14#include <vector>
15#include <verdigris>
16
17struct AVFrame;
18struct SwrContext;
19
20namespace Media
21{
23{
24 int32_t audioStream{-1};
25 int32_t fileRate{};
26 int32_t convertedRate{};
27 int64_t channels{};
28 int64_t fileLength{};
29 int64_t convertedLength{};
30 int64_t max_arr_length{};
31 std::optional<double> tempo;
32
33 // Duration
34 TimeVal duration() const noexcept;
35};
36
37class SCORE_PLUGIN_MEDIA_EXPORT AudioDecoder : public QObject
38{
39 W_OBJECT(AudioDecoder)
40
41public:
42 AudioDecoder(int rate);
44 static std::optional<AudioInfo> do_probe(const QString& path);
45 void decode(const QString& path, int track, audio_handle hdl);
46
47 static std::optional<std::pair<AudioInfo, audio_array>>
48 decode_synchronous(const QString& path, int rate);
49
50 static QHash<QString, AudioInfo>& database();
51
52 int32_t fileSampleRate{};
53 int32_t convertedSampleRate{};
54 int32_t channels{};
55 int32_t track{-1};
56 std::size_t decoded{};
57
58public:
59 void newData() W_SIGNAL(newData);
60 void finishedDecoding(audio_handle hdl) W_SIGNAL(finishedDecoding, hdl);
61
62 void startDecode(QString str, audio_handle hdl) W_SIGNAL(startDecode, str, hdl);
63
64public:
65 void on_startDecode(QString, audio_handle hdl);
66 W_SLOT(on_startDecode);
67
68private:
69 static double read_length(const QString& path);
70
71 QThread* m_baseThread{};
72 QThread m_decodeThread;
73
74 template <typename Decoder>
75 void decodeFrame(Decoder dec, audio_array& data, AVFrame& frame);
76
77 template <typename Decoder>
78 void decodeRemaining(Decoder dec, audio_array& data, AVFrame& frame);
79 std::vector<SwrContext*> resampler;
80 void initResample();
81};
82}
Definition AudioDecoder.hpp:38
Definition AudioDecoder.hpp:23
Definition TimeValue.hpp:21