Example #1
0
RTCPSRPacket::RTCPSRPacket()
{
    // Write as much of the Sender Report as is possible
    char theTempCName[kMaxCNameLen];
    UInt32 cNameLen = RTCPSRPacket::GetACName(theTempCName);
    
    //write the SR & SDES headers
    UInt32* theSRWriter = (UInt32*)&fSenderReportBuffer;
    *theSRWriter = bswap_32(0x80c80006);
    theSRWriter += 7; //number of UInt32s in an SR.
    
    //SDES length is the length of the CName, plus 2 32bit words, plus the 32bit word for the SSRC
    *theSRWriter = bswap_32(0x81ca0000 + (cNameLen >> 2) + 1);
    ::memcpy(&fSenderReportBuffer[kSenderReportSizeInBytes], theTempCName, cNameLen);
    fSenderReportSize = kSenderReportSizeInBytes + cNameLen;

/*
 SERVER INFO PACKET FORMAT
struct qtss_rtcp_struct
{
    RTCPHeader      header;
    UInt32          ssrc;       // ssrc of rtcp originator
    OSType          name;
    UInt32          senderSSRC;
    SInt16          reserved;
    SInt16          length;     // bytes of data (atoms) / 4
    // qtsi_rtcp_atom structures follow
};
*/

    //
    // Write the SERVER INFO APP packet
    UInt32* theAckInfoWriter = (UInt32*)&fSenderReportBuffer[fSenderReportSize];
    *theAckInfoWriter = bswap_32(0x81cc0006);
    theAckInfoWriter += 2;
    *(theAckInfoWriter++) = bswap_32(FOUR_CHARS_TO_INT('q', 't', 's', 'i')); // Ack Info APP name
    theAckInfoWriter++; // leave space for the ssrc (again)
    *(theAckInfoWriter++) = bswap_32(2); // 2 UInt32s for the 'at' field
    *(theAckInfoWriter++) = bswap_32(FOUR_CHARS_TO_INT( 'a', 't', 0, 4 ));
    fSenderReportWithServerInfoSize = (char*)(theAckInfoWriter+1) - fSenderReportBuffer;    
    
    UInt32* theByeWriter = (UInt32*)&fSenderReportBuffer[fSenderReportWithServerInfoSize];
    *theByeWriter = bswap_32(0x81cb0001);
}
Example #2
0
bool SoundHeader::UnpackExtendedSystem7Header(AIStreamBE &header)
{
  try
  {
    signed_8bit = false;
    header.ignore(4);             // sample pointer
    int32 num_channels;
    header >> num_channels;
    stereo = (num_channels == 2);
    header >> rate;
    header >> loop_start;
    header >> loop_end;
    uint8 header_type;
    header >> header_type;
    header.ignore(1);             // baseFrequency
    int32 num_frames;
    header >> num_frames;

    if (header_type == 0xfe) {
      header.ignore(10);                   // AIFF rate
      header.ignore(4);                   // marker chunk
      uint32 format;
      header >> format;
      header.ignore(4 * 3);                   // future use, ptr, ptr
      int16 comp_id;
      header >> comp_id;
      if (format != FOUR_CHARS_TO_INT('t','w','o','s') || comp_id != -1) {
        return false;
      }
      signed_8bit = true;
      header.ignore(4);
    }
    else {
      header.ignore(22);
    }

    int16 sample_size;
    header >> sample_size;

    sixteen_bit = (sample_size == 16);
    bytes_per_frame = (sixteen_bit ? 2 : 1) * (stereo ? 2 : 1);

    length = num_frames * bytes_per_frame;
    little_endian = false;

    if ((loop_end - loop_start >= 4) &&
        ((loop_start % bytes_per_frame) || (loop_end % bytes_per_frame))) {
      logWarning3(
        "loop_start=%i and loop_end=%i but bytes_per_frame=%i; interpreting as frame offsets",
        loop_start, loop_end, bytes_per_frame);
      loop_start *= bytes_per_frame;
      loop_end *= bytes_per_frame;
    }

    return true;
  } catch (...) {
Example #3
0
// Determine file type
Typecode FileSpecifier::GetType()
{

	// if there's an extension, assume it's correct
	const char *extension = strrchr(GetPath(), '.');
	if (extension) {
		extension_mapping *mapping = extensions;
		while (mapping->extension)
		{ 
			if (( mapping->case_sensitive && (strcmp(extension + 1, mapping->extension) == 0)) ||
			    (!mapping->case_sensitive && (strcasecmp(extension + 1, mapping->extension) == 0)))
			{
				return mapping->typecode;
			}
			++mapping;
		}
	}

	// Open file
	OpenedFile f;
	if (!Open(f))
		return _typecode_unknown;
	SDL_RWops *p = f.GetRWops();
	int32 file_length = 0;
	f.GetLength(file_length);

	// Check for Sounds file
	{
		f.SetPosition(0);
		uint32 version = SDL_ReadBE32(p);
		uint32 tag = SDL_ReadBE32(p);
		if ((version == 0 || version == 1) && tag == FOUR_CHARS_TO_INT('s', 'n', 'd', '2'))
			return _typecode_sounds;
	}

	// Check for Map/Physics file
	{
		f.SetPosition(0);
		int version = SDL_ReadBE16(p);
		int data_version = SDL_ReadBE16(p);
		if ((version == 0 || version == 1 || version == 2 || version == 4) && (data_version == 0 || data_version == 1 || data_version == 2)) {
			SDL_RWseek(p, 68, SEEK_CUR);
			int32 directory_offset = SDL_ReadBE32(p);
			if (directory_offset >= file_length)
				goto not_map;
			f.SetPosition(128);
			uint32 tag = SDL_ReadBE32(p);
			// ghs: I do not believe this list is comprehensive
			//      I think it's just what we've seen so far?
			switch (tag) {
			case LINE_TAG:
			case POINT_TAG:
			case SIDE_TAG:
				return _typecode_scenario;
				break;
			case MONSTER_PHYSICS_TAG:
				return _typecode_physics;
				break;
			}
				
		}
not_map: ;
	}

	// Check for Shapes file
	{
		f.SetPosition(0);
		for (int i=0; i<32; i++) {
			uint32 status_flags = SDL_ReadBE32(p);
			int32 offset = SDL_ReadBE32(p);
			int32 length = SDL_ReadBE32(p);
			int32 offset16 = SDL_ReadBE32(p);
			int32 length16 = SDL_ReadBE32(p);
			if (status_flags != 0
			 || (offset != NONE && (offset >= file_length || offset + length > file_length))
			 || (offset16 != NONE && (offset16 >= file_length || offset16 + length16 > file_length)))
				goto not_shapes;
			SDL_RWseek(p, 12, SEEK_CUR);
		}
		return _typecode_shapes;
not_shapes: ;
	}

	// Not identified
	return _typecode_unknown;
}
Example #4
0
char * QTRTPFile::GetSDPFile(int * sdpFileLength)
{
    // Temporary vars
    RTPTrackListEntry*  curEntry;
    UInt32              tempAtomType;

    // General vars
    QTFile::AtomTOCEntry*   globalSDPTOCEntry;
    Bool16                  haveGlobalSDPAtom = false;  
    char                    sdpRangeLine[256];
    char*                   pSDPFile;
    
    
    //
    // Return our cached SDP file if we have one.
    if ( fSDPFile != NULL) 
    {
        *sdpFileLength = fSDPFileLength;
        return fSDPFile;
    }
    
    //
    // Build our range header.
    qtss_sprintf(sdpRangeLine, "a=range:npt=0-%10.5f\r\n", this->GetMovieDuration());


    //
    // Figure out how long the SDP file is going to be.
    fSDPFileLength = ::strlen(sdpRangeLine);
    
    for ( curEntry = fFirstTrack;
         curEntry != NULL;
         curEntry = curEntry->NextTrack
        ) 
    {
        // Temporary vars
        int         trackSDPLength;


        //
        // Get the length of this track's SDP file.
        if( curEntry->HintTrack->GetSDPFileLength(&trackSDPLength) != QTTrack::errNoError )
            continue;
        
        //
        // Add it to our count.
        fSDPFileLength += trackSDPLength;
    }

    //
    // See if this movie has a global SDP atom.
    if( fFile->FindTOCEntry("moov:udta:hnti:rtp ", &globalSDPTOCEntry, NULL) )
    {
        //
        // Verify that this is an SDP atom.
        fFile->Read(globalSDPTOCEntry->AtomDataPos, (char *)&tempAtomType, 4);
        
        if ( ntohl(tempAtomType) == FOUR_CHARS_TO_INT('s', 'd', 'p', ' ') ) 
        {
            haveGlobalSDPAtom = true;
            fSDPFileLength += (UInt32) (globalSDPTOCEntry->AtomDataLength - 4);
        }
    }

    //
    // Build the SDP file.
    fSDPFile = pSDPFile = NEW char[fSDPFileLength + 1];
    if( fSDPFile == NULL )
    {   fErr = errInternalError;
        return NULL;
    }
    
    if( haveGlobalSDPAtom ) 
    {
        fFile->Read(globalSDPTOCEntry->AtomDataPos + 4, pSDPFile, (UInt32) (globalSDPTOCEntry->AtomDataLength - 4) );
        pSDPFile += globalSDPTOCEntry->AtomDataLength - 4;
    }
    
    ::memcpy(pSDPFile, sdpRangeLine, ::strlen(sdpRangeLine));
    
    pSDPFile += ::strlen(sdpRangeLine);
    
    for ( curEntry = fFirstTrack;
          curEntry != NULL;
          curEntry = curEntry->NextTrack
        ) 
    {
        // Temporary vars
        char        *trackSDP;
        int         trackSDPLength;
        
        
        //
        // Get this track's SDP file and add it to our buffer.
        trackSDP = curEntry->HintTrack->GetSDPFile(&trackSDPLength);
        if( trackSDP == NULL )
            continue;
        
        ::memcpy(pSDPFile, trackSDP, trackSDPLength);
        delete [] trackSDP;//ARGH! GetSDPFile allocates the pointer that is being returned.
        pSDPFile += trackSDPLength;
    }
    
    
    //
    // Return the (cached) SDP file.
    *sdpFileLength = fSDPFileLength;
    fSDPFile[fSDPFileLength] = 0;

    return fSDPFile;
}
Example #5
0
// -------------------------------------
// Initialization functions
//
Bool16 QTAtom_dref::Initialize(void)
{
    // Temporary vars
    UInt32      tempInt32;

    // General vars
    UInt64      refPos;


    //
    // Parse this atom's fields.
    ReadInt32(drefPos_VersionFlags, &tempInt32);
    fVersion = (UInt8)((tempInt32 >> 24) & 0x000000ff);
    fFlags = tempInt32 & 0x00ffffff;

    ReadInt32(drefPos_NumRefs, &fNumRefs);

    //
    // Read in all of the refs.
    if( fNumRefs > 0 ) {
        //
        // Allocate our ref table.
        fRefs = NEW DataRefEntry[fNumRefs];
        if( fRefs == NULL )
            return false;

        //
        // Read them all in..
        refPos = drefPos_RefTable;
        for( UInt32 CurRef = 0; CurRef < fNumRefs; CurRef++ ) {
            //
            // Set up the entry.
            fRefs[CurRef].Flags = 0x0;
            fRefs[CurRef].ReferenceType = FOUR_CHARS_TO_INT('N', 'U', 'L', 'L'); // NULL
            fRefs[CurRef].DataLength = 0;
            fRefs[CurRef].Data = NULL;

            fRefs[CurRef].IsEntryInitialized = false;
            fRefs[CurRef].IsFileOpen = false;
            fRefs[CurRef].FCB = NULL;


            //
            // Get the flags and type.
            ReadInt32(refPos + drefRefPos_VersionFlags, &tempInt32);
            fRefs[CurRef].Flags = tempInt32 & 0x00ffffff;

            ReadInt32(refPos + drefRefPos_Type, &tempInt32);
            fRefs[CurRef].ReferenceType = tempInt32;
            
            //
            // We're done if this is a self-referencing atom.
            if( fRefs[CurRef].Flags & flagSelfRef ) {
                fRefs[CurRef].IsEntryInitialized = true;
                continue;
            }
            

            //
            // Get all of the data.
            ReadInt32(refPos + drefRefPos_Size, &tempInt32);
            fRefs[CurRef].DataLength = tempInt32 - 12 /* skip the header */;
            
            fRefs[CurRef].Data = NEW char[fRefs[CurRef].DataLength];
            if( fRefs[CurRef].Data == NULL ) {
                //
                // De-initialize this entry.
                fRefs[CurRef].DataLength = 0;
                fRefs[CurRef].IsEntryInitialized = false;
            } else {
                //
                // Read the entry data.
                ReadBytes(refPos + drefRefPos_Data, fRefs[CurRef].Data, fRefs[CurRef].DataLength);
                
                //
                // Configure the rest of the entry.
                fRefs[CurRef].FCB = NEW QTFile_FileControlBlock();
                if( fRefs[CurRef].FCB == NULL )
                    fRefs[CurRef].IsEntryInitialized = false;
                else
                    fRefs[CurRef].IsEntryInitialized = true;
                fRefs[CurRef].IsFileOpen = false;
            }

            //
            // Skip over this mini-atom.
            refPos += fRefs[CurRef].DataLength + 12 /* account for the header */;
        }
    }