PonyPlayer
ponyplayer.h
浏览该文件的文档.
1//
2// Created by ColorsWind on 2022/5/13.
3//
4#pragma once
5#include <utility>
6#include <QString>
7#include <QDir>
8
9
10#if defined(WIN32) || defined(linux)
11#define INCLUDE_FFMPEG_BEGIN \
12extern "C" { \
13_Pragma("GCC diagnostic push") \
14_Pragma("GCC diagnostic ignored \"-Wold-style-cast\"") \
15_Pragma("GCC diagnostic ignored \"-Wsign-conversion\"") \
16_Pragma("GCC diagnostic ignored \"-Wconversion\"")
17#elif defined(__APPLE__)
18#define INCLUDE_FFMPEG_BEGIN \
19extern "C" { \
20_Pragma("GCC diagnostic push") \
21_Pragma("GCC diagnostic ignored \"-Wold-style-cast\"") \
22_Pragma("GCC diagnostic ignored \"-Wsign-conversion\"") \
23_Pragma("GCC diagnostic ignored \"-Wimplicit-int-conversion\"")
24#endif
25
26#define INCLUDE_FFMPEG_END \
27_Pragma("GCC diagnostic pop") \
28}
29
30
31
32#ifdef NDEBUG
33#define NOT_IMPLEMENT_YET { throw std::runtime_error("Unsupported operation:"); }
34#define ILLEGAL_STATE(msg) throw std::runtime_error(std::string("Illegal State Exception: ").append(msg))
35#else
36#define STRINGIFY(x) #x
37#define TOSTRING(x) STRINGIFY(x)
38#define FILE_AND_LINE __FILE__ ":" TOSTRING(__LINE__)
39#define NOT_IMPLEMENT_YET { throw std::runtime_error("Unsupported operation: " FILE_AND_LINE); }
40#define ILLEGAL_STATE(msg) throw std::runtime_error(std::string("Illegal State Exception: ").append(msg).append(" : " FILE_AND_LINE))
41#endif
42
43namespace PonyPlayer {
44 using PonyThread = const char*;
45 constexpr PonyThread PLAYBACK = "PlaybackThread";
46 constexpr PonyThread DECODER = "DecoderThread";
47 constexpr PonyThread MAIN = "MainThread";
48 constexpr PonyThread RENDER = "RenderThread";
49 constexpr PonyThread PREVIEW = "PreviewThread";
50 constexpr PonyThread FRAME = "FrameControllerThread";
51
52 constexpr PonyThread ANY = "__AnyThread";
53 constexpr PonyThread SELF = "__SelfThread";
54
55 template<typename T0>
56 constexpr bool checkThreadType(T0) {
57 return std::is_same<T0, PonyThread>();
58 }
59
60 template<typename T0, typename ...T>
61 constexpr bool checkThreadType(T0, T ...t) {
62 return std::is_same<T0, PonyThread>() && checkThreadType(t...);
63 }
64
69 inline QString getHome() {
70 QString home = QDir::homePath();
71#ifdef Q_OS_MAC
72 home += "/Library/Containers/PonyPlayer";
73#elif defined(Q_OS_WIN32)
74 home += "/AppData/Local/PonyPlayer";
75#elif defined(Q_OS_LINUX)
76 home += "/.PonyPlayer";
77#endif
78 return home;
79 }
80}
81
82
83
84#define PONY_THREAD_ANNOTATION(...) static_assert([]{using namespace PonyPlayer; return checkThreadType(__VA_ARGS__);}());
85
89#define PONY_GUARD_BY(...) PONY_THREAD_ANNOTATION(__VA_ARGS__)
90
94#define PONY_CONDITION(description)
95#define PONY_THREAD_AFFINITY(thread) PONY_THREAD_ANNOTATION(thread)
96#define PONY_THREAD_SAFE
Definition: audioformat.hpp:155
constexpr PonyThread MAIN
Definition: ponyplayer.h:47
constexpr PonyThread ANY
Definition: ponyplayer.h:52
constexpr PonyThread SELF
Definition: ponyplayer.h:53
constexpr PonyThread RENDER
Definition: ponyplayer.h:48
constexpr bool checkThreadType(T0)
Definition: ponyplayer.h:56
constexpr PonyThread DECODER
Definition: ponyplayer.h:46
const char * PonyThread
Definition: ponyplayer.h:44
constexpr PonyThread PLAYBACK
Definition: ponyplayer.h:45
constexpr PonyThread PREVIEW
Definition: ponyplayer.h:49
QString getHome()
Definition: ponyplayer.h:69
constexpr PonyThread FRAME
Definition: ponyplayer.h:50