MediaTypes.h 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  1. #ifndef MEDIATYPES_H
  2. #define MEDIATYPES_H
  3. #include <cstdint>
  4. #include <string>
  5. #include <vector>
  6. namespace AVPlayer2 {
  7. namespace Types {
  8. // 常量定义
  9. const int MAX_AUDIO_CHANNELS = 8;
  10. const int MAX_VIDEO_PLANES = 4;
  11. const int DEFAULT_SAMPLE_RATE = 44100;
  12. const int DEFAULT_BUFFER_SIZE = 4096;
  13. const float DEFAULT_VOLUME = 1.0f;
  14. const double INVALID_TIMESTAMP = -1.0;
  15. /**
  16. * 音频采样格式枚举
  17. */
  18. enum class AudioSampleFormat {
  19. Unknown, // 未知格式
  20. UInt8, // 8位无符号整数
  21. Int16, // 16位有符号整数
  22. Int32, // 32位有符号整数
  23. Float32, // 32位浮点数
  24. Float64, // 64位浮点数
  25. UInt8Planar, // 8位无符号整数平面格式
  26. Int16Planar, // 16位有符号整数平面格式
  27. Int32Planar, // 32位有符号整数平面格式
  28. Float32Planar, // 32位浮点数平面格式
  29. Float64Planar // 64位浮点数平面格式
  30. };
  31. /**
  32. * 音频帧数据
  33. */
  34. struct AudioFrame {
  35. unsigned char* data[MAX_AUDIO_CHANNELS]; // 音频数据平面指针
  36. int lineSize[MAX_AUDIO_CHANNELS]; // 每个平面的数据大小
  37. int sampleRate; // 采样率
  38. int channels; // 声道数
  39. int samplesPerChannel; // 每声道采样数
  40. AudioSampleFormat sampleFormat; // 采样格式
  41. double timestamp; // 时间戳(秒)
  42. int64_t pts; // 显示时间戳
  43. bool isPlanar; // 是否为平面格式
  44. AudioFrame() {
  45. for (int i = 0; i < MAX_AUDIO_CHANNELS; ++i) {
  46. data[i] = nullptr;
  47. lineSize[i] = 0;
  48. }
  49. sampleRate = DEFAULT_SAMPLE_RATE;
  50. channels = 2;
  51. samplesPerChannel = 0;
  52. sampleFormat = AudioSampleFormat::Int16;
  53. timestamp = INVALID_TIMESTAMP;
  54. pts = 0;
  55. isPlanar = false;
  56. }
  57. };
  58. /**
  59. * 字幕帧数据
  60. */
  61. struct SubtitleFrame {
  62. std::string text; // 字幕文本
  63. double startTime; // 开始时间(秒)
  64. double endTime; // 结束时间(秒)
  65. double timestamp; // 时间戳(秒)
  66. int x; // X坐标
  67. int y; // Y坐标
  68. int width; // 宽度
  69. int height; // 高度
  70. std::string fontFamily; // 字体族
  71. int fontSize; // 字体大小
  72. std::string fontColor; // 字体颜色
  73. std::string backgroundColor; // 背景颜色
  74. bool isBold; // 是否粗体
  75. bool isItalic; // 是否斜体
  76. SubtitleFrame() {
  77. startTime = INVALID_TIMESTAMP;
  78. endTime = INVALID_TIMESTAMP;
  79. timestamp = INVALID_TIMESTAMP;
  80. x = 0;
  81. y = 0;
  82. width = 0;
  83. height = 0;
  84. fontSize = 16;
  85. fontColor = "#FFFFFF";
  86. backgroundColor = "#000000";
  87. isBold = false;
  88. isItalic = false;
  89. }
  90. };
  91. /**
  92. * 媒体流信息
  93. */
  94. struct StreamInfo {
  95. int index; // 流索引
  96. std::string codecName; // 编解码器名称
  97. std::string codecLongName; // 编解码器长名称
  98. int64_t duration; // 持续时间(微秒)
  99. int64_t bitRate; // 比特率
  100. std::string language; // 语言
  101. std::string title; // 标题
  102. // 音频流特有属性
  103. int sampleRate; // 采样率
  104. int channels; // 声道数
  105. AudioSampleFormat sampleFormat; // 采样格式
  106. // 视频流特有属性
  107. int width; // 宽度
  108. int height; // 高度
  109. float frameRate; // 帧率
  110. float aspectRatio; // 宽高比
  111. StreamInfo() {
  112. index = -1;
  113. duration = 0;
  114. bitRate = 0;
  115. sampleRate = 0;
  116. channels = 0;
  117. sampleFormat = AudioSampleFormat::Unknown;
  118. width = 0;
  119. height = 0;
  120. frameRate = 0.0f;
  121. aspectRatio = 0.0f;
  122. }
  123. };
  124. /**
  125. * 媒体文件信息
  126. */
  127. struct MediaInfo {
  128. std::string fileName; // 文件名
  129. std::string formatName; // 格式名称
  130. std::string formatLongName; // 格式长名称
  131. int64_t duration; // 总持续时间(微秒)
  132. int64_t fileSize; // 文件大小(字节)
  133. int64_t bitRate; // 总比特率
  134. std::vector<StreamInfo> audioStreams; // 音频流列表
  135. std::vector<StreamInfo> videoStreams; // 视频流列表
  136. std::vector<StreamInfo> subtitleStreams; // 字幕流列表
  137. std::string metadata; // 元数据(JSON格式)
  138. MediaInfo() {
  139. duration = 0;
  140. fileSize = 0;
  141. bitRate = 0;
  142. }
  143. };
  144. /**
  145. * 播放状态信息
  146. */
  147. struct PlaybackInfo {
  148. double currentTime; // 当前播放时间(秒)
  149. double duration; // 总时长(秒)
  150. double bufferProgress; // 缓冲进度(0.0-1.0)
  151. bool isPlaying; // 是否正在播放
  152. bool isPaused; // 是否暂停
  153. bool isMuted; // 是否静音
  154. float volume; // 音量(0.0-1.0)
  155. float playbackSpeed; // 播放速度
  156. int currentAudioStream; // 当前音频流索引
  157. int currentVideoStream; // 当前视频流索引
  158. int currentSubtitleStream; // 当前字幕流索引
  159. PlaybackInfo() {
  160. currentTime = 0.0;
  161. duration = 0.0;
  162. bufferProgress = 0.0;
  163. isPlaying = false;
  164. isPaused = false;
  165. isMuted = false;
  166. volume = DEFAULT_VOLUME;
  167. playbackSpeed = 1.0f;
  168. currentAudioStream = -1;
  169. currentVideoStream = -1;
  170. currentSubtitleStream = -1;
  171. }
  172. };
  173. /**
  174. * 错误信息
  175. */
  176. struct ErrorInfo {
  177. int code; // 错误码
  178. std::string message; // 错误消息
  179. std::string detail; // 详细信息
  180. double timestamp; // 发生时间戳
  181. std::string component; // 发生错误的组件
  182. ErrorInfo() {
  183. code = 0;
  184. timestamp = 0.0;
  185. }
  186. ErrorInfo(int errorCode, const std::string& errorMessage)
  187. : code(errorCode), message(errorMessage) {
  188. timestamp = 0.0; // 应该设置为当前时间
  189. }
  190. };
  191. } // namespace Types
  192. } // namespace AVPlayer2
  193. #endif // MEDIATYPES_H