*/
#include "avformat.h"
+#ifdef CONFIG_ENCODERS
/* simple formats */
static int raw_write_header(struct AVFormatContext *s)
{
return 0;
}
-static int raw_write_packet(struct AVFormatContext *s, int stream_index,
- const uint8_t *buf, int size, int64_t pts)
+static int raw_write_packet(struct AVFormatContext *s, AVPacket *pkt)
{
- put_buffer(&s->pb, buf, size);
+ put_buffer(&s->pb, pkt->data, pkt->size);
put_flush_packet(&s->pb);
return 0;
}
{
return 0;
}
+#endif //CONFIG_ENCODERS
/* raw input */
static int raw_read_header(AVFormatContext *s, AVFormatParameters *ap)
case CODEC_TYPE_AUDIO:
st->codec.sample_rate = ap->sample_rate;
st->codec.channels = ap->channels;
+ av_set_pts_info(st, 64, 1, st->codec.sample_rate);
break;
case CODEC_TYPE_VIDEO:
st->codec.frame_rate = ap->frame_rate;
size= RAW_PACKET_SIZE;
if (av_new_packet(pkt, size) < 0)
- return -EIO;
+ return AVERROR_IO;
pkt->stream_index = 0;
ret = get_buffer(&s->pb, pkt->data, size);
if (ret <= 0) {
av_free_packet(pkt);
- return -EIO;
+ return AVERROR_IO;
}
/* note: we need to modify the packet size here to handle the last
packet */
return ret;
}
+static int raw_read_partial_packet(AVFormatContext *s, AVPacket *pkt)
+{
+ int ret, size;
+
+ size = RAW_PACKET_SIZE;
+
+ if (av_new_packet(pkt, size) < 0)
+ return AVERROR_IO;
+
+ pkt->stream_index = 0;
+ ret = get_partial_buffer(&s->pb, pkt->data, size);
+ if (ret <= 0) {
+ av_free_packet(pkt);
+ return AVERROR_IO;
+ }
+ pkt->size = ret;
+ return ret;
+}
+
static int raw_read_close(AVFormatContext *s)
{
return 0;
}
+int pcm_read_seek(AVFormatContext *s,
+ int stream_index, int64_t timestamp, int flags)
+{
+ AVStream *st;
+ int block_align, byte_rate;
+ int64_t pos;
+
+ st = s->streams[0];
+ switch(st->codec.codec_id) {
+ case CODEC_ID_PCM_S16LE:
+ case CODEC_ID_PCM_S16BE:
+ case CODEC_ID_PCM_U16LE:
+ case CODEC_ID_PCM_U16BE:
+ block_align = 2 * st->codec.channels;
+ byte_rate = block_align * st->codec.sample_rate;
+ break;
+ case CODEC_ID_PCM_S8:
+ case CODEC_ID_PCM_U8:
+ case CODEC_ID_PCM_MULAW:
+ case CODEC_ID_PCM_ALAW:
+ block_align = st->codec.channels;
+ byte_rate = block_align * st->codec.sample_rate;
+ break;
+ default:
+ block_align = st->codec.block_align;
+ byte_rate = st->codec.bit_rate / 8;
+ break;
+ }
+
+ if (block_align <= 0 || byte_rate <= 0)
+ return -1;
+
+ /* compute the position by aligning it to block_align */
+ pos = av_rescale_rnd(timestamp * byte_rate,
+ st->time_base.num,
+ st->time_base.den * (int64_t)block_align,
+ (flags & AVSEEK_FLAG_BACKWARD) ? AV_ROUND_DOWN : AV_ROUND_UP);
+ pos *= block_align;
+
+ /* recompute exact position */
+ st->cur_dts = av_rescale(pos, st->time_base.den, byte_rate * (int64_t)st->time_base.num);
+ url_fseek(&s->pb, pos + s->data_offset, SEEK_SET);
+ return 0;
+}
+
/* ac3 read */
static int ac3_read_header(AVFormatContext *s,
AVFormatParameters *ap)
st->codec.codec_type = CODEC_TYPE_AUDIO;
st->codec.codec_id = CODEC_ID_AC3;
+ st->need_parsing = 1;
+ /* the parameters will be extracted from the compressed bitstream */
+ return 0;
+}
+
+static int shorten_read_header(AVFormatContext *s,
+ AVFormatParameters *ap)
+{
+ AVStream *st;
+
+ st = av_new_stream(s, 0);
+ if (!st)
+ return AVERROR_NOMEM;
+ st->codec.codec_type = CODEC_TYPE_AUDIO;
+ st->codec.codec_id = CODEC_ID_SHORTEN;
+ st->need_parsing = 1;
+ /* the parameters will be extracted from the compressed bitstream */
+ return 0;
+}
+
+/* dts read */
+static int dts_read_header(AVFormatContext *s,
+ AVFormatParameters *ap)
+{
+ AVStream *st;
+
+ st = av_new_stream(s, 0);
+ if (!st)
+ return AVERROR_NOMEM;
+
+ st->codec.codec_type = CODEC_TYPE_AUDIO;
+ st->codec.codec_id = CODEC_ID_DTS;
+ st->need_parsing = 1;
/* the parameters will be extracted from the compressed bitstream */
return 0;
}
st->codec.codec_type = CODEC_TYPE_VIDEO;
st->codec.codec_id = s->iformat->value;
+ st->need_parsing = 1;
+
/* for mjpeg, specify frame rate */
/* for mpeg4 specify it too (most mpeg4 streams dont have the fixed_vop_rate set ...)*/
- if (st->codec.codec_id == CODEC_ID_MJPEG || st->codec.codec_id == CODEC_ID_MPEG4) {
- if (ap) {
+ if (st->codec.codec_id == CODEC_ID_MJPEG ||
+ st->codec.codec_id == CODEC_ID_MPEG4) {
+ if (ap && ap->frame_rate) {
st->codec.frame_rate = ap->frame_rate;
st->codec.frame_rate_base = ap->frame_rate_base;
} else {
return 0;
}
+static int h261_probe(AVProbeData *p)
+{
+ int code;
+ const uint8_t *d;
+
+ if (p->buf_size < 6)
+ return 0;
+ d = p->buf;
+ code = (d[0] << 12) | (d[1] << 4) | (d[2] >> 4);
+ if (code == 0x10) {
+ return 50;
+ }
+ return 0;
+}
+
+AVInputFormat shorten_iformat = {
+ "shn",
+ "raw shn",
+ 0,
+ NULL,
+ shorten_read_header,
+ raw_read_partial_packet,
+ raw_read_close,
+ .extensions = "shn",
+};
+
AVInputFormat ac3_iformat = {
"ac3",
"raw ac3",
0,
NULL,
ac3_read_header,
- raw_read_packet,
+ raw_read_partial_packet,
raw_read_close,
.extensions = "ac3",
};
+#ifdef CONFIG_ENCODERS
AVOutputFormat ac3_oformat = {
"ac3",
"raw ac3",
raw_write_packet,
raw_write_trailer,
};
+#endif //CONFIG_ENCODERS
+
+AVInputFormat dts_iformat = {
+ "dts",
+ "raw dts",
+ 0,
+ NULL,
+ dts_read_header,
+ raw_read_partial_packet,
+ raw_read_close,
+ .extensions = "dts",
+};
+
+AVInputFormat h261_iformat = {
+ "h261",
+ "raw h261",
+ 0,
+ h261_probe,
+ video_read_header,
+ raw_read_partial_packet,
+ raw_read_close,
+ .extensions = "h261",
+ .value = CODEC_ID_H261,
+};
+
+#ifdef CONFIG_ENCODERS
+AVOutputFormat h261_oformat = {
+ "h261",
+ "raw h261",
+ "video/x-h261",
+ "h261",
+ 0,
+ 0,
+ CODEC_ID_H261,
+ raw_write_header,
+ raw_write_packet,
+ raw_write_trailer,
+};
+#endif //CONFIG_ENCODERS
AVInputFormat h263_iformat = {
"h263",
0,
h263_probe,
video_read_header,
- raw_read_packet,
+ raw_read_partial_packet,
raw_read_close,
// .extensions = "h263", //FIXME remove after writing mpeg4_probe
.value = CODEC_ID_H263,
};
+#ifdef CONFIG_ENCODERS
AVOutputFormat h263_oformat = {
"h263",
"raw h263",
raw_write_packet,
raw_write_trailer,
};
+#endif //CONFIG_ENCODERS
AVInputFormat m4v_iformat = {
"m4v",
0,
NULL /*mpegvideo_probe*/,
video_read_header,
- raw_read_packet,
+ raw_read_partial_packet,
raw_read_close,
.extensions = "m4v", //FIXME remove after writing mpeg4_probe
.value = CODEC_ID_MPEG4,
};
+#ifdef CONFIG_ENCODERS
AVOutputFormat m4v_oformat = {
"m4v",
"raw MPEG4 video format",
raw_write_packet,
raw_write_trailer,
};
+#endif //CONFIG_ENCODERS
AVInputFormat h264_iformat = {
"h264",
0,
NULL /*mpegvideo_probe*/,
video_read_header,
- raw_read_packet,
+ raw_read_partial_packet,
raw_read_close,
.extensions = "h26l,h264", //FIXME remove after writing mpeg4_probe
.value = CODEC_ID_H264,
};
+#ifdef CONFIG_ENCODERS
AVOutputFormat h264_oformat = {
"h264",
"raw H264 video format",
raw_write_packet,
raw_write_trailer,
};
+#endif //CONFIG_ENCODERS
AVInputFormat mpegvideo_iformat = {
"mpegvideo",
0,
mpegvideo_probe,
video_read_header,
- raw_read_packet,
+ raw_read_partial_packet,
raw_read_close,
.value = CODEC_ID_MPEG1VIDEO,
};
+#ifdef CONFIG_ENCODERS
AVOutputFormat mpeg1video_oformat = {
"mpeg1video",
"MPEG video",
raw_write_packet,
raw_write_trailer,
};
+#endif //CONFIG_ENCODERS
+
+#ifdef CONFIG_ENCODERS
+AVOutputFormat mpeg2video_oformat = {
+ "mpeg2video",
+ "MPEG2 video",
+ NULL,
+ "m2v",
+ 0,
+ 0,
+ CODEC_ID_MPEG2VIDEO,
+ raw_write_header,
+ raw_write_packet,
+ raw_write_trailer,
+};
+#endif //CONFIG_ENCODERS
AVInputFormat mjpeg_iformat = {
"mjpeg",
0,
NULL,
video_read_header,
- raw_read_packet,
+ raw_read_partial_packet,
raw_read_close,
.extensions = "mjpg,mjpeg",
.value = CODEC_ID_MJPEG,
};
+#ifdef CONFIG_ENCODERS
AVOutputFormat mjpeg_oformat = {
"mjpeg",
"MJPEG video",
raw_write_packet,
raw_write_trailer,
};
+#endif //CONFIG_ENCODERS
/* pcm formats */
-#define PCMDEF(name, long_name, ext, codec) \
+#define PCMINPUTDEF(name, long_name, ext, codec) \
AVInputFormat pcm_ ## name ## _iformat = {\
#name,\
long_name,\
raw_read_header,\
raw_read_packet,\
raw_read_close,\
+ pcm_read_seek,\
.extensions = ext,\
.value = codec,\
-};\
+};
+
+#if !defined(CONFIG_ENCODERS) && defined(CONFIG_DECODERS)
+
+#define PCMDEF(name, long_name, ext, codec) \
+ PCMINPUTDEF(name, long_name, ext, codec)
+
+#else
+
+#define PCMDEF(name, long_name, ext, codec) \
+ PCMINPUTDEF(name, long_name, ext, codec)\
\
AVOutputFormat pcm_ ## name ## _oformat = {\
#name,\
raw_write_packet,\
raw_write_trailer,\
};
+#endif //CONFIG_ENCODERS
#ifdef WORDS_BIGENDIAN
#define BE_DEF(s) s
packet_size = avpicture_get_size(st->codec.pix_fmt, width, height);
if (packet_size < 0)
- av_abort();
+ return -1;
if (av_new_packet(pkt, packet_size) < 0)
- return -EIO;
+ return AVERROR_IO;
pkt->stream_index = 0;
#if 0
#endif
if (ret != pkt->size) {
av_free_packet(pkt);
- return -EIO;
+ return AVERROR_IO;
} else {
return 0;
}
.value = CODEC_ID_RAWVIDEO,
};
+#ifdef CONFIG_ENCODERS
AVOutputFormat rawvideo_oformat = {
"rawvideo",
"raw video format",
raw_write_packet,
raw_write_trailer,
};
+#endif //CONFIG_ENCODERS
-static int null_write_packet(struct AVFormatContext *s,
- int stream_index,
- const uint8_t *buf, int size, int64_t pts)
+#ifdef CONFIG_ENCODERS
+static int null_write_packet(struct AVFormatContext *s, AVPacket *pkt)
{
return 0;
}
raw_write_trailer,
.flags = AVFMT_NOFILE | AVFMT_RAWPICTURE,
};
+#endif //CONFIG_ENCODERS
+
+#ifndef CONFIG_ENCODERS
+#define av_register_output_format(format)
+#endif
+#ifndef CONFIG_DECODERS
+#define av_register_input_format(format)
+#endif
int raw_init(void)
{
+
+ av_register_input_format(&shorten_iformat);
+
av_register_input_format(&ac3_iformat);
av_register_output_format(&ac3_oformat);
+ av_register_input_format(&dts_iformat);
+
+ av_register_input_format(&h261_iformat);
+ av_register_output_format(&h261_oformat);
+
av_register_input_format(&h263_iformat);
av_register_output_format(&h263_oformat);
av_register_input_format(&mpegvideo_iformat);
av_register_output_format(&mpeg1video_oformat);
+ av_register_output_format(&mpeg2video_oformat);
+
av_register_input_format(&mjpeg_iformat);
av_register_output_format(&mjpeg_oformat);