| 51 | } |
| 52 | |
| 53 | static int init_encoder(const AVCodec *enc, AVCodecContext **enc_ctx, |
| 54 | const AVChannelLayout *ch_layout, int sample_rate) |
| 55 | { |
| 56 | AVCodecContext *ctx; |
| 57 | int result; |
| 58 | char name_buff[NAME_BUFF_SIZE]; |
| 59 | |
| 60 | av_channel_layout_describe(ch_layout, name_buff, NAME_BUFF_SIZE); |
| 61 | av_log(NULL, AV_LOG_INFO, "channel layout: %s, sample rate: %i\n", name_buff, sample_rate); |
| 62 | |
| 63 | ctx = avcodec_alloc_context3(enc); |
| 64 | if (!ctx) { |
| 65 | av_log(NULL, AV_LOG_ERROR, "Can't allocate encoder context\n"); |
| 66 | return AVERROR(ENOMEM); |
| 67 | } |
| 68 | |
| 69 | ctx->sample_fmt = AV_SAMPLE_FMT_S16; |
| 70 | ctx->sample_rate = sample_rate; |
| 71 | av_channel_layout_copy(&ctx->ch_layout, ch_layout); |
| 72 | |
| 73 | result = avcodec_open2(ctx, enc, NULL); |
| 74 | if (result < 0) { |
| 75 | av_log(ctx, AV_LOG_ERROR, "Can't open encoder\n"); |
| 76 | return result; |
| 77 | } |
| 78 | |
| 79 | *enc_ctx = ctx; |
| 80 | return 0; |
| 81 | } |
| 82 | |
| 83 | static int init_decoder(const AVCodec *dec, AVCodecContext **dec_ctx, |
| 84 | const AVChannelLayout *ch_layout) |
no test coverage detected