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

📄 video_fileparse_adap.c

📁 最新MTK手机软件源码
💻 C
📖 第 1 页 / 共 2 页
字号:
            EXT_ASSERT(0, result_frame_no_check, 0, 0);
        }

        VIDEO_ASSERT(0);
        g_video_dec_info_ptr->stop_frame_no = p_file_info->start_frame_no + result_frame_no;
    }

    /* set the last one offset as 0 */
    p_file_info->temp_file_offset[result_frame_no] = 0;

    /* calculate smaple sizes and read from file to buffer */
    current_pos = p_file_info->temp_file_offset[0];
    current_size = 0;
    current_buffer_addr = p_file_info->p_frame_buffer_addr[0];
    sum = 0;

    for (index = 0; index < result_frame_no; index++)
    {
        /*Search the max frame data to be prepared to buffer*/
        if ((index + 1) < result_frame_no)
        {
            p_file_info->p_frame_buffer_addr[index + 1] =
                     p_file_info->p_frame_buffer_addr[index]
                    + p_file_info->p_frame_length[index];
        }

        sum += p_file_info->p_frame_length[index];

        if (sum > p_file_info->max_size)
        {
            if(index > 0)
            {
                /* reach frame buffer size limit */
                result = video_file_read_bitstream_data(current_pos, current_size, current_buffer_addr);
                
                if (result != MEDIA_STATUS_OK)
                {
                    VIDEO_ASSERT(0);
                    return result;
                }
                
                index--;
                p_file_info->result_size += current_size; 
                p_file_info->result_frame_no += (index - start_read_no + 1);
                start_read_no = index + 1;
            }
            break;
        }

        current_size += p_file_info->p_frame_length[index];
        if ((current_pos + current_size) != p_file_info->temp_file_offset[index + 1])
        {
            /* not continous data */
            result = video_file_read_bitstream_data(current_pos, current_size, current_buffer_addr);

            if (result != MEDIA_STATUS_OK)
            {
                VIDEO_ASSERT(0);
                return result;
            }

            p_file_info->result_size += current_size;
            p_file_info->result_frame_no += (index - start_read_no + 1);
            start_read_no = index + 1;
            current_buffer_addr = p_file_info->p_frame_buffer_addr[index+1];
            current_pos = p_file_info->temp_file_offset[index + 1];
            current_size = 0;
        }
    }
  
    return MEDIA_STATUS_OK;
}


/* This function get frame duration from media file parser.
* @param  frame_no start frame number
* @param  size How many frames information is needed.
* @param  result the memory that store the result of frame time.
* @return Media status, which is based MEDIA_STATUS_CODE structure.
*/
MEDIA_STATUS_CODE video_file_get_frametime(kal_uint32 frame_no, kal_uint32 size, kal_uint64 *result)
{
    kal_uint32 index;
    kal_uint32 video_duration;
    kal_uint32 min_frame_time;
    MEDIA_STATUS_CODE result_code;

    /* get frame time */
    g_video_dec_status.PARSE_STATUS =
        MP4_GetDecodeTimeDelta_Array(g_video_dec_info_ptr->pMp4Parser, frame_no, result, &size, MP4_TRACK_VIDEO);
    if (g_video_dec_status.PARSE_STATUS != MP4_PARSER_OK)
    {
        VIDEO_ASSERT(0);
        g_video_dec_info_ptr->stop_frame_no = frame_no + size;
    }

    /* get total duration */
    g_video_dec_status.PARSE_STATUS = MP4_GetMediaDuration(g_video_dec_info_ptr->pMp4Parser, &video_duration,
                                                           MP4_TRACK_VIDEO);
    if (g_video_dec_status.PARSE_STATUS != MP4_PARSER_OK)
    {
        VIDEO_ASSERT(0);
        return MP4_PARSER_ERROR;
    }

    min_frame_time = VIDEO_ANYBASE_TO_ANYBASE(VIDEO_FILE_MIN_FRAME_DURATION, 1000, g_video_dec_info_ptr->video_time_scale);

    /* check each frame time and translate to AV ticks */
    for (index = 0; index < size; index++)
    {
        if ( (result[index] > video_duration) || (result[index] < min_frame_time))
        {
            VIDEO_ASSERT(0);
            /*Tricky to fix error file, modify frame interval*/
            if (index != 0)
            {
            	    result[index] = result[index-1];
            	}
            else
            {
                result_code = video_dec_translate_av_time(min_frame_time, &result[index]);
                if (result_code != MEDIA_STATUS_OK)
                {
                    VIDEO_ASSERT(0);
                    return result_code;
                }  
            }    
            /* previous one has translated, so not translate again */
            continue;
        }

        result_code = video_dec_translate_av_time(result[index], &result[index]);

        if (result_code != MEDIA_STATUS_OK)
        {
            VIDEO_ASSERT(0);
            return result_code;
        }
        if (result[index] == 0)
        {
            /* After translate, frame time is zero*/
            VIDEO_ASSERT(0);
            /*Tricky to fix error file, modify frame interval*/
            if (index != 0)
            {
                /* share time with previous one */
                result[index] = result[index - 1] / 2;
                result[index - 1] = result[index - 1] - result[index];
            }
            else
            {
                result[index] = 64;
            }
        }
    }

    return MEDIA_STATUS_OK;
}


/* Obtain the decode type from media file
* @param None
* @return DECODE_TYPE_MPEG4 or DECODE_TYPE_H263
*/
DECODE_TYPE video_file_get_decode_type(void)
{
    MP4_Video_Type video_type;

    DECODE_TYPE type;
    video_type = MP4_GetVideoType(g_video_dec_info_ptr->pMp4Parser);

    switch (video_type)
    {
    case MP4_VIDEO_MPEG4:
        type = DECODE_TYPE_MPEG4;
        break;

    case MP4_VIDEO_H263:
        type = DECODE_TYPE_H263;
        break;

    default:
        type = DECODE_TYPE_UNKNOW;
        break;
    }

    return type;
}


/* Obtain VOS data from media file
 * @param  VOS VOS structure.
 * @return Media status, which is based MEDIA_STATUS_CODE structure.
 */
MEDIA_STATUS_CODE video_file_get_vos_data(MP4VIDEO_VOS_STRUCT **VOS)
{
    kal_uint32 vos_pos;

    /* Get VOS information */
    vos_pos = MP4_Video_GetVOSOffset(g_video_dec_info_ptr->pMp4Parser);
    g_video_dec_info_ptr->VOS_DATA.size = MP4_Video_GetVOSSize(g_video_dec_info_ptr->pMp4Parser);

    if (g_video_dec_info_ptr->VOS_DATA.size > 100)
    {
        VIDEO_ASSERT(0);

        g_video_dec_status.VIDEO_STATUS = VIDEO_DEC_FATAL_ERROR;
        return VIDEO_ERROR;
    }

    /* Read VOS from file system*/
    g_video_dec_status.FSAL_STATUS = FSAL_Seek(g_video_dec_info_ptr->pstFSAL, vos_pos);
    if (g_video_dec_status.FSAL_STATUS != FSAL_OK)
    {
        VIDEO_ASSERT(0);

        g_video_dec_status.FSAL_ERROR_FILE = g_video_dec_info_ptr->pstFSAL;
        return FSAL_ERROR;
    }

    g_video_dec_status.FSAL_STATUS = FSAL_Read(g_video_dec_info_ptr->pstFSAL,
                                               (kal_uint8 *)g_video_dec_info_ptr->VOS_DATA.vos_data,
                                               g_video_dec_info_ptr->VOS_DATA.size);
    if (g_video_dec_status.FSAL_STATUS != FSAL_OK)
    {
        VIDEO_ASSERT(0);

        g_video_dec_status.FSAL_ERROR_FILE = g_video_dec_info_ptr->pstFSAL;
        return FSAL_ERROR;
    }

    *VOS = &g_video_dec_info_ptr->VOS_DATA;
    return MEDIA_STATUS_OK;
}
#else  /*!MP4_CODEC*/
#include "drv_comm.h"
#endif /*MP4_CODEC*/

⌨️ 快捷键说明

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