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

📄 video_enc_api.c

📁 最新MTK手机软件源码
💻 C
📖 第 1 页 / 共 2 页
字号:
#endif /*MT6228, MT6229, MT6230*/

    g_video_enc_status.running = KAL_FALSE;
}

MEDIA_STATUS_CODE video_enc_init(MP4ENC_SETUP_STRUCT *setup_input, kal_bool resume_enable)
{
    MEDIA_STATUS_CODE result;

    video_enc_prev_time_value = 0;
    g_video_enc_info_ptr->bit_rate = setup_input->bit_rate;
#if 0
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
#endif

    if (g_video_enc_info_ptr->skip_frame_count == 0)
    {
        g_video_enc_info_ptr->FRAME_RATE = 15;
    }
    else
    {
        g_video_enc_info_ptr->FRAME_RATE = 15 / (g_video_enc_info_ptr->skip_frame_count + 1);
        if (g_video_enc_info_ptr->FRAME_RATE == 0)
            g_video_enc_info_ptr->FRAME_RATE = 1;
    }

    if (g_video_enc_info_ptr->FRAME_RATE > Video_Enc_Max_FrameRate)
    {
        VIDEO_ASSERT(0);

        g_video_enc_status.VIDEO_STATUS = VIDEO_ENC_FRAME_RATE_ERROR;
        return VIDEO_ERROR;
    }

    if (resume_enable == KAL_FALSE)
    {
        video_enc_start_by_resume = KAL_FALSE;

        video_enc_pause_info.pause_already = KAL_FALSE;
        result = video_enc_initialize(setup_input, &g_video_enc_info_ptr->im);
        g_video_enc_info_ptr->prev_time_stamp = 0;
        g_video_enc_info_ptr->current_time_duration = 0;
        video_enc_pause_info.current_time_duration = 0;
        video_enc_pause_info.time_scale = 0;
    }
    else
    {
        video_enc_start_by_resume = KAL_TRUE;

        video_encode_drv_pause_info_restore();
        result = video_enc_resume_init(setup_input, &g_video_enc_info_ptr->im);
    }

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

    return MEDIA_STATUS_OK;
}

MEDIA_STATUS_CODE video_encode_comm_setup(MP4ENC_SETUP_STRUCT *setup_input)
{
    MEDIA_STATUS_CODE result;

    pause_current_time_stamp = 0;
    //video encode driver initialize
    result = video_enc_open(setup_input->frame_width, setup_input->frame_height, 0, KAL_FALSE);

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

    //Total bitsteam buffers, as .mp4 file
    /*Jensen: camera dynamic frame rate, so this mechanism should be disable*/
    //g_video_enc_info_ptr->skip_frame_count = skip_frame_count;
    g_video_enc_info_ptr->skip_frame_count = 0;
    g_video_enc_info_ptr->total_file_size = 0;

    result = video_enc_init(setup_input, KAL_FALSE);

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

    g_video_enc_info_ptr->large_quant_count = 0;
    g_video_enc_info_ptr->video_enc_callback = setup_input->call_back;
    g_video_enc_info_ptr->stage = VIDEO_ENC_STAGE_INIT;
    video_is_start_record = VIDEO_ENC_START_RECORD_STATE_START;
    return MEDIA_STATUS_OK;
}

MEDIA_STATUS_CODE video_encode_setup(MP4ENC_SETUP_STRUCT *setup_input)
{
    MEDIA_STATUS_CODE result;

    g_video_enc_status.scenario = VIDEO_SCENARIO_ENCODE;
    result = video_encode_comm_setup(setup_input);
    return result;
}

MEDIA_STATUS_CODE video_encode_resume_setup(MP4ENC_SETUP_STRUCT *setup_input)
{
    MEDIA_STATUS_CODE result;

    g_video_enc_status.scenario = VIDEO_SCENARIO_ENCODE;

    //video encode driver initialize
    result = video_enc_open(setup_input->frame_width, setup_input->frame_height, 0, KAL_TRUE);

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

    //Total bitsteam buffers, as .mp4 file
    /*Jensen: camera dynamic frame rate, so this mechanism should be disable*/
    //g_video_enc_info_ptr->skip_frame_count = skip_frame_count;
    g_video_enc_info_ptr->skip_frame_count = 0;

    result = video_enc_init(setup_input, KAL_TRUE);

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

    g_video_enc_info_ptr->force_I_frame = KAL_TRUE;
    g_video_enc_info_ptr->video_enc_callback = setup_input->call_back;
    g_video_enc_info_ptr->stage = VIDEO_ENC_STAGE_INIT;
    video_is_start_record = VIDEO_ENC_START_RECORD_STATE_RESUME_START;
    return MEDIA_STATUS_OK;
}

void video_encode_drv_pause(void)
{
#if defined(__VIDEO_EDITOR__)
    if (g_video_enc_status.scenario == VIDEO_SCENARIO_EDITOR)
    {
        ASSERT(0);
    //pause_current_time_stamp = video_editor_get_current_time_stamp();
    }
    else
#endif /*__VIDEO_EDITOR__*/

    {
        pause_current_time_stamp = video_enc_get_timestamp();
    }

    kal_mem_cpy(&video_enc_pause_info.im, &g_video_enc_info_ptr->im, sizeof(m4v_enc_im));
    kal_mem_cpy(&video_enc_pause_info.rc_data, &g_video_enc_info_ptr->rc_data, sizeof(RC_STRUCT));
    video_enc_pause_info.current_time_duration = g_video_enc_info_ptr->current_time_duration;
    video_enc_pause_info.prev_time_stamp = g_video_enc_info_ptr->prev_time_stamp;
    video_enc_pause_info.total_frames = g_video_enc_info_ptr->total_frames;
    video_enc_pause_info.hisr_total_frames = g_video_enc_info_ptr->hisr_total_frames;
    video_enc_pause_info.bit_rate = g_video_enc_info_ptr->bit_rate;
    video_enc_pause_info.FRAME_RATE = g_video_enc_info_ptr->FRAME_RATE;
    video_enc_pause_info.video_enc_audio_format = video_enc_audio_format;
#if defined(__VIDEO_EDITOR__)
    if (g_video_enc_status.scenario == VIDEO_SCENARIO_EDITOR)
    {
        //video_enc_pause_info.time_scale = 32768;
        ASSERT(0);
    }
    else
#endif /*__VIDEO_EDITOR__*/

    {
        video_enc_pause_info.time_scale = Media_A2V_GetAudioInterruptTimeScale(video_enc_audio_format, 0x0b);
    }

    video_enc_pause_info.total_file_size = g_video_enc_info_ptr->total_file_size;
    video_enc_pause_info.pause_already = KAL_TRUE;
}

void video_encode_drv_pause_info_restore(void)
{
    ASSERT(video_enc_pause_info.pause_already == KAL_TRUE);

    kal_mem_cpy(&g_video_enc_info_ptr->rc_data, &video_enc_pause_info.rc_data, sizeof(RC_STRUCT));
    kal_mem_cpy(&g_video_enc_info_ptr->im, &video_enc_pause_info.im, sizeof(m4v_enc_im));
    g_video_enc_info_ptr->current_time_duration = video_enc_pause_info.current_time_duration;
    g_video_enc_info_ptr->prev_time_stamp = video_enc_pause_info.prev_time_stamp;
    g_video_enc_info_ptr->total_frames = video_enc_pause_info.hisr_total_frames;
    g_video_enc_info_ptr->hisr_total_frames = video_enc_pause_info.hisr_total_frames;
    g_video_enc_info_ptr->bit_rate = video_enc_pause_info.bit_rate;
    g_video_enc_info_ptr->FRAME_RATE = video_enc_pause_info.FRAME_RATE;
    g_video_enc_info_ptr->total_file_size = video_enc_pause_info.total_file_size;
    video_enc_audio_format = video_enc_pause_info.video_enc_audio_format;
    video_enc_pause_info.pause_already = KAL_FALSE;
}

kal_uint32 video_enc_get_prev_time_stamp(void)
{
    return pause_current_time_stamp;
}

/*Unit: ms*/
kal_uint64 video_enc_get_current_time(void)
{
    kal_uint64 timescale;

    kal_uint64 result;
    kal_uint32 current_ticks;
    kal_uint32 savedMask;
    Media_Format audio_format;

    savedMask = SaveAndSetIRQMask();
    audio_format = video_enc_audio_format;

    if (video_enc_pause_info.pause_already == KAL_TRUE)
    {
        if (video_enc_pause_info.time_scale == 0)
            result = 0;
        else
            result = VIDEO_ANYBASE_TO_MS(video_enc_pause_info.current_time_duration, video_enc_pause_info.time_scale);
    }
    else if (audio_format == 0)
    {
        if (video_is_start_record != VIDEO_ENC_START_RECORD_STATE_STOP)
        {
            if (g_video_enc_info_ptr->encode_stop != KAL_TRUE)
            {
                if (video_enc_pause_info.time_scale == 0)
                {
                    result = 0;
                }
                else
                {
                    result = VIDEO_ANYBASE_TO_MS(video_enc_pause_info.current_time_duration,
                                                 video_enc_pause_info.time_scale);
                }
            }
            else
            {
                result = video_enc_prev_time_value;
            }
        }
        else
        {
            result = 0;
        }
    }
    else if ((video_enc_start_by_resume == KAL_TRUE)
                 && (video_is_start_record
                         != VIDEO_ENC_START_RECORD_STATE_RUNING)) /*MMI/MED will block during pause/resume/restart*/
    {
        if (video_enc_pause_info.time_scale == 0)
            result = 0;
        else
        {
            result = VIDEO_ANYBASE_TO_MS(video_enc_pause_info.current_time_duration, video_enc_pause_info.time_scale);
        }
    }
    else
    {
        timescale = Media_A2V_GetAudioInterruptTimeScale(audio_format, 0x0b);
        if (timescale == 0)
            result = 0;
        else
        {
            current_ticks = video_enc_get_timestamp();

            if (current_ticks >= g_video_enc_info_ptr->prev_time_stamp)
                g_video_enc_info_ptr->current_time_duration += (current_ticks - g_video_enc_info_ptr->prev_time_stamp);
            else
                g_video_enc_info_ptr->current_time_duration += (0xffffffff - g_video_enc_info_ptr->prev_time_stamp
                                                                    + current_ticks);

            g_video_enc_info_ptr->prev_time_stamp = current_ticks;

            result = VIDEO_ANYBASE_TO_MS(g_video_enc_info_ptr->current_time_duration, timescale);
        }
    }

    video_enc_prev_time_value = result;
    RestoreIRQMask(savedMask);
    return result;
}

void video_enc_audiocallback(void (*audio_rec_callback)(Media_Event event))
{
    audio_record_callback = audio_rec_callback;
}

void video_enc_set_audioformat(Media_Format audio_format)
{
    video_enc_audio_format = audio_format;
}

kal_uint32 video_enc_get_bitstream_file_size(void)
{
    return g_video_enc_info_ptr->total_file_size;
}
#else  /*!MP4_CODEC*/
#include "drv_comm.h"
#endif /*MP4_CODEC*/

⌨️ 快捷键说明

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