#pragma once #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include // 引入新的Recorder库 #include "../libs/Recorder/export.h" #include "../libs/Recorder/ultra_low_latency_recorder_config.h" /** * 基于新Recorder库的录制推流组件 * 用于替换原有的AvRecorder实现 */ class RecorderWidget : public QWidget { Q_OBJECT public: struct Settings { QString liveUrl; // 将通过NetworkConfig动态获取 std::string liveName = "stream"; std::string outputDir = "."; int videoBitRate = UltraLowLatencyRecorderConfig::ULTRA_VIDEO_BITRATE; // 使用超低延迟配置 int videoFrameRate = UltraLowLatencyRecorderConfig::ULTRA_VIDEO_FRAMERATE; // 30fps int videoQuality = 100; int audioBitRate = UltraLowLatencyRecorderConfig::ULTRA_AUDIO_BITRATE; // 使用超低延迟配置 }; public: explicit RecorderWidget(QWidget *parent = nullptr); ~RecorderWidget(); // 设置录制推流参数 void setSettings(const Settings& settings); // 新增:外部设置音频设备 void setMicDevice(const AMRECORDER_DEVICE& device); void setSpeakerDevice(const AMRECORDER_DEVICE& device); // 新增:外部设置视频编码器(由 MainPanel 控制) void setVideoEncoderId(int encId); // 开始录制 bool startRecording(); // 停止录制 void stopRecording(); // 开始推流 bool startStreaming(); // 停止推流 void stopStreaming(); // 便捷方法:设置推流流名(用于以房间ID作为流名) void setLiveName(const QString& name); // 新增:供MainPanel调用的按钮功能 void onRecordButtonClicked(); void onStreamButtonClicked(); void onSettingsButtonClicked(); // 预览显示控制 void showPreview(); void hidePreview(); bool isPreviewVisible() const; // 获取状态栏 QWidget* statusBar() const { return m_statusBar; } public slots: void updatePreview(); void updateStatus(); signals: void recordingStarted(); void recordingStopped(); void streamingStarted(); void streamingStopped(); void errorOccurred(const QString& error); private: void initUI(); void initStatusBar(); void initRecorder(); void releaseRecorder(); void setupCallbacks(); void refreshAudioDevices(); // 改为仅维护内部选择,不再更新UI void refreshVideoEncoders(); // 回调函数 static void onDurationCallback(uint64_t duration); static void onErrorCallback(int error); static void onDeviceChangeCallback(int type); static void onPreviewYUVCallback(const unsigned char *data, unsigned int size, int width, int height, int type); static void onPreviewAudioCallback(); private: // UI组件 QVBoxLayout* m_mainLayout = nullptr; QOpenGLWidget* m_previewWidget = nullptr; QComboBox* m_encoderComboBox = nullptr; QComboBox* m_micComboBox = nullptr; // 将不再在UI中创建 QComboBox* m_speakerComboBox = nullptr; // 将不再在UI中创建 QStatusBar* m_statusBar = nullptr; QLabel* m_statusLabel = nullptr; QLabel* m_timeLabel = nullptr; QLabel* m_encoderLabel = nullptr; QLabel* m_vrbLabel = nullptr; // 新增:视频环形缓冲区统计 QLabel* m_arbLabel = nullptr; // 新增:音频环形缓冲区统计 // 定时器 QTimer* m_previewTimer = nullptr; QTimer* m_statusTimer = nullptr; // 录制相关 Settings m_settings; AMRECORDER_SETTING m_recorderSetting; AMRECORDER_CALLBACK m_callbacks; // 外部选择的音频设备(若未设置,则在启动时使用系统默认设备) AMRECORDER_DEVICE m_selectedMicDevice{}; AMRECORDER_DEVICE m_selectedSpeakerDevice{}; // 新增:外部选择的视频编码器 id(默认未选择) int m_selectedEncoderId = -1; // 设备信息(保留成员避免大范围改动,但不再用于UI) AMRECORDER_DEVICE* m_micDevices = nullptr; AMRECORDER_DEVICE* m_speakerDevices = nullptr; AMRECORDER_ENCODERS* m_encoders = nullptr; int m_micCount = 0; int m_speakerCount = 0; int m_encoderCount = 0; // 状态 bool m_isRecording = false; bool m_isStreaming = false; bool m_isInitialized = false; QTime m_recordStartTime; // 预览相关 QMutex m_previewMutex; QByteArray m_previewData; int m_previewWidth = 0; int m_previewHeight = 0; // 静态实例指针,用于回调 static RecorderWidget* s_instance; };