void JPEGVideoRTPSink ::doSpecialFrameHandling(unsigned fragmentationOffset, unsigned char* /*frameStart*/, unsigned /*numBytesInFrame*/, struct timeval frameTimestamp, unsigned numRemainingBytes) { // Our source is known to be a JPEGVideoSource JPEGVideoSource* source = (JPEGVideoSource*)fSource; if (source == NULL) return; // sanity check u_int8_t mainJPEGHeader[8]; // the special header mainJPEGHeader[0] = 0; // Type-specific mainJPEGHeader[1] = fragmentationOffset >> 16; mainJPEGHeader[2] = fragmentationOffset >> 8; mainJPEGHeader[3] = fragmentationOffset; mainJPEGHeader[4] = source->type(); mainJPEGHeader[5] = source->qFactor(); mainJPEGHeader[6] = source->width(); mainJPEGHeader[7] = source->height(); setSpecialHeaderBytes(mainJPEGHeader, sizeof mainJPEGHeader); if (fragmentationOffset == 0 && source->qFactor() >= 128) { // There is also a Quantization Header: u_int8_t precision; u_int16_t length; u_int8_t const* quantizationTables = source->quantizationTables(precision, length); unsigned const quantizationHeaderSize = 4 + length; u_int8_t* quantizationHeader = new u_int8_t[quantizationHeaderSize]; quantizationHeader[0] = 0; // MBZ quantizationHeader[1] = precision; quantizationHeader[2] = length >> 8; quantizationHeader[3] = length&0xFF; if (quantizationTables != NULL) { // sanity check for (u_int16_t i = 0; i < length; ++i) { quantizationHeader[4+i] = quantizationTables[i]; } } setSpecialHeaderBytes(quantizationHeader, quantizationHeaderSize, sizeof mainJPEGHeader /* start position */); delete[] quantizationHeader; }
void JPEGVideoRTPSink ::doSpecialFrameHandling(unsigned fragmentationOffset, unsigned char* /*frameStart*/, unsigned /*numBytesInFrame*/, struct timeval framePresentationTime, unsigned numRemainingBytes) { // Our source is known to be a JPEGVideoSource JPEGVideoSource* source = (JPEGVideoSource*)fSource; if (source == NULL) return; // sanity check u_int8_t mainJPEGHeader[8]; // the special header u_int8_t const type = source->type(); mainJPEGHeader[0] = 0; // Type-specific mainJPEGHeader[1] = fragmentationOffset >> 16; mainJPEGHeader[2] = fragmentationOffset >> 8; mainJPEGHeader[3] = fragmentationOffset; mainJPEGHeader[4] = type; mainJPEGHeader[5] = source->qFactor(); mainJPEGHeader[6] = source->width(); mainJPEGHeader[7] = source->height(); setSpecialHeaderBytes(mainJPEGHeader, sizeof mainJPEGHeader); unsigned restartMarkerHeaderSize = 0; // by default if (type >= 64 && type <= 127) { // There is also a Restart Marker Header: restartMarkerHeaderSize = 4; u_int16_t const restartInterval = source->restartInterval(); // should be non-zero u_int8_t restartMarkerHeader[4]; restartMarkerHeader[0] = restartInterval>>8; restartMarkerHeader[1] = restartInterval&0xFF; restartMarkerHeader[2] = restartMarkerHeader[3] = 0xFF; // F=L=1; Restart Count = 0x3FFF setSpecialHeaderBytes(restartMarkerHeader, restartMarkerHeaderSize, sizeof mainJPEGHeader/* start position */); }