mpeg1.js 49 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683
  1. JSMpeg.Decoder.MPEG1Video = (function(){ "use strict";
  2. // Inspired by Java MPEG-1 Video Decoder and Player by Zoltan Korandi
  3. // https://sourceforge.net/projects/javampeg1video/
  4. var MPEG1 = function(options) {
  5. JSMpeg.Decoder.Base.call(this, options);
  6. this.onDecodeCallback = options.onVideoDecode;
  7. var bufferSize = options.videoBufferSize || 512*1024;
  8. var bufferMode = options.streaming
  9. ? JSMpeg.BitBuffer.MODE.EVICT
  10. : JSMpeg.BitBuffer.MODE.EXPAND;
  11. this.bits = new JSMpeg.BitBuffer(bufferSize, bufferMode);
  12. this.customIntraQuantMatrix = new Uint8Array(64);
  13. this.customNonIntraQuantMatrix = new Uint8Array(64);
  14. this.blockData = new Int32Array(64);
  15. this.currentFrame = 0;
  16. this.decodeFirstFrame = options.decodeFirstFrame !== false;
  17. };
  18. MPEG1.prototype = Object.create(JSMpeg.Decoder.Base.prototype);
  19. MPEG1.prototype.constructor = MPEG1;
  20. MPEG1.prototype.write = function(pts, buffers) {
  21. JSMpeg.Decoder.Base.prototype.write.call(this, pts, buffers);
  22. if (!this.hasSequenceHeader) {
  23. if (this.bits.findStartCode(MPEG1.START.SEQUENCE) === -1) {
  24. return false;
  25. }
  26. this.decodeSequenceHeader();
  27. if (this.decodeFirstFrame) {
  28. this.decode();
  29. }
  30. }
  31. };
  32. MPEG1.prototype.decode = function() {
  33. var startTime = JSMpeg.Now();
  34. if (!this.hasSequenceHeader) {
  35. return false;
  36. }
  37. if (this.bits.findStartCode(MPEG1.START.PICTURE) === -1) {
  38. var bufferedBytes = this.bits.byteLength - (this.bits.index >> 3);
  39. return false;
  40. }
  41. this.decodePicture();
  42. this.advanceDecodedTime(1/this.frameRate);
  43. var elapsedTime = JSMpeg.Now() - startTime;
  44. if (this.onDecodeCallback) {
  45. this.onDecodeCallback(this, elapsedTime);
  46. }
  47. return true;
  48. };
  49. MPEG1.prototype.readHuffman = function(codeTable) {
  50. var state = 0;
  51. do {
  52. state = codeTable[state + this.bits.read(1)];
  53. } while (state >= 0 && codeTable[state] !== 0);
  54. return codeTable[state+2];
  55. };
  56. // Sequence Layer
  57. MPEG1.prototype.frameRate = 30;
  58. MPEG1.prototype.decodeSequenceHeader = function() {
  59. var newWidth = this.bits.read(12),
  60. newHeight = this.bits.read(12);
  61. // skip pixel aspect ratio
  62. this.bits.skip(4);
  63. this.frameRate = MPEG1.PICTURE_RATE[this.bits.read(4)];
  64. // skip bitRate, marker, bufferSize and constrained bit
  65. this.bits.skip(18 + 1 + 10 + 1);
  66. if (newWidth !== this.width || newHeight !== this.height) {
  67. this.width = newWidth;
  68. this.height = newHeight;
  69. this.initBuffers();
  70. if (this.destination) {
  71. this.destination.resize(newWidth, newHeight);
  72. }
  73. }
  74. if (this.bits.read(1)) { // load custom intra quant matrix?
  75. for (var i = 0; i < 64; i++) {
  76. this.customIntraQuantMatrix[MPEG1.ZIG_ZAG[i]] = this.bits.read(8);
  77. }
  78. this.intraQuantMatrix = this.customIntraQuantMatrix;
  79. }
  80. if (this.bits.read(1)) { // load custom non intra quant matrix?
  81. for (var i = 0; i < 64; i++) {
  82. var idx = MPEG1.ZIG_ZAG[i];
  83. this.customNonIntraQuantMatrix[idx] = this.bits.read(8);
  84. }
  85. this.nonIntraQuantMatrix = this.customNonIntraQuantMatrix;
  86. }
  87. this.hasSequenceHeader = true;
  88. };
  89. MPEG1.prototype.initBuffers = function() {
  90. this.intraQuantMatrix = MPEG1.DEFAULT_INTRA_QUANT_MATRIX;
  91. this.nonIntraQuantMatrix = MPEG1.DEFAULT_NON_INTRA_QUANT_MATRIX;
  92. this.mbWidth = (this.width + 15) >> 4;
  93. this.mbHeight = (this.height + 15) >> 4;
  94. this.mbSize = this.mbWidth * this.mbHeight;
  95. this.codedWidth = this.mbWidth << 4;
  96. this.codedHeight = this.mbHeight << 4;
  97. this.codedSize = this.codedWidth * this.codedHeight;
  98. this.halfWidth = this.mbWidth << 3;
  99. this.halfHeight = this.mbHeight << 3;
  100. // Allocated buffers and resize the canvas
  101. this.currentY = new Uint8ClampedArray(this.codedSize);
  102. this.currentY32 = new Uint32Array(this.currentY.buffer);
  103. this.currentCr = new Uint8ClampedArray(this.codedSize >> 2);
  104. this.currentCr32 = new Uint32Array(this.currentCr.buffer);
  105. this.currentCb = new Uint8ClampedArray(this.codedSize >> 2);
  106. this.currentCb32 = new Uint32Array(this.currentCb.buffer);
  107. this.forwardY = new Uint8ClampedArray(this.codedSize);
  108. this.forwardY32 = new Uint32Array(this.forwardY.buffer);
  109. this.forwardCr = new Uint8ClampedArray(this.codedSize >> 2);
  110. this.forwardCr32 = new Uint32Array(this.forwardCr.buffer);
  111. this.forwardCb = new Uint8ClampedArray(this.codedSize >> 2);
  112. this.forwardCb32 = new Uint32Array(this.forwardCb.buffer);
  113. };
  114. // Picture Layer
  115. MPEG1.prototype.currentY = null;
  116. MPEG1.prototype.currentCr = null;
  117. MPEG1.prototype.currentCb = null;
  118. MPEG1.prototype.pictureType = 0;
  119. // Buffers for motion compensation
  120. MPEG1.prototype.forwardY = null;
  121. MPEG1.prototype.forwardCr = null;
  122. MPEG1.prototype.forwardCb = null;
  123. MPEG1.prototype.fullPelForward = false;
  124. MPEG1.prototype.forwardFCode = 0;
  125. MPEG1.prototype.forwardRSize = 0;
  126. MPEG1.prototype.forwardF = 0;
  127. MPEG1.prototype.decodePicture = function(skipOutput) {
  128. this.currentFrame++;
  129. this.bits.skip(10); // skip temporalReference
  130. this.pictureType = this.bits.read(3);
  131. this.bits.skip(16); // skip vbv_delay
  132. // Skip B and D frames or unknown coding type
  133. if (this.pictureType <= 0 || this.pictureType >= MPEG1.PICTURE_TYPE.B) {
  134. return;
  135. }
  136. // full_pel_forward, forward_f_code
  137. if (this.pictureType === MPEG1.PICTURE_TYPE.PREDICTIVE) {
  138. this.fullPelForward = this.bits.read(1);
  139. this.forwardFCode = this.bits.read(3);
  140. if (this.forwardFCode === 0) {
  141. // Ignore picture with zero forward_f_code
  142. return;
  143. }
  144. this.forwardRSize = this.forwardFCode - 1;
  145. this.forwardF = 1 << this.forwardRSize;
  146. }
  147. var code = 0;
  148. do {
  149. code = this.bits.findNextStartCode();
  150. } while (code === MPEG1.START.EXTENSION || code === MPEG1.START.USER_DATA );
  151. while (code >= MPEG1.START.SLICE_FIRST && code <= MPEG1.START.SLICE_LAST) {
  152. this.decodeSlice(code & 0x000000FF);
  153. code = this.bits.findNextStartCode();
  154. }
  155. if (code !== -1) {
  156. // We found the next start code; rewind 32bits and let the main loop
  157. // handle it.
  158. this.bits.rewind(32);
  159. }
  160. // Invoke decode callbacks
  161. if (this.destination) {
  162. this.destination.render(this.currentY, this.currentCr, this.currentCb, true);
  163. }
  164. // If this is a reference picutre then rotate the prediction pointers
  165. if (
  166. this.pictureType === MPEG1.PICTURE_TYPE.INTRA ||
  167. this.pictureType === MPEG1.PICTURE_TYPE.PREDICTIVE
  168. ) {
  169. var
  170. tmpY = this.forwardY,
  171. tmpY32 = this.forwardY32,
  172. tmpCr = this.forwardCr,
  173. tmpCr32 = this.forwardCr32,
  174. tmpCb = this.forwardCb,
  175. tmpCb32 = this.forwardCb32;
  176. this.forwardY = this.currentY;
  177. this.forwardY32 = this.currentY32;
  178. this.forwardCr = this.currentCr;
  179. this.forwardCr32 = this.currentCr32;
  180. this.forwardCb = this.currentCb;
  181. this.forwardCb32 = this.currentCb32;
  182. this.currentY = tmpY;
  183. this.currentY32 = tmpY32;
  184. this.currentCr = tmpCr;
  185. this.currentCr32 = tmpCr32;
  186. this.currentCb = tmpCb;
  187. this.currentCb32 = tmpCb32;
  188. }
  189. };
  190. // Slice Layer
  191. MPEG1.prototype.quantizerScale = 0;
  192. MPEG1.prototype.sliceBegin = false;
  193. MPEG1.prototype.decodeSlice = function(slice) {
  194. this.sliceBegin = true;
  195. this.macroblockAddress = (slice - 1) * this.mbWidth - 1;
  196. // Reset motion vectors and DC predictors
  197. this.motionFwH = this.motionFwHPrev = 0;
  198. this.motionFwV = this.motionFwVPrev = 0;
  199. this.dcPredictorY = 128;
  200. this.dcPredictorCr = 128;
  201. this.dcPredictorCb = 128;
  202. this.quantizerScale = this.bits.read(5);
  203. // skip extra bits
  204. while (this.bits.read(1)) {
  205. this.bits.skip(8);
  206. }
  207. do {
  208. this.decodeMacroblock();
  209. } while (!this.bits.nextBytesAreStartCode());
  210. };
  211. // Macroblock Layer
  212. MPEG1.prototype.macroblockAddress = 0;
  213. MPEG1.prototype.mbRow = 0;
  214. MPEG1.prototype.mbCol = 0;
  215. MPEG1.prototype.macroblockType = 0;
  216. MPEG1.prototype.macroblockIntra = false;
  217. MPEG1.prototype.macroblockMotFw = false;
  218. MPEG1.prototype.motionFwH = 0;
  219. MPEG1.prototype.motionFwV = 0;
  220. MPEG1.prototype.motionFwHPrev = 0;
  221. MPEG1.prototype.motionFwVPrev = 0;
  222. MPEG1.prototype.decodeMacroblock = function() {
  223. // Decode macroblock_address_increment
  224. var
  225. increment = 0,
  226. t = this.readHuffman(MPEG1.MACROBLOCK_ADDRESS_INCREMENT);
  227. while (t === 34) {
  228. // macroblock_stuffing
  229. t = this.readHuffman(MPEG1.MACROBLOCK_ADDRESS_INCREMENT);
  230. }
  231. while (t === 35) {
  232. // macroblock_escape
  233. increment += 33;
  234. t = this.readHuffman(MPEG1.MACROBLOCK_ADDRESS_INCREMENT);
  235. }
  236. increment += t;
  237. // Process any skipped macroblocks
  238. if (this.sliceBegin) {
  239. // The first macroblock_address_increment of each slice is relative
  240. // to beginning of the preverious row, not the preverious macroblock
  241. this.sliceBegin = false;
  242. this.macroblockAddress += increment;
  243. }
  244. else {
  245. if (this.macroblockAddress + increment >= this.mbSize) {
  246. // Illegal (too large) macroblock_address_increment
  247. return;
  248. }
  249. if (increment > 1) {
  250. // Skipped macroblocks reset DC predictors
  251. this.dcPredictorY = 128;
  252. this.dcPredictorCr = 128;
  253. this.dcPredictorCb = 128;
  254. // Skipped macroblocks in P-pictures reset motion vectors
  255. if (this.pictureType === MPEG1.PICTURE_TYPE.PREDICTIVE) {
  256. this.motionFwH = this.motionFwHPrev = 0;
  257. this.motionFwV = this.motionFwVPrev = 0;
  258. }
  259. }
  260. // Predict skipped macroblocks
  261. while (increment > 1) {
  262. this.macroblockAddress++;
  263. this.mbRow = (this.macroblockAddress / this.mbWidth)|0;
  264. this.mbCol = this.macroblockAddress % this.mbWidth;
  265. this.copyMacroblock(
  266. this.motionFwH, this.motionFwV,
  267. this.forwardY, this.forwardCr, this.forwardCb
  268. );
  269. increment--;
  270. }
  271. this.macroblockAddress++;
  272. }
  273. this.mbRow = (this.macroblockAddress / this.mbWidth)|0;
  274. this.mbCol = this.macroblockAddress % this.mbWidth;
  275. // Process the current macroblock
  276. var mbTable = MPEG1.MACROBLOCK_TYPE[this.pictureType];
  277. this.macroblockType = this.readHuffman(mbTable);
  278. this.macroblockIntra = (this.macroblockType & 0x01);
  279. this.macroblockMotFw = (this.macroblockType & 0x08);
  280. // Quantizer scale
  281. if ((this.macroblockType & 0x10) !== 0) {
  282. this.quantizerScale = this.bits.read(5);
  283. }
  284. if (this.macroblockIntra) {
  285. // Intra-coded macroblocks reset motion vectors
  286. this.motionFwH = this.motionFwHPrev = 0;
  287. this.motionFwV = this.motionFwVPrev = 0;
  288. }
  289. else {
  290. // Non-intra macroblocks reset DC predictors
  291. this.dcPredictorY = 128;
  292. this.dcPredictorCr = 128;
  293. this.dcPredictorCb = 128;
  294. this.decodeMotionVectors();
  295. this.copyMacroblock(
  296. this.motionFwH, this.motionFwV,
  297. this.forwardY, this.forwardCr, this.forwardCb
  298. );
  299. }
  300. // Decode blocks
  301. var cbp = ((this.macroblockType & 0x02) !== 0)
  302. ? this.readHuffman(MPEG1.CODE_BLOCK_PATTERN)
  303. : (this.macroblockIntra ? 0x3f : 0);
  304. for (var block = 0, mask = 0x20; block < 6; block++) {
  305. if ((cbp & mask) !== 0) {
  306. this.decodeBlock(block);
  307. }
  308. mask >>= 1;
  309. }
  310. };
  311. MPEG1.prototype.decodeMotionVectors = function() {
  312. var code, d, r = 0;
  313. // Forward
  314. if (this.macroblockMotFw) {
  315. // Horizontal forward
  316. code = this.readHuffman(MPEG1.MOTION);
  317. if ((code !== 0) && (this.forwardF !== 1)) {
  318. r = this.bits.read(this.forwardRSize);
  319. d = ((Math.abs(code) - 1) << this.forwardRSize) + r + 1;
  320. if (code < 0) {
  321. d = -d;
  322. }
  323. }
  324. else {
  325. d = code;
  326. }
  327. this.motionFwHPrev += d;
  328. if (this.motionFwHPrev > (this.forwardF << 4) - 1) {
  329. this.motionFwHPrev -= this.forwardF << 5;
  330. }
  331. else if (this.motionFwHPrev < ((-this.forwardF) << 4)) {
  332. this.motionFwHPrev += this.forwardF << 5;
  333. }
  334. this.motionFwH = this.motionFwHPrev;
  335. if (this.fullPelForward) {
  336. this.motionFwH <<= 1;
  337. }
  338. // Vertical forward
  339. code = this.readHuffman(MPEG1.MOTION);
  340. if ((code !== 0) && (this.forwardF !== 1)) {
  341. r = this.bits.read(this.forwardRSize);
  342. d = ((Math.abs(code) - 1) << this.forwardRSize) + r + 1;
  343. if (code < 0) {
  344. d = -d;
  345. }
  346. }
  347. else {
  348. d = code;
  349. }
  350. this.motionFwVPrev += d;
  351. if (this.motionFwVPrev > (this.forwardF << 4) - 1) {
  352. this.motionFwVPrev -= this.forwardF << 5;
  353. }
  354. else if (this.motionFwVPrev < ((-this.forwardF) << 4)) {
  355. this.motionFwVPrev += this.forwardF << 5;
  356. }
  357. this.motionFwV = this.motionFwVPrev;
  358. if (this.fullPelForward) {
  359. this.motionFwV <<= 1;
  360. }
  361. }
  362. else if (this.pictureType === MPEG1.PICTURE_TYPE.PREDICTIVE) {
  363. // No motion information in P-picture, reset vectors
  364. this.motionFwH = this.motionFwHPrev = 0;
  365. this.motionFwV = this.motionFwVPrev = 0;
  366. }
  367. };
  368. MPEG1.prototype.copyMacroblock = function(motionH, motionV, sY, sCr, sCb) {
  369. var
  370. width, scan,
  371. H, V, oddH, oddV,
  372. src, dest, last;
  373. // We use 32bit writes here
  374. var dY = this.currentY32,
  375. dCb = this.currentCb32,
  376. dCr = this.currentCr32;
  377. // Luminance
  378. width = this.codedWidth;
  379. scan = width - 16;
  380. H = motionH >> 1;
  381. V = motionV >> 1;
  382. oddH = (motionH & 1) === 1;
  383. oddV = (motionV & 1) === 1;
  384. src = ((this.mbRow << 4) + V) * width + (this.mbCol << 4) + H;
  385. dest = (this.mbRow * width + this.mbCol) << 2;
  386. last = dest + (width << 2);
  387. var x, y1, y2, y;
  388. if (oddH) {
  389. if (oddV) {
  390. while (dest < last) {
  391. y1 = sY[src] + sY[src+width]; src++;
  392. for (x = 0; x < 4; x++) {
  393. y2 = sY[src] + sY[src+width]; src++;
  394. y = (((y1 + y2 + 2) >> 2) & 0xff);
  395. y1 = sY[src] + sY[src+width]; src++;
  396. y |= (((y1 + y2 + 2) << 6) & 0xff00);
  397. y2 = sY[src] + sY[src+width]; src++;
  398. y |= (((y1 + y2 + 2) << 14) & 0xff0000);
  399. y1 = sY[src] + sY[src+width]; src++;
  400. y |= (((y1 + y2 + 2) << 22) & 0xff000000);
  401. dY[dest++] = y;
  402. }
  403. dest += scan >> 2; src += scan-1;
  404. }
  405. }
  406. else {
  407. while (dest < last) {
  408. y1 = sY[src++];
  409. for (x = 0; x < 4; x++) {
  410. y2 = sY[src++];
  411. y = (((y1 + y2 + 1) >> 1) & 0xff);
  412. y1 = sY[src++];
  413. y |= (((y1 + y2 + 1) << 7) & 0xff00);
  414. y2 = sY[src++];
  415. y |= (((y1 + y2 + 1) << 15) & 0xff0000);
  416. y1 = sY[src++];
  417. y |= (((y1 + y2 + 1) << 23) & 0xff000000);
  418. dY[dest++] = y;
  419. }
  420. dest += scan >> 2; src += scan-1;
  421. }
  422. }
  423. }
  424. else {
  425. if (oddV) {
  426. while (dest < last) {
  427. for (x = 0; x < 4; x++) {
  428. y = (((sY[src] + sY[src+width] + 1) >> 1) & 0xff); src++;
  429. y |= (((sY[src] + sY[src+width] + 1) << 7) & 0xff00); src++;
  430. y |= (((sY[src] + sY[src+width] + 1) << 15) & 0xff0000); src++;
  431. y |= (((sY[src] + sY[src+width] + 1) << 23) & 0xff000000); src++;
  432. dY[dest++] = y;
  433. }
  434. dest += scan >> 2; src += scan;
  435. }
  436. }
  437. else {
  438. while (dest < last) {
  439. for (x = 0; x < 4; x++) {
  440. y = sY[src]; src++;
  441. y |= sY[src] << 8; src++;
  442. y |= sY[src] << 16; src++;
  443. y |= sY[src] << 24; src++;
  444. dY[dest++] = y;
  445. }
  446. dest += scan >> 2; src += scan;
  447. }
  448. }
  449. }
  450. // Chrominance
  451. width = this.halfWidth;
  452. scan = width - 8;
  453. H = (motionH/2) >> 1;
  454. V = (motionV/2) >> 1;
  455. oddH = ((motionH/2) & 1) === 1;
  456. oddV = ((motionV/2) & 1) === 1;
  457. src = ((this.mbRow << 3) + V) * width + (this.mbCol << 3) + H;
  458. dest = (this.mbRow * width + this.mbCol) << 1;
  459. last = dest + (width << 1);
  460. var cr1, cr2, cr,
  461. cb1, cb2, cb;
  462. if (oddH) {
  463. if (oddV) {
  464. while (dest < last) {
  465. cr1 = sCr[src] + sCr[src+width];
  466. cb1 = sCb[src] + sCb[src+width];
  467. src++;
  468. for (x = 0; x < 2; x++) {
  469. cr2 = sCr[src] + sCr[src+width];
  470. cb2 = sCb[src] + sCb[src+width]; src++;
  471. cr = (((cr1 + cr2 + 2) >> 2) & 0xff);
  472. cb = (((cb1 + cb2 + 2) >> 2) & 0xff);
  473. cr1 = sCr[src] + sCr[src+width];
  474. cb1 = sCb[src] + sCb[src+width]; src++;
  475. cr |= (((cr1 + cr2 + 2) << 6) & 0xff00);
  476. cb |= (((cb1 + cb2 + 2) << 6) & 0xff00);
  477. cr2 = sCr[src] + sCr[src+width];
  478. cb2 = sCb[src] + sCb[src+width]; src++;
  479. cr |= (((cr1 + cr2 + 2) << 14) & 0xff0000);
  480. cb |= (((cb1 + cb2 + 2) << 14) & 0xff0000);
  481. cr1 = sCr[src] + sCr[src+width];
  482. cb1 = sCb[src] + sCb[src+width]; src++;
  483. cr |= (((cr1 + cr2 + 2) << 22) & 0xff000000);
  484. cb |= (((cb1 + cb2 + 2) << 22) & 0xff000000);
  485. dCr[dest] = cr;
  486. dCb[dest] = cb;
  487. dest++;
  488. }
  489. dest += scan >> 2; src += scan-1;
  490. }
  491. }
  492. else {
  493. while (dest < last) {
  494. cr1 = sCr[src];
  495. cb1 = sCb[src];
  496. src++;
  497. for (x = 0; x < 2; x++) {
  498. cr2 = sCr[src];
  499. cb2 = sCb[src++];
  500. cr = (((cr1 + cr2 + 1) >> 1) & 0xff);
  501. cb = (((cb1 + cb2 + 1) >> 1) & 0xff);
  502. cr1 = sCr[src];
  503. cb1 = sCb[src++];
  504. cr |= (((cr1 + cr2 + 1) << 7) & 0xff00);
  505. cb |= (((cb1 + cb2 + 1) << 7) & 0xff00);
  506. cr2 = sCr[src];
  507. cb2 = sCb[src++];
  508. cr |= (((cr1 + cr2 + 1) << 15) & 0xff0000);
  509. cb |= (((cb1 + cb2 + 1) << 15) & 0xff0000);
  510. cr1 = sCr[src];
  511. cb1 = sCb[src++];
  512. cr |= (((cr1 + cr2 + 1) << 23) & 0xff000000);
  513. cb |= (((cb1 + cb2 + 1) << 23) & 0xff000000);
  514. dCr[dest] = cr;
  515. dCb[dest] = cb;
  516. dest++;
  517. }
  518. dest += scan >> 2; src += scan-1;
  519. }
  520. }
  521. }
  522. else {
  523. if (oddV) {
  524. while (dest < last) {
  525. for (x = 0; x < 2; x++) {
  526. cr = (((sCr[src] + sCr[src+width] + 1) >> 1) & 0xff);
  527. cb = (((sCb[src] + sCb[src+width] + 1) >> 1) & 0xff); src++;
  528. cr |= (((sCr[src] + sCr[src+width] + 1) << 7) & 0xff00);
  529. cb |= (((sCb[src] + sCb[src+width] + 1) << 7) & 0xff00); src++;
  530. cr |= (((sCr[src] + sCr[src+width] + 1) << 15) & 0xff0000);
  531. cb |= (((sCb[src] + sCb[src+width] + 1) << 15) & 0xff0000); src++;
  532. cr |= (((sCr[src] + sCr[src+width] + 1) << 23) & 0xff000000);
  533. cb |= (((sCb[src] + sCb[src+width] + 1) << 23) & 0xff000000); src++;
  534. dCr[dest] = cr;
  535. dCb[dest] = cb;
  536. dest++;
  537. }
  538. dest += scan >> 2; src += scan;
  539. }
  540. }
  541. else {
  542. while (dest < last) {
  543. for (x = 0; x < 2; x++) {
  544. cr = sCr[src];
  545. cb = sCb[src]; src++;
  546. cr |= sCr[src] << 8;
  547. cb |= sCb[src] << 8; src++;
  548. cr |= sCr[src] << 16;
  549. cb |= sCb[src] << 16; src++;
  550. cr |= sCr[src] << 24;
  551. cb |= sCb[src] << 24; src++;
  552. dCr[dest] = cr;
  553. dCb[dest] = cb;
  554. dest++;
  555. }
  556. dest += scan >> 2; src += scan;
  557. }
  558. }
  559. }
  560. };
  561. // Block layer
  562. MPEG1.prototype.dcPredictorY = 0;
  563. MPEG1.prototype.dcPredictorCr = 0;
  564. MPEG1.prototype.dcPredictorCb = 0;
  565. MPEG1.prototype.blockData = null;
  566. MPEG1.prototype.decodeBlock = function(block) {
  567. var
  568. n = 0,
  569. quantMatrix;
  570. // Decode DC coefficient of intra-coded blocks
  571. if (this.macroblockIntra) {
  572. var
  573. predictor,
  574. dctSize;
  575. // DC prediction
  576. if (block < 4) {
  577. predictor = this.dcPredictorY;
  578. dctSize = this.readHuffman(MPEG1.DCT_DC_SIZE_LUMINANCE);
  579. }
  580. else {
  581. predictor = (block === 4 ? this.dcPredictorCr : this.dcPredictorCb);
  582. dctSize = this.readHuffman(MPEG1.DCT_DC_SIZE_CHROMINANCE);
  583. }
  584. // Read DC coeff
  585. if (dctSize > 0) {
  586. var differential = this.bits.read(dctSize);
  587. if ((differential & (1 << (dctSize - 1))) !== 0) {
  588. this.blockData[0] = predictor + differential;
  589. }
  590. else {
  591. this.blockData[0] = predictor + ((-1 << dctSize)|(differential+1));
  592. }
  593. }
  594. else {
  595. this.blockData[0] = predictor;
  596. }
  597. // Save predictor value
  598. if (block < 4) {
  599. this.dcPredictorY = this.blockData[0];
  600. }
  601. else if (block === 4) {
  602. this.dcPredictorCr = this.blockData[0];
  603. }
  604. else {
  605. this.dcPredictorCb = this.blockData[0];
  606. }
  607. // Dequantize + premultiply
  608. this.blockData[0] <<= (3 + 5);
  609. quantMatrix = this.intraQuantMatrix;
  610. n = 1;
  611. }
  612. else {
  613. quantMatrix = this.nonIntraQuantMatrix;
  614. }
  615. // Decode AC coefficients (+DC for non-intra)
  616. var level = 0;
  617. while (true) {
  618. var
  619. run = 0,
  620. coeff = this.readHuffman(MPEG1.DCT_COEFF);
  621. if ((coeff === 0x0001) && (n > 0) && (this.bits.read(1) === 0)) {
  622. // end_of_block
  623. break;
  624. }
  625. if (coeff === 0xffff) {
  626. // escape
  627. run = this.bits.read(6);
  628. level = this.bits.read(8);
  629. if (level === 0) {
  630. level = this.bits.read(8);
  631. }
  632. else if (level === 128) {
  633. level = this.bits.read(8) - 256;
  634. }
  635. else if (level > 128) {
  636. level = level - 256;
  637. }
  638. }
  639. else {
  640. run = coeff >> 8;
  641. level = coeff & 0xff;
  642. if (this.bits.read(1)) {
  643. level = -level;
  644. }
  645. }
  646. n += run;
  647. var dezigZagged = MPEG1.ZIG_ZAG[n];
  648. n++;
  649. // Dequantize, oddify, clip
  650. level <<= 1;
  651. if (!this.macroblockIntra) {
  652. level += (level < 0 ? -1 : 1);
  653. }
  654. level = (level * this.quantizerScale * quantMatrix[dezigZagged]) >> 4;
  655. if ((level & 1) === 0) {
  656. level -= level > 0 ? 1 : -1;
  657. }
  658. if (level > 2047) {
  659. level = 2047;
  660. }
  661. else if (level < -2048) {
  662. level = -2048;
  663. }
  664. // Save premultiplied coefficient
  665. this.blockData[dezigZagged] = level * MPEG1.PREMULTIPLIER_MATRIX[dezigZagged];
  666. }
  667. // Move block to its place
  668. var
  669. destArray,
  670. destIndex,
  671. scan;
  672. if (block < 4) {
  673. destArray = this.currentY;
  674. scan = this.codedWidth - 8;
  675. destIndex = (this.mbRow * this.codedWidth + this.mbCol) << 4;
  676. if ((block & 1) !== 0) {
  677. destIndex += 8;
  678. }
  679. if ((block & 2) !== 0) {
  680. destIndex += this.codedWidth << 3;
  681. }
  682. }
  683. else {
  684. destArray = (block === 4) ? this.currentCb : this.currentCr;
  685. scan = (this.codedWidth >> 1) - 8;
  686. destIndex = ((this.mbRow * this.codedWidth) << 2) + (this.mbCol << 3);
  687. }
  688. if (this.macroblockIntra) {
  689. // Overwrite (no prediction)
  690. if (n === 1) {
  691. MPEG1.CopyValueToDestination((this.blockData[0] + 128) >> 8, destArray, destIndex, scan);
  692. this.blockData[0] = 0;
  693. }
  694. else {
  695. MPEG1.IDCT(this.blockData);
  696. MPEG1.CopyBlockToDestination(this.blockData, destArray, destIndex, scan);
  697. JSMpeg.Fill(this.blockData, 0);
  698. }
  699. }
  700. else {
  701. // Add data to the predicted macroblock
  702. if (n === 1) {
  703. MPEG1.AddValueToDestination((this.blockData[0] + 128) >> 8, destArray, destIndex, scan);
  704. this.blockData[0] = 0;
  705. }
  706. else {
  707. MPEG1.IDCT(this.blockData);
  708. MPEG1.AddBlockToDestination(this.blockData, destArray, destIndex, scan);
  709. JSMpeg.Fill(this.blockData, 0);
  710. }
  711. }
  712. n = 0;
  713. };
  714. MPEG1.CopyBlockToDestination = function(block, dest, index, scan) {
  715. for (var n = 0; n < 64; n += 8, index += scan+8) {
  716. dest[index+0] = block[n+0];
  717. dest[index+1] = block[n+1];
  718. dest[index+2] = block[n+2];
  719. dest[index+3] = block[n+3];
  720. dest[index+4] = block[n+4];
  721. dest[index+5] = block[n+5];
  722. dest[index+6] = block[n+6];
  723. dest[index+7] = block[n+7];
  724. }
  725. };
  726. MPEG1.AddBlockToDestination = function(block, dest, index, scan) {
  727. for (var n = 0; n < 64; n += 8, index += scan+8) {
  728. dest[index+0] += block[n+0];
  729. dest[index+1] += block[n+1];
  730. dest[index+2] += block[n+2];
  731. dest[index+3] += block[n+3];
  732. dest[index+4] += block[n+4];
  733. dest[index+5] += block[n+5];
  734. dest[index+6] += block[n+6];
  735. dest[index+7] += block[n+7];
  736. }
  737. };
  738. MPEG1.CopyValueToDestination = function(value, dest, index, scan) {
  739. for (var n = 0; n < 64; n += 8, index += scan+8) {
  740. dest[index+0] = value;
  741. dest[index+1] = value;
  742. dest[index+2] = value;
  743. dest[index+3] = value;
  744. dest[index+4] = value;
  745. dest[index+5] = value;
  746. dest[index+6] = value;
  747. dest[index+7] = value;
  748. }
  749. };
  750. MPEG1.AddValueToDestination = function(value, dest, index, scan) {
  751. for (var n = 0; n < 64; n += 8, index += scan+8) {
  752. dest[index+0] += value;
  753. dest[index+1] += value;
  754. dest[index+2] += value;
  755. dest[index+3] += value;
  756. dest[index+4] += value;
  757. dest[index+5] += value;
  758. dest[index+6] += value;
  759. dest[index+7] += value;
  760. }
  761. };
  762. MPEG1.IDCT = function(block) {
  763. // See http://vsr.informatik.tu-chemnitz.de/~jan/MPEG/HTML/IDCT.html
  764. // for more info.
  765. var
  766. b1, b3, b4, b6, b7, tmp1, tmp2, m0,
  767. x0, x1, x2, x3, x4, y3, y4, y5, y6, y7;
  768. // Transform columns
  769. for (var i = 0; i < 8; ++i) {
  770. b1 = block[4*8+i];
  771. b3 = block[2*8+i] + block[6*8+i];
  772. b4 = block[5*8+i] - block[3*8+i];
  773. tmp1 = block[1*8+i] + block[7*8+i];
  774. tmp2 = block[3*8+i] + block[5*8+i];
  775. b6 = block[1*8+i] - block[7*8+i];
  776. b7 = tmp1 + tmp2;
  777. m0 = block[0*8+i];
  778. x4 = ((b6*473 - b4*196 + 128) >> 8) - b7;
  779. x0 = x4 - (((tmp1 - tmp2)*362 + 128) >> 8);
  780. x1 = m0 - b1;
  781. x2 = (((block[2*8+i] - block[6*8+i])*362 + 128) >> 8) - b3;
  782. x3 = m0 + b1;
  783. y3 = x1 + x2;
  784. y4 = x3 + b3;
  785. y5 = x1 - x2;
  786. y6 = x3 - b3;
  787. y7 = -x0 - ((b4*473 + b6*196 + 128) >> 8);
  788. block[0*8+i] = b7 + y4;
  789. block[1*8+i] = x4 + y3;
  790. block[2*8+i] = y5 - x0;
  791. block[3*8+i] = y6 - y7;
  792. block[4*8+i] = y6 + y7;
  793. block[5*8+i] = x0 + y5;
  794. block[6*8+i] = y3 - x4;
  795. block[7*8+i] = y4 - b7;
  796. }
  797. // Transform rows
  798. for (var i = 0; i < 64; i += 8) {
  799. b1 = block[4+i];
  800. b3 = block[2+i] + block[6+i];
  801. b4 = block[5+i] - block[3+i];
  802. tmp1 = block[1+i] + block[7+i];
  803. tmp2 = block[3+i] + block[5+i];
  804. b6 = block[1+i] - block[7+i];
  805. b7 = tmp1 + tmp2;
  806. m0 = block[0+i];
  807. x4 = ((b6*473 - b4*196 + 128) >> 8) - b7;
  808. x0 = x4 - (((tmp1 - tmp2)*362 + 128) >> 8);
  809. x1 = m0 - b1;
  810. x2 = (((block[2+i] - block[6+i])*362 + 128) >> 8) - b3;
  811. x3 = m0 + b1;
  812. y3 = x1 + x2;
  813. y4 = x3 + b3;
  814. y5 = x1 - x2;
  815. y6 = x3 - b3;
  816. y7 = -x0 - ((b4*473 + b6*196 + 128) >> 8);
  817. block[0+i] = (b7 + y4 + 128) >> 8;
  818. block[1+i] = (x4 + y3 + 128) >> 8;
  819. block[2+i] = (y5 - x0 + 128) >> 8;
  820. block[3+i] = (y6 - y7 + 128) >> 8;
  821. block[4+i] = (y6 + y7 + 128) >> 8;
  822. block[5+i] = (x0 + y5 + 128) >> 8;
  823. block[6+i] = (y3 - x4 + 128) >> 8;
  824. block[7+i] = (y4 - b7 + 128) >> 8;
  825. }
  826. };
  827. // VLC Tables and Constants
  828. MPEG1.PICTURE_RATE = [
  829. 0.000, 23.976, 24.000, 25.000, 29.970, 30.000, 50.000, 59.940,
  830. 60.000, 0.000, 0.000, 0.000, 0.000, 0.000, 0.000, 0.000
  831. ];
  832. MPEG1.ZIG_ZAG = new Uint8Array([
  833. 0, 1, 8, 16, 9, 2, 3, 10,
  834. 17, 24, 32, 25, 18, 11, 4, 5,
  835. 12, 19, 26, 33, 40, 48, 41, 34,
  836. 27, 20, 13, 6, 7, 14, 21, 28,
  837. 35, 42, 49, 56, 57, 50, 43, 36,
  838. 29, 22, 15, 23, 30, 37, 44, 51,
  839. 58, 59, 52, 45, 38, 31, 39, 46,
  840. 53, 60, 61, 54, 47, 55, 62, 63
  841. ]);
  842. MPEG1.DEFAULT_INTRA_QUANT_MATRIX = new Uint8Array([
  843. 8, 16, 19, 22, 26, 27, 29, 34,
  844. 16, 16, 22, 24, 27, 29, 34, 37,
  845. 19, 22, 26, 27, 29, 34, 34, 38,
  846. 22, 22, 26, 27, 29, 34, 37, 40,
  847. 22, 26, 27, 29, 32, 35, 40, 48,
  848. 26, 27, 29, 32, 35, 40, 48, 58,
  849. 26, 27, 29, 34, 38, 46, 56, 69,
  850. 27, 29, 35, 38, 46, 56, 69, 83
  851. ]);
  852. MPEG1.DEFAULT_NON_INTRA_QUANT_MATRIX = new Uint8Array([
  853. 16, 16, 16, 16, 16, 16, 16, 16,
  854. 16, 16, 16, 16, 16, 16, 16, 16,
  855. 16, 16, 16, 16, 16, 16, 16, 16,
  856. 16, 16, 16, 16, 16, 16, 16, 16,
  857. 16, 16, 16, 16, 16, 16, 16, 16,
  858. 16, 16, 16, 16, 16, 16, 16, 16,
  859. 16, 16, 16, 16, 16, 16, 16, 16,
  860. 16, 16, 16, 16, 16, 16, 16, 16
  861. ]);
  862. MPEG1.PREMULTIPLIER_MATRIX = new Uint8Array([
  863. 32, 44, 42, 38, 32, 25, 17, 9,
  864. 44, 62, 58, 52, 44, 35, 24, 12,
  865. 42, 58, 55, 49, 42, 33, 23, 12,
  866. 38, 52, 49, 44, 38, 30, 20, 10,
  867. 32, 44, 42, 38, 32, 25, 17, 9,
  868. 25, 35, 33, 30, 25, 20, 14, 7,
  869. 17, 24, 23, 20, 17, 14, 9, 5,
  870. 9, 12, 12, 10, 9, 7, 5, 2
  871. ]);
  872. // MPEG-1 VLC
  873. // macroblock_stuffing decodes as 34.
  874. // macroblock_escape decodes as 35.
  875. MPEG1.MACROBLOCK_ADDRESS_INCREMENT = new Int16Array([
  876. 1*3, 2*3, 0, // 0
  877. 3*3, 4*3, 0, // 1 0
  878. 0, 0, 1, // 2 1.
  879. 5*3, 6*3, 0, // 3 00
  880. 7*3, 8*3, 0, // 4 01
  881. 9*3, 10*3, 0, // 5 000
  882. 11*3, 12*3, 0, // 6 001
  883. 0, 0, 3, // 7 010.
  884. 0, 0, 2, // 8 011.
  885. 13*3, 14*3, 0, // 9 0000
  886. 15*3, 16*3, 0, // 10 0001
  887. 0, 0, 5, // 11 0010.
  888. 0, 0, 4, // 12 0011.
  889. 17*3, 18*3, 0, // 13 0000 0
  890. 19*3, 20*3, 0, // 14 0000 1
  891. 0, 0, 7, // 15 0001 0.
  892. 0, 0, 6, // 16 0001 1.
  893. 21*3, 22*3, 0, // 17 0000 00
  894. 23*3, 24*3, 0, // 18 0000 01
  895. 25*3, 26*3, 0, // 19 0000 10
  896. 27*3, 28*3, 0, // 20 0000 11
  897. -1, 29*3, 0, // 21 0000 000
  898. -1, 30*3, 0, // 22 0000 001
  899. 31*3, 32*3, 0, // 23 0000 010
  900. 33*3, 34*3, 0, // 24 0000 011
  901. 35*3, 36*3, 0, // 25 0000 100
  902. 37*3, 38*3, 0, // 26 0000 101
  903. 0, 0, 9, // 27 0000 110.
  904. 0, 0, 8, // 28 0000 111.
  905. 39*3, 40*3, 0, // 29 0000 0001
  906. 41*3, 42*3, 0, // 30 0000 0011
  907. 43*3, 44*3, 0, // 31 0000 0100
  908. 45*3, 46*3, 0, // 32 0000 0101
  909. 0, 0, 15, // 33 0000 0110.
  910. 0, 0, 14, // 34 0000 0111.
  911. 0, 0, 13, // 35 0000 1000.
  912. 0, 0, 12, // 36 0000 1001.
  913. 0, 0, 11, // 37 0000 1010.
  914. 0, 0, 10, // 38 0000 1011.
  915. 47*3, -1, 0, // 39 0000 0001 0
  916. -1, 48*3, 0, // 40 0000 0001 1
  917. 49*3, 50*3, 0, // 41 0000 0011 0
  918. 51*3, 52*3, 0, // 42 0000 0011 1
  919. 53*3, 54*3, 0, // 43 0000 0100 0
  920. 55*3, 56*3, 0, // 44 0000 0100 1
  921. 57*3, 58*3, 0, // 45 0000 0101 0
  922. 59*3, 60*3, 0, // 46 0000 0101 1
  923. 61*3, -1, 0, // 47 0000 0001 00
  924. -1, 62*3, 0, // 48 0000 0001 11
  925. 63*3, 64*3, 0, // 49 0000 0011 00
  926. 65*3, 66*3, 0, // 50 0000 0011 01
  927. 67*3, 68*3, 0, // 51 0000 0011 10
  928. 69*3, 70*3, 0, // 52 0000 0011 11
  929. 71*3, 72*3, 0, // 53 0000 0100 00
  930. 73*3, 74*3, 0, // 54 0000 0100 01
  931. 0, 0, 21, // 55 0000 0100 10.
  932. 0, 0, 20, // 56 0000 0100 11.
  933. 0, 0, 19, // 57 0000 0101 00.
  934. 0, 0, 18, // 58 0000 0101 01.
  935. 0, 0, 17, // 59 0000 0101 10.
  936. 0, 0, 16, // 60 0000 0101 11.
  937. 0, 0, 35, // 61 0000 0001 000. -- macroblock_escape
  938. 0, 0, 34, // 62 0000 0001 111. -- macroblock_stuffing
  939. 0, 0, 33, // 63 0000 0011 000.
  940. 0, 0, 32, // 64 0000 0011 001.
  941. 0, 0, 31, // 65 0000 0011 010.
  942. 0, 0, 30, // 66 0000 0011 011.
  943. 0, 0, 29, // 67 0000 0011 100.
  944. 0, 0, 28, // 68 0000 0011 101.
  945. 0, 0, 27, // 69 0000 0011 110.
  946. 0, 0, 26, // 70 0000 0011 111.
  947. 0, 0, 25, // 71 0000 0100 000.
  948. 0, 0, 24, // 72 0000 0100 001.
  949. 0, 0, 23, // 73 0000 0100 010.
  950. 0, 0, 22 // 74 0000 0100 011.
  951. ]);
  952. // macroblock_type bitmap:
  953. // 0x10 macroblock_quant
  954. // 0x08 macroblock_motion_forward
  955. // 0x04 macroblock_motion_backward
  956. // 0x02 macrobkock_pattern
  957. // 0x01 macroblock_intra
  958. //
  959. MPEG1.MACROBLOCK_TYPE_INTRA = new Int8Array([
  960. 1*3, 2*3, 0, // 0
  961. -1, 3*3, 0, // 1 0
  962. 0, 0, 0x01, // 2 1.
  963. 0, 0, 0x11 // 3 01.
  964. ]);
  965. MPEG1.MACROBLOCK_TYPE_PREDICTIVE = new Int8Array([
  966. 1*3, 2*3, 0, // 0
  967. 3*3, 4*3, 0, // 1 0
  968. 0, 0, 0x0a, // 2 1.
  969. 5*3, 6*3, 0, // 3 00
  970. 0, 0, 0x02, // 4 01.
  971. 7*3, 8*3, 0, // 5 000
  972. 0, 0, 0x08, // 6 001.
  973. 9*3, 10*3, 0, // 7 0000
  974. 11*3, 12*3, 0, // 8 0001
  975. -1, 13*3, 0, // 9 00000
  976. 0, 0, 0x12, // 10 00001.
  977. 0, 0, 0x1a, // 11 00010.
  978. 0, 0, 0x01, // 12 00011.
  979. 0, 0, 0x11 // 13 000001.
  980. ]);
  981. MPEG1.MACROBLOCK_TYPE_B = new Int8Array([
  982. 1*3, 2*3, 0, // 0
  983. 3*3, 5*3, 0, // 1 0
  984. 4*3, 6*3, 0, // 2 1
  985. 8*3, 7*3, 0, // 3 00
  986. 0, 0, 0x0c, // 4 10.
  987. 9*3, 10*3, 0, // 5 01
  988. 0, 0, 0x0e, // 6 11.
  989. 13*3, 14*3, 0, // 7 001
  990. 12*3, 11*3, 0, // 8 000
  991. 0, 0, 0x04, // 9 010.
  992. 0, 0, 0x06, // 10 011.
  993. 18*3, 16*3, 0, // 11 0001
  994. 15*3, 17*3, 0, // 12 0000
  995. 0, 0, 0x08, // 13 0010.
  996. 0, 0, 0x0a, // 14 0011.
  997. -1, 19*3, 0, // 15 00000
  998. 0, 0, 0x01, // 16 00011.
  999. 20*3, 21*3, 0, // 17 00001
  1000. 0, 0, 0x1e, // 18 00010.
  1001. 0, 0, 0x11, // 19 000001.
  1002. 0, 0, 0x16, // 20 000010.
  1003. 0, 0, 0x1a // 21 000011.
  1004. ]);
  1005. MPEG1.MACROBLOCK_TYPE = [
  1006. null,
  1007. MPEG1.MACROBLOCK_TYPE_INTRA,
  1008. MPEG1.MACROBLOCK_TYPE_PREDICTIVE,
  1009. MPEG1.MACROBLOCK_TYPE_B
  1010. ];
  1011. MPEG1.CODE_BLOCK_PATTERN = new Int16Array([
  1012. 2*3, 1*3, 0, // 0
  1013. 3*3, 6*3, 0, // 1 1
  1014. 4*3, 5*3, 0, // 2 0
  1015. 8*3, 11*3, 0, // 3 10
  1016. 12*3, 13*3, 0, // 4 00
  1017. 9*3, 7*3, 0, // 5 01
  1018. 10*3, 14*3, 0, // 6 11
  1019. 20*3, 19*3, 0, // 7 011
  1020. 18*3, 16*3, 0, // 8 100
  1021. 23*3, 17*3, 0, // 9 010
  1022. 27*3, 25*3, 0, // 10 110
  1023. 21*3, 28*3, 0, // 11 101
  1024. 15*3, 22*3, 0, // 12 000
  1025. 24*3, 26*3, 0, // 13 001
  1026. 0, 0, 60, // 14 111.
  1027. 35*3, 40*3, 0, // 15 0000
  1028. 44*3, 48*3, 0, // 16 1001
  1029. 38*3, 36*3, 0, // 17 0101
  1030. 42*3, 47*3, 0, // 18 1000
  1031. 29*3, 31*3, 0, // 19 0111
  1032. 39*3, 32*3, 0, // 20 0110
  1033. 0, 0, 32, // 21 1010.
  1034. 45*3, 46*3, 0, // 22 0001
  1035. 33*3, 41*3, 0, // 23 0100
  1036. 43*3, 34*3, 0, // 24 0010
  1037. 0, 0, 4, // 25 1101.
  1038. 30*3, 37*3, 0, // 26 0011
  1039. 0, 0, 8, // 27 1100.
  1040. 0, 0, 16, // 28 1011.
  1041. 0, 0, 44, // 29 0111 0.
  1042. 50*3, 56*3, 0, // 30 0011 0
  1043. 0, 0, 28, // 31 0111 1.
  1044. 0, 0, 52, // 32 0110 1.
  1045. 0, 0, 62, // 33 0100 0.
  1046. 61*3, 59*3, 0, // 34 0010 1
  1047. 52*3, 60*3, 0, // 35 0000 0
  1048. 0, 0, 1, // 36 0101 1.
  1049. 55*3, 54*3, 0, // 37 0011 1
  1050. 0, 0, 61, // 38 0101 0.
  1051. 0, 0, 56, // 39 0110 0.
  1052. 57*3, 58*3, 0, // 40 0000 1
  1053. 0, 0, 2, // 41 0100 1.
  1054. 0, 0, 40, // 42 1000 0.
  1055. 51*3, 62*3, 0, // 43 0010 0
  1056. 0, 0, 48, // 44 1001 0.
  1057. 64*3, 63*3, 0, // 45 0001 0
  1058. 49*3, 53*3, 0, // 46 0001 1
  1059. 0, 0, 20, // 47 1000 1.
  1060. 0, 0, 12, // 48 1001 1.
  1061. 80*3, 83*3, 0, // 49 0001 10
  1062. 0, 0, 63, // 50 0011 00.
  1063. 77*3, 75*3, 0, // 51 0010 00
  1064. 65*3, 73*3, 0, // 52 0000 00
  1065. 84*3, 66*3, 0, // 53 0001 11
  1066. 0, 0, 24, // 54 0011 11.
  1067. 0, 0, 36, // 55 0011 10.
  1068. 0, 0, 3, // 56 0011 01.
  1069. 69*3, 87*3, 0, // 57 0000 10
  1070. 81*3, 79*3, 0, // 58 0000 11
  1071. 68*3, 71*3, 0, // 59 0010 11
  1072. 70*3, 78*3, 0, // 60 0000 01
  1073. 67*3, 76*3, 0, // 61 0010 10
  1074. 72*3, 74*3, 0, // 62 0010 01
  1075. 86*3, 85*3, 0, // 63 0001 01
  1076. 88*3, 82*3, 0, // 64 0001 00
  1077. -1, 94*3, 0, // 65 0000 000
  1078. 95*3, 97*3, 0, // 66 0001 111
  1079. 0, 0, 33, // 67 0010 100.
  1080. 0, 0, 9, // 68 0010 110.
  1081. 106*3, 110*3, 0, // 69 0000 100
  1082. 102*3, 116*3, 0, // 70 0000 010
  1083. 0, 0, 5, // 71 0010 111.
  1084. 0, 0, 10, // 72 0010 010.
  1085. 93*3, 89*3, 0, // 73 0000 001
  1086. 0, 0, 6, // 74 0010 011.
  1087. 0, 0, 18, // 75 0010 001.
  1088. 0, 0, 17, // 76 0010 101.
  1089. 0, 0, 34, // 77 0010 000.
  1090. 113*3, 119*3, 0, // 78 0000 011
  1091. 103*3, 104*3, 0, // 79 0000 111
  1092. 90*3, 92*3, 0, // 80 0001 100
  1093. 109*3, 107*3, 0, // 81 0000 110
  1094. 117*3, 118*3, 0, // 82 0001 001
  1095. 101*3, 99*3, 0, // 83 0001 101
  1096. 98*3, 96*3, 0, // 84 0001 110
  1097. 100*3, 91*3, 0, // 85 0001 011
  1098. 114*3, 115*3, 0, // 86 0001 010
  1099. 105*3, 108*3, 0, // 87 0000 101
  1100. 112*3, 111*3, 0, // 88 0001 000
  1101. 121*3, 125*3, 0, // 89 0000 0011
  1102. 0, 0, 41, // 90 0001 1000.
  1103. 0, 0, 14, // 91 0001 0111.
  1104. 0, 0, 21, // 92 0001 1001.
  1105. 124*3, 122*3, 0, // 93 0000 0010
  1106. 120*3, 123*3, 0, // 94 0000 0001
  1107. 0, 0, 11, // 95 0001 1110.
  1108. 0, 0, 19, // 96 0001 1101.
  1109. 0, 0, 7, // 97 0001 1111.
  1110. 0, 0, 35, // 98 0001 1100.
  1111. 0, 0, 13, // 99 0001 1011.
  1112. 0, 0, 50, // 100 0001 0110.
  1113. 0, 0, 49, // 101 0001 1010.
  1114. 0, 0, 58, // 102 0000 0100.
  1115. 0, 0, 37, // 103 0000 1110.
  1116. 0, 0, 25, // 104 0000 1111.
  1117. 0, 0, 45, // 105 0000 1010.
  1118. 0, 0, 57, // 106 0000 1000.
  1119. 0, 0, 26, // 107 0000 1101.
  1120. 0, 0, 29, // 108 0000 1011.
  1121. 0, 0, 38, // 109 0000 1100.
  1122. 0, 0, 53, // 110 0000 1001.
  1123. 0, 0, 23, // 111 0001 0001.
  1124. 0, 0, 43, // 112 0001 0000.
  1125. 0, 0, 46, // 113 0000 0110.
  1126. 0, 0, 42, // 114 0001 0100.
  1127. 0, 0, 22, // 115 0001 0101.
  1128. 0, 0, 54, // 116 0000 0101.
  1129. 0, 0, 51, // 117 0001 0010.
  1130. 0, 0, 15, // 118 0001 0011.
  1131. 0, 0, 30, // 119 0000 0111.
  1132. 0, 0, 39, // 120 0000 0001 0.
  1133. 0, 0, 47, // 121 0000 0011 0.
  1134. 0, 0, 55, // 122 0000 0010 1.
  1135. 0, 0, 27, // 123 0000 0001 1.
  1136. 0, 0, 59, // 124 0000 0010 0.
  1137. 0, 0, 31 // 125 0000 0011 1.
  1138. ]);
  1139. MPEG1.MOTION = new Int16Array([
  1140. 1*3, 2*3, 0, // 0
  1141. 4*3, 3*3, 0, // 1 0
  1142. 0, 0, 0, // 2 1.
  1143. 6*3, 5*3, 0, // 3 01
  1144. 8*3, 7*3, 0, // 4 00
  1145. 0, 0, -1, // 5 011.
  1146. 0, 0, 1, // 6 010.
  1147. 9*3, 10*3, 0, // 7 001
  1148. 12*3, 11*3, 0, // 8 000
  1149. 0, 0, 2, // 9 0010.
  1150. 0, 0, -2, // 10 0011.
  1151. 14*3, 15*3, 0, // 11 0001
  1152. 16*3, 13*3, 0, // 12 0000
  1153. 20*3, 18*3, 0, // 13 0000 1
  1154. 0, 0, 3, // 14 0001 0.
  1155. 0, 0, -3, // 15 0001 1.
  1156. 17*3, 19*3, 0, // 16 0000 0
  1157. -1, 23*3, 0, // 17 0000 00
  1158. 27*3, 25*3, 0, // 18 0000 11
  1159. 26*3, 21*3, 0, // 19 0000 01
  1160. 24*3, 22*3, 0, // 20 0000 10
  1161. 32*3, 28*3, 0, // 21 0000 011
  1162. 29*3, 31*3, 0, // 22 0000 101
  1163. -1, 33*3, 0, // 23 0000 001
  1164. 36*3, 35*3, 0, // 24 0000 100
  1165. 0, 0, -4, // 25 0000 111.
  1166. 30*3, 34*3, 0, // 26 0000 010
  1167. 0, 0, 4, // 27 0000 110.
  1168. 0, 0, -7, // 28 0000 0111.
  1169. 0, 0, 5, // 29 0000 1010.
  1170. 37*3, 41*3, 0, // 30 0000 0100
  1171. 0, 0, -5, // 31 0000 1011.
  1172. 0, 0, 7, // 32 0000 0110.
  1173. 38*3, 40*3, 0, // 33 0000 0011
  1174. 42*3, 39*3, 0, // 34 0000 0101
  1175. 0, 0, -6, // 35 0000 1001.
  1176. 0, 0, 6, // 36 0000 1000.
  1177. 51*3, 54*3, 0, // 37 0000 0100 0
  1178. 50*3, 49*3, 0, // 38 0000 0011 0
  1179. 45*3, 46*3, 0, // 39 0000 0101 1
  1180. 52*3, 47*3, 0, // 40 0000 0011 1
  1181. 43*3, 53*3, 0, // 41 0000 0100 1
  1182. 44*3, 48*3, 0, // 42 0000 0101 0
  1183. 0, 0, 10, // 43 0000 0100 10.
  1184. 0, 0, 9, // 44 0000 0101 00.
  1185. 0, 0, 8, // 45 0000 0101 10.
  1186. 0, 0, -8, // 46 0000 0101 11.
  1187. 57*3, 66*3, 0, // 47 0000 0011 11
  1188. 0, 0, -9, // 48 0000 0101 01.
  1189. 60*3, 64*3, 0, // 49 0000 0011 01
  1190. 56*3, 61*3, 0, // 50 0000 0011 00
  1191. 55*3, 62*3, 0, // 51 0000 0100 00
  1192. 58*3, 63*3, 0, // 52 0000 0011 10
  1193. 0, 0, -10, // 53 0000 0100 11.
  1194. 59*3, 65*3, 0, // 54 0000 0100 01
  1195. 0, 0, 12, // 55 0000 0100 000.
  1196. 0, 0, 16, // 56 0000 0011 000.
  1197. 0, 0, 13, // 57 0000 0011 110.
  1198. 0, 0, 14, // 58 0000 0011 100.
  1199. 0, 0, 11, // 59 0000 0100 010.
  1200. 0, 0, 15, // 60 0000 0011 010.
  1201. 0, 0, -16, // 61 0000 0011 001.
  1202. 0, 0, -12, // 62 0000 0100 001.
  1203. 0, 0, -14, // 63 0000 0011 101.
  1204. 0, 0, -15, // 64 0000 0011 011.
  1205. 0, 0, -11, // 65 0000 0100 011.
  1206. 0, 0, -13 // 66 0000 0011 111.
  1207. ]);
  1208. MPEG1.DCT_DC_SIZE_LUMINANCE = new Int8Array([
  1209. 2*3, 1*3, 0, // 0
  1210. 6*3, 5*3, 0, // 1 1
  1211. 3*3, 4*3, 0, // 2 0
  1212. 0, 0, 1, // 3 00.
  1213. 0, 0, 2, // 4 01.
  1214. 9*3, 8*3, 0, // 5 11
  1215. 7*3, 10*3, 0, // 6 10
  1216. 0, 0, 0, // 7 100.
  1217. 12*3, 11*3, 0, // 8 111
  1218. 0, 0, 4, // 9 110.
  1219. 0, 0, 3, // 10 101.
  1220. 13*3, 14*3, 0, // 11 1111
  1221. 0, 0, 5, // 12 1110.
  1222. 0, 0, 6, // 13 1111 0.
  1223. 16*3, 15*3, 0, // 14 1111 1
  1224. 17*3, -1, 0, // 15 1111 11
  1225. 0, 0, 7, // 16 1111 10.
  1226. 0, 0, 8 // 17 1111 110.
  1227. ]);
  1228. MPEG1.DCT_DC_SIZE_CHROMINANCE = new Int8Array([
  1229. 2*3, 1*3, 0, // 0
  1230. 4*3, 3*3, 0, // 1 1
  1231. 6*3, 5*3, 0, // 2 0
  1232. 8*3, 7*3, 0, // 3 11
  1233. 0, 0, 2, // 4 10.
  1234. 0, 0, 1, // 5 01.
  1235. 0, 0, 0, // 6 00.
  1236. 10*3, 9*3, 0, // 7 111
  1237. 0, 0, 3, // 8 110.
  1238. 12*3, 11*3, 0, // 9 1111
  1239. 0, 0, 4, // 10 1110.
  1240. 14*3, 13*3, 0, // 11 1111 1
  1241. 0, 0, 5, // 12 1111 0.
  1242. 16*3, 15*3, 0, // 13 1111 11
  1243. 0, 0, 6, // 14 1111 10.
  1244. 17*3, -1, 0, // 15 1111 111
  1245. 0, 0, 7, // 16 1111 110.
  1246. 0, 0, 8 // 17 1111 1110.
  1247. ]);
  1248. // dct_coeff bitmap:
  1249. // 0xff00 run
  1250. // 0x00ff level
  1251. // Decoded values are unsigned. Sign bit follows in the stream.
  1252. // Interpretation of the value 0x0001
  1253. // for dc_coeff_first: run=0, level=1
  1254. // for dc_coeff_next: If the next bit is 1: run=0, level=1
  1255. // If the next bit is 0: end_of_block
  1256. // escape decodes as 0xffff.
  1257. MPEG1.DCT_COEFF = new Int32Array([
  1258. 1*3, 2*3, 0, // 0
  1259. 4*3, 3*3, 0, // 1 0
  1260. 0, 0, 0x0001, // 2 1.
  1261. 7*3, 8*3, 0, // 3 01
  1262. 6*3, 5*3, 0, // 4 00
  1263. 13*3, 9*3, 0, // 5 001
  1264. 11*3, 10*3, 0, // 6 000
  1265. 14*3, 12*3, 0, // 7 010
  1266. 0, 0, 0x0101, // 8 011.
  1267. 20*3, 22*3, 0, // 9 0011
  1268. 18*3, 21*3, 0, // 10 0001
  1269. 16*3, 19*3, 0, // 11 0000
  1270. 0, 0, 0x0201, // 12 0101.
  1271. 17*3, 15*3, 0, // 13 0010
  1272. 0, 0, 0x0002, // 14 0100.
  1273. 0, 0, 0x0003, // 15 0010 1.
  1274. 27*3, 25*3, 0, // 16 0000 0
  1275. 29*3, 31*3, 0, // 17 0010 0
  1276. 24*3, 26*3, 0, // 18 0001 0
  1277. 32*3, 30*3, 0, // 19 0000 1
  1278. 0, 0, 0x0401, // 20 0011 0.
  1279. 23*3, 28*3, 0, // 21 0001 1
  1280. 0, 0, 0x0301, // 22 0011 1.
  1281. 0, 0, 0x0102, // 23 0001 10.
  1282. 0, 0, 0x0701, // 24 0001 00.
  1283. 0, 0, 0xffff, // 25 0000 01. -- escape
  1284. 0, 0, 0x0601, // 26 0001 01.
  1285. 37*3, 36*3, 0, // 27 0000 00
  1286. 0, 0, 0x0501, // 28 0001 11.
  1287. 35*3, 34*3, 0, // 29 0010 00
  1288. 39*3, 38*3, 0, // 30 0000 11
  1289. 33*3, 42*3, 0, // 31 0010 01
  1290. 40*3, 41*3, 0, // 32 0000 10
  1291. 52*3, 50*3, 0, // 33 0010 010
  1292. 54*3, 53*3, 0, // 34 0010 001
  1293. 48*3, 49*3, 0, // 35 0010 000
  1294. 43*3, 45*3, 0, // 36 0000 001
  1295. 46*3, 44*3, 0, // 37 0000 000
  1296. 0, 0, 0x0801, // 38 0000 111.
  1297. 0, 0, 0x0004, // 39 0000 110.
  1298. 0, 0, 0x0202, // 40 0000 100.
  1299. 0, 0, 0x0901, // 41 0000 101.
  1300. 51*3, 47*3, 0, // 42 0010 011
  1301. 55*3, 57*3, 0, // 43 0000 0010
  1302. 60*3, 56*3, 0, // 44 0000 0001
  1303. 59*3, 58*3, 0, // 45 0000 0011
  1304. 61*3, 62*3, 0, // 46 0000 0000
  1305. 0, 0, 0x0a01, // 47 0010 0111.
  1306. 0, 0, 0x0d01, // 48 0010 0000.
  1307. 0, 0, 0x0006, // 49 0010 0001.
  1308. 0, 0, 0x0103, // 50 0010 0101.
  1309. 0, 0, 0x0005, // 51 0010 0110.
  1310. 0, 0, 0x0302, // 52 0010 0100.
  1311. 0, 0, 0x0b01, // 53 0010 0011.
  1312. 0, 0, 0x0c01, // 54 0010 0010.
  1313. 76*3, 75*3, 0, // 55 0000 0010 0
  1314. 67*3, 70*3, 0, // 56 0000 0001 1
  1315. 73*3, 71*3, 0, // 57 0000 0010 1
  1316. 78*3, 74*3, 0, // 58 0000 0011 1
  1317. 72*3, 77*3, 0, // 59 0000 0011 0
  1318. 69*3, 64*3, 0, // 60 0000 0001 0
  1319. 68*3, 63*3, 0, // 61 0000 0000 0
  1320. 66*3, 65*3, 0, // 62 0000 0000 1
  1321. 81*3, 87*3, 0, // 63 0000 0000 01
  1322. 91*3, 80*3, 0, // 64 0000 0001 01
  1323. 82*3, 79*3, 0, // 65 0000 0000 11
  1324. 83*3, 86*3, 0, // 66 0000 0000 10
  1325. 93*3, 92*3, 0, // 67 0000 0001 10
  1326. 84*3, 85*3, 0, // 68 0000 0000 00
  1327. 90*3, 94*3, 0, // 69 0000 0001 00
  1328. 88*3, 89*3, 0, // 70 0000 0001 11
  1329. 0, 0, 0x0203, // 71 0000 0010 11.
  1330. 0, 0, 0x0104, // 72 0000 0011 00.
  1331. 0, 0, 0x0007, // 73 0000 0010 10.
  1332. 0, 0, 0x0402, // 74 0000 0011 11.
  1333. 0, 0, 0x0502, // 75 0000 0010 01.
  1334. 0, 0, 0x1001, // 76 0000 0010 00.
  1335. 0, 0, 0x0f01, // 77 0000 0011 01.
  1336. 0, 0, 0x0e01, // 78 0000 0011 10.
  1337. 105*3, 107*3, 0, // 79 0000 0000 111
  1338. 111*3, 114*3, 0, // 80 0000 0001 011
  1339. 104*3, 97*3, 0, // 81 0000 0000 010
  1340. 125*3, 119*3, 0, // 82 0000 0000 110
  1341. 96*3, 98*3, 0, // 83 0000 0000 100
  1342. -1, 123*3, 0, // 84 0000 0000 000
  1343. 95*3, 101*3, 0, // 85 0000 0000 001
  1344. 106*3, 121*3, 0, // 86 0000 0000 101
  1345. 99*3, 102*3, 0, // 87 0000 0000 011
  1346. 113*3, 103*3, 0, // 88 0000 0001 110
  1347. 112*3, 116*3, 0, // 89 0000 0001 111
  1348. 110*3, 100*3, 0, // 90 0000 0001 000
  1349. 124*3, 115*3, 0, // 91 0000 0001 010
  1350. 117*3, 122*3, 0, // 92 0000 0001 101
  1351. 109*3, 118*3, 0, // 93 0000 0001 100
  1352. 120*3, 108*3, 0, // 94 0000 0001 001
  1353. 127*3, 136*3, 0, // 95 0000 0000 0010
  1354. 139*3, 140*3, 0, // 96 0000 0000 1000
  1355. 130*3, 126*3, 0, // 97 0000 0000 0101
  1356. 145*3, 146*3, 0, // 98 0000 0000 1001
  1357. 128*3, 129*3, 0, // 99 0000 0000 0110
  1358. 0, 0, 0x0802, // 100 0000 0001 0001.
  1359. 132*3, 134*3, 0, // 101 0000 0000 0011
  1360. 155*3, 154*3, 0, // 102 0000 0000 0111
  1361. 0, 0, 0x0008, // 103 0000 0001 1101.
  1362. 137*3, 133*3, 0, // 104 0000 0000 0100
  1363. 143*3, 144*3, 0, // 105 0000 0000 1110
  1364. 151*3, 138*3, 0, // 106 0000 0000 1010
  1365. 142*3, 141*3, 0, // 107 0000 0000 1111
  1366. 0, 0, 0x000a, // 108 0000 0001 0011.
  1367. 0, 0, 0x0009, // 109 0000 0001 1000.
  1368. 0, 0, 0x000b, // 110 0000 0001 0000.
  1369. 0, 0, 0x1501, // 111 0000 0001 0110.
  1370. 0, 0, 0x0602, // 112 0000 0001 1110.
  1371. 0, 0, 0x0303, // 113 0000 0001 1100.
  1372. 0, 0, 0x1401, // 114 0000 0001 0111.
  1373. 0, 0, 0x0702, // 115 0000 0001 0101.
  1374. 0, 0, 0x1101, // 116 0000 0001 1111.
  1375. 0, 0, 0x1201, // 117 0000 0001 1010.
  1376. 0, 0, 0x1301, // 118 0000 0001 1001.
  1377. 148*3, 152*3, 0, // 119 0000 0000 1101
  1378. 0, 0, 0x0403, // 120 0000 0001 0010.
  1379. 153*3, 150*3, 0, // 121 0000 0000 1011
  1380. 0, 0, 0x0105, // 122 0000 0001 1011.
  1381. 131*3, 135*3, 0, // 123 0000 0000 0001
  1382. 0, 0, 0x0204, // 124 0000 0001 0100.
  1383. 149*3, 147*3, 0, // 125 0000 0000 1100
  1384. 172*3, 173*3, 0, // 126 0000 0000 0101 1
  1385. 162*3, 158*3, 0, // 127 0000 0000 0010 0
  1386. 170*3, 161*3, 0, // 128 0000 0000 0110 0
  1387. 168*3, 166*3, 0, // 129 0000 0000 0110 1
  1388. 157*3, 179*3, 0, // 130 0000 0000 0101 0
  1389. 169*3, 167*3, 0, // 131 0000 0000 0001 0
  1390. 174*3, 171*3, 0, // 132 0000 0000 0011 0
  1391. 178*3, 177*3, 0, // 133 0000 0000 0100 1
  1392. 156*3, 159*3, 0, // 134 0000 0000 0011 1
  1393. 164*3, 165*3, 0, // 135 0000 0000 0001 1
  1394. 183*3, 182*3, 0, // 136 0000 0000 0010 1
  1395. 175*3, 176*3, 0, // 137 0000 0000 0100 0
  1396. 0, 0, 0x0107, // 138 0000 0000 1010 1.
  1397. 0, 0, 0x0a02, // 139 0000 0000 1000 0.
  1398. 0, 0, 0x0902, // 140 0000 0000 1000 1.
  1399. 0, 0, 0x1601, // 141 0000 0000 1111 1.
  1400. 0, 0, 0x1701, // 142 0000 0000 1111 0.
  1401. 0, 0, 0x1901, // 143 0000 0000 1110 0.
  1402. 0, 0, 0x1801, // 144 0000 0000 1110 1.
  1403. 0, 0, 0x0503, // 145 0000 0000 1001 0.
  1404. 0, 0, 0x0304, // 146 0000 0000 1001 1.
  1405. 0, 0, 0x000d, // 147 0000 0000 1100 1.
  1406. 0, 0, 0x000c, // 148 0000 0000 1101 0.
  1407. 0, 0, 0x000e, // 149 0000 0000 1100 0.
  1408. 0, 0, 0x000f, // 150 0000 0000 1011 1.
  1409. 0, 0, 0x0205, // 151 0000 0000 1010 0.
  1410. 0, 0, 0x1a01, // 152 0000 0000 1101 1.
  1411. 0, 0, 0x0106, // 153 0000 0000 1011 0.
  1412. 180*3, 181*3, 0, // 154 0000 0000 0111 1
  1413. 160*3, 163*3, 0, // 155 0000 0000 0111 0
  1414. 196*3, 199*3, 0, // 156 0000 0000 0011 10
  1415. 0, 0, 0x001b, // 157 0000 0000 0101 00.
  1416. 203*3, 185*3, 0, // 158 0000 0000 0010 01
  1417. 202*3, 201*3, 0, // 159 0000 0000 0011 11
  1418. 0, 0, 0x0013, // 160 0000 0000 0111 00.
  1419. 0, 0, 0x0016, // 161 0000 0000 0110 01.
  1420. 197*3, 207*3, 0, // 162 0000 0000 0010 00
  1421. 0, 0, 0x0012, // 163 0000 0000 0111 01.
  1422. 191*3, 192*3, 0, // 164 0000 0000 0001 10
  1423. 188*3, 190*3, 0, // 165 0000 0000 0001 11
  1424. 0, 0, 0x0014, // 166 0000 0000 0110 11.
  1425. 184*3, 194*3, 0, // 167 0000 0000 0001 01
  1426. 0, 0, 0x0015, // 168 0000 0000 0110 10.
  1427. 186*3, 193*3, 0, // 169 0000 0000 0001 00
  1428. 0, 0, 0x0017, // 170 0000 0000 0110 00.
  1429. 204*3, 198*3, 0, // 171 0000 0000 0011 01
  1430. 0, 0, 0x0019, // 172 0000 0000 0101 10.
  1431. 0, 0, 0x0018, // 173 0000 0000 0101 11.
  1432. 200*3, 205*3, 0, // 174 0000 0000 0011 00
  1433. 0, 0, 0x001f, // 175 0000 0000 0100 00.
  1434. 0, 0, 0x001e, // 176 0000 0000 0100 01.
  1435. 0, 0, 0x001c, // 177 0000 0000 0100 11.
  1436. 0, 0, 0x001d, // 178 0000 0000 0100 10.
  1437. 0, 0, 0x001a, // 179 0000 0000 0101 01.
  1438. 0, 0, 0x0011, // 180 0000 0000 0111 10.
  1439. 0, 0, 0x0010, // 181 0000 0000 0111 11.
  1440. 189*3, 206*3, 0, // 182 0000 0000 0010 11
  1441. 187*3, 195*3, 0, // 183 0000 0000 0010 10
  1442. 218*3, 211*3, 0, // 184 0000 0000 0001 010
  1443. 0, 0, 0x0025, // 185 0000 0000 0010 011.
  1444. 215*3, 216*3, 0, // 186 0000 0000 0001 000
  1445. 0, 0, 0x0024, // 187 0000 0000 0010 100.
  1446. 210*3, 212*3, 0, // 188 0000 0000 0001 110
  1447. 0, 0, 0x0022, // 189 0000 0000 0010 110.
  1448. 213*3, 209*3, 0, // 190 0000 0000 0001 111
  1449. 221*3, 222*3, 0, // 191 0000 0000 0001 100
  1450. 219*3, 208*3, 0, // 192 0000 0000 0001 101
  1451. 217*3, 214*3, 0, // 193 0000 0000 0001 001
  1452. 223*3, 220*3, 0, // 194 0000 0000 0001 011
  1453. 0, 0, 0x0023, // 195 0000 0000 0010 101.
  1454. 0, 0, 0x010b, // 196 0000 0000 0011 100.
  1455. 0, 0, 0x0028, // 197 0000 0000 0010 000.
  1456. 0, 0, 0x010c, // 198 0000 0000 0011 011.
  1457. 0, 0, 0x010a, // 199 0000 0000 0011 101.
  1458. 0, 0, 0x0020, // 200 0000 0000 0011 000.
  1459. 0, 0, 0x0108, // 201 0000 0000 0011 111.
  1460. 0, 0, 0x0109, // 202 0000 0000 0011 110.
  1461. 0, 0, 0x0026, // 203 0000 0000 0010 010.
  1462. 0, 0, 0x010d, // 204 0000 0000 0011 010.
  1463. 0, 0, 0x010e, // 205 0000 0000 0011 001.
  1464. 0, 0, 0x0021, // 206 0000 0000 0010 111.
  1465. 0, 0, 0x0027, // 207 0000 0000 0010 001.
  1466. 0, 0, 0x1f01, // 208 0000 0000 0001 1011.
  1467. 0, 0, 0x1b01, // 209 0000 0000 0001 1111.
  1468. 0, 0, 0x1e01, // 210 0000 0000 0001 1100.
  1469. 0, 0, 0x1002, // 211 0000 0000 0001 0101.
  1470. 0, 0, 0x1d01, // 212 0000 0000 0001 1101.
  1471. 0, 0, 0x1c01, // 213 0000 0000 0001 1110.
  1472. 0, 0, 0x010f, // 214 0000 0000 0001 0011.
  1473. 0, 0, 0x0112, // 215 0000 0000 0001 0000.
  1474. 0, 0, 0x0111, // 216 0000 0000 0001 0001.
  1475. 0, 0, 0x0110, // 217 0000 0000 0001 0010.
  1476. 0, 0, 0x0603, // 218 0000 0000 0001 0100.
  1477. 0, 0, 0x0b02, // 219 0000 0000 0001 1010.
  1478. 0, 0, 0x0e02, // 220 0000 0000 0001 0111.
  1479. 0, 0, 0x0d02, // 221 0000 0000 0001 1000.
  1480. 0, 0, 0x0c02, // 222 0000 0000 0001 1001.
  1481. 0, 0, 0x0f02 // 223 0000 0000 0001 0110.
  1482. ]);
  1483. MPEG1.PICTURE_TYPE = {
  1484. INTRA: 1,
  1485. PREDICTIVE: 2,
  1486. B: 3
  1487. };
  1488. MPEG1.START = {
  1489. SEQUENCE: 0xB3,
  1490. SLICE_FIRST: 0x01,
  1491. SLICE_LAST: 0xAF,
  1492. PICTURE: 0x00,
  1493. EXTENSION: 0xB5,
  1494. USER_DATA: 0xB2
  1495. };
  1496. return MPEG1;
  1497. })();