[MPlayer-cvslog] r36430 - in trunk: av_helpers.c av_helpers.h libaf/af_lavcac3enc.c libmpcodecs/ae_lavc.c
reimar
subversion at mplayerhq.hu
Sun Aug 25 13:30:44 CEST 2013
Author: reimar
Date: Sun Aug 25 13:30:43 2013
New Revision: 36430
Log:
Extract audio encoding code into a separate helper function.
Modified:
trunk/av_helpers.c
trunk/av_helpers.h
trunk/libaf/af_lavcac3enc.c
trunk/libmpcodecs/ae_lavc.c
Modified: trunk/av_helpers.c
==============================================================================
--- trunk/av_helpers.c Sun Aug 25 13:30:42 2013 (r36429)
+++ trunk/av_helpers.c Sun Aug 25 13:30:43 2013 (r36430)
@@ -22,6 +22,7 @@
#include "libavformat/avformat.h"
#include "mp_msg.h"
#include "av_helpers.h"
+#include "libaf/reorder_ch.h"
int avcodec_initialized;
int avformat_initialized;
@@ -113,3 +114,28 @@ void init_avformat(void)
av_log_set_callback(mp_msp_av_log_callback);
}
}
+
+int lavc_encode_audio(AVCodecContext *ctx, void *src, int src_len, void *dst, int dst_len)
+{
+ int bps = av_get_bytes_per_sample(ctx->sample_fmt);
+ int n;
+ int got;
+ AVPacket pkt;
+ AVFrame frame;
+ if ((ctx->channels == 6 || ctx->channels == 5) &&
+ (!strcmp(ctx->codec->name,"ac3") || !strcmp(ctx->codec->name,"libfaac"))) {
+ int isac3 = !strcmp(ctx->codec->name,"ac3");
+ reorder_channel_nch(src, AF_CHANNEL_LAYOUT_MPLAYER_DEFAULT,
+ isac3 ? AF_CHANNEL_LAYOUT_LAVC_DEFAULT : AF_CHANNEL_LAYOUT_AAC_DEFAULT,
+ ctx->channels,
+ src_len / bps, bps);
+ }
+ pkt.data = dst;
+ pkt.size = dst_len;
+ frame.data[0] = src;
+ frame.linesize[0] = src_len / ctx->channels;
+ frame.nb_samples = frame.linesize[0] / bps;
+ n = avcodec_encode_audio2(ctx, &pkt, &frame, &got);
+ if (n < 0) return n;
+ return got ? pkt.size : 0;
+}
Modified: trunk/av_helpers.h
==============================================================================
--- trunk/av_helpers.h Sun Aug 25 13:30:42 2013 (r36429)
+++ trunk/av_helpers.h Sun Aug 25 13:30:43 2013 (r36430)
@@ -21,7 +21,10 @@
#ifndef MPLAYER_AV_HELPERS_H
#define MPLAYER_AV_HELPERS_H
+struct AVCodecContext;
+
void init_avcodec(void);
void init_avformat(void);
+int lavc_encode_audio(struct AVCodecContext *ctx, void *src, int src_len, void *dst, int dst_len);
#endif /* MPLAYER_AV_HELPERS_H */
Modified: trunk/libaf/af_lavcac3enc.c
==============================================================================
--- trunk/libaf/af_lavcac3enc.c Sun Aug 25 13:30:42 2013 (r36429)
+++ trunk/libaf/af_lavcac3enc.c Sun Aug 25 13:30:43 2013 (r36430)
@@ -229,15 +229,10 @@ static af_data_t* play(struct af_instanc
src += s->expect_len;
left -= s->expect_len;
}
- if (c->nch >= 5)
- reorder_channel_nch(in,
- AF_CHANNEL_LAYOUT_MPLAYER_DEFAULT,
- AF_CHANNEL_LAYOUT_LAVC_DEFAULT,
- c->nch,
- s->expect_len / 2, 2);
- len = avcodec_encode_audio(s->lavc_actx, dest, destsize, in);
+ len = lavc_encode_audio(s->lavc_actx, in, s->expect_len, dest, destsize);
mp_msg(MSGT_AFILTER, MSGL_DBG2, "avcodec_encode_audio got %d, pending %d.\n",
len, s->pending_len);
+ if (len < 0) len = 0;
if (s->add_iec61937_header) {
int bsmod = dest[5] & 0x7;
Modified: trunk/libmpcodecs/ae_lavc.c
==============================================================================
--- trunk/libmpcodecs/ae_lavc.c Sun Aug 25 13:30:42 2013 (r36429)
+++ trunk/libmpcodecs/ae_lavc.c Sun Aug 25 13:30:43 2013 (r36430)
@@ -118,20 +118,9 @@ static int bind_lavc(audio_encoder_t *en
static int encode_lavc(audio_encoder_t *encoder, uint8_t *dest, void *src, int size, int max_size)
{
int n;
- if ((encoder->params.channels == 6 || encoder->params.channels == 5) &&
- (!strcmp(lavc_acodec->name,"ac3") ||
- !strcmp(lavc_acodec->name,"libfaac"))) {
- int isac3 = !strcmp(lavc_acodec->name,"ac3");
- int bps = av_get_bytes_per_sample(lavc_actx->sample_fmt);
- reorder_channel_nch(src, AF_CHANNEL_LAYOUT_MPLAYER_DEFAULT,
- isac3 ? AF_CHANNEL_LAYOUT_LAVC_DEFAULT
- : AF_CHANNEL_LAYOUT_AAC_DEFAULT,
- encoder->params.channels,
- size / bps, bps);
- }
- n = avcodec_encode_audio(lavc_actx, dest, size, src);
- compressed_frame_size = n;
- return n;
+ n = lavc_encode_audio(lavc_actx, src, size, dest, max_size);
+ compressed_frame_size = n < 0 ? 0 : n;
+ return compressed_frame_size;
}
More information about the MPlayer-cvslog
mailing list