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

📄 umc_dv50_video_encoder.cpp

📁 audio-video-codecs.rar语音编解码器
💻 CPP
字号:
/*
//              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) 2006-2007 Intel Corporation. All Rights Reserved.
//
*/
#include "umc_defs.h"
#if defined (UMC_ENABLE_DV50_VIDEO_ENCODER)

#include "umc_dv50_video_encoder.h"
#include "umc_dv_enc_segment_compressor.h"
#include "umc_dv_enc_segment_writer.h"
#include "umc_dv50_enc_segment_reader.h"

namespace UMC
{

DV50VideoEncoder::DV50VideoEncoder(void)
{
}

DV50VideoEncoder::~DV50VideoEncoder(void)
{
    Close();
}

Status DV50VideoEncoder::Init(BaseCodecParams* pBaseParams)
{
    VideoEncoderParams *pParams = DynamicCast<VideoEncoderParams> (pBaseParams);

    if (pParams == NULL)
        return UMC_ERR_NULL_PTR;

    if (m_bIsInit)
        Close();

    //init Huffman Tables
    //377 ENCODE_ELEMENT entries
    //63 Ipp16s elements in TableMaxAmpOnRun table
    //62 (ENCODE_ELEMENT*) entries for encode table
    //4096 - reserved for alignment
    newHuffmanTablesBuffer = ippsMalloc_8u(377 * 4 + 63 * 2 + 62 * 4 + 4096);
    InitHuffmanTables(newHuffmanTablesBuffer);

    if( pParams->info.clip_info.width != 720 || (pParams->info.clip_info.height != 576 && pParams->info.clip_info.height != 480) )
      return UMC_ERR_INVALID_STREAM;

    if(UMC_OK != BaseCodec::Init(pBaseParams))
        return UMC_ERR_INIT;

    m_Params = *pParams;
    m_Params.info.stream_type = DIGITAL_VIDEO_50;

    m_iMaxI = (480 == m_Params.info.clip_info.height) ? 10 : 12;

    // create DV segment writer
    m_pDVWriter = new DVSegmentWriter;
    if (NULL == m_pDVWriter)
        return UMC_ERR_ALLOC;
    if (m_pDVWriter->InitWriter((480 == pParams->info.clip_info.height) ? 0 : 1, 0x7 /*The source is unknown*/))
        return UMC_ERR_FAILED;

    // create segment compressor
    m_pSCompressor = new SegmentCompressor;
    if (NULL == m_pSCompressor)
        return UMC_ERR_ALLOC;
    if (m_pSCompressor->InitCompressor(6, m_pMemoryAllocator))
        return UMC_ERR_FAILED;

    // create segment reader
    m_pSReader = new DV50_SegmentReader( (480 == m_Params.info.clip_info.height) ? 10 : 12);
    if (NULL == m_pSReader)
        return UMC_ERR_ALLOC;

    m_bIsInit = true;

    return UMC_OK;
}

Status DV50VideoEncoder::GetFrame(MediaData *pVideoDataIn, MediaData *pEncodedFrame)
{
    Ipp8u Channel, DIFSeqNum;
    Ipp16s VSegmentNum;
    DV_SEGMENT *lpDVSegment;
    V_SEGMENT *lpVSegment;

    if (!m_bIsInit)
        return UMC_ERR_NOT_INITIALIZED;

    VideoData* pSrcFrame = DynamicCast<VideoData> (pVideoDataIn);
    if (!pSrcFrame || !pEncodedFrame)
        return UMC_ERR_NOT_ENOUGH_DATA;

    if(pEncodedFrame->GetBufferSize() < ((m_iMaxI == 10) ? 240000u : 288000u))
        return UMC_ERR_NOT_ENOUGH_BUFFER;

    m_pDVWriter->m_pDest = (Ipp8u *) pEncodedFrame->GetDataPointer();

    m_pSReader->m_lpSourceFrame = pSrcFrame;

    m_pSCompressor->LockWorkBuffers();
    lpVSegment = &(m_pSCompressor->m_VSegment);
    for(Channel=0; Channel<2; Channel++)
    {
        for (DIFSeqNum = 0; DIFSeqNum < m_iMaxI; DIFSeqNum++)
        {
            m_pDVWriter->StartDIFSequence(DIFSeqNum, Channel /*FSC*/);
            for (VSegmentNum = 0; VSegmentNum < 27; VSegmentNum++)
            {
                m_pDVWriter->SetDVSegment(&lpDVSegment);
                m_pSReader->ReadSegment(lpVSegment, DIFSeqNum + m_iMaxI*Channel, VSegmentNum);
                m_pSCompressor->CompressSegment(lpDVSegment);
            }
        }
    }
    m_pSCompressor->UnlockWorkBuffers();

    pEncodedFrame->SetDataSize( (m_iMaxI == 10) ? 240000u : 288000u);

    return UMC_OK;
}

}//namespace UMC

#endif //(UMC_ENABLE_DV50_VIDEO_ENCODER)

⌨️ 快捷键说明

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