Ejemplo n.º 1
0
bool InFileRTMPStream::AVCBuilder::BuildFrame(MediaFile* pFile, MediaFrame& mediaFrame, IOBuffer& buffer) {
	if (mediaFrame.isBinaryHeader) {
		buffer.ReadFromBuffer(_videoCodecHeaderInit, sizeof (_videoCodecHeaderInit));
	} else {
		if (mediaFrame.isKeyFrame) {
			// video key frame
			buffer.ReadFromBuffer(_videoCodecHeaderKeyFrame, sizeof (_videoCodecHeaderKeyFrame));
		} else {
			//video normal frame
			buffer.ReadFromBuffer(_videoCodecHeader, sizeof (_videoCodecHeader));
		}
		uint32_t cts = (EHTONL(((uint32_t) mediaFrame.cts) & 0x00ffffff)) >> 8;
		buffer.ReadFromBuffer((uint8_t *) & cts, 3);
	}

	if (!pFile->SeekTo(mediaFrame.start)) {
		FATAL("Unable to seek to position %"PRIu64, mediaFrame.start);
		return false;
	}

	if (!buffer.ReadFromFs(*pFile, (uint32_t) mediaFrame.length)) {
		FATAL("Unable to read %"PRIu64" bytes from offset %"PRIu64, mediaFrame.length, mediaFrame.start);
		return false;
	}

	return true;
}
Ejemplo n.º 2
0
bool _AUDIO_AAC::Serialize(IOBuffer &dest) {
	uint8_t temp[sizeof (_aacLength)];
	EHTONLP(temp, _aacLength);
	dest.ReadFromBuffer(temp, sizeof (_aacLength));
	dest.ReadFromBuffer(_pAAC, _aacLength);
	return true;
}
Ejemplo n.º 3
0
bool MP44HTTPStream::FeedData(uint8_t *pData, uint32_t dataLength, uint32_t processedLength,
      uint32_t totalLength, double absoluteTimestamp, bool isAudio) {

  IOBuffer *pBuffer = _pAVProtocol->GetProtocolOutputBuffer();
  pBuffer->ReadFromBuffer(pData, dataLength);
  return _pAVProtocol->EnqueueForOutbound();
}
Ejemplo n.º 4
0
string IOBuffer::DumpBuffer(MSGHDR &message, uint32_t limit) {
	IOBuffer temp;
	for (MSGHDR_MSG_IOVLEN_TYPE i = 0; i < message.MSGHDR_MSG_IOVLEN; i++) {
		temp.ReadFromBuffer((uint8_t *) message.MSGHDR_MSG_IOV[i].IOVEC_IOV_BASE,
				message.MSGHDR_MSG_IOV[i].IOVEC_IOV_LEN);
	}
	return temp.ToString(0, limit);
}
Ejemplo n.º 5
0
bool AMF0Serializer::WriteDouble(IOBuffer &buffer, double value, bool writeType) {
	if (writeType)
		buffer.ReadFromRepeat(AMF0_NUMBER, 1);

	uint64_t temp = 0;
	EHTOND(value, temp);
	buffer.ReadFromBuffer((uint8_t *) & temp, 8);

	return true;
}
Ejemplo n.º 6
0
bool AMF0Serializer::WriteShortString(IOBuffer &buffer, string &value, bool writeType) {
	if (writeType)
		buffer.ReadFromRepeat(AMF0_SHORT_STRING, 1);

	uint16_t length = EHTONS((uint16_t) value.length()); //----MARKED-SHORT----

	buffer.ReadFromBuffer((uint8_t *) & length, 2);
	buffer.ReadFromString(value);

	return true;
}
Ejemplo n.º 7
0
bool AMF0Serializer::WriteLongString(IOBuffer &buffer, string &value, bool writeType) {
	if (writeType)
		buffer.ReadFromRepeat(AMF0_LONG_STRING, 1);

	uint32_t length = EHTONL((uint32_t) value.length());

	buffer.ReadFromBuffer((uint8_t *) & length, 4);
	buffer.ReadFromString(value);

	return true;
}
Ejemplo n.º 8
0
bool InFileRTMPStream::AACBuilder::BuildFrame(MediaFile* pFile, MediaFrame& mediaFrame, IOBuffer& buffer) {
	//1. add the binary header
	if (mediaFrame.isBinaryHeader) {
		buffer.ReadFromBuffer(_audioCodecHeaderInit, sizeof (_audioCodecHeaderInit));
	} else {
		buffer.ReadFromBuffer(_audioCodecHeader, sizeof (_audioCodecHeader));
	}

	//2. Seek into the data file at the correct position
	if (!pFile->SeekTo(mediaFrame.start)) {
		FATAL("Unable to seek to position %"PRIu64, mediaFrame.start);
		return false;
	}

	//3. Read the data
	if (!buffer.ReadFromFs(*pFile, (uint32_t) mediaFrame.length)) {
		FATAL("Unable to read %"PRIu64" bytes from offset %"PRIu64, mediaFrame.length, mediaFrame.start);
		return false;
	}

	return true;
}
Ejemplo n.º 9
0
bool Header::Write(IOBuffer &buffer) {
	if (ci < 64) {
		buffer.ReadFromByte((ht << 6) | ((uint8_t) ci));
	} else if (ci < 319) {
		buffer.ReadFromByte(ht << 6);
		buffer.ReadFromByte((uint8_t) (ci - 64));
	} else if (ci < 65599) {
		uint16_t temp = EHTONS((uint16_t) (ci - 64));
		buffer.ReadFromByte((ht << 6) | 0x01);
		buffer.ReadFromBuffer((uint8_t *) & temp, 2);
	} else {
		FATAL("Invalid channel index");
		return false;
	}

	switch (ht) {
		case HT_FULL:
		{
			if (hf.s.ts < 0x00ffffff) {
				hf.s.ts = EHTONL(hf.s.ts); //----MARKED-LONG---
				hf.s.ml = EHTONL(hf.s.ml << 8); //----MARKED-LONG---
				buffer.ReadFromBuffer(&hf.datac[1], 11);
				hf.s.ts = ENTOHL(hf.s.ts); //----MARKED-LONG---
				hf.s.ml = ENTOHL(hf.s.ml) >> 8; //----MARKED-LONG---
				return true;
			} else {
				uint32_t temp = EHTONL(hf.s.ts); //----MARKED-LONG---
				hf.s.ts = EHTONL(0x00ffffff); //----MARKED-LONG---
				hf.s.ml = EHTONL(hf.s.ml << 8); //----MARKED-LONG---
				buffer.ReadFromBuffer(&hf.datac[1], 11);
				hf.s.ts = ENTOHL(temp); //----MARKED-LONG---
				hf.s.ml = ENTOHL(hf.s.ml) >> 8; //----MARKED-LONG---
				buffer.ReadFromBuffer((uint8_t *) & temp, 4);
				return true;
			}
		}
Ejemplo n.º 10
0
bool _VIDEO_AVC::Serialize(IOBuffer &dest) {
	uint8_t temp[sizeof (_spsLength) + sizeof (_ppsLength) + sizeof (uint32_t)];
	EHTONSP(temp, _spsLength);
	dest.ReadFromBuffer(temp, sizeof (_spsLength));
	dest.ReadFromBuffer(_pSPS, _spsLength);
	EHTONSP(temp, _ppsLength);
	dest.ReadFromBuffer(temp, sizeof (_ppsLength));
	dest.ReadFromBuffer(_pPPS, _ppsLength);
	EHTONLP(temp, _widthOverride);
	dest.ReadFromBuffer(temp, sizeof (uint32_t));
	EHTONLP(temp, _heightOverride);
	dest.ReadFromBuffer(temp, sizeof (uint32_t));
	return true;
}
Ejemplo n.º 11
0
void AtomMVHD::SerializeToBuffer(IOBuffer& data, uint32_t maxFrames) {
  uint32_t start=GETAVAILABLEBYTESCOUNT(data);
  VersionedAtom::SerializeToBuffer(data, maxFrames);
  data.ReadFromDataType<uint32_t>(endianSwap32(_creationTime));
  data.ReadFromDataType<uint32_t>(endianSwap32(_modificationTime));
  data.ReadFromDataType<uint32_t>(endianSwap32(_timeScale));
  _offset=GETAVAILABLEBYTESCOUNT(data);
  data.ReadFromDataType<uint32_t>(endianSwap32(_duration));
  data.ReadFromDataType<uint32_t>(endianSwap32(_preferredRate));
  data.ReadFromDataType<uint16_t>(endianSwap16(_preferredVolume));
  data.ReadFromBuffer(_reserved, sizeof(_reserved));
  for (uint32_t i=0; i<9; i++) 
    data.ReadFromDataType<uint32_t>(endianSwap32(_matrixStructure[i]));
  for (uint32_t i=0; i<6; i++) {
    data.ReadFromRepeat(0x00, 4);
  }
  data.ReadFromDataType<uint32_t>(endianSwap32(_nextTrakId));
  _size=GETAVAILABLEBYTESCOUNT(data)-start;

  *(uint32_t*)(GETIBPOINTER(data)+start) = endianSwap32(_size);
}
Ejemplo n.º 12
0
bool StreamCapabilities::Serialize(IOBuffer &dest) {
	uint8_t temp[28];
	EHTONLLP(temp, __STREAM_CAPABILITIES_VERSION);
	EHTONLLP(temp + 8, videoCodecId);
	EHTONLLP(temp + 16, audioCodecId);
	EHTONLP(temp + 24, bandwidthHint);
	dest.ReadFromBuffer(temp, 28);
	switch (videoCodecId) {
		case CODEC_VIDEO_AVC:
		{
			if (!avc.Serialize(dest)) {
				FATAL("Unable to serialize avc");
				return false;
			}
			break;
		}
		default:
		{
			break;
		}
	}
	switch (audioCodecId) {
		case CODEC_AUDIO_AAC:
		{
			if (!aac.Serialize(dest)) {
				FATAL("Unable to serialize aac");
				return false;
			}
			break;
		}
		default:
		{
			break;
		}
	}
	return true;
}
Ejemplo n.º 13
0
string IOBuffer::DumpBuffer(const uint8_t *pBuffer, uint32_t length) {
	IOBuffer temp;
	temp.ReadFromBuffer(pBuffer, length);
	return temp.ToString();
}
Ejemplo n.º 14
0
bool OutNetRTMP4TSStream::FeedAudioData(uint8_t *pData, uint32_t dataLength,
		double absoluteTimestamp) {
	if (!_videoCodecSent)
		return true;
	//the payload here respects this format:
	//6.2  Audio Data Transport Stream, ADTS
	//iso13818-7 page 26/206

	//1. Send the audio codec setup if necessary
	if (!_audioCodecSent) {
		StreamCapabilities *pCapabilities = GetCapabilities();
		if ((pCapabilities != NULL)
				&& (pCapabilities->audioCodecId == CODEC_AUDIO_AAC)) {
			IOBuffer codecSetup;
			codecSetup.ReadFromRepeat(0xaf, 1);
			codecSetup.ReadFromRepeat(0x00, 1);
			codecSetup.ReadFromBuffer(pCapabilities->aac._pAAC,
					pCapabilities->aac._aacLength);

			if (!BaseOutNetRTMPStream::FeedData(
					GETIBPOINTER(codecSetup), //pData
					GETAVAILABLEBYTESCOUNT(codecSetup), //dataLength
					0, //processedLength
					GETAVAILABLEBYTESCOUNT(codecSetup), //totalLength
					absoluteTimestamp, //absoluteTimestamp
					true //isAudio
					)) {
				FATAL("Unable to send audio codec setup");
				return false;
			}
		}

		_audioCodecSent = true;
	}

	if (_inboundStreamIsRTP) {
		pData[0] = 0xaf;
		pData[1] = 0x01;

		return BaseOutNetRTMPStream::FeedData(
				pData, //pData
				dataLength, //dataLength
				0, //processedLength
				dataLength, //totalLength
				absoluteTimestamp, //absoluteTimestamp
				true //isAudio
				);
	} else {
		//2. Skip the ADTS headers and re-position the buffer
		uint32_t totalADTSHeaderLength = 0;
		if (((pData[1])&0x01) == 0)
			totalADTSHeaderLength = 9;
		else
			totalADTSHeaderLength = 7;
		pData += totalADTSHeaderLength - 2;

		//3. Setup the RTMP header
		pData[0] = 0xaf;
		pData[1] = 0x01;

		//4. Feed
		return BaseOutNetRTMPStream::FeedData(
				pData, //pData
				dataLength - totalADTSHeaderLength + 2, //dataLength
				0, //processedLength
				dataLength - totalADTSHeaderLength + 2, //totalLength
				absoluteTimestamp, //absoluteTimestamp
				true //isAudio
				);
	}
}