* 2008 Benjamin Larsson
* 2011 David Goldwich
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "internal.h"
#include "libavutil/intreadwrite.h"
#include "libavutil/des.h"
+#include "oma.h"
#include "pcm.h"
#include "riff.h"
#include "id3v2.h"
-#define EA3_HEADER_SIZE 96
-#define ID3v2_EA3_MAGIC "ea3"
-#define OMA_ENC_HEADER_SIZE 16
-
-enum {
- OMA_CODECID_ATRAC3 = 0,
- OMA_CODECID_ATRAC3P = 1,
- OMA_CODECID_MP3 = 3,
- OMA_CODECID_LPCM = 4,
- OMA_CODECID_WMA = 5,
-};
-
-static const AVCodecTag codec_oma_tags[] = {
- { CODEC_ID_ATRAC3, OMA_CODECID_ATRAC3 },
- { CODEC_ID_ATRAC3P, OMA_CODECID_ATRAC3P },
- { CODEC_ID_MP3, OMA_CODECID_MP3 },
- { CODEC_ID_PCM_S16BE, OMA_CODECID_LPCM },
-};
static const uint64_t leaf_table[] = {
0xd79e8283acea4620, 0x7a9762f445afd0d8,
return memcmp(&enc_header[pos], oc->sm_val, 8) ? -1 : 0;
}
-static int nprobe(AVFormatContext *s, uint8_t *enc_header, const uint8_t *n_val)
+static int nprobe(AVFormatContext *s, uint8_t *enc_header, int size, const uint8_t *n_val)
{
OMAContext *oc = s->priv_data;
uint32_t pos, taglen, datalen;
taglen = AV_RB32(&enc_header[pos+32]);
datalen = AV_RB32(&enc_header[pos+36]) >> 4;
+ if(taglen + (((uint64_t)datalen)<<4) + 44 > size)
+ return -1;
+
pos += 44 + taglen;
av_des_init(&av_des, n_val, 192, 1);
}
if (!memcmp(oc->r_val, (const uint8_t[8]){0}, 8) ||
rprobe(s, gdata, oc->r_val) < 0 &&
- nprobe(s, gdata, oc->n_val) < 0) {
+ nprobe(s, gdata, geob->datasize, oc->n_val) < 0) {
int i;
for (i = 0; i < sizeof(leaf_table); i += 2) {
uint8_t buf[16];
AV_WL64(buf, leaf_table[i]);
AV_WL64(&buf[8], leaf_table[i+1]);
kset(s, buf, buf, 16);
- if (!rprobe(s, gdata, oc->r_val) || !nprobe(s, gdata, oc->n_val))
+ if (!rprobe(s, gdata, oc->r_val) || !nprobe(s, gdata, geob->datasize, oc->n_val))
break;
}
if (i >= sizeof(leaf_table)) {
static int oma_read_header(AVFormatContext *s,
AVFormatParameters *ap)
{
- static const uint16_t srate_tab[6] = {320,441,480,882,960,0};
int ret, framesize, jsflag, samplerate;
uint32_t codec_params;
int16_t eid;
st->start_time = 0;
st->codec->codec_type = AVMEDIA_TYPE_AUDIO;
st->codec->codec_tag = buf[32];
- st->codec->codec_id = ff_codec_get_id(codec_oma_tags, st->codec->codec_tag);
+ st->codec->codec_id = ff_codec_get_id(ff_oma_codec_tags, st->codec->codec_tag);
switch (buf[32]) {
case OMA_CODECID_ATRAC3:
- samplerate = srate_tab[(codec_params >> 13) & 7]*100;
+ samplerate = ff_oma_srate_tab[(codec_params >> 13) & 7]*100;
if (samplerate != 44100)
av_log_ask_for_sample(s, "Unsupported sample rate: %d\n",
samplerate);
case OMA_CODECID_ATRAC3P:
st->codec->channels = (codec_params >> 10) & 7;
framesize = ((codec_params & 0x3FF) * 8) + 8;
- st->codec->sample_rate = srate_tab[(codec_params >> 13) & 7]*100;
+ st->codec->sample_rate = ff_oma_srate_tab[(codec_params >> 13) & 7]*100;
st->codec->bit_rate = st->codec->sample_rate * framesize * 8 / 1024;
avpriv_set_pts_info(st, 64, 1, st->codec->sample_rate);
av_log(s, AV_LOG_ERROR, "Unsupported codec ATRAC3+!\n");
.read_seek = oma_read_seek,
.flags = AVFMT_GENERIC_INDEX,
.extensions = "oma,omg,aa3",
- .codec_tag = (const AVCodecTag* const []){codec_oma_tags, 0},
+ .codec_tag = (const AVCodecTag* const []){ff_oma_codec_tags, 0},
};