Exemple #1
0
static int celp_codec_check (lib_message_func_t message,
			     const char *stream_type,
			     const char *compressor,
			     int type,
			     int profile,
			     format_list_t *fptr, 
			     const uint8_t *userdata,
			     uint32_t userdata_size,
			     CConfigSet *pConfig)
{
  fmtp_parse_t *fmtp = NULL;
  if (strcasecmp(stream_type, STREAM_TYPE_MP4_FILE) == 0 &&
      type != -1) {
    switch (type) {
    case MP4_MPEG4_AUDIO_TYPE:
      break;
    default:
      return -1;
    }
  }
  if (strcasecmp(stream_type, STREAM_TYPE_RTP) == 0 &&
      fptr != NULL && 
      fptr->rtpmap != NULL &&
      fptr->rtpmap->encode_name != NULL) {
    if (strcasecmp(fptr->rtpmap->encode_name, "mpeg4-generic") != 0) {
      return -1;
    }
    if (userdata == NULL) {
      fmtp = parse_fmtp_for_mpeg4(fptr->fmt_param, message);
      if (fmtp != NULL) {
	userdata = fmtp->config_binary;
	userdata_size = fmtp->config_binary_len;
      }
    }
  }
  if (userdata != NULL) {
    mpeg4_audio_config_t audio_config;
    decode_mpeg4_audio_config(userdata, userdata_size, &audio_config, false);
    if (fmtp != NULL) free_fmtp_parse(fmtp);
    if (audio_object_type_is_celp(&audio_config) == 0) {
      return -1;
    }
    return 1;
  }
  if (compressor != NULL) {
    const char **lptr = celp_compressors;
    while (*lptr != NULL) {
      if (strcasecmp(*lptr, compressor) == 0) {
	return 1;
      }
      lptr++;
    }
  }
  return -1;
}
/*
 * Isma rtp bytestream has a potential set of headers at the beginning
 * of each rtp frame.  This can interleave frames in different packets
 */
rtp_plugin_data_t *isma_rtp_plugin_create (format_list_t *media_fmt,
        uint8_t rtp_payload_type,
        rtp_vft_t *vft,
        void *ifptr)
{
    isma_enc_rtp_data_t *iptr;
    fmtp_parse_t *fmtp;

    iptr = MALLOC_STRUCTURE(isma_enc_rtp_data_t);
    if ( iptr == NULL )
        return NULL;

    memset(iptr, 0, sizeof(isma_enc_rtp_data_t));

    if (strcasecmp(media_fmt->media->media, "audio") == 0) {
        ismacrypInitSession(&(iptr->myEncSID), KeyTypeAudio);
    }

    iptr->m_vft = vft;
    iptr->m_ifptr = ifptr;

    iptr->m_rtp_packet_mutex = SDL_CreateMutex();
#ifdef ISMA_RTP_DUMP_OUTPUT_TO_FILE
    iptr->m_outfile = fopen("isma.aac", "w");
#endif
    iptr->m_frame_data_head = NULL;
    iptr->m_frame_data_on = NULL;
    iptr->m_frame_data_free = NULL;
    isma_frame_data_t *p;
    for (iptr->m_frame_data_max = 0; iptr->m_frame_data_max < 25; iptr->m_frame_data_max++) {
        p = (isma_frame_data_t *)malloc(sizeof(isma_frame_data_t));
        p->frame_data_next = iptr->m_frame_data_free;
        iptr->m_frame_data_free = p;
    }

    fmtp = parse_fmtp_for_mpeg4(media_fmt->fmt_param, iptr->m_vft->log_msg);

    mpeg4_audio_config_t audio_config;
    decode_mpeg4_audio_config(fmtp->config_binary,
                              fmtp->config_binary_len,
                              &audio_config);
    if (audio_object_type_is_aac(&audio_config)) {
        iptr->m_rtp_ts_add = audio_config.codec.aac.frame_len_1024 != 0 ? 1024 : 960;
    } else {
        iptr->m_rtp_ts_add = audio_config.codec.celp.samples_per_frame;
        isma_message(LOG_DEBUG, ismaencrtp, "celp spf is %d", iptr->m_rtp_ts_add);
    }
    iptr->m_rtp_ts_add = (iptr->m_rtp_ts_add * media_fmt->rtpmap->clock_rate) /
                         audio_config.frequency;
    isma_message(LOG_DEBUG, ismaencrtp,
                 "Rtp ts add is %d (%d %d)", iptr->m_rtp_ts_add,
                 media_fmt->rtpmap->clock_rate,
                 audio_config.frequency);
    iptr->m_fmtp = fmtp;
    iptr->m_min_first_header_bits = iptr->m_fmtp->size_length + iptr->m_fmtp->index_length;
    iptr->m_min_header_bits = iptr->m_fmtp->size_length + iptr->m_fmtp->index_delta_length;
    if (iptr->m_fmtp->CTS_delta_length > 0) {
        iptr->m_min_header_bits++;
        iptr->m_min_first_header_bits++;
    }
    if (iptr->m_fmtp->DTS_delta_length > 0) {
        iptr->m_min_header_bits++;
        iptr->m_min_first_header_bits++;
    }

    isma_message(LOG_DEBUG, ismaencrtp, "min headers are %d %d", iptr->m_min_first_header_bits,
                 iptr->m_min_header_bits);

    iptr->m_min_header_bits += iptr->m_fmtp->auxiliary_data_size_length;
    iptr->m_min_first_header_bits += iptr->m_fmtp->auxiliary_data_size_length;
    iptr->m_frag_reass_buffer = NULL;
    iptr->m_frag_reass_size_max = 0;
    return (&iptr->plug);
}
Exemple #3
0
static int aac_codec_check (lib_message_func_t message,
                const char *compressor,
                int type,
                int profile,
                format_list_t *fptr,
                const uint8_t *userdata,
                uint32_t userdata_size
#ifdef HAVE_PLUGIN_VERSION_0_8
              ,CConfigSet *pConfig
#endif
              )
{
  fmtp_parse_t *fmtp = NULL;
  if (compressor != NULL &&
      strcasecmp(compressor, "MP4 FILE") == 0 &&
      type != -1) {
    switch (type) {
    case MP4_MPEG2_AAC_MAIN_AUDIO_TYPE:
    case MP4_MPEG2_AAC_LC_AUDIO_TYPE:
    case MP4_MPEG2_AAC_SSR_AUDIO_TYPE:
    case MP4_MPEG4_AUDIO_TYPE:
      break;
    default:
      return -1;
    }
  }
  if (fptr != NULL &&
      fptr->rtpmap != NULL &&
      fptr->rtpmap->encode_name != NULL) {
    if (strcasecmp(fptr->rtpmap->encode_name, "mpeg4-generic") != 0) {
      return -1;
    }
    if (userdata == NULL) {
      fmtp = parse_fmtp_for_mpeg4(fptr->fmt_param, message);
      if (fmtp != NULL) {
    userdata = fmtp->config_binary;
    userdata_size = fmtp->config_binary_len;
      }
    }
  }
  if (userdata != NULL) {
    mpeg4_audio_config_t audio_config;
    decode_mpeg4_audio_config(userdata, userdata_size, &audio_config);
    message(LOG_DEBUG, "aac", "audio type is %d", audio_config.audio_object_type);
    if (fmtp != NULL) free_fmtp_parse(fmtp);

    if (audio_object_type_is_aac(&audio_config) == 0) {
      return -1;
    }
#if 0
    if (audio_config.audio_object_type == 17) {
      message(LOG_INFO, "aac", "audio type is legal ISMA, but not supported");
      return -1;
    }
#endif
    return 2;
  }
#if 0
  // I'm not sure I want to be here if we don't have an audio config
  if (compressor != NULL) {
    const char **lptr = aac_compressors;
    while (*lptr != NULL) {
      if (strcasecmp(*lptr, compressor) == 0) {
    return 2;
      }
      lptr++;
    }
  }
#endif
  return -1;
}
Exemple #4
0
/*
 * Create CAACodec class
 */
static codec_data_t *aac_codec_create (const char *stream_type,
				       const char *compressor, 
				       int type, 
				       int profile, 
				       format_list_t *media_fmt,
				       audio_info_t *audio,
				       const uint8_t *userdata,
				       uint32_t userdata_size,
				       audio_vft_t *vft,
				       void *ifptr)

{
  aac_codec_t *aac;

  aac = (aac_codec_t *)malloc(sizeof(aac_codec_t));
  memset(aac, 0, sizeof(aac_codec_t));

  aac->m_vft = vft;
  aac->m_ifptr = ifptr;
  fmtp_parse_t *fmtp = NULL;
  // Start setting up FAAC stuff...

  aac->m_resync_with_header = 1;
  aac->m_record_sync_time = 1;
  
  aac->m_faad_inited = 0;
  aac->m_audio_inited = 0;
  aac->m_temp_buff = (uint8_t *)malloc(4096);

  // Use media_fmt to indicate that we're streaming.
  if (media_fmt != NULL) {
    // haven't checked for null buffer
    // This is not necessarilly right - it is, for the most part, but
    // we should be reading the fmtp statement, and looking at the config.
    // (like we do below in the userdata section...
    aac->m_freq = media_fmt->rtpmap->clock_rate;
    fmtp = parse_fmtp_for_mpeg4(media_fmt->fmt_param, vft->log_msg);
    if (fmtp != NULL) {
      userdata = fmtp->config_binary;
      userdata_size = fmtp->config_binary_len;
    }
  } else {
    if (audio != NULL) {
      aac->m_freq = audio->freq;
    } else {
      aac->m_freq = 44100;
    }
  }
  aac->m_chans = 2; // this may be wrong - the isma spec, Appendix A.1.1 of
  // Appendix H says the default is 1 channel...
  aac->m_output_frame_size = 1024;
  aac->m_object_type = AACMAIN;
  if (userdata != NULL || fmtp != NULL) {
    mpeg4_audio_config_t audio_config;
    decode_mpeg4_audio_config(userdata, userdata_size, &audio_config);
    aac->m_object_type = audio_config.audio_object_type;
    aac->m_freq = audio_config.frequency;
    aac->m_chans = audio_config.channels;
    if (audio_config.codec.aac.frame_len_1024 == 0) {
      aac->m_output_frame_size = 960;
    }
  }

  aa_message(LOG_INFO, aaclib,"AAC object type is %d", aac->m_object_type);
  aac->m_info = faacDecOpen();
  faacDecConfiguration config;
  config.defObjectType = aac->m_object_type;
  config.defSampleRate = aac->m_freq;
  faacDecSetConfiguration(aac->m_info, &config);
  aac->m_msec_per_frame = aac->m_output_frame_size;
  aac->m_msec_per_frame *= TO_U64(1000);
  aac->m_msec_per_frame /= aac->m_freq;

  //  faad_init_bytestream(&m_info->ld, c_read_byte, c_bookmark, m_bytestream);

  aa_message(LOG_INFO, aaclib, "Setting freq to %d", aac->m_freq);
#if DUMP_OUTPUT_TO_FILE
  aac->m_outfile = fopen("temp.raw", "w");
#endif
  if (fmtp != NULL) {
    free_fmtp_parse(fmtp);
  }
  return (codec_data_t *)aac;
}
Exemple #5
0
static int aac_codec_check (lib_message_func_t message,
			    const char *stream_type,
			    const char *compressor,
			    int type,
			    int profile,
			    format_list_t *fptr, 
			    const uint8_t *userdata,
			    uint32_t userdata_size,
			    CConfigSet *pConfig)
{
  fmtp_parse_t *fmtp = NULL;
  if (compressor != NULL && 
      strcasecmp(stream_type, "MP4 FILE") == 0 &&
      type != -1) {
    switch (type) {
    case MP4_MPEG2_AAC_MAIN_AUDIO_TYPE:
    case MP4_MPEG2_AAC_LC_AUDIO_TYPE:
    case MP4_MPEG2_AAC_SSR_AUDIO_TYPE:
    case MP4_MPEG4_AUDIO_TYPE:
      break;
    default:
      return -1;
    }
  }
  if (strcasecmp(stream_type, STREAM_TYPE_RTP) == 0 &&
      fptr != NULL && 
      fptr->rtpmap != NULL &&
      fptr->rtpmap->encode_name != NULL) {
    if ((strcasecmp(fptr->rtpmap->encode_name, "mpeg4-generic") != 0) &&
        (strcasecmp(fptr->rtpmap->encode_name, "enc-mpeg4-generic") != 0)) {
      return -1;
    }
    if (userdata == NULL) {
      fmtp = parse_fmtp_for_mpeg4(fptr->fmt_param, message);
      if (fmtp != NULL) {
	userdata = fmtp->config_binary;
	userdata_size = fmtp->config_binary_len;
      }
    }
  }
  if (userdata != NULL) {
    mpeg4_audio_config_t audio_config;
    decode_mpeg4_audio_config(userdata, userdata_size, &audio_config);
    //    message(LOG_DEBUG, "aac", "audio type is %d", audio_config.audio_object_type);
    if (fmtp != NULL) free_fmtp_parse(fmtp);
    
    if (audio_object_type_is_aac(&audio_config) == 0) {
      return -1;
    }
    if (audio_config.audio_object_type == 17) {
      message(LOG_INFO, "aac", "audio type is legal ISMA, but not supported");
      return -1;
    }
    return 1;
  }
  if (compressor != NULL) {
    const char **lptr = aac_compressors;
    while (*lptr != NULL) {
      if (strcasecmp(*lptr, compressor) == 0) {
	return 1;
      }
      lptr++;
    }
  }
  return -1;
}
Exemple #6
0
static codec_data_t *celp_codec_create (const char *stream_type,
					const char *compressor, 
					int type, 
					int profile, 
					format_list_t *media_fmt,
					audio_info_t *audio,
					const uint8_t *userdata,
					uint32_t userdata_size,
					audio_vft_t *vft,
					void *ifptr)

{


  int i;
  celp_codec_t *celp;
  celp = (celp_codec_t *)malloc(sizeof(celp_codec_t));
  memset(celp, 0, sizeof(celp_codec_t));
  
#if 1 	 
  celp->m_vft = vft;
  celp->m_ifptr = ifptr;
  fmtp_parse_t *fmtp = NULL;

  BsInit(0, 0, 0);
  
  // Start setting up CELP stuff...
  
  celp->m_record_sync_time = 1;
  
  celp->m_celp_inited = 0;
  celp->m_audio_inited = 0;
  //celp->m_temp_buff = (float *)malloc(4096);

  
  // Use media_fmt to indicate that we're streaming.
  if (media_fmt != NULL) {
    // haven't checked for null buffer
    // This is not necessarilly right - it is, for the most part, but
    // we should be reading the fmtp statement, and looking at the config.
    // (like we do below in the userdata section...
    celp->m_freq = media_fmt->rtpmap->clock_rate;
    fmtp = parse_fmtp_for_mpeg4(media_fmt->fmt_param, vft->log_msg);
    if (fmtp != NULL) {
      userdata = fmtp->config_binary;
      userdata_size = fmtp->config_binary_len;
    }
  } else {
    if (audio != NULL) {
      celp->m_freq = audio->freq;
    } else {
      celp->m_freq = 44100;
    }
  }
  //celp->m_chans = 1; // this may be wrong - the isma spec, Appendix A.1.1 of
  // Appendix H says the default is 1 channel...
  //celp->m_output_frame_size = 2048;
  // celp->m_object_type = 8;CELP  AACMAIN;
  mpeg4_audio_config_t audio_config;
  if (userdata != NULL || fmtp != NULL) {
    
    celp_message(LOG_DEBUG, celplib, "config len %d %02x %02x %02x %02x", 
		 userdata_size, userdata[0], userdata[1], userdata[2], 
		 userdata[3]);
    decode_mpeg4_audio_config(userdata, userdata_size, &audio_config, false);
    celp->m_object_type = audio_config.audio_object_type;
    celp->m_freq = audio_config.frequency;
    celp->m_chans = audio_config.channels;
  }


	

  // write 
  BsBitBuffer *bitHeader;
  BsBitStream	*hdrStream;


  bitHeader=BsAllocBuffer(userdata_size * 8);

  //wmay removed
  bitHeader->numBit=userdata_size*8;
  bitHeader->size=userdata_size*8;

  memcpy(bitHeader->data,userdata,userdata_size);


  hdrStream = BsOpenBufferRead(bitHeader);

  BsGetSkip (hdrStream,userdata_size*8-audio_config.codec.celp.NumOfBitsInBuffer);
  BsBitBuffer *bBuffer=BsAllocBuffer(userdata_size*8);
  BsGetBuffer (hdrStream, bBuffer,audio_config.codec.celp.NumOfBitsInBuffer);
  int delayNumSample;


  DecLpcInit(celp->m_chans,celp->m_freq,0,NULL,
	     bBuffer ,&celp->m_output_frame_size,&delayNumSample);


  celp->m_samples_per_frame = celp->m_output_frame_size;
  celp->m_msec_per_frame *= TO_U64(1000);
  celp->m_msec_per_frame /= celp->m_freq;
  celp->m_last=userdata_size;
	
  BsFreeBuffer (bitHeader);

  BsFreeBuffer (bBuffer);

	
  celp->m_sampleBuf=(float**)malloc(celp->m_chans*sizeof(float*));
  for(i=0;i<celp->m_chans;i++)
    // wmay - added 2 times - return for frame size was samples, not bytes
    celp->m_sampleBuf[i]=(float*)malloc(2*celp->m_output_frame_size*sizeof(float));

  celp->m_bufs = 
    (uint16_t *)malloc(sizeof(uint16_t) * 2 * celp->m_chans * celp->m_output_frame_size);
  //celp->audiFile = AudioOpenWrite("out1.au",".au",
  //		  celp->m_chans,celp->m_freq);




  celp_message(LOG_INFO, celplib,"CELP object type is %d", celp->m_object_type);
  //celp_message(LOG_INFO, celplib,"CELP channel are %d", celp->m_chans );
  celp_message(LOG_INFO, celplib, "Setting freq to %d", celp->m_freq);
  celp_message(LOG_INFO, celplib, "output frame size is %d", celp->m_output_frame_size);
  
 


#if DUMP_OUTPUT_TO_FILE
  celp->m_outfile = fopen("temp.raw", "w");
#endif
  if (fmtp != NULL) {
    free_fmtp_parse(fmtp);
  }
#endif	 
  celp->m_vft->audio_configure(celp->m_ifptr,
			       celp->m_freq, 
			       celp->m_chans, 
			       AUDIO_FMT_S16,
			       celp->m_output_frame_size);

  return (codec_data_t *)celp;


}