libavcodec/vaapi_mpeg2.c

Go to the documentation of this file.
00001 /*
00002  * MPEG-2 HW decode acceleration through VA API
00003  *
00004  * Copyright (C) 2008-2009 Splitted-Desktop Systems
00005  *
00006  * This file is part of FFmpeg.
00007  *
00008  * FFmpeg is free software; you can redistribute it and/or
00009  * modify it under the terms of the GNU Lesser General Public
00010  * License as published by the Free Software Foundation; either
00011  * version 2.1 of the License, or (at your option) any later version.
00012  *
00013  * FFmpeg is distributed in the hope that it will be useful,
00014  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00015  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
00016  * Lesser General Public License for more details.
00017  *
00018  * You should have received a copy of the GNU Lesser General Public
00019  * License along with FFmpeg; if not, write to the Free Software
00020  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
00021  */
00022 
00023 #include "vaapi_internal.h"
00024 #include "dsputil.h"
00025 
00027 static inline int mpeg2_get_f_code(MpegEncContext *s)
00028 {
00029 return (s->mpeg_f_code[0][0] << 12) | (s->mpeg_f_code[0][1] << 8) |
00030 (s->mpeg_f_code[1][0] << 4) | s->mpeg_f_code[1][1];
00031 }
00032 
00034 static inline int mpeg2_get_is_frame_start(MpegEncContext *s)
00035 {
00036 return s->first_field || s->picture_structure == PICT_FRAME;
00037 }
00038 
00039 static int vaapi_mpeg2_start_frame(AVCodecContext *avctx, av_unused const uint8_t *buffer, av_unused uint32_t size)
00040 {
00041 struct MpegEncContext * const s = avctx->priv_data;
00042 struct vaapi_context * const vactx = avctx->hwaccel_context;
00043 VAPictureParameterBufferMPEG2 *pic_param;
00044 VAIQMatrixBufferMPEG2 *iq_matrix;
00045 int i;
00046 
00047 av_dlog(avctx, "vaapi_mpeg2_start_frame()\n");
00048 
00049 vactx->slice_param_size = sizeof(VASliceParameterBufferMPEG2);
00050 
00051 /* Fill in VAPictureParameterBufferMPEG2 */
00052 pic_param = ff_vaapi_alloc_pic_param(vactx, sizeof(VAPictureParameterBufferMPEG2));
00053 if (!pic_param)
00054 return -1;
00055 pic_param->horizontal_size = s->width;
00056 pic_param->vertical_size = s->height;
00057 pic_param->forward_reference_picture = VA_INVALID_ID;
00058 pic_param->backward_reference_picture = VA_INVALID_ID;
00059 pic_param->picture_coding_type = s->pict_type;
00060 pic_param->f_code = mpeg2_get_f_code(s);
00061 pic_param->picture_coding_extension.value = 0; /* reset all bits */
00062 pic_param->picture_coding_extension.bits.intra_dc_precision = s->intra_dc_precision;
00063 pic_param->picture_coding_extension.bits.picture_structure = s->picture_structure;
00064 pic_param->picture_coding_extension.bits.top_field_first = s->top_field_first;
00065 pic_param->picture_coding_extension.bits.frame_pred_frame_dct = s->frame_pred_frame_dct;
00066 pic_param->picture_coding_extension.bits.concealment_motion_vectors = s->concealment_motion_vectors;
00067 pic_param->picture_coding_extension.bits.q_scale_type = s->q_scale_type;
00068 pic_param->picture_coding_extension.bits.intra_vlc_format = s->intra_vlc_format;
00069 pic_param->picture_coding_extension.bits.alternate_scan = s->alternate_scan;
00070 pic_param->picture_coding_extension.bits.repeat_first_field = s->repeat_first_field;
00071 pic_param->picture_coding_extension.bits.progressive_frame = s->progressive_frame;
00072 pic_param->picture_coding_extension.bits.is_first_field = mpeg2_get_is_frame_start(s);
00073 
00074 switch (s->pict_type) {
00075 case AV_PICTURE_TYPE_B:
00076 pic_param->backward_reference_picture = ff_vaapi_get_surface_id(&s->next_picture);
00077 // fall-through
00078 case AV_PICTURE_TYPE_P:
00079 pic_param->forward_reference_picture = ff_vaapi_get_surface_id(&s->last_picture);
00080 break;
00081 }
00082 
00083 /* Fill in VAIQMatrixBufferMPEG2 */
00084 iq_matrix = ff_vaapi_alloc_iq_matrix(vactx, sizeof(VAIQMatrixBufferMPEG2));
00085 if (!iq_matrix)
00086 return -1;
00087 iq_matrix->load_intra_quantiser_matrix = 1;
00088 iq_matrix->load_non_intra_quantiser_matrix = 1;
00089 iq_matrix->load_chroma_intra_quantiser_matrix = 1;
00090 iq_matrix->load_chroma_non_intra_quantiser_matrix = 1;
00091 
00092 for (i = 0; i < 64; i++) {
00093 int n = s->dsp.idct_permutation[ff_zigzag_direct[i]];
00094 iq_matrix->intra_quantiser_matrix[i] = s->intra_matrix[n];
00095 iq_matrix->non_intra_quantiser_matrix[i] = s->inter_matrix[n];
00096 iq_matrix->chroma_intra_quantiser_matrix[i] = s->chroma_intra_matrix[n];
00097 iq_matrix->chroma_non_intra_quantiser_matrix[i] = s->chroma_inter_matrix[n];
00098 }
00099 return 0;
00100 }
00101 
00102 static int vaapi_mpeg2_end_frame(AVCodecContext *avctx)
00103 {
00104 return ff_vaapi_common_end_frame(avctx->priv_data);
00105 }
00106 
00107 static int vaapi_mpeg2_decode_slice(AVCodecContext *avctx, const uint8_t *buffer, uint32_t size)
00108 {
00109 MpegEncContext * const s = avctx->priv_data;
00110 VASliceParameterBufferMPEG2 *slice_param;
00111 GetBitContext gb;
00112 uint32_t quantiser_scale_code, intra_slice_flag, macroblock_offset;
00113 
00114 av_dlog(avctx, "vaapi_mpeg2_decode_slice(): buffer %p, size %d\n", buffer, size);
00115 
00116 /* Determine macroblock_offset */
00117 init_get_bits(&gb, buffer, 8 * size);
00118 if (get_bits_long(&gb, 32) >> 8 != 1) /* start code */
00119 return AVERROR_INVALIDDATA;
00120 quantiser_scale_code = get_bits(&gb, 5);
00121 intra_slice_flag = get_bits1(&gb);
00122 if (intra_slice_flag) {
00123 skip_bits(&gb, 8);
00124 while (get_bits1(&gb) != 0)
00125 skip_bits(&gb, 8);
00126 }
00127 macroblock_offset = get_bits_count(&gb);
00128 
00129 /* Fill in VASliceParameterBufferMPEG2 */
00130 slice_param = (VASliceParameterBufferMPEG2 *)ff_vaapi_alloc_slice(avctx->hwaccel_context, buffer, size);
00131 if (!slice_param)
00132 return -1;
00133 slice_param->macroblock_offset = macroblock_offset;
00134 slice_param->slice_horizontal_position = s->mb_x;
00135 slice_param->slice_vertical_position = s->mb_y;
00136 slice_param->quantiser_scale_code = quantiser_scale_code;
00137 slice_param->intra_slice_flag = intra_slice_flag;
00138 return 0;
00139 }
00140 
00141 AVHWAccel ff_mpeg2_vaapi_hwaccel = {
00142 .name = "mpeg2_vaapi",
00143 .type = AVMEDIA_TYPE_VIDEO,
00144 .id = CODEC_ID_MPEG2VIDEO,
00145 .pix_fmt = PIX_FMT_VAAPI_VLD,
00146 .start_frame = vaapi_mpeg2_start_frame,
00147 .end_frame = vaapi_mpeg2_end_frame,
00148 .decode_slice = vaapi_mpeg2_decode_slice,
00149 };

Generated on Fri Oct 26 02:45:59 2012 for FFmpeg by doxygen 1.5.8

AltStyle によって変換されたページ (->オリジナル) /