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

📄 umc_vc1_video_decoder.cpp

📁 audio-video-codecs.rar语音编解码器
💻 CPP
📖 第 1 页 / 共 5 页
字号:
                    break;
                }
            }
            else
            {
                if (!m_bIsWMPSplitter)
                {
                    if ((*m_pContext->m_bitstream.pBitstream&0xFF) == 0xC5) // sequence header
                    {
                        params.m_pData = in;
                        params.lFlags = m_decoderFlags;
                        params.info.stream_type = m_ClipInfo.stream_type;
                        params.info.stream_subtype = m_ClipInfo.stream_subtype;
                        params.numThreads = m_iThreadDecoderNum;
                        if(m_allocatedPostProcessing == NULL)
                            params.pPostProcessing = m_PostProcessing;
                        else
                            m_PostProcessing = NULL;

                        Close();

                        Init(&params);
                        out_data->SetTime(m_pts);
                        return UMC_ERR_NOT_ENOUGH_DATA;
                    }
                    //skip frame size
                    m_pContext->m_bitstream.pBitstream += 2;
                }
                else
                {
                    m_pContext->m_bitstream.pBitstream += 1;
                }
#ifdef VC1_DEBUG_ON
                VM_Debug::GetInstance(VC1DebugRoutine).vm_debug_frame(frameCount,0,NULL,1);
#endif
                m_lFrameCount++;
#ifdef VC1_DEBUG_ON
                VM_Debug::GetInstance(VC1DebugRoutine).vm_debug_frame(-1,VC1_POSITION,
                                            VM_STRING("frameCount: %d\n"), frameCount);
#endif
                try //work with queue of frame descriptors and process every frame
                {
                    umcRes = m_pSelfDecoder->VC1DecodeFrame(this,in,out_data);
                }
                catch (vc1_exception ex)
                {
                    exception_type e_type = ex.get_exception_type();
                    if (e_type == internal_pipeline_error)
                        return UMC_ERR_FAILED;
                }

#ifdef _PROJECT_STATISTICS_
                        m_timeStatistics->frameCount++;
#endif
            }
           readSize = m_pContext->m_FrameSize;
        }
        else
        {
            //Using MediaData

            if(((m_decoderFlags & FLAG_VDEC_4BYTE_ACCESS) == FLAG_VDEC_4BYTE_ACCESS))
            {
                printf("Using MediaData and swapping input data into splitter is impossible!\n");
                umcRes = UMC_ERR_FAILED;
            }
            else
            {
                //maybe
                m_pContext->m_FrameSize = (Ipp32u)in->GetDataSize();

                memset(m_dataBuffer,0,(Ipp32u)m_frameData->GetDataSize());

                if(m_pContext->m_seqLayerHeader->PROFILE == VC1_PROFILE_ADVANCED)
                {
                    m_frameData->GetExData()->count = 0;
                    memset(m_frameData->GetExData()->offsets, 0,START_CODE_NUMBER*sizeof(Ipp32s));
                    memset(m_frameData->GetExData()->values, 0,START_CODE_NUMBER*sizeof(Ipp32s));
                    umcRes = GetStartCodes(in, m_frameData, &readSize);
                    m_pContext->m_FrameSize = (Ipp32u)m_frameData->GetDataSize();
                }
                else
                {
                    GetFrameSize(in);

                    while(m_pContext->m_FrameSize > m_frameData->GetBufferSize())
                        ResizeBuffer();

                    ippsCopy_8u((Ipp8u*)in->GetBufferPointer(),  m_dataBuffer,
                                m_pContext->m_FrameSize);
                }

                m_pContext->m_pBufferStart  = (Ipp8u*) m_dataBuffer;
                m_pContext->m_bitstream.pBitstream  = (Ipp32u*)(m_pContext->m_pBufferStart);
                m_pContext->m_bitstream.bitOffset   = 31;

                m_pContext->m_Offsets = m_frameData->GetExData()->offsets;
                m_pContext->m_values = m_frameData->GetExData()->values;


                //swap data
                SwapData((Ipp8u*)m_frameData->GetBufferPointer(),
                         (Ipp32u)m_frameData->GetDataSize());

                if(!m_decoderInitFlag)
                {
                     Ipp32u start_code = *((Ipp32u*)(m_pContext->m_pBufferStart));

                     if((start_code != (VC1_SequenceHeader|0x00000100))&& (m_ClipInfo.stream_subtype == VC1_VIDEO_VC1))
                        return UMC_ERR_NOT_ENOUGH_DATA;

                    params.m_pData = in;
                    params.lFlags = m_decoderFlags;
                    params.info.stream_type = m_ClipInfo.stream_type;
                    params.info.stream_subtype = m_ClipInfo.stream_subtype;
                    params.numThreads = m_iThreadDecoderNum;
                    if(m_allocatedPostProcessing == NULL)
                        params.pPostProcessing = m_PostProcessing;
                    else
                        m_PostProcessing = NULL;

                    Close();

                    Init(&params);
                        out_data->SetTime(m_pts);
                        STATISTICS_END_TIME  (m_timeStatistics->startTime,
                         m_timeStatistics->endTime,
                         m_timeStatistics->totalTime);

                    return UMC_ERR_NOT_ENOUGH_DATA;
                }

                if(m_pContext->m_seqLayerHeader->PROFILE == VC1_PROFILE_ADVANCED)
                {
                    Ipp32u start_code = *((Ipp32u*)(m_pContext->m_pBufferStart));
                    //skip start code
                    m_pContext->m_bitstream.pBitstream += 1;

                    //advanced profile
                    switch (start_code)
                    {
                    case VC1_SequenceHeader|0x00000100:
                        {
                            //need to change display index
                            m_pContext->m_frmBuff.m_iDisplayIndex = m_pStore->GetNextIndex();
                            m_pStore->FreeIndexQueue();
                            m_pStore->ResetDSQueue();
                            m_lFrameCount = 0;
                            m_pContext->m_frmBuff.m_iPrevIndex  = -1;
                            m_pContext->m_frmBuff.m_iNextIndex= -1;
                            m_pContext->m_frmBuff.m_iCurrIndex = -1;
                            m_pContext->m_bIntensityCompensation = 0;

                            if (/*out_data!=NULL && */
                                m_pContext->m_frmBuff.m_iDisplayIndex>-1 && (umcRes == UMC_OK))
                            {
                                umcRes = WriteFrame(in,m_pContext,out_data);
                                umcRes =  UMC_OK;
                            }
                            else
                                umcRes =  UMC_ERR_NOT_ENOUGH_DATA;

                            params.m_pData = in;
                            params.lFlags = m_decoderFlags;
                            params.info.stream_type = m_ClipInfo.stream_type;
                            params.info.stream_subtype = m_ClipInfo.stream_subtype;
                            params.numThreads = m_iThreadDecoderNum;
                            if(m_allocatedPostProcessing == NULL)
                                params.pPostProcessing = m_PostProcessing;
                            else
                                m_PostProcessing = NULL;

                            Close();

                            Init(&params);
                                out_data->SetTime(m_pts);
                            return umcRes;
                        }
                        break;
                    case VC1_EndOfSequence|0x00000100:
                        {
                            //need to change display index
                            //m_pContext->m_frmBuff.m_iDisplayIndex =  VC1TaskStore::GetInstance(VC1Routine)->GetNextIndex();
                            //VC1TaskStore::GetInstance(VC1Routine)->FreeIndexQueue();
                            //VC1TaskStore::GetInstance(VC1Routine)->ResetDSQueue();
                            //m_lFrameCount = 0;
                            //m_pContext->m_frmBuff.m_iPrevIndex  = -1;
                            //m_pContext->m_frmBuff.m_iNextIndex= -1;
                            //m_pContext->m_frmBuff.m_iCurrIndex = -1;
                            //m_pContext->m_bIntensityCompensation = 0;

                            //if (/*out_data!=NULL && */
                            //    m_pContext->m_frmBuff.m_iDisplayIndex>-1 && (umcRes == UMC_OK))
                            //{
                            //    umcRes = WriteFrame_Adv(in,m_pContext,out_data);
                            //    umcRes = UMC_OK;
                            //}
                            //else
                            //    umcRes = UMC_ERR_NOT_INITIALIZED;

                            //m_decoderInitFlag = 0;
                            m_pContext->m_Offsets++;
                            m_pContext->m_values++;
                        }
                        break;
                    case VC1_EntryPointHeader|0x00000100:
                        EntryPointLayer(m_pContext);
                        m_pContext->m_Offsets++;
                        m_pContext->m_values++;
                        umcRes =  UMC_ERR_NOT_ENOUGH_DATA;
                        break;
                    case VC1_FrameHeader|0x00000100:
                        {
#ifdef VC1_DEBUG_ON
                            VM_Debug::GetInstance(VC1DebugRoutine).vm_debug_frame(frameCount,0,NULL,1);
#endif

#ifdef SLICE_INFO
                            printf("frameCount =%d\n", frameCount);
#endif
                            ++m_lFrameCount;
#ifdef VC1_DEBUG_ON
                            VM_Debug::GetInstance(VC1DebugRoutine).vm_debug_frame(-1,VC1_POSITION,
                                                        VM_STRING("frameCount = %d\n"), frameCount);
#endif
                            try //work with queue of frame descriptors and process every frame
                            {
                                umcRes = m_pSelfDecoder->VC1DecodeFrame(this,in,out_data);
                            }
                            catch (vc1_exception ex)
                            {
                                exception_type e_type = ex.get_exception_type();
                                if (e_type == internal_pipeline_error)
                                    return UMC_ERR_FAILED;

                            }
#ifdef _PROJECT_STATISTICS_
                        m_timeStatistics->frameCount++;
#endif
                        }
                        break;
                    case VC1_Field|0x00000100:
                    case VC1_SliceLevelUserData|0x00000100:
                    case VC1_FieldLevelUserData|0x00000100:
                    case VC1_FrameLevelUserData|0x00000100:
                    case VC1_EntryPointLevelUserData|0x00000100:
                    case VC1_SequenceLevelUserData|0x00000100:
                        m_pContext->m_Offsets++;
                        m_pContext->m_values++;
                        umcRes = UMC_ERR_NOT_ENOUGH_DATA;
                        break;
                    default:
                        printf("incorrect start code suffix \n");
                        umcRes = UMC_ERR_SYNC;
                        break;
                    }
                }
                else
                {
                    if ((*m_pContext->m_bitstream.pBitstream&0xFF) == 0xC5) // sequence header
                    {
                        params.m_pData = in;
                        params.lFlags = m_decoderFlags;
                        params.info.stream_type = m_ClipInfo.stream_type;
                        params.info.stream_subtype = m_ClipInfo.stream_subtype;
                        params.numThreads = m_iThreadDecoderNum;
                        if(m_allocatedPostProcessing == NULL)
                            params.pPostProcessing = m_PostProcessing;
                        else
                            m_PostProcessing = NULL;

                        Close();

                        Init(&params);
                        out_data->SetTime(m_pts);
                        return UMC_ERR_NOT_ENOUGH_DATA;
                    }
                    //skip frame size
                    m_pContext->m_bitstream.pBitstream += 2;

#ifdef VC1_DEBUG_ON
                    VM_Debug::GetInstance(VC1DebugRoutine).vm_debug_frame(frameCount,0,NULL,1);
#endif
                    ++m_lFrameCount;
#ifdef VC1_DEBUG_ON
                    VM_Debug::GetInstance(VC1DebugRoutine).vm_debug_frame(-1,VC1_POSITION,
                                                VM_STRING("frameCount: %d\n"), frameCount);
#endif
                    try //work with queue of frame descriptors and process every frame
                    {
                        umcRes = m_pSelfDecoder->VC1DecodeFrame(this,in,out_data);
                    }
                    catch (vc1_exception ex)
                    {
                        exception_type e_type = ex.get_exception_type();
                        if (e_type== internal_pipeline_error)
                            return UMC_ERR_FAILED;
                        // for vld exceptions we can continue decoding?
                    }

                }
            }

        }
        GetPTS(in->GetTime());
        out_data->SetTime(m_pts);
        in->MoveDataPointer(readSize);

   STATISTICS_END_TIME  (m_timeStatistics->startTime,
                         m_timeStatistics->endTime,
                         m_timeStatistics->totalTime);


    }
    if(umcRes == VC1_WRN_INVALID_STREAM)
        umcRes = UMC_ERR_INVALID_STREAM;
    return umcRes;
}

Status VC1VideoDecoder::Close(void)
{
    Status umcRes = UMC_OK;

    if (m_pStore)
        m_pStore->StopDecoding();


    if(m_pdecoder)
    {
        for(Ipp32u i = 0; i < m_iThreadDecoderNum; i += 1)
        {
#ifdef  VC1_THREAD_STATISTIC
            if (m_eEntryArray[i])
            {
                ippsFree(m_eEntryArray[i]);
                m_eEntryArray[i] = NULL;
            }
            if (m_pdecoder[i]->m_pJobSlice->m_Statistic)
            {
                delete m_pdecoder[i]->m_pJobSlice->m_Statistic;
                m_pdecoder[i] = NULL;
            }
#endif
            if(m_pdecoder[i])
            {
                if (i > 0)
                    m_pdecoder[i]->WaitAndStop();
                delete m_pdecoder[i];
                m_pdecoder[i] = NULL;
            }
        }
#ifdef  VC1_THREAD_STATISTIC
        ippsFree(m_eEntryArray);
        m_eEntryArray = NULL;

#endif
        delete m_pdecoder;
        m_pdecoder = NULL;
    }

    if (m_pStore)
    {
        m_pStore->Reset();
        delete m_pStore;
        m_pStore = NULL;
    }

⌨️ 快捷键说明

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