Files
piik/internal/app/nativecontrol/wire.go
T
AAA 72ca6f2bc9 fix(media): improve sharing recovery and mobile picture controls
Windows capture-device errors could end an otherwise recoverable share, and reused Browser frames could arrive with the wrong orientation on receivers without the same orientation extension. Recover through the existing capture generation, start new encoded generations with an independent frame, and normalize orientation before shared encoding.

The maintenance scope also keeps compact headers aligned, cycles local rotation through four directions, accepts late coordinated UDP replies, requests Browser own-audio exclusion, and improves capture/input diagnostics. It preserves the published 2.x protocol and storage contracts.

Validation: 106 test files / 1878 tests, TypeScript, production Web/website builds, Windows Go core tests/vet and supported cross-builds passed. Candidate CI passed all 3 Server and 6 App targets, including native macOS builds, plus vulnerability and race checks. Controlled WGC/Pion recovery, retained-clock/first-frame checks, Browser orientation/SFU playback and responsive-header checks passed. The downloaded candidate set passed the existing publication dry-run: all 9 targets and 10 distribution packages share v2.5.2 and source 916baefa05, with matching checksums.

Original-device investigations remain open, including #502 and the reported low source frame rate. This PR does not claim those reports are resolved.

## Release notes

**Piik, now in your pocket.**

Piik App supports Android screen sharing, with touch controls for a friend's computer.

**手机,也能开播。**

Piik App 支持 Android 屏幕分享,也能用手机控制朋友的电脑。

### English

Piik v2.5.2 improves sharing recovery, picture orientation and mobile controls. It keeps the existing 2.x compatibility baseline.

- Improve Windows sharing recovery after graphics-device errors, and resume new encoder generations with a decodable picture.
- Preserve rotated and mirrored pictures when Browser encoding is shared across receivers, including SFU routes.
- Rotate the local picture in 90° steps; keep mobile header controls aligned and its connection indicator visible.
- Improve P2P establishment when coordinated UDP replies arrive late.
- Ask compatible browsers to exclude Piik's own playback from screen audio, and improve native capture and remote-input diagnostics.

Update the App and self-hosted site together to receive all fixes, then refresh open pages. Browser settings and existing room data are retained.

### 中文

Piik v2.5.2 改善分享恢复、画面方向与手机操作,沿用现有 2.x 兼容基线。

- 改善 Windows 图形设备异常后的分享恢复,新编码器接替时从可正常解码的画面开始。
- 修正浏览器共享编码时旋转或镜像画面的方向,覆盖 SFU 等接收线路。
- 本机画面每次旋转 90°;手机顶部工具栏保持对齐,连接状态清晰可见。
- 改善协同打洞时 UDP 回复较晚到达的 P2P 建连。
- 向支持的浏览器请求排除 Piik 页面自身播放的声音,并完善原生采集与远控输入的诊断信息。

请一起更新 App 与自部署站点,以获得全部修复,随后刷新已打开的页面。浏览器设置与已有房间数据保留。
2026-11-01 12:00:26 -04:00

397 lines
12 KiB
Go

package nativecontrol
import (
"github.com/TNTcraftHIM/Piik/internal/app/mediaedge"
"github.com/TNTcraftHIM/Piik/internal/app/nativecapture"
"github.com/TNTcraftHIM/Piik/internal/app/remoteinput"
"github.com/TNTcraftHIM/Piik/internal/server/protocol"
"github.com/pion/webrtc/v4"
)
type requestEnvelope struct {
reportSourceCancellation bool
Version int `json:"version"`
ID string `json:"id"`
Type string `json:"type"`
}
type responseEnvelope struct {
Version int `json:"version"`
ID string `json:"id"`
Type string `json:"type"`
}
type requestFailedResponse struct {
responseEnvelope
Code string `json:"code"`
}
type captureOptionsRequest requestEnvelope
type listSourcesRequest requestEnvelope
type sourcePreviewRequest struct {
Version int `json:"version"`
ID string `json:"id"`
Type string `json:"type"`
Source nativecapture.CaptureTarget `json:"source"`
}
type qualitySettings = protocol.QualitySettings
type startShareRequest struct {
ReportSourceCancellation bool `json:"reportSourceCancellation,omitempty"`
ReportCaptureFailure bool `json:"reportCaptureFailure,omitempty"`
Version int `json:"version"`
ID string `json:"id"`
Type string `json:"type"`
ShareID string `json:"shareId"`
Source nativecapture.CaptureTarget `json:"source"`
Audio bool `json:"audio"`
MicrophoneMixing bool `json:"microphoneMixing,omitempty"`
RemoteInput bool `json:"remoteInput,omitempty"`
ExcludeAudio *nativecapture.CaptureTarget `json:"excludeAudio,omitempty"`
ShowCaptureBorder bool `json:"showCaptureBorder,omitempty"`
AdapterIndex uint32 `json:"adapterIndex"`
EncoderIndex uint32 `json:"encoderIndex"`
EdgeCapacity int `json:"edgeCapacity"`
Profile qualitySettings `json:"profile"`
Codec string `json:"codec"`
}
type microphoneRequest struct {
requestEnvelope
ShareID string `json:"shareId"`
Enabled *bool `json:"enabled,omitempty"`
Volume *float64 `json:"volume,omitempty"`
DeviceID *string `json:"deviceId,omitempty"`
}
type shareVolumeRequest struct {
requestEnvelope
ShareID string `json:"shareId"`
Volume *float64 `json:"volume"`
}
type remoteControlRequest struct {
requestEnvelope
ShareID string `json:"shareId"`
RequestID string `json:"requestId"`
Allow *bool `json:"allow"`
}
type remoteInputPeersRequest struct {
requestEnvelope
ShareID string `json:"shareId"`
Peers []protocol.RemoteInputPeer `json:"peers"`
}
type remoteControlPolicyRequest struct {
requestEnvelope
ShareID string `json:"shareId"`
Mode string `json:"mode"`
Password string `json:"password,omitempty"`
CoPlay bool `json:"coPlay,omitempty"`
}
type remoteControlStateEvent struct {
eventEnvelope
remoteinput.State
}
type remoteControlSimultaneousRequest struct {
requestEnvelope
ShareID string `json:"shareId"`
Enabled *bool `json:"enabled"`
}
type remoteStopShortcutRequest struct {
requestEnvelope
ShareID string `json:"shareId"`
Key int `json:"key,omitempty"`
}
type remoteStopShortcutResponse struct {
responseEnvelope
remoteinput.StopShortcut
}
type audioStateEvent struct {
eventEnvelope
SourceAudio bool `json:"sourceAudio"`
Microphone bool `json:"microphone"`
Failed bool `json:"failed"`
}
type updateShareRequest struct {
Version int `json:"version"`
ID string `json:"id"`
Type string `json:"type"`
ShareID string `json:"shareId"`
Profile qualitySettings `json:"profile"`
}
type replaceShareSourceRequest struct {
ReportSourceCancellation bool `json:"reportSourceCancellation,omitempty"`
Version int `json:"version"`
ID string `json:"id"`
Type string `json:"type"`
ShareID string `json:"shareId"`
Source nativecapture.CaptureTarget `json:"source"`
Audio bool `json:"audio"`
ExcludeAudio *nativecapture.CaptureTarget `json:"excludeAudio,omitempty"`
ShowCaptureBorder bool `json:"showCaptureBorder,omitempty"`
AdapterIndex uint32 `json:"adapterIndex"`
EncoderIndex uint32 `json:"encoderIndex"`
}
type stopShareRequest struct {
Version int `json:"version"`
ID string `json:"id"`
Type string `json:"type"`
ShareID string `json:"shareId"`
}
type pauseShareRequest struct {
Version int `json:"version"`
ID string `json:"id"`
Type string `json:"type"`
ShareID string `json:"shareId"`
Paused bool `json:"paused"`
}
type iceServer struct {
URLs []string `json:"urls"`
}
type prepareEdgeRequest struct {
Version int `json:"version"`
ID string `json:"id"`
Type string `json:"type"`
ShareID string `json:"shareId"`
ConnectionID string `json:"connectionId"`
SourceConnectionID string `json:"sourceConnectionId,omitempty"`
ICEServers []iceServer `json:"iceServers"`
Punched bool `json:"punched,omitempty"`
}
type prepareLocalEdgeRequest struct {
Version int `json:"version"`
ID string `json:"id"`
Type string `json:"type"`
ShareID string `json:"shareId"`
ConnectionID string `json:"connectionId"`
SourceConnectionID string `json:"sourceConnectionId,omitempty"`
Restart bool `json:"restart"`
}
type receiveOfferRequest struct {
Version int `json:"version"`
ID string `json:"id"`
Type string `json:"type"`
ShareID string `json:"shareId"`
ConnectionID string `json:"connectionId"`
EdgeCapacity int `json:"edgeCapacity"`
ICEServers []iceServer `json:"iceServers"`
SDP string `json:"sdp"`
ReuseReceiver bool `json:"reuseReceiver,omitempty"`
Punched bool `json:"punched,omitempty"`
}
type receiveCandidateRequest struct {
Version int `json:"version"`
ID string `json:"id"`
Type string `json:"type"`
ShareID string `json:"shareId"`
ConnectionID string `json:"connectionId"`
Candidate *webrtc.ICECandidateInit `json:"candidate"`
}
type closeReceiverRequest struct {
Version int `json:"version"`
ID string `json:"id"`
Type string `json:"type"`
ShareID string `json:"shareId"`
ConnectionID string `json:"connectionId"`
}
type stopReceiveRequest struct {
Version int `json:"version"`
ID string `json:"id"`
Type string `json:"type"`
ShareID string `json:"shareId"`
}
type edgeAnswerRequest struct {
Version int `json:"version"`
ID string `json:"id"`
Type string `json:"type"`
ShareID string `json:"shareId"`
ConnectionID string `json:"connectionId"`
SDP string `json:"sdp"`
OfferID string `json:"offerId,omitempty"`
}
type edgeCandidateRequest struct {
Version int `json:"version"`
ID string `json:"id"`
Type string `json:"type"`
ShareID string `json:"shareId"`
ConnectionID string `json:"connectionId"`
Candidate *webrtc.ICECandidateInit `json:"candidate"`
}
type closeEdgeRequest struct {
Version int `json:"version"`
ID string `json:"id"`
Type string `json:"type"`
ShareID string `json:"shareId"`
ConnectionID string `json:"connectionId"`
}
type sourceListResponse struct {
responseEnvelope
Sources []nativecapture.CaptureTarget `json:"sources"`
}
type sourcePreviewResponse struct {
responseEnvelope
SourceKey string `json:"sourceKey"`
Mime string `json:"mime"`
Data string `json:"data"`
}
type captureOptionsResponse struct {
responseEnvelope
Adapters []nativecapture.Adapter `json:"adapters"`
}
type shareStartedResponse struct {
responseEnvelope
ShareID string `json:"shareId"`
Audio bool `json:"audio"`
SourceAudio *bool `json:"sourceAudio,omitempty"`
Codec string `json:"codec"`
}
type shareUpdatedResponse struct {
responseEnvelope
ShareID string `json:"shareId"`
}
type shareSourceReplacedResponse struct {
responseEnvelope
ShareID string `json:"shareId"`
}
type edgeOfferResponse struct {
responseEnvelope
ShareID string `json:"shareId"`
ConnectionID string `json:"connectionId"`
SDP string `json:"sdp"`
}
type receiveAnswerResponse struct {
responseEnvelope
ShareID string `json:"shareId"`
ConnectionID string `json:"connectionId"`
SDP string `json:"sdp"`
Audio bool `json:"audio"`
Codec string `json:"codec"`
Reused *bool `json:"reused,omitempty"`
}
type eventEnvelope struct {
Version int `json:"version"`
Type string `json:"type"`
ShareID string `json:"shareId"`
ConnectionID string `json:"connectionId,omitempty"`
PublicationGeneration string `json:"publicationGeneration,omitempty"`
}
type publicationIdentity struct {
requestEnvelope
ShareID string `json:"shareId"`
PublicationGeneration string `json:"publicationGeneration"`
ConnectionID string `json:"connectionId"`
}
type preparePublicationRequest struct {
publicationIdentity
ICEServers []iceServer `json:"iceServers"`
}
type publicationAnswerRequest struct {
publicationIdentity
SDP string `json:"sdp"`
}
type publicationCandidateRequest struct {
publicationIdentity
Candidate *webrtc.ICECandidateInit `json:"candidate"`
}
type publicationLayersRequest struct {
publicationIdentity
ActiveCount *int `json:"activeCount"`
}
type publicationResponse struct {
responseEnvelope
ShareID string `json:"shareId"`
PublicationGeneration string `json:"publicationGeneration"`
ConnectionID string `json:"connectionId"`
SDP string `json:"sdp,omitempty"`
Media mediaedge.PublicationMedia `json:"media"`
}
type publicationQualityEvent struct {
eventEnvelope
mediaedge.PublicationQualitySample
}
type captureStateEvent struct {
eventEnvelope
State string `json:"state"`
}
type edgeCandidateEvent struct {
eventEnvelope
Candidate *webrtc.ICECandidateInit `json:"candidate"`
}
type edgeStateEvent struct {
eventEnvelope
State string `json:"state"`
}
type edgePathEvent struct {
eventEnvelope
LocalType string `json:"localType"`
RemoteType string `json:"remoteType"`
NatTraversalPath string `json:"natTraversalPath"`
}
type edgeQualityEvent struct {
eventEnvelope
SampleTimestampMs int64 `json:"sampleTimestampMs"`
SampleWindowMs int64 `json:"sampleWindowMs"`
RTPStatsID string `json:"rtpStatsId"`
TrackIdentifier string `json:"trackIdentifier"`
State string `json:"state"`
Reason *string `json:"reason"`
IntervalFramesSent uint64 `json:"intervalFramesEncoded"` // Published v10 name for output frames.
FramesPerSecond float64 `json:"framesPerSecond"`
BitrateKbps float64 `json:"bitrateKbps"`
AvailableOutgoingKbps float64 `json:"availableOutgoingKbps"`
Width uint32 `json:"width"`
Height uint32 `json:"height"`
}
type shareEndedEvent struct {
Version int `json:"version"`
Type string `json:"type"`
ShareID string `json:"shareId"`
Failed bool `json:"failed"`
Failure *nativecapture.Failure `json:"failure,omitempty"`
}