⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mpg_gethdr.c

📁 瑞星微公司RK27XX系列芯片的SDK开发包
💻 C
📖 第 1 页 / 共 3 页
字号:
            else
                number_of_frame_center_offsets = 2;
        }
        else
        {
            number_of_frame_center_offsets = 1;
        }
    }
    else
    {
        if (picture_structure != FRAME_PICTURE)
        {
            number_of_frame_center_offsets = 1;
        }
        else
        {
            if (repeat_first_field)
                number_of_frame_center_offsets = 3;
            else
                number_of_frame_center_offsets = 2;
        }
    }


    /* now parse */
    for (i = 0; i < number_of_frame_center_offsets; i++)
    {
        frame_center_horizontal_offset[i] = Get_Bits(ld, 16);
        marker_bit(ld, "picture_display_extension, first marker bit");

        frame_center_vertical_offset[i]   = Get_Bits(ld, 16);
        marker_bit(ld, "picture_display_extension, second marker bit");
    }

#ifdef VERBOSE
    if (Verbose_Flag > NO_LAYER)
    {
        printf("picture display extension (byte %d)\n", (pos >> 3) - 4);
        if (Verbose_Flag > SEQUENCE_LAYER)
        {

            for (i = 0; i < number_of_frame_center_offsets; i++)
            {
                printf("  frame_center_horizontal_offset[%d]=%d\n", i,
                       frame_center_horizontal_offset[i]);
                printf("  frame_center_vertical_offset[%d]=%d\n", i,
                       frame_center_vertical_offset[i]);
            }
        }
    }
#endif /* VERBOSE */

#ifdef VERIFY
    verify_picture_display_extension++;
#endif /* VERIFY */

}


/* decode picture coding extension */
static void picture_coding_extension()
{
    int pos;

    int f_code[2][2];
    int intra_dc_precision;
    //int picture_structure;
    //int top_field_first;
    int frame_pred_frame_dct;
    int concealment_motion_vectors;

    int intra_vlc_format;

    //int repeat_first_field;

    int chroma_420_type;
    int progressive_frame;
    int composite_display_flag;
    int v_axis;
    int field_sequence;
    int sub_carrier;
    int burst_amplitude;
    int sub_carrier_phase;

    pos = ld->Bitcnt;

    f_code[0][0] = Get_Bits(ld, 4);
    f_code[0][1] = Get_Bits(ld, 4);
    f_code[1][0] = Get_Bits(ld, 4);
    f_code[1][1] = Get_Bits(ld, 4);

    intra_dc_precision         = Get_Bits(ld, 2);
    picture_structure          = Get_Bits(ld, 2);
    top_field_first            = Get_Bits(ld, 1);
    frame_pred_frame_dct       = Get_Bits(ld, 1);
    concealment_motion_vectors = Get_Bits(ld, 1);
    ld->q_scale_type           = Get_Bits(ld, 1);
    intra_vlc_format           = Get_Bits(ld, 1);
    ld->alternate_scan         = Get_Bits(ld, 1);
    repeat_first_field         = Get_Bits(ld, 1);
    chroma_420_type            = Get_Bits(ld, 1);
    progressive_frame          = Get_Bits(ld, 1);
    composite_display_flag     = Get_Bits(ld, 1);

    if (composite_display_flag)
    {
        v_axis            = Get_Bits(ld, 1);
        field_sequence    = Get_Bits(ld, 3);
        sub_carrier       = Get_Bits(ld, 1);
        burst_amplitude   = Get_Bits(ld, 7);
        sub_carrier_phase = Get_Bits(ld, 8);
    }

#ifdef VERBOSE
    if (Verbose_Flag > NO_LAYER)
    {
        printf("picture coding extension (byte %d)\n", (pos >> 3) - 4);
        if (Verbose_Flag > SEQUENCE_LAYER)
        {
            printf("  forward horizontal f_code=%d\n", f_code[0][0]);
            printf("  forward vertical f_code=%d\n", f_code[0][1]);
            printf("  backward horizontal f_code=%d\n", f_code[1][0]);
            printf("  backward_vertical f_code=%d\n", f_code[1][1]);
            printf("  intra_dc_precision=%d\n", intra_dc_precision);
            printf("  picture_structure=%d\n", picture_structure);
            printf("  top_field_first=%d\n", top_field_first);
            printf("  frame_pred_frame_dct=%d\n", frame_pred_frame_dct);
            printf("  concealment_motion_vectors=%d\n", concealment_motion_vectors);
            printf("  q_scale_type=%d\n", ld->q_scale_type);
            printf("  intra_vlc_format=%d\n", intra_vlc_format);
            printf("  alternate_scan=%d\n", ld->alternate_scan);
            printf("  repeat_first_field=%d\n", repeat_first_field);
            printf("  chroma_420_type=%d\n", chroma_420_type);
            printf("  progressive_frame=%d\n", progressive_frame);
            printf("  composite_display_flag=%d\n", composite_display_flag);

            if (composite_display_flag)
            {
                printf("    v_axis=%d\n", v_axis);
                printf("    field_sequence=%d\n", field_sequence);
                printf("    sub_carrier=%d\n", sub_carrier);
                printf("    burst_amplitude=%d\n", burst_amplitude);
                printf("    sub_carrier_phase=%d\n", sub_carrier_phase);
            }
        }
    }
#endif /* VERBOSE */

#ifdef VERIFY
    verify_picture_coding_extension++;
#endif /* VERIFY */
}


/* decode picture spatial scalable extension */
/* ISO/IEC 13818-2 section 6.2.3.5. */
static void picture_spatial_scalable_extension()
{
#ifdef SCALABLE
    int pos;

    int lower_layer_temporal_reference;
    int lower_layer_horizontal_offset;
    int lower_layer_vertical_offset;
    int spatial_temporal_weight_code_table_index;
    int lower_layer_progressive_frame;
    int lower_layer_deinterlaced_field_select;

    pos = ld->Bitcnt;

    ld->pict_scal = 1; /* use spatial scalability in this picture */

    lower_layer_temporal_reference = Get_Bits(ld, 10);
    marker_bit(ld, "picture_spatial_scalable_extension(), first marker bit");
    lower_layer_horizontal_offset = Get_Bits(ld, 15);
    if (lower_layer_horizontal_offset >= 16384)
        lower_layer_horizontal_offset -= 32768;
    marker_bit(ld, "picture_spatial_scalable_extension(), second marker bit");
    lower_layer_vertical_offset = Get_Bits(ld, 15);
    if (lower_layer_vertical_offset >= 16384)
        lower_layer_vertical_offset -= 32768;
    spatial_temporal_weight_code_table_index = Get_Bits(ld, 2);
    lower_layer_progressive_frame = Get_Bits(ld, 1);
    lower_layer_deinterlaced_field_select = Get_Bits(ld, 1);

#ifdef VERBOSE
    if (Verbose_Flag > NO_LAYER)
    {
        printf("picture spatial scalable extension (byte %d)\n", (pos >> 3) - 4);
        if (Verbose_Flag > SEQUENCE_LAYER)
        {
            printf("  lower_layer_temporal_reference=%d\n", lower_layer_temporal_reference);
            printf("  lower_layer_horizontal_offset=%d\n", lower_layer_horizontal_offset);
            printf("  lower_layer_vertical_offset=%d\n", lower_layer_vertical_offset);
            printf("  spatial_temporal_weight_code_table_index=%d\n",
                   spatial_temporal_weight_code_table_index);
            printf("  lower_layer_progressive_frame=%d\n", lower_layer_progressive_frame);
            printf("  lower_layer_deinterlaced_field_select=%d\n", lower_layer_deinterlaced_field_select);
        }
    }
#endif /* VERBOSE */

#ifdef VERIFY
    verify_picture_spatial_scalable_extension++;
#endif /* VERIFY */

#endif /* SCALABLE */

}


/* decode picture temporal scalable extension
 *
 * not implemented
 */
/* ISO/IEC 13818-2 section 6.2.3.4. */
static void picture_temporal_scalable_extension()
{
    Error(/*"temporal scalability not supported\n"*/);

#ifdef VERIFY
    verify_picture_temporal_scalable_extension++;
#endif /* VERIFY */
}


/* decode extra bit information */
/* ISO/IEC 13818-2 section 6.2.3.4. */
static int extra_bit_information()
{
    int Byte_Count = 0;

    while (Get_Bits1(ld))
    {
        Flush_Buffer(ld, 8);
        Byte_Count++;
    }

    return(Byte_Count);
}



/* ISO/IEC 13818-2 section 5.3 */
/* Purpose: this function is mainly designed to aid in bitstream conformance
   testing.  A simple Flush_Buffer(1) would do */
void marker_bit(layer_data *laydat, char *text)
{
    int marker;

    marker = Get_Bits(laydat, 1);

#ifdef VERIFY
    if (!marker)
        printf("ERROR: %s--marker_bit set to 0", text);
#endif
}


/* ISO/IEC 13818-2  sections 6.3.4.1 and 6.2.2.2.2 */
static void user_data()
{
    /* skip ahead to the next start code */
    next_start_code(ld);
}



/* Copyright extension */
/* ISO/IEC 13818-2 section 6.2.3.6. */
/* (header added in November, 1994 to the IS document) */


static void copyright_extension()
{
    int pos;
    int reserved_data;

    int copyright_flag;
    int copyright_identifier;
    int original_or_copy;
    int copyright_number_1;
    int copyright_number_2;
    int copyright_number_3;

    pos = ld->Bitcnt;


    copyright_flag =       Get_Bits(ld, 1);
    copyright_identifier = Get_Bits(ld, 8);
    original_or_copy =     Get_Bits(ld, 1);

    /* reserved */
    reserved_data = Get_Bits(ld, 7);

    marker_bit(ld, "copyright_extension(), first marker bit");
    copyright_number_1 =   Get_Bits(ld, 20);
    marker_bit(ld, "copyright_extension(), second marker bit");
    copyright_number_2 =   Get_Bits(ld, 22);
    marker_bit(ld, "copyright_extension(), third marker bit");
    copyright_number_3 =   Get_Bits(ld, 22);

#ifdef VERIFY
    if (Verbose_Flag > NO_LAYER)
    {
        printf("copyright_extension (byte %d)\n", (pos >> 3) - 4);
        if (Verbose_Flag > SEQUENCE_LAYER)
        {
            printf("  copyright_flag =%d\n", copyright_flag);

            printf("  copyright_identifier=%d\n", copyright_identifier);

            printf("  original_or_copy = %d (original=1, copy=0)\n",
                   original_or_copy);

            printf("  copyright_number_1=%d\n", copyright_number_1);
            printf("  copyright_number_2=%d\n", copyright_number_2);
            printf("  copyright_number_3=%d\n", copyright_number_3);
        }
    }

    verify_copyright_extension++;
#endif /* VERIFY */
}


#if 0
/* introduced in September 1995 to assist Spatial Scalability */
static void Update_Temporal_Reference_Tacking_Data()
{
    static int temporal_reference_wrap  = 0;
    static int temporal_reference_old   = 0;

    if (ld == &base)   /* *CH* */
    {
        if (picture_coding_type != B_TYPE && temporal_reference != temporal_reference_old)
            /* check first field of */
        {
            /* non-B-frame */
            if (temporal_reference_wrap)
            {/* wrap occured at previous I- or P-frame */
                /* now all intervening B-frames which could
                   still have high temporal_reference values are done  */
                Temporal_Reference_Base += 1024;
                temporal_reference_wrap = 0;
            }

            /* distinguish from a reset */
            if (temporal_reference < temporal_reference_old && !Temporal_Reference_GOP_Reset)
                temporal_reference_wrap = 1;  /* we must have just passed a GOP-Header! */

            temporal_reference_old = temporal_reference;
            Temporal_Reference_GOP_Reset = 0;
        }

        True_Framenum = Temporal_Reference_Base + temporal_reference;

        /* temporary wrap of TR at 1024 for M frames */
        if (temporal_reference_wrap && temporal_reference <= temporal_reference_old)
            True_Framenum += 1024;

        True_Framenum_max = (True_Framenum > True_Framenum_max) ?
                            True_Framenum : True_Framenum_max;
    }
}
#endif

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -