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

📄 mpg_gethdr.c

📁 瑞星微公司RK27XX系列芯片的SDK开发包
💻 C
📖 第 1 页 / 共 3 页
字号:
                case SEQUENCE_EXTENSION_ID:
                    sequence_extension();
                    break;
                case SEQUENCE_DISPLAY_EXTENSION_ID:
                    sequence_display_extension();
                    break;
                case QUANT_MATRIX_EXTENSION_ID:
                    quant_matrix_extension();
                    break;
                case SEQUENCE_SCALABLE_EXTENSION_ID:
                    sequence_scalable_extension();
                    break;
                case PICTURE_DISPLAY_EXTENSION_ID:
                    picture_display_extension();
                    break;
                case PICTURE_CODING_EXTENSION_ID:
                    picture_coding_extension();
                    break;
                case PICTURE_SPATIAL_SCALABLE_EXTENSION_ID:
                    picture_spatial_scalable_extension();
                    break;
                case PICTURE_TEMPORAL_SCALABLE_EXTENSION_ID:
                    picture_temporal_scalable_extension();
                    break;
                case COPYRIGHT_EXTENSION_ID:
                    copyright_extension();
                    break;
                default:
                    //fprintf(stderr,"reserved extension start code ID %d\n",ext_ID);
                    break;
            }
            next_start_code(ld);
        }
        else
        {
#ifdef VERBOSE
            if (Verbose_Flag > NO_LAYER)
                printf("user data\n");
#endif /* VERBOSE */
            Flush_Buffer32(ld);
            user_data();
        }
    }
}


/* decode sequence extension */

/* ISO/IEC 13818-2 section 6.2.2.3 */
static void sequence_extension()
{
    int horizontal_size_extension;
    int vertical_size_extension;
    int bit_rate_extension;
    int vbv_buffer_size_extension;

    int profile_and_level_indication;
    //int progressive_sequence;
    //int chroma_format;
    int low_delay;
    int frame_rate_extension_n;
    int frame_rate_extension_d;

    /* derive bit position for trace */
#ifdef VERBOSE
    pos = ld->Bitcnt;
#endif

    ld->MPEG2_Flag = 1;

    ld->scalable_mode = SC_NONE; /* unless overwritten by sequence_scalable_extension() */
    //layer_id = 0;                /* unless overwritten by sequence_scalable_extension() */

    profile_and_level_indication = Get_Bits(ld, 8);
    progressive_sequence         = Get_Bits(ld, 1);
    chroma_format                = Get_Bits(ld, 2);
    horizontal_size_extension    = Get_Bits(ld, 2);
    vertical_size_extension      = Get_Bits(ld, 2);
    bit_rate_extension           = Get_Bits(ld, 12);
    marker_bit(ld, "sequence_extension");
    vbv_buffer_size_extension    = Get_Bits(ld, 8);
    low_delay                    = Get_Bits(ld, 1);
    frame_rate_extension_n       = Get_Bits(ld, 2);
    frame_rate_extension_d       = Get_Bits(ld, 5);

    mpeg.frameRate = mpeg_frame_rate_Table[mpeg_frame_rate_code] *
                     ((frame_rate_extension_n + 1) / (frame_rate_extension_d + 1));

    /* special case for 422 profile & level must be made */
    if ((profile_and_level_indication >> 7) & 1)
    {  /* escape bit of profile_and_level_indication set */

        /* 4:2:2 Profile @ Main Level */
        if ((profile_and_level_indication&15) == 5)
        {
            profile = PROFILE_422;
            level   = MAIN_LEVEL;
        }
    }
    else
    {
        profile = profile_and_level_indication >> 4;  /* Profile is upper nibble */
        level   = profile_and_level_indication & 0xF;  /* Level is lower nibble */
    }


    horizontal_size = (horizontal_size_extension << 12) | (horizontal_size & 0x0fff);
    vertical_size = (vertical_size_extension << 12) | (vertical_size & 0x0fff);


    /* ISO/IEC 13818-2 does not define bit_rate_value to be composed of
     * both the original bit_rate_value parsed in sequence_header() and
     * the optional bit_rate_extension in sequence_extension_header().
     * However, we use it for bitstream verification purposes.
     */

    bit_rate_value += (bit_rate_extension << 18);
    mpeg_bit_rate = ((double) bit_rate_value) * 400.0;
    vbv_buffer_size += (vbv_buffer_size_extension << 10);

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

        if (Verbose_Flag > SEQUENCE_LAYER)
        {
            printf("  profile_and_level_indication=%d\n", profile_and_level_indication);

            if (profile_and_level_indication < 128)
            {
                printf("    profile=%d, level=%d\n", profile, level);
            }

            printf("  progressive_sequence=%d\n", progressive_sequence);
            printf("  chroma_format=%d\n", chroma_format);
            printf("  horizontal_size_extension=%d\n", horizontal_size_extension);
            printf("  vertical_size_extension=%d\n", vertical_size_extension);
            printf("  bit_rate_extension=%d\n", bit_rate_extension);
            printf("  vbv_buffer_size_extension=%d\n", vbv_buffer_size_extension);
            printf("  low_delay=%d\n", low_delay);
            printf("  frame_rate_extension_n=%d\n", frame_rate_extension_n);
            printf("  frame_rate_extension_d=%d\n", frame_rate_extension_d);
        }
    }
#endif /* VERBOSE */

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


}


/* decode sequence display extension */

static void sequence_display_extension()
{
    int pos;

    int video_format;
    int color_description;
    int color_primaries;
    int transfer_characteristics;
    int matrix_coefficients;
    int display_horizontal_size;
    int display_vertical_size;

    pos = ld->Bitcnt;
    video_format      = Get_Bits(ld, 3);
    color_description = Get_Bits(ld, 1);

    if (color_description)
    {
        color_primaries          = Get_Bits(ld, 8);
        transfer_characteristics = Get_Bits(ld, 8);
        matrix_coefficients      = Get_Bits(ld, 8);
    }

    display_horizontal_size = Get_Bits(ld, 14);
    marker_bit(ld, "sequence_display_extension");
    display_vertical_size   = Get_Bits(ld, 14);

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

            printf("  video_format=%d\n", video_format);
            printf("  color_description=%d\n", color_description);

            if (color_description)
            {
                printf("    color_primaries=%d\n", color_primaries);
                printf("    transfer_characteristics=%d\n", transfer_characteristics);
                printf("    matrix_coefficients=%d\n", matrix_coefficients);
            }
            printf("  display_horizontal_size=%d\n", display_horizontal_size);
            printf("  display_vertical_size=%d\n", display_vertical_size);
        }
    }
#endif /* VERBOSE */

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

}


/* decode quant matrix entension */
/* ISO/IEC 13818-2 section 6.2.3.2 */
static void quant_matrix_extension()
{
    int i;
    int pos;

    pos = ld->Bitcnt;

    if ((/*ld->load_intra_quantizer_matrix = */Get_Bits(ld, 1)))
    {
        for (i = 0; i < 64; i++)
        {
            Get_Bits(ld, 8);
        }
    }

    if ((/*ld->load_non_intra_quantizer_matrix = */Get_Bits(ld, 1)))
    {
        for (i = 0; i < 64; i++)
        {
            Get_Bits(ld, 8);
        }
    }

    if ((/*ld->load_chroma_intra_quantizer_matrix = */Get_Bits(ld, 1)))
    {
        for (i = 0; i < 64; i++)
            Get_Bits(ld, 8);
    }

    if ((/*ld->load_chroma_non_intra_quantizer_matrix = */Get_Bits(ld, 1)))
    {
        for (i = 0; i < 64; i++)
            Get_Bits(ld, 8);
    }

#ifdef VERBOSE
    if (Verbose_Flag > NO_LAYER)
    {
        printf("quant matrix extension (byte %d)\n", (pos >> 3) - 4);
        printf("  load_intra_quantizer_matrix=%d\n",
               ld->load_intra_quantizer_matrix);
        printf("  load_non_intra_quantizer_matrix=%d\n",
               ld->load_non_intra_quantizer_matrix);
        printf("  load_chroma_intra_quantizer_matrix=%d\n",
               ld->load_chroma_intra_quantizer_matrix);
        printf("  load_chroma_non_intra_quantizer_matrix=%d\n",
               ld->load_chroma_non_intra_quantizer_matrix);
    }
#endif /* VERBOSE */

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

}


/* decode sequence scalable extension */
/* ISO/IEC 13818-2   section 6.2.2.5 */
static void sequence_scalable_extension()
{
    int pos;

    int layer_id;
    int lower_layer_prediction_horizontal_size;
    int lower_layer_prediction_vertical_size;
    int horizontal_subsampling_factor_m;
    int horizontal_subsampling_factor_n;
    int vertical_subsampling_factor_m;
    int vertical_subsampling_factor_n;

    pos = ld->Bitcnt;

    /* values (without the +1 offset) of scalable_mode are defined in
       Table 6-10 of ISO/IEC 13818-2 */
    ld->scalable_mode = Get_Bits(ld, 2) + 1; /* add 1 to make SC_DP != SC_NONE */

#ifndef SCALABLE
    ld->scalable_mode = SC_NONE;
#endif

    layer_id = Get_Bits(ld, 4);

    if (ld->scalable_mode == SC_SPAT)
    {
        lower_layer_prediction_horizontal_size = Get_Bits(ld, 14);
        marker_bit(ld, "sequence_scalable_extension()");
        lower_layer_prediction_vertical_size   = Get_Bits(ld, 14);
        horizontal_subsampling_factor_m        = Get_Bits(ld, 5);
        horizontal_subsampling_factor_n        = Get_Bits(ld, 5);
        vertical_subsampling_factor_m          = Get_Bits(ld, 5);
        vertical_subsampling_factor_n          = Get_Bits(ld, 5);
    }

    if (ld->scalable_mode == SC_TEMP)
        Error(/*"temporal scalability not implemented\n"*/);

#ifdef VERBOSE
    if (Verbose_Flag > NO_LAYER)
    {
        printf("sequence scalable extension (byte %d)\n", (pos >> 3) - 4);
        if (Verbose_Flag > SEQUENCE_LAYER)
        {
            printf("  scalable_mode=%d\n", ld->scalable_mode - 1);
            printf("  layer_id=%d\n", layer_id);
            if (ld->scalable_mode == SC_SPAT)
            {
                printf("    lower_layer_prediction_horiontal_size=%d\n",
                       lower_layer_prediction_horizontal_size);
                printf("    lower_layer_prediction_vertical_size=%d\n",
                       lower_layer_prediction_vertical_size);
                printf("    horizontal_subsampling_factor_m=%d\n",
                       horizontal_subsampling_factor_m);
                printf("    horizontal_subsampling_factor_n=%d\n",
                       horizontal_subsampling_factor_n);
                printf("    vertical_subsampling_factor_m=%d\n",
                       vertical_subsampling_factor_m);
                printf("    vertical_subsampling_factor_n=%d\n",
                       vertical_subsampling_factor_n);
            }
        }
    }
#endif /* VERBOSE */

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

}


/* decode picture display extension */
/* ISO/IEC 13818-2 section 6.2.3.3. */
static void picture_display_extension()
{
    int i;
    int number_of_frame_center_offsets;
    int pos;

    int frame_center_horizontal_offset[3];
    int frame_center_vertical_offset[3];

    pos = ld->Bitcnt;
    /* based on ISO/IEC 13818-2 section 6.3.12
      (November 1994) Picture display extensions */

    /* derive number_of_frame_center_offsets */
    if (progressive_sequence)
    {
        if (repeat_first_field)
        {
            if (top_field_first)
                number_of_frame_center_offsets = 3;

⌨️ 快捷键说明

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