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

📄 mp4parse.c

📁 这是在PCA下的基于IPP库示例代码例子,在网上下了IPP的库之后,设置相关参数就可以编译该代码.
💻 C
📖 第 1 页 / 共 3 页
字号:
/* ///////////////////////////////////////////////////////////////////////////               INTEL CORPORATION PROPRIETARY INFORMATION//  This software is supplied under the terms of a license agreement or//  nondisclosure agreement with Intel Corporation and may not be copied//  or disclosed except in accordance with the terms of that agreement.//        Copyright (c) 2001-2005 Intel Corporation. All Rights Reserved.////  Description:    Parses MPEG-4 headers//*/#include "mp4.h"mp4_Status mp4_Parse_VisualObject(mp4_Info* pInfo){    mp4_VisualObject  *VO = &pInfo->VisualObject;    VO->is_identifier = mp4_GetBit(pInfo);    if (VO->is_identifier) {        VO->verid = mp4_GetBits9(pInfo, 4);        VO->priority = mp4_GetBits9(pInfo, 3);    } else        VO->verid = 1;    VO->type = mp4_GetBits9(pInfo, 4);    if (VO->type != MP4_VISUAL_OBJECT_TYPE_VIDEO) {        mp4_Error("Error: Unsupported object: visual_object_type != video ID");        return MP4_STATUS_NOTSUPPORT;    }    VO->VideoSignalType.video_range = 0;    VO->VideoSignalType.matrix_coefficients = MP4_VIDEO_COLORS_ITU_R_BT_709;    if (VO->type == MP4_VISUAL_OBJECT_TYPE_VIDEO || VO->type == MP4_VISUAL_OBJECT_TYPE_TEXTURE) {        VO->VideoSignalType.is_video_signal_type = mp4_GetBit(pInfo);        if (VO->VideoSignalType.is_video_signal_type) {            VO->VideoSignalType.video_format = mp4_GetBits9(pInfo, 3);            VO->VideoSignalType.video_range = mp4_GetBit(pInfo);            VO->VideoSignalType.is_colour_description = mp4_GetBit(pInfo);            if (VO->VideoSignalType.is_colour_description) {                VO->VideoSignalType.colour_primaries = mp4_GetBits9(pInfo, 8);                VO->VideoSignalType.transfer_characteristics = mp4_GetBits9(pInfo, 8);                VO->VideoSignalType.matrix_coefficients = mp4_GetBits9(pInfo, 8);            }        }    }    return MP4_STATUS_OK;}static mp4_Status mp4_Parse_QuantMatrix(mp4_Info* pInfo, Ipp8u pQM[64]){    Ipp32u  code;    int     i;    for (i = 0; i < 64; i ++) {        code = mp4_GetBits9(pInfo, 8);        if (code == 0) break;            pQM[mp4_ClassicalZigzag[i]] = (Ipp8u)code;    }    code = pQM[mp4_ClassicalZigzag[i-1]];    for (; i < 64; i ++) {        pQM[mp4_ClassicalZigzag[i]] = (Ipp8u)code;    }    return MP4_STATUS_OK;}mp4_Status mp4_Parse_VideoObject(mp4_Info* pInfo){    Ipp32u  code;    int     i;    mp4_VisualObject  *VO = &pInfo->VisualObject;    mp4_VideoObject  *VOL = &pInfo->VisualObject.VideoObject;    code = mp4_ShowBits(pInfo, 32);    // check short_video_start_marker    if ((code & (~0x3FF)) == 0x8000) {        VOL->short_video_header = 1;        VOL->quant_precision = 5;        VOL->shape = MP4_SHAPE_TYPE_RECTANGULAR;        VOL->obmc_disable = 1;        VOL->quant_type = 0;        VOL->resync_marker_disable = 1;        VOL->data_partitioned = 0;        VOL->reversible_vlc = 0;        VOL->VideoObjectPlane.rounding_type = 0;        VOL->VideoObjectPlane.fcode_forward = 1;        VOL->VideoObjectPlane.coded = 1;        VOL->interlaced = 0;        VOL->complexity_estimation_disable = 1;        VOL->scalability = 0;        VOL->not_8_bit = 0;        VOL->bits_per_pixel = 8;        VO->VideoSignalType.colour_primaries = 1;        VO->VideoSignalType.transfer_characteristics = 1;        VO->VideoSignalType.matrix_coefficients = 6;        VO->VideoObject.VideoObjectPlaneH263.source_format = (pInfo->bufptr[4] >> 2) & 0x7;        i = VO->VideoObject.VideoObjectPlaneH263.source_format - 1;        if (i < 0 || i > 4) {            mp4_Error("Error: Bad value for VideoPlaneWithShortHeader.source_format");            return MP4_STATUS_PARSE_ERROR;        }        VOL->width = mp4_H263_width[i];        VOL->height = mp4_H263_height[i];        VOL->VideoObjectPlaneH263.num_gobs_in_vop = mp4_H263_gobvop[i];        VOL->VideoObjectPlaneH263.num_macroblocks_in_gob = mp4_H263_mbgob[i];        VOL->vop_time_increment_resolution = 30000;        // VOL->VideoObjectPlane.time_increment = -1001;        return MP4_STATUS_OK;    }    if (code < 256 + MP4_VIDEO_OBJECT_LAYER_MIN_SC || code > 256 + MP4_VIDEO_OBJECT_LAYER_MAX_SC) {        mp4_Error("Error: Bad start code for VideoObjectLayer");        return MP4_STATUS_PARSE_ERROR;    }    mp4_FlushBits(pInfo, 32);    // video_object_start_code is founded    VOL->id = code & 15;    VOL->short_video_header = 0;    VOL->random_accessible_vol = mp4_GetBit(pInfo);    VOL->type_indication = mp4_GetBits9(pInfo, 8);    if (VOL->type_indication != MP4_VIDEO_OBJECT_TYPE_SIMPLE &&        VOL->type_indication != MP4_VIDEO_OBJECT_TYPE_CORE &&        VOL->type_indication != MP4_VIDEO_OBJECT_TYPE_MAIN &&        VOL->type_indication != MP4_VIDEO_OBJECT_TYPE_ADVANCED_REAL_TIME_SIMPLE &&        VOL->type_indication != MP4_VIDEO_OBJECT_TYPE_ADVANCED_CODING_EFFICIENCY &&        VOL->type_indication != MP4_VIDEO_OBJECT_TYPE_ADVANCED_SIMPLE) {//f        mp4_Error("Error: Unsupported video_object");//f        return MP4_STATUS_NOTSUPPORT;    }    VOL->is_identifier = mp4_GetBit(pInfo);    if (VOL->is_identifier) {        VOL->verid = mp4_GetBits9(pInfo, 4);        VOL->priority = mp4_GetBits9(pInfo, 3);    } else        VOL->verid = 1;    VOL->aspect_ratio_info = mp4_GetBits9(pInfo, 4);    if (VOL->aspect_ratio_info == MP4_ASPECT_RATIO_EXTPAR) {        VOL->aspect_ratio_info_par_width = mp4_GetBits9(pInfo, 8);        VOL->aspect_ratio_info_par_height = mp4_GetBits9(pInfo, 8);    }    VOL->is_vol_control_parameters = mp4_GetBit(pInfo);    if (VOL->is_vol_control_parameters) {        VOL->VOLControlParameters.chroma_format = mp4_GetBits9(pInfo, 2);        if (VOL->VOLControlParameters.chroma_format != MP4_CHROMA_FORMAT_420) {            mp4_Error("Error: vol_control_parameters.chroma_format != 4:2:0");            return MP4_STATUS_PARSE_ERROR;        }        VOL->VOLControlParameters.low_delay = mp4_GetBit(pInfo);        VOL->VOLControlParameters.vbv_parameters = mp4_GetBit(pInfo);        if (VOL->VOLControlParameters.vbv_parameters) {            VOL->VOLControlParameters.bit_rate = mp4_GetBits(pInfo, 15) << 15;            if (!mp4_GetMarkerBit(pInfo)) return MP4_STATUS_PARSE_ERROR;            VOL->VOLControlParameters.bit_rate += mp4_GetBits(pInfo, 15);            if (!mp4_GetMarkerBit(pInfo)) return MP4_STATUS_PARSE_ERROR;            if (VOL->VOLControlParameters.bit_rate == 0) {                mp4_Error("Error: vbv_parameters bit_rate == 0");                return MP4_STATUS_PARSE_ERROR;            }            VOL->VOLControlParameters.vbv_buffer_size = mp4_GetBits(pInfo, 15) << 3;            if (!mp4_GetMarkerBit(pInfo)) return MP4_STATUS_PARSE_ERROR;            VOL->VOLControlParameters.vbv_buffer_size += mp4_GetBits9(pInfo, 3);            if (VOL->VOLControlParameters.vbv_buffer_size == 0) {                mp4_Error("Error: vbv_parameters vbv_buffer_size == 0");                return MP4_STATUS_PARSE_ERROR;            }            VOL->VOLControlParameters.vbv_occupancy = mp4_GetBits(pInfo, 11) << 15;            if (!mp4_GetMarkerBit(pInfo)) return MP4_STATUS_PARSE_ERROR;            VOL->VOLControlParameters.vbv_occupancy += mp4_GetBits(pInfo, 15);            if (!mp4_GetMarkerBit(pInfo)) return MP4_STATUS_PARSE_ERROR;        }    }    VOL->shape = mp4_GetBits9(pInfo, 2);    if (VOL->shape != MP4_SHAPE_TYPE_RECTANGULAR) {        mp4_Error("Error: video_object_layer_shape != rectangular (not supported)");        return MP4_STATUS_PARSE_ERROR;    }    if (VOL->verid != 1 && VOL->shape == MP4_SHAPE_TYPE_GRAYSCALE) {        VOL->shape_extension = mp4_GetBits9(pInfo, 4);        if (VOL->shape_extension >= MP4_SHAPE_EXT_NUM) {            mp4_Error("Error: wrong value for video_object_layer_shape_extension");            return MP4_STATUS_PARSE_ERROR;        }    } else        VOL->shape_extension = MP4_SHAPE_EXT_NUM;    if (!mp4_GetMarkerBit(pInfo)) return MP4_STATUS_PARSE_ERROR;    VOL->vop_time_increment_resolution = mp4_GetBits(pInfo, 16);    if (VOL->vop_time_increment_resolution == 0) {        mp4_Error("Error: wrong value for vop_time_increment_resolution");        return MP4_STATUS_PARSE_ERROR;    }    if (!mp4_GetMarkerBit(pInfo)) return MP4_STATUS_PARSE_ERROR;    // define number bits in vop_time_increment_resolution    code = VOL->vop_time_increment_resolution - 1;    i = 0;    do {        code >>= 1;        i ++;    } while (code);    VOL->vop_time_increment_resolution_bits = i;    VOL->fixed_vop_rate = mp4_GetBit(pInfo);    if (VOL->fixed_vop_rate) {        VOL->fixed_vop_time_increment = mp4_GetBits(pInfo, VOL->vop_time_increment_resolution_bits);    }    if (VOL->shape != MP4_SHAPE_TYPE_BINARYONLY) {        if (VOL->shape == MP4_SHAPE_TYPE_RECTANGULAR) {            if (!mp4_GetMarkerBit(pInfo)) return MP4_STATUS_PARSE_ERROR;            VOL->width = mp4_GetBits(pInfo, 13);            if (!mp4_GetMarkerBit(pInfo)) return MP4_STATUS_PARSE_ERROR;            VOL->height = mp4_GetBits(pInfo, 13);            if (!mp4_GetMarkerBit(pInfo)) return MP4_STATUS_PARSE_ERROR;        }        VOL->interlaced = mp4_GetBit(pInfo);        VOL->obmc_disable = mp4_GetBit(pInfo);        VOL->sprite_enable = mp4_GetBits9(pInfo, VOL->verid != 1 ? 2 : 1);        if (VOL->sprite_enable == MP4_SPRITE_STATIC || VOL->sprite_enable == MP4_SPRITE_GMC) {            if (VOL->sprite_enable == MP4_SPRITE_STATIC) {                VOL->sprite_width = mp4_GetBits(pInfo, 13);                if (!mp4_GetMarkerBit(pInfo)) return MP4_STATUS_PARSE_ERROR;                VOL->sprite_height = mp4_GetBits(pInfo, 13);                if (!mp4_GetMarkerBit(pInfo)) return MP4_STATUS_PARSE_ERROR;                VOL->sprite_left_coordinate = mp4_GetBits(pInfo, 13);                VOL->sprite_left_coordinate <<= (32 - 13);                VOL->sprite_left_coordinate >>= (32 - 13);                if (VOL->sprite_left_coordinate & 1) {                    mp4_Error("Error: sprite_left_coordinate must be divisible by 2");                    return MP4_STATUS_PARSE_ERROR;                }                if (!mp4_GetMarkerBit(pInfo)) return MP4_STATUS_PARSE_ERROR;                VOL->sprite_top_coordinate = mp4_GetBits(pInfo, 13);                VOL->sprite_top_coordinate <<= (32 - 13);                VOL->sprite_top_coordinate >>= (32 - 13);                if (VOL->sprite_top_coordinate & 1) {                    mp4_Error("Error: sprite_top_coordinate must be divisible by 2");                    return MP4_STATUS_PARSE_ERROR;                }                if (!mp4_GetMarkerBit(pInfo)) return MP4_STATUS_PARSE_ERROR;            }            VOL->sprite_warping_points = mp4_GetBits9(pInfo, 6);            if (VOL->sprite_warping_points > 4 ||                (VOL->sprite_warping_points == 4 &&                 VOL->sprite_enable == MP4_SPRITE_GMC)) {                mp4_Error("Error: bad no_of_sprite_warping_points");                return MP4_STATUS_PARSE_ERROR;            }            VOL->sprite_warping_accuracy = mp4_GetBits9(pInfo, 2);            VOL->sprite_brightness_change = mp4_GetBit(pInfo);            if (VOL->sprite_enable == MP4_SPRITE_GMC) {                if (VOL->sprite_brightness_change) {                    mp4_Error("Error: sprite_brightness_change should be 0 for GMC sprites");                    return MP4_STATUS_PARSE_ERROR;                }            }            if (VOL->sprite_enable != MP4_SPRITE_GMC) {                VOL->low_latency_sprite_enable = mp4_GetBit(pInfo);                if (VOL->low_latency_sprite_enable) {                    mp4_Error("Error: low_latency_sprite not supported");                    return MP4_STATUS_PARSE_ERROR;                }            }        }        if (VOL->verid != 1 && VOL->shape != MP4_SHAPE_TYPE_RECTANGULAR) {            VOL->sadct_disable = mp4_GetBit(pInfo);            if (!VOL->sadct_disable) {                mp4_Error("Error: Shape Adaptive DCT is not supported");                return MP4_STATUS_PARSE_ERROR;            }        }        VOL->not_8_bit = mp4_GetBit(pInfo);        if (VOL->not_8_bit) {            mp4_Error("Error: only 8-bits data is supported");            return MP4_STATUS_PARSE_ERROR;        }        if (VOL->not_8_bit) {            VOL->quant_precision = mp4_GetBits9(pInfo, 4);            if (VOL->quant_precision < 3 || VOL->quant_precision > 9) {                mp4_Error("Error: quant_precision must be in range [3; 9]");                return MP4_STATUS_PARSE_ERROR;            }            VOL->bits_per_pixel = mp4_GetBits9(pInfo, 4);            if (VOL->bits_per_pixel < 4 || VOL->bits_per_pixel > 12) {                mp4_Error("Error: bits_per_pixel must be in range [4; 12]");                return MP4_STATUS_PARSE_ERROR;            }        } else {

⌨️ 快捷键说明

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