summaryrefslogtreecommitdiff
path: root/src/libfaad/xine_faad_decoder.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/libfaad/xine_faad_decoder.c')
-rw-r--r--src/libfaad/xine_faad_decoder.c43
1 files changed, 38 insertions, 5 deletions
diff --git a/src/libfaad/xine_faad_decoder.c b/src/libfaad/xine_faad_decoder.c
index 934140a32..b90bc701f 100644
--- a/src/libfaad/xine_faad_decoder.c
+++ b/src/libfaad/xine_faad_decoder.c
@@ -18,6 +18,10 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
*/
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
@@ -35,10 +39,14 @@
#include "audio_out.h"
#include "buffer.h"
#include "xineutils.h"
+#ifdef HAVE_FAAD_H
+#include <faad.h>
+#else
#include "common.h"
#include "structs.h"
#include "decoder.h"
#include "syntax.h"
+#endif
#define FAAD_MIN_STREAMSIZE 768 /* 6144 bits/channel */
@@ -271,7 +279,32 @@ static void faad_decode_audio ( faad_decoder_t *this, int end_frame ) {
lprintf("decoded %d/%d output %ld\n",
used, this->size, this->faac_finfo.samples );
-
+
+ /* Performing necessary channel reordering because aac uses a different
+ * layout than alsa:
+ *
+ * aac 5.1 channel layout: c l r ls rs lfe
+ * alsa 5.1 channel layout: l r ls rs c lfe
+ *
+ * Reordering is only necessary for 5.0 and above. Currently only 5.0
+ * and 5.1 is being taken care of, the rest will stay in the wrong order
+ * for now.
+ *
+ * WARNING: the following needs a output format of 16 bits per sample.
+ * TODO: - reorder while copying (in the while() loop) and optimizing
+ */
+ if(this->num_channels == 5 || this->num_channels == 6)
+ {
+ int i = 0;
+ uint16_t* buf = (uint16_t*)(sample_buffer);
+
+ for(; i < this->faac_finfo.samples; i += this->num_channels) {
+ uint16_t center = buf[i];
+ *((uint64_t*)(buf + i)) = *((uint64_t*)(buf + i + 1));
+ buf[i + 4] = center;
+ }
+ }
+
while( decoded ) {
audio_buffer = this->stream->audio_out->get_buffer (this->stream->audio_out);
@@ -320,7 +353,7 @@ static void faad_decode_data (audio_decoder_t *this_gen, buf_element_t *buf) {
if( !this->faac_dec && (buf->decoder_flags & BUF_FLAG_SPECIAL) &&
buf->decoder_info[1] == BUF_SPECIAL_DECODER_CONFIG ) {
- this->dec_config = xine_xmalloc(buf->decoder_info[2]);
+ this->dec_config = malloc(buf->decoder_info[2]);
this->dec_config_size = buf->decoder_info[2];
memcpy(this->dec_config, buf->decoder_info_ptr[2], buf->decoder_info[2]);
@@ -341,7 +374,7 @@ static void faad_decode_data (audio_decoder_t *this_gen, buf_element_t *buf) {
xine_waveformatex *wavex = (xine_waveformatex *) buf->content;
if( wavex->cbSize > 0 ) {
- this->dec_config = xine_xmalloc(wavex->cbSize);
+ this->dec_config = malloc(wavex->cbSize);
this->dec_config_size = wavex->cbSize;
memcpy(this->dec_config, buf->content + sizeof(xine_waveformatex),
wavex->cbSize);
@@ -417,7 +450,7 @@ static audio_decoder_t *open_plugin (audio_decoder_class_t *class_gen, xine_stre
faad_decoder_t *this ;
- this = (faad_decoder_t *) xine_xmalloc (sizeof (faad_decoder_t));
+ this = calloc(1, sizeof (faad_decoder_t));
this->audio_decoder.decode_data = faad_decode_data;
this->audio_decoder.reset = faad_reset;
@@ -458,7 +491,7 @@ static void *init_plugin (xine_t *xine, void *data) {
faad_class_t *this ;
- this = (faad_class_t *) xine_xmalloc (sizeof (faad_class_t));
+ this = calloc(1, sizeof (faad_class_t));
this->decoder_class.open_plugin = open_plugin;
this->decoder_class.get_identifier = get_identifier;