MP4_VLD.C
上传用户:tuheem
上传日期:2007-05-01
资源大小:21889k
文件大小:7k
- #include <stdio.h>
- #include "mp4_vars.h"
- #include "getbits.h"
- #include "mp4_vld.h"
- /**
- *
- **/
- /***/
- event_t vld_intra_dct()
- {
- event_t event;
- tab_type *tab = (tab_type *) NULL;
- int lmax, rmax;
- tab = vldTableB16(showbits(12));
- if (!tab) {
- event.run =
- event.level =
- event.last = -1;
- return event;
- }
- if (tab->val != ESCAPE) {
- event.run = (tab->val >> 6) & 63;
- event.level = tab->val & 63;
- event.last = (tab->val >> 12) & 1;
- event.level = getbits(1) ? -event.level : event.level;
- } else {
- switch (showbits(2)) {
- case 0x0 :
- case 0x1 :
- flushbits(1);
- tab = vldTableB16(showbits(12));
- if (!tab) {
- event.run =
- event.level =
- event.last = -1;
- return event;
- }
- event.run = (tab->val >> 6) & 63;
- event.level = tab->val & 63;
- event.last = (tab->val >> 12) & 1;
- lmax = vldTableB19(event.last, event.run);
- event.level += lmax;
- event.level = getbits(1) ? -event.level : event.level;
- break;
- case 0x2 :
- flushbits(2);
- tab = vldTableB16(showbits(12));
- if (!tab) {
- event.run =
- event.level =
- event.last = -1;
- break;
- }
- event.run = (tab->val >> 6) & 63;
- event.level = tab->val & 63;
- event.last = (tab->val >> 12) & 1;
- rmax = vldTableB21(event.last, event.level);
- event.run = event.run + rmax + 1;
- event.level = getbits(1) ? -event.level : event.level;
- break;
- case 0x3 :
- flushbits(2);
- event.last = getbits(1);
- event.run = getbits(6);
- getbits(1);
- event.level = getbits(12);
-
- event.level = (event.level & 0x800) ? (event.level | (-1 ^ 0xfff)) : event.level;
- getbits(1);
- break;
- }
- }
- return event;
- }
- /***/
- event_t vld_inter_dct()
- {
- event_t event;
- tab_type *tab = (tab_type *) NULL;
- int lmax, rmax;
- tab = vldTableB17(showbits(12));
- if (!tab) {
- event.run =
- event.level =
- event.last = -1;
- return event;
- }
- if (tab->val != ESCAPE) {
- event.run = (tab->val >> 4) & 255;
- event.level = tab->val & 15;
- event.last = (tab->val >> 12) & 1;
- event.level = getbits(1) ? -event.level : event.level;
- } else {
- int mode = showbits(2);
- switch (mode) {
- case 0x0 :
- case 0x1 :
- flushbits(1);
- tab = vldTableB17(showbits(12));
- if (!tab) {
- event.run =
- event.level =
- event.last = -1;
- return event;
- }
- event.run = (tab->val >> 4) & 255;
- event.level = tab->val & 15;
- event.last = (tab->val >> 12) & 1;
- lmax = vldTableB20(event.last, event.run);
- event.level += lmax;
- event.level = getbits(1) ? -event.level : event.level;
- break;
- case 0x2 :
- flushbits(2);
- tab = vldTableB17(showbits(12));
- if (!tab) {
- event.run =
- event.level =
- event.last = -1;
- break;
- }
- event.run = (tab->val >> 4) & 255;
- event.level = tab->val & 15;
- event.last = (tab->val >> 12) & 1;
- rmax = vldTableB22(event.last, event.level);
- event.run = event.run + rmax + 1;
- event.level = getbits(1) ? -event.level : event.level;
- break;
- case 0x3 :
- flushbits(2);
- event.last = getbits(1);
- event.run = getbits(6);
- getbits(1);
- event.level = getbits(12);
-
- event.level = (event.level & 0x800) ? (event.level | (-1 ^ 0xfff)) : event.level;
- getbits(1);
- break;
- }
- }
- return event;
- }
- /***/
- event_t vld_event(int intraFlag)
- {
- if (intraFlag) {
- return vld_intra_dct();
- } else {
- return vld_inter_dct();
- }
- }
- /***/
- int vldTableB19(int last, int run) {
- if (!last){
- if (run == 0) {
- return 27;
- } else if (run == 1) {
- return 10;
- } else if (run == 2) {
- return 5;
- } else if (run == 3) {
- return 4;
- } else if (run <= 7) {
- return 3;
- } else if (run <= 9) {
- return 2;
- } else if (run <= 14) {
- return 1;
- } else {
- return 0;
- }
- } else {
- if (run == 0) {
- return 8;
- } else if (run == 1) {
- return 3;
- } else if (run <= 6) {
- return 2;
- } else if (run <= 20) {
- return 1;
- } else {
- return 0;
- }
- }
- }
- /***/
- int vldTableB20(int last, int run) {
- if (!last){
- if (run == 0) {
- return 12;
- } else if (run == 1) {
- return 6;
- } else if (run == 2) {
- return 4;
- } else if (run <= 6) {
- return 3;
- } else if (run <= 10) {
- return 2;
- } else if (run <= 26) {
- return 1;
- } else {
- return 0;
- }
- } else {
- if (run == 0) {
- return 3;
- } else if (run == 1) {
- return 2;
- } else if (run <= 40) {
- return 1;
- } else {
- return 0;
- }
- }
- }
- /***/
- int vldTableB21(int last, int level) {
- if (!last){
- if (level == 1) {
- return 14;
- } else if (level == 2) {
- return 9;
- } else if (level == 3) {
- return 7;
- } else if (level == 4) {
- return 3;
- } else if (level == 5) {
- return 2;
- } else if (level <= 10) {
- return 1;
- } else if (level <= 27) {
- return 0;
- } else {
- return 0;
- }
- } else {
- if (level == 1) {
- return 20;
- } else if (level == 2) {
- return 6;
- } else if (level == 3) {
- return 1;
- } else if (level <= 8) {
- return 0;
- } else {
- return 0;
- }
- }
- }
- /***/
- int vldTableB22(int last, int level) {
- if (!last){ /* LAST == 0 */
- if (level == 1) {
- return 26;
- } else if (level == 2) {
- return 10;
- } else if (level == 3) {
- return 6;
- } else if (level == 4) {
- return 2;
- } else if (level <= 6) {
- return 1;
- } else if (level <= 12) {
- return 0;
- } else {
- return 0;
- }
- } else {
- if (level == 1) {
- return 40;
- } else if (level == 2) {
- return 1;
- } else if (level == 3) {
- return 0;
- } else {
- return 0;
- }
- }
- }
- /***/
- tab_type *vldTableB16(int code) {
- tab_type *tab;
- if (code >= 512) {
- tab = &(mp4_tables->tableB16_1[(code >> 5) - 16]);
- } else if (code >= 128) {
- tab = &(mp4_tables->tableB16_2[(code >> 2) - 32]);
- } else if (code >= 8) {
- tab = &(mp4_tables->tableB16_3[(code >> 0) - 8]);
- } else {
-
- return (tab_type *) NULL;
- }
- flushbits(tab->len);
- return tab;
- }
- /***/
- tab_type *vldTableB17(int code) {
- tab_type *tab;
- if (code >= 512) {
- tab = &(mp4_tables->tableB17_1[(code >> 5) - 16]);
- } else if (code >= 128) {
- tab = &(mp4_tables->tableB17_2[(code >> 2) - 32]);
- } else if (code >= 8) {
- tab = &(mp4_tables->tableB17_3[(code >> 0) - 8]);
- } else {
-
- return (tab_type *) NULL;
- }
- flushbits(tab->len);
- return tab;
- }
- /***/