Пример #1
0
static int writeGenericSample(FILE_STREAM_T *pStreamIn, uint32_t sampleSize, 
                              void *pCbData, int chunk_idx, uint32_t sampleDurationHz) {

  CBDATA_WRITE_GENERIC_SAMPLE_T *pCbDataGeneric = NULL;
  unsigned int idxByteInSample = 0;
  unsigned int lenRead;
  int idxArena = 0;
  int rc = 0;

  if((pCbDataGeneric = (CBDATA_WRITE_GENERIC_SAMPLE_T *) pCbData) == NULL) {
    return -1;
  }

  while(idxByteInSample < sampleSize) {

    if((lenRead = sampleSize - idxByteInSample) > sizeof(pCbDataGeneric->arena) - idxArena) {
      lenRead = sizeof(pCbDataGeneric->arena) - idxArena;
    }

    if(ReadFileStream(pStreamIn, &pCbDataGeneric->arena[idxArena], lenRead) < 0) {
      return -1;
    }

    if((rc = WriteFileStream(pCbDataGeneric->pStreamOut, 
                             pCbDataGeneric->arena, lenRead + idxArena)) < 0) {
      return -1;
    }
    
    idxArena = 0;
    idxByteInSample += lenRead;
   
  }

  return rc;
}
Пример #2
0
int flvsrv_cbWriteDataFile(void *pArg, const unsigned char *pData, unsigned int len) {
  int rc = 0;
  FLVSRV_CTXT_T *pFlvCtxt = (FLVSRV_CTXT_T *) pArg;

  //fprintf(stderr, "CB FLV RECORD len:%d\n", len);

  if(pFlvCtxt->recordFile.fp == FILEOPS_INVALID_FP) {

    if(capture_openOutputFile(&pFlvCtxt->recordFile, pFlvCtxt->overwriteFile, NULL) < 0) {

      // Do not call outfmt_removeCb since we're invoked from the cb thread
      //outfmt_removeCb(pFlvCtxt->pRecordOutFmt);
      pFlvCtxt->pRecordOutFmt->do_outfmt = 0;
      pFlvCtxt->pRecordOutFmt = NULL;

      return -1;
    }
    LOG(X_INFO("Created flv recording output file %s"), pFlvCtxt->recordFile.filename);
   
  }

  if((rc = WriteFileStream(&pFlvCtxt->recordFile, pData, len)) < 0) {
    LOG(X_ERROR("Failed to write flv %s %u bytes, total: %llu)"),
               (pFlvCtxt->writeErrDescr ? pFlvCtxt->writeErrDescr : ""), len, pFlvCtxt->totXmit);
  } else {
    pFlvCtxt->totXmit += len;
  }

  return rc;
}
Пример #3
0
int mp4_cbReadDataNet(void *pArg, void *pData, unsigned int len) {
  int rc = 0;
  unsigned int cachedRdSz = 0;
  MP4_FILE_STREAM_T *pMp4Fs = (MP4_FILE_STREAM_T *) pArg;
  MP4_NET_STREAM_T *pNs = (MP4_NET_STREAM_T *) pMp4Fs->pCbData;
  CAP_HTTP_MP4_T *pCapHttpMp4 = pNs->pCapHttpMp4;

  //fprintf(stderr, "mp4_cbReadDataNet len:%d, mdat:%d, %llu/%llu\n", len, pCapHttpMp4->rcvState.readingMdat, pCapHttpMp4->rcvState.mdatIdx, pCapHttpMp4->rcvState.mdatSize);

  if(pCapHttpMp4->common.pCfg->running != 0 || g_proc_exit) {
    return -1;
  }

  //
  // Check pre-buffered content since reading of the HTTP headers may have eaten some of the actual content
  //
  if(pCapHttpMp4->common.pdata && pCapHttpMp4->common.datasz > pCapHttpMp4->common.dataoffset) {
    cachedRdSz = MIN(len, pCapHttpMp4->common.datasz - pCapHttpMp4->common.dataoffset);
    memcpy(pData, &pCapHttpMp4->common.pdata[pCapHttpMp4->common.dataoffset], cachedRdSz);
    //fprintf(stderr, "mp4_cbReadDataNet CACHED RD sz:%d, %d/%d\n", cachedRdSz, pCapHttpMp4->common.dataoffset, pCapHttpMp4->common.datasz);
    pCapHttpMp4->common.dataoffset += cachedRdSz;
  }

  if(len > cachedRdSz &&
     (rc = netio_recvnb_exact(pNs->pNetSock, &((unsigned char *)pData)[cachedRdSz], 
                              len - cachedRdSz, pNs->rcvTmtMs)) != (len - cachedRdSz)) {
    if(rc == 0) {
      return rc;
    }
    return -1;
  }

  pMp4Fs->offset += len;

//if(pMp4Fs->offset < 300000)
  //
  // Write the frame content to the (temporary) mp4 cached file
  //
  if((rc = WriteFileStream(&pCapHttpMp4->rcvState.fStream, pData, len)) < 0) {
    return rc;
  }

  //usleep(8000);

  //if(pCapHttpMp4->rcvState.readingMdat) {
  //    pCapHttpMp4->rcvState.mdatIdx += len;
  //}

  //fprintf(stderr, "mp4_cbReadDataNet done reading len:%d, offset at: %llu, fd:%d\n", len, pMp4Fs->offset, pNs->pNeetsock->sock); //avc_dumpHex(stderr, pData, MIN(16, len), 1);

  return rc;
}
Пример #4
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;
}