GF_Err gf_isom_rtp_packet_begin(GF_ISOFile *the_file, u32 trackNumber, s32 relativeTime, u8 PackingBit, u8 eXtensionBit, u8 MarkerBit, u8 PayloadType, u8 B_frame, u8 IsRepeatedPacket, u16 SequenceNumber) { GF_TrackBox *trak; GF_HintSampleEntryBox *entry; GF_RTPPacket *pck; u32 dataRefIndex; GF_Err e; trak = gf_isom_get_track_from_file(the_file, trackNumber); if (!trak || !CheckHintFormat(trak, GF_ISOM_HINT_RTP)) return GF_BAD_PARAM; e = Media_GetSampleDesc(trak->Media, trak->Media->information->sampleTable->currentEntryIndex, (GF_SampleEntryBox **) &entry, &dataRefIndex); if (e) return e; if (!entry->hint_sample) return GF_BAD_PARAM; pck = (GF_RTPPacket *) gf_isom_hint_pck_new(entry->hint_sample->HintType); pck->P_bit = PackingBit ? 1 : 0; pck->X_bit = eXtensionBit ? 1 : 0; pck->M_bit = MarkerBit ? 1 : 0; pck->payloadType = PayloadType; pck->SequenceNumber = SequenceNumber; pck->B_bit = B_frame ? 1 : 0; pck->R_bit = IsRepeatedPacket ? 1 : 0; pck->relativeTransTime = relativeTime; return gf_list_add(entry->hint_sample->packetTable, pck); }
GF_Err gf_isom_hint_sample_read(GF_HintSample *ptr, GF_BitStream *bs, u32 sampleSize) { u16 entryCount, i; GF_HintPacket *pck; GF_Err e; u64 sizeIn, sizeOut; sizeIn = gf_bs_available(bs); entryCount = gf_bs_read_u16(bs); ptr->reserved = gf_bs_read_u16(bs); for (i = 0; i < entryCount; i++) { pck = gf_isom_hint_pck_new(ptr->HintType); e = gf_isom_hint_pck_read(ptr->HintType, pck, bs); if (e) return e; gf_list_add(ptr->packetTable, pck); } sizeOut = gf_bs_available(bs) - sizeIn; //do we have some more data after the packets ?? if ((u32)sizeOut < sampleSize) { ptr->dataLength = sampleSize - (u32)sizeOut; ptr->AdditionalData = (char*)gf_malloc(sizeof(char) * ptr->dataLength); gf_bs_read_data(bs, ptr->AdditionalData, ptr->dataLength); } return GF_OK; }
GF_Err gf_isom_hint_sample_read(GF_HintSample *ptr, GF_BitStream *bs, u32 sampleSize) { u16 i; u32 type; GF_HintPacket *pck; GF_Err e; char *szName = (ptr->hint_subtype==GF_ISOM_BOX_TYPE_RTCP_STSD) ? "RTCP" : "RTP"; u64 sizeIn, sizeOut; sizeIn = gf_bs_available(bs); switch (ptr->hint_subtype) { case GF_ISOM_BOX_TYPE_RTP_STSD: case GF_ISOM_BOX_TYPE_SRTP_STSD: case GF_ISOM_BOX_TYPE_RRTP_STSD: case GF_ISOM_BOX_TYPE_RTCP_STSD: break; case GF_ISOM_BOX_TYPE_FDP_STSD: ptr->size = gf_bs_read_u32(bs); type = gf_bs_read_u32(bs); if (type != GF_ISOM_BOX_TYPE_FDSA) { GF_LOG(GF_LOG_ERROR, GF_LOG_CONTAINER, ("[iso] invalid FDT sample, top box type %s not fdsa\n", gf_4cc_to_str(type) )); return GF_ISOM_INVALID_MEDIA; } return gf_isom_box_read((GF_Box*)ptr, bs); default: return GF_NOT_SUPPORTED; } ptr->packetCount = gf_bs_read_u16(bs); ptr->reserved = gf_bs_read_u16(bs); if (ptr->packetCount>=sampleSize) { GF_LOG(GF_LOG_ERROR, GF_LOG_CONTAINER, ("[iso] broken %s sample: %d packet_count indicated but only %d bytes in samples\n", szName, ptr->packetCount, sampleSize)); return GF_ISOM_INVALID_MEDIA; } for (i = 0; i < ptr->packetCount; i++) { if (! gf_bs_available(bs) ) { GF_LOG(GF_LOG_ERROR, GF_LOG_CONTAINER, ("[iso] %s hint sample has no more data but still %d entries to read\n", szName, ptr->packetCount-i)); return GF_ISOM_INVALID_MEDIA; } pck = gf_isom_hint_pck_new(ptr->hint_subtype); pck->trackID = ptr->trackID; pck->sampleNumber = ptr->sampleNumber; gf_list_add(ptr->packetTable, pck); e = gf_isom_hint_pck_read(pck, bs); if (e) return e; } if (ptr->hint_subtype==GF_ISOM_BOX_TYPE_RTCP_STSD) return GF_OK; sizeOut = gf_bs_available(bs) - sizeIn; //do we have some more data after the packets ?? if ((u32)sizeOut < sampleSize) { ptr->dataLength = sampleSize - (u32)sizeOut; ptr->AdditionalData = (char*)gf_malloc(sizeof(char) * ptr->dataLength); gf_bs_read_data(bs, ptr->AdditionalData, ptr->dataLength); } return GF_OK; }