00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #include "avcodec.h"
00026 #include "dsputil.h"
00027 #include "mpegvideo.h"
00028 #include "xvmc_render.h"
00029
00030 #include "xvmccommon.c"
00031
00032 int XVMC_VLD_field_start(MpegEncContext* s, AVCodecContext* avctx)
00033 {
00034 xvmc_render_state_t *render;
00035 XvMCMpegControl binfo;
00036 XvMCQMatrix qmatrix;
00037 int i;
00038
00039 XVMC_field_start(s, avctx);
00040
00041 render = (xvmc_render_state_t*) s->current_picture.data[2];
00042 bzero(&binfo, sizeof(binfo));
00043 bzero(&qmatrix, sizeof(qmatrix));
00044
00045 for (i = 0; i < 64; i++)
00046 {
00047 if (s->alternate_scan)
00048 {
00049
00050
00051
00052
00053
00054
00055
00056 qmatrix.intra_quantiser_matrix[i]
00057 = s->intra_matrix[s->dsp.idct_permutation[i]];
00058 qmatrix.non_intra_quantiser_matrix[i]
00059 = s->inter_matrix[s->dsp.idct_permutation[i]];
00060 qmatrix.chroma_intra_quantiser_matrix[i]
00061 = s->chroma_intra_matrix[s->dsp.idct_permutation[i]];
00062 qmatrix.chroma_non_intra_quantiser_matrix[i]
00063 = s->chroma_inter_matrix[s->dsp.idct_permutation[i]];
00064 }
00065 else
00066 {
00067 qmatrix.intra_quantiser_matrix[i]
00068 = s->intra_matrix[s->dsp.idct_permutation[i]];
00069 qmatrix.non_intra_quantiser_matrix[i]
00070 = s->inter_matrix[s->dsp.idct_permutation[i]];
00071 qmatrix.chroma_intra_quantiser_matrix[i]
00072 = s->chroma_intra_matrix[s->dsp.idct_permutation[i]];
00073 qmatrix.chroma_non_intra_quantiser_matrix[i]
00074 = s->chroma_inter_matrix[s->dsp.idct_permutation[i]];
00075 }
00076 }
00077
00078 qmatrix.load_intra_quantiser_matrix = 1;
00079 qmatrix.load_non_intra_quantiser_matrix = 1;
00080 qmatrix.load_chroma_intra_quantiser_matrix = 1;
00081 qmatrix.load_chroma_non_intra_quantiser_matrix = 1;
00082
00083 binfo.flags = 0;
00084 if (s->alternate_scan)
00085 binfo.flags |= XVMC_ALTERNATE_SCAN;
00086 if (s->top_field_first)
00087 binfo.flags |= XVMC_TOP_FIELD_FIRST;
00088 if (s->frame_pred_frame_dct)
00089 binfo.flags |= XVMC_PRED_DCT_FRAME;
00090 else
00091 binfo.flags |= XVMC_PRED_DCT_FIELD;
00092
00093 if (s->intra_vlc_format)
00094 binfo.flags |= XVMC_INTRA_VLC_FORMAT;
00095 if (!s->first_field && !s->progressive_sequence)
00096 binfo.flags |= XVMC_SECOND_FIELD;
00097 if (s->q_scale_type)
00098 binfo.flags |= XVMC_Q_SCALE_TYPE;
00099 if (s->concealment_motion_vectors)
00100 binfo.flags |= XVMC_CONCEALMENT_MOTION_VECTORS;
00101 if (s->progressive_sequence)
00102 binfo.flags |= XVMC_PROGRESSIVE_SEQUENCE;
00103
00104 binfo.picture_structure = s->picture_structure;
00105 switch (s->pict_type)
00106 {
00107 case I_TYPE: binfo.picture_coding_type = XVMC_I_PICTURE; break;
00108 case P_TYPE: binfo.picture_coding_type = XVMC_P_PICTURE; break;
00109 case B_TYPE: binfo.picture_coding_type = XVMC_B_PICTURE; break;
00110 default: av_log(avctx, AV_LOG_ERROR,
00111 "%s: Unknown picture coding type: %d\n",
00112 __FUNCTION__, s->pict_type);
00113 }
00114
00115 binfo.intra_dc_precision = s->intra_dc_precision;;
00116
00117 if (s->codec_id == CODEC_ID_MPEG2VIDEO)
00118 binfo.mpeg_coding = 2;
00119 else
00120 binfo.mpeg_coding = 1;
00121
00122 #ifdef ZAP
00123
00124 s->mb_width = (s->width + 15) / 16;
00125 s->mb_height = (s->codec_id == CODEC_ID_MPEG2VIDEO
00126 && !s->progressive_sequence) ?
00127 2 * ((s->height + 31) / 32) : (s->height + 15) / 16;
00128 #endif
00129
00130 binfo.FVMV_range = (s->mpeg_f_code[0][1] - 1);
00131 binfo.FHMV_range = (s->mpeg_f_code[0][0] - 1);
00132 binfo.BVMV_range = (s->mpeg_f_code[1][1] - 1);
00133 binfo.BHMV_range = (s->mpeg_f_code[1][0] - 1);
00134
00135 Status status;
00136
00137 status = XvMCLoadQMatrix(render->disp, render->ctx, &qmatrix);
00138 if (status)
00139 av_log(avctx, AV_LOG_ERROR, "XvMCLoadQMatrix: Error: %d\n", status);
00140
00141 status = XvMCBeginSurface(render->disp, render->ctx, render->p_surface,
00142 render->p_past_surface, render->p_future_surface,
00143 &binfo);
00144 if (status)
00145 av_log(avctx, AV_LOG_ERROR, "XvMCBeginSurface: Error: %d\n", status);
00146
00147 return 0;
00148 }
00149
00150 void XVMC_VLD_field_end(MpegEncContext* s)
00151 {
00152 xvmc_render_state_t* render;
00153
00154 render = (xvmc_render_state_t *)s->current_picture.data[2];
00155 assert(render != NULL);
00156
00157 XvMCFlushSurface(render->disp, render->p_surface);
00158 XvMCSyncSurface(render->disp, render->p_surface);
00159
00160 s->error_count = 0;
00161 }
00162
00163 static int length_to_next_start(uint8_t* pbuf_ptr, int buf_size)
00164 {
00165 uint8_t* buf_ptr;
00166 unsigned int state = 0xFFFFFFFF, v;
00167
00168 buf_ptr = pbuf_ptr;
00169 while (buf_ptr < pbuf_ptr + buf_size)
00170 {
00171 v = *buf_ptr++;
00172 if (state == 0x000001) {
00173 return buf_ptr - pbuf_ptr - 4;
00174 }
00175 state = ((state << 8) | v) & 0xffffff;
00176 }
00177 return -1;
00178 }
00179
00180 #define SLICE_MIN_START_CODE 0x00000101
00181 #define SLICE_MAX_START_CODE 0x000001af
00182
00183
00184 int XVMC_VLD_decode_slice(MpegEncContext* s, int mb_y,
00185 uint8_t* buffer, int buf_size)
00186 {
00187 int slicelen = length_to_next_start(buffer, buf_size);
00188 xvmc_render_state_t* render;
00189
00190 if (slicelen < 0)
00191 {
00192 if ((mb_y == s->mb_height - 1) ||
00193 (!s->progressive_sequence && (mb_y == ((s->mb_height >> 1) -1))))
00194 slicelen = buf_size;
00195 else
00196 return -1;
00197 }
00198
00199 render = (xvmc_render_state_t*)s->current_picture.data[2];
00200 render->slice_code = SLICE_MIN_START_CODE + mb_y;
00201 render->slice_data = buffer;
00202 render->slice_datalen = slicelen;
00203
00204 ff_draw_horiz_band(s, 0, 0);
00205
00206 return slicelen;
00207 }
00208