Commit c9a65ca8 authored by Fabrice Bellard's avatar Fabrice Bellard

converted to new API

Originally committed as revision 547 to svn://svn.ffmpeg.org/ffmpeg/trunk
parent db7f1f95
......@@ -5,10 +5,13 @@ PWD=$(shell pwd)
CFLAGS= $(OPTFLAGS) -Wall -g -I.. -I$(SRC_PATH) -I$(SRC_PATH)/libavcodec -DHAVE_AV_CONFIG_H
OBJS= rm.o mpeg.o asf.o avienc.o jpeg.o swf.o wav.o raw.o \
avidec.o ffm.o \
avio.o aviobuf.o utils.o \
file.o img.o au.o gif.o mov.o crc.o
OBJS= utils.o
# mux and demuxes
OBJS+=mpeg.o mpegts.o ffm.o crc.o img.o raw.o rm.o asf.o \
avienc.o avidec.o wav.o swf.o au.o gif.o mov.o jpeg.o
# file I/O
OBJS+= avio.o aviobuf.o file.o
ifeq ($(CONFIG_GRAB),yes)
OBJS+= grab.o audio.o
......
......@@ -420,12 +420,7 @@ static int asf_write_header1(AVFormatContext *s, INT64 file_size, INT64 data_chu
static int asf_write_header(AVFormatContext *s)
{
ASFContext *asf;
asf = av_mallocz(sizeof(ASFContext));
if (!asf)
return -1;
s->priv_data = asf;
ASFContext *asf = s->priv_data;
asf->packet_size = PACKET_SIZE;
asf->nb_packets = 0;
......@@ -614,8 +609,6 @@ static int asf_write_trailer(AVFormatContext *s)
}
put_flush_packet(&s->pb);
av_free(asf);
return 0;
}
......@@ -679,9 +672,34 @@ static void get_str16_nolen(ByteIOContext *pb, int len, char *buf, int buf_size)
*q = '\0';
}
static int asf_probe(AVProbeData *pd)
{
GUID g;
const unsigned char *p;
int i;
/* check file header */
if (pd->buf_size <= 32)
return 0;
p = pd->buf;
g.v1 = p[0] | (p[1] << 8) | (p[2] << 16) | (p[3] << 24);
p += 4;
g.v2 = p[0] | (p[1] << 8);
p += 2;
g.v3 = p[0] | (p[1] << 8);
p += 2;
for(i=0;i<8;i++)
g.v4[i] = *p++;
if (!memcmp(&g, &asf_header, sizeof(GUID)))
return AVPROBE_SCORE_MAX;
else
return 0;
}
static int asf_read_header(AVFormatContext *s, AVFormatParameters *ap)
{
ASFContext *asf;
ASFContext *asf = s->priv_data;
GUID g;
ByteIOContext *pb = &s->pb;
AVStream *st;
......@@ -689,11 +707,6 @@ static int asf_read_header(AVFormatContext *s, AVFormatParameters *ap)
int size, i, bps;
INT64 gsize;
asf = av_mallocz(sizeof(ASFContext));
if (!asf)
return -1;
s->priv_data = asf;
get_guid(pb, &g);
if (memcmp(&g, &asf_header, sizeof(GUID)))
goto fail;
......@@ -1015,11 +1028,22 @@ static int asf_read_close(AVFormatContext *s)
return 0;
}
AVFormat asf_format = {
AVInputFormat asf_iformat = {
"asf",
"asf format",
sizeof(ASFContext),
asf_probe,
asf_read_header,
asf_read_packet,
asf_read_close,
};
AVOutputFormat asf_oformat = {
"asf",
"asf format",
"application/octet-stream",
"asf,wmv",
sizeof(ASFContext),
#ifdef CONFIG_MP3LAME
CODEC_ID_MP3LAME,
#else
......@@ -1029,8 +1053,11 @@ AVFormat asf_format = {
asf_write_header,
asf_write_packet,
asf_write_trailer,
asf_read_header,
asf_read_packet,
asf_read_close,
};
int asf_init(void)
{
av_register_input_format(&asf_iformat);
av_register_output_format(&asf_oformat);
return 0;
}
......@@ -99,6 +99,18 @@ static int au_write_trailer(AVFormatContext *s)
return 0;
}
static int au_probe(AVProbeData *p)
{
/* check file header */
if (p->buf_size <= 24)
return 0;
if (p->buf[0] == '.' && p->buf[1] == 's' &&
p->buf[2] == 'n' && p->buf[3] == 'd')
return AVPROBE_SCORE_MAX;
else
return 0;
}
/* au input */
static int au_read_header(AVFormatContext *s,
AVFormatParameters *ap)
......@@ -175,18 +187,32 @@ static int au_read_close(AVFormatContext *s)
return 0;
}
AVFormat au_format = {
static AVInputFormat au_iformat = {
"au",
"SUN AU Format",
0,
au_probe,
au_read_header,
au_read_packet,
au_read_close,
};
static AVOutputFormat au_oformat = {
"au",
"SUN AU Format",
"audio/basic",
"au",
0,
CODEC_ID_PCM_S16BE,
CODEC_ID_NONE,
au_write_header,
au_write_packet,
au_write_trailer,
au_read_header,
au_read_packet,
au_read_close,
};
int au_init(void)
{
av_register_input_format(&au_iformat);
av_register_output_format(&au_oformat);
return 0;
}
......@@ -147,21 +147,15 @@ static int audio_close(AudioData *s)
/* sound output support */
static int audio_write_header(AVFormatContext *s1)
{
AudioData *s;
AudioData *s = s1->priv_data;
AVStream *st;
int ret;
s = av_mallocz(sizeof(AudioData));
if (!s)
return -ENOMEM;
s1->priv_data = s;
st = s1->streams[0];
s->sample_rate = st->codec.sample_rate;
s->channels = st->codec.channels;
ret = audio_open(s, 1);
if (ret < 0) {
av_free(s);
return -EIO;
} else {
return 0;
......@@ -201,7 +195,6 @@ static int audio_write_trailer(AVFormatContext *s1)
AudioData *s = s1->priv_data;
audio_close(s);
av_free(s);
return 0;
}
......@@ -209,31 +202,23 @@ static int audio_write_trailer(AVFormatContext *s1)
static int audio_read_header(AVFormatContext *s1, AVFormatParameters *ap)
{
AudioData *s;
AudioData *s = s1->priv_data;
AVStream *st;
int ret;
if (!ap || ap->sample_rate <= 0 || ap->channels <= 0)
return -1;
s = av_mallocz(sizeof(AudioData));
if (!s)
return -ENOMEM;
st = av_mallocz(sizeof(AVStream));
st = av_new_stream(s1, 0);
if (!st) {
av_free(s);
return -ENOMEM;
}
s1->priv_data = s;
s1->nb_streams = 1;
s1->streams[0] = st;
s->sample_rate = ap->sample_rate;
s->channels = ap->channels;
ret = audio_open(s, 0);
if (ret < 0) {
av_free(st);
av_free(s);
return -EIO;
} else {
/* take real parameters */
......@@ -284,15 +269,26 @@ static int audio_read_close(AVFormatContext *s1)
AudioData *s = s1->priv_data;
audio_close(s);
av_free(s);
return 0;
}
AVFormat audio_device_format = {
AVInputFormat audio_in_format = {
"audio_device",
"audio grab and output",
sizeof(AudioData),
NULL,
audio_read_header,
audio_read_packet,
audio_read_close,
flags: AVFMT_NOFILE,
};
AVOutputFormat audio_out_format = {
"audio_device",
"audio grab and output",
"",
"",
sizeof(AudioData),
/* XXX: we make the assumption that the soundcard accepts this format */
/* XXX: find better solution with "preinit" method, needed also in
other formats */
......@@ -305,10 +301,12 @@ AVFormat audio_device_format = {
audio_write_header,
audio_write_packet,
audio_write_trailer,
audio_read_header,
audio_read_packet,
audio_read_close,
NULL,
AVFMT_NOFILE,
flags: AVFMT_NOFILE,
};
int audio_init(void)
{
av_register_input_format(&audio_in_format);
av_register_output_format(&audio_out_format);
return 0;
}
......@@ -23,8 +23,3 @@ extern CodecTag codec_wav_tags[];
unsigned int codec_get_tag(const CodecTag *tags, int id);
int codec_get_id(const CodecTag *tags, unsigned int tag);
/* avidec.c */
int avi_read_header(AVFormatContext *s, AVFormatParameters *ap);
int avi_read_packet(AVFormatContext *s, AVPacket *pkt);
int avi_read_close(AVFormatContext *s);
......@@ -47,19 +47,13 @@ void print_tag(const char *str, unsigned int tag, int size)
int avi_read_header(AVFormatContext *s, AVFormatParameters *ap)
{
AVIContext *avi;
AVIContext *avi = s->priv_data;
ByteIOContext *pb = &s->pb;
UINT32 tag, tag1;
int codec_type, stream_index, size, frame_period, bit_rate;
int i, bps;
AVStream *st;
avi = av_malloc(sizeof(AVIContext));
if (!avi)
return -1;
memset(avi, 0, sizeof(AVIContext));
s->priv_data = avi;
/* check RIFF header */
tag = get_le32(pb);
......@@ -246,7 +240,35 @@ int avi_read_packet(AVFormatContext *s, AVPacket *pkt)
int avi_read_close(AVFormatContext *s)
{
AVIContext *avi = s->priv_data;
av_free(avi);
return 0;
}
static int avi_probe(AVProbeData *p)
{
/* check file header */
if (p->buf_size <= 32)
return 0;
if (p->buf[0] == 'R' && p->buf[1] == 'I' &&
p->buf[2] == 'F' && p->buf[3] == 'F' &&
p->buf[8] == 'A' && p->buf[9] == 'V' &&
p->buf[10] == 'I' && p->buf[11] == ' ')
return AVPROBE_SCORE_MAX;
else
return 0;
}
static AVInputFormat avi_iformat = {
"avi",
"avi format",
sizeof(AVIContext),
avi_probe,
avi_read_header,
avi_read_packet,
avi_read_close,
};
int avidec_init(void)
{
av_register_input_format(&avi_iformat);
return 0;
}
......@@ -143,18 +143,12 @@ void parse_specific_params(AVCodecContext *stream, int *au_byterate, int *au_ssi
static int avi_write_header(AVFormatContext *s)
{
AVIContext *avi;
AVIContext *avi = s->priv_data;
ByteIOContext *pb = &s->pb;
int bitrate, n, i, nb_frames, au_byterate, au_ssize, au_scale;
AVCodecContext *stream, *video_enc;
offset_t list1, list2, strh, strf;
avi = av_malloc(sizeof(AVIContext));
if (!avi)
return -1;
memset(avi, 0, sizeof(AVIContext));
s->priv_data = avi;
put_tag(pb, "RIFF");
put_le32(pb, 0); /* file length */
put_tag(pb, "AVI ");
......@@ -388,23 +382,24 @@ static int avi_write_trailer(AVFormatContext *s)
url_fseek(pb, file_size, SEEK_SET);
}
put_flush_packet(pb);
av_free(avi);
return 0;
}
AVFormat avi_format = {
static AVOutputFormat avi_oformat = {
"avi",
"avi format",
"video/x-msvideo",
"avi",
sizeof(AVIContext),
CODEC_ID_MP2,
CODEC_ID_MSMPEG4,
avi_write_header,
avi_write_packet,
avi_write_trailer,
avi_read_header,
avi_read_packet,
avi_read_close,
};
int avienc_init(void)
{
av_register_output_format(&avi_oformat);
return 0;
}
......@@ -105,14 +105,6 @@ offset_t url_seek(URLContext *h, offset_t pos, int whence)
return ret;
}
int url_getformat(URLContext *h, URLFormat *f)
{
memset(f, 0, sizeof(*f));
if (!h->prot->url_getformat)
return -ENODATA;
return h->prot->url_getformat(h, f);
}
int url_close(URLContext *h)
{
int ret;
......
......@@ -12,16 +12,6 @@ struct URLContext {
void *priv_data;
};
typedef struct URLFormat {
char format_name[32];
int sample_rate;
int frame_rate;
int channels;
int height;
int width;
enum PixelFormat pix_fmt;
} URLFormat;
typedef struct URLContext URLContext;
typedef struct URLPollEntry {
......@@ -36,7 +26,6 @@ int url_open(URLContext **h, const char *filename, int flags);
int url_read(URLContext *h, unsigned char *buf, int size);
int url_write(URLContext *h, unsigned char *buf, int size);
offset_t url_seek(URLContext *h, offset_t pos, int whence);
int url_getformat(URLContext *h, URLFormat *f);
int url_close(URLContext *h);
int url_exist(const char *filename);
offset_t url_filesize(URLContext *h);
......@@ -50,9 +39,6 @@ typedef struct URLProtocol {
int (*url_write)(URLContext *h, unsigned char *buf, int size);
offset_t (*url_seek)(URLContext *h, offset_t pos, int whence);
int (*url_close)(URLContext *h);
/* get precise information about the format, if available. return
-ENODATA if not available */
int (*url_getformat)(URLContext *h, URLFormat *f);
struct URLProtocol *next;
} URLProtocol;
......
......@@ -61,14 +61,9 @@ typedef struct CRCState {
UINT32 crcval;
} CRCState;
/* simple formats */
static int crc_write_header(struct AVFormatContext *s)
{
CRCState *crc;
crc = av_malloc(sizeof(CRCState));
if (!crc)
return -1;
s->priv_data = crc;
CRCState *crc = s->priv_data;
/* init CRC */
crc->crcval = adler32(0, NULL, 0);
......@@ -93,18 +88,24 @@ static int crc_write_trailer(struct AVFormatContext *s)
snprintf(buf, sizeof(buf), "CRC=%08x\n", crc->crcval);
put_buffer(&s->pb, buf, strlen(buf));
put_flush_packet(&s->pb);
av_free(crc);
return 0;
}
AVFormat crc_format = {
AVOutputFormat crc_format = {
"crc",
"crc testing format",
NULL,
"",
sizeof(CRCState),
CODEC_ID_PCM_S16LE,
CODEC_ID_RAWVIDEO,
crc_write_header,
crc_write_packet,
crc_write_trailer,
};
int crc_init(void)
{
av_register_output_format(&crc_format);
return 0;
}
......@@ -51,6 +51,9 @@ typedef struct FFMContext {
UINT8 packet[1]; /* must be last */
} FFMContext;
/* disable pts hack for testing */
int ffm_nopts = 0;
static void flush_packet(AVFormatContext *s)
{
FFMContext *ffm = s->priv_data;
......@@ -112,18 +115,13 @@ static void ffm_write_data(AVFormatContext *s,
static int ffm_write_header(AVFormatContext *s)
{
FFMContext *ffm = s->priv_data;
AVStream *st;
FFMStream *fst;
FFMContext *ffm;
ByteIOContext *pb = &s->pb;
AVCodecContext *codec;
int bit_rate, i;
ffm = av_mallocz(sizeof(FFMContext) + FFM_PACKET_SIZE);
if (!ffm)
return -1;
s->priv_data = ffm;
ffm->packet_size = FFM_PACKET_SIZE;
/* header */
......@@ -177,6 +175,9 @@ static int ffm_write_header(AVFormatContext *s)
abort();
}
/* hack to have real time */
if (ffm_nopts)
fst->pts = 0;
else
fst->pts = gettime();
}
......@@ -200,7 +201,6 @@ static int ffm_write_header(AVFormatContext *s)
fst = st->priv_data;
av_free(fst);
}
av_free(ffm);
return -1;
}
......@@ -252,7 +252,6 @@ static int ffm_write_trailer(AVFormatContext *s)
for(i=0;i<s->nb_streams;i++)
av_free(s->streams[i]->priv_data);
av_free(ffm);
return 0;
}
......@@ -342,20 +341,14 @@ static int ffm_read_data(AVFormatContext *s,
static int ffm_read_header(AVFormatContext *s, AVFormatParameters *ap)
{
FFMContext *ffm = s->priv_data;
AVStream *st;
FFMStream *fst;
FFMContext *ffm;
ByteIOContext *pb = &s->pb;
AVCodecContext *codec;
int i;
UINT32 tag;
ffm = av_mallocz(sizeof(FFMContext) + FFM_PACKET_SIZE);
if (!ffm)
return -1;
s->priv_data = ffm;
/* header */
tag = get_le32(pb);
if (tag != MKTAG('F', 'F', 'M', '1'))
......@@ -436,8 +429,6 @@ static int ffm_read_header(AVFormatContext *s, AVFormatParameters *ap)
av_free(st);
}
}
if (ffm)
av_free(ffm);
return -1;
}
......@@ -619,19 +610,35 @@ static int ffm_read_close(AVFormatContext *s)
return 0;
}
AVFormat ffm_format = {
AVInputFormat ffm_iformat = {
"ffm",
"ffm format",
sizeof(FFMContext),
NULL,
ffm_read_header,
ffm_read_packet,
ffm_read_close,
ffm_seek,
extensions: "ffm",
};
AVOutputFormat ffm_oformat = {
"ffm",
"ffm format",
"",
"ffm",
sizeof(FFMContext) + FFM_PACKET_SIZE,
/* not really used */
CODEC_ID_MP2,
CODEC_ID_MPEG1VIDEO,
ffm_write_header,
ffm_write_packet,
ffm_write_trailer,
ffm_read_header,
ffm_read_packet,
ffm_read_close,
ffm_seek,
};
int ffm_init(void)
{
av_register_input_format(&ffm_iformat);
av_register_output_format(&ffm_oformat);
return 0;
}
......@@ -192,7 +192,7 @@ typedef struct {
static int gif_write_header(AVFormatContext *s)
{
GIFContext *gif;
GIFContext *gif = s->priv_data;
ByteIOContext *pb = &s->pb;
AVCodecContext *enc, *video_enc;
int i, width, height, rate;
......@@ -201,12 +201,6 @@ static int gif_write_header(AVFormatContext *s)
if(s->nb_streams > 1)
return -1;
*/
gif = av_malloc(sizeof(GIFContext));
if (!gif)
return -1;
s->priv_data = gif;
gif->time = 0;
gif->file_time = 0;
......@@ -376,28 +370,28 @@ static int gif_write_packet(AVFormatContext *s, int stream_index,
static int gif_write_trailer(AVFormatContext *s)
{
GIFContext *gif = s->priv_data;
ByteIOContext *pb = &s->pb;
put_byte(pb, 0x3b);
put_flush_packet(&s->pb);
av_free(gif);
return 0;
}
AVFormat gif_format = {
static AVOutputFormat gif_oformat = {
"gif",
"GIF Animation",
"image/gif",
"gif",
sizeof(GIFContext),
CODEC_ID_NONE,
CODEC_ID_RAWVIDEO,
gif_write_header,
gif_write_packet,
gif_write_trailer,
NULL, /* read_header */
NULL, /* read_packet */
NULL, /* read_close */
};
int gif_init(void)
{
av_register_output_format(&gif_oformat);
return 0;
}
......@@ -48,7 +48,7 @@ static int gb_frame = 0;
static int grab_read_header(AVFormatContext *s1, AVFormatParameters *ap)
{
VideoData *s;
VideoData *s = s1->priv_data;
AVStream *st;
int width, height;
int video_fd, frame_size;
......@@ -62,17 +62,9 @@ static int grab_read_header(AVFormatContext *s1, AVFormatParameters *ap)
height = ap->height;
frame_rate = ap->frame_rate;
s = av_mallocz(sizeof(VideoData));
if (!s)
return -ENOMEM;
st = av_mallocz(sizeof(AVStream));
if (!st) {
av_free(s);
st = av_new_stream(s1, 0);
if (!st)
return -ENOMEM;
}
s1->priv_data = s;
s1->nb_streams = 1;
s1->streams[0] = st;
s->width = width;
s->height = height;
......@@ -232,7 +224,6 @@ static int grab_read_header(AVFormatContext *s1, AVFormatParameters *ap)
if (video_fd >= 0)
close(video_fd);
av_free(st);
av_free(s);
return -EIO;
}
......@@ -327,24 +318,22 @@ static int grab_read_close(AVFormatContext *s1)
ioctl(s->fd, VIDIOCSAUDIO, &audio_saved);
close(s->fd);
av_free(s);
return 0;
}
AVFormat video_grab_device_format = {
AVInputFormat video_grab_device_format = {
"video_grab_device",
"video grab",
"",
"",
CODEC_ID_NONE,
CODEC_ID_NONE,
sizeof(VideoData),
NULL,
NULL,
NULL,
grab_read_header,
grab_read_packet,
grab_read_close,
NULL,
AVFMT_NOFILE,
flags: AVFMT_NOFILE,
};
int video_grab_init(void)
{
av_register_input_format(&video_grab_device_format);
return 0;
}
/*
* Image format
* Copyright (c) 2000, 2001 Gerard Lantau.
* Copyright (c) 2000, 2001, 2002 Gerard Lantau.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
......@@ -18,6 +18,21 @@
*/
#include "avformat.h"
extern AVInputFormat pgm_iformat;
extern AVOutputFormat pgm_oformat;
extern AVInputFormat pgmyuv_iformat;
extern AVOutputFormat pgmyuv_oformat;
extern AVInputFormat ppm_iformat;
extern AVOutputFormat ppm_oformat;
extern AVInputFormat imgyuv_iformat;
extern AVOutputFormat imgyuv_oformat;
extern AVInputFormat pgmpipe_iformat;
extern AVOutputFormat pgmpipe_oformat;
extern AVInputFormat pgmyuvpipe_iformat;
extern AVOutputFormat pgmyuvpipe_oformat;
extern AVInputFormat ppmpipe_iformat;
extern AVOutputFormat ppmpipe_oformat;
#define IMGFMT_YUV 1
#define IMGFMT_PGMYUV 2
#define IMGFMT_PGM 3
......@@ -248,46 +263,38 @@ static int infer_size(int *width_ptr, int *height_ptr, int size)
static int img_read_header(AVFormatContext *s1, AVFormatParameters *ap)
{
VideoData *s;
VideoData *s = s1->priv_data;
int i, h;
char buf[1024];
char buf1[32];
ByteIOContext pb1, *f = &pb1;
AVStream *st;
s = av_malloc(sizeof(VideoData));
if (!s)
return -ENOMEM;
s1->priv_data = s;
s1->nb_streams = 1;
st = av_mallocz(sizeof(AVStream));
st = av_new_stream(s1, 0);
if (!st) {
av_free(s);
return -ENOMEM;
}
s1->streams[0] = st;
strcpy(s->path, s1->filename);
s->img_number = 0;
/* find format */
if (s1->format->flags & AVFMT_NOFILE)
if (s1->iformat->flags & AVFMT_NOFILE)
s->is_pipe = 0;
else
s->is_pipe = 1;
if (s1->format == &pgmyuvpipe_format ||
s1->format == &pgmyuv_format)
if (s1->iformat == &pgmyuvpipe_iformat ||
s1->iformat == &pgmyuv_iformat)
s->img_fmt = IMGFMT_PGMYUV;
else if (s1->format == &pgmpipe_format ||
s1->format == &pgm_format)
else if (s1->iformat == &pgmpipe_iformat ||
s1->iformat == &pgm_iformat)
s->img_fmt = IMGFMT_PGM;
else if (s1->format == &imgyuv_format)
else if (s1->iformat == &imgyuv_iformat)
s->img_fmt = IMGFMT_YUV;
else if (s1->format == &ppmpipe_format ||
s1->format == &ppm_format)
else if (s1->iformat == &ppmpipe_iformat ||
s1->iformat == &ppm_iformat)
s->img_fmt = IMGFMT_PPM;
else
goto fail;
......@@ -378,8 +385,6 @@ static int img_read_header(AVFormatContext *s1, AVFormatParameters *ap)
static int img_read_close(AVFormatContext *s1)
{
VideoData *s = s1->priv_data;
av_free(s);
return 0;
}
......@@ -479,31 +484,27 @@ static int yuv_save(AVPicture *picture, int width, int height, const char *filen
static int img_write_header(AVFormatContext *s)
{
VideoData *img;
VideoData *img = s->priv_data;
img = av_mallocz(sizeof(VideoData));
if (!img)
return -1;
s->priv_data = img;
img->img_number = 1;
strcpy(img->path, s->filename);
/* find format */
if (s->format->flags & AVFMT_NOFILE)
if (s->oformat->flags & AVFMT_NOFILE)
img->is_pipe = 0;
else
img->is_pipe = 1;
if (s->format == &pgmyuvpipe_format ||
s->format == &pgmyuv_format) {
if (s->oformat == &pgmyuvpipe_oformat ||
s->oformat == &pgmyuv_oformat) {
img->img_fmt = IMGFMT_PGMYUV;
} else if (s->format == &pgmpipe_format ||
s->format == &pgm_format) {
} else if (s->oformat == &pgmpipe_oformat ||
s->oformat == &pgm_oformat) {
img->img_fmt = IMGFMT_PGM;
} else if (s->format == &imgyuv_format) {
} else if (s->oformat == &imgyuv_oformat) {
img->img_fmt = IMGFMT_YUV;
} else if (s->format == &ppmpipe_format ||
s->format == &ppm_format) {
} else if (s->oformat == &ppmpipe_oformat ||
s->oformat == &ppm_oformat) {
img->img_fmt = IMGFMT_PPM;
} else {
goto fail;
......@@ -590,22 +591,41 @@ static int img_write_packet(AVFormatContext *s, int stream_index,
static int img_write_trailer(AVFormatContext *s)
{
VideoData *img = s->priv_data;
av_free(img);
return 0;
}
AVFormat pgm_format = {
AVInputFormat pgm_iformat = {
"pgm",
"pgm image format",
sizeof(VideoData),
NULL,
img_read_header,
img_read_packet,
img_read_close,
NULL,
AVFMT_NOFILE | AVFMT_NEEDNUMBER,
extensions: "pgm",
};
AVOutputFormat pgm_oformat = {
"pgm",
"pgm image format",
"",
"pgm",
sizeof(VideoData),
CODEC_ID_NONE,
CODEC_ID_RAWVIDEO,
img_write_header,
img_write_packet,
img_write_trailer,
AVFMT_NOFILE | AVFMT_NEEDNUMBER,
};
AVInputFormat pgmyuv_iformat = {
"pgmyuv",
"pgm with YUV content image format",
sizeof(VideoData),
NULL, /* no probe */
img_read_header,
img_read_packet,
img_read_close,
......@@ -613,107 +633,170 @@ AVFormat pgm_format = {
AVFMT_NOFILE | AVFMT_NEEDNUMBER,
};
AVFormat pgmyuv_format = {
AVOutputFormat pgmyuv_oformat = {
"pgmyuv",
"pgm with YUV content image format",
"",
"pgm",
sizeof(VideoData),
CODEC_ID_NONE,
CODEC_ID_RAWVIDEO,
img_write_header,
img_write_packet,
img_write_trailer,
AVFMT_NOFILE | AVFMT_NEEDNUMBER,
};
AVInputFormat ppm_iformat = {
"ppm",
"ppm image format",
sizeof(VideoData),
NULL,
img_read_header,
img_read_packet,
img_read_close,
NULL,
AVFMT_NOFILE | AVFMT_NEEDNUMBER,
AVFMT_NOFILE | AVFMT_NEEDNUMBER | AVFMT_RGB24,
extensions: "ppm",
};
AVFormat ppm_format = {
AVOutputFormat ppm_oformat = {
"ppm",
"ppm image format",
"",
"ppm",
sizeof(VideoData),
CODEC_ID_NONE,
CODEC_ID_RAWVIDEO,
img_write_header,
img_write_packet,
img_write_trailer,
AVFMT_NOFILE | AVFMT_NEEDNUMBER | AVFMT_RGB24,
};
AVInputFormat imgyuv_iformat = {
".Y.U.V",
".Y.U.V format",
sizeof(VideoData),
NULL,
img_read_header,
img_read_packet,
img_read_close,
NULL,
AVFMT_NOFILE | AVFMT_NEEDNUMBER,
extensions: "Y",
};
AVFormat imgyuv_format = {
AVOutputFormat imgyuv_oformat = {
".Y.U.V",
".Y.U.V format",
"",
"Y",
sizeof(VideoData),
CODEC_ID_NONE,
CODEC_ID_RAWVIDEO,
img_write_header,
img_write_packet,
img_write_trailer,
AVFMT_NOFILE | AVFMT_NEEDNUMBER,
};
AVInputFormat pgmpipe_iformat = {
"pgmpipe",
"PGM pipe format",
sizeof(VideoData),
NULL, /* no probe */
img_read_header,
img_read_packet,
img_read_close,
NULL,
AVFMT_NOFILE | AVFMT_NEEDNUMBER,
};
AVFormat pgmpipe_format = {
AVOutputFormat pgmpipe_oformat = {
"pgmpipe",
"PGM pipe format",
"",
"pgm",
sizeof(VideoData),
CODEC_ID_NONE,
CODEC_ID_RAWVIDEO,
img_write_header,
img_write_packet,
img_write_trailer,
};
AVInputFormat pgmyuvpipe_iformat = {
"pgmyuvpipe",
"PGM YUV pipe format",
sizeof(VideoData),
NULL, /* no probe */
img_read_header,
img_read_packet,
img_read_close,
NULL,
};
AVFormat pgmyuvpipe_format = {
AVOutputFormat pgmyuvpipe_oformat = {
"pgmyuvpipe",
"PGM YUV pipe format",
"",
"pgm",
sizeof(VideoData),
CODEC_ID_NONE,
CODEC_ID_RAWVIDEO,
img_write_header,
img_write_packet,
img_write_trailer,
};
AVInputFormat ppmpipe_iformat = {
"ppmpipe",
"PPM pipe format",
sizeof(VideoData),
NULL, /* no probe */
img_read_header,
img_read_packet,
img_read_close,
NULL,
flags: AVFMT_RGB24,
};
AVFormat ppmpipe_format = {
AVOutputFormat ppmpipe_oformat = {
"ppmpipe",
"PPM pipe format",
"",
"ppm",
sizeof(VideoData),
CODEC_ID_NONE,
CODEC_ID_RAWVIDEO,
img_write_header,
img_write_packet,
img_write_trailer,
img_read_header,
img_read_packet,
img_read_close,
NULL,
flags: AVFMT_RGB24,
};
int img_init(void)
{
av_register_input_format(&pgm_iformat);
av_register_output_format(&pgm_oformat);
av_register_input_format(&pgmyuv_iformat);
av_register_output_format(&pgmyuv_oformat);
av_register_input_format(&ppm_iformat);
av_register_output_format(&ppm_oformat);
av_register_input_format(&imgyuv_iformat);
av_register_output_format(&imgyuv_oformat);
av_register_input_format(&pgmpipe_iformat);
av_register_output_format(&pgmpipe_oformat);
av_register_input_format(&pgmyuvpipe_iformat);
av_register_output_format(&pgmyuvpipe_oformat);
av_register_input_format(&ppmpipe_iformat);
av_register_output_format(&ppmpipe_oformat);
return 0;
}
......@@ -52,11 +52,12 @@ static int mpjpeg_write_trailer(AVFormatContext *s)
return 0;
}
AVFormat mpjpeg_format = {
static AVOutputFormat mpjpeg_format = {
"mpjpeg",
"Mime multipart JPEG format",
"multipart/x-mixed-replace;boundary=" BOUNDARY_TAG,
"mjpg",
0,
CODEC_ID_NONE,
CODEC_ID_MJPEG,
mpjpeg_write_header,
......@@ -86,11 +87,12 @@ static int single_jpeg_write_trailer(AVFormatContext *s)
return 0;
}
AVFormat single_jpeg_format = {
static AVOutputFormat single_jpeg_format = {
"singlejpeg",
"single JPEG image",
"image/jpeg",
"jpg,jpeg",
0,
CODEC_ID_NONE,
CODEC_ID_MJPEG,
single_jpeg_write_header,
......@@ -114,7 +116,7 @@ static int jpeg_write_header(AVFormatContext *s1)
if (!s)
return -1;
s1->priv_data = s;
nstrcpy(s->path, sizeof(s->path), s1->filename);
pstrcpy(s->path, sizeof(s->path), s1->filename);
s->img_number = 1;
return 0;
}
......@@ -162,7 +164,7 @@ static int jpeg_read_header(AVFormatContext *s1, AVFormatParameters *ap)
if (!s)
return -1;
s1->priv_data = s;
nstrcpy(s->path, sizeof(s->path), s1->filename);
pstrcpy(s->path, sizeof(s->path), s1->filename);
s1->nb_streams = 1;
st = av_mallocz(sizeof(AVStream));
......@@ -231,20 +233,38 @@ static int jpeg_read_close(AVFormatContext *s1)
return 0;
}
AVFormat jpeg_format = {
static AVInputFormat jpeg_iformat = {
"jpeg",
"JPEG image",
sizeof(JpegContext),
NULL,
jpeg_read_header,
jpeg_read_packet,
jpeg_read_close,
NULL,
flags: AVFMT_NOFILE | AVFMT_NEEDNUMBER,
extensions: "jpg,jpeg",
};
static AVOutputFormat jpeg_oformat = {
"jpeg",
"JPEG image",
"image/jpeg",
"jpg,jpeg",
sizeof(JpegContext),
CODEC_ID_NONE,
CODEC_ID_MJPEG,
jpeg_write_header,
jpeg_write_packet,
jpeg_write_trailer,
jpeg_read_header,
jpeg_read_packet,
jpeg_read_close,
NULL,
AVFMT_NOFILE | AVFMT_NEEDNUMBER,
flags: AVFMT_NOFILE | AVFMT_NEEDNUMBER,
};
int jpeg_init(void)
{
av_register_output_format(&mpjpeg_format);
av_register_output_format(&single_jpeg_format);
av_register_input_format(&jpeg_iformat);
av_register_output_format(&jpeg_oformat);
return 0;
}
......@@ -44,7 +44,7 @@
* QuickTime is a trademark of Apple (AFAIK :))
*/
#define DEBUG
//#define DEBUG
#ifdef DEBUG
/*
......@@ -394,7 +394,7 @@ static int parse_hdlr(const MOVParseTableEntry *parse_table, ByteIOContext *pb,
{
MOVContext *c;
int len;
char *buf, ch;
char *buf;
UINT32 type;
AVStream *st;
UINT32 ctype;
......@@ -453,21 +453,23 @@ static int parse_hdlr(const MOVParseTableEntry *parse_table, ByteIOContext *pb,
return 0; /* nothing left to read */
/* XXX: MP4 uses a C string, not a pascal one */
/* component name */
if(c->mp4) {
#ifdef DEBUG
puts("MP4!!!");
#endif
while ((ch = get_byte(pb)));
} else {
len = get_byte(pb);
if(len) {
/* XXX: use a better heuristic */
if(len < 32) {
/* assume that it is a Pascal like string */
buf = av_malloc(len+1);
get_buffer(pb, buf, len);
buf[len] = '\0';
#ifdef DEBUG
puts(buf);
printf("**buf='%s'\n", buf);
#endif
av_free(buf);
} else {
/* MP4 string */
for(;;) {
if (len == 0)
break;
len = get_byte(pb);
}
}
......@@ -763,21 +765,34 @@ static void mov_free_stream_context(MOVStreamContext *sc)
}
}
/* XXX: is it suffisant ? */
static int mov_probe(AVProbeData *p)
{
/* check file header */
if (p->buf_size <= 12)
return 0;
if ((p->buf[4] == 'm' && p->buf[5] == 'o' &&
p->buf[6] == 'o' && p->buf[7] == 'v') ||
(p->buf[4] == 'm' && p->buf[5] == 'd' &&
p->buf[6] == 'a' && p->buf[7] == 't'))
return AVPROBE_SCORE_MAX;
else
return 0;
}
static int mov_read_header(AVFormatContext *s, AVFormatParameters *ap)
{
MOVContext *mov;
MOVContext *mov = s->priv_data;
ByteIOContext *pb = &s->pb;
int i, j, nb, err;
INT64 size;
mov = av_mallocz(sizeof(MOVContext));
if (!mov)
return -1;
s->priv_data = mov;
mov->fc = s;
if(s->format->name[1] == 'p')
#if 0
/* XXX: I think we should auto detect */
if(s->iformat->name[1] == 'p')
mov->mp4 = 1;
#endif
if(!url_is_streamed(pb)) /* .mov and .mp4 aren't streamable anyway (only progressive download if moov is before mdat) */
size = url_filesize(url_fileno(pb));
else
......@@ -916,38 +931,21 @@ static int mov_read_close(AVFormatContext *s)
mov_free_stream_context(mov->streams[i]);
for(i=0; i<s->nb_streams; i++)
av_free(s->streams[i]);
av_free(mov);
return 0;
}
AVFormat mov_format = {
static AVInputFormat mov_iformat = {
"mov",
"QuickTime format",
"video/quicktime",
"mov",
CODEC_ID_MP2,
CODEC_ID_MJPEG,
NULL,
NULL,
NULL,
"QuickTime/MPEG4 format",
sizeof(MOVContext),
mov_probe,
mov_read_header,
mov_read_packet,
mov_read_close,
};
AVFormat mp4_format = {
"mp4",
"MPEG4 file format",
"video/mpeg4",
"mp4",
CODEC_ID_MP2,
CODEC_ID_MJPEG,
NULL,
NULL,
NULL,
mov_read_header,
mov_read_packet,
mov_read_close,
};
int mov_init(void)
{
av_register_input_format(&mov_iformat);
return 0;
}
This diff is collapsed.
......@@ -281,17 +281,11 @@ static void write_packet_header(AVFormatContext *ctx, StreamInfo *stream,
static int rm_write_header(AVFormatContext *s)
{
RMContext *rm = s->priv_data;
StreamInfo *stream;
RMContext *rm;
int n;
AVCodecContext *codec;
rm = av_malloc(sizeof(RMContext));
if (!rm)
return -1;
memset(rm, 0, sizeof(RMContext));
s->priv_data = rm;
for(n=0;n<s->nb_streams;n++) {
s->streams[n]->id = n;
codec = &s->streams[n]->codec;
......@@ -438,8 +432,6 @@ static int rm_write_trailer(AVFormatContext *s)
put_be32(pb, 0);
}
put_flush_packet(pb);
av_free(rm);
return 0;
}
......@@ -475,7 +467,7 @@ static void get_str8(ByteIOContext *pb, char *buf, int buf_size)
static int rm_read_header(AVFormatContext *s, AVFormatParameters *ap)
{
RMContext *rm;
RMContext *rm = s->priv_data;
AVStream *st;
ByteIOContext *pb = &s->pb;
unsigned int tag, v;
......@@ -487,10 +479,6 @@ static int rm_read_header(AVFormatContext *s, AVFormatParameters *ap)
if (get_le32(pb) != MKTAG('.', 'R', 'M', 'F'))
return -EIO;
rm = av_mallocz(sizeof(RMContext));
if (!rm)
return -ENOMEM;
s->priv_data = rm;
get_be32(pb); /* header size */
get_be16(pb);
......@@ -579,7 +567,7 @@ static int rm_read_header(AVFormatContext *s, AVFormatParameters *ap)
st->codec.codec_id = CODEC_ID_AC3;
} else {
st->codec.codec_id = CODEC_ID_NONE;
nstrcpy(st->codec.codec_name, sizeof(st->codec.codec_name),
pstrcpy(st->codec.codec_name, sizeof(st->codec.codec_name),
buf);
}
} else {
......@@ -706,23 +694,48 @@ static int rm_read_packet(AVFormatContext *s, AVPacket *pkt)
static int rm_read_close(AVFormatContext *s)
{
RMContext *rm = s->priv_data;
av_free(rm);
return 0;
}
AVFormat rm_format = {
static int rm_probe(AVProbeData *p)
{
/* check file header */
if (p->buf_size <= 32)
return 0;
if (p->buf[0] == '.' && p->buf[1] == 'R' &&
p->buf[2] == 'M' && p->buf[3] == 'F' &&
p->buf[4] == 0 && p->buf[5] == 0)
return AVPROBE_SCORE_MAX;
else
return 0;
}
AVInputFormat rm_iformat = {
"rm",
"rm format",
sizeof(RMContext),
rm_probe,
rm_read_header,
rm_read_packet,
rm_read_close,
};
AVOutputFormat rm_oformat = {
"rm",
"rm format",
"audio/x-pn-realaudio",
"rm,ra",
sizeof(RMContext),
CODEC_ID_AC3,
CODEC_ID_RV10,
rm_write_header,
rm_write_packet,
rm_write_trailer,
rm_read_header,
rm_read_packet,
rm_read_close,
};
int rm_init(void)
{
av_register_input_format(&rm_iformat);
av_register_output_format(&rm_oformat);
return 0;
}
......@@ -438,6 +438,19 @@ static int get_swf_tag(ByteIOContext *pb, int *len_ptr)
return tag;
}
static int swf_probe(AVProbeData *p)
{
/* check file header */
if (p->buf_size <= 16)
return 0;
if (p->buf[0] == 'F' && p->buf[1] == 'W' &&
p->buf[2] == 'S' && p->buf[3] == '\0')
return AVPROBE_SCORE_MAX;
else
return 0;
}
static int swf_read_header(AVFormatContext *s, AVFormatParameters *ap)
{
ByteIOContext *pb = &s->pb;
......@@ -528,18 +541,32 @@ static int swf_read_close(AVFormatContext *s)
return 0;
}
AVFormat swf_format = {
static AVInputFormat swf_iformat = {
"swf",
"Flash format",
0,
swf_probe,
swf_read_header,
swf_read_packet,
swf_read_close,
};
static AVOutputFormat swf_oformat = {
"swf",
"Flash format",
"application/x-shockwave-flash",
"swf",
sizeof(SWFContext),
CODEC_ID_MP2,
CODEC_ID_MJPEG,
swf_write_header,
swf_write_packet,
swf_write_trailer,
swf_read_header,
swf_read_packet,
swf_read_close,
};
int swf_init(void)
{
av_register_input_format(&swf_iformat);
av_register_output_format(&swf_oformat);
return 0;
}
......@@ -110,16 +110,10 @@ typedef struct {
static int wav_write_header(AVFormatContext *s)
{
WAVContext *wav;
WAVContext *wav = s->priv_data;
ByteIOContext *pb = &s->pb;
offset_t fmt;
wav = av_malloc(sizeof(WAVContext));
if (!wav)
return -1;
memset(wav, 0, sizeof(WAVContext));
s->priv_data = wav;
put_tag(pb, "RIFF");
put_le32(pb, 0); /* file length */
put_tag(pb, "WAVE");
......@@ -165,8 +159,6 @@ static int wav_write_trailer(AVFormatContext *s)
put_flush_packet(pb);
}
av_free(wav);
return 0;
}
......@@ -191,6 +183,20 @@ static int find_tag(ByteIOContext *pb, UINT32 tag1)
return size;
}
static int wav_probe(AVProbeData *p)
{
/* check file header */
if (p->buf_size <= 32)
return 0;
if (p->buf[0] == 'R' && p->buf[1] == 'I' &&
p->buf[2] == 'F' && p->buf[3] == 'F' &&
p->buf[8] == 'W' && p->buf[9] == 'A' &&
p->buf[10] == 'V' && p->buf[11] == 'E')
return AVPROBE_SCORE_MAX;
else
return 0;
}
/* wav input */
static int wav_read_header(AVFormatContext *s,
AVFormatParameters *ap)
......@@ -233,13 +239,9 @@ static int wav_read_header(AVFormatContext *s,
return -1;
/* now we are ready: build format streams */
st = av_malloc(sizeof(AVStream));
st = av_new_stream(s, 0);
if (!st)
return -1;
s->nb_streams = 1;
s->streams[0] = st;
st->id = 0;
return AVERROR_NOMEM;
st->codec.codec_type = CODEC_TYPE_AUDIO;
st->codec.codec_tag = id;
......@@ -280,18 +282,32 @@ static int wav_read_close(AVFormatContext *s)
return 0;
}
AVFormat wav_format = {
static AVInputFormat wav_iformat = {
"wav",
"wav format",
0,
wav_probe,
wav_read_header,
wav_read_packet,
wav_read_close,
};
static AVOutputFormat wav_oformat = {
"wav",
"wav format",
"audio/x-wav",
"wav",
sizeof(WAVContext),
CODEC_ID_PCM_S16LE,
CODEC_ID_NONE,
wav_write_header,
wav_write_packet,
wav_write_trailer,
wav_read_header,
wav_read_packet,
wav_read_close,
};
int wav_init(void)
{
av_register_input_format(&wav_iformat);
av_register_output_format(&wav_oformat);
return 0;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment