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

📄 mp4.cpp

📁 网络MPEG4IP流媒体开发源代码
💻 CPP
📖 第 1 页 / 共 4 页
字号:
	if (MP4_IS_VALID_FILE_HANDLE(hFile)) {		try {			((MP4File*)hFile)->ReadRtpHint(				hintTrackId, hintSampleId, pNumPackets);			return true;		}		catch (MP4Error* e) {			PRINT_ERROR(e);			delete e;		}	}	return false;}extern "C" u_int16_t MP4GetRtpHintNumberOfPackets(	MP4FileHandle hFile,	MP4TrackId hintTrackId){	if (MP4_IS_VALID_FILE_HANDLE(hFile)) {		try {			return ((MP4File*)hFile)->GetRtpHintNumberOfPackets(hintTrackId);		}		catch (MP4Error* e) {			PRINT_ERROR(e);			delete e;		}	}	return 0;}extern "C" int8_t MP4GetRtpPacketBFrame(	MP4FileHandle hFile,	MP4TrackId hintTrackId,	u_int16_t packetIndex){	if (MP4_IS_VALID_FILE_HANDLE(hFile)) {		try {			return ((MP4File*)hFile)->				GetRtpPacketBFrame(hintTrackId, packetIndex);		}		catch (MP4Error* e) {			PRINT_ERROR(e);			delete e;		}	}	return -1;}extern "C" int32_t MP4GetRtpPacketTransmitOffset(	MP4FileHandle hFile,	MP4TrackId hintTrackId,	u_int16_t packetIndex){	if (MP4_IS_VALID_FILE_HANDLE(hFile)) {		try {			return ((MP4File*)hFile)->				GetRtpPacketTransmitOffset(hintTrackId, packetIndex);		}		catch (MP4Error* e) {			PRINT_ERROR(e);			delete e;		}	}	return 0;}extern "C" bool MP4ReadRtpPacket(	MP4FileHandle hFile,	MP4TrackId hintTrackId,	u_int16_t packetIndex,	u_int8_t** ppBytes, 	u_int32_t* pNumBytes,	u_int32_t ssrc,	bool includeHeader,	bool includePayload){	if (MP4_IS_VALID_FILE_HANDLE(hFile)) {		try {			((MP4File*)hFile)->ReadRtpPacket(				hintTrackId, packetIndex, 				ppBytes, pNumBytes, 				ssrc, includeHeader, includePayload);			return true;		}		catch (MP4Error* e) {			PRINT_ERROR(e);			delete e;		}	}	return false;}extern "C" MP4Timestamp MP4GetRtpTimestampStart(	MP4FileHandle hFile,	MP4TrackId hintTrackId){	if (MP4_IS_VALID_FILE_HANDLE(hFile)) {		try {			return ((MP4File*)hFile)->GetRtpTimestampStart(hintTrackId);		}		catch (MP4Error* e) {			PRINT_ERROR(e);			delete e;		}	}	return MP4_INVALID_TIMESTAMP;}extern "C" bool MP4SetRtpTimestampStart(	MP4FileHandle hFile,	MP4TrackId hintTrackId,	MP4Timestamp rtpStart){	if (MP4_IS_VALID_FILE_HANDLE(hFile)) {		try {			((MP4File*)hFile)->SetRtpTimestampStart(				hintTrackId, rtpStart);			return true;		}		catch (MP4Error* e) {			PRINT_ERROR(e);			delete e;		}	}	return false;}extern "C" bool MP4AddRtpHint(	MP4FileHandle hFile,	MP4TrackId hintTrackId){	return MP4AddRtpVideoHint(hFile, hintTrackId, false, 0);}extern "C" bool MP4AddRtpVideoHint(	MP4FileHandle hFile,	MP4TrackId hintTrackId,	bool isBframe, 	u_int32_t timestampOffset){	if (MP4_IS_VALID_FILE_HANDLE(hFile)) {		try {			((MP4File*)hFile)->AddRtpHint(hintTrackId, 				isBframe, timestampOffset);			return true;		}		catch (MP4Error* e) {			PRINT_ERROR(e);			delete e;		}	}	return false;}extern "C" bool MP4AddRtpPacket(	MP4FileHandle hFile,	MP4TrackId hintTrackId,	bool setMbit,	int32_t transmitOffset){	if (MP4_IS_VALID_FILE_HANDLE(hFile)) {		try {			((MP4File*)hFile)->AddRtpPacket(				hintTrackId, setMbit, transmitOffset);			return true;		}		catch (MP4Error* e) {			PRINT_ERROR(e);			delete e;		}	}	return false;}extern "C" bool MP4AddRtpImmediateData(	MP4FileHandle hFile,	MP4TrackId hintTrackId,	const u_int8_t* pBytes,	u_int32_t numBytes){	if (MP4_IS_VALID_FILE_HANDLE(hFile)) {		try {			((MP4File*)hFile)->AddRtpImmediateData(hintTrackId, 				pBytes, numBytes);			return true;		}		catch (MP4Error* e) {			PRINT_ERROR(e);			delete e;		}	}	return false;}extern "C" bool MP4AddRtpSampleData(	MP4FileHandle hFile,	MP4TrackId hintTrackId,	MP4SampleId sampleId,	u_int32_t dataOffset,	u_int32_t dataLength){	if (MP4_IS_VALID_FILE_HANDLE(hFile)) {		try {			((MP4File*)hFile)->AddRtpSampleData(				hintTrackId, sampleId, dataOffset, dataLength);			return true;		}		catch (MP4Error* e) {			PRINT_ERROR(e);			delete e;		}	}	return false;}extern "C" bool MP4AddRtpESConfigurationPacket(	MP4FileHandle hFile,	MP4TrackId hintTrackId){	if (MP4_IS_VALID_FILE_HANDLE(hFile)) {		try {			((MP4File*)hFile)->AddRtpESConfigurationPacket(hintTrackId);			return true;		}		catch (MP4Error* e) {			PRINT_ERROR(e);			delete e;		}	}	return false;}extern "C" bool MP4WriteRtpHint(	MP4FileHandle hFile,	MP4TrackId hintTrackId,	MP4Duration duration,	bool isSyncSample){	if (MP4_IS_VALID_FILE_HANDLE(hFile)) {		try {			((MP4File*)hFile)->WriteRtpHint(				hintTrackId, duration, isSyncSample);			return true;		}		catch (MP4Error* e) {			PRINT_ERROR(e);			delete e;		}	}	return false;}/* ISMA specific operations */extern "C" bool MP4MakeIsmaCompliant(	const char* fileName, 	u_int32_t verbosity,	bool addIsmaComplianceSdp){	MP4File* pFile = NULL;	try {		pFile = new MP4File(verbosity);		pFile->Modify(fileName);		pFile->MakeIsmaCompliant(addIsmaComplianceSdp);		pFile->Close();		delete pFile;		return true;	}	catch (MP4Error* e) {		VERBOSE_ERROR(verbosity, e->Print());		delete e;	}	delete pFile;	return false;}extern "C" char* MP4MakeIsmaSdpIod(	u_int8_t videoProfile,	u_int32_t videoBitrate,	u_int8_t* videoConfig,	u_int32_t videoConfigLength,	u_int8_t audioProfile,	u_int32_t audioBitrate,	u_int8_t* audioConfig,	u_int32_t audioConfigLength,	u_int32_t verbosity){	MP4File* pFile = NULL;	try {		pFile = new MP4File(verbosity);		u_int8_t* pBytes = NULL;		u_int64_t numBytes = 0;		pFile->CreateIsmaIodFromParams(			videoProfile,			videoBitrate,			videoConfig,			videoConfigLength,			audioProfile,			audioBitrate,			audioConfig,			audioConfigLength,			&pBytes,			&numBytes);		char* iodBase64 = 			MP4ToBase64(pBytes, numBytes);		MP4Free(pBytes);		char* sdpIod = 			(char*)MP4Malloc(strlen(iodBase64) + 64);		sprintf(sdpIod,			"a=mpeg4-iod: \042data:application/mpeg4-iod;base64,%s\042",			iodBase64);		MP4Free(iodBase64);		delete pFile;		return sdpIod;	}	catch (MP4Error* e) {		VERBOSE_ERROR(verbosity, e->Print());		delete e;	}	delete pFile;	return NULL;}/* Edit list */extern "C" MP4EditId MP4AddTrackEdit(	MP4FileHandle hFile,	MP4TrackId trackId,	MP4EditId editId,	MP4Timestamp startTime,	MP4Duration duration,	bool dwell){	if (MP4_IS_VALID_FILE_HANDLE(hFile)) {		try {			MP4EditId newEditId =				((MP4File*)hFile)->AddTrackEdit(trackId, editId);			if (newEditId != MP4_INVALID_EDIT_ID) {				((MP4File*)hFile)->SetTrackEditMediaStart(					trackId, newEditId, startTime);				((MP4File*)hFile)->SetTrackEditDuration(					trackId, newEditId, duration);				((MP4File*)hFile)->SetTrackEditDwell(					trackId, newEditId, dwell);			}			return newEditId;		}		catch (MP4Error* e) {			PRINT_ERROR(e);			delete e;		}	}	return MP4_INVALID_EDIT_ID;}extern "C" bool MP4DeleteTrackEdit(	MP4FileHandle hFile,	MP4TrackId trackId,	MP4EditId editId){	if (MP4_IS_VALID_FILE_HANDLE(hFile)) {		try {			((MP4File*)hFile)->DeleteTrackEdit(trackId, editId);			return true;		}		catch (MP4Error* e) {			PRINT_ERROR(e);			delete e;		}	}	return false;}extern "C" u_int32_t MP4GetTrackNumberOfEdits(	MP4FileHandle hFile,	MP4TrackId trackId){	if (MP4_IS_VALID_FILE_HANDLE(hFile)) {		try {			return ((MP4File*)hFile)->GetTrackNumberOfEdits(trackId);		}		catch (MP4Error* e) {			PRINT_ERROR(e);			delete e;		}	}	return 0;}extern "C" MP4Timestamp MP4GetTrackEditMediaStart(	MP4FileHandle hFile,	MP4TrackId trackId,	MP4EditId editId){	if (MP4_IS_VALID_FILE_HANDLE(hFile)) {		try {			return ((MP4File*)hFile)->GetTrackEditMediaStart(				trackId, editId);		}		catch (MP4Error* e) {			PRINT_ERROR(e);			delete e;		}	}	return MP4_INVALID_TIMESTAMP;}extern "C" MP4Duration MP4GetTrackEditTotalDuration(	MP4FileHandle hFile,	MP4TrackId trackId,	MP4EditId editId){	if (MP4_IS_VALID_FILE_HANDLE(hFile)) {		try {			return ((MP4File*)hFile)->GetTrackEditTotalDuration(				trackId, editId);		}		catch (MP4Error* e) {			PRINT_ERROR(e);			delete e;		}	}	return MP4_INVALID_DURATION;}extern "C" bool MP4SetTrackEditMediaStart(	MP4FileHandle hFile,	MP4TrackId trackId,	MP4EditId editId,	MP4Timestamp startTime){	if (MP4_IS_VALID_FILE_HANDLE(hFile)) {		try {			((MP4File*)hFile)->SetTrackEditMediaStart(				trackId, editId, startTime);			return true;		}		catch (MP4Error* e) {			PRINT_ERROR(e);			delete e;		}	}	return false;}extern "C" MP4Duration MP4GetTrackEditDuration(	MP4FileHandle hFile,	MP4TrackId trackId,	MP4EditId editId){	if (MP4_IS_VALID_FILE_HANDLE(hFile)) {		try {			return ((MP4File*)hFile)->GetTrackEditDuration(trackId, editId);		}		catch (MP4Error* e) {			PRINT_ERROR(e);			delete e;		}	}	return MP4_INVALID_DURATION;}extern "C" bool MP4SetTrackEditDuration(	MP4FileHandle hFile,	MP4TrackId trackId,	MP4EditId editId,	MP4Duration duration){	if (MP4_IS_VALID_FILE_HANDLE(hFile)) {		try {			((MP4File*)hFile)->SetTrackEditDuration(trackId, editId, duration);			return true;		}		catch (MP4Error* e) {			PRINT_ERROR(e);			delete e;		}	}	return false;}extern "C" int8_t MP4GetTrackEditDwell(	MP4FileHandle hFile,	MP4TrackId trackId,	MP4EditId editId){	if (MP4_IS_VALID_FILE_HANDLE(hFile)) {		try {			return ((MP4File*)hFile)->GetTrackEditDwell(trackId, editId);		}		catch (MP4Error* e) {			PRINT_ERROR(e);			delete e;		}	}	return -1;}extern "C" bool MP4SetTrackEditDwell(	MP4FileHandle hFile,	MP4TrackId trackId,	MP4EditId editId,	bool dwell){	if (MP4_IS_VALID_FILE_HANDLE(hFile)) {		try {			((MP4File*)hFile)->SetTrackEditDwell(trackId, editId, dwell);			return true;		}		catch (MP4Error* e) {			PRINT_ERROR(e);			delete e;		}	}	return false;}extern "C" bool MP4ReadSampleFromEditTime(	/* input parameters */	MP4FileHandle hFile,	MP4TrackId trackId, 	MP4Timestamp when,	/* output parameters */	u_int8_t** ppBytes, 	u_int32_t* pNumBytes, 	MP4Timestamp* pStartTime, 	MP4Duration* pDuration,	MP4Duration* pRenderingOffset, 	bool* pIsSyncSample){	MP4SampleId sampleId = 		MP4GetSampleIdFromEditTime(			hFile,			trackId, 			when, 			pStartTime,			pDuration);	return MP4ReadSample(		hFile,		trackId, 		sampleId, 		ppBytes, 		pNumBytes, 		NULL,		NULL, 		pRenderingOffset, 		pIsSyncSample);}extern "C" MP4SampleId MP4GetSampleIdFromEditTime(	MP4FileHandle hFile,	MP4TrackId trackId, 	MP4Timestamp when,	MP4Timestamp* pStartTime,	MP4Duration* pDuration){	if (MP4_IS_VALID_FILE_HANDLE(hFile)) {		try {			return ((MP4File*)hFile)->GetSampleIdFromEditTime(				trackId, when, pStartTime, pDuration);		}		catch (MP4Error* e) {			PRINT_ERROR(e);			delete e;		}	}	return MP4_INVALID_SAMPLE_ID;}/* Utlities */extern "C" char* MP4BinaryToBase16(	const u_int8_t* pData, 	u_int32_t dataSize){	if (pData || dataSize == 0) {		try {			return MP4ToBase16(pData, dataSize);		}		catch (MP4Error* e) {			delete e;		}	}	return NULL;}extern "C" char* MP4BinaryToBase64(	const u_int8_t* pData, 	u_int32_t dataSize){	if (pData || dataSize == 0) {		try {			return MP4ToBase64(pData, dataSize);		}		catch (MP4Error* e) {			delete e;		}	}	return NULL;}

⌨️ 快捷键说明

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