/** * \brief init feeder * \param audec pointer to audec * \return 0 on success otherwise -1 if an error occurred */ int feeder_init(aml_audio_dec_t *audec) { int ret; dsp_operations_t *dsp_ops; dsp_ops = &audec->adsp_ops; audec->format = get_audio_format(); if (audec->format == ADEC_AUDIO_FORMAT_UNKNOWN) { adec_print("Unknown audio format!"); return -1; } ret = audiodsp_init(dsp_ops); if (ret) { adec_print("audio dsp init failed!"); return -1; } ret = audiodsp_start(audec); if (ret == 0) { dsp_ops->dsp_on = 1; dsp_ops->dsp_read = audiodsp_stream_read; dsp_ops->get_cur_pts = audiodsp_get_pts; dsp_ops->get_cur_pcrscr = audiodsp_get_pcrscr; dsp_ops->set_cur_apts = audiodsp_set_apts; } else { audiodsp_release(dsp_ops); dsp_ops->dsp_on = 0; dsp_ops->dsp_read = NULL; dsp_ops->get_cur_pts = NULL; dsp_ops->get_cur_pcrscr = NULL; /* TODO: amport init */ } return ret; }
int mgcp_transcoding_setup(struct mgcp_endpoint *endp, struct mgcp_rtp_end *dst_end, struct mgcp_rtp_end *src_end) { struct mgcp_process_rtp_state *state; enum audio_format src_fmt, dst_fmt; const struct mgcp_rtp_codec *src_codec = &src_end->codec; const struct mgcp_rtp_codec *dst_codec = &dst_end->codec; /* cleanup first */ if (dst_end->rtp_process_data) { talloc_free(dst_end->rtp_process_data); dst_end->rtp_process_data = NULL; } if (!src_end) return 0; src_fmt = get_audio_format(src_codec); dst_fmt = get_audio_format(dst_codec); LOGP(DMGCP, LOGL_ERROR, "Checking transcoding: %s (%d) -> %s (%d)\n", src_codec->subtype_name, src_codec->payload_type, dst_codec->subtype_name, dst_codec->payload_type); if (src_fmt == AF_INVALID || dst_fmt == AF_INVALID) { if (!src_codec->subtype_name || !dst_codec->subtype_name) /* Not enough info, do nothing */ return 0; if (strcmp(src_codec->subtype_name, dst_codec->subtype_name) == 0) /* Nothing to do */ return 0; LOGP(DMGCP, LOGL_ERROR, "Cannot transcode: %s codec not supported (%s -> %s).\n", src_fmt != AF_INVALID ? "destination" : "source", src_codec->audio_name, dst_codec->audio_name); return -EINVAL; } if (src_codec->rate && dst_codec->rate && src_codec->rate != dst_codec->rate) { LOGP(DMGCP, LOGL_ERROR, "Cannot transcode: rate conversion (%d -> %d) not supported.\n", src_codec->rate, dst_codec->rate); return -EINVAL; } state = talloc_zero(endp->tcfg->cfg, struct mgcp_process_rtp_state); talloc_set_destructor(state, processing_state_destructor); dst_end->rtp_process_data = state; state->src_fmt = src_fmt; switch (state->src_fmt) { case AF_L16: case AF_S16: state->src_frame_size = 80 * sizeof(short); state->src_samples_per_frame = 80; break; case AF_GSM: state->src_frame_size = sizeof(gsm_frame); state->src_samples_per_frame = 160; state->src.gsm_handle = gsm_create(); if (!state->src.gsm_handle) { LOGP(DMGCP, LOGL_ERROR, "Failed to initialize GSM decoder.\n"); return -EINVAL; } break; #ifdef HAVE_BCG729 case AF_G729: state->src_frame_size = 10; state->src_samples_per_frame = 80; state->src.g729_dec = initBcg729DecoderChannel(); if (!state->src.g729_dec) { LOGP(DMGCP, LOGL_ERROR, "Failed to initialize G.729 decoder.\n"); return -EINVAL; } break; #endif case AF_PCMA: state->src_frame_size = 80; state->src_samples_per_frame = 80; break; default: break; } state->dst_fmt = dst_fmt; switch (state->dst_fmt) { case AF_L16: case AF_S16: state->dst_frame_size = 80*sizeof(short); state->dst_samples_per_frame = 80; break; case AF_GSM: state->dst_frame_size = sizeof(gsm_frame); state->dst_samples_per_frame = 160; state->dst.gsm_handle = gsm_create(); if (!state->dst.gsm_handle) { LOGP(DMGCP, LOGL_ERROR, "Failed to initialize GSM encoder.\n"); return -EINVAL; } break; #ifdef HAVE_BCG729 case AF_G729: state->dst_frame_size = 10; state->dst_samples_per_frame = 80; state->dst.g729_enc = initBcg729EncoderChannel(); if (!state->dst.g729_enc) { LOGP(DMGCP, LOGL_ERROR, "Failed to initialize G.729 decoder.\n"); return -EINVAL; } break; #endif case AF_PCMA: state->dst_frame_size = 80; state->dst_samples_per_frame = 80; break; default: break; } if (dst_end->force_output_ptime) state->dst_packet_duration = mgcp_rtp_packet_duration(endp, dst_end); LOGP(DMGCP, LOGL_INFO, "Initialized RTP processing on: 0x%x " "conv: %d (%d, %d, %s) -> %d (%d, %d, %s)\n", ENDPOINT_NUMBER(endp), src_fmt, src_codec->payload_type, src_codec->rate, src_end->fmtp_extra, dst_fmt, dst_codec->payload_type, dst_codec->rate, dst_end->fmtp_extra); return 0; }
status_t OggTobiasSeekable::GetStreamInfo(int64 *frameCount, bigtime_t *duration, media_format *format) { TRACE("OggTobiasSeekable::GetStreamInfo\n"); status_t result = B_OK; ogg_packet packet; // get header packet if (GetHeaderPackets().size() < 1) { result = GetPacket(&packet); if (result != B_OK) { return result; } SaveHeaderPacket(packet); } packet = GetHeaderPackets()[0]; if (!packet.b_o_s) { return B_ERROR; // first packet was not beginning of stream } // parse header packet if (packet.bytes < 1+(signed)sizeof(tobias_stream_header)) { return B_ERROR; } void * data = &(packet.packet[1]); tobias_stream_header * header = (tobias_stream_header *)data; if (strcmp(header->streamtype, "video") == 0) { result = get_video_format(header, format); if (result != B_OK) { return result; } } else if (strcmp(header->streamtype, "audio") == 0) { result = get_audio_format(header, format); if (result != B_OK) { return result; } } else if (strcmp(header->streamtype, "text") == 0) { result = get_text_format(header, format); if (result != B_OK) { return result; } } else { *frameCount = 0; // unknown streamtype return B_BAD_VALUE; } // get comment packet if (GetHeaderPackets().size() < 2) { result = GetPacket(&packet); if (result != B_OK) { return result; } SaveHeaderPacket(packet); } format->SetMetaData((void*)&GetHeaderPackets(),sizeof(GetHeaderPackets())); fMediaFormat = *format; fMicrosecPerFrame = header->time_unit / 10.0; fFrameRate = header->samples_per_unit * 1000000.0 / fMicrosecPerFrame; // TODO: count the frames in the first page.. somehow.. :-/ int64 frames = 0; ogg_page page; // read the first page result = ReadPage(&page); if (result != B_OK) { return result; } int64 fFirstGranulepos = ogg_page_granulepos(&page); TRACE("OggVorbisSeekable::GetStreamInfo: first granulepos: %lld\n", fFirstGranulepos); // read our last page off_t last = inherited::Seek(GetLastPagePosition(), SEEK_SET); if (last < 0) { return last; } result = ReadPage(&page); if (result != B_OK) { return result; } int64 last_granulepos = ogg_page_granulepos(&page); // seek back to the start int64 frame = 0; bigtime_t time = 0; result = Seek(B_MEDIA_SEEK_TO_TIME, &frame, &time); if (result != B_OK) { return result; } // compute frame count and duration from sample count frames = last_granulepos - fFirstGranulepos; *frameCount = frames; *duration = (long long)((1000000LL * frames) / (double)fFrameRate); return B_OK; }