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 
17 struct AVFrame;
18 struct SwrContext;
19 
20 namespace Media
21 {
22 struct AudioInfo
23 {
24  int32_t fileRate{};
25  int32_t convertedRate{};
26  int64_t channels{};
27  int64_t fileLength{};
28  int64_t convertedLength{};
29  int64_t max_arr_length{};
30  std::optional<double> tempo;
31 
32  // Duration
33  TimeVal duration() const noexcept;
34 };
35 
36 class SCORE_PLUGIN_MEDIA_EXPORT AudioDecoder : public QObject
37 {
38  W_OBJECT(AudioDecoder)
39 
40 public:
41  AudioDecoder(int rate);
42  ~AudioDecoder();
43  static std::optional<AudioInfo> do_probe(const QString& path);
44  void decode(const QString& path, int track, audio_handle hdl);
45 
46  static std::optional<std::pair<AudioInfo, audio_array>>
47  decode_synchronous(const QString& path, int rate);
48 
49  static QHash<QString, AudioInfo>& database();
50 
51  int32_t fileSampleRate{};
52  int32_t convertedSampleRate{};
53  int32_t channels{};
54  int32_t track{-1};
55  std::size_t decoded{};
56 
57 public:
58  void newData() W_SIGNAL(newData);
59  void finishedDecoding(audio_handle hdl) W_SIGNAL(finishedDecoding, hdl);
60 
61  void startDecode(QString str, audio_handle hdl) W_SIGNAL(startDecode, str, hdl);
62 
63 public:
64  void on_startDecode(QString, audio_handle hdl);
65  W_SLOT(on_startDecode);
66 
67 private:
68  static double read_length(const QString& path);
69 
70  QThread* m_baseThread{};
71  QThread m_decodeThread;
72 
73  template <typename Decoder>
74  void decodeFrame(Decoder dec, audio_array& data, AVFrame& frame);
75 
76  template <typename Decoder>
77  void decodeRemaining(Decoder dec, audio_array& data, AVFrame& frame);
78  std::vector<SwrContext*> resampler;
79  void initResample();
80 };
81 }
Definition: AudioDecoder.hpp:37
Definition: AudioDecoder.hpp:23
Definition: TimeValue.hpp:21