mp4_decoder.c
资源名称:VC++视频传输.rar [点击查看]
上传用户:hxb_1234
上传日期:2010-03-30
资源大小:8328k
文件大小:4k
源码类别:
VC书籍
开发平台:
Visual C++
- #include <stdio.h>
- #include <stdlib.h>
- #include <ctype.h>
- #include <fcntl.h>
- #include <string.h>
- #include <assert.h>
- #ifdef WIN32
- #include <io.h>
- #endif
- #include "mp4_vars.h"
- #include "decore.h"
- // 解码器初始化
- void initdecoder (DEC_BUFFERS buffers)
- {
- int i, j, cc;
- save_tables(mp4_tables);
- mp4_state->clp = mp4_state->clp_data + 384;
- for (i = -384; i < 640; i++)
- mp4_state->clp[i] = (unsigned char) ( (i < 0) ? 0 : ((i > 255) ? 255 : i) );
- // DC和AC系数的预测因为DCT变换后的系数分为DC(直流)和AC(交流)两类而DC系数是左上角
- // 的第一个值,其它的为AC系数 DC/AC预测是使用相邻块的DC/AC值来预测当前块的系数值。
- // (注意:预测仅在第一行和第一列进行)
- // 直流(dc)预测
- for (i = 0; i < (2*DEC_MBC+1); i++)
- mp4_state->coeff_pred.dc_store_lum[0][i] = 1024;
- for (i = 1; i < (2*DEC_MBR+1); i++)
- mp4_state->coeff_pred.dc_store_lum[i][0] = 1024;
- for (i = 0; i < (DEC_MBC+1); i++) {
- mp4_state->coeff_pred.dc_store_chr[0][0][i] = 1024;
- mp4_state->coeff_pred.dc_store_chr[1][0][i] = 1024;
- }
- for (i = 1; i < (DEC_MBR+1); i++) {
- mp4_state->coeff_pred.dc_store_chr[0][i][0] = 1024;
- mp4_state->coeff_pred.dc_store_chr[1][i][0] = 1024;
- }
- // 交流(ac)预测
- for (i = 0; i < (2*DEC_MBC+1); i++)
- for (j = 0; j < 7; j++) {
- mp4_state->coeff_pred.ac_left_lum[0][i][j] = 0;
- mp4_state->coeff_pred.ac_top_lum[0][i][j] = 0;
- }
- for (i = 1; i < (2*DEC_MBR+1); i++)
- for (j = 0; j < 7; j++) {
- mp4_state->coeff_pred.ac_left_lum[i][0][j] = 0;
- mp4_state->coeff_pred.ac_top_lum[i][0][j] = 0;
- }
- for (i = 0; i < (DEC_MBC+1); i++)
- for (j = 0; j < 7; j++) {
- mp4_state->coeff_pred.ac_left_chr[0][0][i][j] = 0;
- mp4_state->coeff_pred.ac_top_chr[0][0][i][j] = 0;
- mp4_state->coeff_pred.ac_left_chr[1][0][i][j] = 0;
- mp4_state->coeff_pred.ac_top_chr[1][0][i][j] = 0;
- }
- for (i = 1; i < (DEC_MBR+1); i++)
- for (j = 0; j < 7; j++) {
- mp4_state->coeff_pred.ac_left_chr[0][i][0][j] = 0;
- mp4_state->coeff_pred.ac_top_chr[0][i][0][j] = 0;
- mp4_state->coeff_pred.ac_left_chr[1][i][0][j] = 0;
- mp4_state->coeff_pred.ac_top_chr[1][i][0][j] = 0;
- }
- for (i = 0; i < mp4_state->mb_width + 1; i++)
- mp4_state->modemap[0][i] = INTRA;
- for (i = 0; i < mp4_state->mb_height + 1; i++) {
- mp4_state->modemap[i][0] = INTRA;
- mp4_state->modemap[i][mp4_state->mb_width+1] = INTRA;
- }
- for (cc = 0; cc < 3; cc++)
- {
- if (cc == 0)
- {
- edged_ref[cc] = (unsigned char *) buffers.mp4_edged_ref_buffers;
- assert(edged_ref[cc]);
- edged_for[cc] = (unsigned char *) buffers.mp4_edged_for_buffers;
- assert(edged_for[cc]);
- frame_ref[cc] = edged_ref[cc] + mp4_state->coded_picture_width * 32 + 32;
- frame_for[cc] = edged_for[cc] + mp4_state->coded_picture_width * 32 + 32;
- }
- else
- {
- unsigned int offset;
- if (cc == 1)
- offset = mp4_state->coded_picture_width * mp4_state->coded_picture_height;
- else
- offset = mp4_state->coded_picture_width * mp4_state->coded_picture_height +
- mp4_state->chrom_width * mp4_state->chrom_height;
- edged_ref[cc] = (unsigned char *) buffers.mp4_edged_ref_buffers + offset;
- assert(edged_ref[cc]);
- edged_for[cc] = (unsigned char *) buffers.mp4_edged_for_buffers + offset;
- assert(edged_for[cc]);
- frame_ref[cc] = edged_ref[cc] + mp4_state->chrom_width * 16 + 16;
- frame_for[cc] = edged_for[cc] + mp4_state->chrom_width * 16 + 16;
- }
- }
- // 显示帧
- for (cc = 0; cc < 3; cc++)
- {
- unsigned int offset;
- switch (cc)
- {
- case 0:
- offset = 0;
- break;
- case 1:
- offset = mp4_state->horizontal_size * mp4_state->vertical_size;
- break;
- case 2:
- offset = (mp4_state->horizontal_size * mp4_state->vertical_size) +
- ((mp4_state->horizontal_size * mp4_state->vertical_size) >> 2);
- break;
- }
- display_frame[cc] = (unsigned char *) buffers.mp4_display_buffers + offset;
- assert(display_frame[cc]);
- }
- }
- /***/
- void closedecoder ()
- {
- }