void MP4File::MakeIsmaCompliant(bool addIsmaComplianceSdp) { ProtectWriteOperation("MP4MakeIsmaCompliant"); if (m_useIsma) { // already done return; } // 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; } const char *audio_media_data_name, *video_media_data_name; audio_media_data_name = MP4GetTrackMediaDataName(this, audioTrackId); if (!(ATOMID(audio_media_data_name) == ATOMID("mp4a") || ATOMID(audio_media_data_name) == ATOMID("enca"))) { VERBOSE_ERROR(m_verbosity, printf("MakeIsmaCompliant:can't make ISMA compliant when file contains an %s track\n", audio_media_data_name); );
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\015\012"); } sprintf(&sdpBuf[strlen(sdpBuf)], "a=mpeg4-iod: \042data:application/mpeg4-iod;base64,%s\042\015\012", iodBase64); SetSessionSdp(sdpBuf); VERBOSE_ISMA(GetVerbosity(), printf("IOD SDP = %s\n", sdpBuf)); MP4Free(iodBase64); iodBase64 = NULL; MP4Free(pBytes); pBytes = NULL; MP4Free(sdpBuf); sdpBuf = NULL; }