isma.cpp
资源名称:NETVIDEO.rar [点击查看]
上传用户:sun1608
上传日期:2007-02-02
资源大小:6116k
文件大小:20k
源码类别:
流媒体/Mpeg4/MP4
开发平台:
Visual C++
- /*
- * 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. All Rights Reserved.
- *
- * Contributor(s):
- * Dave Mackie dmackie@cisco.com
- */
- #include "mp4common.h"
- static u_int8_t BifsV2Config[3] = {
- 0x00, 0x00, 0x40 // IsCommandStream
- };
- void MP4File::MakeIsmaCompliant(bool addIsmaComplianceSdp)
- {
- ProtectWriteOperation("MP4MakeIsmaCompliant");
- if (m_useIsma) {
- // already done
- return;
- }
- m_useIsma = true;
- // find first audio and/or video tracks
- MP4TrackId audioTrackId = MP4_INVALID_TRACK_ID;
- try {
- audioTrackId = FindTrackId(0, MP4_AUDIO_TRACK_TYPE);
- }
- catch (MP4Error* e) {
- delete e;
- }
- MP4TrackId videoTrackId = MP4_INVALID_TRACK_ID;
- try {
- videoTrackId = FindTrackId(0, MP4_VIDEO_TRACK_TYPE);
- }
- catch (MP4Error* e) {
- delete e;
- }
- u_int64_t fileMsDuration =
- ConvertFromMovieDuration(GetDuration(), MP4_MSECS_TIME_SCALE);
- // delete any existing OD track
- if (m_odTrackId != MP4_INVALID_TRACK_ID) {
- DeleteTrack(m_odTrackId);
- }
- AddODTrack();
- SetODProfileLevel(0xFF);
- if (audioTrackId != MP4_INVALID_TRACK_ID) {
- AddTrackToOd(audioTrackId);
- }
- if (videoTrackId != MP4_INVALID_TRACK_ID) {
- AddTrackToOd(videoTrackId);
- }
- // delete any existing scene track
- MP4TrackId sceneTrackId = MP4_INVALID_TRACK_ID;
- try {
- sceneTrackId = FindTrackId(0, MP4_SCENE_TRACK_TYPE);
- }
- catch (MP4Error *e) {
- delete e;
- }
- if (sceneTrackId != MP4_INVALID_TRACK_ID) {
- DeleteTrack(sceneTrackId);
- }
- // add scene track
- sceneTrackId = AddSceneTrack();
- SetSceneProfileLevel(0xFF);
- SetGraphicsProfileLevel(0xFF);
- SetTrackIntegerProperty(sceneTrackId,
- "mdia.minf.stbl.stsd.mp4s.esds.decConfigDescr.objectTypeId",
- MP4SystemsV2ObjectType);
- SetTrackESConfiguration(sceneTrackId,
- BifsV2Config, sizeof(BifsV2Config));
- u_int8_t* pBytes = NULL;
- u_int64_t numBytes = 0;
- // write OD Update Command
- CreateIsmaODUpdateCommandFromFileForFile(
- m_odTrackId,
- audioTrackId,
- videoTrackId,
- &pBytes,
- &numBytes);
- WriteSample(m_odTrackId, pBytes, numBytes, fileMsDuration);
- MP4Free(pBytes);
- pBytes = NULL;
- // write BIFS Scene Replace Command
- CreateIsmaSceneCommand(
- MP4_IS_VALID_TRACK_ID(audioTrackId),
- MP4_IS_VALID_TRACK_ID(videoTrackId),
- &pBytes,
- &numBytes);
- WriteSample(sceneTrackId, pBytes, numBytes, fileMsDuration);
- MP4Free(pBytes);
- pBytes = NULL;
- // add session level sdp
- CreateIsmaIodFromFile(
- m_odTrackId,
- sceneTrackId,
- audioTrackId,
- videoTrackId,
- &pBytes,
- &numBytes);
- char* iodBase64 = MP4ToBase64(pBytes, numBytes);
- char* sdpBuf = (char*)MP4Calloc(strlen(iodBase64) + 256);
- if (addIsmaComplianceSdp) {
- strcpy(sdpBuf, "a=isma-compliance:1,1.0,1 15 12");
- }
- sprintf(&sdpBuf[strlen(sdpBuf)],
- "a=mpeg4-iod: