2 * Copyright (C) 2006 Andre Noll <maan@systemlinux.org>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
18 /** \file aac_afh.c para_server's aac audio format handler */
21 #include "server.cmdline.h"
28 /* must be big enough to hold header */
29 #define DEFAULT_INBUF_SIZE 65536
32 static int inbuf_size;
33 static unsigned char *inbuf;
34 static ssize_t *chunk_table;
35 struct audio_format *af;
37 unsigned num_chunks, chunk_num;
39 NeAACDecHandle handle;
40 static void aac_close_audio_file(void)
45 * Init m4a file and write some tech data to given pointers.
47 static int aac_get_file_info(FILE *file, char *info_str, long unsigned *frames,
50 int ret, skip, decoder_len;
52 unsigned long rate = 0;
53 unsigned char channels = 0;
56 inbuf_size = DEFAULT_INBUF_SIZE;
57 inbuf = para_malloc(inbuf_size);
60 PARA_INFO_LOG("file: %p\n", file);
61 ret = read(fileno(infile), inbuf, inbuf_size);
62 PARA_INFO_LOG("read %d bytes\n", ret);
65 PARA_INFO_LOG("checking aac %d bytes\n", ret);
67 ret = aac_find_esds(inbuf, inbuf_len, &skip);
72 ret = NeAACDecInit(handle, inbuf + skip,
73 inbuf_len - skip, &rate, &channels);
74 PARA_INFO_LOG("rate: %lu, channels: %d\n", rate, channels);
80 * Simple stream reposition routine
82 static int aac_reposition_stream(long unsigned request)
87 static int get_chunk_size(long unsigned chunk_num)
90 if (chunk_num >= num_chunks)
92 ret = chunk_table[chunk_num + 1] - chunk_table[chunk_num];
96 PARA_DEBUG_LOG("chunk %d: %lli-%lli (%lli bytes)\n",
98 chunk_table[chunk_num],
99 chunk_table[chunk_num + 1] - 1,
105 char *aac_read_chunk(long unsigned current_chunk, ssize_t *len)
107 return (char *)inbuf;
110 void aac_afh_init(void *p)
113 af->reposition_stream = aac_reposition_stream;
114 af->get_file_info = aac_get_file_info,
115 af->read_chunk = aac_read_chunk;
116 af->close_audio_file = aac_close_audio_file;
117 af->get_header_info = NULL;
118 af->chunk_tv.tv_sec = 0;
119 af->chunk_tv.tv_usec = 250 * 1000;
120 tv_scale(3, &af->chunk_tv, &af->eof_tv);