GF_EXPORT GF_Err gf_bifs_encode_au(GF_BifsEncoder *codec, u16 ESID, GF_List *command_list, char **out_data, u32 *out_data_length) { GF_BitStream *bs; GF_Err e; if (!codec || !command_list || !out_data || !out_data_length) return GF_BAD_PARAM; // gf_mx_p(codec->mx); codec->info = BE_GetStream(codec, ESID); if (!codec->info) { // gf_mx_v(codec->mx); return GF_BAD_PARAM; } bs = gf_bs_new(NULL, 0, GF_BITSTREAM_WRITE); if (codec->info->config.elementaryMasks) { e = GF_NOT_SUPPORTED; } else { e = gf_bifs_enc_commands(codec, command_list, bs); } gf_bs_align(bs); gf_bs_get_content(bs, out_data, out_data_length); gf_bs_del(bs); // gf_mx_v(codec->mx); return e; }
u32 MPEGVS_OnData(struct __input_device * dr, const char* data) { GF_BitStream *bs; char *buf; u32 buf_size; float x, y, z; bs = gf_bs_new(NULL, 0, GF_BITSTREAM_WRITE); sscanf(data, "%f;%f;%f;", &x, &y, &z); gf_bs_write_int(bs, 1, 1); gf_bs_write_float(bs, x); gf_bs_write_float(bs, y); gf_bs_write_float(bs, z); gf_bs_align(bs); gf_bs_get_content(bs, &buf, &buf_size); gf_bs_del(bs); dr->DispatchFrame(dr, (u8*)buf, buf_size); gf_free(buf); return GF_OK; }
GF_EXPORT GF_Err gf_odf_avc_cfg_write(GF_AVCConfig *cfg, char **outData, u32 *outSize) { u32 i, count; GF_BitStream *bs = gf_bs_new(NULL, 0, GF_BITSTREAM_WRITE); gf_bs_write_int(bs, cfg->configurationVersion, 8); gf_bs_write_int(bs, cfg->AVCProfileIndication , 8); gf_bs_write_int(bs, cfg->profile_compatibility, 8); gf_bs_write_int(bs, cfg->AVCLevelIndication, 8); gf_bs_write_int(bs, 0x3F, 6); gf_bs_write_int(bs, cfg->nal_unit_size - 1, 2); gf_bs_write_int(bs, 0x7, 3); count = gf_list_count(cfg->sequenceParameterSets); gf_bs_write_int(bs, count, 5); for (i=0; i<count; i++) { GF_AVCConfigSlot *sl = (GF_AVCConfigSlot *)gf_list_get(cfg->sequenceParameterSets, i); gf_bs_write_int(bs, sl->size, 16); gf_bs_write_data(bs, sl->data, sl->size); } count = gf_list_count(cfg->pictureParameterSets); gf_bs_write_int(bs, count, 8); for (i=0; i<count; i++) { GF_AVCConfigSlot *sl = (GF_AVCConfigSlot *)gf_list_get(cfg->pictureParameterSets, i); gf_bs_write_int(bs, sl->size, 16); gf_bs_write_data(bs, sl->data, sl->size); } *outSize = 0; *outData = NULL; gf_bs_get_content(bs, outData, outSize); gf_bs_del(bs); return GF_OK; }
GF_EXPORT GF_Err gf_bifs_encoder_get_rap(GF_BifsEncoder *codec, char **out_data, u32 *out_data_length) { GF_BitStream *bs; GF_Err e; GF_List *ctx_bck; /*reset context for RAP encoding*/ ctx_bck = codec->encoded_nodes; codec->encoded_nodes = gf_list_new(); if (!codec->info) codec->info = (BIFSStreamInfo*)gf_list_get(codec->streamInfo, 0); bs = gf_bs_new(NULL, 0, GF_BITSTREAM_WRITE); GF_BIFS_WRITE_INT(codec, bs, 3, 2, "SceneReplace", NULL); e = BE_SceneReplace(codec, codec->scene_graph, bs); if (e == GF_OK) { GF_BIFS_WRITE_INT(codec, bs, 0, 1, "moreCommands", NULL); gf_bs_get_content(bs, out_data, out_data_length); } gf_bs_del(bs); /*restore context*/ gf_list_del(codec->encoded_nodes); codec->encoded_nodes = ctx_bck; return e; }
GF_EXPORT GF_Err gf_oci_codec_encode(OCICodec *codec, char **outAU, u32 *au_length) { GF_BitStream *bs; u32 i, size, desc_size; GF_Err e; OCIEvent *ev; if (!codec || !codec->Mode || *outAU) return GF_BAD_PARAM; bs = NULL; size = 0; //get the size of each event i=0; while ((ev = (OCIEvent *)gf_list_enum(codec->OCIEvents, &i))) { //fixed size header size += 10; e = gf_odf_size_descriptor_list(codec->OCIEvents, &desc_size); if (e) goto err_exit; size += desc_size; } //encode bs = gf_bs_new(NULL, 0, GF_BITSTREAM_WRITE); e = WriteSevenBitLength(bs, size); if (e) goto err_exit; //get one event, write it and delete it while (gf_list_count(codec->OCIEvents)) { ev = (OCIEvent *)gf_list_get(codec->OCIEvents, 0); gf_list_rem(codec->OCIEvents, 0); gf_bs_write_int(bs, ev->EventID, 15); gf_bs_write_int(bs, ev->AbsoluteTimeFlag, 1); gf_bs_write_data(bs, ev->StartingTime, 4); gf_bs_write_data(bs, ev->duration, 4); e = gf_odf_write_descriptor_list(bs, ev->OCIDescriptors); gf_oci_event_del(ev); if (e) goto err_exit; //OCI Event is aligned gf_bs_align(bs); } gf_bs_get_content(bs, outAU, au_length); gf_bs_del(bs); return GF_OK; err_exit: if (bs) gf_bs_del(bs); //delete everything while (gf_list_count(codec->OCIEvents)) { ev = (OCIEvent *)gf_list_get(codec->OCIEvents, 0); gf_list_rem(codec->OCIEvents, 0); gf_oci_event_del(ev); } return e; }
GF_EXPORT GF_Err gf_odf_encode_ui_config(GF_UIConfig *cfg, GF_DefaultDescriptor **out_dsi) { u32 i, len; GF_BitStream *bs; GF_DefaultDescriptor *dsi; if (!out_dsi || (cfg->tag != GF_ODF_UI_CFG_TAG)) return GF_BAD_PARAM; *out_dsi = NULL; if (!cfg->deviceName) return GF_OK; bs = gf_bs_new(NULL, 0, GF_BITSTREAM_WRITE); len = strlen(cfg->deviceName); gf_bs_write_int(bs, len, 8); for (i=0; i<len; i++) gf_bs_write_int(bs, cfg->deviceName[i], 8); if (!stricmp(cfg->deviceName, "StringSensor")) { /*fixme - this should be UTF-8 chars*/ if (cfg->delChar || cfg->termChar) { gf_bs_write_int(bs, cfg->termChar, 8); gf_bs_write_int(bs, cfg->delChar, 8); } } if (cfg->ui_data) gf_bs_write_data(bs, cfg->ui_data, cfg->ui_data_length); dsi = (GF_DefaultDescriptor *) gf_odf_desc_new(GF_ODF_DSI_TAG); gf_bs_get_content(bs, &dsi->data, &dsi->dataLength); gf_bs_del(bs); *out_dsi = dsi; return GF_OK; }
u32 RunHTKDec(void *par) { GF_BitStream *bs; char *szWord; s32 word_index; u32 len, val, i; Float word_score; GF_SLHeader slh; GF_Codec *cod; unsigned char *buf; u32 buf_size; ISPriv *is_dec = (ISPriv *)par; // while (is_dec->htk_running) HTK_DoDetection(); szWord = HTK_GetWord(); word_index = HTK_GetWordIndex(); word_score = HTK_GetWordScore(); bs = gf_bs_new(NULL, 0, GF_BITSTREAM_WRITE); /*HTK sensor buffer format: SFString - SFInt32 - SFFloat*/ gf_bs_write_int(bs, 1, 1); len = strlen(szWord); val = gf_get_bit_size(len); gf_bs_write_int(bs, val, 5); gf_bs_write_int(bs, len, val); for (i=0; i<len; i++) gf_bs_write_int(bs, szWord[i], 8); gf_bs_write_int(bs, 1, 1); gf_bs_write_int(bs, word_index, 32); gf_bs_write_int(bs, 1, 1); gf_bs_write_float(bs, word_score); gf_bs_align(bs); gf_bs_get_content(bs, &buf, &buf_size); gf_bs_del(bs); memset(&slh, 0, sizeof(GF_SLHeader)); slh.accessUnitStartFlag = slh.accessUnitEndFlag = 1; slh.compositionTimeStamp = 0; /*get all IS keySensor decoders and send frame*/ i=0; while ((cod = gf_list_enum(is_dec->scene->root_od->term->input_streams, &i))) { ISPriv *is = cod->decio->privateStack; if (is != is_dec) continue; if (is->type==IS_HTKSensor) { GF_Channel *ch = gf_list_get(cod->inChannels, 0); gf_es_receive_sl_packet(ch->service, ch, buf, buf_size, &slh, GF_OK); } } free(buf); is_dec->htk_running = 0; return 0; }
GF_EXPORT GF_Err gf_odf_codec_get_au(GF_ODCodec *codec, char **outAU, u32 *au_length) { if (!codec || !codec->bs || !outAU || *outAU) return GF_BAD_PARAM; gf_bs_get_content(codec->bs, outAU, au_length); gf_bs_del(codec->bs); codec->bs = NULL; return GF_OK; }
GF_EXPORT GF_Err gf_bifs_encoder_get_config(GF_BifsEncoder *codec, u16 ESID, char **out_data, u32 *out_data_length) { GF_BitStream *bs; if (!codec || !out_data || !out_data_length) return GF_BAD_PARAM; // gf_mx_p(codec->mx); codec->info = BE_GetStream(codec, ESID); if (!codec->info) { // gf_mx_v(codec->mx); return GF_BAD_PARAM; } bs = gf_bs_new(NULL, 0, GF_BITSTREAM_WRITE); if (codec->info->config.version==2) { gf_bs_write_int(bs, codec->info->config.Use3DMeshCoding ? 1 : 0, 1); gf_bs_write_int(bs, codec->info->config.UsePredictiveMFField ? 1 : 0, 1); } gf_bs_write_int(bs, codec->info->config.NodeIDBits, 5); gf_bs_write_int(bs, codec->info->config.RouteIDBits, 5); if (codec->info->config.version==2) { gf_bs_write_int(bs, codec->info->config.ProtoIDBits, 5); } if (codec->info->config.elementaryMasks) { u32 i, count; gf_bs_write_int(bs, 0, 1); gf_bs_write_int(bs, codec->info->config.BAnimRAP, 1); count = gf_list_count(codec->info->config.elementaryMasks); for (i=0; i<count; i++) { BIFSElementaryMask *em = (BIFSElementaryMask *)gf_list_get(codec->info->config.elementaryMasks, i); if (em->node) gf_bs_write_int(bs, gf_node_get_id((GF_Node*)em->node), codec->info->config.NodeIDBits); else gf_bs_write_int(bs, em->node_id, codec->info->config.NodeIDBits); gf_bs_write_int(bs, (i+1==count) ? 0 : 1, 1); } } else { gf_bs_write_int(bs, 1, 1); gf_bs_write_int(bs, codec->info->config.PixelMetrics ? 1 : 0, 1); if (codec->info->config.Width || codec->info->config.Height) { gf_bs_write_int(bs, 1, 1); gf_bs_write_int(bs, codec->info->config.Width, 16); gf_bs_write_int(bs, codec->info->config.Height, 16); } else { gf_bs_write_int(bs, 0, 1); } } gf_bs_align(bs); gf_bs_get_content(bs, out_data, out_data_length); gf_bs_del(bs); // gf_mx_v(codec->mx); return GF_OK; }
GF_EXPORT GF_Err gf_odf_avc_cfg_write(GF_AVCConfig *cfg, char **outData, u32 *outSize) { u32 i, count; GF_BitStream *bs = gf_bs_new(NULL, 0, GF_BITSTREAM_WRITE); gf_bs_write_int(bs, cfg->configurationVersion, 8); gf_bs_write_int(bs, cfg->AVCProfileIndication , 8); gf_bs_write_int(bs, cfg->profile_compatibility, 8); gf_bs_write_int(bs, cfg->AVCLevelIndication, 8); gf_bs_write_int(bs, 0x3F, 6); gf_bs_write_int(bs, cfg->nal_unit_size - 1, 2); gf_bs_write_int(bs, 0x7, 3); count = gf_list_count(cfg->sequenceParameterSets); gf_bs_write_int(bs, count, 5); for (i=0; i<count; i++) { GF_AVCConfigSlot *sl = (GF_AVCConfigSlot *)gf_list_get(cfg->sequenceParameterSets, i); gf_bs_write_int(bs, sl->size, 16); gf_bs_write_data(bs, sl->data, sl->size); } count = gf_list_count(cfg->pictureParameterSets); gf_bs_write_int(bs, count, 8); for (i=0; i<count; i++) { GF_AVCConfigSlot *sl = (GF_AVCConfigSlot *)gf_list_get(cfg->pictureParameterSets, i); gf_bs_write_int(bs, sl->size, 16); gf_bs_write_data(bs, sl->data, sl->size); } switch (cfg->AVCProfileIndication) { case 100: case 110: case 122: case 144: gf_bs_write_int(bs, 0xFF, 6); gf_bs_write_int(bs, cfg->chroma_format, 2); gf_bs_write_int(bs, 0xFF, 5); gf_bs_write_int(bs, cfg->luma_bit_depth - 8, 3); gf_bs_write_int(bs, 0xFF, 5); gf_bs_write_int(bs, cfg->chroma_bit_depth - 8, 3); count = cfg->sequenceParameterSetExtensions ? gf_list_count(cfg->sequenceParameterSetExtensions) : 0; gf_bs_write_u8(bs, count); for (i=0; i<count; i++) { GF_AVCConfigSlot *sl = (GF_AVCConfigSlot *) gf_list_get(cfg->sequenceParameterSetExtensions, i); gf_bs_write_u16(bs, sl->size); gf_bs_write_data(bs, sl->data, sl->size); } break; } *outSize = 0; *outData = NULL; gf_bs_get_content(bs, outData, outSize); gf_bs_del(bs); return GF_OK; }
static GF_Err JP2_AttachStream(GF_BaseDecoder *ifcg, GF_ESD *esd) { GF_BitStream *bs; JP2CTX(); if (esd->dependsOnESID || esd->decoderConfig->upstream) return GF_NOT_SUPPORTED; if (!esd->decoderConfig->decoderSpecificInfo) return GF_OK; if (esd->decoderConfig->objectTypeIndication==GPAC_OTI_IMAGE_JPEG_2000) { bs = gf_bs_new(esd->decoderConfig->decoderSpecificInfo->data, esd->decoderConfig->decoderSpecificInfo->dataLength, GF_BITSTREAM_READ); ctx->height = gf_bs_read_u32(bs); ctx->width = gf_bs_read_u32(bs); ctx->nb_comp = gf_bs_read_u16(bs); ctx->bpp = 1 + gf_bs_read_u8(bs); ctx->out_size = ctx->width * ctx->height * ctx->nb_comp /* * ctx->bpp / 8 */; gf_bs_del(bs); switch (ctx->nb_comp) { case 1: ctx->pixel_format = GF_PIXEL_GREYSCALE; break; case 2: ctx->pixel_format = GF_PIXEL_ALPHAGREY; break; case 3: ctx->pixel_format = GF_PIXEL_RGB_24; break; case 4: ctx->pixel_format = GF_PIXEL_RGBA; break; default: return GF_NOT_SUPPORTED; } } else { bs = gf_bs_new(esd->decoderConfig->decoderSpecificInfo->data, esd->decoderConfig->decoderSpecificInfo->dataLength, GF_BITSTREAM_READ); gf_bs_read_u32(bs); ctx->width = gf_bs_read_u16(bs); ctx->height = gf_bs_read_u16(bs); gf_bs_del(bs); bs = gf_bs_new(NULL, 0, GF_BITSTREAM_WRITE); gf_bs_write_u32(bs, 12); gf_bs_write_u32(bs, GF_4CC('j','P',' ',' ') ); gf_bs_write_u32(bs, 0x0D0A870A); gf_bs_write_u32(bs, 20); gf_bs_write_u32(bs, GF_4CC('f','t','y','p') ); gf_bs_write_u32(bs, GF_4CC('j','p','2',' ') ); gf_bs_write_u32(bs, 0); gf_bs_write_u32(bs, GF_4CC('j','p','2',' ') ); gf_bs_write_data(bs, esd->decoderConfig->decoderSpecificInfo->data+8, esd->decoderConfig->decoderSpecificInfo->dataLength-8); gf_bs_get_content(bs, &ctx->dsi, &ctx->dsi_size); gf_bs_del(bs); ctx->nb_comp = 3; ctx->out_size = 3*ctx->width*ctx->height/2; ctx->pixel_format = GF_PIXEL_YV12; } return GF_OK; }
GF_EXPORT GF_Err gf_odf_hevc_cfg_write(GF_HEVCConfig *cfg, char **outData, u32 *outSize) { GF_Err e; GF_BitStream *bs = gf_bs_new(NULL, 0, GF_BITSTREAM_WRITE); *outSize = 0; *outData = NULL; e = gf_odf_hevc_cfg_write_bs(cfg, bs); if (e==GF_OK) gf_bs_get_content(bs, outData, outSize); gf_bs_del(bs); return e; }
/*allocates and writes the SL-PDU (Header + PDU) given the SLConfig and the GF_SLHeader for this PDU. AUs must be split in PDUs by another process if needed (packetizer).*/ GF_EXPORT void gf_sl_packetize(GF_SLConfig* slConfig, GF_SLHeader *Header, char *PDU, u32 size, char **outPacket, u32 *OutSize) { GF_BitStream *bs = gf_bs_new(NULL, 0, GF_BITSTREAM_WRITE); *OutSize = 0; if (!bs) return; if (slConfig->useAccessUnitStartFlag) gf_bs_write_int(bs, Header->accessUnitStartFlag, 1); if (slConfig->useAccessUnitEndFlag) gf_bs_write_int(bs, Header->accessUnitEndFlag, 1); if (slConfig->OCRLength > 0) gf_bs_write_int(bs, Header->OCRflag, 1); if (slConfig->useIdleFlag) gf_bs_write_int(bs, Header->idleFlag, 1); if (slConfig->usePaddingFlag) { gf_bs_write_int(bs, Header->paddingFlag, 1); if (Header->paddingFlag) gf_bs_write_int(bs, Header->paddingBits, 3); } if (! Header->idleFlag && (! Header->paddingFlag || Header->paddingBits != 0)) { if (slConfig->packetSeqNumLength > 0) gf_bs_write_int(bs, Header->packetSequenceNumber, slConfig->packetSeqNumLength); if (slConfig->degradationPriorityLength > 0) { gf_bs_write_int(bs, Header->degradationPriorityFlag, 1); if (Header->degradationPriorityFlag) gf_bs_write_int(bs, Header->degradationPriority, slConfig->degradationPriorityLength); } if (Header->OCRflag) gf_bs_write_long_int(bs, Header->objectClockReference, slConfig->OCRLength); if (Header->accessUnitStartFlag) { if (slConfig->useRandomAccessPointFlag) gf_bs_write_int(bs, Header->randomAccessPointFlag, 1); if (slConfig->AUSeqNumLength > 0) gf_bs_write_int(bs, Header->AU_sequenceNumber, slConfig->AUSeqNumLength); if (slConfig->useTimestampsFlag) { gf_bs_write_int(bs, Header->decodingTimeStampFlag, 1); gf_bs_write_int(bs, Header->compositionTimeStampFlag, 1); } if (slConfig->instantBitrateLength > 0) gf_bs_write_int(bs, Header->instantBitrateFlag, 1); if (Header->decodingTimeStampFlag) gf_bs_write_long_int(bs, Header->decodingTimeStamp, slConfig->timestampLength); if (Header->compositionTimeStampFlag) gf_bs_write_long_int(bs, Header->compositionTimeStamp, slConfig->timestampLength); if (slConfig->AULength > 0) gf_bs_write_int(bs, Header->accessUnitLength, slConfig->AULength); if (Header->instantBitrateFlag) gf_bs_write_int(bs, Header->instantBitrate, slConfig->instantBitrateLength); } } //done with the Header, Alin gf_bs_align(bs); //write the PDU - already byte aligned with stuffing (paddingBits in SL Header) gf_bs_write_data(bs, PDU, size); gf_bs_align(bs); gf_bs_get_content(bs, outPacket, OutSize); gf_bs_del(bs); }
static void rtp_amr_flush(GP_RTPPacketizer *builder) { char *hdr; u32 hdr_size; if (!builder->bytesInPacket) return; gf_bs_get_content(builder->pck_hdr, &hdr, &hdr_size); gf_bs_del(builder->pck_hdr); builder->pck_hdr = NULL; /*overwrite last frame F bit*/ hdr[builder->last_au_sn] &= 0x7F; builder->OnData(builder->cbk_obj, hdr, hdr_size, 1); gf_free(hdr); builder->OnPacketDone(builder->cbk_obj, &builder->rtp_header); builder->bytesInPacket = 0; builder->last_au_sn = 0; }
/*Dummy input just send a file name, no multitrack to handle so we don't need to check sub_url nor expected type*/ static GF_Descriptor *DC_GetServiceDesc(GF_InputService *plug, u32 expect_type, const char *sub_url) { u32 size = 0; char *uri; GF_ESD *esd; GF_BitStream *bs; DCReader *read = (DCReader *) plug->priv; GF_InitialObjectDescriptor *iod = (GF_InitialObjectDescriptor *) gf_odf_desc_new(GF_ODF_IOD_TAG); iod->scene_profileAndLevel = 1; iod->graphics_profileAndLevel = 1; iod->OD_profileAndLevel = 1; iod->audio_profileAndLevel = 0xFE; iod->visual_profileAndLevel = 0xFE; iod->objectDescriptorID = 1; if (read->is_views_url) { iod->URLString = gf_strdup(read->url); return (GF_Descriptor *)iod; } esd = gf_odf_desc_esd_new(0); esd->slConfig->timestampResolution = 1000; esd->slConfig->useTimestampsFlag = 1; esd->ESID = 0xFFFE; esd->decoderConfig->streamType = GF_STREAM_PRIVATE_SCENE; esd->decoderConfig->objectTypeIndication = read->oti; if (read->dnload) { uri = (char *) gf_dm_sess_get_cache_name(read->dnload); gf_dm_sess_get_stats(read->dnload, NULL, NULL, &size, NULL, NULL, NULL); } else { FILE *f = gf_fopen(read->url, "rt"); gf_fseek(f, 0, SEEK_END); size = (u32) gf_ftell(f); gf_fclose(f); uri = read->url; } bs = gf_bs_new(NULL, 0, GF_BITSTREAM_WRITE); gf_bs_write_u32(bs, size); gf_bs_write_data(bs, uri, (u32) strlen(uri)); gf_bs_get_content(bs, &esd->decoderConfig->decoderSpecificInfo->data, &esd->decoderConfig->decoderSpecificInfo->dataLength); gf_bs_del(bs); gf_list_add(iod->ESDescriptors, esd); return (GF_Descriptor *)iod; }
//stores the hint sample in the file //set IsRandomAccessPoint if you want to indicate that this is a random access point //in the stream GF_Err gf_isom_end_hint_sample(GF_ISOFile *the_file, u32 trackNumber, u8 IsRandomAccessPoint) { GF_TrackBox *trak; GF_HintSampleEntryBox *entry; u32 dataRefIndex; GF_Err e; GF_BitStream *bs; GF_ISOSample *samp; trak = gf_isom_get_track_from_file(the_file, trackNumber); if (!trak || !IsHintTrack(trak)) 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; //first of all, we need to adjust the offset for data referenced IN THIS hint sample //and get some PckSize e = AdjustHintInfo(entry, trak->Media->information->sampleTable->SampleSize->sampleCount + 1); if (e) return e; //ok, let's write the sample bs = gf_bs_new(NULL, 0, GF_BITSTREAM_WRITE); e = gf_isom_hint_sample_write(entry->hint_sample, bs); if (e) { gf_bs_del(bs); return e; } samp = gf_isom_sample_new(); samp->CTS_Offset = 0; samp->IsRAP = IsRandomAccessPoint; samp->DTS = entry->hint_sample->TransmissionTime; //get the sample gf_bs_get_content(bs, &samp->data, &samp->dataLength); gf_bs_del(bs); //finally add the sample e = gf_isom_add_sample(the_file, trackNumber, trak->Media->information->sampleTable->currentEntryIndex, samp); gf_isom_sample_del(&samp); //and delete the sample in our entry ... gf_isom_hint_sample_del(entry->hint_sample); entry->hint_sample = NULL; return e; }
GF_Err MCDec_InitMpeg4Decoder(MCDec *ctx) { char *dsi_data = NULL; u32 dsi_data_size = 0; if (!ctx->esd->decoderConfig->decoderSpecificInfo) { ctx->esd->decoderConfig->decoderSpecificInfo = (GF_DefaultDescriptor *) gf_odf_desc_new(GF_ODF_DSI_TAG); } if (ctx->esd->decoderConfig->decoderSpecificInfo->data) { GF_M4VDecSpecInfo vcfg; GF_BitStream *bs; gf_m4v_get_config(ctx->esd->decoderConfig->decoderSpecificInfo->data, ctx->esd->decoderConfig->decoderSpecificInfo->dataLength, &vcfg); ctx->width = vcfg.width; ctx->height = vcfg.height; if (ctx->esd->slConfig) { ctx->esd->slConfig->predefined = 2; } bs = gf_bs_new(NULL, 0, GF_BITSTREAM_WRITE); gf_bs_write_u32(bs, 0); gf_odf_desc_write_bs((GF_Descriptor *) ctx->esd, bs); gf_bs_get_content(bs, &dsi_data, &dsi_data_size); gf_bs_del(bs); ctx->mime = "video/mp4v-es"; char *esds = (char *)malloc(dsi_data_size); memcpy(esds, dsi_data, dsi_data_size); esds[0] = 0x00; esds[1] = 0x00; esds[2] = 0x00; esds[3] = 0x01; AMediaFormat_setBuffer(ctx->format, "csd-0", esds, dsi_data_size); gf_free(dsi_data); return GF_OK; } return GF_NOT_SUPPORTED; }
GF_EXPORT GF_Err gf_odf_desc_write(GF_Descriptor *desc, char **outEncDesc, u32 *outSize) { GF_Err e; GF_BitStream *bs; if (!desc || !outEncDesc || !outSize) return GF_BAD_PARAM; *outEncDesc = NULL; *outSize = 0; bs = gf_bs_new(NULL, 0, GF_BITSTREAM_WRITE); if (!bs) return GF_OUT_OF_MEM; e = gf_odf_desc_write_bs(desc, bs); //then get the content from our bitstream gf_bs_get_content(bs, outEncDesc, outSize); gf_bs_del(bs); return e; }
GF_ISOSample *gf_isom_webvtt_to_sample(void *s) { GF_Err e = GF_OK; GF_ISOSample *res; GF_BitStream *bs; u32 i; GF_WebVTTCue *cue; GF_WebVTTSample *samp = (GF_WebVTTSample *)s; if (!samp) return NULL; bs = gf_bs_new(NULL, 0, GF_BITSTREAM_WRITE); if (gf_list_count(samp->cues)) { i=0; while ((cue = (GF_WebVTTCue *)gf_list_enum(samp->cues, &i))) { e = webvtt_write_cue(bs, cue); if (e) break; } if (e) { gf_bs_del(bs); return NULL; } } else { GF_Box *cuebox = (GF_Box *)vtte_New(); e = gf_isom_box_size((GF_Box *)cuebox); if (!e) e = gf_isom_box_write((GF_Box *)cuebox, bs); gf_isom_box_del((GF_Box *)cuebox); if (e) { gf_bs_del(bs); return NULL; } } res = gf_isom_sample_new(); if (!res) { gf_bs_del(bs); return NULL; } gf_bs_get_content(bs, &res->data, &res->dataLength); gf_bs_del(bs); res->IsRAP = RAP; return res; }
static void rtp_evrc_smv_flush(GP_RTPPacketizer *builder) { if (!builder->bytesInPacket) return; if (builder->auh_size>1) { char *hdr; u32 hdr_size; /*padding*/ if (builder->last_au_sn % 2) gf_bs_write_int(builder->pck_hdr, 0, 4); gf_bs_get_content(builder->pck_hdr, &hdr, &hdr_size); gf_bs_del(builder->pck_hdr); builder->pck_hdr = NULL; /*overwrite count*/ hdr[0] = 0; hdr[1] = builder->last_au_sn-1;/*MMM + frameCount-1*/ builder->OnData(builder->cbk_obj, hdr, hdr_size, 1); gf_free(hdr); } builder->OnPacketDone(builder->cbk_obj, &builder->rtp_header); builder->bytesInPacket = 0; builder->last_au_sn = 0; }
GF_Err gf_isom_text_get_encoded_tx3g(GF_ISOFile *file, u32 track, u32 sidx, u32 sidx_offset, char **tx3g, u32 *tx3g_size) { GF_BitStream *bs; GF_TrackBox *trak; GF_Tx3gSampleEntryBox *a; trak = gf_isom_get_track_from_file(file, track); if (!trak) return GF_BAD_PARAM; a = (GF_Tx3gSampleEntryBox *) gf_list_get(trak->Media->information->sampleTable->SampleDescription->boxList, sidx-1); if (!a) return GF_BAD_PARAM; if ((a->type != GF_ISOM_BOX_TYPE_TX3G) && (a->type != GF_ISOM_BOX_TYPE_TEXT)) return GF_BAD_PARAM; bs = gf_bs_new(NULL, 0, GF_BITSTREAM_WRITE); gf_isom_write_tx3g(a, bs, sidx, sidx_offset); *tx3g = NULL; *tx3g_size = 0; gf_bs_get_content(bs, tx3g, tx3g_size); gf_bs_del(bs); return GF_OK; }
GF_Err gf_isom_rewrite_text_sample(GF_ISOSample *samp, u32 sampleDescriptionIndex, u32 sample_dur) { GF_BitStream *bs; u32 pay_start, txt_size; Bool is_utf_16 = 0; if (!samp || !samp->data || !samp->dataLength) return GF_OK; bs = gf_bs_new(samp->data, samp->dataLength, GF_BITSTREAM_READ); txt_size = gf_bs_read_u16(bs); gf_bs_del(bs); /*remove BOM*/ pay_start = 2; if (txt_size>2) { /*seems 3GP only accepts BE UTF-16 (no LE, no UTF32)*/ if (((u8) samp->data[2]==(u8) 0xFE) && ((u8)samp->data[3]==(u8) 0xFF)) { is_utf_16 = 1; pay_start = 4; txt_size -= 2; } } /*rewrite as TTU(1)*/ bs = gf_bs_new(NULL, 0, GF_BITSTREAM_WRITE); gf_bs_write_int(bs, is_utf_16, 1); gf_bs_write_int(bs, 0, 4); gf_bs_write_int(bs, 1, 3); gf_bs_write_u16(bs, 8 + samp->dataLength - pay_start); gf_bs_write_u8(bs, sampleDescriptionIndex + SAMPLE_INDEX_OFFSET); gf_bs_write_u24(bs, sample_dur); /*write text size*/ gf_bs_write_u16(bs, txt_size); if (txt_size) gf_bs_write_data(bs, samp->data + pay_start, samp->dataLength - pay_start); gf_free(samp->data); samp->data = NULL; gf_bs_get_content(bs, &samp->data, &samp->dataLength); gf_bs_del(bs); return GF_OK; }
GF_ISOSample *gf_isom_text_to_sample(GF_TextSample *samp) { GF_Err e; GF_ISOSample *res; GF_BitStream *bs; u32 i; if (!samp) return NULL; bs = gf_bs_new(NULL, 0, GF_BITSTREAM_WRITE); gf_bs_write_u16(bs, samp->len); if (samp->len) gf_bs_write_data(bs, samp->text, samp->len); e = gpp_write_modifier(bs, (GF_Box *)samp->styles); if (!e) e = gpp_write_modifier(bs, (GF_Box *)samp->highlight_color); if (!e) e = gpp_write_modifier(bs, (GF_Box *)samp->scroll_delay); if (!e) e = gpp_write_modifier(bs, (GF_Box *)samp->box); if (!e) e = gpp_write_modifier(bs, (GF_Box *)samp->wrap); if (!e) { GF_Box *a; i=0; while ((a = (GF_Box*)gf_list_enum(samp->others, &i))) { e = gpp_write_modifier(bs, a); if (e) break; } } if (e) { gf_bs_del(bs); return NULL; } res = gf_isom_sample_new(); if (!res) { gf_bs_del(bs); return NULL; } gf_bs_get_content(bs, &res->data, &res->dataLength); gf_bs_del(bs); res->IsRAP = 1; return res; }
/* * Writing the generic sample structure into a sample buffer * 2 options: * - putting the text or XML in the sample directly * - or using a meta box to structure the sample data */ GF_ISOSample *gf_isom_generic_subtitle_to_sample(GF_GenericSubtitleSample *samp) { GF_ISOSample *res; GF_BitStream *bs; if (!samp) return NULL; bs = gf_bs_new(NULL, 0, GF_BITSTREAM_WRITE); //gf_bs_write_u16(bs, samp->len); if (samp->len) gf_bs_write_data(bs, samp->text, samp->len); else gf_bs_write_data(bs, "", 1); res = gf_isom_sample_new(); if (!res) { gf_bs_del(bs); return NULL; } gf_bs_get_content(bs, &res->data, &res->dataLength); gf_bs_del(bs); res->IsRAP = 1; return res; }
static GF_ESD* get_esd() { GF_BitStream *dsi = gf_bs_new(NULL, 0, GF_BITSTREAM_WRITE); GF_ESD *esd = gf_odf_desc_esd_new(0); esd->ESID = 1; esd->decoderConfig->streamType = GF_STREAM_AUDIO; esd->decoderConfig->objectTypeIndication = GPAC_OTI_RAW_MEDIA_STREAM; esd->decoderConfig->avgBitrate = esd->decoderConfig->maxBitrate = 0; esd->slConfig->timestampResolution = FM_FAKE_PULL_AUDIO_FREQ; /*Decoder Specific Info for raw media*/ gf_bs_write_u32(dsi, FM_FAKE_PULL_AUDIO_FREQ); /*u32 sample_rate*/ gf_bs_write_u16(dsi, FM_FAKE_PULL_CHAN_NUM); /*u16 nb_channels*/ gf_bs_write_u16(dsi, FM_FAKE_PULL_BITS); /*u16 nb_bits_per_sample*/ gf_bs_write_u32(dsi, FM_FAKE_PULL_FRAME_LEN); /*u32 frame_size*/ gf_bs_write_u32(dsi, 0); /*u32 channel_config*/ gf_bs_get_content(dsi, &esd->decoderConfig->decoderSpecificInfo->data, &esd->decoderConfig->decoderSpecificInfo->dataLength); gf_bs_del(dsi); return esd; }
static GF_ESD *AAC_GetESD(AACReader *read) { GF_BitStream *dsi; GF_ESD *esd; u32 i, sbr_sr_idx; esd = gf_odf_desc_esd_new(0); esd->decoderConfig->streamType = GF_STREAM_AUDIO; esd->decoderConfig->objectTypeIndication = read->oti; esd->ESID = 1; esd->OCRESID = 1; esd->slConfig->timestampResolution = read->sample_rate; if (read->is_live) esd->slConfig->useAccessUnitEndFlag = esd->slConfig->useAccessUnitStartFlag = 1; dsi = gf_bs_new(NULL, 0, GF_BITSTREAM_WRITE); /*write as regular AAC*/ gf_bs_write_int(dsi, read->prof, 5); gf_bs_write_int(dsi, read->sr_idx, 4); gf_bs_write_int(dsi, read->nb_ch, 4); gf_bs_align(dsi); /*always signal implicit S BR in case it's used*/ sbr_sr_idx = read->sr_idx; for (i=0; i<16; i++) { if (GF_M4ASampleRates[i] == (u32) 2*read->sample_rate) { sbr_sr_idx = i; break; } } gf_bs_write_int(dsi, 0x2b7, 11); gf_bs_write_int(dsi, 5, 5); gf_bs_write_int(dsi, 1, 1); gf_bs_write_int(dsi, sbr_sr_idx, 4); gf_bs_align(dsi); gf_bs_get_content(dsi, &esd->decoderConfig->decoderSpecificInfo->data, &esd->decoderConfig->decoderSpecificInfo->dataLength); gf_bs_del(dsi); return esd; }
static GF_Err HEVC_ConfigurationScalableStream(HEVCDec *ctx, GF_ESD *esd) { GF_HEVCConfig *cfg = NULL; char *data; u32 data_len; GF_BitStream *bs; u32 i, j; if (!esd->decoderConfig->decoderSpecificInfo || !esd->decoderConfig->decoderSpecificInfo->data) return GF_OK; cfg = gf_odf_hevc_cfg_read(esd->decoderConfig->decoderSpecificInfo->data, esd->decoderConfig->decoderSpecificInfo->dataLength, GF_FALSE); if (!cfg) return GF_NON_COMPLIANT_BITSTREAM; if (ctx->nalu_size_length != cfg->nal_unit_size) return GF_NON_COMPLIANT_BITSTREAM; bs = gf_bs_new(NULL, 0, GF_BITSTREAM_WRITE); for (i=0; i< gf_list_count(cfg->param_array); i++) { GF_HEVCParamArray *ar = (GF_HEVCParamArray *)gf_list_get(cfg->param_array, i); for (j=0; j< gf_list_count(ar->nalus); j++) { GF_AVCConfigSlot *sl = (GF_AVCConfigSlot *)gf_list_get(ar->nalus, j); gf_bs_write_int(bs, sl->size, 8*ctx->nalu_size_length); gf_bs_write_data(bs, sl->data, sl->size); } } gf_bs_get_content(bs, &data, &data_len); gf_bs_del(bs); libOpenHevcDecode(ctx->openHevcHandle, (u8 *)data, data_len, 0); if (ctx->raw_out) fwrite((u8 *)data, 1, data_len, ctx->raw_out); gf_free(data); libOpenHevcSetActiveDecoders(ctx->openHevcHandle, 2); libOpenHevcSetViewLayers(ctx->openHevcHandle, 1); return GF_OK; }
GF_Err gf_isom_ismacryp_sample_to_sample(GF_ISMASample *s, GF_ISOSample *dest) { GF_BitStream *bs; if (!s || !dest) return GF_BAD_PARAM; bs = gf_bs_new(NULL, 0, GF_BITSTREAM_WRITE); if (s->flags & GF_ISOM_ISMA_USE_SEL_ENC) { gf_bs_write_int(bs, (s->flags & GF_ISOM_ISMA_IS_ENCRYPTED) ? 1 : 0, 1); gf_bs_write_int(bs, 0, 7); } if (s->flags & GF_ISOM_ISMA_IS_ENCRYPTED) { if (s->IV_length) gf_bs_write_long_int(bs, s->IV, 8*s->IV_length); if (s->KI_length) gf_bs_write_data(bs, (char*)s->key_indicator, s->KI_length); } gf_bs_write_data(bs, s->data, s->dataLength); if (dest->data) free(dest->data); dest->data = NULL; dest->dataLength = 0; gf_bs_get_content(bs, &dest->data, &dest->dataLength); gf_bs_del(bs); return GF_OK; }
GF_EXPORT GF_Err gf_odf_desc_list_write(GF_List *descList, char **outEncList, u32 *outSize) { GF_BitStream *bs; GF_Err e; if (!descList || !outEncList || *outEncList || !outSize) return GF_BAD_PARAM; *outSize = 0; bs = gf_bs_new(NULL, 0, GF_BITSTREAM_WRITE); if (!bs) return GF_OUT_OF_MEM; e = gf_odf_write_descriptor_list(bs, descList); if (e) { gf_bs_del(bs); return e; } gf_bs_get_content(bs, outEncList, outSize); gf_bs_del(bs); return GF_OK; }
static void DEV_Start(struct __input_device *ifce) { GF_BitStream *bs; char *buf, *szWord; u32 len, val, i, buf_size; szWord = "Hello InputSensor!"; bs = gf_bs_new(NULL, 0, GF_BITSTREAM_WRITE); /*HTK sensor buffer format: SFString - SFInt32 - SFFloat*/ gf_bs_write_int(bs, 1, 1); len = strlen(szWord); val = gf_get_bit_size(len); gf_bs_write_int(bs, val, 5); gf_bs_write_int(bs, len, val); for (i=0; i<len; i++) gf_bs_write_int(bs, szWord[i], 8); gf_bs_align(bs); gf_bs_get_content(bs, &buf, &buf_size); gf_bs_del(bs); ifce->DispatchFrame(ifce, buf, buf_size); gf_free(buf); }