Skip to content

Commit

Permalink
postprocessing: use ffmpeg new channel layout API when available
Browse files Browse the repository at this point in the history
  • Loading branch information
atoppi committed May 3, 2024
1 parent 070c415 commit cefca79
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
4 changes: 4 additions & 0 deletions src/postprocessing/pp-avformat.c
Expand Up @@ -64,7 +64,11 @@ AVStream *janus_pp_new_audio_avstream(AVFormatContext *fctx, int codec_id, int s
c->codec_id = codec_id;
c->codec_type = AVMEDIA_TYPE_AUDIO;
c->sample_rate = samplerate;
#ifdef NEW_CHANNEL_LAYOUT
c->ch_layout.nb_channels = channels;
#else
c->channels = channels;
#endif
if(extradata) {
c->extradata_size = size;
c->extradata = av_memdup(extradata, size);
Expand Down
5 changes: 5 additions & 0 deletions src/postprocessing/pp-avformat.h
Expand Up @@ -40,6 +40,11 @@
#define USE_CODECPAR
#endif

/* https://github.com/FFmpeg/FFmpeg/commit/cdba98bb80e2ab73d34659c610771b020afc6a77 */
#if LIBAVCODEC_VER_AT_LEAST(59, 24)
#define NEW_CHANNEL_LAYOUT
#endif

void janus_pp_setup_avformat(void);

AVFormatContext *janus_pp_create_avformatcontext(const char *format, const char *metadata, const char *destination);
Expand Down
7 changes: 6 additions & 1 deletion src/postprocessing/pp-g722.c
Expand Up @@ -211,7 +211,12 @@ int janus_pp_g722_process(FILE *file, janus_pp_frame_packet *list, int *working)
int data_size = av_get_bytes_per_sample(dec_ctx->sample_fmt);
int i=0, ch=0;
for(i=0; i<frame->nb_samples; i++) {
for(ch=0; ch<dec_ctx->channels; ch++) {
#ifdef NEW_CHANNEL_LAYOUT
int channels = dec_ctx->ch_layout.nb_channels;
#else
int channels = dec_ctx->channels;
#endif
for(ch=0; ch<channels; ch++) {
fwrite(frame->data[ch] + data_size*i, 1, data_size, wav_file);
}
}
Expand Down

0 comments on commit cefca79

Please sign in to comment.