📄 umc_vob_reader.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_vob_reader.h"#include "ippdefs.h"#include "ipps.h"#include "vm_debug.h"#include "vm_strings.h"#include "umc_dynamic_cast.h"UMC::VobReader::VobReader(){ m_vob_size = NULL; m_vob_dig = NULL; m_vob_list = NULL;}UMC::VobReader::~VobReader(){Close();}UMC::StatusUMC::VobReader::Init(DataReaderParams *pInit){UMC::Status umcRes = UMC_OK;FileReaderParams* initVobExt = DynamicCast<FileReaderParams, DataReaderParams>(pInit);if(!initVobExt)return UMC_NULL_PTR;m_vob_num = 0; m_vob_current = 0;m_vob_size_sum = 0;umcRes = FindVobFiles(initVobExt->m_file_name);if (UMC_OK != umcRes)return umcRes;UMC::FileReaderParams FileParams; FileParams.m_portion_size = 0; vm_string_strcpy(FileParams.m_file_name, m_vob_list[m_vob_current]);vm_debug_trace(-1, VM_STRING("Init.Open %d\n"),m_vob_current);umcRes = FileReaderCur.Init(&FileParams);return umcRes;}UMC::Status UMC::VobReader::Close(){ UMC::Status umcRes = UMC_OK; umcRes = FileReaderCur.Close();//FileReaderNxt.Close(); if(m_vob_size) { free(m_vob_size); } if(m_vob_dig) { free(m_vob_dig); } if(m_vob_list) { for(int j=0; j<m_vob_num; j++) { if(m_vob_list[j]) { free(m_vob_list[j]); } } free(m_vob_list); }return umcRes;}UMC::Status UMC::VobReader::Reset(){ UMC::Status umcRes = UMC_OK; UMC::FileReaderParams FileParams;if(m_vob_current == 0) {umcRes = FileReaderCur.Reset();return umcRes;} umcRes = FileReaderCur.Close();if(umcRes == UMC_OK) {m_vob_current = 0; vm_string_strcpy(FileParams.m_file_name, m_vob_list[m_vob_current]);umcRes = FileReaderCur.Init(&FileParams);}return umcRes;}UMC::Status UMC::VobReader::ReadData(void *data, vm_var32 *nsize){ UMC::Status umcRes;if( (m_vob_size[m_vob_current]-FileReaderCur.GetPosition()) < *nsize ) { umcRes = FileReaderCur.GetData(data,nsize); if(m_vob_current < m_vob_num){vm_debug_trace(-1, VM_STRING("GetData.Close %d\n"),m_vob_current); umcRes = FileReaderCur.Close(); if (UMC_OK != umcRes) return umcRes; UMC::FileReaderParams FileParams; FileParams.m_portion_size = 0; vm_string_strcpy(FileParams.m_file_name, m_vob_list[++m_vob_current]);vm_debug_trace(-1, VM_STRING("GetData.Open %d\n"),m_vob_current);umcRes = FileReaderCur.Init(&FileParams); if (UMC_OK != umcRes) return umcRes; } else { return UMC_END_OF_STREAM; } } else { umcRes = FileReaderCur.GetData(data,nsize); if (UMC_END_OF_STREAM == umcRes) { umcRes = UMC_OK; } }return umcRes;}UMC::Status UMC::VobReader::CacheData(void *data, vm_var32 *nsize, int how_far){return FileReaderCur.CheckData(data, nsize, how_far);}UMC::Status UMC::VobReader::MovePosition(vm_sizet npos){UMC::Status umcRes = UMC_OK; vm_sizet curr_pos = FileReaderCur.GetPosition(); vm_sizet curr_sum = 0; vm_sizet shift_pos = npos; int i = 0; int curr_vob = m_vob_current; if((curr_pos + npos) >= (m_vob_size[m_vob_current]-4)){if(m_vob_current < m_vob_num){vm_debug_trace(-1, VM_STRING("MovePosition.Close %d\n"),curr_vob); FileReaderCur.Close(); if (UMC_OK != umcRes) return umcRes; UMC::FileReaderParams FileParams; FileParams.m_portion_size = 0; while(1) { curr_sum += m_vob_size[curr_vob]; if ((curr_pos + shift_pos) < (curr_sum-4)) break;if(npos >= m_vob_size[curr_vob]) npos -= m_vob_size[curr_vob]; curr_vob++; }if(curr_vob >= m_vob_num) return UMC_END_OF_STREAM; m_vob_current = curr_vob; vm_string_strcpy(FileParams.m_file_name, m_vob_list[m_vob_current]);vm_debug_trace(-1, VM_STRING("MovePosition.Open %d\n"),m_vob_current); umcRes = FileReaderCur.Init(&FileParams);} else {return UMC_END_OF_STREAM;}} umcRes = FileReaderCur.MovePosition(npos); FileReaderCur.StartReadingAfterReposition();if (UMC_OK != umcRes)return umcRes; return umcRes;}vm_sizet UMC::VobReader::GetPosition(){ vm_sizet pos = 0; for(int i = 0;i<m_vob_current;i++){ pos = pos + m_vob_size[i]; } pos = pos + FileReaderCur.GetPosition(); return pos;}UMC::Status UMC::VobReader::SetPosition(double position){vm_var64s pos_1 = (vm_var64s)((double)(vm_var64s)m_vob_size_sum*position);vm_var64s pos_2 = 0;int num = 0; int curr_num = 0;double set_pos = 0.;for(int i = 0;i<m_vob_num;i++){pos_2 += m_vob_size[i];num = i; if (pos_2 > pos_1) {break; } curr_num = i;} pos_2 = pos_2 - m_vob_size[num]; pos_1 = pos_1 - pos_2;set_pos = (double)pos_1/(double)(vm_var64s)m_vob_size[curr_num]; if (m_vob_current != curr_num) { Status umcRes = UMC_OK;vm_debug_trace(-1, VM_STRING("SetPosition(double).Close %d\n"),m_vob_current); FileReaderCur.Close(); if (UMC_OK != umcRes) return umcRes; UMC::FileReaderParams FileParams; FileParams.m_portion_size = 0; m_vob_current = curr_num; vm_string_strcpy(FileParams.m_file_name, m_vob_list[m_vob_current]);vm_debug_trace(-1, VM_STRING("SetPosition.Open %d\n"),m_vob_current); umcRes = FileReaderCur.Init(&FileParams); } FileReaderCur.SetPosition(set_pos); return FileReaderCur.StartReadingAfterReposition();}vm_sizet UMC::VobReader::GetSize(){ return (vm_sizet)m_vob_size_sum;}UMC::Status UMC::VobReader::FindVobFiles(vm_char *file_name){ UMC::Status umcRes = UMC_OK; vm_char fname[MAXIMUM_PATH];vm_mmap m_mmap; vm_char* tmp_ptr;VobStruct *vobPrevPtr, *vobCurrentPtr; int skipped_zero;vobPrevPtr = vobCurrentPtr = NULL;m_vob_num = 0;m_vob_size_sum = 0; skipped_zero = 0; vm_string_strcpy(fname, file_name);tmp_ptr = (vm_char*)fname; // find last "_" while (vm_string_strstr(tmp_ptr,VM_STRING("_"))) { tmp_ptr = vm_string_strstr(tmp_ptr,VM_STRING("_")) + 1; } // skip "0" while (vm_string_strstr(tmp_ptr,VM_STRING("0"))) { tmp_ptr = vm_string_strstr(tmp_ptr,VM_STRING("0")) + 1; skipped_zero++; } // detect first number int start_number = 0; vm_string_sscanf(tmp_ptr,VM_STRING("%d"),&start_number);vobCurrentPtr = (VobStruct*)malloc(sizeof(VobStruct)); if (NULL == vobCurrentPtr) return UMC_ALLOC;vobCurrentPtr->prevPtr = NULL; // try to open file by file for(m_vob_num = 0;;m_vob_num++,start_number++) { if ( ( 10 == start_number && skipped_zero) || (100 == start_number && skipped_zero)) { tmp_ptr -= 1; skipped_zero--; } vm_string_sprintf(tmp_ptr,VM_STRING("%d.vob"),start_number); vm_string_strcpy(vobCurrentPtr->vob_name, fname);vobCurrentPtr->vob_size = vm_mmap_create(&m_mmap,vobCurrentPtr->vob_name, FLAG_ATTRIBUTE_READ); vobCurrentPtr->vob_dig = start_number; vm_mmap_close(&m_mmap);m_vob_size_sum += vobCurrentPtr->vob_size; if (vobCurrentPtr->vob_size) { vobPrevPtr = vobCurrentPtr; vobCurrentPtr = (VobStruct*)malloc(sizeof(VobStruct)); if (NULL == vobCurrentPtr) break; vobCurrentPtr->prevPtr = vobPrevPtr; } else { vobCurrentPtr = vobPrevPtr; break; } } if(m_vob_num > 0) { m_vob_size = (vm_var64*)malloc(sizeof(vm_var64)*m_vob_num); m_vob_dig = (int*)malloc(sizeof(int)*m_vob_num); m_vob_list = (vm_char**)malloc(sizeof(vm_char*)*m_vob_num); if (m_vob_size && m_vob_dig && m_vob_list) { for(int j=m_vob_num-1; j>=0; j--){ m_vob_list[j] = (vm_char*)malloc(sizeof(vm_char)*MAXIMUM_PATH); vm_string_strcpy(m_vob_list[j],vobCurrentPtr->vob_name); m_vob_dig[j] = vobCurrentPtr->vob_dig; m_vob_size[j] = vobCurrentPtr->vob_size; vobPrevPtr = vobCurrentPtr; vobCurrentPtr = vobCurrentPtr->prevPtr; if(vobPrevPtr!=NULL) free(vobPrevPtr); } } else { for(int j=m_vob_num-1; j>=0; j--){ vobPrevPtr = vobCurrentPtr; vobCurrentPtr = vobCurrentPtr->prevPtr; if(vobPrevPtr!=NULL) free(vobPrevPtr); } return UMC_ALLOC; } } else { // No VOB files found // NOTE: this is an expected case if the vob_reader is used // in an attempt to parse a media file that is not a VOB return UMC_FAILED_TO_INITIALIZE; }return umcRes;}/*UMC::Status UMC::VobReader::FindVobFiles(vm_char *file_name){ UMC::Status umcRes = UMC_OK; vm_char drive[_MAX_DRIVE]; vm_char dir[_MAX_DIR]; vm_char fname[_MAX_FNAME]; vm_char ext[_MAX_EXT]; vm_char tmp_str[_MAX_FNAME];vm_mmap m_mmap; vm_char *ptr1,*ptr2;VobStruct *vobPrevPtr, *vobCurrentPtr;vobPrevPtr = vobCurrentPtr = NULL;m_vob_num = 0;m_vob_size_sum = 0; vm_string_splitpath( file_name, drive, dir, fname, ext );vm_string_strcpy(tmp_str, fname); int shift = 0;ptr1 = NULL;ptr2 = NULL; while (vm_string_strstr(fname,VM_STRING("_"))) { ptr1 = vm_string_strstr(fname,VM_STRING("_")); shift += (int)(ptr1 + 1 - fname); vm_string_strcpy(fname, ptr1+1); } vm_string_strcpy(fname, tmp_str);if(ptr1 != NULL) vm_string_strcpy(fname+shift, VM_STRING("*.vob"));elsevm_string_strcat(fname, VM_STRING(".vob"));vm_string_makepath(file_name,drive, dir, fname, NULL); vm_finddata_t vob_file;long hFile; if( (hFile = vm_string_findfirst( file_name, &vob_file )) == -1L ) { umcRes = UMC_FAILED_TO_INITIALIZE;} else { vobPrevPtr = (VobStruct*)malloc(sizeof(VobStruct));vm_string_makepath( vobPrevPtr->vob_name, drive, dir, vob_file.name, VM_STRING("") );vm_string_splitpath( vobPrevPtr->vob_name, drive, dir, fname, ext ); vobPrevPtr->prevPtr = NULL; vm_string_strcpy(tmp_str, fname); int shift = 0; ptr1 = NULL; while (vm_string_strstr(fname,VM_STRING("_"))) { ptr1 = vm_string_strstr(fname,VM_STRING("_")); shift += (int)(ptr1 + 1 - fname); vm_string_strcpy(fname, ptr1+1); } vm_string_strcpy(fname, tmp_str);vobPrevPtr->vob_dig = vm_string_atol(fname+shift);vobPrevPtr->vob_size = vm_mmap_create(&m_mmap,vobPrevPtr->vob_name, FLAG_ATTRIBUTE_READ); vm_mmap_close(&m_mmap);m_vob_size_sum = vobPrevPtr->vob_size;vobCurrentPtr = vobPrevPtr; m_vob_num++; while( vm_string_findnext( hFile, &vob_file ) == 0 ) {//if(m_vob_num >= MAX_VOB_NUM) break;vobCurrentPtr = (VobStruct*)malloc(sizeof(VobStruct)); vobCurrentPtr->prevPtr = vobPrevPtr;vm_string_makepath( vobCurrentPtr->vob_name, drive, dir, vob_file.name, VM_STRING("") );vm_string_splitpath( vobCurrentPtr->vob_name, drive, dir, fname, ext ); vm_string_strcpy(tmp_str, fname); int shift = 0; ptr1 = NULL; while (vm_string_strstr(fname,VM_STRING("_"))) { ptr1 = vm_string_strstr(fname,VM_STRING("_")); shift += (int)(ptr1 + 1 - fname); vm_string_strcpy(fname, ptr1+1); } vm_string_strcpy(fname, tmp_str); vobCurrentPtr->vob_dig = vm_string_atol(fname+shift);vobCurrentPtr->vob_size = vm_mmap_create(&m_mmap,vobCurrentPtr->vob_name, FLAG_ATTRIBUTE_READ);vm_mmap_close(&m_mmap); m_vob_size_sum += vobCurrentPtr->vob_size; m_vob_num++;vobPrevPtr = vobCurrentPtr; } _findclose( hFile ); }m_vob_size = (vm_var64*)malloc(sizeof(vm_var64)*m_vob_num);m_vob_dig = (int*)malloc(sizeof(int)*m_vob_num); m_vob_list = (vm_char**)malloc(sizeof(vm_char*)*m_vob_num);for(int j=0; j<m_vob_num; j++){m_vob_list[j] = (vm_char*)malloc(sizeof(vm_char)*MAXIMUM_PATH);memset(m_vob_list[j], 0, MAXIMUM_PATH*sizeof(vm_char));vm_string_strcpy(m_vob_list[j],vobCurrentPtr->vob_name);m_vob_dig[j] = vobCurrentPtr->vob_dig; m_vob_size[j] = vobCurrentPtr->vob_size;vobPrevPtr = vobCurrentPtr; vobCurrentPtr = vobCurrentPtr->prevPtr;if(vobPrevPtr!=NULL) free(vobPrevPtr);}if (UMC_OK == umcRes) { int buf_i; vm_char buf_c[MAXIMUM_PATH]; memset(buf_c, 0, MAXIMUM_PATH*sizeof(vm_char)); for(int i=m_vob_num-1;i>=0;i--){ for(int j=0;j<i;j++){ if(m_vob_dig[j] > m_vob_dig[j+1]) { buf_i = m_vob_dig[j]; m_vob_dig[j] = m_vob_dig[j+1]; m_vob_dig[j+1] = buf_i; vm_string_strcpy(buf_c,m_vob_list[j]); vm_string_strcpy(m_vob_list[j],m_vob_list[j+1]); vm_string_strcpy(m_vob_list[j+1],buf_c);}}}}return umcRes;}*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -