(inBytes, scope)
| 1271 | |
| 1272 | //=======从WebM字节流中提取pcm数据,提取成功返回Float32Array,失败返回null||-1===== |
| 1273 | var WebM_Extract=function(inBytes, scope){ |
| 1274 | if(!scope.pos){ |
| 1275 | scope.pos=[0]; scope.tracks={}; scope.bytes=[]; |
| 1276 | }; |
| 1277 | var tracks=scope.tracks, position=[scope.pos[0]]; |
| 1278 | var endPos=function(){ scope.pos[0]=position[0] }; |
| 1279 | |
| 1280 | var sBL=scope.bytes.length; |
| 1281 | var bytes=new Uint8Array(sBL+inBytes.length); |
| 1282 | bytes.set(scope.bytes); bytes.set(inBytes,sBL); |
| 1283 | scope.bytes=bytes; |
| 1284 | |
| 1285 | //先读取文件头和Track信息 |
| 1286 | if(!scope._ht){ |
| 1287 | readMatroskaVInt(bytes, position);//EBML Header |
| 1288 | readMatroskaBlock(bytes, position);//跳过EBML Header内容 |
| 1289 | if(!BytesEq(readMatroskaVInt(bytes, position), [0x18,0x53,0x80,0x67])){ |
| 1290 | return;//未识别到Segment |
| 1291 | } |
| 1292 | readMatroskaVInt(bytes, position);//跳过Segment长度值 |
| 1293 | while(position[0]<bytes.length){ |
| 1294 | var eid0=readMatroskaVInt(bytes, position); |
| 1295 | var bytes0=readMatroskaBlock(bytes, position); |
| 1296 | var pos0=[0],audioIdx=0; |
| 1297 | if(!bytes0)return;//数据不全,等待缓冲 |
| 1298 | //Track完整数据,循环读取TrackEntry |
| 1299 | if(BytesEq(eid0, [0x16,0x54,0xAE,0x6B])){ |
| 1300 | while(pos0[0]<bytes0.length){ |
| 1301 | var eid1=readMatroskaVInt(bytes0, pos0); |
| 1302 | var bytes1=readMatroskaBlock(bytes0, pos0); |
| 1303 | var pos1=[0],track={channels:0,sampleRate:0}; |
| 1304 | if(BytesEq(eid1, [0xAE])){//TrackEntry |
| 1305 | while(pos1[0]<bytes1.length){ |
| 1306 | var eid2=readMatroskaVInt(bytes1, pos1); |
| 1307 | var bytes2=readMatroskaBlock(bytes1, pos1); |
| 1308 | var pos2=[0]; |
| 1309 | if(BytesEq(eid2, [0xD7])){//Track Number |
| 1310 | var val=BytesInt(bytes2); |
| 1311 | track.number=val; |
| 1312 | tracks[val]=track; |
| 1313 | }else if(BytesEq(eid2, [0x83])){//Track Type |
| 1314 | var val=BytesInt(bytes2); |
| 1315 | if(val==1) track.type="video"; |
| 1316 | else if(val==2) { |
| 1317 | track.type="audio"; |
| 1318 | if(!audioIdx) scope.track0=track; |
| 1319 | track.idx=audioIdx++; |
| 1320 | }else track.type="Type-"+val; |
| 1321 | }else if(BytesEq(eid2, [0x86])){//Track Codec |
| 1322 | var str=""; |
| 1323 | for(var i=0;i<bytes2.length;i++){ |
| 1324 | str+=String.fromCharCode(bytes2[i]); |
| 1325 | } |
| 1326 | track.codec=str; |
| 1327 | }else if(BytesEq(eid2, [0xE1])){ |
| 1328 | while(pos2[0]<bytes2.length){//循环读取 Audio 属性 |
| 1329 | var eid3=readMatroskaVInt(bytes2, pos2); |
| 1330 | var bytes3=readMatroskaBlock(bytes2, pos2); |
no test coverage detected
searching dependent graphs…