📄 umc_avi_index.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) 2003-2005 Intel Corporation. All Rights Reserved.//*/#include "umc_avi_index.h"using namespace UMC;AVIIndex::AVIIndex() :m_pIndTable(NULL), m_uiTblSize(0){}AVIIndex::~AVIIndex(){ Close(); }voidAVIIndex::Close(){ if (NULL != m_pIndTable) { delete[] m_pIndTable; m_pIndTable = NULL; } m_uiTblSize = 0;}StatusAVIIndex::GenerateIndexTable(AVIChunk& rSrcChunk){ Status umcRes = UMC_OK; rSrcChunk.GoChunkHead(); // go to start of RIFF chunk if (UMC_OK == umcRes) { umcRes = rSrcChunk.DescendLIST(AVI_FOURCC_MOVI); } vm_var32 uiChunkNum = 0; while (UMC_OK == umcRes) { if (UMC_OK == umcRes) { umcRes = rSrcChunk.DescendChunk(AVI_FOURCC_ANY_); } if (UMC_OK == umcRes) { uiChunkNum++; umcRes = rSrcChunk.Ascend(); } } // Continue only if we've enumerated all data chunks // and break in case of error if (UMC_NOT_FIND_SYNCWORD == umcRes) { umcRes = UMC_OK; } if (UMC_OK == umcRes) { rSrcChunk.GoChunkHead(); // go to start of RIFF chunk delete[] m_pIndTable; m_pIndTable = new IndTblEntry[uiChunkNum]; if (NULL == m_pIndTable) { umcRes = UMC_ALLOC; } else { m_uiTblSize = uiChunkNum; memset(m_pIndTable, 0, sizeof(IndTblEntry) * uiChunkNum); } } for (vm_var32 i = 0; UMC_OK == umcRes && i < uiChunkNum; i++) { if (UMC_OK == umcRes) { umcRes = rSrcChunk.DescendChunk(AVI_FOURCC_ANY_); } if (UMC_OK == umcRes && rSrcChunk.GetChunkSize() >= 4) { m_pIndTable[i].ChunkType = rSrcChunk.GetChunkFOURCC(); m_pIndTable[i].uiPos = rSrcChunk.GetChunkHead(); m_pIndTable[i].uiSize = rSrcChunk.GetChunkSize(); } if (UMC_OK == umcRes) { umcRes = rSrcChunk.Ascend(); } } if (UMC_OK == umcRes || UMC_NOT_FIND_SYNCWORD == umcRes) { umcRes = rSrcChunk.Ascend(); } return umcRes;}StatusAVIIndex::Init(AVIChunk& rSrcChunk){ Status umcRes = UMC_OK; Close(); if (UMC_OK == umcRes) { umcRes = rSrcChunk.DescendChunk(AVI_FOURCC_IDX1); } if (UMC_OK == umcRes) { vm_var32 uiTblNum = 0; if (UMC_OK == umcRes) { uiTblNum = rSrcChunk.GetChunkSize(); if (0 == uiTblNum) { umcRes = UMC_BAD_STREAM; } } if (UMC_OK == umcRes) { m_pIndTable = new IndTblEntry[uiTblNum / sizeof(IndTblEntry)]; if (NULL == m_pIndTable) { umcRes = UMC_ALLOC; } else { m_uiTblSize = uiTblNum / sizeof(IndTblEntry); } } if (UMC_OK == umcRes) { umcRes = rSrcChunk.GetData(reinterpret_cast<vm_byte*>(m_pIndTable), m_uiTblSize * sizeof(IndTblEntry)); }#ifdef _BIG_ENDIAN_ if (UMC_OK == umcRes) { for (vm_var32 i = 0; UMC_OK == umcRes && i < m_uiTblSize; i++) { m_pIndTable[i].SwapBigEndian(); } }#endif // _BIG_ENDIAN_ if (UMC_OK == umcRes) { umcRes = rSrcChunk.Ascend(); } }// else// { umcRes = GenerateIndexTable(rSrcChunk); } return umcRes;}StatusAVIIndex::GetMaxChunkSize(const tFOURCC ChunkType, vm_var32& ruiSize){ Status umcRes = UMC_OK; ruiSize = 0; if (NULL == m_pIndTable) { umcRes = UMC_BAD_FORMAT; } assert(NULL == m_pIndTable || 0 != m_uiTblSize); if (UMC_OK == umcRes) { for (vm_var32 i = 0; i < m_uiTblSize; i++) { if (ChunkType == m_pIndTable[i].ChunkType && ruiSize < m_pIndTable[i].uiSize) { ruiSize = m_pIndTable[i].uiSize; } } } if (UMC_OK == umcRes && 0 == ruiSize) { umcRes = UMC_BAD_FORMAT; } return umcRes;}StatusAVIIndex::GetIndexTableEntry(vm_var32 uiIndex, IndTblEntry& rEntry){ Status umcRes = UMC_OK; if (uiIndex >= m_uiTblSize) { umcRes = UMC_OPERATION_FAILED; } else { rEntry = m_pIndTable[uiIndex]; } return umcRes;}StatusAVIIndex::GetFrameByPos(double dfPos, const tFOURCC fourccCode, vm_sizet& ruiFilePos, vm_var32& ruiFrameNum, vm_sizet& ruiCurStreamByte){ Status umcRes = UMC_OK; assert(0.0 <= dfPos && 1.0 >= dfPos); if (0 == m_uiTblSize || NULL == m_pIndTable) { umcRes = UMC_NOT_INITIALIZED; } vm_var32 uiFrameNum = 0; if (UMC_OK == umcRes) { vm_var32 i = 0; for (i = 0; i < m_uiTblSize; i++) { if (fourccCode == m_pIndTable[i].ChunkType) { uiFrameNum++; } } if (0 == uiFrameNum) { umcRes = UMC_BAD_FORMAT; } } if (UMC_OK == umcRes) { ruiFrameNum = static_cast<vm_var32>(uiFrameNum * dfPos); ruiCurStreamByte = 0; uiFrameNum = 0; vm_var32 i = 0; while (i < m_uiTblSize && uiFrameNum < ruiFrameNum) { if (fourccCode == m_pIndTable[i].ChunkType) { uiFrameNum++; ruiCurStreamByte += m_pIndTable[i].uiSize; } i++; } if (uiFrameNum == ruiFrameNum) { if (0 < i) i--; ruiFilePos = m_pIndTable[i].uiPos; } } return umcRes;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -