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 enum Flag : int32_t
25 {
26 DrwavCanDecode = (1 << 0),
27 SndfileCanDecode = (1 << 1),
28 LibavCanDecode = (1 << 2),
29 };
30
31 int32_t flags{};
32 int32_t audioStream{-1};
33 int32_t fileRate{};
34 int32_t convertedRate{};
35 int64_t channels{};
36 int64_t fileLength{};
37 int64_t convertedLength{};
38 int64_t max_arr_length{};
39 std::optional<double> tempo;
40
41 // Duration
42 TimeVal duration() const noexcept;
43};
44
45class SCORE_PLUGIN_MEDIA_EXPORT AudioDecoder : public QObject
46{
47 W_OBJECT(AudioDecoder)
48
49public:
50 AudioDecoder(int rate);
52 static std::optional<AudioInfo> do_probe(const QString& path);
53 void decode(const QString& path, int track, audio_handle hdl);
54
55 static std::optional<std::pair<AudioInfo, audio_array>>
56 decode_synchronous(const QString& path, int rate);
57
60 static std::optional<AudioInfo> find_info(const QString& path);
61 static void store_info(const QString& path, const AudioInfo& info);
62
63 int32_t fileSampleRate{};
64 int32_t convertedSampleRate{};
65 int32_t channels{};
66 int32_t track{-1};
70 std::atomic<std::size_t> decoded{};
73 std::size_t produced{};
74
75public:
76 void newData() W_SIGNAL(newData);
77 void finishedDecoding(audio_handle hdl) W_SIGNAL(finishedDecoding, hdl);
78
79 void startDecode(QString str, audio_handle hdl) W_SIGNAL(startDecode, str, hdl);
80
81public:
82 void on_startDecode(QString, audio_handle hdl);
83 W_SLOT(on_startDecode);
84
85private:
86 static double read_length(const QString& path);
87
88 QThread* m_baseThread{};
89 QThread m_decodeThread;
90
91 template <typename Decoder>
92 void decodeFrame(Decoder dec, audio_array& data, AVFrame& frame);
93
94 template <typename Decoder>
95 void decodeRemaining(Decoder dec, audio_array& data, AVFrame& frame);
96 std::vector<SwrContext*> resampler;
97 void initResample();
98};
99}
Definition AudioDecoder.hpp:46
Definition AudioDecoder.hpp:23
Definition TimeValue.hpp:21