Repository navigation
Expand file tree
/
Copy pathPlayerInfo.cpp
More file actions
210 lines (208 loc) · 23.1 KB
/
Copy pathPlayerInfo.cpp
File metadata and controls
210 lines (208 loc) · 23.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
#include "player/PlayerBuiltinProfiles.h"
#include "player/PlayerWindow.h"
#include "player/PlayerInfoPanel.h"
#include "player/PlayerDiscMenu.h"
#include "backend/ThreeFpPlayer.h"
#include "ui/PreviewPane.h"
#include <QCoreApplication>
#include <QApplication>
#include <QFileInfo>
#include <QDateTime>
#include <cmath>
#include <QJsonArray>
#include <QJsonDocument>
#include <QLabel>
#include <QPushButton>
#include <QSettings>
#include <QThread>
#include <QColorSpace>
#include <QPainter>
#include <windows.h>
#include <psapi.h>
namespace vsr {
void PlayerWindow::updateInfo() {
updateAlgorithmBadges();
if(minimalMode_){infoVisible_=false;static_cast<PlayerInfoPanel *>(info_)->hidePanel();audioInfo_->hidePanel();return;}
static_cast<PlayerInfoPanel *>(info_)->setWidthLimit(settings_->value("info/audioDetailed",false).toBool() && !imageMode_?std::max(320,pane_->surface()->width()-524):0);
if(!infoVisible_ || imageMode_ || (discMenu_ && discMenu_->active()))audioInfo_->hidePanel();
if(discMenu_ && discMenu_->active()){
const auto programme=discMenu_->programme();
if(infoVisible_)static_cast<PlayerInfoPanel *>(info_)->showText(tr("BD:%1\n渲染器:libVLC · 光盘导航/菜单合成\n位置:%2 s · 时长:%3 s\n输入视频:%4 × %5 · %6 fps\n视口:%7 × %8\n当前音轨:%9 · 当前字幕:%10\n章节:%11\n模式:%12\n处理链:菜单交互;正片识别后恢复所选滤镜").arg(source_).arg(position()/10000000.,0,'f',2).arg(discMenu_->duration()/10000000.,0,'f',2).arg(programme.value("width").toInt()).arg(programme.value("height").toInt()).arg(programme.value("fps").toDouble(),0,'f',3).arg(pane_->surface()->width()).arg(pane_->surface()->height()).arg(programme.value("audio").toInt()).arg(programme.value("subtitle").toInt()).arg(programme.value("chapters").toArray().size()).arg(discMenuNavigation_?tr("交互菜单 (方向键/Enter)"):tr("短节目")));
layoutInfoPanels();return;
}
if(imageMode_){
if(!infoVisible_)return;
usage_=resources_.sample();const auto image=pane_->image();const QFileInfo file(source_);
const auto viewport=pane_->surface()->size()*pane_->surface()->devicePixelRatioF();
const auto fitted=QSizeF(pane_->imageDisplaySize()).scaled(QSizeF(viewport),Qt::KeepAspectRatio)*pane_->zoom();
const auto color=image.colorSpace().isValid()?image.colorSpace().description():tr("未提供");
QStringList lines;
lines<<tr("文件名:%1").arg(file.fileName())<<tr("路径:%1").arg(file.absoluteFilePath())
<<tr("文件大小:%1 MiB · 格式:%2").arg(file.size()/1048576.0,0,'f',2).arg(file.suffix().toUpper())
<<tr("输入图片:%1 × %2 · %3 MP · 颜色空间:%4").arg(image.width()).arg(image.height()).arg(double(image.width())*image.height()/1e6,0,'f',2).arg(color)
<<tr("源像素:%1 · 原始位深:%2 bit/channel").arg(image.text("sourcePixelFormat").isEmpty()?file.suffix().toUpper():image.text("sourcePixelFormat"),image.text("sourceBitDepth").isEmpty()?tr("未提供"):image.text("sourceBitDepth"))
<<tr("解码器:%1 · 耗时:%2 ms").arg(image.text("decoder"),image.text("decodeMilliseconds"))
<<tr("解码像素:%1 bit/pixel · Alpha:%2 · 像素内存:%3 MiB").arg(image.depth()).arg(image.hasAlphaChannel()?tr("是"):tr("否")).arg(image.sizeInBytes()/1048576.0,0,'f',1)
<<tr("输出:%1 × %2 · 视口:%3 × %4 · 缩放:%5%").arg(fitted.width(),0,'f',0).arg(fitted.height(),0,'f',0).arg(viewport.width()).arg(viewport.height()).arg(pane_->zoom()*100,0,'f',1)
<<tr("图片渲染器:Qt Raster · 可见区域裁切 · SDR")
<<tr("VS 滤镜:未启用 · 预解码:未启用")
<<tr("CPU:%1 · GPU:%2 · 内存:%3 MiB").arg(usage_.processCpu>=0?QString::number(usage_.processCpu,'f',1)+"%":tr("采样中"),usage_.gpu>=0?QString::number(usage_.gpu,'f',1)+"%":tr("未提供")).arg(usage_.memoryMiB);
static_cast<PlayerInfoPanel *>(info_)->showText(lines.join('\n'));layoutInfoPanels();return;
}
usage_=resources_.sample(infoVisible_);
const auto refreshed = QJsonDocument::fromJson(clock_->mediaInfo().toUtf8()).object();
if (!refreshed.isEmpty()) media_ = refreshed;
applyBlurayMetadata();
const auto selectedAudio=clock_->snapshot().selectedAudioStream;const auto selectedVideo=clock_->snapshot().selectedVideoStream;
QJsonObject video, audio;
for (const auto &entry : media_.value("streams").toArray()) {
const auto stream = entry.toObject();
if (stream.value("type").toString() == "video" && (selectedVideo>=0?stream.value("index").toInt()==selectedVideo:video.isEmpty())) video = stream;
if (stream.value("type").toString() == "audio" && stream.value("index").toInt()==selectedAudio) audio = stream;
}
videoBadge_->setText(audioMode_?tr("音频"):video.value("codec").toString("—")); audioBadge_->setText(audio.value("codec").toString("—"));
const auto source = clock_->snapshot(); const auto rendered = outputSnapshot();
const auto decoder = source_.isEmpty() ? (settings_->value("decode/mode",2).toUInt()==2?QStringLiteral("3FP-HW"):QStringLiteral("3FP-SW")) : lavVideo_ ? QStringLiteral("LAV") : !direct_ ? QStringLiteral("VS / VPY") : source.decodeMode == 2 ? QStringLiteral("3FP-HW") : QStringLiteral("3FP-SW");
decoderBadge_->setText(decoder); hdrBadge_->setText(source.isHdrSource ? "HDR" : "SDR");
hdrBadge_->setToolTip(madvrMode()?tr("HDR / SDR 输出与色调映射由 madVR 控制"):source.isHdrSource ? (rendered.actualColorMode ? tr("HDR 输出") : tr("HDR 源,映射到 SDR 显示器")) : tr("SDR 源"));
if (!infoVisible_) return;
// Native already counts only generations that reached Present; coalesced frames are separate.
const bool playbackActive=lavVideo_?playing_:source.state==ThreeFpState::Playing;
const auto count=rendered.presentedVideoFrames;
if(count<infoLastFrames_){infoLastFrames_=count;infoCurrentFps_=0;infoFpsTimer_.restart();}
if(infoFpsTimer_.isValid() && infoFpsTimer_.elapsed()>=500){infoCurrentFps_=count>=infoLastFrames_?(count-infoLastFrames_)*1000./infoFpsTimer_.elapsed():0;infoLastFrames_=count;infoFpsTimer_.restart();}
else if(!infoFpsTimer_.isValid()){infoFpsTimer_.start();infoLastFrames_=count;}
const auto fps = clip_.fpsDenominator > 0 ? static_cast<double>(clip_.fpsNumerator) / clip_.fpsDenominator : 0;
const auto at = position();
const auto videoRate = source.videoBitRate ? source.videoBitRate : static_cast<quint64>(video.value("bitRate").toDouble());
const auto audioRate = source.audioBitRate ? source.audioBitRate : static_cast<quint64>(audio.value("bitRate").toDouble());
const auto formatRate = [](quint64 value) { return value ? QString::number(value / 1000) + " kb/s" : tr("未知"); };
const auto formatTime = [](qint64 ticks) { const auto ms = qMax<qint64>(0,ticks / 10000); return QString("%1:%2:%3.%4").arg(ms/3600000,2,10,QChar('0')).arg(ms/60000%60,2,10,QChar('0')).arg(ms/1000%60,2,10,QChar('0')).arg(ms%1000,3,10,QChar('0')); };
const double sourceFps = video.value("averageFrameRateDenominator").toInt() > 0 ? video.value("averageFrameRateNumerator").toDouble() / video.value("averageFrameRateDenominator").toInt() : fps;
const double frameTime = clip_.fpsNumerator > 0 ? lastFrame_ * 10000000.0 * clip_.fpsDenominator / clip_.fpsNumerator : 0;
const auto fitted = QSize(clip_.width, clip_.height).scaled(pane_->surface()->size()*pane_->surface()->devicePixelRatioF(), Qt::KeepAspectRatio) * pane_->zoom();
const auto processing=(direct_?clock_:output_)->processingSize();
const bool hlsl=direct_ || !customShaderPackage_.isEmpty() && !hlslFailed_ && hlslFallback_.isEmpty();
const auto outputBits = audio.value("outputValidBitsPerSample").toInt();
const bool lavAudio=lavAudio_;
auto audioOutput = lavAudio ? tr("由 LAV / DirectShow 协商") : QString("%1 · %2 Hz · %3 声道 · %4 bit")
.arg(audio.value("outputFloat").toBool() ? "Float PCM" : "PCM").arg(audio.value("outputSampleRate").toInt()).arg(audio.value("outputChannels").toInt()).arg(outputBits);
if(!lavAudio && media_.contains("audioOutputActive")) {
if(!media_.value("audioOutputActive").toBool())audioOutput=tr("3FP 输出未激活(暂停时可释放独占设备)");
else {
audioOutput+=media_.value("audioOutputExclusive").toBool()?tr(" · WASAPI 独占"):tr(" · WASAPI 共享");
if(settings_->value("audio/exclusive",false).toBool() && !media_.value("audioOutputExclusive").toBool())audioOutput+=tr("(独占请求已回退)");
if(media_.value("audioSourceRate").toInt()>0 && media_.value("audioSourceRate").toInt()!=media_.value("audioOutputRate").toInt())audioOutput+=tr(" · 已重采样");
}
}
QStringList lines;
auto cpuPowerStatus=usage_.cpuPowerStatus;cpuPowerStatus.replace(QChar(0xff08),'(').replace(QChar(0xff09),')');
lines << tr("文件名:%1").arg(QFileInfo(source_).fileName())
<< tr("当前时间:%1 · 时间轴:%2 / %3 (%4%) · #帧数:%5 / %6")
.arg(QDateTime::currentDateTime().toString("HH:mm:ss"), formatTime(at), formatTime(source.duration100ns))
.arg(source.duration100ns > 0 ? at * 100.0 / source.duration100ns : 0, 0, 'f', 1).arg(lastFrame_).arg(clip_.totalFrames)
<< tr("CPU:%1 · GPU:%2 · 内存:%3 MiB").arg(usage_.processCpu>=0?QString::number(usage_.processCpu,'f',1)+"%":tr("采样中"),usage_.gpu>=0?QString::number(usage_.gpu,'f',1)+"%":tr("未提供")).arg(usage_.memoryMiB)
<< tr("功耗:CPU %1 · GPU(NVIDIA) %2").arg(usage_.cpuWatts>=0?QString::number(usage_.cpuWatts,'f',1)+" W":cpuPowerStatus,usage_.gpuWatts>=0?QString::number(usage_.gpuWatts,'f',1)+" W":QString("N/A"))
<< ""
<< tr("视频解码器:%1 · VS 源:%2").arg(decoder, direct_ ? tr("原生直通") : preset_.isEmpty() ? tr("3FP 原生(色彩保留)") : tr("VPY 定义"))
<< tr("输入:%1 · %2×%3 · %4-%5 · 帧率:%6 · 位率:%7")
.arg(video.value("codec").toString()).arg(video.value("width").toInt()).arg(video.value("height").toInt())
.arg(video.value("pixelFormat").toString(),video.value("profile").toString()).arg(sourceFps,0,'f',3).arg(formatRate(videoRate))
<< (madvrMode()?tr("输出:%1 · %2×%3 · 目标帧率:%4 · 显示格式由 madVR 协商%5%6"):tr("输出:%1 · %2×%3 · 目标帧率:%4 · 显示:%5 bit / %6"))
.arg(madvrMode()?tr("LAV / madVR 协商"):direct_?video.value("pixelFormat").toString():settings_->value("decode/output").toString().isEmpty()?clip_.formatName:settings_->value("decode/output").toString()).arg(clip_.width).arg(clip_.height).arg(fps*speed_,0,'f',3).arg(madvrMode()?QString():QString::number(rendered.videoOutputBitDepth)).arg(madvrMode()?QString():rendered.actualColorMode ? "HDR" : "SDR")
<< (madvrMode()?tr("视频渲染器:madshi video renderer"):tr("视频渲染器:VS Real-Time Video Renderer"))
<< (madvrMode()?tr(" 帧与丢帧统计:由 madVR 控制器提供"):tr(" 已提交:%1 · 丢帧:%2(VS 跳过 %3 / 原生丢弃 %4 / 合并 %5)")
.arg(direct_?rendered.presentedVideoFrames:submittedFrames_).arg(skippedFrames_+rendered.droppedVideoFrames+rendered.coalescedVideoFrames).arg(skippedFrames_).arg(rendered.droppedVideoFrames).arg(rendered.coalescedVideoFrames))
<< tr(" 实时帧率缺口:%1 fps · 视频落后时钟:%2 ms")
.arg(playbackActive?qMax(0.0,fps*speed_-infoCurrentFps_):0,0,'f',2)
.arg(rendered.frameTimeBaseDenominator>0?qMax(0.0,(at-rendered.framePts*double(rendered.frameTimeBaseNumerator)*1e7/rendered.frameTimeBaseDenominator)/10000):0,0,'f',1)
<< ((madvrMode() || direct_)?tr(" VS 处理:未启用 · 原生直通"):tr(" VS 请求耗时:%1 ms · 同步偏移:%2 ms · 平均呈现等待:%3 ms · 预解码:%4 帧")
.arg(frameMilliseconds_,0,'f',1).arg((frameTime-at)/10000,0,'f',1).arg(rendered.swapChainPresents?rendered.presentWait100ns/10000.0/rendered.swapChainPresents:0,0,'f',2).arg(prefetchCount()))
<< tr("视频帧大小:源 %1×%2 → %3 输出 %4×%5 → 显示 %6×%7")
.arg(video.value("width").toInt()).arg(video.value("height").toInt()).arg(hlsl?"HLSL":"VS")
.arg(hlsl && !processing.isEmpty()?processing.width():clip_.width).arg(hlsl && !processing.isEmpty()?processing.height():clip_.height).arg(fitted.width()).arg(fitted.height())
<< ""
<< tr("音频解码器:%1").arg(lavAudio ? "LAV Audio Decoder" : "3FP / FFmpeg")
<< tr("输入:%1 · %2 Hz · %3 声道 · %4 · %5 bit · %6")
.arg(audio.value("codec").toString()).arg(audio.value("sampleRate").toInt()).arg(audio.value("channels").toInt())
.arg(audio.value("sampleFormat").toString()).arg(audio.value("rawSampleBits").toInt()).arg(formatRate(audioRate))
<< tr("输出:%1").arg(audioOutput)
<< tr("渲染输入:%1").arg(audioOutput)
<< tr("音频渲染器:%1").arg(lavAudio ? "DirectShow Audio Renderer" : "Built-in WASAPI Audio Renderer")
<< (lavAudio ? tr(" 缓冲时间:未提供 · 同步偏移:未提供") : tr(" 缓冲时间:%1 ms · 同步偏移:%2 ms · 时间戳抖动帧:%3")
.arg(source.bufferedAudio100ns/10000.0,0,'f',1).arg((source.audioPosition100ns-at)/10000.0,0,'f',1).arg(source.audioTimestampJitterFrames))
<< "" << tr("倍速:%1× · %2").arg(speed_,0,'f',2).arg(preset_.isEmpty() ? tr("原画") : QFileInfo(preset_).fileName());
lines << tr("补帧:%1").arg(interpolationStage()>=0?interpolationNames().at(interpolationStage())+(interpolationAuto_?tr(" · 自动降档"):tr(" · 手动固定")):tr("未启用"));
const QStringList algorithms{"Nearest Neighbour","Bilinear","Bicubic","Lanczos3","Jinc","Spline36","Super-XBR","D3D11","Lanczos4",qualityNames().at(1),qualityNames().at(0),qualityNames().at(2),qualityNames().at(3),qualityNames().at(6),qualityNames().at(7),openNguActive_?QString("OpenNGU"):QString("Jinc")};
const QString scalingName=nativeAnime_ && qualityStage_>=8?qualityNames().value(qualityStage_):!customShaderPackage_.isEmpty() && !hlslFailed_ && hlslFallback_.isEmpty()?QString("HLSL"):madvrMode()?QString("madVR"):direct_?algorithms.value(scalingAlgorithm()):interpolationStage()>=0?(interpolationRenderer()?tr("D3D11"):tr("Jinc 直通")):profile()=="Anime"?qualityNames().at(std::clamp(qualityStage_,0,10)):algorithms.value(scalingAlgorithm());
if(hlslFallback_.startsWith("OpenNGU"))lines << hlslFallback_;
lines << tr("上采样:%1 · 第二上采样:%2 · 下采样:%3")
.arg(!preset_.isEmpty() && profile().isEmpty()?QString("N/A"):scalingName,algorithms.value(settings_->value("render/secondUpscale",4).toInt()),algorithms.value(scalingAlgorithm(true)));
lines << tr("当前 VPY:%1").arg(preset_.isEmpty()?tr("未启用"):profile().isEmpty()?preset_:tr("%1 · %2(内置预设)").arg(qualityStage_+1).arg(QFileInfo(preset_).fileName()));
if(decodePoolBytes_)lines << tr("动态缓冲池:上限 %1 MiB · 目标 %2 帧 · %3").arg(decodePoolBytes_/1048576).arg(decodePoolFrames_).arg(decodePoolFrames_>8?tr("尖峰前瞻"):tr("常规"));
if(madvrMode())lines << tr("色彩引擎:madVR");
else {
const auto color=(direct_?clock_:output_)->colorStatus();
lines << tr("色彩引擎:%1 · %2").arg(QString::fromUtf8(color.engine),color.activeEngine?"libplacebo D3D11":tr("3FP 原生"));
if(color.activeEngine) {
const auto tagged=[](unsigned value,const QStringList& names){return QString("%1 (%2)").arg(names.value(value,"Unknown")).arg(value);};
lines << tr("色彩输入:Matrix %1 · Primaries %2 · Transfer %3 · Range %4 · Chroma %5 · %6 bit")
.arg(tagged(color.sourceMatrix,{"RGB","BT.709","Unspecified","Reserved","FCC","BT.470BG","SMPTE170M","SMPTE240M","YCgCo","BT.2020 NCL","BT.2020 CL","SMPTE2085","Chroma NCL","Chroma CL","ICtCp"}))
.arg(tagged(color.sourcePrimaries,{"Reserved","BT.709","Unspecified","Reserved","BT.470M","BT.470BG","SMPTE170M","SMPTE240M","Film","BT.2020","SMPTE428","P3-DCI","P3-D65"}))
.arg(tagged(color.sourceTransfer,{"Reserved","BT.709","Unspecified","Reserved","Gamma2.2","Gamma2.8","SMPTE170M","SMPTE240M","Linear","Log","Log-sqrt","IEC61966-2-4","BT.1361","sRGB","BT.2020 10","BT.2020 12","PQ","SMPTE428","HLG"}))
.arg(tagged(color.sourceRange,{"Unspecified","Limited","Full"})).arg(tagged(color.sourceChroma,{"Unspecified","Left","Center","Top-left","Top","Bottom-left","Bottom"})).arg(color.sourceBits);
lines << tr("元数据来源:%1 · 显式字段掩码 %2(其余按兼容规则推断)")
.arg(color.sourceKind==2?"VS props":"Decoded AVFrame").arg(color.explicitFields);
lines << tr("色彩目标:%1 nit · 黑位 %2 nit · ICC %3 · LUT %4 · 提交 %5 ms")
.arg(color.targetPeak,0,'f',0).arg(color.targetBlack,0,'f',4).arg(color.iccState).arg(color.lutActive).arg(color.renderSubmitMs,0,'f',2);
lines << tr("HDR 静态信息:Mastering %1 / %2 nit · MaxCLL %3 · MaxFALL %4")
.arg(color.masteringPeak,0,'f',1).arg(color.masteringBlack,0,'f',4).arg(color.maxCll,0,'f',1).arg(color.maxFall,0,'f',1);
if(color.profile[0])lines << tr("显示 ICC:%1").arg(QString::fromUtf8(color.profile));
lines << QString("HDR10+ %1 · Dolby Vision %2 / reshape %3 · Vivid %4").arg(color.hdr10plus).arg(color.doviDetected).arg(color.doviActive).arg(color.vividDetected);
const QStringList tones{"Auto","Spline","ST2094-40","BT.2390","Clip","Linear"},gamuts{"Auto","Perceptual","Softclip","Relative","Clip"};
lines << QString("Tone %1 · Gamut %2 · Dither %3 · Stream fields %4")
.arg(tones.value(color.tone),gamuts.value(color.gamut)).arg(color.dither).arg(color.streamFields);
}
if(color.fallback[0]) lines << tr("色彩回退 / 限制:%1").arg(QString::fromUtf8(color.fallback));
}
for(auto &line:lines)if(line.contains(tr("已提交:")))line=tr(" 当前帧率:%1 fps · ").arg(playbackActive?infoCurrentFps_:0,0,'f',2)+line.trimmed();
if(audioMode_){
int videoStart=-1,audioStart=-1,audioEnd=-1;
for(int i=0;i<lines.size();++i){if(lines[i].startsWith(tr("视频解码器:")))videoStart=i;if(lines[i].startsWith(tr("音频解码器:")))audioStart=i;if(lines[i].startsWith(tr("倍速:")))audioEnd=i;}
if(videoStart>=0 && audioStart>videoStart){auto audioLines=lines.mid(audioStart,audioEnd-audioStart+1);lines=lines.mid(0,videoStart);lines<<tr("视频:无动态视频 · 音频模式")<<(audioMetadata_.cover.isNull()?tr("封面图片:无"):tr("封面图片:%1 × %2 · Qt Raster · 静态图片").arg(audioMetadata_.cover.width()).arg(audioMetadata_.cover.height()))<<tr("VS / 补帧 / 视频硬解:未启用")<<"";lines<<audioLines;lines<<tr("歌词:%1 · %2 行").arg(audioMetadata_.lyricSource.isEmpty()?tr("未提供"):audioMetadata_.lyricSource).arg(audioMetadata_.lyrics.size());}
lines[1]=tr("当前时间:%1 · 时间轴:%2 / %3").arg(QDateTime::currentDateTime().toString("HH:mm:ss"),formatTime(at),formatTime(source.duration100ns));
}
QStringList files{tr("源文件:%1").arg(source_)};
if(!preset_.isEmpty())files<<tr("预设:%1").arg(preset_);
if(!externalAudio_.isEmpty())files<<tr("外部音频:%1").arg(externalAudio_);
if(!externalSubtitle_.isEmpty())files<<tr("字幕 1:%1").arg(externalSubtitle_);
if(!externalSecondarySubtitle_.isEmpty())files<<tr("字幕 2:%1").arg(externalSecondarySubtitle_);
lines=files+lines;static_cast<PlayerInfoPanel *>(info_)->showText(lines.join('\n'));if(isActiveWindow() && !QApplication::activePopupWidget())info_->raise();
updateAudioInfo(audio,audioRate);
layoutInfoPanels();
}
void PlayerWindow::updateAudioInfo(const QJsonObject &audio,quint64 bitRate) {
if(!infoVisible_ || !settings_->value("info/audioDetailed",false).toBool()){audioInfo_->hidePanel();return;}
if(audio.isEmpty()){audioInfo_->hidePanel();return;}
ThreeFpAudioLevels input,output;const bool available=!lavAudio_ && clock_->audioLevels(input,true) && clock_->audioLevels(output,false);
QImage image(440,490,QImage::Format_ARGB32_Premultiplied);image.fill(Qt::transparent);QPainter p(&image);p.setFont(QFont(settings_->value("theme/latinFont","Comic Sans MS").toString(),10));p.setPen(QColor("#e8eaed"));
p.drawText(4,20,tr("音频 %1:%2 | %3").arg(lavAudio_?"DirectShow":"WASAPI",audio.value("codec").toString(),lavAudio_?tr("由后端协商"):audio.value("outputExclusive").toBool()?tr("独占"):tr("共享")));
p.drawText(4,46,tr("音频实时比特率:%1 kbps").arg(bitRate/1000));
const auto meters=[&](int y,const QString &label,const ThreeFpAudioLevels &levels,bool source){
p.setPen(QColor("#b7d9d2"));p.drawText(4,y,label);
const int channels=std::clamp(int(levels.channels),0,8);const int count=std::max(1,channels);const int spacing=430/count;
QStringList names=channels==1?QStringList{"M"}:channels==2?QStringList{"L","R"}:channels==6?QStringList{"L","R","C","LFE","BL","BR"}:channels==8?QStringList{"L","R","C","LFE","BL","BR","SL","SR"}:QStringList{};
if(source && audio.value("channelLayout").toString().contains("5.1(side)"))names={"L","R","C","LFE","SL","SR"};
for(int c=0;c<channels;++c){
const double db=20*std::log10(std::max(1e-6f,levels.values[c]));const int height=qRound(std::clamp((db+60)/60,0.,1.)*125);const QRect bar(4+c*spacing,y+14,spacing-12,150);
p.fillRect(bar,QColor(25,25,27));QLinearGradient gradient(bar.bottomLeft(),bar.topLeft());gradient.setColorAt(0,QColor("#628929"));gradient.setColorAt(.72,QColor("#b98a21"));gradient.setColorAt(1,QColor("#bd1616"));p.fillRect(QRect(bar.left(),bar.top()+125-height,bar.width(),height),gradient);
p.setPen(QColor("#e8eaed"));p.drawText(bar.adjusted(0,125,0,0),Qt::AlignCenter,names.value(c,QString::number(c+1)));p.drawText(QRect(bar.left()-3,bar.bottom()+4,spacing-5,20),Qt::AlignCenter,levels.values[c]<=0?QString("−∞"):QString::number(db,'f',1));
}
};
const auto format=audio.value("sampleFormat").toString();const int bits=format.startsWith("u8")?8:format.startsWith("s16")?16:format.startsWith("s64")||format.startsWith("dbl")?64:32;
meters(76,tr("输入:%1 Hz | %2 bit %3 | %4 声道").arg(audio.value("sampleRate").toInt()).arg(bits).arg(format.contains("flt")||format.contains("dbl")?tr("浮点"):"PCM").arg(audio.value("channels").toInt()),input,true);
meters(282,tr("输出:%1 Hz | %2 bit %3 | %4 声道").arg(audio.value("outputSampleRate").toInt()).arg(audio.value("outputValidBitsPerSample").toInt()).arg(audio.value("outputFloat").toBool()?tr("浮点"):"PCM").arg(audio.value("outputChannels").toInt()),output,false);
p.setPen(QColor("#c4c8d1"));p.drawText(4,487,available?tr("声道峰值电平 (dBFS),输入为混音前 PCM"):tr("当前音频后端未提供电平读数"));p.end();
audioInfo_->showText(QString(20,'\n')+QString(65,' '));audioInfo_->showAudioPixmap(QPixmap::fromImage(image));audioInfo_->setVisible(info_->isVisible());
}
}