* Constant Defines
***********************************************************************/
// Maximum debug message length
-#define KMAXMSGSIZE 1024
-#define KMAX_MP3FRAME_LENGTH_IN_BYTES 2884
+#define KMAXMSGSIZE 1024
+#define KMAX_MP3FRAME_LENGTH_IN_BYTES 2884
// Initial search range, resetted to the file size once valid mp3
// frame is found
-#define KMAX_INITIAL_SEARCH_FILE_SIZE_IN_BYTES 500000
+#define KMAX_INITIAL_SEARCH_FILE_SIZE_IN_BYTES 500000
/***********************************************************************
* Global constant definitions
static const uint32 VBR_SCALE_FLAG = 0x0008;
static const uint32 FRAMES_AND_BYTES = (FRAMES_FLAG | BYTES_FLAG);
-static const uint8 MPEG_LAYER_I = 0x03;
-static const uint8 MPEG_LAYER_II = 0x02;
-static const uint8 MPEG_LAYER_III = 0X01;
+static const uint8 MPEG_LAYER_I = 0x03;
+static const uint8 MPEG_LAYER_II = 0x02;
+static const uint8 MPEG_LAYER_III = 0X01;
-static const uint8 CHANNEL_MODE_JOINT_STEREO = 0x01;
-static const uint8 CHANNEL_MODE_STEREO = 0x00;
-static const uint8 CHANNEL_MODE_DUAL_CHANNEL = 0x02;
-static const uint8 CHANNEL_MODE_MONO = 0x03;
+static const uint8 CHANNEL_MODE_JOINT_STEREO = 0x01;
+static const uint8 CHANNEL_MODE_STEREO = 0x00;
+static const uint8 CHANNEL_MODE_DUAL_CHANNEL = 0x02;
+static const uint8 CHANNEL_MODE_MONO = 0x03;
-static const uint8 FRAME_VESION_MPEG_1 = 0x03;
-static const uint8 FRAME_VESION_MPEG_2 = 0x02;
-static const uint8 FRAME_VESION_MPEG_2_5 = 0x00;
+static const uint8 FRAME_VESION_MPEG_1 = 0x03;
+static const uint8 FRAME_VESION_MPEG_2 = 0x02;
+static const uint8 FRAME_VESION_MPEG_2_5 = 0x00;
-static const uint8 MP3_FRAME_HEADER_SIZE = 0x04;
-static const uint32 MP3_FIRST_FRAME_SIZE = 128;
+static const uint8 MP3_FRAME_HEADER_SIZE = 0x04;
+static const uint32 MP3_FIRST_FRAME_SIZE = 128;
/***********************************************************************
* End XING VBR Header Constants
***********************************************************************/
/***********************************************************************
* FUNCTION: SwapFileToHostByteOrderInt32
* DESCRIPTION: Swaps the bytes in an integer to the correct host
- * byte order
+ * byte order
* INPUT/OUTPUT PARAMETERS:
* RETURN VALUE:
* SIDE EFFECTS:
/***********************************************************************
* FUNCTION: ParseMP3File
* DESCRIPTION: This function MUST be called after the Constructor and before
- * any other public function is called. Otherwise the object's
- * member data will be uninitialized.
+ * any other public function is called. Otherwise the object's
+ * member data will be uninitialized.
* INPUT/OUTPUT PARAMETERS:
* RETURN VALUE:
* SIDE EFFECTS:
}
/***********************************************************************
- * Function : ScanMP3File
- * Purpose : Fetches duration of the clip playing
- * Duration is returned, by different
- * means by the pre-defined priorities
- * Input : fpUsed
- * Output : iClipDurationComputed
- * Return : error code
- * Modified :
+ * Function : ScanMP3File
+ * Purpose : Fetches duration of the clip playing
+ * Duration is returned, by different
+ * means by the pre-defined priorities
+ * Input : fpUsed
+ * Output : iClipDurationComputed
+ * Return : error code
+ * Modified :
***********************************************************************/
MP3ErrorType MP3Parser::ScanMP3File(PVFile * fpUsed, uint32 aFramesToScan)
{
/***********************************************************************
* FUNCTION: GetMP3Header
* DESCRIPTION: Parse Header Bit fields into a structure (Pass in 4 bytes)
- * Validate ranges and reserved fields.
+ * Validate ranges and reserved fields.
* INPUT/OUTPUT PARAMETERS:
* RETURN VALUE:
* SIDE EFFECTS:
/***********************************************************************
* FUNCTION: DecodeVBRIHeader
- * DESCRIPTION: Decode VBRI Header and store TOC entries used for
- repositioning
+ * DESCRIPTION: Decode VBRI Header and store TOC entries used for
+ repositioning
* INPUT/OUTPUT PARAMETERS:
* RETURN VALUE:
* SIDE EFFECTS:
}
/***********************************************************************
- * Function : GetChannelMode
- * Purpose : Fetch Channel mode for the clip
- * Input : None
- * Output :
- * Return : ChannelMode
- * Modified :
+ * Function : GetChannelMode
+ * Purpose : Fetch Channel mode for the clip
+ * Input : None
+ * Output :
+ * Return : ChannelMode
+ * Modified :
***********************************************************************/
uint32 MP3Parser::GetChannelMode() const
{
}
/***********************************************************************
- * Function : GetDurationFromMetadata
- * Purpose : Fetch duration value from id3 frame (TLEN - track length)
- * Input : None
- * Output : iClipDurationFromMetadata
- * Return : clip duration
- * Modified :
+ * Function : GetDurationFromMetadata
+ * Purpose : Fetch duration value from id3 frame (TLEN - track length)
+ * Input : None
+ * Output : iClipDurationFromMetadata
+ * Return : clip duration
+ * Modified :
***********************************************************************/
uint32 MP3Parser::GetDurationFromMetadata()
{
}
/***********************************************************************
- * Function : ConvertSizeToTime
- * Purpose : Fetches duration of the clip playing
- * Duration is returned, by different
- * means by the pre-defined priorities
- * Input : aMetadataDuration, true if duration from metadata is needed
- * Output : None
- * Return : Clip duration
- * Modified :
+ * Function : ConvertSizeToTime
+ * Purpose : Fetches duration of the clip playing
+ * Duration is returned, by different
+ * means by the pre-defined priorities
+ * Input : aMetadataDuration, true if duration from metadata is needed
+ * Output : None
+ * Return : Clip duration
+ * Modified :
**********************************************************************/
int32 MP3Parser::ConvertSizeToTime(uint32 aFileSize, uint32& aNPTInMS)
{
}
/***********************************************************************
- * Function : GetDuration
- * Purpose : Fetches duration of the clip playing
- * Duration is returned, by different
- * means by the pre-defined priorities
- * Input : aMetadataDuration, true if duration from metadata is needed
- * Output : None
- * Return : Clip duration
- * Modified :
+ * Function : GetDuration
+ * Purpose : Fetches duration of the clip playing
+ * Duration is returned, by different
+ * means by the pre-defined priorities
+ * Input : aMetadataDuration, true if duration from metadata is needed
+ * Output : None
+ * Return : Clip duration
+ * Modified :
**********************************************************************/
uint32 MP3Parser::GetDuration(bool aMetadataDuration)
{
}
/***********************************************************************
- * Function : GetMetadataSize
- * Purpose : Fetches size of id3 data
- * Input : None
- * Output : aSize, size of metadata
- * Return : error code
- * Modified :
+ * Function : GetMetadataSize
+ * Purpose : Fetches size of id3 data
+ * Input : None
+ * Output : aSize, size of metadata
+ * Return : error code
+ * Modified :
***********************************************************************/
MP3ErrorType MP3Parser::GetMetadataSize(uint32 &aMetadataSize)
{
}
/***********************************************************************
- * Function : GetMinBytesRequired
- * Purpose : Fetches size of maximum Mp3 frame
- * Input : None
- * Output : None
- * Return : aSize, size of max mp3 frame
- * Modified :
+ * Function : GetMinBytesRequired
+ * Purpose : Fetches size of maximum Mp3 frame
+ * Input : None
+ * Output : None
+ * Return : aSize, size of max mp3 frame
+ * Modified :
***********************************************************************/
uint32 MP3Parser::GetMinBytesRequired(bool aNextBytes)
{
/***********************************************************************
* FUNCTION: mp3FindSync
* DESCRIPTION: This function reads the whole file searching for a sync
- * word. Once it finds one, it check for 4 continuous sync
- * words to avoid a false synchronization
+ * word. Once it finds one, it check for 4 continuous sync
+ * words to avoid a false synchronization
* INPUT/OUTPUT PARAMETERS:
* RETURN VALUE:
* SIDE EFFECTS:
syncOffset = 0;
iMaxSyncBufferSize = 627; /* default for 192 kbps, 44.1 kHz */
- if (!aFile)
+ if (aFile->GetCPM() != NULL)
{
- if (fp->GetCPM() != NULL)
- {
- iLocalFileSizeSet = (int32)MP3Utils::getCurrentFileSize(fp, iLocalFileSize);
- }
+ iLocalFileSizeSet = (int32)MP3Utils::getCurrentFileSize(aFile, iLocalFileSize);
+ }
- uint32 contentLength = MP3FileIO::getContentLength(fp);
- if (0 != contentLength)
- {
- // if content length is known, check for reading beyond EOF
- if ((seekPoint + iMaxSyncBufferSize) >= contentLength)
- {
- return MP3_END_OF_FILE;
- }
- }
+ uint32 contentLength = MP3FileIO::getContentLength(aFile);
+ if ((contentLength != 0) && ((seekPoint + iMaxSyncBufferSize) >= contentLength))
+ {
+ // if content length is known, check for reading beyond EOF
+ return MP3_END_OF_FILE;
+ }
- if ((iLocalFileSize != 0) && (seekPoint + iMaxSyncBufferSize > (uint32)iLocalFileSize))
- {
- return MP3_INSUFFICIENT_DATA;
- }
+ if ((iLocalFileSize != 0) && (seekPoint + iMaxSyncBufferSize > (uint32)iLocalFileSize))
+ {
+ return MP3_INSUFFICIENT_DATA;
+ }
- if (pSyncBuffer)
- {
- OSCL_ARRAY_DELETE(pSyncBuffer);
- pSyncBuffer = NULL;
- }
+ if (pSyncBuffer)
+ {
+ OSCL_ARRAY_DELETE(pSyncBuffer);
+ pSyncBuffer = NULL;
}
int32 leavecode = 0;
return MP3_ERROR_UNKNOWN; /* buffer couldn't be allocated */
}
- PVFile* fpused = (aFile) ? aFile : fp;
- seekPoint = fpused->Tell();
+ seekPoint = aFile->Tell();
uint32 i = 0;
uint32 j = 0;
uint32 BufferSize = 0;
else
{
uint32 remBytes = 0;
- if (fp->GetRemainingBytes(remBytes))
+ if (aFile->GetRemainingBytes(remBytes))
{
- maxSearchOffset = OSCL_MIN(iInitSearchFileSize, fpused->Tell() + remBytes - seekPoint);
+ maxSearchOffset = OSCL_MIN(iInitSearchFileSize, aFile->Tell() + remBytes - seekPoint);
}
}
{
revSeek = 0;
// Grab a new buffer for a byte by byte search
- if (!MP3FileIO::readByteData(fpused, iMaxSyncBufferSize, &pSyncBuffer[1], &BufferSize))
+ if (!MP3FileIO::readByteData(aFile, iMaxSyncBufferSize, &pSyncBuffer[1], &BufferSize))
{
if (pSyncBuffer)
{
if ((pSyncBuffer[i+1] & 0xF0) == 0xF0)
{
// if partial match is found verify that 4 consecutives sync word are valid
- MP3Utils::SeektoOffset(fpused, 0 - (int32) iMaxSyncBufferSize + (int32) i - 1, Oscl_File::SEEKCUR);
- mp3Err = IsValidFrame(&(pSyncBuffer[i]), j + i - 1, seekPoint, fpused);
+ MP3Utils::SeektoOffset(aFile, 0 - (int32) iMaxSyncBufferSize + (int32) i - 1, Oscl_File::SEEKCUR);
+ mp3Err = IsValidFrame(&(pSyncBuffer[i]), j + i - 1, seekPoint, aFile);
if (mp3Err == MP3_SUCCESS)
{
- MP3Utils::SeektoOffset(fpused, 0 - (int32)j - i + 1, Oscl_File::SEEKCUR);
+ MP3Utils::SeektoOffset(aFile, 0 - (int32)j - i + 1, Oscl_File::SEEKCUR);
break;
}
else if (mp3Err == MP3_INSUFFICIENT_DATA)
else
{
// Drop the frame
- MP3Utils::SeektoOffset(fpused, iMaxSyncBufferSize - i + 1, Oscl_File::SEEKCUR);
+ MP3Utils::SeektoOffset(aFile, iMaxSyncBufferSize - i + 1, Oscl_File::SEEKCUR);
}
}
// MPEG 2.5
else if ((pSyncBuffer[i+1] & 0xF0) == 0xE0)
{
// if partial match is found verify that 4 consecutives sync word are valid
- MP3Utils::SeektoOffset(fpused, 0 - (int32) iMaxSyncBufferSize + (int32) i - 1, Oscl_File::SEEKCUR);
- mp3Err = IsValidFrame(&(pSyncBuffer[i]), j + i - 1, seekPoint, fpused);
+ MP3Utils::SeektoOffset(aFile, 0 - (int32) iMaxSyncBufferSize + (int32) i - 1, Oscl_File::SEEKCUR);
+ mp3Err = IsValidFrame(&(pSyncBuffer[i]), j + i - 1, seekPoint, aFile);
if (mp3Err == MP3_SUCCESS)
{
- MP3Utils::SeektoOffset(fpused, 0 - (int32)j - i + 1, Oscl_File::SEEKCUR);
+ MP3Utils::SeektoOffset(aFile, 0 - (int32)j - i + 1, Oscl_File::SEEKCUR);
break;
}
else if (mp3Err == MP3_INSUFFICIENT_DATA)
else
{
// Drop the frame
- MP3Utils::SeektoOffset(fpused, iMaxSyncBufferSize - i + 1, Oscl_File::SEEKCUR);
+ MP3Utils::SeektoOffset(aFile, iMaxSyncBufferSize - i + 1, Oscl_File::SEEKCUR);
}
}
}
else
{
uint32 remBytes = 0;
- if (fp->GetRemainingBytes(remBytes))
+ if (aFile->GetRemainingBytes(remBytes))
{
/* One valid frame was found -> reset initial size remaining file size*/
iInitSearchFileSize = OSCL_MIN(iInitSearchFileSize, remBytes);
/***********************************************************************
* FUNCTION: IsValidFrameHeader
* DESCRIPTION: This function now check the sync word and then with the
- * information retrieved from the header, predict the location
- * of the following 3 headers. Then, if the sampling frequencies
- * and number of channels match for all headers, the frame header
- * is considered valid
+ * information retrieved from the header, predict the location
+ * of the following 3 headers. Then, if the sampling frequencies
+ * and number of channels match for all headers, the frame header
+ * is considered valid
* INPUT/OUTPUT PARAMETERS:
* RETURN VALUE:
* SIDE EFFECTS:
* FUNCTION: mp3VerifyCRC
* DESCRIPTION:
* INPUT/OUTPUT PARAMETERS: verifies the crc if crc check is enabled and
- * crc flag is present
+ * crc flag is present
* RETURN VALUE:
* SIDE EFFECTS:
***********************************************************************/
uint32 n;
uint16 tmpchar, crcmask, tmpi;
crcmask = tmpchar = 0;
- uint16 crc = 0xffff; // start with inverted value of 0
+ uint16 crc = 0xffff; // start with inverted value of 0
// start with byte 2 of header
for (n = 16; n < dwBitSize; n++)
crc ^= 0x8005;
}
}
- crc &= 0xffff; // invert the result
+ crc &= 0xffff; // invert the result
return crc;
}
int32 returnValue = tableLength + 26; //TOC bytes + Upper header bytes
- VbriHead -= 22; //Reset the file pointer to its original place
+ VbriHead -= 22; //Reset the file pointer to its original place
return returnValue;
}
/***********************************************************************
- * Function : IsMp3File
- * Purpose : Verifies whether the file passed in is a possibly
- * valid mp3 clip
- * Input : aFile, file to check
- * aInitSearchFileSize, amount of data to use for verification
- * Output : None
- * Return : error code
- * Modified :
+ * Function : IsMp3File
+ * Purpose : Verifies whether the file passed in is a possibly
+ * valid mp3 clip
+ * Input : aFile, file to check
+ * aInitSearchFileSize, amount of data to use for verification
+ * Output : None
+ * Return : error code
+ * Modified :
***********************************************************************/
MP3ErrorType MP3Parser::IsMp3File(MP3_FF_FILE* aFile, uint32 aInitSearchFileSize)
{
{
uint32 seekOffset = 0;
MP3Utils::SeektoOffset(fp, 0 - MP3_FRAME_HEADER_SIZE, Oscl_File::SEEKCUR);
- errCode = mp3FindSync(StartOffset, seekOffset);
+ errCode = mp3FindSync(StartOffset, seekOffset, fp);
if (errCode == MP3_SUCCESS)
{
errCode = MP3Utils::SeektoOffset(fp, seekOffset, Oscl_File::SEEKCUR);
}
/***********************************************************************
- * Function : SetFileSize
- * Purpose : Notification from the lib user for the file size,
- * Once File size is received, the same is used to
- * estimate the clip duration
- * Return : error code
- * Input : aFileSize
- * Output : None
- * Modified :
+ * Function : SetFileSize
+ * Purpose : Notification from the lib user for the file size,
+ * Once File size is received, the same is used to
+ * estimate the clip duration
+ * Return : error code
+ * Input : aFileSize
+ * Output : None
+ * Modified :
***********************************************************************/
MP3ErrorType MP3Parser::SetFileSize(const uint32 aFileSize)
{
}
/**
- * Function : EstimateDurationFromExternalFileSize
- * Purpose : Estimates the clip duration from external file size
- * Return : error code
- * Input : None
- * Output : Clip duration
- * Modified :
+ * Function : EstimateDurationFromExternalFileSize
+ * Purpose : Estimates the clip duration from external file size
+ * Return : error code
+ * Input : None
+ * Output : Clip duration
+ * Modified :
**/
MP3ErrorType MP3Parser::EstimateDurationFromExternalFileSize(uint32 &aClipDuration)
{
}
/***********************************************************************
- * Function : GetDurationFromVBRIHeader
- * Purpose : Estimates the clip duration from Vbri/Xing headers
- * Return : error code
- * Input : None
- * Output : Clip duration
- * Modified :
+ * Function : GetDurationFromVBRIHeader
+ * Purpose : Estimates the clip duration from Vbri/Xing headers
+ * Return : error code
+ * Input : None
+ * Output : Clip duration
+ * Modified :
***********************************************************************/
MP3ErrorType MP3Parser::GetDurationFromVBRIHeader(uint32 &aClipDuration)
{
}
/***********************************************************************
- * Function : GetDurationFromRandomScan
- * Purpose : Estimates the clip duration by average bitrate
- * Average bit rate is calculated by randomnly scannning
- * predefined number of frames
- * Return : error code
- * Input : None
- * Output : Clip duration
- * Modified :
+ * Function : GetDurationFromRandomScan
+ * Purpose : Estimates the clip duration by average bitrate
+ * Average bit rate is calculated by randomnly scannning
+ * predefined number of frames
+ * Return : error code
+ * Input : None
+ * Output : Clip duration
+ * Modified :
***********************************************************************/
MP3ErrorType MP3Parser::GetDurationFromRandomScan(uint32 &aClipDuration)
{
}
/***********************************************************************
- * Function : ComputeDurationFromNRandomFrames
- * Purpose : Estimates average bit rate by randomnly scannning input
- * number of frames
- * Return : error code
- * Input : numFrames
- * Output : iAvgBitrateInbpsFromRandomScan
- * Modified :
+ * Function : ComputeDurationFromNRandomFrames
+ * Purpose : Estimates average bit rate by randomnly scannning input
+ * number of frames
+ * Return : error code
+ * Input : numFrames
+ * Output : iAvgBitrateInbpsFromRandomScan
+ * Modified :
***********************************************************************/
MP3ErrorType MP3Parser::ComputeDurationFromNRandomFrames(PVFile * fpUsed, int32 aNumFrames, int32 aNumRandomLoc)
{