[FFmpeg-devel] [PATCH] oma demuxer
Michael Niedermayer
michaelni
Mon May 5 23:16:40 CEST 2008
On Mon, May 05, 2008 at 10:14:35PM +0200, Benjamin Larsson wrote:
> Hi, here is a demuxer for the oma container. Sample file to test the
> decoder can be found here:
>
> http://samples.mplayerhq.hu/oma/01-Untitled(1).oma
>
> It works but spits out lots "Multiple frames in a packet" messages. What
> has to be done to fix that issue.
Pass single packets instead of 4 at a time but thats obvious you even
explicitly multiply by 4.
[...]
> +typedef struct {
> + int filesize;
unneeded
> + int packetsize;
redundant
> + int npackets;
unused
> + int datapos;
unneeded
> +} OMAContext;
> +
> +typedef struct {
> + int index;
> + int bitrate;
> + int framesize;
> + int channels;
> + int coding_mode;
> +} ATRAC3ModeDesc;
> +
> +static const ATRAC3ModeDesc atrac3_modes[4] = {
> + {0, 66000, 192, 2, 1},
> + {1, 94000, 272, 2, 1},
> + {2, 105000, 304, 2, 0},
> + {3, 132000, 384, 2, 0}
> +};
this could be an anonymous struct
int is not needed, smaller types are enough
one field equals the index one is const
> +
> +static int is_ea3_tag_header(const uint8_t *buf)
> +{
> + return (buf[0] == 'e' && buf[1] == 'a' && buf[2] == '3' && buf[3] == 3 && buf[4] == 0);
> +}
strcmp, memcmp, whatever
> +
> +static int16_t get_encryption_id(const uint8_t *buf)
> +{
> + return (buf[0] << 8 | buf[1]);
> +}
we have code to read 16bits
[...]
> +static int oma_read_header(AVFormatContext *s,
> + AVFormatParameters *ap)
> +{
> + int filesize, ret, taglen, pos, codec_id, framesize, i, mode;
> + int16_t eid;
> + uint8_t buf[EA3_HEADER_SIZE];
> + const uint8_t *edata;
> + AVStream *st;
> + OMAContext *ctx = s->priv_data;
> +
> + filesize = url_fsize(s->pb);
> + if (filesize < 10)
> + return -1;
remove this
[...]
> + st->codec->channels = atrac3_modes[mode].channels;
> + st->codec->sample_rate = 44100;
> + st->codec->bit_rate = atrac3_modes[mode].bitrate;
> + st->codec->block_align = atrac3_modes[mode].framesize;
vertical align
> +
> + /* fake the atrac3 extradata */
> + st->codec->extradata_size = 14;
> + edata = av_mallocz(14 + FF_INPUT_BUFFER_PADDING_SIZE);
> + if (!edata)
> + return AVERROR(ENOMEM);
> +
> + st->codec->extradata = edata;
> + bytestream_put_le16(&edata, 1);
> + bytestream_put_le32(&edata, 4096); // samples_per_channel
> + bytestream_put_le16(&edata, atrac3_modes[mode].coding_mode);
> + bytestream_put_le16(&edata, atrac3_modes[mode].coding_mode);
> + bytestream_put_le16(&edata, 1);
> + bytestream_put_le16(&edata, 0);
redundant
> +
> + st->need_parsing = AVSTREAM_PARSE_FULL;
This does not work as there is no ATRAC3 parser
[...]
> +static int oma_read_packet(AVFormatContext *s, AVPacket *pkt)
> +{
> + int ret, size, left;
> + OMAContext *ctx = s->priv_data;
> +
> + size = ctx->packetsize * 4;
> + left = ctx->filesize - url_ftell(s->pb);
> + if (left < size)
> + size = left;
> +
> + ret= av_get_packet(s->pb, pkt, size);
> +
> + pkt->stream_index = 0;
> + if (ret <= 0) {
> + return AVERROR(EIO);
> + }
> + /* note: we need to modify the packet size here to handle the last
> + packet */
> + pkt->size = ret;
?
> + return ret;
> +}
> +
> +#ifdef CONFIG_OMA_DEMUXER
> +AVInputFormat oma_demuxer = {
> + "oma",
> + "Sony OpenMG audio",
> + sizeof(OMAContext),
> + oma_read_probe,
> + oma_read_header,
> + oma_read_packet,
> + NULL,
> + .flags= AVFMT_GENERIC_INDEX,
> + .extensions = "oma,aa3", /* XXX: use probe */
senseles as a probe function exists.
> +};
> +#endif
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel at mplayerhq.hu
> https://lists.mplayerhq.hu/mailman/listinfo/ffmpeg-devel
--
Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB
Its not that you shouldnt use gotos but rather that you should write
readable code and code with gotos often but not always is less readable
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: Digital signature
URL: <http://lists.mplayerhq.hu/pipermail/ffmpeg-devel/attachments/20080505/6bc6cbd8/attachment.pgp>
More information about the ffmpeg-devel
mailing list