import{d as z,P as p,k as ve,l as _,cY as ge,n as g,v as ye,p as I,cN as Ce,d7 as Se,q as we,F as be,u as De,d8 as Pe,f as ee,d5 as _e,N as xe,m as ke,c as R,Y as te,h as Ee,o as Te,cL as Ie,be as Ae,Z as F,a1 as H,a0 as Ne,a2 as Oe,a3 as Ue,$ as Ve,T as ie,a9 as $e,cI as Me,cJ as Re,a7 as Be,ay as ze,aV as Fe,d9 as Ge,c9 as ne,bg as G,at as je}from"./index-8a67e3df.js";import{h as He,B as Le,i as We,f as B,d as L,g as se,V as W,b as Y,c as oe,a as q,A as J,j as Ye,F as K,D as j,e as ae,C as qe}from"./canvas-2aaf4e1d.js";import"./dayjs-919e6097.js";import{P as Je}from"./index-6a257713.js";var Ke=["prefixCls"];const Ze=z({compatConfig:{MODE:3},name:"Steps",props:{type:p.string.def("default"),prefixCls:p.string.def("vc-steps"),iconPrefix:p.string.def("vc"),direction:p.string.def("horizontal"),labelPlacement:p.string.def("horizontal"),status:p.string.def("process"),size:p.string.def(""),progressDot:p.oneOfType([p.looseBool,p.func]).def(void 0),initial:p.number.def(0),current:p.number.def(0),icons:p.shape({finish:p.any,error:p.any}).loose,stepIcon:Function},slots:["stepIcon","progressDot"],emits:["change"],setup:function(e,i){var t=i.slots,s=i.emit,y=function(c){var r=e.current;r!==c&&s("change",c)};return function(){var o,c,r=e.prefixCls,u=e.direction,m=e.type,w=e.labelPlacement,h=e.iconPrefix,v=e.status,x=e.size,l=e.current,C=e.progressDot,f=C===void 0?t.progressDot:C,T=e.initial,S=e.icons,b=e.stepIcon,E=b===void 0?t.stepIcon:b,D=m==="navigation",N=f?"vertical":w,V=ve(r,"".concat(r,"-").concat(u),(o={},_(o,"".concat(r,"-").concat(x),x),_(o,"".concat(r,"-label-").concat(N),u==="horizontal"),_(o,"".concat(r,"-dot"),!!f),_(o,"".concat(r,"-navigation"),D),o)),$=ge((c=t.default)===null||c===void 0?void 0:c.call(t));return g("div",{class:V},[$.map(function(M,O){var U=M.props||{},n=U.prefixCls,a=n===void 0?r:n,d=ye(U,Ke),k=T+O,P=I(I({},d),{},{stepNumber:k+1,stepIndex:k,key:k,prefixCls:a,iconPrefix:h,progressDot:f,icons:S,stepIcon:E,onStepClick:y});return v==="error"&&O===l-1&&(P.class="".concat(r,"-next-error")),d.status||(k===l?P.status=v:k>1===32)this.startTime=Date.now(),this.currentPTS=this.pts;else return!1;else if((i[4]&15)==7)this.startTime=Date.now(),this.currentPTS=this.pts;else return!1;if(this.currentPTS==this.pts)return i[4]&15,this.videoBufferSize+=i.length,t.push(i.slice()),!1;if(t.length&&this.currentPTS!=this.pts){let s=0,y="key";return this.videoDecoderConfig?.codec=="hevc"?(t[0][4]&126)>>1!=32&&(y="delta"):(t[0][4]&15)==1&&(y="delta"),this.gotVideo?.({type:y,data:t.length==1?t[0]:t.reduce((o,c)=>(o.subarray(s).set(c),s+=c.length,o),new Uint8Array(this.videoBufferSize)),timestamp:(Date.now()-this.startTime)*1e3}),t.length=0,!0}return this.videoBufferSize+=i.length,t.push(i.slice()),this.currentPTS=this.pts,!1}demuxAudio(e){const i=this.parsePESPacket(e);if(this.audioDecoderConfig?.codec=="aac"&&!this.audioDecoderConfig?.description){const t=We(i.subarray(7));this.audioDecoderConfig={codec:"aac",description:t.audioSpecificConfig,sampleRate:t.sampleRate,numberOfChannels:t.channel},this.emit(B.AUDIO_ENCODER_CONFIG_CHANGED,this.audioDecoderConfig)}return this.gotAudio?.({type:"key",data:this.audioDecoderConfig?.codec=="aac"?i.subarray(7):i,timestamp:this.dts,duration:0}),!0}parsePESPacket(e){if(e.length<4)throw new Error("Short buffer");const i=e[1],t=i>>7==1,s=(i&64)>>6==1,y=e[2];if(e.length4&&(this.pts=(o[0]&14)<<29|o[1]<<22|(o[2]&254)<<14|o[3]<<7|o[4]>>1,s&&o.length>9?this.dts=(o[5]&14)<<29|o[6]<<22|(o[7]&254)<<14|o[8]<<7|o[9]>>1:this.dts=this.pts),e.subarray(3+y)}decProgramStreamMap(e){const i=new DataView(e.buffer,e.byteOffset,e.byteLength),t=e.length;let s=2;const y=i.getUint16(s);s+=2,s+=y;let o=i.getUint16(s);for(s+=2;o>0&&!(t<=s+1);){const c=e[s];s++;const r=e[s];if(s++,r>=224&&r<=239?(this.videoStreamType=c,this.videoDecoderConfig={codec:{[it]:"avc",[nt]:"hevc"}[c]||"unknown"},this.emit(B.VIDEO_ENCODER_CONFIG_CHANGED,this.videoDecoderConfig)):r>=192&&r<=223&&(this.audioStreamType=c,this.audioDecoderConfig={codec:{[st]:"aac",[ot]:"pcma",[at]:"pcmu"}[c]||"unknown",numberOfChannels:1,sampleRate:8e3},this.audioDecoderConfig.codec!="aac"&&this.emit(B.AUDIO_ENCODER_CONFIG_CHANGED,this.audioDecoderConfig)),t<=s+1)break;const u=i.getUint16(s);s+=2,s+=u,o-=4+u}}}const ct={class:"video-container"},lt={key:0,class:"loading-container"},dt=["srcObject"],ut=z({__name:"jb4",props:{videoShadow:{},streamPath:{},format:{},speed:{},pause:{type:Boolean},startTime:{}},emits:["postion","play"],setup(A,{emit:e}){const i=A,t=e;let s,y=0,o=0;const c=R();let r;const u=R();let m,w;const h=R(),v=typeof VideoDecoder=="function",x=R();let l=null,C=null,f=null;function T(){return typeof WebAssembly>"u"?!1:WebAssembly.validate(new Uint8Array([0,97,115,109,1,0,0,0,1,5,1,96,0,1,123,3,2,1,0,10,10,1,8,0,65,0,253,15,253,98,11]))}let S=D(v?L:T()?se:W),b=N(v?q:J),E=!1;te(()=>{u.value&&(u.value.addEventListener("playing",()=>{t("play",!0)}),u.value.addEventListener("pause",()=>{t("play","pause")}),u.value.addEventListener("ended",()=>{t("play","ended")}),u.value.addEventListener("error",()=>{t("play","error")}))});function D(n){const a=new n;return a.on(Y.VideoCodecInfo,d=>{`${d.width}${d.height}`}),a.on(Y.VideoFrame,d=>{t("play",!0),w?w.write(d):l&&x.value&&(U.value=!1,l.writeVideo(d),d.close())}),a.on(Y.Error,d=>{console.error(d),E=!1,S instanceof L&&(S=D(T()?se:W),S.initialize().then(()=>{f&&S.configure({...f})}))}),a}function N(n){const a=new n;return a.on(oe.Error,d=>{console.error(d),a instanceof q&&(b=N(J),b.initialize().then(()=>{C&&b.configure({...C})}))}),a.on(oe.AudioFrame,d=>{m?m.write(d):l&&(U.value=!1,l.writeAudio(d))}),a}function V(){b?.close(),C=null}function $(){S?.close(),f=null}te(async()=>{if(i.streamPath&&i.format){r&&clearInterval(r),r=setInterval(async()=>{if(i.streamPath)try{const n=await Ge(i.streamPath);c.value=n,n.steps.some(a=>a.error)&&(ne.error({message:"播放失败",description:n.steps.find(a=>a.error)?.error}),t("play","error"),clearInterval(r))}catch{}},1e3);try{switch(s&&(V(),$(),await s.close()),b=N(v?q:J),S=D(v?L:W),await S.initialize(),await b.initialize(),i.format){case"ps":s=new ae(`${G("ps","","ws")}/${i.streamPath}`),O(new rt(s,j.PUSH));break;case"http-flv":s=new tt(`${G("flv","")}/${i.streamPath}`),O(new K(s,j.PUSH));break;case"ws-flv":s=new ae(`${G("flv","","ws")}/${i.streamPath}`),O(new K(s,j.PUSH));break;case"webrtc":const n=new RTCPeerConnection;n.ontrack=P=>{P.streams.length!==0&&(h.value=P.streams[0])},n.oniceconnectionstatechange=()=>{n.iceConnectionState},n.onicecandidate=P=>{P.candidate},n.addTransceiver("video",{direction:"recvonly"}),n.addTransceiver("audio",{direction:"recvonly"});const a=await n.createOffer();await n.setLocalDescription(a);const k=await(await fetch(`${G("webrtc","/play")}/${i.streamPath}`,{method:"POST",mode:"cors",cache:"no-cache",credentials:"include",redirect:"follow",referrerPolicy:"no-referrer",headers:{"Content-Type":"application/sdp"},body:a.sdp})).text();await n.setRemoteDescription(new RTCSessionDescription({type:"answer",sdp:k})),n.ondatachannel=P=>{const he=P.channel,X=new Ye(he);O(new K(X,j.PUSH)),X.connect()},s=n;return}await s.connect()}catch(n){ne.error({message:"播放失败",description:n instanceof Event?"连接失败":String(n)}),t("play","connect error")}}});const M="cmd".split("").map(n=>n.charCodeAt(0));Ee(()=>i.pause,n=>{i.format==="ws-flv"&&s.send(new Uint8Array([...M,n?1:2]))});function O(n){if(v&&typeof MediaStreamTrackGenerator=="function"){const a=new MediaStreamTrackGenerator({kind:"audio"});m=a.writable.getWriter(),a.onmute=()=>{t("play","audio mute")};const d=new MediaStreamTrackGenerator({kind:"video"});w=d.writable.getWriter(),d.onmute=()=>{t("play","videomute")},h.value=new MediaStream([a,d])}n.on(B.VIDEO_ENCODER_CONFIG_CHANGED,a=>{f={...a},delete f.description,S.state==="initialized"&&S.configure(f),!v&&x.value&&(l=new qe(x.value))}),n.on(B.AUDIO_ENCODER_CONFIG_CHANGED,a=>{C=a;try{b.configure({...a})}catch(d){console.error(d)}}),n.gotVideo=a=>{try{if(S.state!=="configured"){console.warn("Video decoder not configured yet, waiting...");return}if(!E&&a.type!=="key"){console.warn("Waiting for keyframe...");return}a.type==="key"&&(E||(E=!0)),S.decode(a),y=a.timestamp,i.startTime!==void 0&&i.startTime!==null&&t("postion",y-o+i.startTime)}catch(d){console.error(d,a)}},n.gotAudio=a=>{if(b.state!=="configured"){console.warn("Audio decoder not configured yet, waiting...");return}b.decode(a)}}const U=R(!0);return Te(()=>{if(!v&&u.value){const n=document.createElement("canvas");n.style.width="100%",n.style.objectFit="cover",n.style.borderRadius="6px",i.videoShadow&&(n.style.boxShadow="4px 4px 8px 4px #dedede"),u.value.parentElement?.replaceChild(n,u.value),x.value=n}Ie(u.value,"canplay",()=>{U.value=!1,clearInterval(r)})}),Ae(()=>{clearInterval(r),s?.close(),w&&w.close(),m&&m.close(),l&&(l=null)}),(n,a)=>(F(),H("div",ct,[U.value?(F(),H("div",lt,[g(ie(ce),{current:c.value?.currentStep,direction:"vertical",size:"small"},{default:Ne(()=>[(F(!0),H(Oe,null,Ue(c.value?.steps,(d,k)=>(F(),Ve(ie(ce).Step,{key:k,title:d.name,description:d.description,status:d.error?"error":k==c.value?.currentStep?"process":"wait"},null,8,["title","description","status"]))),128))]),_:1},8,["current"])])):$e("",!0),Me(Be("video",{ref_key:"videoEle",ref:u,class:ze(["video",{videoShadow:n.videoShadow}]),srcObject:h.value,autoplay:""},null,10,dt),[[Re,!U.value]]),Fe(n.$slots,"default",{},void 0,!0)]))}});const ht=je(ut,[["__scopeId","data-v-de0eabac"]]);export{ht as V}; //# sourceMappingURL=jb4-5138f1a1.js.map