📄 mp4.cpp
字号:
/* * The contents of this file are subject to the Mozilla Public * License Version 1.1 (the "License"); you may not use this file * except in compliance with the License. You may obtain a copy of * the License at http://www.mozilla.org/MPL/ * * Software distributed under the License is distributed on an "AS * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or * implied. See the License for the specific language governing * rights and limitations under the License. * * The Original Code is MPEG4IP. * * The Initial Developer of the Original Code is Cisco Systems Inc. * Portions created by Cisco Systems Inc. are * Copyright (C) Cisco Systems Inc. 2001 - 2005. All Rights Reserved. * * 3GPP features implementation is based on 3GPP's TS26.234-v5.60, * and was contributed by Ximpo Group Ltd. * * Portions created by Ximpo Group Ltd. are * Copyright (C) Ximpo Group Ltd. 2003, 2004. All Rights Reserved. * * Contributor(s): * Dave Mackie dmackie@cisco.com * Alix Marchandise-Franquet alix@cisco.com * Ximpo Group Ltd. mp4v2@ximpo.com * Bill May wmay@cisco.com *//* * MP4 library API functions * * These are wrapper functions that provide C linkage conventions * to the library, and catch any internal errors, ensuring that * a proper return value is given. */#include "mp4common.h"#define PRINT_ERROR(e) \ VERBOSE_ERROR(((MP4File*)hFile)->GetVerbosity(), e->Print());/* file operations */// benski> extern "C" MP4FileHandle MP4ReadEx (const char* fileName, void *user, struct Virtual_IO *virtual_IO, u_int32_t verbosity){ MP4File* pFile = NULL; try { pFile = new MP4File(verbosity); pFile->ReadEx(fileName, user, virtual_IO); return (MP4FileHandle)pFile; } catch (MP4Error* e) { VERBOSE_ERROR(verbosity, e->Print()); delete e; delete pFile; return MP4_INVALID_FILE_HANDLE; }}extern "C" MP4FileHandle MP4Read(const char* fileName, u_int32_t verbosity){ MP4File* pFile = NULL; try { pFile = new MP4File(verbosity); pFile->Read(fileName); return (MP4FileHandle)pFile; } catch (MP4Error* e) { VERBOSE_ERROR(verbosity, e->Print()); delete e; delete pFile; return MP4_INVALID_FILE_HANDLE; }}extern "C" MP4FileHandle MP4Create (const char* fileName, u_int32_t verbosity, u_int32_t flags){ return MP4CreateEx(fileName, verbosity, flags);}extern "C" MP4FileHandle MP4CreateEx (const char* fileName, u_int32_t verbosity, u_int32_t flags, int add_ftyp, int add_iods, char* majorBrand, u_int32_t minorVersion, char** supportedBrands, u_int32_t supportedBrandsCount){ MP4File* pFile = NULL; try { pFile = new MP4File(verbosity); // LATER useExtensibleFormat, moov first, then mvex's pFile->Create(fileName, flags, add_ftyp, add_iods, majorBrand, minorVersion, supportedBrands, supportedBrandsCount); return (MP4FileHandle)pFile; } catch (MP4Error* e) { VERBOSE_ERROR(verbosity, e->Print()); delete e; delete pFile; return MP4_INVALID_FILE_HANDLE; }}extern "C" MP4FileHandle MP4Modify(const char* fileName, u_int32_t verbosity, u_int32_t flags){ MP4File* pFile = NULL; try { pFile = new MP4File(verbosity); // LATER useExtensibleFormat, moov first, then mvex's if (pFile->Modify(fileName)) return (MP4FileHandle)pFile; } catch (MP4Error* e) { VERBOSE_ERROR(verbosity, e->Print()); delete e; } if (pFile) delete pFile; return MP4_INVALID_FILE_HANDLE;}extern "C" bool MP4Optimize(const char* existingFileName, const char* newFileName, u_int32_t verbosity){ try { MP4File* pFile = new MP4File(verbosity); pFile->Optimize(existingFileName, newFileName); delete pFile; return true; } catch (MP4Error* e) { VERBOSE_ERROR(verbosity, e->Print()); delete e; } return false;}extern "C" void MP4Close(MP4FileHandle hFile){ if (MP4_IS_VALID_FILE_HANDLE(hFile)) { try { ((MP4File*)hFile)->Close(); delete (MP4File*)hFile; return; } catch (MP4Error* e) { PRINT_ERROR(e); delete e; } } return ;}extern "C" bool MP4Dump( MP4FileHandle hFile, FILE* pDumpFile, bool dumpImplicits){ if (MP4_IS_VALID_FILE_HANDLE(hFile)) { try { ((MP4File*)hFile)->Dump(pDumpFile, dumpImplicits); return true; } catch (MP4Error* e) { PRINT_ERROR(e); delete e; } } return false;}/* specific file properties */extern "C" u_int32_t MP4GetVerbosity(MP4FileHandle hFile){ if (MP4_IS_VALID_FILE_HANDLE(hFile)) { try { return ((MP4File*)hFile)->GetVerbosity(); } catch (MP4Error* e) { PRINT_ERROR(e); delete e; } } return 0;}extern "C" void MP4SetVerbosity(MP4FileHandle hFile, u_int32_t verbosity){ if (MP4_IS_VALID_FILE_HANDLE(hFile)) { try { ((MP4File*)hFile)->SetVerbosity(verbosity); return; } catch (MP4Error* e) { PRINT_ERROR(e); delete e; } } return;}extern "C" MP4Duration MP4GetDuration(MP4FileHandle hFile){ if (MP4_IS_VALID_FILE_HANDLE(hFile)) { try { return ((MP4File*)hFile)->GetDuration(); } catch (MP4Error* e) { PRINT_ERROR(e); delete e; } } return MP4_INVALID_DURATION;}extern "C" u_int32_t MP4GetTimeScale(MP4FileHandle hFile){ if (MP4_IS_VALID_FILE_HANDLE(hFile)) { try { return ((MP4File*)hFile)->GetTimeScale(); } catch (MP4Error* e) { PRINT_ERROR(e); delete e; } } return 0;}extern "C" bool MP4SetTimeScale(MP4FileHandle hFile, u_int32_t value){ if (MP4_IS_VALID_FILE_HANDLE(hFile)) { try { ((MP4File*)hFile)->SetTimeScale(value); return true; } catch (MP4Error* e) { PRINT_ERROR(e); delete e; } } return false;}extern "C" u_int8_t MP4GetODProfileLevel(MP4FileHandle hFile){ if (MP4_IS_VALID_FILE_HANDLE(hFile)) { try { return ((MP4File*)hFile)->GetODProfileLevel(); } catch (MP4Error* e) { PRINT_ERROR(e); delete e; } } return 0;}extern "C" bool MP4SetODProfileLevel(MP4FileHandle hFile, u_int8_t value){ if (MP4_IS_VALID_FILE_HANDLE(hFile)) { try { ((MP4File*)hFile)->SetODProfileLevel(value); return true; } catch (MP4Error* e) { PRINT_ERROR(e); delete e; } } return false;}extern "C" u_int8_t MP4GetSceneProfileLevel(MP4FileHandle hFile){ if (MP4_IS_VALID_FILE_HANDLE(hFile)) { try { return ((MP4File*)hFile)->GetSceneProfileLevel(); } catch (MP4Error* e) { PRINT_ERROR(e); delete e; } } return 0;}extern "C" bool MP4SetSceneProfileLevel(MP4FileHandle hFile, u_int8_t value){ if (MP4_IS_VALID_FILE_HANDLE(hFile)) { try { ((MP4File*)hFile)->SetSceneProfileLevel(value); return true; } catch (MP4Error* e) { PRINT_ERROR(e); delete e; } } return false;}extern "C" u_int8_t MP4GetVideoProfileLevel(MP4FileHandle hFile, MP4TrackId trackId){ if (MP4_IS_VALID_FILE_HANDLE(hFile)) { try { return ((MP4File*)hFile)->GetVideoProfileLevel(); } catch (MP4Error* e) { PRINT_ERROR(e); delete e; } if (MP4_IS_VALID_TRACK_ID(trackId)) { uint8_t *foo; uint32_t bufsize; uint8_t type; // for mpeg4 video tracks, try to look for the VOSH header, // which has this info. type = MP4GetTrackEsdsObjectTypeId(hFile, trackId); if (type == MP4_MPEG4_VIDEO_TYPE) { if (MP4GetTrackESConfiguration(hFile, trackId, &foo, &bufsize)) { uint8_t *ptr = foo; while (bufsize > 0) { if (htonl(*(uint32_t *)ptr) == 0x1b0) { uint8_t ret = ptr[4]; free(foo); return ret; } ptr++; bufsize--; } free(foo); } } } } return 0;}extern "C" void MP4SetVideoProfileLevel(MP4FileHandle hFile, u_int8_t value){ if (MP4_IS_VALID_FILE_HANDLE(hFile)) { try { ((MP4File*)hFile)->SetVideoProfileLevel(value); return ; } catch (MP4Error* e) { PRINT_ERROR(e); delete e; } } return ;}extern "C" u_int8_t MP4GetAudioProfileLevel(MP4FileHandle hFile){ if (MP4_IS_VALID_FILE_HANDLE(hFile)) { try { return ((MP4File*)hFile)->GetAudioProfileLevel(); } catch (MP4Error* e) { PRINT_ERROR(e); delete e; } } return 0;}extern "C" void MP4SetAudioProfileLevel(MP4FileHandle hFile, u_int8_t value){ if (MP4_IS_VALID_FILE_HANDLE(hFile)) { try { ((MP4File*)hFile)->SetAudioProfileLevel(value); } catch (MP4Error* e) { PRINT_ERROR(e); delete e; } }}extern "C" u_int8_t MP4GetGraphicsProfileLevel(MP4FileHandle hFile){ if (MP4_IS_VALID_FILE_HANDLE(hFile)) { try { return ((MP4File*)hFile)->GetGraphicsProfileLevel(); } catch (MP4Error* e) { PRINT_ERROR(e); delete e; } } return 0;}extern "C" bool MP4SetGraphicsProfileLevel(MP4FileHandle hFile, u_int8_t value){ if (MP4_IS_VALID_FILE_HANDLE(hFile)) { try { ((MP4File*)hFile)->SetGraphicsProfileLevel(value); return true; } catch (MP4Error* e) { PRINT_ERROR(e); delete e; } } return false;}/* generic file properties */extern "C" bool MP4HaveAtom (MP4FileHandle hFile, const char *atomName){ if (MP4_IS_VALID_FILE_HANDLE(hFile)) { try { return ((MP4File *)hFile)->FindAtom(atomName) != NULL; } catch (MP4Error *e) { PRINT_ERROR(e); delete e; } } return false;}extern "C" bool MP4GetIntegerProperty( MP4FileHandle hFile, const char* propName, u_int64_t *retvalue){ if (MP4_IS_VALID_FILE_HANDLE(hFile)) { try { *retvalue = ((MP4File*)hFile)->GetIntegerProperty(propName); return true; } catch (MP4Error* e) { PRINT_ERROR(e); delete e; } } return false;}extern "C" bool MP4GetFloatProperty( MP4FileHandle hFile, const char* propName, float *retvalue){ if (MP4_IS_VALID_FILE_HANDLE(hFile)) { try { *retvalue = ((MP4File*)hFile)->GetFloatProperty(propName); return true; } catch (MP4Error* e) { PRINT_ERROR(e); delete e; } } return false;}extern "C" bool MP4GetStringProperty( MP4FileHandle hFile, const char* propName, const char **retvalue){ if (MP4_IS_VALID_FILE_HANDLE(hFile)) { try { *retvalue = ((MP4File*)hFile)->GetStringProperty(propName); return true; } catch (MP4Error* e) { PRINT_ERROR(e); delete e; } } return false;}extern "C" bool MP4GetBytesProperty( MP4FileHandle hFile, const char* propName, u_int8_t** ppValue, u_int32_t* pValueSize){ if (MP4_IS_VALID_FILE_HANDLE(hFile)) { try { ((MP4File*)hFile)->GetBytesProperty(propName, ppValue, pValueSize); return true; } catch (MP4Error* e) { PRINT_ERROR(e); delete e; } } *ppValue = NULL; *pValueSize = 0; return false;}extern "C" bool MP4SetIntegerProperty( MP4FileHandle hFile, const char* propName, int64_t value){ if (MP4_IS_VALID_FILE_HANDLE(hFile)) { try { ((MP4File*)hFile)->SetIntegerProperty(propName, value); return true; } catch (MP4Error* e) { PRINT_ERROR(e); delete e; } } return false;}extern "C" bool MP4SetFloatProperty( MP4FileHandle hFile, const char* propName, float value){ if (MP4_IS_VALID_FILE_HANDLE(hFile)) { try { ((MP4File*)hFile)->SetFloatProperty(propName, value); return true; } catch (MP4Error* e) { PRINT_ERROR(e); delete e; } } return false;}extern "C" bool MP4SetStringProperty( MP4FileHandle hFile, const char* propName, const char* value){ if (MP4_IS_VALID_FILE_HANDLE(hFile)) { try { ((MP4File*)hFile)->SetStringProperty(propName, value); return true; } catch (MP4Error* e) { PRINT_ERROR(e); delete e; } } return false;}extern "C" bool MP4SetBytesProperty( MP4FileHandle hFile, const char* propName, const u_int8_t* pValue, u_int32_t valueSize){ if (MP4_IS_VALID_FILE_HANDLE(hFile)) { try { ((MP4File*)hFile)->SetBytesProperty(propName, pValue, valueSize); return true; } catch (MP4Error* e) { PRINT_ERROR(e); delete e; } } return false;}/* track operations */extern "C" MP4TrackId MP4AddTrack( MP4FileHandle hFile, const char* type){ if (MP4_IS_VALID_FILE_HANDLE(hFile)) { try { return ((MP4File*)hFile)->AddSystemsTrack(type); } catch (MP4Error* e) { PRINT_ERROR(e); delete e; } } return MP4_INVALID_TRACK_ID;}extern "C" MP4TrackId MP4AddSystemsTrack( MP4FileHandle hFile, const char* type){ if (MP4_IS_VALID_FILE_HANDLE(hFile)) { try { return ((MP4File*)hFile)->AddSystemsTrack(type); } catch (MP4Error* e) { PRINT_ERROR(e); delete e; } } return MP4_INVALID_TRACK_ID;}extern "C" MP4TrackId MP4AddODTrack(MP4FileHandle hFile){ if (MP4_IS_VALID_FILE_HANDLE(hFile)) { try {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -