Mercurial > mplayer.hg
comparison av_helpers.c @ 36335:f77a74ebb95e
Quick an inefficient hack to enable planar encoding.
Should fix bugzilla #2094.
author | reimar |
---|---|
date | Sun, 25 Aug 2013 11:30:45 +0000 |
parents | c1033e9288b1 |
children | d9d308031e9e |
comparison
equal
deleted
inserted
replaced
36334:c1033e9288b1 | 36335:f77a74ebb95e |
---|---|
115 } | 115 } |
116 } | 116 } |
117 | 117 |
118 int lavc_encode_audio(AVCodecContext *ctx, void *src, int src_len, void *dst, int dst_len) | 118 int lavc_encode_audio(AVCodecContext *ctx, void *src, int src_len, void *dst, int dst_len) |
119 { | 119 { |
120 void *orig_src = src; | |
120 int bps = av_get_bytes_per_sample(ctx->sample_fmt); | 121 int bps = av_get_bytes_per_sample(ctx->sample_fmt); |
122 int planar = ctx->channels > 1 && av_sample_fmt_is_planar(ctx->sample_fmt); | |
121 int n; | 123 int n; |
122 int got; | 124 int got; |
123 AVPacket pkt; | 125 AVPacket pkt; |
124 AVFrame frame; | 126 AVFrame *frame = avcodec_alloc_frame(); |
125 if ((ctx->channels == 6 || ctx->channels == 5) && | 127 if ((ctx->channels == 6 || ctx->channels == 5) && |
126 (!strcmp(ctx->codec->name,"ac3") || !strcmp(ctx->codec->name,"libfaac"))) { | 128 (!strcmp(ctx->codec->name,"ac3") || !strcmp(ctx->codec->name,"libfaac"))) { |
127 int isac3 = !strcmp(ctx->codec->name,"ac3"); | 129 int isac3 = !strcmp(ctx->codec->name,"ac3"); |
128 reorder_channel_nch(src, AF_CHANNEL_LAYOUT_MPLAYER_DEFAULT, | 130 reorder_channel_nch(src, AF_CHANNEL_LAYOUT_MPLAYER_DEFAULT, |
129 isac3 ? AF_CHANNEL_LAYOUT_LAVC_DEFAULT : AF_CHANNEL_LAYOUT_AAC_DEFAULT, | 131 isac3 ? AF_CHANNEL_LAYOUT_LAVC_DEFAULT : AF_CHANNEL_LAYOUT_AAC_DEFAULT, |
130 ctx->channels, | 132 ctx->channels, |
131 src_len / bps, bps); | 133 src_len / bps, bps); |
132 } | 134 } |
133 pkt.data = dst; | 135 pkt.data = dst; |
134 pkt.size = dst_len; | 136 pkt.size = dst_len; |
135 frame.data[0] = src; | 137 frame->nb_samples = src_len / ctx->channels / bps; |
136 frame.linesize[0] = src_len / ctx->channels; | 138 if (planar) { |
137 frame.nb_samples = frame.linesize[0] / bps; | 139 // TODO: this is horribly inefficient. |
138 n = avcodec_encode_audio2(ctx, &pkt, &frame, &got); | 140 int ch; |
141 src = av_mallocz(src_len); | |
142 for (ch = 0; ch < ctx->channels; ch++) { | |
143 uint8_t *tmps = (uint8_t *)orig_src + ch*bps; | |
144 uint8_t *tmpd = (uint8_t *)src + ch*src_len/ctx->channels; | |
145 int s; | |
146 for (s = 0; s < frame->nb_samples; s++) { | |
147 memcpy(tmpd, tmps, bps); | |
148 tmps += ctx->channels * bps; | |
149 tmpd += bps; | |
150 } | |
151 } | |
152 } | |
153 n = avcodec_fill_audio_frame(frame, ctx->channels, ctx->sample_fmt, src, src_len, 1); | |
154 if (n < 0) return 0; | |
155 n = avcodec_encode_audio2(ctx, &pkt, frame, &got); | |
156 avcodec_free_frame(&frame); | |
157 if (planar) av_free(src); | |
139 if (n < 0) return n; | 158 if (n < 0) return n; |
140 return got ? pkt.size : 0; | 159 return got ? pkt.size : 0; |
141 } | 160 } |