2021-06-17 22:44:06 +02:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
|
|
#include <unordered_map>
|
2022-03-05 14:20:07 +01:00
|
|
|
#include <atomic>
|
|
|
|
|
#include <deque>
|
|
|
|
|
#include <mutex>
|
|
|
|
|
#include <thread>
|
|
|
|
|
#include "Utilities/StrUtil.h"
|
|
|
|
|
#include "Utilities/Thread.h"
|
2022-07-08 22:43:13 +02:00
|
|
|
#include "Emu/Cell/Modules/cellMusic.h"
|
2021-06-17 22:44:06 +02:00
|
|
|
|
|
|
|
|
namespace utils
|
|
|
|
|
{
|
2022-04-20 23:44:22 +02:00
|
|
|
std::string av_error_to_string(int error);
|
|
|
|
|
|
2021-06-17 22:44:06 +02:00
|
|
|
struct media_info
|
|
|
|
|
{
|
2022-02-20 19:01:21 +01:00
|
|
|
std::string path;
|
|
|
|
|
|
2021-06-24 21:26:40 +02:00
|
|
|
s32 audio_av_codec_id = 0; // 0 = AV_CODEC_ID_NONE
|
|
|
|
|
s32 video_av_codec_id = 0; // 0 = AV_CODEC_ID_NONE
|
|
|
|
|
s32 audio_bitrate_bps = 0; // Bit rate in bit/s
|
|
|
|
|
s32 video_bitrate_bps = 0; // Bit rate in bit/s
|
|
|
|
|
s32 sample_rate = 0; // Samples per second
|
2021-06-17 22:44:06 +02:00
|
|
|
s64 duration_us = 0; // in AV_TIME_BASE fractional seconds (= microseconds)
|
|
|
|
|
|
|
|
|
|
std::unordered_map<std::string, std::string> metadata;
|
|
|
|
|
|
|
|
|
|
// Convenience function for metadata
|
|
|
|
|
template <typename T>
|
|
|
|
|
T get_metadata(const std::string& key, const T& def) const;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
std::pair<bool, media_info> get_media_info(const std::string& path, s32 av_media_type);
|
2022-02-20 15:22:41 +01:00
|
|
|
|
|
|
|
|
template <typename D>
|
|
|
|
|
void parse_metadata(D& dst, const utils::media_info& mi, const std::string& key, const std::string& def, usz max_length)
|
|
|
|
|
{
|
|
|
|
|
std::string value = mi.get_metadata<std::string>(key, def);
|
|
|
|
|
if (value.size() > max_length)
|
|
|
|
|
{
|
|
|
|
|
value.resize(max_length);
|
|
|
|
|
}
|
|
|
|
|
strcpy_trunc(dst, value);
|
|
|
|
|
};
|
2022-03-05 14:20:07 +01:00
|
|
|
|
|
|
|
|
class audio_decoder
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
audio_decoder();
|
|
|
|
|
~audio_decoder();
|
|
|
|
|
|
2022-07-08 22:43:13 +02:00
|
|
|
void set_context(music_selection_context context);
|
2022-03-05 14:20:07 +01:00
|
|
|
void set_swap_endianness(bool swapped);
|
2022-07-08 22:43:13 +02:00
|
|
|
void clear();
|
2022-03-05 14:20:07 +01:00
|
|
|
void stop();
|
|
|
|
|
void decode();
|
2022-07-08 22:43:13 +02:00
|
|
|
u32 set_next_index(bool next);
|
2022-03-05 14:20:07 +01:00
|
|
|
|
2022-07-08 22:43:13 +02:00
|
|
|
shared_mutex m_mtx;
|
2022-03-05 14:20:07 +01:00
|
|
|
const s32 sample_rate = 48000;
|
|
|
|
|
std::vector<u8> data;
|
|
|
|
|
atomic_t<u64> m_size = 0;
|
|
|
|
|
atomic_t<u64> duration_ms = 0;
|
2022-07-08 22:43:13 +02:00
|
|
|
atomic_t<bool> track_fully_decoded{false};
|
|
|
|
|
atomic_t<bool> track_fully_consumed{false};
|
2022-03-05 14:20:07 +01:00
|
|
|
atomic_t<bool> has_error{false};
|
|
|
|
|
std::deque<std::pair<u64, u64>> timestamps_ms;
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
bool m_swap_endianness = false;
|
2022-07-08 22:43:13 +02:00
|
|
|
music_selection_context m_context{};
|
2022-03-05 14:20:07 +01:00
|
|
|
std::unique_ptr<named_thread<std::function<void()>>> m_thread;
|
|
|
|
|
};
|
2021-06-17 22:44:06 +02:00
|
|
|
}
|