[FFmpeg-devel] [PATCH][VAAPI][4/6] Add MPEG-4 / H.263 bitstream decoding (take 9)

Michael Niedermayer michaelni
Tue Mar 31 17:59:23 CEST 2009


On Tue, Mar 31, 2009 at 03:24:31PM +0200, Gwenole Beauchesne wrote:
> Le 30 mars 09 ? 18:19, Gwenole Beauchesne a ?crit :
>
>> On Sun, 29 Mar 2009, Michael Niedermayer wrote:
>>
>>> On Sun, Mar 29, 2009 at 09:31:21AM +0200, Gwenole Beauchesne wrote:
>>>> Le 29 mars 09 ? 04:28, Michael Niedermayer a ?crit :
>>>>
>>>>>> +/** Reconstruct bitstream intra_dc_vlc_thr */
>>>>>> +static int mpeg4_get_intra_dc_vlc_thr(MpegEncContext *s)
>>>>>> +{
>>>>>> +    int v = 0;
>>>>>
>>>>>> +    if (s->shape != 2) { /* video_object_layer_shape != "binary only" 
>>>>>> */
>>>>>
>>>>> binary only shaps work?
>>>>
>>>> I am only trying to reconstruct the original intra_dc_vlc_thr syntax
>>>> element in the bitstream. And AFAICS, this is only defined if not binary
>>>> shape.
>>>>
>>>> That was to save an exra field from MpegEncContext since we don't really
>>>> have an H263Context to add whatever we want for H.263.
>>>
>>> what fails if you remove the check?
>>
>> My eyes. ;-)

We are currently attempting some experiment in chernobyl with one of our
developers, namely to grow a second pair of eyes. If this turns out
successfull maybe you should try that too? ;)


>> I fail to see a difference with the very few samples I have 
>> but that covers only the H.263 samples from mpq and I did not find any for 
>> !short-header case. i.e. I just can't say this will really work for all 
>> samples.

you found no mpeg4 asp, no divx no xvid on mphq?


>
> Here is a new patch with the check removed, though I am still not very 
> satisfied with that removal: the HW doesn't know about the shape.
>
>>>>>> +    /* Parameters defined by source_format field (Table 6-25) */
>>>>>> +    const int source_format = h263_get_picture_format(s->width,
>>>>>> s->height);
>>>>>> +    static const uint16_t num_macroblocks_in_gob[8] =
>>>>>> +        { 0, 8, 11, 22, 88, 352, 0, 0 };
>>>>>> +    static const uint8_t num_gobs_in_vop[8] =
>>>>>> +        { 0, 6, 9, 18, 18, 18, 0, 0 };
>>>>>
>>>>> use mb_height/mb_width please or maybe we have a more fitting field
>>>>> i dont remember
>>>>
>>>> What do you mean?
>>>
>>> i mean we have a functioning encoder by that all needed parts must exist
>>> already, ive now checked and theres ff_h263_get_gob_height() that seems
>>> what we need.
>>
>> pic_param->num_macroblocks_in_gob = s->mb_width * 
>> ff_h263_get_gob_height(s);
>> pic_param->num_gobs_in_vop = s->mb_height / ff_h263_get_gob_height(s);
>> ?
>
> Changed the last line to:
> pic_param->num_gobs_in_vop = (s->mb_width * s->mb_height) / 
> pic_param->num_macroblocks_in_gob;
> which should be more abvious than the previous "simplification".
>
> Only tested with 352x288 clips, did not find any larger ones.

ffmpeg can create larger ones, also ffmpeg can make mpeg4 asp
you also should find some after running the regression tests


[...]
> +/** Reconstruct bitstream intra_dc_vlc_thr */
> +static int mpeg4_get_intra_dc_vlc_thr(MpegEncContext *s)
> +{
> +    int v = 0;
> +    switch (s->intra_dc_threshold) {
> +    case 99: v = 0; break;
> +    case 13: v = 1; break;
> +    case 15: v = 2; break;
> +    case 17: v = 3; break;
> +    case 19: v = 4; break;
> +    case 21: v = 5; break;
> +    case 23: v = 6; break;
> +    case 0:  v = 7; break;
> +    }
> +    return v;
> +}

s/v=X;break/return X/


> +
> +static int vaapi_mpeg4_start_frame(AVCodecContext *avctx, av_unused const uint8_t *buffer, av_unused uint32_t size)
> +{
> +    MpegEncContext * const s = avctx->priv_data;
> +    struct vaapi_context * const vactx = avctx->hwaccel_context;
> +    VAPictureParameterBufferMPEG4 *pic_param;
> +    VAIQMatrixBufferMPEG4 *iq_matrix;
> +    int i;
> +
> +    dprintf(avctx, "vaapi_mpeg4_start_frame()\n");
> +
> +    vactx->slice_param_size = sizeof(VASliceParameterBufferMPEG4);
> +
> +    /* Fill in VAPictureParameterBufferMPEG4 */
> +    pic_param = ff_vaapi_alloc_picture(vactx, sizeof(VAPictureParameterBufferMPEG4));
> +    if (!pic_param)
> +        return -1;
> +    pic_param->vop_width                                = s->width;
> +    pic_param->vop_height                               = s->height;
> +    pic_param->forward_reference_picture                = 0xffffffff;
> +    pic_param->backward_reference_picture               = 0xffffffff;
> +    pic_param->vol_fields.value                         = 0; /* reset all bits */
> +    pic_param->vol_fields.bits.short_video_header       = avctx->codec->id == CODEC_ID_H263;
> +    pic_param->vol_fields.bits.chroma_format            = CHROMA_420;
> +    pic_param->vol_fields.bits.interlaced               = !s->progressive_sequence;
> +    pic_param->vol_fields.bits.obmc_disable             = 1;
> +    pic_param->vol_fields.bits.sprite_enable            = s->vol_sprite_usage;
> +    pic_param->vol_fields.bits.sprite_warping_accuracy  = s->sprite_warping_accuracy;
> +    pic_param->vol_fields.bits.quant_type               = s->mpeg_quant;
> +    pic_param->vol_fields.bits.quarter_sample           = s->quarter_sample;
> +    pic_param->vol_fields.bits.data_partitioned         = s->data_partitioning;
> +    pic_param->vol_fields.bits.reversible_vlc           = s->rvlc;
> +    pic_param->no_of_sprite_warping_points              = s->num_sprite_warping_points;
> +    for (i = 0; i < s->num_sprite_warping_points && i < 3; i++) {
> +        pic_param->sprite_trajectory_du[i]              = s->sprite_traj[i][0];
> +        pic_param->sprite_trajectory_dv[i]              = s->sprite_traj[i][1];
> +    }
> +    pic_param->quant_precision                          = s->quant_precision;
> +    pic_param->vop_fields.value                         = 0; /* reset all bits */
> +    pic_param->vop_fields.bits.vop_coding_type          = s->pict_type - FF_I_TYPE;
> +    pic_param->vop_fields.bits.backward_reference_vop_coding_type = s->pict_type == FF_B_TYPE ? s->next_picture.pict_type - FF_I_TYPE : 0;
> +    pic_param->vop_fields.bits.vop_rounding_type        = s->no_rounding;
> +    pic_param->vop_fields.bits.intra_dc_vlc_thr         = mpeg4_get_intra_dc_vlc_thr(s);
> +    pic_param->vop_fields.bits.top_field_first          = s->top_field_first;
> +    pic_param->vop_fields.bits.alternate_vertical_scan_flag = s->alternate_scan;
> +    pic_param->vop_fcode_forward                        = s->f_code;
> +    pic_param->vop_fcode_backward                       = s->b_code;
> +    pic_param->num_macroblocks_in_gob                   = s->mb_width * ff_h263_get_gob_height(s);
> +    pic_param->num_gobs_in_vop                          = (s->mb_width * s->mb_height) / pic_param->num_macroblocks_in_gob;
> +    pic_param->TRB                                      = s->picture_structure != PICT_FRAME ? s->pb_field_time : s->pb_time;
> +    pic_param->TRD                                      = s->picture_structure != PICT_FRAME ? s->pp_field_time : s->pp_time;

s->picture_structure == PICT_FRAME, always for mpeg4


[...]
-- 
Michael     GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

In a rich man's house there is no place to spit but his face.
-- Diogenes of Sinope
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: Digital signature
URL: <http://lists.mplayerhq.hu/pipermail/ffmpeg-devel/attachments/20090331/46e4db55/attachment.pgp>



More information about the ffmpeg-devel mailing list