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

📄 mp4parse.c

📁 audio-video-codecs.rar语音编解码器
💻 C
📖 第 1 页 / 共 4 页
字号:
/* ///////////////////////////////////////////////////////////////////////
//
//               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-2008 Intel Corporation. All Rights Reserved.
//
//  Description:    Parses MPEG-4 headers
//
*/

#include "umc_defs.h"

#if defined (UMC_ENABLE_MPEG4_VIDEO_DECODER)

#include "mp4.h"


mp4_Status mp4_Parse_VisualObjectSequence(mp4_Info* pInfo) {
    pInfo->profile_and_level_indication = mp4_GetBits9(pInfo, 8);
    if (pInfo->profile_and_level_indication != MP4_SIMPLE_PROFILE_LEVEL_1 &&
        pInfo->profile_and_level_indication != MP4_SIMPLE_PROFILE_LEVEL_2 &&
        pInfo->profile_and_level_indication != MP4_SIMPLE_PROFILE_LEVEL_3 &&
        pInfo->profile_and_level_indication != MP4_SIMPLE_PROFILE_LEVEL_0 &&
        pInfo->profile_and_level_indication != MP4_CORE_PROFILE_LEVEL_1 &&
        pInfo->profile_and_level_indication != MP4_CORE_PROFILE_LEVEL_2 &&
        pInfo->profile_and_level_indication != MP4_MAIN_PROFILE_LEVEL_2 &&
        pInfo->profile_and_level_indication != MP4_MAIN_PROFILE_LEVEL_3 &&
        pInfo->profile_and_level_indication != MP4_MAIN_PROFILE_LEVEL_4 &&
        pInfo->profile_and_level_indication != MP4_ADVANCED_REAL_TIME_SIMPLE_PROFILE_LEVEL_1 &&
        pInfo->profile_and_level_indication != MP4_ADVANCED_REAL_TIME_SIMPLE_PROFILE_LEVEL_2 &&
        pInfo->profile_and_level_indication != MP4_ADVANCED_REAL_TIME_SIMPLE_PROFILE_LEVEL_3 &&
        pInfo->profile_and_level_indication != MP4_ADVANCED_REAL_TIME_SIMPLE_PROFILE_LEVEL_4 &&
        pInfo->profile_and_level_indication != MP4_ADVANCED_CODING_EFFICIENCY_PROFILE_LEVEL_1 &&
        pInfo->profile_and_level_indication != MP4_ADVANCED_CODING_EFFICIENCY_PROFILE_LEVEL_2 &&
        pInfo->profile_and_level_indication != MP4_ADVANCED_CODING_EFFICIENCY_PROFILE_LEVEL_3 &&
        pInfo->profile_and_level_indication != MP4_ADVANCED_CODING_EFFICIENCY_PROFILE_LEVEL_4 &&
        pInfo->profile_and_level_indication != MP4_ADVANCED_CORE_PROFILE_LEVEL_1 &&
        pInfo->profile_and_level_indication != MP4_ADVANCED_CORE_PROFILE_LEVEL_2 &&
        pInfo->profile_and_level_indication != MP4_ADVANCED_SIMPLE_PROFILE_LEVEL_0 &&
        pInfo->profile_and_level_indication != MP4_ADVANCED_SIMPLE_PROFILE_LEVEL_1 &&
        pInfo->profile_and_level_indication != MP4_ADVANCED_SIMPLE_PROFILE_LEVEL_2 &&
        pInfo->profile_and_level_indication != MP4_ADVANCED_SIMPLE_PROFILE_LEVEL_3 &&
        pInfo->profile_and_level_indication != MP4_ADVANCED_SIMPLE_PROFILE_LEVEL_4 &&
        pInfo->profile_and_level_indication != MP4_ADVANCED_SIMPLE_PROFILE_LEVEL_5 &&
        pInfo->profile_and_level_indication != MP4_ADVANCED_SIMPLE_PROFILE_LEVEL_3B) {
        mp4_Error("Warning: Unsupported profile_and_level_indication");
        if (pInfo->strictSyntaxCheck)
            return MP4_STATUS_NOTSUPPORT;
    }
    if (pInfo->profile_and_level_indication != MP4_SIMPLE_PROFILE_LEVEL_1 &&
        pInfo->profile_and_level_indication != MP4_SIMPLE_PROFILE_LEVEL_2 &&
        pInfo->profile_and_level_indication != MP4_SIMPLE_PROFILE_LEVEL_3 &&
        pInfo->profile_and_level_indication != MP4_SIMPLE_PROFILE_LEVEL_0 &&
        pInfo->profile_and_level_indication != MP4_ADVANCED_SIMPLE_PROFILE_LEVEL_0 &&
        pInfo->profile_and_level_indication != MP4_ADVANCED_SIMPLE_PROFILE_LEVEL_1 &&
        pInfo->profile_and_level_indication != MP4_ADVANCED_SIMPLE_PROFILE_LEVEL_2 &&
        pInfo->profile_and_level_indication != MP4_ADVANCED_SIMPLE_PROFILE_LEVEL_3 &&
        pInfo->profile_and_level_indication != MP4_ADVANCED_SIMPLE_PROFILE_LEVEL_4 &&
        pInfo->profile_and_level_indication != MP4_ADVANCED_SIMPLE_PROFILE_LEVEL_5 &&
        pInfo->profile_and_level_indication != MP4_ADVANCED_SIMPLE_PROFILE_LEVEL_3B) {
        mp4_Error("Warning: Some features of present profile_and_level_indication may be not supported");
    }
    return MP4_STATUS_OK;
}


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);
        if ((VO->verid != 1) && (VO->verid != 2) && (VO->verid != 4) && (VO->verid != 5)) {
            VO->verid = 1;
            mp4_Error("Warning: Unsupported visual_object_verid");
            //f if (pInfo->strictSyntaxCheck)
            //f     return MP4_STATUS_NOTSUPPORT;
        }
        VO->priority = mp4_GetBits9(pInfo, 3);
        if (VO->priority == 0) {
            mp4_Error("Warning: Wrong value of visual_object_priority");
            //f if (pInfo->strictSyntaxCheck)
            //f     return MP4_STATUS_PARSE_ERROR;
        }
    } 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_format = MP4_VIDEO_FORMAT_UNSPECIFIED;
    VO->VideoSignalType.video_range = 0;
    VO->VideoSignalType.colour_primaries = MP4_VIDEO_COLORS_ITU_R_BT_709;
    VO->VideoSignalType.transfer_characteristics = MP4_VIDEO_COLORS_ITU_R_BT_709;
    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);
            if (VO->VideoSignalType.video_format > MP4_VIDEO_FORMAT_UNSPECIFIED) {
                mp4_Error("Warning: Wrong value of video_format");
                //f if (pInfo->strictSyntaxCheck)
                //f     return MP4_STATUS_PARSE_ERROR;
            }
            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);
                if (VO->VideoSignalType.colour_primaries == MP4_VIDEO_COLORS_FORBIDDEN) {
                    mp4_Error("Error: Wrong value of colour_primaries");
                    if (pInfo->strictSyntaxCheck)
                        return MP4_STATUS_PARSE_ERROR;
                }
                if (VO->VideoSignalType.colour_primaries > MP4_VIDEO_COLORS_GENERIC_FILM) {
                    mp4_Error("Warning: Wrong value of colour_primaries");
                    //f if (pInfo->strictSyntaxCheck)
                    //f     return MP4_STATUS_PARSE_ERROR;
                }
                VO->VideoSignalType.transfer_characteristics = mp4_GetBits9(pInfo, 8);
                if (VO->VideoSignalType.transfer_characteristics == 0) {
                    mp4_Error("Error: Wrong value of transfer_characteristics");
                    if (pInfo->strictSyntaxCheck)
                        return MP4_STATUS_PARSE_ERROR;
                }
                if (VO->VideoSignalType.transfer_characteristics > 10) {
                    mp4_Error("Warning: Wrong value of transfer_characteristics");
                    //f if (pInfo->strictSyntaxCheck)
                    //f     return MP4_STATUS_PARSE_ERROR;
                }
                VO->VideoSignalType.matrix_coefficients = mp4_GetBits9(pInfo, 8);
                if (VO->VideoSignalType.matrix_coefficients == 0) {
                    mp4_Error("Error: Wrong value of matrix_coefficients");
                    if (pInfo->strictSyntaxCheck)
                        return MP4_STATUS_PARSE_ERROR;
                }
                if (VO->VideoSignalType.matrix_coefficients > 8) {
                    mp4_Error("Warning: Wrong value of matrix_coefficients");
                    //f if (pInfo->strictSyntaxCheck)
                    //f     return MP4_STATUS_PARSE_ERROR;
                }
            }
        }
    }
    return MP4_STATUS_OK;
}


static mp4_Status mp4_Parse_QuantMatrix(mp4_Info* pInfo, Ipp8u pQM[64])
{
    Ipp32u  code;
    Ipp32s  i;

    for (i = 0; i < 64; i ++) {
        code = mp4_GetBits9(pInfo, 8);
        if (code == 0) break;
            pQM[mp4_ClassicalZigzag[i]] = (Ipp8u)code;
    }
    if (i > 0) {
        code = pQM[mp4_ClassicalZigzag[i-1]];
        for (; i < 64; i ++)
            pQM[mp4_ClassicalZigzag[i]] = (Ipp8u)code;
    } else {
        for (i = 1; i < 64; i ++)
            pQM[mp4_ClassicalZigzag[i]] = (Ipp8u)mp4_ClassicalZigzag[0];
    }
    return MP4_STATUS_OK;
}


mp4_Status mp4_Parse_VideoObject(mp4_Info* pInfo)
{
    Ipp32u  code;
    Ipp32s  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->VideoObjectPlaneH263.num_rows_in_gob = mp4_H263_rowgob[i];
        VOL->vop_time_increment_resolution = 30000;
        // VOL->VideoObjectPlane.time_increment = -1001;
        VOL->VOLControlParameters.low_delay = 1;
        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) {
        mp4_Error("Warning: Unsupported video_object_type_indication, some features may be not supported");
        //f if (pInfo->strictSyntaxCheck)
        //f     return MP4_STATUS_NOTSUPPORT;
    }
    VOL->is_identifier = mp4_GetBit(pInfo);
    if (VOL->is_identifier) {
        VOL->verid = mp4_GetBits9(pInfo, 4);
        if ((VOL->verid != 1) && (VOL->verid != 2) && (VOL->verid != 4) && (VOL->verid != 5)) {
            mp4_Error("Warning: Unsupported video_object_layer_verid");
            VOL->verid = VO->verid;
            //f if (pInfo->strictSyntaxCheck)
            //f     return MP4_STATUS_NOTSUPPORT;
        }
        VOL->priority = mp4_GetBits9(pInfo, 3);
        if (VOL->priority == 0) {
            mp4_Error("Warning: Wrong value of video_object_layer_priority");
            //f if (pInfo->strictSyntaxCheck)
            //f     return MP4_STATUS_PARSE_ERROR;
        }
    } else
        VOL->verid = VO->verid;
    VOL->aspect_ratio_info = mp4_GetBits9(pInfo, 4);
    if (VOL->aspect_ratio_info == MP4_ASPECT_RATIO_FORBIDDEN) {
        mp4_Error("Error: Wrong value of aspect_ratio_info");
        if (pInfo->strictSyntaxCheck)
            return MP4_STATUS_PARSE_ERROR;
    }
    if (VOL->aspect_ratio_info > MP4_ASPECT_RATIO_40_33 && VOL->aspect_ratio_info < MP4_ASPECT_RATIO_EXTPAR) {
        mp4_Error("Warning: Wrong value of aspect_ratio_info");
        //f if (pInfo->strictSyntaxCheck)
        //f     return MP4_STATUS_PARSE_ERROR;
    }
    if (VOL->aspect_ratio_info == MP4_ASPECT_RATIO_EXTPAR) {
        VOL->aspect_ratio_info_par_width = mp4_GetBits9(pInfo, 8);
        if (VOL->aspect_ratio_info_par_width == 0) {
            mp4_Error("Error: Wrong value of par_width");
            if (pInfo->strictSyntaxCheck)
                return MP4_STATUS_PARSE_ERROR;
        }
        VOL->aspect_ratio_info_par_height = mp4_GetBits9(pInfo, 8);
        if (VOL->aspect_ratio_info_par_height == 0) {
            mp4_Error("Error: Wrong value of par_height");
            if (pInfo->strictSyntaxCheck)
                return MP4_STATUS_PARSE_ERROR;
        }

⌨️ 快捷键说明

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