#ifndef MEDIATYPES_H #define MEDIATYPES_H #include #include #include namespace AVPlayer2 { namespace Types { // 常量定义 const int MAX_AUDIO_CHANNELS = 8; const int MAX_VIDEO_PLANES = 4; const int DEFAULT_SAMPLE_RATE = 44100; const int DEFAULT_BUFFER_SIZE = 4096; const float DEFAULT_VOLUME = 1.0f; const double INVALID_TIMESTAMP = -1.0; /** * 音频采样格式枚举 */ enum class AudioSampleFormat { Unknown, // 未知格式 UInt8, // 8位无符号整数 Int16, // 16位有符号整数 Int32, // 32位有符号整数 Float32, // 32位浮点数 Float64, // 64位浮点数 UInt8Planar, // 8位无符号整数平面格式 Int16Planar, // 16位有符号整数平面格式 Int32Planar, // 32位有符号整数平面格式 Float32Planar, // 32位浮点数平面格式 Float64Planar // 64位浮点数平面格式 }; /** * 音频帧数据 */ struct AudioFrame { unsigned char* data[MAX_AUDIO_CHANNELS]; // 音频数据平面指针 int lineSize[MAX_AUDIO_CHANNELS]; // 每个平面的数据大小 int sampleRate; // 采样率 int channels; // 声道数 int samplesPerChannel; // 每声道采样数 AudioSampleFormat sampleFormat; // 采样格式 double timestamp; // 时间戳(秒) int64_t pts; // 显示时间戳 bool isPlanar; // 是否为平面格式 AudioFrame() { for (int i = 0; i < MAX_AUDIO_CHANNELS; ++i) { data[i] = nullptr; lineSize[i] = 0; } sampleRate = DEFAULT_SAMPLE_RATE; channels = 2; samplesPerChannel = 0; sampleFormat = AudioSampleFormat::Int16; timestamp = INVALID_TIMESTAMP; pts = 0; isPlanar = false; } }; /** * 字幕帧数据 */ struct SubtitleFrame { std::string text; // 字幕文本 double startTime; // 开始时间(秒) double endTime; // 结束时间(秒) double timestamp; // 时间戳(秒) int x; // X坐标 int y; // Y坐标 int width; // 宽度 int height; // 高度 std::string fontFamily; // 字体族 int fontSize; // 字体大小 std::string fontColor; // 字体颜色 std::string backgroundColor; // 背景颜色 bool isBold; // 是否粗体 bool isItalic; // 是否斜体 SubtitleFrame() { startTime = INVALID_TIMESTAMP; endTime = INVALID_TIMESTAMP; timestamp = INVALID_TIMESTAMP; x = 0; y = 0; width = 0; height = 0; fontSize = 16; fontColor = "#FFFFFF"; backgroundColor = "#000000"; isBold = false; isItalic = false; } }; /** * 媒体流信息 */ struct StreamInfo { int index; // 流索引 std::string codecName; // 编解码器名称 std::string codecLongName; // 编解码器长名称 int64_t duration; // 持续时间(微秒) int64_t bitRate; // 比特率 std::string language; // 语言 std::string title; // 标题 // 音频流特有属性 int sampleRate; // 采样率 int channels; // 声道数 AudioSampleFormat sampleFormat; // 采样格式 // 视频流特有属性 int width; // 宽度 int height; // 高度 float frameRate; // 帧率 float aspectRatio; // 宽高比 StreamInfo() { index = -1; duration = 0; bitRate = 0; sampleRate = 0; channels = 0; sampleFormat = AudioSampleFormat::Unknown; width = 0; height = 0; frameRate = 0.0f; aspectRatio = 0.0f; } }; /** * 媒体文件信息 */ struct MediaInfo { std::string fileName; // 文件名 std::string formatName; // 格式名称 std::string formatLongName; // 格式长名称 int64_t duration; // 总持续时间(微秒) int64_t fileSize; // 文件大小(字节) int64_t bitRate; // 总比特率 std::vector audioStreams; // 音频流列表 std::vector videoStreams; // 视频流列表 std::vector subtitleStreams; // 字幕流列表 std::string metadata; // 元数据(JSON格式) MediaInfo() { duration = 0; fileSize = 0; bitRate = 0; } }; /** * 播放状态信息 */ struct PlaybackInfo { double currentTime; // 当前播放时间(秒) double duration; // 总时长(秒) double bufferProgress; // 缓冲进度(0.0-1.0) bool isPlaying; // 是否正在播放 bool isPaused; // 是否暂停 bool isMuted; // 是否静音 float volume; // 音量(0.0-1.0) float playbackSpeed; // 播放速度 int currentAudioStream; // 当前音频流索引 int currentVideoStream; // 当前视频流索引 int currentSubtitleStream; // 当前字幕流索引 PlaybackInfo() { currentTime = 0.0; duration = 0.0; bufferProgress = 0.0; isPlaying = false; isPaused = false; isMuted = false; volume = DEFAULT_VOLUME; playbackSpeed = 1.0f; currentAudioStream = -1; currentVideoStream = -1; currentSubtitleStream = -1; } }; /** * 错误信息 */ struct ErrorInfo { int code; // 错误码 std::string message; // 错误消息 std::string detail; // 详细信息 double timestamp; // 发生时间戳 std::string component; // 发生错误的组件 ErrorInfo() { code = 0; timestamp = 0.0; } ErrorInfo(int errorCode, const std::string& errorMessage) : code(errorCode), message(errorMessage) { timestamp = 0.0; // 应该设置为当前时间 } }; } // namespace Types } // namespace AVPlayer2 #endif // MEDIATYPES_H