Esempio n. 1
0
int esds_cbWriteSample(FILE_STREAM_T *pStreamIn, uint32_t sampleSize, 
                       void *pCbData, int chunkIdx, uint32_t sampleDurationHz) {

  ESDS_CBDATA_WRITE_SAMPLE_T *pCbDataEsds = NULL;
  unsigned int idxByteInSample = 0;
  unsigned int lenRead;
  int idx= 0;
  int rc = 0;

  //fprintf(stderr, "esds_cbWriteSample chunkIdx:%d sampleSize:%d sampleDurationHz:%d\n", chunkIdx, sampleSize, sampleDurationHz);

  if((pCbDataEsds = (ESDS_CBDATA_WRITE_SAMPLE_T *) pCbData) == NULL) {
    return -1;
  }

  if((idx= aac_encodeADTSHdr(pCbDataEsds->bs.buf, pCbDataEsds->bs.sz,
                 &pCbDataEsds->decoderCfg, sampleSize)) < 0) {
    LOG(X_ERROR("Failed to create ADTS header for frame"));
    return -1;
  }

  while(idxByteInSample < sampleSize) {

    if((lenRead = sampleSize - idxByteInSample) > pCbDataEsds->bs.sz - idx) {
      lenRead = pCbDataEsds->bs.sz - idx;
    }

    if(ReadFileStream(pStreamIn, &pCbDataEsds->bs.buf[idx], lenRead) < 0) {
      return -1;
    }

    if((rc = WriteFileStream(pCbDataEsds->pStreamOut, pCbDataEsds->bs.buf, 
                             lenRead + idx)) < 0) {
      return -1;
    }

    idx= 0;
    idxByteInSample += lenRead;

  }

  return rc;
}
Esempio n. 2
0
static int flvsrv_init_aud_aac(CODEC_AUD_CTXT_T *pCtxtA, const uint8_t *pAdtsHdr) {
  CODEC_AUD_CTXT_AAC_T *pCtxtAac = &pCtxtA->codecCtxt.aac;
  int rc;

  memset(pCtxtAac, 0, sizeof(CODEC_AUD_CTXT_AAC_T));


  if(pCtxtA->pStreamerCfg && !pCtxtA->pStreamerCfg->xcode.aud.common.cfgDo_xcode &&
     XCODE_AUD_UDATA_PTR(&pCtxtA->pStreamerCfg->xcode)->u.aac.descr.sp.init) {

    LOG(X_DEBUG("Loading aac sequence start from source media"));

    memcpy(&pCtxtAac->adtsFrame.sp, &XCODE_AUD_UDATA_PTR(&pCtxtA->pStreamerCfg->xcode)->u.aac.descr.sp,
           sizeof(pCtxtAac->adtsFrame.sp));

    aac_encodeADTSHdr(pCtxtAac->adtsHdr, sizeof(pCtxtAac->adtsHdr), &pCtxtAac->adtsFrame.sp, 0);

  } else {

    LOG(X_DEBUG("Loading aac sequence start from stream ADTS header"));

    if(aac_decodeAdtsHdr(pAdtsHdr, 7, &pCtxtAac->adtsFrame) < 0) {
      return -1;
    }
    memcpy(pCtxtAac->adtsHdr, pAdtsHdr, 7);

  }

  if((rc = esds_encodeDecoderSp((uint8_t *) pCtxtAac->spbuf, sizeof(pCtxtAac->spbuf),
    &pCtxtAac->adtsFrame.sp)) <= 0) {
    return -1;
  }

  pCtxtA->ctxt.clockHz = esds_getFrequencyVal(ESDS_FREQ_IDX(pCtxtAac->adtsFrame.sp));
  pCtxtA->ctxt.channels = pCtxtAac->adtsFrame.sp.channelIdx;
  pCtxtA->ctxt.pstartHdrs = pCtxtAac->spbuf;
  pCtxtA->ctxt.startHdrsLen = rc;

  //fprintf(stderr, "init_aud_aac haveExtFreqIdx:%d, %dHz\n", pCtxtAac->adtsFrame.sp.haveExtFreqIdx, esds_getFrequencyVal(ESDS_FREQ_IDX(pCtxtAac->adtsFrame.sp))); avc_dumpHex(stderr, pCtxtA->ctxt.pstartHdrs, pCtxtA->ctxt.startHdrsLen, 1);

  return 0;
}