* - Sound data organized in packets follow the EA3 header
* (can be encrypted using the Sony DRM!).
*
- * CODEC SUPPORT: Only ATRAC3 codec is currently supported!
+ * Supported decoders: ATRAC3, ATRAC3+, MP3, LPCM
*/
+#include <inttypes.h>
+
#include "libavutil/channel_layout.h"
#include "avformat.h"
#include "internal.h"
#include "libavutil/intreadwrite.h"
#include "libavutil/des.h"
+#include "libavutil/mathematics.h"
#include "oma.h"
#include "pcm.h"
#include "id3v2.h"
if (geob->datasize < 64) {
av_log(s, AV_LOG_ERROR,
- "Invalid GEOB data size: %u\n", geob->datasize);
+ "Invalid GEOB data size: %"PRIu32"\n", geob->datasize);
return AVERROR_INVALIDDATA;
}
return AVERROR_INVALIDDATA;
}
oc->rid = AV_RB32(&gdata[OMA_ENC_HEADER_SIZE + 28]);
- av_log(s, AV_LOG_DEBUG, "RID: %.8x\n", oc->rid);
+ av_log(s, AV_LOG_DEBUG, "RID: %.8"PRIx32"\n", oc->rid);
memcpy(oc->iv, &header[0x58], 8);
hex_log(s, AV_LOG_DEBUG, "IV", oc->iv, 8);
channel_id = (codec_params >> 10) & 7;
if (!channel_id) {
av_log(s, AV_LOG_ERROR,
- "Invalid ATRAC-X channel id: %d\n", channel_id);
+ "Invalid ATRAC-X channel id: %"PRIu32"\n", channel_id);
return AVERROR_INVALIDDATA;
}
st->codec->channel_layout = ff_oma_chid_to_native_layout[channel_id - 1];
st->codec->sample_rate = samplerate;
st->codec->bit_rate = samplerate * framesize * 8 / 2048;
avpriv_set_pts_info(st, 64, 1, samplerate);
- av_log(s, AV_LOG_ERROR, "Unsupported codec ATRAC3+!\n");
break;
case OMA_CODECID_MP3:
st->need_parsing = AVSTREAM_PARSE_FULL;
static int oma_read_packet(AVFormatContext *s, AVPacket *pkt)
{
- OMAContext *oc = s->priv_data;
- int packet_size = s->streams[0]->codec->block_align;
- int ret = av_get_packet(s->pb, pkt, packet_size);
+ OMAContext *oc = s->priv_data;
+ AVStream *st = s->streams[0];
+ int packet_size = st->codec->block_align;
+ int byte_rate = st->codec->bit_rate >> 3;
+ int64_t pos = avio_tell(s->pb);
+ int ret = av_get_packet(s->pb, pkt, packet_size);
if (ret < packet_size)
pkt->flags |= AV_PKT_FLAG_CORRUPT;
pkt->stream_index = 0;
+ if (pos > 0) {
+ pkt->pts =
+ pkt->dts = av_rescale(pos, st->time_base.den,
+ byte_rate * (int64_t)st->time_base.num);
+ }
+
if (oc->encrypted) {
/* previous unencrypted block saved in IV for
* the next packet (CBC mode) */
static int oma_read_probe(AVProbeData *p)
{
- const uint8_t *buf;
+ const uint8_t *buf = p->buf;
unsigned tag_len = 0;
- buf = p->buf;
-
- if (p->buf_size < ID3v2_HEADER_SIZE ||
- !ff_id3v2_match(buf, ID3v2_EA3_MAGIC) ||
- buf[3] != 3 || // version must be 3
- buf[4]) // flags byte zero
- return 0;
-
- tag_len = ff_id3v2_tag_len(buf);
+ if (p->buf_size >= ID3v2_HEADER_SIZE && ff_id3v2_match(buf, ID3v2_EA3_MAGIC))
+ tag_len = ff_id3v2_tag_len(buf);
/* This check cannot overflow as tag_len has at most 28 bits */
if (p->buf_size < tag_len + 5)
/* EA3 header comes late, might be outside of the probe buffer */
- return AVPROBE_SCORE_EXTENSION;
+ return tag_len ? AVPROBE_SCORE_EXTENSION : 0;
buf += tag_len;