static rtp_check_return_t check (lib_message_func_t msg, format_list_t *fmt, uint8_t rtp_payload_type, CConfigSet *pConfig) { if (fmt == NULL || fmt->rtpmap == NULL ) { return RTP_PLUGIN_NO_MATCH; } if ( (strcasecmp(fmt->rtpmap->encode_name, "enc-mpeg4-generic") != 0) ) { return RTP_PLUGIN_NO_MATCH; } if (strcasecmp(fmt->media->media, "audio") != 0 ) { return RTP_PLUGIN_NO_MATCH; } fmtp_parse_t *fmtp; int len; fmtp = parse_fmtp_for_mpeg4(fmt->fmt_param, msg); if (fmtp == NULL) { return RTP_PLUGIN_NO_MATCH; } len = fmtp->size_length; free_fmtp_parse(fmtp); if (len == 0) { return RTP_PLUGIN_NO_MATCH; } return RTP_PLUGIN_MATCH; }
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; }
static void isma_rtp_destroy (rtp_plugin_data_t *pifptr) { isma_enc_rtp_data_t *iptr = (isma_enc_rtp_data_t *)pifptr; #ifdef ISMA_RTP_DUMP_OUTPUT_TO_FILE fclose(iptr->m_outfile); #endif isma_frame_data_t *p; if (iptr->m_frag_reass_buffer != NULL) { CHECK_AND_FREE(iptr->m_frag_reass_buffer); iptr->m_frag_reass_buffer = NULL; } if (iptr->m_frame_data_on != NULL) { iptr->m_frame_data_on->frame_data_next = iptr->m_frame_data_head; iptr->m_frame_data_head = iptr->m_frame_data_on; iptr->m_frame_data_on = NULL; } while (iptr->m_frame_data_free != NULL) { p = iptr->m_frame_data_free; iptr->m_frame_data_free = p->frame_data_next; CHECK_AND_FREE(p); } while (iptr->m_frame_data_head != NULL) { p = iptr->m_frame_data_head; // if fragmented frame, free all frag_data if (p->is_fragment == 1) { isma_frag_data_t * q = p->frag_data; while (q != NULL) { p->frag_data = q->frag_data_next; CHECK_AND_FREE(q); q = p->frag_data; } } iptr->m_frame_data_head = p->frame_data_next; CHECK_AND_FREE(p); } if (iptr->m_fmtp != NULL) { free_fmtp_parse(iptr->m_fmtp); } CHECK_AND_FREE(iptr); }
static codec_data_t *ffmpeg_create (const char *stream_type, const char *compressor, int type, int profile, format_list_t *media_fmt, video_info_t *vinfo, const uint8_t *userdata, uint32_t ud_size, video_vft_t *vft, void *ifptr) { ffmpeg_codec_t *ffmpeg; ffmpeg = MALLOC_STRUCTURE(ffmpeg_codec_t); memset(ffmpeg, 0, sizeof(*ffmpeg)); ffmpeg->m_vft = vft; ffmpeg->m_ifptr = ifptr; avcodec_init(); avcodec_register_all(); av_log_set_level(AV_LOG_QUIET); ffmpeg->m_codecId = ffmpeg_find_codec(stream_type, compressor, type, profile, media_fmt, userdata, ud_size); // must have a codecID - we checked it earlier ffmpeg->m_codec = avcodec_find_decoder(ffmpeg->m_codecId); ffmpeg->m_c = avcodec_alloc_context(); ffmpeg->m_picture = avcodec_alloc_frame(); bool open_codec = true; bool run_userdata = false; bool free_userdata = false; switch (ffmpeg->m_codecId) { case CODEC_ID_MJPEG: break; case CODEC_ID_H264: // need to find height and width if (media_fmt != NULL && media_fmt->fmt_param != NULL) { userdata = h264_sdp_parse_sprop_param_sets(media_fmt->fmt_param, &ud_size, ffmpeg->m_vft->log_msg); if (userdata != NULL) free_userdata = true; ffmpeg_message(LOG_DEBUG, "ffmpeg", "sprop len %d", ud_size); } if (ud_size > 0) { ffmpeg_message(LOG_DEBUG, "ffmpeg", "userdata len %d", ud_size); open_codec = ffmpeg_find_h264_size(ffmpeg, userdata, ud_size); ffmpeg_message(LOG_DEBUG, "ffmpeg", "open codec is %d", open_codec); run_userdata = true; } else { open_codec = false; } break; case CODEC_ID_MPEG4: { fmtp_parse_t *fmtp = NULL; open_codec = false; if (media_fmt != NULL) { fmtp = parse_fmtp_for_mpeg4(media_fmt->fmt_param, ffmpeg->m_vft->log_msg); if (fmtp->config_binary != NULL) { userdata = fmtp->config_binary; ud_size = fmtp->config_binary_len; fmtp->config_binary = NULL; free_userdata = true; } } if (ud_size > 0) { uint8_t *vol = MP4AV_Mpeg4FindVol((uint8_t *)userdata, ud_size); u_int8_t TimeBits; u_int16_t TimeTicks; u_int16_t FrameDuration; u_int16_t FrameWidth; u_int16_t FrameHeight; u_int8_t aspectRatioDefine; u_int8_t aspectRatioWidth; u_int8_t aspectRatioHeight; if (vol) { if (MP4AV_Mpeg4ParseVol(vol, ud_size - (vol - userdata), &TimeBits, &TimeTicks, &FrameDuration, &FrameWidth, &FrameHeight, &aspectRatioDefine, &aspectRatioWidth, &aspectRatioHeight)) { ffmpeg->m_c->width = FrameWidth; ffmpeg->m_c->height = FrameHeight; open_codec = true; run_userdata = true; } } } if (fmtp != NULL) { free_fmtp_parse(fmtp); } } break; case CODEC_ID_SVQ3: ffmpeg->m_c->extradata = (void *)userdata; ffmpeg->m_c->extradata_size = ud_size; if (vinfo != NULL) { ffmpeg->m_c->width = vinfo->width; ffmpeg->m_c->height = vinfo->height; } break; default: break; } if (open_codec) { if (avcodec_open(ffmpeg->m_c, ffmpeg->m_codec) < 0) { ffmpeg_message(LOG_CRIT, "ffmpeg", "failed to open codec"); return NULL; } ffmpeg_message(LOG_DEBUG, "ffmpeg", "pixel format is %d", ffmpeg->m_c->pix_fmt); ffmpeg->m_codec_opened = true; if (run_userdata) { uint32_t offset = 0; do { int got_picture; offset += avcodec_decode_video(ffmpeg->m_c, ffmpeg->m_picture, &got_picture, (uint8_t *)userdata + offset, ud_size - offset); } while (offset < ud_size); } } if (free_userdata) { CHECK_AND_FREE(userdata); } ffmpeg->m_did_pause = 1; return ((codec_data_t *)ffmpeg); }
/* * Create CAACodec class */ static codec_data_t *aac_codec_create (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_audio_inited = 0; // 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; } } aac->m_info = faacDecOpen(); unsigned long srate; unsigned char chan; if ((userdata == NULL && fmtp == NULL) || (faacDecInit2(aac->m_info, (uint8_t *)userdata, userdata_size, &srate, &chan) < 0)) { if (fmtp != NULL) free_fmtp_parse(fmtp); return NULL; } mp4AudioSpecificConfig mp4ASC; aac->m_output_frame_size = 1024; if (AudioSpecificConfig((unsigned char *)userdata, userdata_size, &mp4ASC)) { if (mp4ASC.frameLengthFlag) { aac->m_output_frame_size = 960; } } aac->m_freq = srate; aac->m_chans = chan; aac->m_faad_inited = 1; aac->m_msec_per_frame = aac->m_output_frame_size; aac->m_msec_per_frame *= M_LLU; 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; }
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; }
/* * 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; }
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; }
static int xvid_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, CConfigSet *pConfig) { int retval; retval = 3; if (compressor != NULL && (strcasecmp(compressor, "MP4 FILE") == 0)) { if ((type == MP4_MPEG4_VIDEO_TYPE) && ((profile >= MPEG4_SP_L1 && profile <= MPEG4_SP_L3) || (profile == MPEG4_SP_L0))) { return retval; } return -1; } if (fptr != NULL) { // find format. If matches, call parse_fmtp_for_mpeg4, look at // profile level. if (fptr->rtpmap != NULL && fptr->rtpmap->encode_name != NULL) { if (strcasecmp(fptr->rtpmap->encode_name, "MP4V-ES") == 0) { fmtp_parse_t *fmtp; media_desc_t *mptr = fptr->media; if (find_unparsed_a_value(mptr->unparsed_a_lines, "a=x-mpeg4-simple-profile-decoder") != NULL) { // our own special code for simple profile decoder return retval; } fmtp = parse_fmtp_for_mpeg4(fptr->fmt_param, message); int retvl = -1; if (fmtp != NULL) { int profile = fmtp->profile_level_id; if ((profile >= MPEG4_SP_L1 && profile <= MPEG4_SP_L3) || (profile == MPEG4_SP_L0)) { retvl = retval; } else if (fmtp->config_binary != NULL) { // see if they indicate simple tools in VOL #if 0 uint8_t *volptr; volptr = MP4AV_Mpeg4FindVol(fmtp->config_binary, fmtp->config_binary_len); if (volptr != NULL && ((volptr[4] & 0x7f) == 0) && ((volptr[5] & 0x80) == 0x80)) { message(LOG_ERR, "xvid", "indicated simple tools in xvid"); retvl = retval; } #endif } free_fmtp_parse(fmtp); } return retvl; } } return -1; } if (compressor != NULL) { const char **lptr = xvid_compressors; while (*lptr != NULL) { if (strcasecmp(*lptr, compressor) == 0) { return retval; } lptr++; } } return -1; }
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; }