00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #include <limits.h>
00025 #include "avcodec.h"
00026 #include "h264.h"
00027 #include "vc1.h"
00028
00029 #undef NDEBUG
00030 #include <assert.h>
00031
00032 #include "vdpau.h"
00033 #include "vdpau_internal.h"
00034
00041 void ff_vdpau_h264_set_reference_frames(MpegEncContext *s)
00042 {
00043 H264Context *h = s->avctx->priv_data;
00044 struct vdpau_render_state *render, *render_ref;
00045 VdpReferenceFrameH264 *rf, *rf2;
00046 Picture *pic;
00047 int i, list, pic_frame_idx;
00048
00049 render = (struct vdpau_render_state *)s->current_picture_ptr->data[0];
00050 assert(render);
00051
00052 rf = &render->info.h264.referenceFrames[0];
00053 #define H264_RF_COUNT FF_ARRAY_ELEMS(render->info.h264.referenceFrames)
00054
00055 for (list = 0; list < 2; ++list) {
00056 Picture **lp = list ? h->long_ref : h->short_ref;
00057 int ls = list ? h->long_ref_count : h->short_ref_count;
00058
00059 for (i = 0; i < ls; ++i) {
00060 pic = lp[i];
00061 if (!pic || !pic->reference)
00062 continue;
00063 pic_frame_idx = pic->long_ref ? pic->pic_id : pic->frame_num;
00064
00065 render_ref = (struct vdpau_render_state *)pic->data[0];
00066 assert(render_ref);
00067
00068 rf2 = &render->info.h264.referenceFrames[0];
00069 while (rf2 != rf) {
00070 if (
00071 (rf2->surface == render_ref->surface)
00072 && (rf2->is_long_term == pic->long_ref)
00073 && (rf2->frame_idx == pic_frame_idx)
00074 )
00075 break;
00076 ++rf2;
00077 }
00078 if (rf2 != rf) {
00079 rf2->top_is_reference |= (pic->reference & PICT_TOP_FIELD) ? VDP_TRUE : VDP_FALSE;
00080 rf2->bottom_is_reference |= (pic->reference & PICT_BOTTOM_FIELD) ? VDP_TRUE : VDP_FALSE;
00081 continue;
00082 }
00083
00084 if (rf >= &render->info.h264.referenceFrames[H264_RF_COUNT])
00085 continue;
00086
00087 rf->surface = render_ref->surface;
00088 rf->is_long_term = pic->long_ref;
00089 rf->top_is_reference = (pic->reference & PICT_TOP_FIELD) ? VDP_TRUE : VDP_FALSE;
00090 rf->bottom_is_reference = (pic->reference & PICT_BOTTOM_FIELD) ? VDP_TRUE : VDP_FALSE;
00091 rf->field_order_cnt[0] = pic->field_poc[0];
00092 rf->field_order_cnt[1] = pic->field_poc[1];
00093 rf->frame_idx = pic_frame_idx;
00094
00095 ++rf;
00096 }
00097 }
00098
00099 for (; rf < &render->info.h264.referenceFrames[H264_RF_COUNT]; ++rf) {
00100 rf->surface = VDP_INVALID_HANDLE;
00101 rf->is_long_term = 0;
00102 rf->top_is_reference = 0;
00103 rf->bottom_is_reference = 0;
00104 rf->field_order_cnt[0] = 0;
00105 rf->field_order_cnt[1] = 0;
00106 rf->frame_idx = 0;
00107 }
00108 }
00109
00110 void ff_vdpau_add_data_chunk(MpegEncContext *s,
00111 const uint8_t *buf, int buf_size)
00112 {
00113 struct vdpau_render_state *render;
00114
00115 render = (struct vdpau_render_state *)s->current_picture_ptr->data[0];
00116 assert(render);
00117
00118 render->bitstream_buffers= av_fast_realloc(
00119 render->bitstream_buffers,
00120 &render->bitstream_buffers_allocated,
00121 sizeof(*render->bitstream_buffers)*(render->bitstream_buffers_used + 1)
00122 );
00123
00124 render->bitstream_buffers[render->bitstream_buffers_used].struct_version = VDP_BITSTREAM_BUFFER_VERSION;
00125 render->bitstream_buffers[render->bitstream_buffers_used].bitstream = buf;
00126 render->bitstream_buffers[render->bitstream_buffers_used].bitstream_bytes = buf_size;
00127 render->bitstream_buffers_used++;
00128 }
00129
00130 void ff_vdpau_h264_picture_complete(MpegEncContext *s)
00131 {
00132 H264Context *h = s->avctx->priv_data;
00133 struct vdpau_render_state *render;
00134 int i;
00135
00136 render = (struct vdpau_render_state *)s->current_picture_ptr->data[0];
00137 assert(render);
00138
00139 render->info.h264.slice_count = h->slice_num;
00140 if (render->info.h264.slice_count < 1)
00141 return;
00142
00143 for (i = 0; i < 2; ++i) {
00144 int foc = s->current_picture_ptr->field_poc[i];
00145 if (foc == INT_MAX)
00146 foc = 0;
00147 render->info.h264.field_order_cnt[i] = foc;
00148 }
00149
00150 render->info.h264.is_reference = (s->current_picture_ptr->reference & 3) ? VDP_TRUE : VDP_FALSE;
00151 render->info.h264.frame_num = h->frame_num;
00152 render->info.h264.field_pic_flag = s->picture_structure != PICT_FRAME;
00153 render->info.h264.bottom_field_flag = s->picture_structure == PICT_BOTTOM_FIELD;
00154 render->info.h264.num_ref_frames = h->sps.ref_frame_count;
00155 render->info.h264.mb_adaptive_frame_field_flag = h->sps.mb_aff && !render->info.h264.field_pic_flag;
00156 render->info.h264.constrained_intra_pred_flag = h->pps.constrained_intra_pred;
00157 render->info.h264.weighted_pred_flag = h->pps.weighted_pred;
00158 render->info.h264.weighted_bipred_idc = h->pps.weighted_bipred_idc;
00159 render->info.h264.frame_mbs_only_flag = h->sps.frame_mbs_only_flag;
00160 render->info.h264.transform_8x8_mode_flag = h->pps.transform_8x8_mode;
00161 render->info.h264.chroma_qp_index_offset = h->pps.chroma_qp_index_offset[0];
00162 render->info.h264.second_chroma_qp_index_offset = h->pps.chroma_qp_index_offset[1];
00163 render->info.h264.pic_init_qp_minus26 = h->pps.init_qp - 26;
00164 render->info.h264.num_ref_idx_l0_active_minus1 = h->pps.ref_count[0] - 1;
00165 render->info.h264.num_ref_idx_l1_active_minus1 = h->pps.ref_count[1] - 1;
00166 render->info.h264.log2_max_frame_num_minus4 = h->sps.log2_max_frame_num - 4;
00167 render->info.h264.pic_order_cnt_type = h->sps.poc_type;
00168 render->info.h264.log2_max_pic_order_cnt_lsb_minus4 = h->sps.log2_max_poc_lsb - 4;
00169 render->info.h264.delta_pic_order_always_zero_flag = h->sps.delta_pic_order_always_zero_flag;
00170 render->info.h264.direct_8x8_inference_flag = h->sps.direct_8x8_inference_flag;
00171 render->info.h264.entropy_coding_mode_flag = h->pps.cabac;
00172 render->info.h264.pic_order_present_flag = h->pps.pic_order_present;
00173 render->info.h264.deblocking_filter_control_present_flag = h->pps.deblocking_filter_parameters_present;
00174 render->info.h264.redundant_pic_cnt_present_flag = h->pps.redundant_pic_cnt_present;
00175 memcpy(render->info.h264.scaling_lists_4x4, h->pps.scaling_matrix4, sizeof(render->info.h264.scaling_lists_4x4));
00176 memcpy(render->info.h264.scaling_lists_8x8, h->pps.scaling_matrix8, sizeof(render->info.h264.scaling_lists_8x8));
00177
00178 ff_draw_horiz_band(s, 0, s->avctx->height);
00179 render->bitstream_buffers_used = 0;
00180 }
00181
00182 void ff_vdpau_mpeg_picture_complete(MpegEncContext *s, const uint8_t *buf,
00183 int buf_size, int slice_count)
00184 {
00185 struct vdpau_render_state *render, *last, *next;
00186 int i;
00187
00188 if (!s->current_picture_ptr) return;
00189
00190 render = (struct vdpau_render_state *)s->current_picture_ptr->data[0];
00191 assert(render);
00192
00193
00194 render->info.mpeg.picture_structure = s->picture_structure;
00195 render->info.mpeg.picture_coding_type = s->pict_type;
00196 render->info.mpeg.intra_dc_precision = s->intra_dc_precision;
00197 render->info.mpeg.frame_pred_frame_dct = s->frame_pred_frame_dct;
00198 render->info.mpeg.concealment_motion_vectors = s->concealment_motion_vectors;
00199 render->info.mpeg.intra_vlc_format = s->intra_vlc_format;
00200 render->info.mpeg.alternate_scan = s->alternate_scan;
00201 render->info.mpeg.q_scale_type = s->q_scale_type;
00202 render->info.mpeg.top_field_first = s->top_field_first;
00203 render->info.mpeg.full_pel_forward_vector = s->full_pel[0];
00204 render->info.mpeg.full_pel_backward_vector = s->full_pel[1];
00205 render->info.mpeg.f_code[0][0] = s->mpeg_f_code[0][0];
00206 render->info.mpeg.f_code[0][1] = s->mpeg_f_code[0][1];
00207 render->info.mpeg.f_code[1][0] = s->mpeg_f_code[1][0];
00208 render->info.mpeg.f_code[1][1] = s->mpeg_f_code[1][1];
00209 for (i = 0; i < 64; ++i) {
00210 render->info.mpeg.intra_quantizer_matrix[i] = s->intra_matrix[i];
00211 render->info.mpeg.non_intra_quantizer_matrix[i] = s->inter_matrix[i];
00212 }
00213
00214 render->info.mpeg.forward_reference = VDP_INVALID_HANDLE;
00215 render->info.mpeg.backward_reference = VDP_INVALID_HANDLE;
00216
00217 switch(s->pict_type){
00218 case FF_B_TYPE:
00219 next = (struct vdpau_render_state *)s->next_picture.data[0];
00220 assert(next);
00221 render->info.mpeg.backward_reference = next->surface;
00222
00223 case FF_P_TYPE:
00224 last = (struct vdpau_render_state *)s->last_picture.data[0];
00225 if (!last)
00226 last = render;
00227 render->info.mpeg.forward_reference = last->surface;
00228 }
00229
00230 ff_vdpau_add_data_chunk(s, buf, buf_size);
00231
00232 render->info.mpeg.slice_count = slice_count;
00233
00234 if (slice_count)
00235 ff_draw_horiz_band(s, 0, s->avctx->height);
00236 render->bitstream_buffers_used = 0;
00237 }
00238
00239 void ff_vdpau_vc1_decode_picture(MpegEncContext *s, const uint8_t *buf,
00240 int buf_size)
00241 {
00242 VC1Context *v = s->avctx->priv_data;
00243 struct vdpau_render_state *render, *last, *next;
00244
00245 render = (struct vdpau_render_state *)s->current_picture.data[0];
00246 assert(render);
00247
00248
00249 render->info.vc1.frame_coding_mode = v->fcm;
00250 render->info.vc1.postprocflag = v->postprocflag;
00251 render->info.vc1.pulldown = v->broadcast;
00252 render->info.vc1.interlace = v->interlace;
00253 render->info.vc1.tfcntrflag = v->tfcntrflag;
00254 render->info.vc1.finterpflag = v->finterpflag;
00255 render->info.vc1.psf = v->psf;
00256 render->info.vc1.dquant = v->dquant;
00257 render->info.vc1.panscan_flag = v->panscanflag;
00258 render->info.vc1.refdist_flag = v->refdist_flag;
00259 render->info.vc1.quantizer = v->quantizer_mode;
00260 render->info.vc1.extended_mv = v->extended_mv;
00261 render->info.vc1.extended_dmv = v->extended_dmv;
00262 render->info.vc1.overlap = v->overlap;
00263 render->info.vc1.vstransform = v->vstransform;
00264 render->info.vc1.loopfilter = v->s.loop_filter;
00265 render->info.vc1.fastuvmc = v->fastuvmc;
00266 render->info.vc1.range_mapy_flag = v->range_mapy_flag;
00267 render->info.vc1.range_mapy = v->range_mapy;
00268 render->info.vc1.range_mapuv_flag = v->range_mapuv_flag;
00269 render->info.vc1.range_mapuv = v->range_mapuv;
00270
00271 render->info.vc1.multires = v->multires;
00272 render->info.vc1.syncmarker = v->s.resync_marker;
00273 render->info.vc1.rangered = v->rangered | (v->rangeredfrm << 1);
00274 render->info.vc1.maxbframes = v->s.max_b_frames;
00275
00276 render->info.vc1.deblockEnable = v->postprocflag & 1;
00277 render->info.vc1.pquant = v->pq;
00278
00279 render->info.vc1.forward_reference = VDP_INVALID_HANDLE;
00280 render->info.vc1.backward_reference = VDP_INVALID_HANDLE;
00281
00282 if (v->bi_type)
00283 render->info.vc1.picture_type = 4;
00284 else
00285 render->info.vc1.picture_type = s->pict_type - 1 + s->pict_type / 3;
00286
00287 switch(s->pict_type){
00288 case FF_B_TYPE:
00289 next = (struct vdpau_render_state *)s->next_picture.data[0];
00290 assert(next);
00291 render->info.vc1.backward_reference = next->surface;
00292
00293 case FF_P_TYPE:
00294 last = (struct vdpau_render_state *)s->last_picture.data[0];
00295 if (!last)
00296 last = render;
00297 render->info.vc1.forward_reference = last->surface;
00298 }
00299
00300 ff_vdpau_add_data_chunk(s, buf, buf_size);
00301
00302 render->info.vc1.slice_count = 1;
00303
00304 ff_draw_horiz_band(s, 0, s->avctx->height);
00305 render->bitstream_buffers_used = 0;
00306 }
00307
00308