return -ENOMEM;
}
- c = avcodec_find_encoder(priv->codec_in->codec_id);
+ c = avcodec_find_encoder(out->audio_codec);
if (!c)
return -EINVAL;
return -ENOMEM;
priv->codec_out->codec_id = c->id;
- priv->codec_out->bit_rate = 64 * 1024;
+// priv->codec_out->bit_rate = 64 * 1024;
priv->codec_out->sample_rate = 44100;
- priv->codec_out->sample_fmt = priv->codec_in->sample_fmt;
+ priv->codec_out->sample_fmt = c->sample_fmts[0];
priv->codec_out->channels = 2;
priv->codec_out->channel_layout = av_get_default_channel_layout(priv->codec_out->channels);
priv->codec_out->time_base = (AVRational){1, priv->codec_out->sample_rate};
goto error;
}
- io->priv = priv;
+ io->aopen = 1;
+ io->priv = priv;
return 0;
error:
{
simp_avio_t* io = arg;
simp_audio_t* priv = io->priv;
-
scf_list_t ih;
+ int ret;
+
scf_list_init(&ih);
- while (!io->exit) {
+ if (priv->ctx_out) {
+ av_dump_format(priv->ctx_out, 0, priv->ctx_out->url, 1);
+
+ if (!(priv->ctx_out->oformat->flags & AVFMT_NOFILE)) {
- int ret = __output_audio(io, priv->codec_out, priv->opkt, priv->oframe);
+ ret = avio_open(&priv->ctx_out->pb, priv->ctx_out->url, AVIO_FLAG_WRITE);
+ if (ret < 0) {
+ scf_loge("Could not open output file '%s'", priv->ctx_out->url);
+ io->error = ret;
+ goto end;
+ }
+ }
+
+ ret = avformat_write_header(priv->ctx_out, NULL);
if (ret < 0) {
+ scf_loge("avformat_write_header error, ret: %s\n", av_err2str(ret));
io->error = ret;
goto end;
}
+ }
- ret = __input_audio(io, priv->codec_in, priv->ipkt, priv->iframe, &ih);
+ while (!io->exit) {
- av_packet_unref(priv->ipkt);
+ if (priv->ctx_out) {
+ ret = __output_audio(io, priv->codec_out, priv->opkt, priv->oframe);
+ if (ret < 0) {
+ io->error = ret;
+ goto end;
+ }
+ }
- if (ret < 0) {
- io->error = ret;
- goto end;
+ if (priv->ctx_in) {
+ ret = __input_audio(io, priv->codec_in, priv->ipkt, priv->iframe, &ih);
+
+ av_packet_unref(priv->ipkt);
+ if (ret < 0) {
+ io->error = ret;
+ goto end;
+ }
}
// AEC: audio echo cancel