diff Plugins/Input/aac/libmp4v2/mp4file.cpp @ 201:f2dc045d2327 trunk

[svn] libmp4v2 goes back to the future
author chainsaw
date Thu, 17 Nov 2005 14:01:18 -0800
parents 0a2ad94e8607
children
line wrap: on
line diff
--- a/Plugins/Input/aac/libmp4v2/mp4file.cpp	Thu Nov 17 12:21:04 2005 -0800
+++ b/Plugins/Input/aac/libmp4v2/mp4file.cpp	Thu Nov 17 14:01:18 2005 -0800
@@ -13,7 +13,7 @@
  * 
  * The Initial Developer of the Original Code is Cisco Systems Inc.
  * Portions created by Cisco Systems Inc. are
- * Copyright (C) Cisco Systems Inc. 2001 - 2004.  All Rights Reserved.
+ * 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.
@@ -25,6 +25,7 @@
  *		Dave Mackie		  dmackie@cisco.com
  *              Alix Marchandise-Franquet alix@cisco.com
  *              Ximpo Group Ltd.          mp4v2@ximpo.com
+ *              Bill May                  wmay@cisco.com
  */
 
 #include "mp4common.h"
@@ -61,6 +62,11 @@
 MP4File::~MP4File()
 {
 	MP4Free(m_fileName);
+	if (m_pFile != NULL) {
+	  // not closed ?
+	  fclose(m_pFile);
+	  m_pFile = NULL;
+	}
 	delete m_pRootAtom;
 	for (u_int32_t i = 0; i < m_pTracks.Size(); i++) {
 		delete m_pTracks[i];
@@ -1425,7 +1431,40 @@
   return trackId;
 }
 
-
+MP4TrackId MP4File::AddCntlTrackDefault (uint32_t timeScale,
+					 MP4Duration sampleDuration,
+					 const char *type)
+{
+  MP4TrackId trackId = AddTrack(MP4_CNTL_TRACK_TYPE, timeScale);
+
+  InsertChildAtom(MakeTrackName(trackId, "mdia.minf"), "nmhd", 0);
+  AddChildAtom(MakeTrackName(trackId, "mdia.minf.stbl.stsd"), type);
+
+  // stsd is a unique beast in that it has a count of the number 
+  // of child atoms that needs to be incremented after we add the mp4v atom
+  MP4Integer32Property* pStsdCountProperty;
+  FindIntegerProperty(
+		      MakeTrackName(trackId, "mdia.minf.stbl.stsd.entryCount"),
+		      (MP4Property**)&pStsdCountProperty);
+  pStsdCountProperty->IncrementValue();
+  
+  SetTrackIntegerProperty(trackId, 
+			  "mdia.minf.stbl.stsz.sampleSize", sampleDuration);
+  
+  m_pTracks[FindTrackIndex(trackId)]->
+    SetFixedSampleDuration(sampleDuration);
+  
+  return trackId;
+}
+
+MP4TrackId MP4File::AddHrefTrack (uint32_t timeScale, 
+				  MP4Duration sampleDuration)
+{
+  MP4TrackId trackId = AddCntlTrackDefault(timeScale, sampleDuration, "href");
+
+  return trackId;
+}
+		  
 MP4TrackId MP4File::AddVideoTrackDefault(
 	u_int32_t timeScale, 
 	MP4Duration sampleDuration, 
@@ -1628,7 +1667,7 @@
 }
 
 bool MP4File::AddH264SequenceParameterSet (MP4TrackId trackId,
-					   uint8_t *pSequence,
+					   const uint8_t *pSequence,
 					   uint16_t sequenceLen)
 {
   MP4Atom *avcCAtom = 
@@ -1670,8 +1709,8 @@
   return true;
 }
 bool MP4File::AddH264PictureParameterSet (MP4TrackId trackId,
-					   uint8_t *pPict,
-					   uint16_t pictLen)
+					  const uint8_t *pPict,
+					  uint16_t pictLen)
 {
   MP4Atom *avcCAtom = 
     FindAtom(MakeTrackName(trackId,
@@ -2326,7 +2365,7 @@
 	return m_pTracks[FindTrackIndex(trackId)]->GetFixedSampleDuration();
 }
 
-float MP4File::GetTrackVideoFrameRate(MP4TrackId trackId)
+double MP4File::GetTrackVideoFrameRate(MP4TrackId trackId)
 {
 	MP4SampleId numSamples =
 		GetTrackNumberOfSamples(trackId);
@@ -2339,7 +2378,7 @@
 		return 0.0;
 	}
 
-	return ((double)numSamples / UINT64_TO_DOUBLE(msDuration)) * MP4_MSECS_TIME_SCALE;
+	return ((double)numSamples / (double) msDuration) * MP4_MSECS_TIME_SCALE;
 }
 
 int MP4File::GetTrackAudioChannels (MP4TrackId trackId)