Example #1
0
void MP4BytesProperty::SetValue(const u_int8_t* pValue, u_int32_t valueSize, 
	u_int32_t index) 
{
	if (m_readOnly) {
		throw new MP4Error(EACCES, "property is read-only", m_name);
	}
	if (m_fixedValueSize) {
		if (valueSize > m_fixedValueSize) {
			throw new MP4Error("value size exceeds fixed value size",
				"MP4BytesProperty::SetValue");
		}
		if (m_values[index] == NULL) {
			m_values[index] = (u_int8_t*)MP4Calloc(m_fixedValueSize);
			m_valueSizes[index] = m_fixedValueSize;
		}
		if (pValue) {
			memcpy(m_values[index], pValue, valueSize);
		}
	} else {
		MP4Free(m_values[index]);
		if (pValue) {
			m_values[index] = (u_int8_t*)MP4Malloc(valueSize);
			memcpy(m_values[index], pValue, valueSize);
			m_valueSizes[index] = valueSize;
		} else {
			m_values[index] = NULL;
			m_valueSizes[index] = 0;
		}
	}
}
Example #2
0
MP4BytesProperty::MP4BytesProperty(char* name, u_int32_t valueSize,
                                   u_int32_t defaultValueSize)
	: MP4Property(name)
{
	SetCount(1);
	m_values[0] = (u_int8_t*)MP4Calloc(valueSize);
	m_valueSizes[0] = valueSize;
	m_fixedValueSize = 0;
        m_defaultValueSize = defaultValueSize;
}
Example #3
0
void MP4StringProperty::Read(MP4File* pFile, u_int32_t index)
{
	if (m_implicit) {
		return;
	}
	if (m_useCountedFormat) {
		m_values[index] = pFile->ReadCountedString(
			(m_useUnicode ? 2 : 1), m_useExpandedCount);
	} else if (m_fixedLength) {
		MP4Free(m_values[index]);
		m_values[index] = (char*)MP4Calloc(m_fixedLength + 1);
		pFile->ReadBytes((u_int8_t*)m_values[index], m_fixedLength);
	} else {
		m_values[index] = pFile->ReadString();
	}
}
Example #4
0
void MP4StringProperty::SetValue(const char* value, u_int32_t index) 
{
	if (m_readOnly) {
		throw new MP4Error(EACCES, "property is read-only", m_name);
	}

	MP4Free(m_values[index]);

	if (m_fixedLength) {
		m_values[index] = (char*)MP4Calloc(m_fixedLength + 1);
		if (value) {
			strncpy(m_values[index], value, m_fixedLength);
		}
	} else {
		if (value) {
			m_values[index] = MP4Stralloc(value);
		} else {
			m_values[index] = NULL;
		}
	}
}
Example #5
0
extern "C" char* MP4Info(
	MP4FileHandle mp4File,
	MP4TrackId trackId)
{
	char* info = NULL;

	if (MP4_IS_VALID_FILE_HANDLE(mp4File)) {
		try {
			if (trackId == MP4_INVALID_TRACK_ID) {
			  uint buflen = 4 * 1024;
				info = (char*)MP4Calloc(buflen);

				buflen -= snprintf(info, buflen,
						"Track\tType\tInfo\n");

				u_int32_t numTracks = MP4GetNumberOfTracks(mp4File);

				for (u_int32_t i = 0; i < numTracks; i++) {
					trackId = MP4FindTrackId(mp4File, i);
					char* trackInfo = PrintTrackInfo(mp4File, trackId);
					strncat(info, trackInfo, buflen);
					uint newlen = wcslen(trackInfo);
					if (newlen > buflen) buflen = 0;
					else buflen -= newlen;
					MP4Free(trackInfo);
				}
			} else {
				info = PrintTrackInfo(mp4File, trackId);
			}
		}
		catch (MP4Error* e) {
			delete e;
		}
	}

	return info;
}
Example #6
0
  /*! \brief Read property from file.
  
      \param pFile                input, file handle.
      \param index                input, index to read.
  */
	void Read(MP4File* pFile, u_int32_t index = 0) {
	  MP4Free(m_values[index]);
	  m_values[index] = (char*)MP4Calloc(m_fixedLength + 1);
	  (void)pFile->ReadBytes((u_int8_t*)m_values[index], m_fixedLength);
  }
Example #7
0
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;
}
Example #8
0
File: log.cpp Project: 2php/mp4v2
/**
 * Log a buffer as ascii-hex
 *
 * @param indent the number of spaces to indent the buffer
 *
 * @param verbosity the level of detail the message contains
 *
 * @param pBytes the buffer to log
 *
 * @param numBytes the number of bytes to log
 *
 * @param format the format string to use to process the
 * remaining arguments, where the format + remaining args
 * describe @p pBytes.  The resulting string should not
 * contain a newline.  Only the first 255 characters of the
 * resulting string (not including the NUL terminator) make
 * it to the log callback or stdout.
 */
void
Log::hexDump( uint8_t           indent,
              MP4LogLevel       verbosity_,
              const uint8_t*    pBytes,
              uint32_t          numBytes,
              const char*       format,
              ... )
{
    va_list     ap;

    ASSERT(pBytes || (numBytes == 0));
    ASSERT(format);

    if (verbosity_ > this->_verbosity)
    {
        // We're not set verbose enough to log this
        return;
    }

    // Build the description by processing format and the
    // remaining args.  Since we don't have asprintf, pick
    // an arbitrary length for the string and use snprintf.
    // To save a memory allocation, only do this if there's
    // a non-empty format string or non-zero indent
    char *desc = NULL;
    if (format[0] || indent)
    {
        desc = (char *)MP4Calloc(256 + indent);
        sprintf(desc,"%*c",indent,' ');
        va_start(ap,format);
        vsnprintf(desc + indent,255,format,ap);
        va_end(ap);
    }

    // From here we can use the C++ standard lib classes and
    // build a string for each line
    for (uint32_t i = 0;(i < numBytes);i += 16)
    {
        // ios_base::ate means at end.  With out this desc
        // gets overwritten with each << operation
        ostringstream oneLine(desc ? desc : "",ios_base::ate);

        // Append the byte offset this line starts with as
        // an 8 character, leading 0, hex number.  Leave the
        // fill character set to 0 for the remaining
        // operations
        oneLine << ':' << hex << setw(8) << setfill('0') <<
            std::right << i << setw(0) << setfill(' ') << ": ";

        uint32_t curlen = min((uint32_t)16,numBytes - i);
        const uint8_t *b = pBytes + i;
        uint32_t j;

        for (j = 0;(j < curlen);j++)
        {
            oneLine << hex << setw(2) << setfill('0') << right << static_cast<uint32_t>(b[j]);
            oneLine << setw(0) << setfill(' ') << ' ';
        }

        for (; j < 16; j++)
        {
            oneLine << "   ";
        }

        b = pBytes + i;
        for (j = 0;(j < curlen);j++)
        {
            if (isprint(static_cast<int>(b[j])))
            {
                oneLine << static_cast<char>(b[j]);
            }
            else
            {
                oneLine << '.';
            }
        }

        // We can either call the callback directly or use
        // the Log::printf function.  To call the callback
        // directly, we need a va_list.  (I think) we need
        // and extra function call to build that, so we may
        // as well call Log::printf.  It's going to
        // double-check the verbosity and the callback
        // function pointer, but that seems OK (13-feb-09,
        // dbyron)
        this->printf(verbosity_,"%s",oneLine.str().c_str());
    }

    if (desc)
    {
        MP4Free(desc);
        desc = NULL;
    }
}