import{d as z,P as p,k as he,l as _,cO as ye,n as g,v as Ce,p as I,cP as Se,cQ as we,q as be,F as De,u as Pe,cR as _e,f as ee,cS as xe,N as ke,m as Ee,c as M,Y as te,h as Te,o as Ie,cT as Ae,bf as Ne,Z as F,a1 as H,a7 as ie,a0 as Oe,a2 as Ue,a3 as Ve,$ as $e,T as ne,a9 as Re,cU as Me,cV as Be,ay as ze,aW as Fe,cW as Ge,c4 as se,bh as G,at as We}from"./index-a8341fa1.js";import{C as He,B as je,a as Le,D as B,V as j,b as oe,c as L,d as Y,A as re,e as q,f as K,g as Ye,F as Q,h as W,W as ae,i as qe}from"./canvas-b3f2b616.js";import"./dayjs-919e6097.js";import{P as Ke}from"./index-04d608f8.js";var Qe=["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 a=e.current;a!==c&&s("change",c)};return function(){var o,c,a=e.prefixCls,u=e.direction,h=e.type,w=e.labelPlacement,m=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=h==="navigation",N=f?"vertical":w,V=he(a,"".concat(a,"-").concat(u),(o={},_(o,"".concat(a,"-").concat(x),x),_(o,"".concat(a,"-label-").concat(N),u==="horizontal"),_(o,"".concat(a,"-dot"),!!f),_(o,"".concat(a,"-navigation"),D),o)),$=ye((c=t.default)===null||c===void 0?void 0:c.call(t));return g("div",{class:V},[$.map(function(R,O){var U=R.props||{},n=U.prefixCls,r=n===void 0?a:n,d=Ce(U,Qe),k=T+O,P=I(I({},d),{},{stepNumber:k+1,stepIndex:k,key:k,prefixCls:r,iconPrefix:m,progressDot:f,icons:S,stepIcon:E,onStepClick:y});return v==="error"&&O===l-1&&(P.class="".concat(a,"-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=Le(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 a=e[s];if(s++,a>=224&&a<=239?(this.videoStreamType=c,this.videoDecoderConfig={codec:{[it]:"avc",[nt]:"hevc"}[c]||"unknown"},this.emit(B.VIDEO_ENCODER_CONFIG_CHANGED,this.videoDecoderConfig)):a>=192&&a<=223&&(this.audioStreamType=c,this.audioDecoderConfig={codec:{[st]:"aac",[ot]:"pcma",[rt]:"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={class:"steps-wrapper"},ut=["srcObject"],ft=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=M();let a;const u=M();let h,w;const m=M(),v=typeof VideoDecoder=="function",x=M();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?j:T()?oe:L),b=N(v?q:K),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 r=new n;return r.on(Y.VideoCodecInfo,d=>{`${d.width}${d.height}`}),r.on(Y.VideoFrame,d=>{t("play",!0),w?w.write(d):l&&x.value&&(U.value=!1,l.writeVideo(d),d.close())}),r.on(Y.Error,d=>{console.error(d),E=!1,S instanceof j&&(S=D(T()?oe:L),S.initialize().then(()=>{f&&S.configure({...f})}))}),r}function N(n){const r=new n;return r.on(re.Error,d=>{console.error(d),r instanceof q&&(b=N(K),b.initialize().then(()=>{C&&b.configure({...C})}))}),r.on(re.AudioFrame,d=>{h?h.write(d):l&&(U.value=!1,l.writeAudio(d))}),r}function V(){b?.close(),C=null}function $(){S?.close(),f=null}te(async()=>{if(i.streamPath&&i.format){a&&clearInterval(a),a=setInterval(async()=>{if(i.streamPath)try{const n=await Ge(i.streamPath);c.value=n,n.steps.some(r=>r.error)&&(se.error({message:"播放失败",description:n.steps.find(r=>r.error)?.error}),t("play","error"),clearInterval(a))}catch{}},1e3);try{switch(s&&(V(),$(),await s.close()),b=N(v?q:K),S=D(v?j:L),await S.initialize(),await b.initialize(),i.format){case"ps":s=new ae(`${G("ps","","ws")}/${i.streamPath}`),O(new at(s,W.PUSH));break;case"http-flv":s=new tt(`${G("flv","")}/${i.streamPath}`),O(new Q(s,W.PUSH));break;case"ws-flv":s=new ae(`${G("flv","","ws")}/${i.streamPath}`),O(new Q(s,W.PUSH));break;case"webrtc":const n=new RTCPeerConnection;n.ontrack=P=>{P.streams.length!==0&&(m.value=P.streams[0])},n.oniceconnectionstatechange=()=>{n.iceConnectionState},n.onicecandidate=P=>{P.candidate},n.addTransceiver("video",{direction:"recvonly"}),n.addTransceiver("audio",{direction:"recvonly"});const r=await n.createOffer();await n.setLocalDescription(r);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:r.sdp})).text();await n.setRemoteDescription(new RTCSessionDescription({type:"answer",sdp:k})),n.ondatachannel=P=>{const ge=P.channel,X=new Ye(ge);O(new Q(X,W.PUSH)),X.connect()},s=n;return}await s.connect()}catch(n){se.error({message:"播放失败",description:n instanceof Event?"连接失败":String(n)}),t("play","connect error")}}});const R="cmd".split("").map(n=>n.charCodeAt(0));Te(()=>i.pause,n=>{i.format==="ws-flv"&&s.send(new Uint8Array([...R,n?1:2]))});function O(n){if(v&&typeof MediaStreamTrackGenerator=="function"){const r=new MediaStreamTrackGenerator({kind:"audio"});h=r.writable.getWriter(),r.onmute=()=>{t("play","audio mute")};const d=new MediaStreamTrackGenerator({kind:"video"});w=d.writable.getWriter(),d.onmute=()=>{t("play","videomute")},m.value=new MediaStream([r,d])}n.on(B.VIDEO_ENCODER_CONFIG_CHANGED,r=>{f={...r},delete f.description,S.state==="initialized"&&S.configure(f),!v&&x.value&&(l=new qe(x.value))}),n.on(B.AUDIO_ENCODER_CONFIG_CHANGED,r=>{C=r;try{b.configure({...r})}catch(d){console.error(d)}}),n.gotVideo=r=>{try{if(S.state!=="configured"){console.warn("Video decoder not configured yet, waiting...");return}if(!E&&r.type!=="key"){console.warn("Waiting for keyframe...");return}r.type==="key"&&(E||(E=!0)),S.decode(r),y=r.timestamp,i.startTime!==void 0&&i.startTime!==null&&t("postion",y-o+i.startTime)}catch(d){console.error(d,r)}},n.gotAudio=r=>{if(b.state!=="configured"){console.warn("Audio decoder not configured yet, waiting...");return}b.decode(r)}}const U=M(!0);return Ie(()=>{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}Ae(u.value,"canplay",()=>{U.value=!1,clearInterval(a)})}),Ne(()=>{clearInterval(a),s?.close(),w&&w.close(),h&&h.close(),l&&(l=null)}),(n,r)=>(F(),H("div",ct,[U.value?(F(),H("div",lt,[ie("div",dt,[g(ne(le),{current:c.value?.currentStep,direction:"vertical",size:"small"},{default:Oe(()=>[(F(!0),H(Ue,null,Ve(c.value?.steps,(d,k)=>(F(),$e(ne(le).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"])])])):Re("",!0),Me(ie("video",{ref_key:"videoEle",ref:u,class:ze(["video",{videoShadow:n.videoShadow}]),srcObject:m.value,autoplay:""},null,10,ut),[[Be,!U.value]]),Fe(n.$slots,"default",{},void 0,!0)]))}});const gt=We(ft,[["__scopeId","data-v-b6320304"]]);export{gt as V}; //# sourceMappingURL=jb4-7b5b6ba3.js.map