VPATH=$(SRC_PATH)
-CFLAGS= $(OPTFLAGS) -Wall -g -I. -I$(SRC_PATH) -I$(SRC_PATH)/libavcodec -I$(SRC_PATH)/libav -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -D_GNU_SOURCE
+CFLAGS= $(OPTFLAGS) -Wall -g -I. -I$(SRC_PATH) -I$(SRC_PATH)/libavcodec -I$(SRC_PATH)/libavformat -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -D_GNU_SOURCE
ifeq ($(CONFIG_DARWIN),yes)
LDFLAGS+= -g -d
FFSLDFLAGS= -Wl,-bind_at_load
endif
ifeq ($(BUILD_SHARED),yes)
-DEP_LIBS=libavcodec/libavcodec.so libav/libavformat.a
+DEP_LIBS=libavcodec/libavcodec.so libavformat/libavformat.a
else
-DEP_LIBS=libavcodec/libavcodec.a libav/libavformat.a
+DEP_LIBS=libavcodec/libavcodec.a libavformat/libavformat.a
ifeq ($(CONFIG_MP3LAME),yes)
EXTRALIBS+=-lmp3lame
endif
lib:
$(MAKE) -C libavcodec all
- $(MAKE) -C libav all
+ $(MAKE) -C libavformat all
ffmpeg_g$(EXE): ffmpeg.o $(DEP_LIBS)
- $(CC) $(LDFLAGS) -o $@ ffmpeg.o -L./libavcodec -L./libav \
+ $(CC) $(LDFLAGS) -o $@ ffmpeg.o -L./libavcodec -L./libavformat \
-lavformat -lavcodec $(EXTRALIBS)
ffmpeg$(EXE): ffmpeg_g$(EXE)
ffserver$(EXE): ffserver.o $(DEP_LIBS)
$(CC) $(LDFLAGS) $(FFSLDFLAGS) \
- -o $@ ffserver.o -L./libavcodec -L./libav \
+ -o $@ ffserver.o -L./libavcodec -L./libavformat \
-lavformat -lavcodec -ldl $(EXTRALIBS)
ffplay: ffmpeg$(EXE)
installlib:
$(MAKE) -C libavcodec installlib
- $(MAKE) -C libav installlib
+ $(MAKE) -C libavformat installlib
dep: depend
clean: $(CLEANVHOOK)
$(MAKE) -C libavcodec clean
- $(MAKE) -C libav clean
+ $(MAKE) -C libavformat clean
$(MAKE) -C tests clean
rm -f *.o *~ .depend gmon.out TAGS ffmpeg_g$(EXE) $(PROG)
rm -f config.mak config.h
TAGS:
- etags *.[ch] libav/*.[ch] libavcodec/*.[ch]
+ etags *.[ch] libavformat/*.[ch] libavcodec/*.[ch]
# regression tests
+++ /dev/null
-config.h
-config.mak
-*ffmpeg
-ffserver
-Makefile.*
-.depend
+++ /dev/null
-#
-# libavformat Makefile
-# (c) 2000, 2001, 2002 Fabrice Bellard
-#
-include ../config.mak
-
-VPATH=$(SRC_PATH)/libav
-
-CFLAGS= $(OPTFLAGS) -Wall -g -I.. -I$(SRC_PATH) -I$(SRC_PATH)/libavcodec -DHAVE_AV_CONFIG_H -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -D_GNU_SOURCE
-
-OBJS= utils.o cutils.o allformats.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 dv.o framehook.o
-# file I/O
-OBJS+= avio.o aviobuf.o file.o
-
-ifeq ($(BUILD_STRPTIME),yes)
-OBJS+= strptime.o
-endif
-
-ifeq ($(CONFIG_VIDEO4LINUX),yes)
-OBJS+= grab.o
-endif
-
-ifeq ($(CONFIG_AUDIO_OSS),yes)
-OBJS+= audio.o
-endif
-
-ifeq ($(CONFIG_AUDIO_BEOS),yes)
-OBJS+= beosaudio.o
-endif
-
-ifeq ($(CONFIG_NETWORK),yes)
-OBJS+= udp.o tcp.o http.o rtsp.o rtp.o rtpproto.o
-# BeOS network stuff
-ifeq ($(CONFIG_BEOS_NETSERVER),yes)
-OBJS+= barpainet.o
-endif
-endif
-
-ifeq ($(CONFIG_VORBIS),yes)
-OBJS+= ogg.o
-endif
-
-LIB= libavformat.a
-
-all: $(LIB)
-
-$(LIB): $(OBJS)
- rm -f $@
- $(AR) rc $@ $(OBJS)
- $(RANLIB) $@
-
-installlib: all
- install -m 644 $(LIB) $(prefix)/lib
- mkdir -p $(prefix)/include/ffmpeg
- install -m 644 $(SRC_PATH)/libav/avformat.h $(SRC_PATH)/libav/avio.h \
- $(SRC_PATH)/libav/rtp.h $(SRC_PATH)/libav/rtsp.h \
- $(SRC_PATH)/libav/rtspcodes.h \
- $(prefix)/include/ffmpeg
-
-%.o: %.c
- $(CC) $(CFLAGS) -c -o $@ $<
-
-# BeOS: remove -Wall to get rid of all the "multibyte constant" warnings
-%.o: %.cpp
- g++ $(subst -Wall,,$(CFLAGS)) -c -o $@ $<
-
-clean:
- rm -f *.o *~ *.a
+++ /dev/null
-/*
- * Register all the formats and protocols
- * Copyright (c) 2000, 2001, 2002 Fabrice Bellard
- *
- * This library 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 of the License, or (at your option) any later version.
- *
- * This library 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 this library; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
-#include "avformat.h"
-
-/* If you do not call this function, then you can select exactly which
- formats you want to support */
-
-/**
- * Initialize libavcodec and register all the codecs and formats.
- */
-void av_register_all(void)
-{
- avcodec_init();
- avcodec_register_all();
-
- mpegps_init();
- mpegts_init();
- crc_init();
- img_init();
- raw_init();
- rm_init();
- asf_init();
- avienc_init();
- avidec_init();
- wav_init();
- swf_init();
- au_init();
- gif_init();
- mov_init();
- jpeg_init();
- dv_init();
-
-#ifdef CONFIG_VORBIS
- ogg_init();
-#endif
-
-#ifndef CONFIG_WIN32
- ffm_init();
-#endif
-#ifdef CONFIG_VIDEO4LINUX
- video_grab_init();
-#endif
-#if defined(CONFIG_AUDIO_OSS) || defined(CONFIG_AUDIO_BEOS)
- audio_init();
-#endif
-
- /* file protocols */
- register_protocol(&file_protocol);
- register_protocol(&pipe_protocol);
-#ifdef CONFIG_NETWORK
- rtsp_init();
- rtp_init();
- register_protocol(&udp_protocol);
- register_protocol(&rtp_protocol);
- register_protocol(&tcp_protocol);
- register_protocol(&http_protocol);
-#endif
-}
+++ /dev/null
-/*
- * ASF compatible encoder and decoder.
- * Copyright (c) 2000, 2001 Fabrice Bellard.
- *
- * This library 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 of the License, or (at your option) any later version.
- *
- * This library 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 this library; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
-#include "avformat.h"
-#include "avi.h"
-#include "mpegaudio.h"
-
-#define PACKET_SIZE 3200
-#define PACKET_HEADER_SIZE 12
-#define FRAME_HEADER_SIZE 17
-
-typedef struct {
- int num;
- int seq;
- /* use for reading */
- AVPacket pkt;
- int frag_offset;
- int timestamp;
- INT64 duration;
-
- int ds_span; /* descrambling */
- int ds_packet_size;
- int ds_chunk_size;
- int ds_data_size;
- int ds_silence_data;
-
-} ASFStream;
-
-typedef struct {
- UINT32 v1;
- UINT16 v2;
- UINT16 v3;
- UINT8 v4[8];
-} GUID;
-
-typedef struct __attribute__((packed)) {
- GUID guid; // generated by client computer
- uint64_t file_size; // in bytes
- // invalid if broadcasting
- uint64_t create_time; // time of creation, in 100-nanosecond units since 1.1.1601
- // invalid if broadcasting
- uint64_t packets_count; // how many packets are there in the file
- // invalid if broadcasting
- uint64_t play_time; // play time, in 100-nanosecond units
- // invalid if broadcasting
- uint64_t send_time; // time to send file, in 100-nanosecond units
- // invalid if broadcasting (could be ignored)
- uint32_t preroll; // timestamp of the first packet, in milliseconds
- // if nonzero - substract from time
- uint32_t ignore; // preroll is 64bit - but let's just ignore it
- uint32_t flags; // 0x01 - broadcast
- // 0x02 - seekable
- // rest is reserved should be 0
- uint32_t min_pktsize; // size of a data packet
- // invalid if broadcasting
- uint32_t max_pktsize; // shall be the same as for min_pktsize
- // invalid if broadcasting
- uint32_t max_bitrate; // bandwith of stream in bps
- // should be the sum of bitrates of the
- // individual media streams
-} ASFMainHeader;
-
-
-typedef struct {
- int seqno;
- int packet_size;
- int is_streamed;
- int asfid2avid[128]; /* conversion table from asf ID 2 AVStream ID */
- ASFStream streams[128]; /* it's max number and it's not that big */
- /* non streamed additonnal info */
- INT64 nb_packets;
- INT64 duration; /* in 100ns units */
- /* packet filling */
- int packet_size_left;
- int packet_timestamp_start;
- int packet_timestamp_end;
- int packet_nb_frames;
- UINT8 packet_buf[PACKET_SIZE];
- ByteIOContext pb;
- /* only for reading */
- uint64_t data_offset; /* begining of the first data packet */
-
- ASFMainHeader hdr;
-
- int packet_flags;
- int packet_property;
- int packet_timestamp;
- int packet_segsizetype;
- int packet_segments;
- int packet_seq;
- int packet_replic_size;
- int packet_key_frame;
- int packet_padsize;
- int packet_frag_offset;
- int packet_frag_size;
- int packet_frag_timestamp;
- int packet_multi_size;
- int packet_obj_size;
- int packet_time_delta;
- int packet_time_start;
-
- int stream_index;
- ASFStream* asf_st; /* currently decoded stream */
-} ASFContext;
-
-static const GUID asf_header = {
- 0x75B22630, 0x668E, 0x11CF, { 0xA6, 0xD9, 0x00, 0xAA, 0x00, 0x62, 0xCE, 0x6C },
-};
-
-static const GUID file_header = {
- 0x8CABDCA1, 0xA947, 0x11CF, { 0x8E, 0xE4, 0x00, 0xC0, 0x0C, 0x20, 0x53, 0x65 },
-};
-
-static const GUID stream_header = {
- 0xB7DC0791, 0xA9B7, 0x11CF, { 0x8E, 0xE6, 0x00, 0xC0, 0x0C, 0x20, 0x53, 0x65 },
-};
-
-static const GUID audio_stream = {
- 0xF8699E40, 0x5B4D, 0x11CF, { 0xA8, 0xFD, 0x00, 0x80, 0x5F, 0x5C, 0x44, 0x2B },
-};
-
-static const GUID audio_conceal_none = {
- // 0x49f1a440, 0x4ece, 0x11d0, { 0xa3, 0xac, 0x00, 0xa0, 0xc9, 0x03, 0x48, 0xf6 },
- // New value lifted from avifile
- 0x20fb5700, 0x5b55, 0x11cf, { 0xa8, 0xfd, 0x00, 0x80, 0x5f, 0x5c, 0x44, 0x2b },
-};
-
-static const GUID video_stream = {
- 0xBC19EFC0, 0x5B4D, 0x11CF, { 0xA8, 0xFD, 0x00, 0x80, 0x5F, 0x5C, 0x44, 0x2B },
-};
-
-static const GUID video_conceal_none = {
- 0x20FB5700, 0x5B55, 0x11CF, { 0xA8, 0xFD, 0x00, 0x80, 0x5F, 0x5C, 0x44, 0x2B },
-};
-
-
-static const GUID comment_header = {
- 0x75b22633, 0x668e, 0x11cf, { 0xa6, 0xd9, 0x00, 0xaa, 0x00, 0x62, 0xce, 0x6c },
-};
-
-static const GUID codec_comment_header = {
- 0x86D15240, 0x311D, 0x11D0, { 0xA3, 0xA4, 0x00, 0xA0, 0xC9, 0x03, 0x48, 0xF6 },
-};
-static const GUID codec_comment1_header = {
- 0x86d15241, 0x311d, 0x11d0, { 0xa3, 0xa4, 0x00, 0xa0, 0xc9, 0x03, 0x48, 0xf6 },
-};
-
-static const GUID data_header = {
- 0x75b22636, 0x668e, 0x11cf, { 0xa6, 0xd9, 0x00, 0xaa, 0x00, 0x62, 0xce, 0x6c },
-};
-
-static const GUID index_guid = {
- 0x33000890, 0xe5b1, 0x11cf, { 0x89, 0xf4, 0x00, 0xa0, 0xc9, 0x03, 0x49, 0xcb },
-};
-
-static const GUID head1_guid = {
- 0x5fbf03b5, 0xa92e, 0x11cf, { 0x8e, 0xe3, 0x00, 0xc0, 0x0c, 0x20, 0x53, 0x65 },
-};
-
-static const GUID head2_guid = {
- 0xabd3d211, 0xa9ba, 0x11cf, { 0x8e, 0xe6, 0x00, 0xc0, 0x0c, 0x20, 0x53, 0x65 },
-};
-
-/* I am not a number !!! This GUID is the one found on the PC used to
- generate the stream */
-static const GUID my_guid = {
- 0, 0, 0, { 0, 0, 0, 0, 0, 0, 0, 0 },
-};
-
-static void put_guid(ByteIOContext *s, const GUID *g)
-{
- int i;
-
- put_le32(s, g->v1);
- put_le16(s, g->v2);
- put_le16(s, g->v3);
- for(i=0;i<8;i++)
- put_byte(s, g->v4[i]);
-}
-
-static void put_str16(ByteIOContext *s, const char *tag)
-{
- int c;
-
- put_le16(s,strlen(tag) + 1);
- for(;;) {
- c = (UINT8)*tag++;
- put_le16(s, c);
- if (c == '\0')
- break;
- }
-}
-
-static void put_str16_nolen(ByteIOContext *s, const char *tag)
-{
- int c;
-
- for(;;) {
- c = (UINT8)*tag++;
- put_le16(s, c);
- if (c == '\0')
- break;
- }
-}
-
-static INT64 put_header(ByteIOContext *pb, const GUID *g)
-{
- INT64 pos;
-
- pos = url_ftell(pb);
- put_guid(pb, g);
- put_le64(pb, 24);
- return pos;
-}
-
-/* update header size */
-static void end_header(ByteIOContext *pb, INT64 pos)
-{
- INT64 pos1;
-
- pos1 = url_ftell(pb);
- url_fseek(pb, pos + 16, SEEK_SET);
- put_le64(pb, pos1 - pos);
- url_fseek(pb, pos1, SEEK_SET);
-}
-
-/* write an asf chunk (only used in streaming case) */
-static void put_chunk(AVFormatContext *s, int type, int payload_length, int flags)
-{
- ASFContext *asf = s->priv_data;
- ByteIOContext *pb = &s->pb;
- int length;
-
- length = payload_length + 8;
- put_le16(pb, type);
- put_le16(pb, length);
- put_le32(pb, asf->seqno);
- put_le16(pb, flags); /* unknown bytes */
- put_le16(pb, length);
- asf->seqno++;
-}
-
-/* convert from unix to windows time */
-static INT64 unix_to_file_time(int ti)
-{
- INT64 t;
-
- t = ti * INT64_C(10000000);
- t += INT64_C(116444736000000000);
- return t;
-}
-
-/* write the header (used two times if non streamed) */
-static int asf_write_header1(AVFormatContext *s, INT64 file_size, INT64 data_chunk_size)
-{
- ASFContext *asf = s->priv_data;
- ByteIOContext *pb = &s->pb;
- int header_size, n, extra_size, extra_size2, wav_extra_size, file_time;
- int has_title;
- AVCodecContext *enc;
- INT64 header_offset, cur_pos, hpos;
- int bit_rate;
-
- has_title = (s->title[0] || s->author[0] || s->copyright[0] || s->comment[0]);
-
- bit_rate = 0;
- for(n=0;n<s->nb_streams;n++) {
- enc = &s->streams[n]->codec;
-
- bit_rate += enc->bit_rate;
- }
-
- if (asf->is_streamed) {
- put_chunk(s, 0x4824, 0, 0xc00); /* start of stream (length will be patched later) */
- }
-
- put_guid(pb, &asf_header);
- put_le64(pb, -1); /* header length, will be patched after */
- put_le32(pb, 3 + has_title + s->nb_streams); /* number of chunks in header */
- put_byte(pb, 1); /* ??? */
- put_byte(pb, 2); /* ??? */
-
- /* file header */
- header_offset = url_ftell(pb);
- hpos = put_header(pb, &file_header);
- put_guid(pb, &my_guid);
- put_le64(pb, file_size);
- file_time = 0;
- put_le64(pb, unix_to_file_time(file_time));
- put_le64(pb, asf->nb_packets); /* number of packets */
- put_le64(pb, asf->duration); /* end time stamp (in 100ns units) */
- put_le64(pb, asf->duration); /* duration (in 100ns units) */
- put_le32(pb, 0); /* start time stamp */
- put_le32(pb, 0); /* ??? */
- put_le32(pb, asf->is_streamed ? 1 : 0); /* ??? */
- put_le32(pb, asf->packet_size); /* packet size */
- put_le32(pb, asf->packet_size); /* packet size */
- put_le32(pb, bit_rate); /* Nominal data rate in bps */
- end_header(pb, hpos);
-
- /* unknown headers */
- hpos = put_header(pb, &head1_guid);
- put_guid(pb, &head2_guid);
- put_le32(pb, 6);
- put_le16(pb, 0);
- end_header(pb, hpos);
-
- /* title and other infos */
- if (has_title) {
- hpos = put_header(pb, &comment_header);
- put_le16(pb, 2 * (strlen(s->title) + 1));
- put_le16(pb, 2 * (strlen(s->author) + 1));
- put_le16(pb, 2 * (strlen(s->copyright) + 1));
- put_le16(pb, 2 * (strlen(s->comment) + 1));
- put_le16(pb, 0);
- put_str16_nolen(pb, s->title);
- put_str16_nolen(pb, s->author);
- put_str16_nolen(pb, s->copyright);
- put_str16_nolen(pb, s->comment);
- end_header(pb, hpos);
- }
-
- /* stream headers */
- for(n=0;n<s->nb_streams;n++) {
- INT64 es_pos;
- // ASFStream *stream = &asf->streams[n];
-
- enc = &s->streams[n]->codec;
- asf->streams[n].num = n + 1;
- asf->streams[n].seq = 0;
-
- switch(enc->codec_type) {
- case CODEC_TYPE_AUDIO:
- wav_extra_size = 0;
- extra_size = 18 + wav_extra_size;
- extra_size2 = 0;
- break;
- default:
- case CODEC_TYPE_VIDEO:
- wav_extra_size = 0;
- extra_size = 0x33;
- extra_size2 = 0;
- break;
- }
-
- hpos = put_header(pb, &stream_header);
- if (enc->codec_type == CODEC_TYPE_AUDIO) {
- put_guid(pb, &audio_stream);
- put_guid(pb, &audio_conceal_none);
- } else {
- put_guid(pb, &video_stream);
- put_guid(pb, &video_conceal_none);
- }
- put_le64(pb, 0); /* ??? */
- es_pos = url_ftell(pb);
- put_le32(pb, extra_size); /* wav header len */
- put_le32(pb, extra_size2); /* additional data len */
- put_le16(pb, n + 1); /* stream number */
- put_le32(pb, 0); /* ??? */
-
- if (enc->codec_type == CODEC_TYPE_AUDIO) {
- /* WAVEFORMATEX header */
- int wavsize = put_wav_header(pb, enc);
-
- if (wavsize < 0)
- return -1;
- if (wavsize != extra_size) {
- cur_pos = url_ftell(pb);
- url_fseek(pb, es_pos, SEEK_SET);
- put_le32(pb, wavsize); /* wav header len */
- url_fseek(pb, cur_pos, SEEK_SET);
- }
- } else {
- put_le32(pb, enc->width);
- put_le32(pb, enc->height);
- put_byte(pb, 2); /* ??? */
- put_le16(pb, 40); /* size */
-
- /* BITMAPINFOHEADER header */
- put_bmp_header(pb, enc, codec_bmp_tags, 1);
- }
- end_header(pb, hpos);
- }
-
- /* media comments */
-
- hpos = put_header(pb, &codec_comment_header);
- put_guid(pb, &codec_comment1_header);
- put_le32(pb, s->nb_streams);
- for(n=0;n<s->nb_streams;n++) {
- AVCodec *p;
-
- enc = &s->streams[n]->codec;
- p = avcodec_find_encoder(enc->codec_id);
-
- put_le16(pb, asf->streams[n].num);
- put_str16(pb, p ? p->name : enc->codec_name);
- put_le16(pb, 0); /* no parameters */
- /* id */
- if (enc->codec_type == CODEC_TYPE_AUDIO) {
- put_le16(pb, 2);
- put_le16(pb, codec_get_tag(codec_wav_tags, enc->codec_id));
- } else {
- put_le16(pb, 4);
- put_le32(pb, codec_get_tag(codec_bmp_tags, enc->codec_id));
- }
- }
- end_header(pb, hpos);
-
- /* patch the header size fields */
-
- cur_pos = url_ftell(pb);
- header_size = cur_pos - header_offset;
- if (asf->is_streamed) {
- header_size += 8 + 30 + 50;
-
- url_fseek(pb, header_offset - 10 - 30, SEEK_SET);
- put_le16(pb, header_size);
- url_fseek(pb, header_offset - 2 - 30, SEEK_SET);
- put_le16(pb, header_size);
-
- header_size -= 8 + 30 + 50;
- }
- header_size += 24 + 6;
- url_fseek(pb, header_offset - 14, SEEK_SET);
- put_le64(pb, header_size);
- url_fseek(pb, cur_pos, SEEK_SET);
-
- /* movie chunk, followed by packets of packet_size */
- asf->data_offset = cur_pos;
- put_guid(pb, &data_header);
- put_le64(pb, data_chunk_size);
- put_guid(pb, &my_guid);
- put_le64(pb, asf->nb_packets); /* nb packets */
- put_byte(pb, 1); /* ??? */
- put_byte(pb, 1); /* ??? */
- return 0;
-}
-
-static int asf_write_header(AVFormatContext *s)
-{
- ASFContext *asf = s->priv_data;
-
- av_set_pts_info(s, 32, 1, 1000); /* 32 bit pts in ms */
-
- asf->packet_size = PACKET_SIZE;
- asf->nb_packets = 0;
-
- if (asf_write_header1(s, 0, 50) < 0) {
- //av_free(asf);
- return -1;
- }
-
- put_flush_packet(&s->pb);
-
- asf->packet_nb_frames = 0;
- asf->packet_timestamp_start = -1;
- asf->packet_timestamp_end = -1;
- asf->packet_size_left = asf->packet_size - PACKET_HEADER_SIZE;
- init_put_byte(&asf->pb, asf->packet_buf, asf->packet_size, 1,
- NULL, NULL, NULL, NULL);
-
- return 0;
-}
-
-static int asf_write_stream_header(AVFormatContext *s)
-{
- ASFContext *asf = s->priv_data;
-
- asf->is_streamed = 1;
-
- return asf_write_header(s);
-}
-
-/* write a fixed size packet */
-static int put_packet(AVFormatContext *s,
- unsigned int timestamp, unsigned int duration,
- int nb_frames, int padsize)
-{
- ASFContext *asf = s->priv_data;
- ByteIOContext *pb = &s->pb;
- int flags;
-
- if (asf->is_streamed) {
- put_chunk(s, 0x4424, asf->packet_size, 0);
- }
-
- put_byte(pb, 0x82);
- put_le16(pb, 0);
-
- flags = 0x01; /* nb segments present */
- if (padsize > 0) {
- if (padsize < 256)
- flags |= 0x08;
- else
- flags |= 0x10;
- }
- put_byte(pb, flags); /* flags */
- put_byte(pb, 0x5d);
- if (flags & 0x10)
- put_le16(pb, padsize - 2);
- if (flags & 0x08)
- put_byte(pb, padsize - 1);
- put_le32(pb, timestamp);
- put_le16(pb, duration);
- put_byte(pb, nb_frames | 0x80);
-
- return PACKET_HEADER_SIZE + ((flags & 0x18) >> 3);
-}
-
-static void flush_packet(AVFormatContext *s)
-{
- ASFContext *asf = s->priv_data;
- int hdr_size, ptr;
-
- hdr_size = put_packet(s, asf->packet_timestamp_start,
- asf->packet_timestamp_end - asf->packet_timestamp_start,
- asf->packet_nb_frames, asf->packet_size_left);
-
- /* Clear out the padding bytes */
- ptr = asf->packet_size - hdr_size - asf->packet_size_left;
- memset(asf->packet_buf + ptr, 0, asf->packet_size_left);
-
- put_buffer(&s->pb, asf->packet_buf, asf->packet_size - hdr_size);
-
- put_flush_packet(&s->pb);
- asf->nb_packets++;
- asf->packet_nb_frames = 0;
- asf->packet_timestamp_start = -1;
- asf->packet_timestamp_end = -1;
- asf->packet_size_left = asf->packet_size - PACKET_HEADER_SIZE;
- init_put_byte(&asf->pb, asf->packet_buf, asf->packet_size, 1,
- NULL, NULL, NULL, NULL);
-}
-
-static void put_frame_header(AVFormatContext *s, ASFStream *stream, int timestamp,
- int payload_size, int frag_offset, int frag_len)
-{
- ASFContext *asf = s->priv_data;
- ByteIOContext *pb = &asf->pb;
- int val;
-
- val = stream->num;
- if (s->streams[val - 1]->codec.key_frame /* && frag_offset == 0 */)
- val |= 0x80;
- put_byte(pb, val);
- put_byte(pb, stream->seq);
- put_le32(pb, frag_offset); /* fragment offset */
- put_byte(pb, 0x08); /* flags */
- put_le32(pb, payload_size);
- put_le32(pb, timestamp);
- put_le16(pb, frag_len);
-}
-
-
-/* Output a frame. We suppose that payload_size <= PACKET_SIZE.
-
- It is there that you understand that the ASF format is really
- crap. They have misread the MPEG Systems spec !
- */
-static void put_frame(AVFormatContext *s, ASFStream *stream, int timestamp,
- UINT8 *buf, int payload_size)
-{
- ASFContext *asf = s->priv_data;
- int frag_pos, frag_len, frag_len1;
-
- frag_pos = 0;
- while (frag_pos < payload_size) {
- frag_len = payload_size - frag_pos;
- frag_len1 = asf->packet_size_left - FRAME_HEADER_SIZE;
- if (frag_len1 > 0) {
- if (frag_len > frag_len1)
- frag_len = frag_len1;
- put_frame_header(s, stream, timestamp+1, payload_size, frag_pos, frag_len);
- put_buffer(&asf->pb, buf, frag_len);
- asf->packet_size_left -= (frag_len + FRAME_HEADER_SIZE);
- asf->packet_timestamp_end = timestamp;
- if (asf->packet_timestamp_start == -1)
- asf->packet_timestamp_start = timestamp;
- asf->packet_nb_frames++;
- } else {
- frag_len = 0;
- }
- frag_pos += frag_len;
- buf += frag_len;
- /* output the frame if filled */
- if (asf->packet_size_left <= FRAME_HEADER_SIZE)
- flush_packet(s);
- }
- stream->seq++;
-}
-
-
-static int asf_write_packet(AVFormatContext *s, int stream_index,
- UINT8 *buf, int size, int timestamp)
-{
- ASFContext *asf = s->priv_data;
- ASFStream *stream;
- INT64 duration;
- AVCodecContext *codec;
-
- codec = &s->streams[stream_index]->codec;
- stream = &asf->streams[stream_index];
-
- if (codec->codec_type == CODEC_TYPE_AUDIO) {
- duration = (codec->frame_number * codec->frame_size * INT64_C(10000000)) /
- codec->sample_rate;
- } else {
- duration = codec->frame_number *
- ((INT64_C(10000000) * FRAME_RATE_BASE) / codec->frame_rate);
- }
- if (duration > asf->duration)
- asf->duration = duration;
-
- put_frame(s, stream, timestamp, buf, size);
- return 0;
-}
-
-static int asf_write_trailer(AVFormatContext *s)
-{
- ASFContext *asf = s->priv_data;
- INT64 file_size;
-
- /* flush the current packet */
- if (asf->pb.buf_ptr > asf->pb.buffer)
- flush_packet(s);
-
- if (asf->is_streamed) {
- put_chunk(s, 0x4524, 0, 0); /* end of stream */
- } else {
- /* rewrite an updated header */
- file_size = url_ftell(&s->pb);
- url_fseek(&s->pb, 0, SEEK_SET);
- asf_write_header1(s, file_size, file_size - asf->data_offset);
- }
-
- put_flush_packet(&s->pb);
- return 0;
-}
-
-/**********************************/
-/* decoding */
-
-//#define DEBUG
-
-#ifdef DEBUG
-static void print_guid(const GUID *g)
-{
- int i;
- printf("0x%08x, 0x%04x, 0x%04x, {", g->v1, g->v2, g->v3);
- for(i=0;i<8;i++)
- printf(" 0x%02x,", g->v4[i]);
- printf("}\n");
-}
-#endif
-
-static void get_guid(ByteIOContext *s, GUID *g)
-{
- int i;
-
- g->v1 = get_le32(s);
- g->v2 = get_le16(s);
- g->v3 = get_le16(s);
- for(i=0;i<8;i++)
- g->v4[i] = get_byte(s);
-}
-
-#if 0
-static void get_str16(ByteIOContext *pb, char *buf, int buf_size)
-{
- int len, c;
- char *q;
-
- len = get_le16(pb);
- q = buf;
- while (len > 0) {
- c = get_le16(pb);
- if ((q - buf) < buf_size - 1)
- *q++ = c;
- len--;
- }
- *q = '\0';
-}
-#endif
-
-static void get_str16_nolen(ByteIOContext *pb, int len, char *buf, int buf_size)
-{
- int c;
- char *q;
-
- q = buf;
- while (len > 0) {
- c = get_le16(pb);
- if ((q - buf) < buf_size - 1)
- *q++ = c;
- len-=2;
- }
- *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 = s->priv_data;
- GUID g;
- ByteIOContext *pb = &s->pb;
- AVStream *st;
- ASFStream *asf_st;
- int size, i;
- INT64 gsize;
-
- av_set_pts_info(s, 32, 1, 1000); /* 32 bit pts in ms */
-
- get_guid(pb, &g);
- if (memcmp(&g, &asf_header, sizeof(GUID)))
- goto fail;
- get_le64(pb);
- get_le32(pb);
- get_byte(pb);
- get_byte(pb);
- memset(&asf->asfid2avid, -1, sizeof(asf->asfid2avid));
- for(;;) {
- get_guid(pb, &g);
- gsize = get_le64(pb);
-#ifdef DEBUG
- printf("%08Lx: ", url_ftell(pb) - 24);
- print_guid(&g);
- printf(" size=0x%Lx\n", gsize);
-#endif
- if (gsize < 24)
- goto fail;
- if (!memcmp(&g, &file_header, sizeof(GUID))) {
- get_guid(pb, &asf->hdr.guid);
- asf->hdr.file_size = get_le64(pb);
- asf->hdr.create_time = get_le64(pb);
- asf->hdr.packets_count = get_le64(pb);
- asf->hdr.play_time = get_le64(pb);
- asf->hdr.send_time = get_le64(pb);
- asf->hdr.preroll = get_le32(pb);
- asf->hdr.ignore = get_le32(pb);
- asf->hdr.flags = get_le32(pb);
- asf->hdr.min_pktsize = get_le32(pb);
- asf->hdr.max_pktsize = get_le32(pb);
- asf->hdr.max_bitrate = get_le32(pb);
- asf->packet_size = asf->hdr.max_pktsize;
- asf->nb_packets = asf->hdr.packets_count;
- } else if (!memcmp(&g, &stream_header, sizeof(GUID))) {
- int type, total_size;
- unsigned int tag1;
- INT64 pos1, pos2;
-
- pos1 = url_ftell(pb);
-
- st = av_mallocz(sizeof(AVStream));
- if (!st)
- goto fail;
- s->streams[s->nb_streams] = st;
- asf_st = av_mallocz(sizeof(ASFStream));
- if (!asf_st)
- goto fail;
- st->priv_data = asf_st;
- st->time_length = (asf->hdr.send_time - asf->hdr.preroll) / 10; // us
- get_guid(pb, &g);
- if (!memcmp(&g, &audio_stream, sizeof(GUID))) {
- type = CODEC_TYPE_AUDIO;
- } else if (!memcmp(&g, &video_stream, sizeof(GUID))) {
- type = CODEC_TYPE_VIDEO;
- } else {
- goto fail;
- }
- get_guid(pb, &g);
- total_size = get_le64(pb);
- get_le32(pb);
- get_le32(pb);
- st->id = get_le16(pb) & 0x7f; /* stream id */
- // mapping of asf ID to AV stream ID;
- asf->asfid2avid[st->id] = s->nb_streams++;
-
- get_le32(pb);
- st->codec.codec_type = type;
- st->codec.frame_rate = 15 * s->pts_den / s->pts_num; // 15 fps default
- if (type == CODEC_TYPE_AUDIO) {
- get_wav_header(pb, &st->codec, 1);
- /* We have to init the frame size at some point .... */
- pos2 = url_ftell(pb);
- if (gsize > (pos2 + 8 - pos1 + 24)) {
- asf_st->ds_span = get_byte(pb);
- asf_st->ds_packet_size = get_le16(pb);
- asf_st->ds_chunk_size = get_le16(pb);
- asf_st->ds_data_size = get_le16(pb);
- asf_st->ds_silence_data = get_byte(pb);
- }
- //printf("Descrambling: ps:%d cs:%d ds:%d s:%d sd:%d\n",
- // asf_st->ds_packet_size, asf_st->ds_chunk_size,
- // asf_st->ds_data_size, asf_st->ds_span, asf_st->ds_silence_data);
- if (asf_st->ds_span > 1) {
- if (!asf_st->ds_chunk_size
- || (asf_st->ds_packet_size/asf_st->ds_chunk_size <= 1))
- asf_st->ds_span = 0; // disable descrambling
- }
- switch (st->codec.codec_id) {
- case CODEC_ID_MP3LAME:
- st->codec.frame_size = MPA_FRAME_SIZE;
- break;
- case CODEC_ID_PCM_S16LE:
- case CODEC_ID_PCM_S16BE:
- case CODEC_ID_PCM_U16LE:
- case CODEC_ID_PCM_U16BE:
- case CODEC_ID_PCM_S8:
- case CODEC_ID_PCM_U8:
- case CODEC_ID_PCM_ALAW:
- case CODEC_ID_PCM_MULAW:
- st->codec.frame_size = 1;
- break;
- default:
- /* This is probably wrong, but it prevents a crash later */
- st->codec.frame_size = 1;
- break;
- }
- } else {
- get_le32(pb);
- get_le32(pb);
- get_byte(pb);
- size = get_le16(pb); /* size */
- get_le32(pb); /* size */
- st->codec.width = get_le32(pb);
- st->codec.height = get_le32(pb);
- /* not available for asf */
- get_le16(pb); /* panes */
- get_le16(pb); /* depth */
- tag1 = get_le32(pb);
- url_fskip(pb, 20);
- if (size > 40) {
- st->codec.extradata_size = size - 40;
- st->codec.extradata = av_mallocz(st->codec.extradata_size);
- get_buffer(pb, st->codec.extradata, st->codec.extradata_size);
- }
- st->codec.codec_tag = st->codec.fourcc = tag1;
- st->codec.codec_id = codec_get_id(codec_bmp_tags, tag1);
- }
- pos2 = url_ftell(pb);
- url_fskip(pb, gsize - (pos2 - pos1 + 24));
- } else if (!memcmp(&g, &data_header, sizeof(GUID))) {
- break;
- } else if (!memcmp(&g, &comment_header, sizeof(GUID))) {
- int len1, len2, len3, len4, len5;
-
- len1 = get_le16(pb);
- len2 = get_le16(pb);
- len3 = get_le16(pb);
- len4 = get_le16(pb);
- len5 = get_le16(pb);
- get_str16_nolen(pb, len1, s->title, sizeof(s->title));
- get_str16_nolen(pb, len2, s->author, sizeof(s->author));
- get_str16_nolen(pb, len3, s->copyright, sizeof(s->copyright));
- get_str16_nolen(pb, len4, s->comment, sizeof(s->comment));
- url_fskip(pb, len5);
-#if 0
- } else if (!memcmp(&g, &head1_guid, sizeof(GUID))) {
- int v1, v2;
- get_guid(pb, &g);
- v1 = get_le32(pb);
- v2 = get_le16(pb);
- } else if (!memcmp(&g, &codec_comment_header, sizeof(GUID))) {
- int len, v1, n, num;
- char str[256], *q;
- char tag[16];
-
- get_guid(pb, &g);
- print_guid(&g);
-
- n = get_le32(pb);
- for(i=0;i<n;i++) {
- num = get_le16(pb); /* stream number */
- get_str16(pb, str, sizeof(str));
- get_str16(pb, str, sizeof(str));
- len = get_le16(pb);
- q = tag;
- while (len > 0) {
- v1 = get_byte(pb);
- if ((q - tag) < sizeof(tag) - 1)
- *q++ = v1;
- len--;
- }
- *q = '\0';
- }
-#endif
- } else if (url_feof(pb)) {
- goto fail;
- } else {
- url_fseek(pb, gsize - 24, SEEK_CUR);
- }
- }
- get_guid(pb, &g);
- get_le64(pb);
- get_byte(pb);
- get_byte(pb);
- if (url_feof(pb))
- goto fail;
- asf->data_offset = url_ftell(pb);
- asf->packet_size_left = 0;
-
- return 0;
-
- fail:
- for(i=0;i<s->nb_streams;i++) {
- AVStream *st = s->streams[i];
- if (st) {
- av_free(st->priv_data);
- av_free(st->codec.extradata);
- }
- av_free(st);
- }
- return -1;
-}
-
-#define DO_2BITS(bits, var, defval) \
- switch (bits & 3) \
- { \
- case 3: var = get_le32(pb); rsize += 4; break; \
- case 2: var = get_le16(pb); rsize += 2; break; \
- case 1: var = get_byte(pb); rsize++; break; \
- default: var = defval; break; \
- }
-
-static int asf_get_packet(AVFormatContext *s)
-{
- ASFContext *asf = s->priv_data;
- ByteIOContext *pb = &s->pb;
- uint32_t packet_length, padsize;
- int rsize = 11;
- int c = get_byte(pb);
- if (c != 0x82) {
- if (!url_feof(pb))
- printf("ff asf bad header %x at:%Ld\n", c, url_ftell(pb));
- return -EIO;
- }
- if ((c & 0x0f) == 2) { // always true for now
- if (get_le16(pb) != 0) {
- if (!url_feof(pb))
- printf("ff asf bad non zero\n");
- return -EIO;
- }
- }
-
- asf->packet_flags = get_byte(pb);
- asf->packet_property = get_byte(pb);
-
- DO_2BITS(asf->packet_flags >> 5, packet_length, asf->packet_size);
- DO_2BITS(asf->packet_flags >> 1, padsize, 0); // sequence ignored
- DO_2BITS(asf->packet_flags >> 3, padsize, 0); // padding length
-
- asf->packet_timestamp = get_le32(pb);
- get_le16(pb); /* duration */
- // rsize has at least 11 bytes which have to be present
-
- if (asf->packet_flags & 0x01) {
- asf->packet_segsizetype = get_byte(pb); rsize++;
- asf->packet_segments = asf->packet_segsizetype & 0x3f;
- } else {
- asf->packet_segments = 1;
- asf->packet_segsizetype = 0x80;
- }
- asf->packet_size_left = packet_length - padsize - rsize;
- if (packet_length < asf->hdr.min_pktsize)
- padsize += asf->hdr.min_pktsize - packet_length;
- asf->packet_padsize = padsize;
-#ifdef DEBUG
- printf("packet: size=%d padsize=%d left=%d\n", asf->packet_size, asf->packet_padsize, asf->packet_size_left);
-#endif
- return 0;
-}
-
-static int asf_read_packet(AVFormatContext *s, AVPacket *pkt)
-{
- ASFContext *asf = s->priv_data;
- ASFStream *asf_st = 0;
- ByteIOContext *pb = &s->pb;
- //static int pc = 0;
- for (;;) {
- int rsize = 0;
- if (asf->packet_size_left < FRAME_HEADER_SIZE
- || asf->packet_segments < 1) {
- //asf->packet_size_left <= asf->packet_padsize) {
- int ret = asf->packet_size_left + asf->packet_padsize;
- //printf("PacketLeftSize:%d Pad:%d Pos:%Ld\n", asf->packet_size_left, asf->packet_padsize, url_ftell(pb));
- /* fail safe */
- url_fskip(pb, ret);
- ret = asf_get_packet(s);
- //printf("READ ASF PACKET %d r:%d c:%d\n", ret, asf->packet_size_left, pc++);
- if (ret < 0 || url_feof(pb))
- return -EIO;
- asf->packet_time_start = 0;
- continue;
- }
- if (asf->packet_time_start == 0) {
- /* read frame header */
- int num = get_byte(pb);
- asf->packet_segments--;
- rsize++;
- asf->packet_key_frame = (num & 0x80) >> 7;
- asf->stream_index = asf->asfid2avid[num & 0x7f];
- // sequence should be ignored!
- DO_2BITS(asf->packet_property >> 4, asf->packet_seq, 0);
- DO_2BITS(asf->packet_property >> 2, asf->packet_frag_offset, 0);
- DO_2BITS(asf->packet_property, asf->packet_replic_size, 0);
-
- if (asf->packet_replic_size > 1) {
- // it should be always at least 8 bytes - FIXME validate
- asf->packet_obj_size = get_le32(pb);
- asf->packet_frag_timestamp = get_le32(pb); // timestamp
- if (asf->packet_replic_size > 8)
- url_fskip(pb, asf->packet_replic_size - 8);
- rsize += asf->packet_replic_size; // FIXME - check validity
- } else {
- // multipacket - frag_offset is begining timestamp
- asf->packet_time_start = asf->packet_frag_offset;
- asf->packet_frag_offset = 0;
- asf->packet_frag_timestamp = asf->packet_timestamp;
-
- if (asf->packet_replic_size == 1) {
- asf->packet_time_delta = get_byte(pb);
- rsize++;
- }
- }
- if (asf->packet_flags & 0x01) {
- DO_2BITS(asf->packet_segsizetype >> 6, asf->packet_frag_size, 0); // 0 is illegal
-#undef DO_2BITS
- //printf("Fragsize %d\n", asf->packet_frag_size);
- } else {
- asf->packet_frag_size = asf->packet_size_left - rsize;
- //printf("Using rest %d %d %d\n", asf->packet_frag_size, asf->packet_size_left, rsize);
- }
- if (asf->packet_replic_size == 1) {
- asf->packet_multi_size = asf->packet_frag_size;
- if (asf->packet_multi_size > asf->packet_size_left) {
- asf->packet_segments = 0;
- continue;
- }
- }
- asf->packet_size_left -= rsize;
- //printf("___objsize____ %d %d rs:%d\n", asf->packet_obj_size, asf->packet_frag_offset, rsize);
-
- if (asf->stream_index < 0) {
- asf->packet_time_start = 0;
- /* unhandled packet (should not happen) */
- url_fskip(pb, asf->packet_frag_size);
- asf->packet_size_left -= asf->packet_frag_size;
- printf("ff asf skip %d %d\n", asf->packet_frag_size, num & 0x7f);
- continue;
- }
- asf->asf_st = s->streams[asf->stream_index]->priv_data;
- }
- asf_st = asf->asf_st;
-
- if ((asf->packet_frag_offset != asf_st->frag_offset
- || (asf->packet_frag_offset
- && asf->packet_seq != asf_st->seq)) // seq should be ignored
- ) {
- /* cannot continue current packet: free it */
- // FIXME better check if packet was already allocated
- printf("ff asf parser skips: %d - %d o:%d - %d %d %d fl:%d\n",
- asf_st->pkt.size,
- asf->packet_obj_size,
- asf->packet_frag_offset, asf_st->frag_offset,
- asf->packet_seq, asf_st->seq, asf->packet_frag_size);
- if (asf_st->pkt.size)
- av_free_packet(&asf_st->pkt);
- asf_st->frag_offset = 0;
- if (asf->packet_frag_offset != 0) {
- url_fskip(pb, asf->packet_frag_size);
- printf("ff asf parser skiping %db\n", asf->packet_frag_size);
- asf->packet_size_left -= asf->packet_frag_size;
- continue;
- }
- }
- if (asf->packet_replic_size == 1) {
- // frag_offset is here used as the begining timestamp
- asf->packet_frag_timestamp = asf->packet_time_start;
- asf->packet_time_start += asf->packet_time_delta;
- asf->packet_obj_size = asf->packet_frag_size = get_byte(pb);
- asf->packet_size_left--;
- asf->packet_multi_size--;
- if (asf->packet_multi_size < asf->packet_obj_size)
- {
- asf->packet_time_start = 0;
- url_fskip(pb, asf->packet_multi_size);
- asf->packet_size_left -= asf->packet_multi_size;
- continue;
- }
- asf->packet_multi_size -= asf->packet_obj_size;
- //printf("COMPRESS size %d %d %d ms:%d\n", asf->packet_obj_size, asf->packet_frag_timestamp, asf->packet_size_left, asf->packet_multi_size);
- }
- if (asf_st->frag_offset == 0) {
- /* new packet */
- av_new_packet(&asf_st->pkt, asf->packet_obj_size);
- asf_st->seq = asf->packet_seq;
- asf_st->pkt.pts = asf->packet_frag_timestamp - asf->hdr.preroll;
- asf_st->pkt.stream_index = asf->stream_index;
- if (asf->packet_key_frame)
- asf_st->pkt.flags |= PKT_FLAG_KEY;
- }
-
- /* read data */
- //printf("READ PACKET s:%d os:%d o:%d,%d l:%d DATA:%p\n",
- // asf->packet_size, asf_st->pkt.size, asf->packet_frag_offset,
- // asf_st->frag_offset, asf->packet_frag_size, asf_st->pkt.data);
- asf->packet_size_left -= asf->packet_frag_size;
- if (asf->packet_size_left < 0)
- continue;
- get_buffer(pb, asf_st->pkt.data + asf->packet_frag_offset,
- asf->packet_frag_size);
- asf_st->frag_offset += asf->packet_frag_size;
- /* test if whole packet is read */
- if (asf_st->frag_offset == asf_st->pkt.size) {
- /* return packet */
- if (asf_st->ds_span > 1) {
- /* packet descrambling */
- char* newdata = av_malloc(asf_st->pkt.size);
- if (newdata) {
- int offset = 0;
- while (offset < asf_st->pkt.size) {
- int off = offset / asf_st->ds_chunk_size;
- int row = off / asf_st->ds_span;
- int col = off % asf_st->ds_span;
- int idx = row + col * asf_st->ds_packet_size / asf_st->ds_chunk_size;
- //printf("off:%d row:%d col:%d idx:%d\n", off, row, col, idx);
- memcpy(newdata + offset,
- asf_st->pkt.data + idx * asf_st->ds_chunk_size,
- asf_st->ds_chunk_size);
- offset += asf_st->ds_chunk_size;
- }
- av_free(asf_st->pkt.data);
- asf_st->pkt.data = newdata;
- }
- }
- asf_st->frag_offset = 0;
- memcpy(pkt, &asf_st->pkt, sizeof(AVPacket));
- //printf("packet %d %d\n", asf_st->pkt.size, asf->packet_frag_size);
- asf_st->pkt.size = 0;
- asf_st->pkt.data = 0;
- break; // packet completed
- }
- }
- return 0;
-}
-
-static int asf_read_close(AVFormatContext *s)
-{
- int i;
-
- for(i=0;i<s->nb_streams;i++) {
- AVStream *st = s->streams[i];
- av_free(st->priv_data);
- av_free(st->codec.extradata);
- }
- return 0;
-}
-
-static int asf_read_seek(AVFormatContext *s, int64_t pts)
-{
- printf("SEEK TO %Ld", pts);
- return -1;
-}
-
-static AVInputFormat asf_iformat = {
- "asf",
- "asf format",
- sizeof(ASFContext),
- asf_probe,
- asf_read_header,
- asf_read_packet,
- asf_read_close,
- asf_read_seek,
-};
-
-static AVOutputFormat asf_oformat = {
- "asf",
- "asf format",
- "application/octet-stream",
- "asf,wmv",
- sizeof(ASFContext),
-#ifdef CONFIG_MP3LAME
- CODEC_ID_MP3LAME,
-#else
- CODEC_ID_MP2,
-#endif
- CODEC_ID_MSMPEG4V3,
- asf_write_header,
- asf_write_packet,
- asf_write_trailer,
-};
-
-static AVOutputFormat asf_stream_oformat = {
- "asf_stream",
- "asf format",
- "application/octet-stream",
- "asf,wmv",
- sizeof(ASFContext),
-#ifdef CONFIG_MP3LAME
- CODEC_ID_MP3LAME,
-#else
- CODEC_ID_MP2,
-#endif
- CODEC_ID_MSMPEG4V3,
- asf_write_stream_header,
- asf_write_packet,
- asf_write_trailer,
-};
-
-int asf_init(void)
-{
- av_register_input_format(&asf_iformat);
- av_register_output_format(&asf_oformat);
- av_register_output_format(&asf_stream_oformat);
- return 0;
-}
+++ /dev/null
-/*
- * AU encoder and decoder
- * Copyright (c) 2001 Fabrice Bellard.
- *
- * This library 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 of the License, or (at your option) any later version.
- *
- * This library 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 this library; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
-
-/*
- * First version by Francois Revol revol@free.fr
- *
- * Reference documents:
- * http://www.opengroup.org/public/pubs/external/auformat.html
- * http://www.goice.co.jp/member/mo/formats/au.html
- */
-
-#include "avformat.h"
-#include "avi.h"
-
-/* if we don't know the size in advance */
-#define AU_UNKOWN_SIZE ((UINT32)(~0))
-
-/* The ffmpeg codecs we support, and the IDs they have in the file */
-static const CodecTag codec_au_tags[] = {
- { CODEC_ID_PCM_MULAW, 1 },
- { CODEC_ID_PCM_S16BE, 3 },
- { CODEC_ID_PCM_ALAW, 27 },
- { 0, 0 },
-};
-
-/* AUDIO_FILE header */
-static int put_au_header(ByteIOContext *pb, AVCodecContext *enc)
-{
- int tag;
-
- tag = codec_get_tag(codec_au_tags, enc->codec_id);
- if (tag == 0)
- return -1;
- put_tag(pb, ".snd"); /* magic number */
- put_be32(pb, 24); /* header size */
- put_be32(pb, AU_UNKOWN_SIZE); /* data size */
- put_be32(pb, (UINT32)tag); /* codec ID */
- put_be32(pb, enc->sample_rate);
- put_be32(pb, (UINT32)enc->channels);
- return 0;
-}
-
-static int au_write_header(AVFormatContext *s)
-{
- ByteIOContext *pb = &s->pb;
-
- s->priv_data = NULL;
-
- /* format header */
- if (put_au_header(pb, &s->streams[0]->codec) < 0) {
- return -1;
- }
-
- put_flush_packet(pb);
-
- return 0;
-}
-
-static int au_write_packet(AVFormatContext *s, int stream_index_ptr,
- UINT8 *buf, int size, int force_pts)
-{
- ByteIOContext *pb = &s->pb;
- put_buffer(pb, buf, size);
- return 0;
-}
-
-static int au_write_trailer(AVFormatContext *s)
-{
- ByteIOContext *pb = &s->pb;
- offset_t file_size;
-
- if (!url_is_streamed(&s->pb)) {
-
- /* update file size */
- file_size = url_ftell(pb);
- url_fseek(pb, 8, SEEK_SET);
- put_be32(pb, (UINT32)(file_size - 24));
- url_fseek(pb, file_size, SEEK_SET);
-
- put_flush_packet(pb);
- }
-
- 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)
-{
- int size;
- unsigned int tag;
- ByteIOContext *pb = &s->pb;
- unsigned int id, codec, channels, rate;
- AVStream *st;
-
- /* check ".snd" header */
- tag = get_le32(pb);
- if (tag != MKTAG('.', 's', 'n', 'd'))
- return -1;
- size = get_be32(pb); /* header size */
- get_be32(pb); /* data size */
-
- id = get_be32(pb);
- rate = get_be32(pb);
- channels = get_be32(pb);
-
- codec = codec_get_id(codec_au_tags, id);
-
- if (size >= 24) {
- /* skip unused data */
- url_fseek(pb, size - 24, SEEK_CUR);
- }
-
- /* now we are ready: build format streams */
- st = av_malloc(sizeof(AVStream));
- if (!st)
- return -1;
- s->nb_streams = 1;
- s->streams[0] = st;
-
- st->id = 0;
-
- st->codec.codec_type = CODEC_TYPE_AUDIO;
- st->codec.codec_tag = id;
- st->codec.codec_id = codec;
- st->codec.channels = channels;
- st->codec.sample_rate = rate;
- return 0;
-}
-
-#define MAX_SIZE 4096
-
-static int au_read_packet(AVFormatContext *s,
- AVPacket *pkt)
-{
- int ret;
-
- if (url_feof(&s->pb))
- return -EIO;
- if (av_new_packet(pkt, MAX_SIZE))
- return -EIO;
- pkt->stream_index = 0;
-
- ret = get_buffer(&s->pb, pkt->data, pkt->size);
- if (ret < 0)
- av_free_packet(pkt);
- /* note: we need to modify the packet size here to handle the last
- packet */
- pkt->size = ret;
- return 0;
-}
-
-static int au_read_close(AVFormatContext *s)
-{
- return 0;
-}
-
-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,
-};
-
-int au_init(void)
-{
- av_register_input_format(&au_iformat);
- av_register_output_format(&au_oformat);
- return 0;
-}
+++ /dev/null
-/*
- * Linux audio play and grab interface
- * Copyright (c) 2000, 2001 Fabrice Bellard.
- *
- * This library 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 of the License, or (at your option) any later version.
- *
- * This library 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 this library; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
-#include "avformat.h"
-
-#include <stdlib.h>
-#include <stdio.h>
-#include <string.h>
-#include <sys/soundcard.h>
-#include <unistd.h>
-#include <fcntl.h>
-#include <sys/ioctl.h>
-#include <sys/mman.h>
-#include <sys/time.h>
-
-const char *audio_device = "/dev/dsp";
-
-#define AUDIO_BLOCK_SIZE 4096
-
-typedef struct {
- int fd;
- int sample_rate;
- int channels;
- int frame_size; /* in bytes ! */
- int codec_id;
- int flip_left : 1;
- UINT8 buffer[AUDIO_BLOCK_SIZE];
- int buffer_ptr;
-} AudioData;
-
-static int audio_open(AudioData *s, int is_output)
-{
- int audio_fd;
- int tmp, err;
- char *flip = getenv("AUDIO_FLIP_LEFT");
-
- /* open linux audio device */
- if (is_output)
- audio_fd = open(audio_device, O_WRONLY);
- else
- audio_fd = open(audio_device, O_RDONLY);
- if (audio_fd < 0) {
- perror(audio_device);
- return -EIO;
- }
-
- if (flip && *flip == '1') {
- s->flip_left = 1;
- }
-
- /* non blocking mode */
- if (!is_output)
- fcntl(audio_fd, F_SETFL, O_NONBLOCK);
-
- s->frame_size = AUDIO_BLOCK_SIZE;
-#if 0
- tmp = (NB_FRAGMENTS << 16) | FRAGMENT_BITS;
- err = ioctl(audio_fd, SNDCTL_DSP_SETFRAGMENT, &tmp);
- if (err < 0) {
- perror("SNDCTL_DSP_SETFRAGMENT");
- }
-#endif
-
- /* select format : favour native format */
- err = ioctl(audio_fd, SNDCTL_DSP_GETFMTS, &tmp);
-
-#ifdef WORDS_BIGENDIAN
- if (tmp & AFMT_S16_BE) {
- tmp = AFMT_S16_BE;
- } else if (tmp & AFMT_S16_LE) {
- tmp = AFMT_S16_LE;
- } else {
- tmp = 0;
- }
-#else
- if (tmp & AFMT_S16_LE) {
- tmp = AFMT_S16_LE;
- } else if (tmp & AFMT_S16_BE) {
- tmp = AFMT_S16_BE;
- } else {
- tmp = 0;
- }
-#endif
-
- switch(tmp) {
- case AFMT_S16_LE:
- s->codec_id = CODEC_ID_PCM_S16LE;
- break;
- case AFMT_S16_BE:
- s->codec_id = CODEC_ID_PCM_S16BE;
- break;
- default:
- fprintf(stderr, "Soundcard does not support 16 bit sample format\n");
- close(audio_fd);
- return -EIO;
- }
- err=ioctl(audio_fd, SNDCTL_DSP_SETFMT, &tmp);
- if (err < 0) {
- perror("SNDCTL_DSP_SETFMT");
- goto fail;
- }
-
- tmp = (s->channels == 2);
- err = ioctl(audio_fd, SNDCTL_DSP_STEREO, &tmp);
- if (err < 0) {
- perror("SNDCTL_DSP_STEREO");
- goto fail;
- }
- if (tmp)
- s->channels = 2;
-
- tmp = s->sample_rate;
- err = ioctl(audio_fd, SNDCTL_DSP_SPEED, &tmp);
- if (err < 0) {
- perror("SNDCTL_DSP_SPEED");
- goto fail;
- }
- s->sample_rate = tmp; /* store real sample rate */
- s->fd = audio_fd;
-
- return 0;
- fail:
- close(audio_fd);
- return -EIO;
-}
-
-static int audio_close(AudioData *s)
-{
- close(s->fd);
- return 0;
-}
-
-/* sound output support */
-static int audio_write_header(AVFormatContext *s1)
-{
- AudioData *s = s1->priv_data;
- AVStream *st;
- int ret;
-
- st = s1->streams[0];
- s->sample_rate = st->codec.sample_rate;
- s->channels = st->codec.channels;
- ret = audio_open(s, 1);
- if (ret < 0) {
- return -EIO;
- } else {
- return 0;
- }
-}
-
-static int audio_write_packet(AVFormatContext *s1, int stream_index,
- UINT8 *buf, int size, int force_pts)
-{
- AudioData *s = s1->priv_data;
- int len, ret;
-
- while (size > 0) {
- len = AUDIO_BLOCK_SIZE - s->buffer_ptr;
- if (len > size)
- len = size;
- memcpy(s->buffer + s->buffer_ptr, buf, len);
- s->buffer_ptr += len;
- if (s->buffer_ptr >= AUDIO_BLOCK_SIZE) {
- for(;;) {
- ret = write(s->fd, s->buffer, AUDIO_BLOCK_SIZE);
- if (ret > 0)
- break;
- if (ret < 0 && (errno != EAGAIN && errno != EINTR))
- return -EIO;
- }
- s->buffer_ptr = 0;
- }
- buf += len;
- size -= len;
- }
- return 0;
-}
-
-static int audio_write_trailer(AVFormatContext *s1)
-{
- AudioData *s = s1->priv_data;
-
- audio_close(s);
- return 0;
-}
-
-/* grab support */
-
-static int audio_read_header(AVFormatContext *s1, AVFormatParameters *ap)
-{
- AudioData *s = s1->priv_data;
- AVStream *st;
- int ret;
-
- if (!ap || ap->sample_rate <= 0 || ap->channels <= 0)
- return -1;
-
- st = av_new_stream(s1, 0);
- if (!st) {
- return -ENOMEM;
- }
- s->sample_rate = ap->sample_rate;
- s->channels = ap->channels;
-
- ret = audio_open(s, 0);
- if (ret < 0) {
- av_free(st);
- return -EIO;
- }
-
- /* take real parameters */
- st->codec.codec_type = CODEC_TYPE_AUDIO;
- st->codec.codec_id = s->codec_id;
- st->codec.sample_rate = s->sample_rate;
- st->codec.channels = s->channels;
-
- av_set_pts_info(s1, 48, 1, 1000000); /* 48 bits pts in us */
- return 0;
-}
-
-static int audio_read_packet(AVFormatContext *s1, AVPacket *pkt)
-{
- AudioData *s = s1->priv_data;
- int ret, bdelay;
- int64_t cur_time;
- struct audio_buf_info abufi;
-
- if (av_new_packet(pkt, s->frame_size) < 0)
- return -EIO;
- for(;;) {
- ret = read(s->fd, pkt->data, pkt->size);
- if (ret > 0)
- break;
- if (ret == -1 && (errno == EAGAIN || errno == EINTR)) {
- av_free_packet(pkt);
- pkt->size = 0;
- return 0;
- }
- if (!(ret == 0 || (ret == -1 && (errno == EAGAIN || errno == EINTR)))) {
- av_free_packet(pkt);
- return -EIO;
- }
- }
- pkt->size = ret;
-
- /* compute pts of the start of the packet */
- cur_time = av_gettime();
- bdelay = ret;
- if (ioctl(s->fd, SNDCTL_DSP_GETISPACE, &abufi) == 0) {
- bdelay += abufi.bytes;
- }
- /* substract time represented by the number of bytes in the audio fifo */
- cur_time -= (bdelay * 1000000LL) / (s->sample_rate * s->channels);
-
- /* convert to wanted units */
- pkt->pts = cur_time & ((1LL << 48) - 1);
-
- if (s->flip_left && s->channels == 2) {
- int i;
- short *p = (short *) pkt->data;
-
- for (i = 0; i < ret; i += 4) {
- *p = ~*p;
- p += 2;
- }
- }
- return 0;
-}
-
-static int audio_read_close(AVFormatContext *s1)
-{
- AudioData *s = s1->priv_data;
-
- audio_close(s);
- return 0;
-}
-
-static 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,
-};
-
-static 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 */
-#ifdef WORDS_BIGENDIAN
- CODEC_ID_PCM_S16BE,
-#else
- CODEC_ID_PCM_S16LE,
-#endif
- CODEC_ID_NONE,
- audio_write_header,
- audio_write_packet,
- audio_write_trailer,
- .flags = AVFMT_NOFILE,
-};
-
-int audio_init(void)
-{
- av_register_input_format(&audio_in_format);
- av_register_output_format(&audio_out_format);
- return 0;
-}
+++ /dev/null
-#ifndef AVFORMAT_H
-#define AVFORMAT_H
-
-#define LIBAVFORMAT_VERSION_INT 0x000406
-#define LIBAVFORMAT_VERSION "0.4.6"
-#define LIBAVFORMAT_BUILD 4602
-
-#include "avcodec.h"
-
-#include "avio.h"
-
-/* packet functions */
-
-#define AV_NOPTS_VALUE 0
-
-typedef struct AVPacket {
- INT64 pts; /* presentation time stamp in stream units (set av_set_pts_info) */
- UINT8 *data;
- int size;
- int stream_index;
- int flags;
- int duration;
-#define PKT_FLAG_KEY 0x0001
-} AVPacket;
-
-int av_new_packet(AVPacket *pkt, int size);
-void av_free_packet(AVPacket *pkt);
-
-/*************************************************/
-/* fractional numbers for exact pts handling */
-
-/* the exact value of the fractional number is: 'val + num / den'. num
- is assumed to be such as 0 <= num < den */
-typedef struct AVFrac {
- INT64 val, num, den;
-} AVFrac;
-
-void av_frac_init(AVFrac *f, INT64 val, INT64 num, INT64 den);
-void av_frac_add(AVFrac *f, INT64 incr);
-void av_frac_set(AVFrac *f, INT64 val);
-
-/*************************************************/
-/* input/output formats */
-
-struct AVFormatContext;
-
-/* this structure contains the data a format has to probe a file */
-typedef struct AVProbeData {
- char *filename;
- unsigned char *buf;
- int buf_size;
-} AVProbeData;
-
-#define AVPROBE_SCORE_MAX 100
-
-typedef struct AVFormatParameters {
- int frame_rate;
- int sample_rate;
- int channels;
- int width;
- int height;
- enum PixelFormat pix_fmt;
-} AVFormatParameters;
-
-#define AVFMT_NOFILE 0x0001 /* no file should be opened */
-#define AVFMT_NEEDNUMBER 0x0002 /* needs '%d' in filename */
-#define AVFMT_NOHEADER 0x0004 /* signal that no header is present
- (streams are added dynamically) */
-#define AVFMT_SHOW_IDS 0x0008 /* show format stream IDs numbers */
-#define AVFMT_RGB24 0x0010 /* force RGB24 output for ppm (hack
- - need better api) */
-#define AVFMT_RAWPICTURE 0x0020 /* format wants AVPicture structure for
- raw picture data */
-
-typedef struct AVOutputFormat {
- const char *name;
- const char *long_name;
- const char *mime_type;
- const char *extensions; /* comma separated extensions */
- /* size of private data so that it can be allocated in the wrapper */
- int priv_data_size;
- /* output support */
- enum CodecID audio_codec; /* default audio codec */
- enum CodecID video_codec; /* default video codec */
- int (*write_header)(struct AVFormatContext *);
- /* XXX: change prototype for 64 bit pts */
- int (*write_packet)(struct AVFormatContext *,
- int stream_index,
- unsigned char *buf, int size, int force_pts);
- int (*write_trailer)(struct AVFormatContext *);
- /* can use flags: AVFMT_NOFILE, AVFMT_NEEDNUMBER */
- int flags;
- /* private fields */
- struct AVOutputFormat *next;
-} AVOutputFormat;
-
-typedef struct AVInputFormat {
- const char *name;
- const char *long_name;
- /* size of private data so that it can be allocated in the wrapper */
- int priv_data_size;
- /* tell if a given file has a chance of being parsing by this format */
- int (*read_probe)(AVProbeData *);
- /* read the format header and initialize the AVFormatContext
- structure. Return 0 if OK. 'ap' if non NULL contains
- additionnal paramters. Only used in raw format right
- now. 'av_new_stream' should be called to create new streams. */
- int (*read_header)(struct AVFormatContext *,
- AVFormatParameters *ap);
- /* read one packet and put it in 'pkt'. pts and flags are also
- set. 'av_new_stream' can be called only if the flag
- AVFMT_NOHEADER is used. */
- int (*read_packet)(struct AVFormatContext *, AVPacket *pkt);
- /* close the stream. The AVFormatContext and AVStreams are not
- freed by this function */
- int (*read_close)(struct AVFormatContext *);
- /* seek at or before a given pts (given in microsecond). The pts
- origin is defined by the stream */
- int (*read_seek)(struct AVFormatContext *, INT64 pts);
- /* can use flags: AVFMT_NOFILE, AVFMT_NEEDNUMBER, AVFMT_NOHEADER */
- int flags;
- /* if extensions are defined, then no probe is done. You should
- usually not use extension format guessing because it is not
- reliable enough */
- const char *extensions;
- /* general purpose read only value that the format can use */
- int value;
- /* private fields */
- struct AVInputFormat *next;
-} AVInputFormat;
-
-typedef struct AVStream {
- int index; /* stream index in AVFormatContext */
- int id; /* format specific stream id */
- AVCodecContext codec; /* codec context */
- int r_frame_rate; /* real frame rate of the stream */
- uint64_t time_length; /* real length of the stream in miliseconds */
- void *priv_data;
- /* internal data used in av_find_stream_info() */
- int codec_info_state;
- int codec_info_nb_repeat_frames;
- int codec_info_nb_real_frames;
- /* PTS generation when outputing stream */
- AVFrac pts;
- /* ffmpeg.c private use */
- int stream_copy; /* if TRUE, just copy stream */
-} AVStream;
-
-#define MAX_STREAMS 20
-
-/* format I/O context */
-typedef struct AVFormatContext {
- /* can only be iformat or oformat, not both at the same time */
- struct AVInputFormat *iformat;
- struct AVOutputFormat *oformat;
- void *priv_data;
- ByteIOContext pb;
- int nb_streams;
- AVStream *streams[MAX_STREAMS];
- char filename[1024]; /* input or output filename */
- /* stream info */
- char title[512];
- char author[512];
- char copyright[512];
- char comment[512];
- int flags; /* format specific flags */
- /* private data for pts handling (do not modify directly) */
- int pts_wrap_bits; /* number of bits in pts (used for wrapping control) */
- int pts_num, pts_den; /* value to convert to seconds */
- /* This buffer is only needed when packets were already buffered but
- not decoded, for example to get the codec parameters in mpeg
- streams */
- struct AVPacketList *packet_buffer;
-} AVFormatContext;
-
-typedef struct AVPacketList {
- AVPacket pkt;
- struct AVPacketList *next;
-} AVPacketList;
-
-extern AVInputFormat *first_iformat;
-extern AVOutputFormat *first_oformat;
-
-/* XXX: use automatic init with either ELF sections or C file parser */
-/* modules */
-
-/* mpeg.c */
-int mpegps_init(void);
-
-/* mpegts.c */
-extern AVInputFormat mpegts_demux;
-int mpegts_init(void);
-
-/* rm.c */
-int rm_init(void);
-
-/* crc.c */
-int crc_init(void);
-
-/* img.c */
-int img_init(void);
-
-/* asf.c */
-int asf_init(void);
-
-/* avienc.c */
-int avienc_init(void);
-
-/* avidec.c */
-int avidec_init(void);
-
-/* swf.c */
-int swf_init(void);
-
-/* mov.c */
-int mov_init(void);
-
-/* jpeg.c */
-int jpeg_init(void);
-
-/* gif.c */
-int gif_init(void);
-
-/* au.c */
-int au_init(void);
-
-/* wav.c */
-int wav_init(void);
-
-/* raw.c */
-int raw_init(void);
-
-/* ogg.c */
-int ogg_init(void);
-
-/* dv.c */
-int dv_init(void);
-
-/* ffm.c */
-int ffm_init(void);
-
-/* rtsp.c */
-extern AVInputFormat redir_demux;
-int redir_open(AVFormatContext **ic_ptr, ByteIOContext *f);
-
-#include "rtp.h"
-
-#include "rtsp.h"
-
-/* utils.c */
-#define MKTAG(a,b,c,d) (a | (b << 8) | (c << 16) | (d << 24))
-#define MKBETAG(a,b,c,d) (d | (c << 8) | (b << 16) | (a << 24))
-
-void av_register_input_format(AVInputFormat *format);
-void av_register_output_format(AVOutputFormat *format);
-AVOutputFormat *guess_stream_format(const char *short_name,
- const char *filename, const char *mime_type);
-AVOutputFormat *guess_format(const char *short_name,
- const char *filename, const char *mime_type);
-
-void av_hex_dump(UINT8 *buf, int size);
-
-void av_register_all(void);
-
-typedef struct FifoBuffer {
- UINT8 *buffer;
- UINT8 *rptr, *wptr, *end;
-} FifoBuffer;
-
-int fifo_init(FifoBuffer *f, int size);
-void fifo_free(FifoBuffer *f);
-int fifo_size(FifoBuffer *f, UINT8 *rptr);
-int fifo_read(FifoBuffer *f, UINT8 *buf, int buf_size, UINT8 **rptr_ptr);
-void fifo_write(FifoBuffer *f, UINT8 *buf, int size, UINT8 **wptr_ptr);
-
-/* media file input */
-AVInputFormat *av_find_input_format(const char *short_name);
-AVInputFormat *av_probe_input_format(AVProbeData *pd, int is_opened);
-int av_open_input_file(AVFormatContext **ic_ptr, const char *filename,
- AVInputFormat *fmt,
- int buf_size,
- AVFormatParameters *ap);
-
-#define AVERROR_UNKNOWN (-1) /* unknown error */
-#define AVERROR_IO (-2) /* i/o error */
-#define AVERROR_NUMEXPECTED (-3) /* number syntax expected in filename */
-#define AVERROR_INVALIDDATA (-4) /* invalid data found */
-#define AVERROR_NOMEM (-5) /* not enough memory */
-#define AVERROR_NOFMT (-6) /* unknown format */
-
-int av_find_stream_info(AVFormatContext *ic);
-int av_read_packet(AVFormatContext *s, AVPacket *pkt);
-void av_close_input_file(AVFormatContext *s);
-AVStream *av_new_stream(AVFormatContext *s, int id);
-void av_set_pts_info(AVFormatContext *s, int pts_wrap_bits,
- int pts_num, int pts_den);
-
-/* media file output */
-int av_write_header(AVFormatContext *s);
-int av_write_frame(AVFormatContext *s, int stream_index, const uint8_t *buf,
- int size);
-int av_write_trailer(AVFormatContext *s);
-
-void dump_format(AVFormatContext *ic,
- int index,
- const char *url,
- int is_output);
-int parse_image_size(int *width_ptr, int *height_ptr, const char *str);
-INT64 parse_date(const char *datestr, int duration);
-
-INT64 av_gettime(void);
-
-/* ffm specific for ffserver */
-#define FFM_PACKET_SIZE 4096
-offset_t ffm_read_write_index(int fd);
-void ffm_write_write_index(int fd, offset_t pos);
-void ffm_set_write_index(AVFormatContext *s, offset_t pos, offset_t file_size);
-
-int find_info_tag(char *arg, int arg_size, const char *tag1, const char *info);
-
-int get_frame_filename(char *buf, int buf_size,
- const char *path, int number);
-int filename_number_test(const char *filename);
-
-/* grab specific */
-int video_grab_init(void);
-int audio_init(void);
-
-extern const char *v4l_device;
-extern const char *audio_device;
-
-#ifdef HAVE_AV_CONFIG_H
-int strstart(const char *str, const char *val, const char **ptr);
-int stristart(const char *str, const char *val, const char **ptr);
-void pstrcpy(char *buf, int buf_size, const char *str);
-char *pstrcat(char *buf, int buf_size, const char *s);
-
-struct in_addr;
-int resolve_host(struct in_addr *sin_addr, const char *hostname);
-
-void url_split(char *proto, int proto_size,
- char *hostname, int hostname_size,
- int *port_ptr,
- char *path, int path_size,
- const char *url);
-
-int match_ext(const char *filename, const char *extensions);
-
-#endif /* HAVE_AV_CONFIG_H */
-
-#endif /* AVFORMAT_H */
+++ /dev/null
-
-#define AVIF_HASINDEX 0x00000010 // Index at end of file?
-#define AVIF_MUSTUSEINDEX 0x00000020
-#define AVIF_ISINTERLEAVED 0x00000100
-#define AVIF_TRUSTCKTYPE 0x00000800 // Use CKType to find key frames?
-#define AVIF_WASCAPTUREFILE 0x00010000
-#define AVIF_COPYRIGHTED 0x00020000
-
-offset_t start_tag(ByteIOContext *pb, const char *tag);
-void end_tag(ByteIOContext *pb, offset_t start);
-
-typedef struct CodecTag {
- int id;
- unsigned int tag;
- unsigned int invalid_asf : 1;
-} CodecTag;
-
-void put_bmp_header(ByteIOContext *pb, AVCodecContext *enc, const CodecTag *tags, int for_asf);
-int put_wav_header(ByteIOContext *pb, AVCodecContext *enc);
-int wav_codec_get_id(unsigned int tag, int bps);
-void get_wav_header(ByteIOContext *pb, AVCodecContext *codec,
- int has_extra_data);
-
-extern const CodecTag codec_bmp_tags[];
-extern const CodecTag codec_wav_tags[];
-
-unsigned int codec_get_tag(const CodecTag *tags, int id);
-int codec_get_id(const CodecTag *tags, unsigned int tag);
+++ /dev/null
-/*
- * AVI decoder.
- * Copyright (c) 2001 Fabrice Bellard.
- *
- * This library 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 of the License, or (at your option) any later version.
- *
- * This library 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 this library; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
-#include "avformat.h"
-#include "avi.h"
-
-//#define DEBUG
-
-typedef struct AVIIndex {
- unsigned char tag[4];
- unsigned int flags, pos, len;
- struct AVIIndex *next;
-} AVIIndex;
-
-typedef struct {
- INT64 movi_end;
- offset_t movi_list;
- AVIIndex *first, *last;
-} AVIContext;
-
-#ifdef DEBUG
-static void print_tag(const char *str, unsigned int tag, int size)
-{
- printf("%s: tag=%c%c%c%c size=0x%x\n",
- str, tag & 0xff,
- (tag >> 8) & 0xff,
- (tag >> 16) & 0xff,
- (tag >> 24) & 0xff,
- size);
-}
-#endif
-
-static int avi_read_header(AVFormatContext *s, AVFormatParameters *ap)
-{
- AVIContext *avi = s->priv_data;
- ByteIOContext *pb = &s->pb;
- UINT32 tag, tag1;
- int codec_type, stream_index, size, frame_period, bit_rate;
- int i;
- AVStream *st;
-
- /* check RIFF header */
- tag = get_le32(pb);
-
- if (tag != MKTAG('R', 'I', 'F', 'F'))
- return -1;
- get_le32(pb); /* file size */
- tag = get_le32(pb);
- if (tag != MKTAG('A', 'V', 'I', ' '))
- return -1;
-
- /* first list tag */
- stream_index = -1;
- codec_type = -1;
- frame_period = 0;
- for(;;) {
- if (url_feof(pb))
- goto fail;
- tag = get_le32(pb);
- size = get_le32(pb);
-#ifdef DEBUG
- print_tag("tag", tag, size);
-#endif
-
- switch(tag) {
- case MKTAG('L', 'I', 'S', 'T'):
- /* ignored, except when start of video packets */
- tag1 = get_le32(pb);
-#ifdef DEBUG
- print_tag("list", tag1, 0);
-#endif
- if (tag1 == MKTAG('m', 'o', 'v', 'i')) {
- avi->movi_end = url_ftell(pb) + size - 4;
-#ifdef DEBUG
- printf("movi end=%Lx\n", avi->movi_end);
-#endif
- goto end_of_header;
- }
- break;
- case MKTAG('a', 'v', 'i', 'h'):
- /* avi header */
- /* using frame_period is bad idea */
- frame_period = get_le32(pb);
- bit_rate = get_le32(pb) * 8;
- url_fskip(pb, 4 * 4);
- s->nb_streams = get_le32(pb);
- for(i=0;i<s->nb_streams;i++) {
- AVStream *st = av_mallocz(sizeof(AVStream));
- if (!st)
- goto fail;
- s->streams[i] = st;
- }
- url_fskip(pb, size - 7 * 4);
- break;
- case MKTAG('s', 't', 'r', 'h'):
- /* stream header */
- stream_index++;
- tag1 = get_le32(pb);
- switch(tag1) {
- case MKTAG('v', 'i', 'd', 's'):
- codec_type = CODEC_TYPE_VIDEO;
- get_le32(pb); /* codec tag */
- get_le32(pb); /* flags */
- get_le16(pb); /* priority */
- get_le16(pb); /* language */
- get_le32(pb); /* XXX: initial frame ? */
- get_le32(pb); /* scale */
- get_le32(pb); /* rate */
- size -= 6 * 4;
- break;
- case MKTAG('a', 'u', 'd', 's'):
- codec_type = CODEC_TYPE_AUDIO;
- /* nothing really useful */
- }
- url_fskip(pb, size - 4);
- break;
- case MKTAG('s', 't', 'r', 'f'):
- /* stream header */
- if (stream_index >= s->nb_streams) {
- url_fskip(pb, size);
- } else {
- st = s->streams[stream_index];
- switch(codec_type) {
- case CODEC_TYPE_VIDEO:
- get_le32(pb); /* size */
- st->codec.width = get_le32(pb);
- st->codec.height = get_le32(pb);
- if (frame_period)
- st->codec.frame_rate = (INT64_C(1000000) * FRAME_RATE_BASE) / frame_period;
- else
- st->codec.frame_rate = 25 * FRAME_RATE_BASE;
- get_le16(pb); /* panes */
- get_le16(pb); /* depth */
- tag1 = get_le32(pb);
-#ifdef DEBUG
- print_tag("video", tag1, 0);
-#endif
- st->codec.codec_type = CODEC_TYPE_VIDEO;
- st->codec.codec_tag = tag1;
- st->codec.codec_id = codec_get_id(codec_bmp_tags, tag1);
- url_fskip(pb, size - 5 * 4);
- break;
- case CODEC_TYPE_AUDIO:
- get_wav_header(pb, &st->codec, (size >= 18));
- break;
- default:
- url_fskip(pb, size);
- break;
- }
- }
- break;
- default:
- /* skip tag */
- size += (size & 1);
- url_fskip(pb, size);
- break;
- }
- }
- end_of_header:
- /* check stream number */
- if (stream_index != s->nb_streams - 1) {
- fail:
- for(i=0;i<s->nb_streams;i++) {
- av_freep(&s->streams[i]);
- }
- return -1;
- }
-
- return 0;
-}
-
-static int avi_read_packet(AVFormatContext *s, AVPacket *pkt)
-{
- AVIContext *avi = s->priv_data;
- ByteIOContext *pb = &s->pb;
- int n, d1, d2, size;
-
- for(;;) {
- if (url_feof(pb) || url_ftell(pb) >= avi->movi_end)
- return -1;
- d1 = get_byte(pb) - '0';
- d2 = get_byte(pb) - '0';
- if (d1 < 0 || d1 > 9 || d2 < 0 || d2 > 9)
- continue;
-
- n = d1 * 10 + d2;
- if (n < 0 || n >= s->nb_streams)
- continue;
-
- d1 = get_byte(pb);
- d2 = get_byte(pb);
- if ((d1 == 'd' && d2 == 'c')
- || (d1 == 'w' && d2 == 'b'))
- break;
- }
- size = get_le32(pb);
- av_new_packet(pkt, size);
- pkt->stream_index = n;
-
- get_buffer(pb, pkt->data, pkt->size);
-
- if (size & 1)
- get_byte(pb);
-
- return 0;
-}
-
-static int avi_read_close(AVFormatContext *s)
-{
- 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;
-}
+++ /dev/null
-/*
- * AVI encoder.
- * Copyright (c) 2000 Fabrice Bellard.
- *
- * This library 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 of the License, or (at your option) any later version.
- *
- * This library 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 this library; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
-#include "avformat.h"
-#include "avi.h"
-
-/*
- * TODO:
- * - fill all fields if non streamed (nb_frames for example)
- */
-
-typedef struct AVIIndex {
- unsigned char tag[4];
- unsigned int flags, pos, len;
- struct AVIIndex *next;
-} AVIIndex;
-
-typedef struct {
- offset_t movi_list, frames_hdr_all, frames_hdr_strm[MAX_STREAMS];
- int audio_strm_length[MAX_STREAMS];
- AVIIndex *first, *last;
-} AVIContext;
-
-offset_t start_tag(ByteIOContext *pb, const char *tag)
-{
- put_tag(pb, tag);
- put_le32(pb, 0);
- return url_ftell(pb);
-}
-
-void end_tag(ByteIOContext *pb, offset_t start)
-{
- offset_t pos;
-
- pos = url_ftell(pb);
- url_fseek(pb, start - 4, SEEK_SET);
- put_le32(pb, (UINT32)(pos - start));
- url_fseek(pb, pos, SEEK_SET);
-}
-
-/* Note: when encoding, the first matching tag is used, so order is
- important if multiple tags possible for a given codec. */
-const CodecTag codec_bmp_tags[] = {
- { CODEC_ID_H263, MKTAG('H', '2', '6', '3') },
- { CODEC_ID_H263P, MKTAG('H', '2', '6', '3') },
- { CODEC_ID_H263I, MKTAG('I', '2', '6', '3') }, /* intel h263 */
- { CODEC_ID_MJPEG, MKTAG('M', 'J', 'P', 'G') },
- { CODEC_ID_MPEG4, MKTAG('D', 'I', 'V', 'X'), .invalid_asf = 1 },
- { CODEC_ID_MPEG4, MKTAG('d', 'i', 'v', 'x'), .invalid_asf = 1 },
- { CODEC_ID_MPEG4, MKTAG('D', 'X', '5', '0'), .invalid_asf = 1 },
- { CODEC_ID_MPEG4, MKTAG('X', 'V', 'I', 'D'), .invalid_asf = 1 },
- { CODEC_ID_MPEG4, MKTAG('x', 'v', 'i', 'd'), .invalid_asf = 1 },
- { CODEC_ID_MPEG4, MKTAG('m', 'p', '4', 's'), .invalid_asf = 1 },
- { CODEC_ID_MPEG4, MKTAG('M', 'P', '4', 'S') },
- { CODEC_ID_MPEG4, MKTAG('M', '4', 'S', '2') },
- { CODEC_ID_MPEG4, MKTAG('m', '4', 's', '2') },
- { CODEC_ID_MPEG4, MKTAG(0x04, 0, 0, 0) }, /* some broken avi use this */
- { CODEC_ID_MSMPEG4V3, MKTAG('D', 'I', 'V', '3'), .invalid_asf = 1 }, /* default signature when using MSMPEG4 */
- { CODEC_ID_MSMPEG4V3, MKTAG('d', 'i', 'v', '3'), .invalid_asf = 1 },
- { CODEC_ID_MSMPEG4V3, MKTAG('M', 'P', '4', '3') },
- { CODEC_ID_MSMPEG4V2, MKTAG('M', 'P', '4', '2') },
- { CODEC_ID_MSMPEG4V1, MKTAG('M', 'P', 'G', '4') },
- { CODEC_ID_WMV1, MKTAG('W', 'M', 'V', '1') },
- { CODEC_ID_DVVIDEO, MKTAG('d', 'v', 's', 'l') },
- { CODEC_ID_DVVIDEO, MKTAG('d', 'v', 's', 'd') },
- { CODEC_ID_DVVIDEO, MKTAG('D', 'V', 'S', 'D') },
- { CODEC_ID_DVVIDEO, MKTAG('d', 'v', 'h', 'd') },
- { CODEC_ID_MPEG1VIDEO, MKTAG('m', 'p', 'g', '1') },
- { CODEC_ID_MPEG1VIDEO, MKTAG('m', 'p', 'g', '2') },
- { CODEC_ID_MPEG1VIDEO, MKTAG('P', 'I', 'M', '1') },
- { CODEC_ID_MJPEG, MKTAG('M', 'J', 'P', 'G') },
- { 0, 0 },
-};
-
-unsigned int codec_get_tag(const CodecTag *tags, int id)
-{
- while (tags->id != 0) {
- if (tags->id == id)
- return tags->tag;
- tags++;
- }
- return 0;
-}
-
-static unsigned int codec_get_asf_tag(const CodecTag *tags, int id)
-{
- while (tags->id != 0) {
- if (!tags->invalid_asf && tags->id == id)
- return tags->tag;
- tags++;
- }
- return 0;
-}
-
-int codec_get_id(const CodecTag *tags, unsigned int tag)
-{
- while (tags->id != 0) {
- if (tags->tag == tag)
- return tags->id;
- tags++;
- }
- return 0;
-}
-
-unsigned int codec_get_bmp_tag(int id)
-{
- return codec_get_tag(codec_bmp_tags, id);
-}
-
-/* BITMAPINFOHEADER header */
-void put_bmp_header(ByteIOContext *pb, AVCodecContext *enc, const CodecTag *tags, int for_asf)
-{
- put_le32(pb, 40); /* size */
- put_le32(pb, enc->width);
- put_le32(pb, enc->height);
- put_le16(pb, 1); /* planes */
- put_le16(pb, 24); /* depth */
- /* compression type */
- put_le32(pb, for_asf ? codec_get_asf_tag(tags, enc->codec_id) : codec_get_tag(tags, enc->codec_id));
- put_le32(pb, enc->width * enc->height * 3);
- put_le32(pb, 0);
- put_le32(pb, 0);
- put_le32(pb, 0);
- put_le32(pb, 0);
-}
-
-static void parse_specific_params(AVCodecContext *stream, int *au_byterate, int *au_ssize, int *au_scale)
-{
- switch(stream->codec_id) {
- case CODEC_ID_PCM_S16LE:
- *au_scale = *au_ssize = 2*stream->channels;
- *au_byterate = *au_ssize * stream->sample_rate;
- break;
- case CODEC_ID_PCM_U8:
- case CODEC_ID_PCM_ALAW:
- case CODEC_ID_PCM_MULAW:
- *au_scale = *au_ssize = stream->channels;
- *au_byterate = *au_ssize * stream->sample_rate;
- break;
- case CODEC_ID_MP2:
- *au_ssize = 1;
- *au_scale = 1;
- *au_byterate = stream->bit_rate / 8;
- case CODEC_ID_MP3LAME:
- *au_ssize = 1;
- *au_scale = 1;
- *au_byterate = stream->bit_rate / 8;
- default:
- *au_ssize = 1;
- *au_scale = 1;
- *au_byterate = stream->bit_rate / 8;
- break;
- }
-}
-
-static int avi_write_header(AVFormatContext *s)
-{
- 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;
-
- put_tag(pb, "RIFF");
- put_le32(pb, 0); /* file length */
- put_tag(pb, "AVI ");
-
- /* header list */
- list1 = start_tag(pb, "LIST");
- put_tag(pb, "hdrl");
-
- /* avi header */
- put_tag(pb, "avih");
- put_le32(pb, 14 * 4);
- bitrate = 0;
-
- video_enc = NULL;
- for(n=0;n<s->nb_streams;n++) {
- stream = &s->streams[n]->codec;
- bitrate += stream->bit_rate;
- if (stream->codec_type == CODEC_TYPE_VIDEO)
- video_enc = stream;
- }
-
- if (!video_enc) {
- av_free(avi);
- return -1;
- }
- nb_frames = 0;
-
- put_le32(pb, (UINT32)(INT64_C(1000000) * FRAME_RATE_BASE / video_enc->frame_rate));
- put_le32(pb, bitrate / 8); /* XXX: not quite exact */
- put_le32(pb, 0); /* padding */
- put_le32(pb, AVIF_TRUSTCKTYPE | AVIF_HASINDEX | AVIF_ISINTERLEAVED); /* flags */
- avi->frames_hdr_all = url_ftell(pb); /* remember this offset to fill later */
- put_le32(pb, nb_frames); /* nb frames, filled later */
- put_le32(pb, 0); /* initial frame */
- put_le32(pb, s->nb_streams); /* nb streams */
- put_le32(pb, 1024 * 1024); /* suggested buffer size */
- put_le32(pb, video_enc->width);
- put_le32(pb, video_enc->height);
- put_le32(pb, 0); /* reserved */
- put_le32(pb, 0); /* reserved */
- put_le32(pb, 0); /* reserved */
- put_le32(pb, 0); /* reserved */
-
- /* stream list */
- for(i=0;i<n;i++) {
- list2 = start_tag(pb, "LIST");
- put_tag(pb, "strl");
-
- stream = &s->streams[i]->codec;
-
- /* stream generic header */
- strh = start_tag(pb, "strh");
- switch(stream->codec_type) {
- case CODEC_TYPE_VIDEO:
- put_tag(pb, "vids");
- put_le32(pb, codec_get_bmp_tag(stream->codec_id));
- put_le32(pb, 0); /* flags */
- put_le16(pb, 0); /* priority */
- put_le16(pb, 0); /* language */
- put_le32(pb, 0); /* initial frame */
- put_le32(pb, 1000); /* scale */
- put_le32(pb, (1000 * stream->frame_rate) / FRAME_RATE_BASE); /* rate */
- put_le32(pb, 0); /* start */
- avi->frames_hdr_strm[i] = url_ftell(pb); /* remember this offset to fill later */
- put_le32(pb, nb_frames); /* length, XXX: fill later */
- put_le32(pb, 1024 * 1024); /* suggested buffer size */
- put_le32(pb, -1); /* quality */
- put_le32(pb, stream->width * stream->height * 3); /* sample size */
- put_le16(pb, 0);
- put_le16(pb, 0);
- put_le16(pb, stream->width);
- put_le16(pb, stream->height);
- break;
- case CODEC_TYPE_AUDIO:
- put_tag(pb, "auds");
- put_le32(pb, 1); /* tag */
- put_le32(pb, 0); /* flags */
- put_le16(pb, 0); /* priority */
- put_le16(pb, 0); /* language */
- put_le32(pb, 0); /* initial frame */
- parse_specific_params(stream, &au_byterate, &au_ssize, &au_scale);
- put_le32(pb, au_scale); /* scale */
- put_le32(pb, au_byterate); /* rate */
- put_le32(pb, 0); /* start */
- avi->frames_hdr_strm[i] = url_ftell(pb); /* remember this offset to fill later */
- put_le32(pb, 0); /* length, XXX: filled later */
- put_le32(pb, 12 * 1024); /* suggested buffer size */
- put_le32(pb, -1); /* quality */
- put_le32(pb, au_ssize); /* sample size */
- put_le32(pb, 0);
- put_le32(pb, 0);
- break;
- default:
- av_abort();
- }
- end_tag(pb, strh);
-
- strf = start_tag(pb, "strf");
- switch(stream->codec_type) {
- case CODEC_TYPE_VIDEO:
- put_bmp_header(pb, stream, codec_bmp_tags, 0);
- break;
- case CODEC_TYPE_AUDIO:
- if (put_wav_header(pb, stream) < 0) {
- av_free(avi);
- return -1;
- }
- break;
- default:
- av_abort();
- }
- end_tag(pb, strf);
- end_tag(pb, list2);
- }
-
- end_tag(pb, list1);
-
- avi->movi_list = start_tag(pb, "LIST");
- avi->first = NULL;
- avi->last = NULL;
- put_tag(pb, "movi");
-
- put_flush_packet(pb);
-
- return 0;
-}
-
-static int avi_write_packet(AVFormatContext *s, int stream_index,
- UINT8 *buf, int size, int force_pts)
-{
- AVIContext *avi = s->priv_data;
- ByteIOContext *pb = &s->pb;
- AVIIndex *idx;
- unsigned char tag[5];
- unsigned int flags;
- AVCodecContext *enc;
-
- enc = &s->streams[stream_index]->codec;
-
- tag[0] = '0';
- tag[1] = '0' + stream_index;
- if (enc->codec_type == CODEC_TYPE_VIDEO) {
- tag[2] = 'd';
- tag[3] = 'c';
- flags = enc->key_frame ? 0x10 : 0x00;
- } else {
- tag[2] = 'w';
- tag[3] = 'b';
- flags = 0x10;
- }
- if (enc->codec_type == CODEC_TYPE_AUDIO)
- avi->audio_strm_length[stream_index] += size;
-
- if (!url_is_streamed(&s->pb)) {
- idx = av_malloc(sizeof(AVIIndex));
- memcpy(idx->tag, tag, 4);
- idx->flags = flags;
- idx->pos = url_ftell(pb) - avi->movi_list;
- idx->len = size;
- idx->next = NULL;
- if (!avi->last)
- avi->first = idx;
- else
- avi->last->next = idx;
- avi->last = idx;
- }
-
- put_buffer(pb, tag, 4);
- put_le32(pb, size);
- put_buffer(pb, buf, size);
- if (size & 1)
- put_byte(pb, 0);
-
- put_flush_packet(pb);
- return 0;
-}
-
-static int avi_write_trailer(AVFormatContext *s)
-{
- ByteIOContext *pb = &s->pb;
- AVIContext *avi = s->priv_data;
- offset_t file_size, idx_chunk;
- int n, nb_frames, au_byterate, au_ssize, au_scale;
- AVCodecContext *stream;
- AVIIndex *idx;
-
- if (!url_is_streamed(&s->pb)) {
- end_tag(pb, avi->movi_list);
-
- idx_chunk = start_tag(pb, "idx1");
- idx = avi->first;
- while (idx != NULL) {
- put_buffer(pb, idx->tag, 4);
- put_le32(pb, idx->flags);
- put_le32(pb, idx->pos);
- put_le32(pb, idx->len);
- idx = idx->next;
- }
- end_tag(pb, idx_chunk);
-
- /* update file size */
- file_size = url_ftell(pb);
- url_fseek(pb, 4, SEEK_SET);
- put_le32(pb, (UINT32)(file_size - 8));
-
- /* Fill in frame/sample counters */
- nb_frames = 0;
- for(n=0;n<s->nb_streams;n++) {
- if (avi->frames_hdr_strm[n] != 0) {
- stream = &s->streams[n]->codec;
- url_fseek(pb, avi->frames_hdr_strm[n], SEEK_SET);
- if (stream->codec_type == CODEC_TYPE_VIDEO) {
- put_le32(pb, stream->frame_number);
- if (nb_frames < stream->frame_number)
- nb_frames = stream->frame_number;
- } else {
- if (stream->codec_id == CODEC_ID_MP2 || stream->codec_id == CODEC_ID_MP3LAME) {
- put_le32(pb, stream->frame_number);
- nb_frames += stream->frame_number;
- } else {
- parse_specific_params(stream, &au_byterate, &au_ssize, &au_scale);
- put_le32(pb, avi->audio_strm_length[n] / au_ssize);
- }
- }
- }
- }
- if (avi->frames_hdr_all != 0) {
- url_fseek(pb, avi->frames_hdr_all, SEEK_SET);
- put_le32(pb, nb_frames);
- }
- url_fseek(pb, file_size, SEEK_SET);
- }
- put_flush_packet(pb);
- return 0;
-}
-
-static AVOutputFormat avi_oformat = {
- "avi",
- "avi format",
- "video/x-msvideo",
- "avi",
- sizeof(AVIContext),
- CODEC_ID_MP2,
- CODEC_ID_MSMPEG4V3,
- avi_write_header,
- avi_write_packet,
- avi_write_trailer,
-};
-
-int avienc_init(void)
-{
- av_register_output_format(&avi_oformat);
- return 0;
-}
+++ /dev/null
-/*
- * Unbuffered io for ffmpeg system
- * Copyright (c) 2001 Fabrice Bellard
- *
- * This library 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 of the License, or (at your option) any later version.
- *
- * This library 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 this library; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
-#include "avformat.h"
-
-URLProtocol *first_protocol = NULL;
-
-int register_protocol(URLProtocol *protocol)
-{
- URLProtocol **p;
- p = &first_protocol;
- while (*p != NULL) p = &(*p)->next;
- *p = protocol;
- protocol->next = NULL;
- return 0;
-}
-
-int url_open(URLContext **puc, const char *filename, int flags)
-{
- URLContext *uc;
- URLProtocol *up;
- const char *p;
- char proto_str[128], *q;
- int err;
-
- p = filename;
- q = proto_str;
- while (*p != '\0' && *p != ':') {
- if ((q - proto_str) < sizeof(proto_str) - 1)
- *q++ = *p;
- p++;
- }
- /* if the protocol has length 1, we consider it is a dos drive */
- if (*p == '\0' || (q - proto_str) <= 1) {
- strcpy(proto_str, "file");
- } else {
- *q = '\0';
- }
-
- up = first_protocol;
- while (up != NULL) {
- if (!strcmp(proto_str, up->name))
- goto found;
- up = up->next;
- }
- err = -ENOENT;
- goto fail;
- found:
- uc = av_malloc(sizeof(URLContext));
- if (!uc) {
- err = -ENOMEM;
- goto fail;
- }
- uc->prot = up;
- uc->flags = flags;
- uc->is_streamed = 0; /* default = not streamed */
- uc->max_packet_size = 0; /* default: stream file */
- err = up->url_open(uc, filename, flags);
- if (err < 0) {
- av_free(uc);
- *puc = NULL;
- return err;
- }
- *puc = uc;
- return 0;
- fail:
- *puc = NULL;
- return err;
-}
-
-int url_read(URLContext *h, unsigned char *buf, int size)
-{
- int ret;
- if (h->flags & URL_WRONLY)
- return -EIO;
- ret = h->prot->url_read(h, buf, size);
- return ret;
-}
-
-int url_write(URLContext *h, unsigned char *buf, int size)
-{
- int ret;
- if (!(h->flags & (URL_WRONLY | URL_RDWR)))
- return -EIO;
- /* avoid sending too big packets */
- if (h->max_packet_size && size > h->max_packet_size)
- return -EIO;
- ret = h->prot->url_write(h, buf, size);
- return ret;
-}
-
-offset_t url_seek(URLContext *h, offset_t pos, int whence)
-{
- offset_t ret;
-
- if (!h->prot->url_seek)
- return -EPIPE;
- ret = h->prot->url_seek(h, pos, whence);
- return ret;
-}
-
-int url_close(URLContext *h)
-{
- int ret;
-
- ret = h->prot->url_close(h);
- av_free(h);
- return ret;
-}
-
-int url_exist(const char *filename)
-{
- URLContext *h;
- if (url_open(&h, filename, URL_RDONLY) < 0)
- return 0;
- url_close(h);
- return 1;
-}
-
-offset_t url_filesize(URLContext *h)
-{
- offset_t pos, size;
-
- pos = url_seek(h, 0, SEEK_CUR);
- size = url_seek(h, 0, SEEK_END);
- url_seek(h, pos, SEEK_SET);
- return size;
-}
-
-/*
- * Return the maximum packet size associated to packetized file
- * handle. If the file is not packetized (stream like http or file on
- * disk), then 0 is returned.
- *
- * @param h file handle
- * @return maximum packet size in bytes
- */
-int url_get_max_packet_size(URLContext *h)
-{
- return h->max_packet_size;
-}
+++ /dev/null
-#ifndef AVIO_H
-#define AVIO_H
-
-/* output byte stream handling */
-
-typedef INT64 offset_t;
-
-/* unbuffered I/O */
-
-struct URLContext {
- struct URLProtocol *prot;
- int flags;
- int is_streamed; /* true if streamed (no seek possible), default = false */
- int max_packet_size; /* if non zero, the stream is packetized with this max packet size */
- void *priv_data;
-};
-
-typedef struct URLContext URLContext;
-
-typedef struct URLPollEntry {
- URLContext *handle;
- int events;
- int revents;
-} URLPollEntry;
-
-#define URL_RDONLY 0
-#define URL_WRONLY 1
-#define URL_RDWR 2
-
-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_close(URLContext *h);
-int url_exist(const char *filename);
-offset_t url_filesize(URLContext *h);
-int url_get_max_packet_size(URLContext *h);
-/* not implemented */
-int url_poll(URLPollEntry *poll_table, int n, int timeout);
-
-typedef struct URLProtocol {
- const char *name;
- 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_close)(URLContext *h);
- struct URLProtocol *next;
-} URLProtocol;
-
-extern URLProtocol *first_protocol;
-
-int register_protocol(URLProtocol *protocol);
-
-typedef struct {
- unsigned char *buffer;
- int buffer_size;
- unsigned char *buf_ptr, *buf_end;
- void *opaque;
- int (*read_packet)(void *opaque, UINT8 *buf, int buf_size);
- void (*write_packet)(void *opaque, UINT8 *buf, int buf_size);
- int (*seek)(void *opaque, offset_t offset, int whence);
- offset_t pos; /* position in the file of the current buffer */
- int must_flush; /* true if the next seek should flush */
- int eof_reached; /* true if eof reached */
- int write_flag; /* true if open for writing */
- int is_streamed;
- int max_packet_size;
-} ByteIOContext;
-
-int init_put_byte(ByteIOContext *s,
- unsigned char *buffer,
- int buffer_size,
- int write_flag,
- void *opaque,
- int (*read_packet)(void *opaque, UINT8 *buf, int buf_size),
- void (*write_packet)(void *opaque, UINT8 *buf, int buf_size),
- int (*seek)(void *opaque, offset_t offset, int whence));
-
-void put_byte(ByteIOContext *s, int b);
-void put_buffer(ByteIOContext *s, const unsigned char *buf, int size);
-void put_le64(ByteIOContext *s, UINT64 val);
-void put_be64(ByteIOContext *s, UINT64 val);
-void put_le32(ByteIOContext *s, unsigned int val);
-void put_be32(ByteIOContext *s, unsigned int val);
-void put_le16(ByteIOContext *s, unsigned int val);
-void put_be16(ByteIOContext *s, unsigned int val);
-void put_tag(ByteIOContext *s, const char *tag);
-
-void put_be64_double(ByteIOContext *s, double val);
-void put_strz(ByteIOContext *s, const char *buf);
-
-offset_t url_fseek(ByteIOContext *s, offset_t offset, int whence);
-void url_fskip(ByteIOContext *s, offset_t offset);
-offset_t url_ftell(ByteIOContext *s);
-int url_feof(ByteIOContext *s);
-
-#define URL_EOF (-1)
-int url_fgetc(ByteIOContext *s);
-int url_fprintf(ByteIOContext *s, const char *fmt, ...);
-char *url_fgets(ByteIOContext *s, char *buf, int buf_size);
-
-void put_flush_packet(ByteIOContext *s);
-
-int get_buffer(ByteIOContext *s, unsigned char *buf, int size);
-int get_byte(ByteIOContext *s);
-unsigned int get_le32(ByteIOContext *s);
-UINT64 get_le64(ByteIOContext *s);
-unsigned int get_le16(ByteIOContext *s);
-
-double get_be64_double(ByteIOContext *s);
-char *get_strz(ByteIOContext *s, char *buf, int maxlen);
-unsigned int get_be16(ByteIOContext *s);
-unsigned int get_be32(ByteIOContext *s);
-UINT64 get_be64(ByteIOContext *s);
-
-static inline int url_is_streamed(ByteIOContext *s)
-{
- return s->is_streamed;
-}
-
-int url_fdopen(ByteIOContext *s, URLContext *h);
-int url_setbufsize(ByteIOContext *s, int buf_size);
-int url_fopen(ByteIOContext *s, const char *filename, int flags);
-int url_fclose(ByteIOContext *s);
-URLContext *url_fileno(ByteIOContext *s);
-int url_fget_max_packet_size(ByteIOContext *s);
-
-int url_open_buf(ByteIOContext *s, UINT8 *buf, int buf_size, int flags);
-int url_close_buf(ByteIOContext *s);
-
-int url_open_dyn_buf(ByteIOContext *s);
-int url_open_dyn_packet_buf(ByteIOContext *s, int max_packet_size);
-int url_close_dyn_buf(ByteIOContext *s, UINT8 **pbuffer);
-
-/* file.c */
-extern URLProtocol file_protocol;
-extern URLProtocol pipe_protocol;
-
-/* udp.c */
-extern URLProtocol udp_protocol;
-int udp_set_remote_url(URLContext *h, const char *uri);
-int udp_get_local_port(URLContext *h);
-int udp_get_file_handle(URLContext *h);
-
-/* tcp.c */
-extern URLProtocol tcp_protocol;
-
-/* http.c */
-extern URLProtocol http_protocol;
-
-#endif
-
+++ /dev/null
-/*
- * Buffered I/O for ffmpeg system
- * Copyright (c) 2000,2001 Fabrice Bellard
- *
- * This library 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 of the License, or (at your option) any later version.
- *
- * This library 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 this library; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
-#include "avformat.h"
-#include <stdarg.h>
-
-#define IO_BUFFER_SIZE 32768
-
-int init_put_byte(ByteIOContext *s,
- unsigned char *buffer,
- int buffer_size,
- int write_flag,
- void *opaque,
- int (*read_packet)(void *opaque, UINT8 *buf, int buf_size),
- void (*write_packet)(void *opaque, UINT8 *buf, int buf_size),
- int (*seek)(void *opaque, offset_t offset, int whence))
-{
- s->buffer = buffer;
- s->buffer_size = buffer_size;
- s->buf_ptr = buffer;
- s->write_flag = write_flag;
- if (!s->write_flag)
- s->buf_end = buffer;
- else
- s->buf_end = buffer + buffer_size;
- s->opaque = opaque;
- s->write_packet = write_packet;
- s->read_packet = read_packet;
- s->seek = seek;
- s->pos = 0;
- s->must_flush = 0;
- s->eof_reached = 0;
- s->is_streamed = 0;
- s->max_packet_size = 0;
- return 0;
-}
-
-
-static void flush_buffer(ByteIOContext *s)
-{
- if (s->buf_ptr > s->buffer) {
- if (s->write_packet)
- s->write_packet(s->opaque, s->buffer, s->buf_ptr - s->buffer);
- s->pos += s->buf_ptr - s->buffer;
- }
- s->buf_ptr = s->buffer;
-}
-
-void put_byte(ByteIOContext *s, int b)
-{
- *(s->buf_ptr)++ = b;
- if (s->buf_ptr >= s->buf_end)
- flush_buffer(s);
-}
-
-void put_buffer(ByteIOContext *s, const unsigned char *buf, int size)
-{
- int len;
-
- while (size > 0) {
- len = (s->buf_end - s->buf_ptr);
- if (len > size)
- len = size;
- memcpy(s->buf_ptr, buf, len);
- s->buf_ptr += len;
-
- if (s->buf_ptr >= s->buf_end)
- flush_buffer(s);
-
- buf += len;
- size -= len;
- }
-}
-
-void put_flush_packet(ByteIOContext *s)
-{
- flush_buffer(s);
- s->must_flush = 0;
-}
-
-offset_t url_fseek(ByteIOContext *s, offset_t offset, int whence)
-{
- offset_t offset1;
-
- if (whence != SEEK_CUR && whence != SEEK_SET)
- return -EINVAL;
-
- if (s->write_flag) {
- if (whence == SEEK_CUR) {
- offset1 = s->pos + (s->buf_ptr - s->buffer);
- if (offset == 0)
- return offset1;
- offset += offset1;
- }
- offset1 = offset - s->pos;
- if (!s->must_flush &&
- offset1 >= 0 && offset1 < (s->buf_end - s->buffer)) {
- /* can do the seek inside the buffer */
- s->buf_ptr = s->buffer + offset1;
- } else {
- if (!s->seek)
- return -EPIPE;
- flush_buffer(s);
- s->must_flush = 1;
- s->buf_ptr = s->buffer;
- s->seek(s->opaque, offset, SEEK_SET);
- s->pos = offset;
- }
- } else {
- if (whence == SEEK_CUR) {
- offset1 = s->pos - (s->buf_end - s->buffer) + (s->buf_ptr - s->buffer);
- if (offset == 0)
- return offset1;
- offset += offset1;
- }
- offset1 = offset - (s->pos - (s->buf_end - s->buffer));
- if (offset1 >= 0 && offset1 <= (s->buf_end - s->buffer)) {
- /* can do the seek inside the buffer */
- s->buf_ptr = s->buffer + offset1;
- } else {
- if (!s->seek)
- return -EPIPE;
- s->buf_ptr = s->buffer;
- s->buf_end = s->buffer;
- s->seek(s->opaque, offset, SEEK_SET);
- s->pos = offset;
- }
- s->eof_reached = 0;
- }
- return offset;
-}
-
-void url_fskip(ByteIOContext *s, offset_t offset)
-{
- url_fseek(s, offset, SEEK_CUR);
-}
-
-offset_t url_ftell(ByteIOContext *s)
-{
- return url_fseek(s, 0, SEEK_CUR);
-}
-
-int url_feof(ByteIOContext *s)
-{
- return s->eof_reached;
-}
-
-void put_le32(ByteIOContext *s, unsigned int val)
-{
- put_byte(s, val);
- put_byte(s, val >> 8);
- put_byte(s, val >> 16);
- put_byte(s, val >> 24);
-}
-
-void put_be32(ByteIOContext *s, unsigned int val)
-{
- put_byte(s, val >> 24);
- put_byte(s, val >> 16);
- put_byte(s, val >> 8);
- put_byte(s, val);
-}
-
-/* IEEE format is assumed */
-void put_be64_double(ByteIOContext *s, double val)
-{
- union {
- double d;
- UINT64 ull;
- } u;
- u.d = val;
- put_be64(s, u.ull);
-}
-
-void put_strz(ByteIOContext *s, const char *str)
-{
- if (str)
- put_buffer(s, (const unsigned char *) str, strlen(str) + 1);
- else
- put_byte(s, 0);
-}
-
-void put_le64(ByteIOContext *s, UINT64 val)
-{
- put_le32(s, (UINT32)(val & 0xffffffff));
- put_le32(s, (UINT32)(val >> 32));
-}
-
-void put_be64(ByteIOContext *s, UINT64 val)
-{
- put_be32(s, (UINT32)(val >> 32));
- put_be32(s, (UINT32)(val & 0xffffffff));
-}
-
-void put_le16(ByteIOContext *s, unsigned int val)
-{
- put_byte(s, val);
- put_byte(s, val >> 8);
-}
-
-void put_be16(ByteIOContext *s, unsigned int val)
-{
- put_byte(s, val >> 8);
- put_byte(s, val);
-}
-
-void put_tag(ByteIOContext *s, const char *tag)
-{
- while (*tag) {
- put_byte(s, *tag++);
- }
-}
-
-/* Input stream */
-
-static void fill_buffer(ByteIOContext *s)
-{
- int len;
-
- /* no need to do anything if EOF already reached */
- if (s->eof_reached)
- return;
- len = s->read_packet(s->opaque, s->buffer, s->buffer_size);
- if (len <= 0) {
- /* do not modify buffer if EOF reached so that a seek back can
- be done without rereading data */
- s->eof_reached = 1;
- } else {
- s->pos += len;
- s->buf_ptr = s->buffer;
- s->buf_end = s->buffer + len;
- }
-}
-
-/* NOTE: return 0 if EOF, so you cannot use it if EOF handling is
- necessary */
-/* XXX: put an inline version */
-int get_byte(ByteIOContext *s)
-{
- if (s->buf_ptr < s->buf_end) {
- return *s->buf_ptr++;
- } else {
- fill_buffer(s);
- if (s->buf_ptr < s->buf_end)
- return *s->buf_ptr++;
- else
- return 0;
- }
-}
-
-/* NOTE: return URL_EOF (-1) if EOF */
-int url_fgetc(ByteIOContext *s)
-{
- if (s->buf_ptr < s->buf_end) {
- return *s->buf_ptr++;
- } else {
- fill_buffer(s);
- if (s->buf_ptr < s->buf_end)
- return *s->buf_ptr++;
- else
- return URL_EOF;
- }
-}
-
-int get_buffer(ByteIOContext *s, unsigned char *buf, int size)
-{
- int len, size1;
-
- size1 = size;
- while (size > 0) {
- len = s->buf_end - s->buf_ptr;
- if (len > size)
- len = size;
- if (len == 0) {
- fill_buffer(s);
- len = s->buf_end - s->buf_ptr;
- if (len == 0)
- break;
- } else {
- memcpy(buf, s->buf_ptr, len);
- buf += len;
- s->buf_ptr += len;
- size -= len;
- }
- }
- return size1 - size;
-}
-
-unsigned int get_le16(ByteIOContext *s)
-{
- unsigned int val;
- val = get_byte(s);
- val |= get_byte(s) << 8;
- return val;
-}
-
-unsigned int get_le32(ByteIOContext *s)
-{
- unsigned int val;
- val = get_byte(s);
- val |= get_byte(s) << 8;
- val |= get_byte(s) << 16;
- val |= get_byte(s) << 24;
- return val;
-}
-
-UINT64 get_le64(ByteIOContext *s)
-{
- UINT64 val;
- val = (UINT64)get_le32(s);
- val |= (UINT64)get_le32(s) << 32;
- return val;
-}
-
-unsigned int get_be16(ByteIOContext *s)
-{
- unsigned int val;
- val = get_byte(s) << 8;
- val |= get_byte(s);
- return val;
-}
-
-unsigned int get_be32(ByteIOContext *s)
-{
- unsigned int val;
- val = get_byte(s) << 24;
- val |= get_byte(s) << 16;
- val |= get_byte(s) << 8;
- val |= get_byte(s);
- return val;
-}
-
-double get_be64_double(ByteIOContext *s)
-{
- union {
- double d;
- UINT64 ull;
- } u;
-
- u.ull = get_be64(s);
- return u.d;
-}
-
-char *get_strz(ByteIOContext *s, char *buf, int maxlen)
-{
- int i = 0;
- char c;
-
- while ((c = get_byte(s))) {
- if (i < maxlen-1)
- buf[i++] = c;
- }
-
- buf[i] = 0; /* Ensure null terminated, but may be truncated */
-
- return buf;
-}
-
-UINT64 get_be64(ByteIOContext *s)
-{
- UINT64 val;
- val = (UINT64)get_be32(s) << 32;
- val |= (UINT64)get_be32(s);
- return val;
-}
-
-/* link with avio functions */
-
-void url_write_packet(void *opaque, UINT8 *buf, int buf_size)
-{
- URLContext *h = opaque;
- url_write(h, buf, buf_size);
-}
-
-int url_read_packet(void *opaque, UINT8 *buf, int buf_size)
-{
- URLContext *h = opaque;
- return url_read(h, buf, buf_size);
-}
-
-int url_seek_packet(void *opaque, INT64 offset, int whence)
-{
- URLContext *h = opaque;
- url_seek(h, offset, whence);
- return 0;
-}
-
-int url_fdopen(ByteIOContext *s, URLContext *h)
-{
- UINT8 *buffer;
- int buffer_size, max_packet_size;
-
-
- max_packet_size = url_get_max_packet_size(h);
- if (max_packet_size) {
- buffer_size = max_packet_size; /* no need to bufferize more than one packet */
- } else {
- buffer_size = IO_BUFFER_SIZE;
- }
- buffer = av_malloc(buffer_size);
- if (!buffer)
- return -ENOMEM;
-
- if (init_put_byte(s, buffer, buffer_size,
- (h->flags & URL_WRONLY) != 0, h,
- url_read_packet, url_write_packet, url_seek_packet) < 0) {
- av_free(buffer);
- return -EIO;
- }
- s->is_streamed = h->is_streamed;
- s->max_packet_size = max_packet_size;
- return 0;
-}
-
-/* XXX: must be called before any I/O */
-int url_setbufsize(ByteIOContext *s, int buf_size)
-{
- UINT8 *buffer;
- buffer = av_malloc(buf_size);
- if (!buffer)
- return -ENOMEM;
-
- av_free(s->buffer);
- s->buffer = buffer;
- s->buffer_size = buf_size;
- s->buf_ptr = buffer;
- if (!s->write_flag)
- s->buf_end = buffer;
- else
- s->buf_end = buffer + buf_size;
- return 0;
-}
-
-/* NOTE: when opened as read/write, the buffers are only used for
- reading */
-int url_fopen(ByteIOContext *s, const char *filename, int flags)
-{
- URLContext *h;
- int err;
-
- err = url_open(&h, filename, flags);
- if (err < 0)
- return err;
- err = url_fdopen(s, h);
- if (err < 0) {
- url_close(h);
- return err;
- }
- return 0;
-}
-
-int url_fclose(ByteIOContext *s)
-{
- URLContext *h = s->opaque;
-
- av_free(s->buffer);
- memset(s, 0, sizeof(ByteIOContext));
- return url_close(h);
-}
-
-URLContext *url_fileno(ByteIOContext *s)
-{
- return s->opaque;
-}
-
-/* XXX: currently size is limited */
-int url_fprintf(ByteIOContext *s, const char *fmt, ...)
-{
- va_list ap;
- char buf[4096];
- int ret;
-
- va_start(ap, fmt);
- ret = vsnprintf(buf, sizeof(buf), fmt, ap);
- va_end(ap);
- put_buffer(s, buf, strlen(buf));
- return ret;
-}
-
-/* note: unlike fgets, the EOL character is not returned and a whole
- line is parsed. return NULL if first char read was EOF */
-char *url_fgets(ByteIOContext *s, char *buf, int buf_size)
-{
- int c;
- char *q;
-
- c = url_fgetc(s);
- if (c == EOF)
- return NULL;
- q = buf;
- for(;;) {
- if (c == EOF || c == '\n')
- break;
- if ((q - buf) < buf_size - 1)
- *q++ = c;
- c = url_fgetc(s);
- }
- if (buf_size > 0)
- *q = '\0';
- return buf;
-}
-
-/*
- * Return the maximum packet size associated to packetized buffered file
- * handle. If the file is not packetized (stream like http or file on
- * disk), then 0 is returned.
- *
- * @param h buffered file handle
- * @return maximum packet size in bytes
- */
-int url_fget_max_packet_size(ByteIOContext *s)
-{
- return s->max_packet_size;
-}
-
-/* buffer handling */
-int url_open_buf(ByteIOContext *s, UINT8 *buf, int buf_size, int flags)
-{
- return init_put_byte(s, buf, buf_size,
- (flags & URL_WRONLY) != 0, NULL, NULL, NULL, NULL);
-}
-
-/* return the written or read size */
-int url_close_buf(ByteIOContext *s)
-{
- put_flush_packet(s);
- return s->buf_ptr - s->buffer;
-}
-
-/* output in a dynamic buffer */
-
-typedef struct DynBuffer {
- int pos, size, allocated_size;
- UINT8 *buffer;
- int io_buffer_size;
- UINT8 io_buffer[1];
-} DynBuffer;
-
-static void dyn_buf_write(void *opaque, UINT8 *buf, int buf_size)
-{
- DynBuffer *d = opaque;
- int new_size, new_allocated_size;
- UINT8 *new_buffer;
-
- /* reallocate buffer if needed */
- new_size = d->pos + buf_size;
- new_allocated_size = d->allocated_size;
- while (new_size > new_allocated_size) {
- if (!new_allocated_size)
- new_allocated_size = new_size;
- else
- new_allocated_size = (new_allocated_size * 3) / 2 + 1;
- }
-
- if (new_allocated_size > d->allocated_size) {
- new_buffer = av_malloc(new_allocated_size);
- if (!new_buffer)
- return;
- memcpy(new_buffer, d->buffer, d->size);
- av_free(d->buffer);
- d->buffer = new_buffer;
- d->allocated_size = new_allocated_size;
- }
- memcpy(d->buffer + d->pos, buf, buf_size);
- d->pos = new_size;
- if (d->pos > d->size)
- d->size = d->pos;
-}
-
-static void dyn_packet_buf_write(void *opaque, UINT8 *buf, int buf_size)
-{
- unsigned char buf1[4];
-
- /* packetized write: output the header */
- buf1[0] = (buf_size >> 24);
- buf1[1] = (buf_size >> 16);
- buf1[2] = (buf_size >> 8);
- buf1[3] = (buf_size);
- dyn_buf_write(opaque, buf1, 4);
-
- /* then the data */
- dyn_buf_write(opaque, buf, buf_size);
-}
-
-static int dyn_buf_seek(void *opaque, offset_t offset, int whence)
-{
- DynBuffer *d = opaque;
-
- if (whence == SEEK_CUR)
- offset += d->pos;
- else if (whence == SEEK_END)
- offset += d->size;
- if (offset < 0 || offset > 0x7fffffffLL)
- return -1;
- d->pos = offset;
- return 0;
-}
-
-static int url_open_dyn_buf_internal(ByteIOContext *s, int max_packet_size)
-{
- DynBuffer *d;
- int io_buffer_size, ret;
-
- if (max_packet_size)
- io_buffer_size = max_packet_size;
- else
- io_buffer_size = 1024;
-
- d = av_malloc(sizeof(DynBuffer) + io_buffer_size);
- if (!d)
- return -1;
- d->io_buffer_size = io_buffer_size;
- d->buffer = NULL;
- d->pos = 0;
- d->size = 0;
- d->allocated_size = 0;
- ret = init_put_byte(s, d->io_buffer, io_buffer_size,
- 1, d, NULL,
- max_packet_size ? dyn_packet_buf_write : dyn_buf_write,
- max_packet_size ? NULL : dyn_buf_seek);
- if (ret == 0) {
- s->max_packet_size = max_packet_size;
- }
- return ret;
-}
-
-/*
- * Open a write only memory stream.
- *
- * @param s new IO context
- * @return zero if no error.
- */
-int url_open_dyn_buf(ByteIOContext *s)
-{
- return url_open_dyn_buf_internal(s, 0);
-}
-
-/*
- * Open a write only packetized memory stream with a maximum packet
- * size of 'max_packet_size'. The stream is stored in a memory buffer
- * with a big endian 4 byte header giving the packet size in bytes.
- *
- * @param s new IO context
- * @param max_packet_size maximum packet size (must be > 0)
- * @return zero if no error.
- */
-int url_open_dyn_packet_buf(ByteIOContext *s, int max_packet_size)
-{
- if (max_packet_size <= 0)
- return -1;
- return url_open_dyn_buf_internal(s, max_packet_size);
-}
-
-/*
- * Return the written size and a pointer to the buffer. The buffer
- * must be freed with av_free().
- * @param s IO context
- * @param pointer to a byte buffer
- * @return the length of the byte buffer
- */
-int url_close_dyn_buf(ByteIOContext *s, UINT8 **pbuffer)
-{
- DynBuffer *d = s->opaque;
- int size;
-
- put_flush_packet(s);
-
- *pbuffer = d->buffer;
- size = d->size;
- av_free(d);
- return size;
-}
+++ /dev/null
-
-#include <stdlib.h>
-#include <strings.h>
-#include "barpainet.h"
-
-int inet_aton (const char * str, struct in_addr * add) {
- const char * pch = str;
- unsigned int add1 = 0, add2 = 0, add3 = 0, add4 = 0;
-
- add1 = atoi(pch);
- pch = strpbrk(pch,".");
- if (pch == 0 || ++pch == 0) goto done;
- add2 = atoi(pch);
- pch = strpbrk(pch,".");
- if (pch == 0 || ++pch == 0) goto done;
- add3 = atoi(pch);
- pch = strpbrk(pch,".");
- if (pch == 0 || ++pch == 0) goto done;
- add4 = atoi(pch);
-
-done:
- add->s_addr=(add4<<24)+(add3<<16)+(add2<<8)+add1;
-
- return 1;
-}
+++ /dev/null
-#ifndef BARPA_INET_H
-#define BARPA_INET_H
-
-#include "../config.h"
-
-#ifdef CONFIG_BEOS_NETSERVER
-
-# include <socket.h>
-int inet_aton (const char * str, struct in_addr * add);
-# define PF_INET AF_INET
-# define SO_SNDBUF 0x40000001
-
-/* fake */
-struct ip_mreq {
- struct in_addr imr_multiaddr; /* IP multicast address of group */
- struct in_addr imr_interface; /* local IP address of interface */
-};
-
-#else
-# include <arpa/inet.h>
-#endif
-
-#endif /* BARPA_INET_H */
+++ /dev/null
-/*
- * BeOS audio play interface
- * Copyright (c) 2000, 2001 Fabrice Bellard.
- *
- * This library 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 of the License, or (at your option) any later version.
- *
- * This library 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 this library; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
-
-#include <signal.h>
-#include <stdlib.h>
-#include <stdio.h>
-#include <string.h>
-#include <unistd.h>
-#include <sys/time.h>
-
-#include <Application.h>
-#include <SoundPlayer.h>
-
-extern "C" {
-#include "avformat.h"
-}
-
-/* enable performance checks */
-//#define PERF_CHECK
-
-//const char *audio_device = "/dev/dsp";
-const char *audio_device = "beosaudio:";
-
-/* Pipes are 4k in BeOS IIRC */
-#define AUDIO_BLOCK_SIZE 4096
-//#define AUDIO_BLOCK_SIZE 2048
-#define AUDIO_BLOCK_COUNT 8
-
-#define AUDIO_BUFFER_SIZE (AUDIO_BLOCK_SIZE*AUDIO_BLOCK_COUNT)
-
-/* pipes suck for realtime */
-#define USE_RING_BUFFER 1
-
-typedef struct {
- int fd;
- int sample_rate;
- int channels;
- int frame_size; /* in bytes ! */
- CodecID codec_id;
- int flip_left : 1;
- UINT8 buffer[AUDIO_BUFFER_SIZE];
- int buffer_ptr;
- int pipefd; /* the other end of the pipe */
- /* ring buffer */
- sem_id input_sem;
- int input_index;
- sem_id output_sem;
- int output_index;
- int queued;
- BSoundPlayer *player;
- int has_quit; /* signal callbacks not to wait */
- volatile bigtime_t starve_time;
-} AudioData;
-
-static thread_id main_thid;
-static thread_id bapp_thid;
-static int own_BApp_created = 0;
-static int refcount = 0;
-
-/* create the BApplication and Run() it */
-static int32 bapp_thread(void *arg)
-{
- new BApplication("application/x-vnd.ffmpeg");
- own_BApp_created = 1;
- be_app->Run();
- /* kill the process group */
-// kill(0, SIGINT);
-// kill(main_thid, SIGHUP);
- return B_OK;
-}
-
-/* create the BApplication only if needed */
-static void create_bapp_if_needed(void)
-{
- if (refcount++ == 0) {
- /* needed by libmedia */
- if (be_app == NULL) {
- bapp_thid = spawn_thread(bapp_thread, "ffmpeg BApplication", B_NORMAL_PRIORITY, NULL);
- resume_thread(bapp_thid);
- while (!own_BApp_created)
- snooze(50000);
- }
- }
-}
-
-static void destroy_bapp_if_needed(void)
-{
- if (--refcount == 0 && own_BApp_created) {
- be_app->Lock();
- be_app->Quit();
- be_app = NULL;
- }
-}
-
-/* called back by BSoundPlayer */
-static void audioplay_callback(void *cookie, void *buffer, size_t bufferSize, const media_raw_audio_format &format)
-{
- AudioData *s;
- size_t len, amount;
- unsigned char *buf = (unsigned char *)buffer;
-
- s = (AudioData *)cookie;
- if (s->has_quit)
- return;
- while (bufferSize > 0) {
-#ifdef PERF_CHECK
- bigtime_t t;
- t = system_time();
-#endif
-#ifdef USE_RING_BUFFER
- len = MIN(AUDIO_BLOCK_SIZE, bufferSize);
- if (acquire_sem_etc(s->output_sem, len, B_CAN_INTERRUPT, 0LL) < B_OK) {
- s->has_quit = 1;
- s->player->SetHasData(false);
- return;
- }
- amount = MIN(len, (AUDIO_BUFFER_SIZE - s->output_index));
- memcpy(buf, &s->buffer[s->output_index], amount);
- s->output_index += amount;
- if (s->output_index >= AUDIO_BUFFER_SIZE) {
- s->output_index %= AUDIO_BUFFER_SIZE;
- memcpy(buf + amount, &s->buffer[s->output_index], len - amount);
- s->output_index += len-amount;
- s->output_index %= AUDIO_BUFFER_SIZE;
- }
- release_sem_etc(s->input_sem, len, 0);
-#else
- len = read(s->pipefd, buf, bufferSize);
-#endif
-#ifdef PERF_CHECK
- t = system_time() - t;
- s->starve_time = MAX(s->starve_time, t);
-#endif
-#ifndef USE_RING_BUFFER
- if (len < B_OK) {
- puts("EPIPE");
- s->player->SetHasData(false);
- snooze(100000);
- return;
- }
- if (len == 0) {
- s->player->SetHasData(false);
- snooze(100000);
- return;
- }
-#endif
- buf += len;
- bufferSize -= len;
- }
-}
-
-static int audio_open(AudioData *s, int is_output)
-{
- int p[2];
- int ret;
- media_raw_audio_format format;
-
- if (!is_output)
- return -EIO; /* not for now */
-#ifdef USE_RING_BUFFER
- s->input_sem = create_sem(AUDIO_BUFFER_SIZE, "ffmpeg_ringbuffer_input");
-// s->input_sem = create_sem(AUDIO_BLOCK_SIZE, "ffmpeg_ringbuffer_input");
- if (s->input_sem < B_OK)
- return -EIO;
- s->output_sem = create_sem(0, "ffmpeg_ringbuffer_output");
- if (s->output_sem < B_OK) {
- delete_sem(s->input_sem);
- return -EIO;
- }
- s->input_index = 0;
- s->output_index = 0;
- s->queued = 0;
-#else
- ret = pipe(p);
- if (ret < 0)
- return -EIO;
- s->fd = p[is_output?1:0];
- s->pipefd = p[is_output?0:1];
- if (s->fd < 0) {
- perror(is_output?"audio out":"audio in");
- return -EIO;
- }
-#endif
- create_bapp_if_needed();
- /* non blocking mode */
-// fcntl(s->fd, F_SETFL, O_NONBLOCK);
-// fcntl(s->pipefd, F_SETFL, O_NONBLOCK);
- s->frame_size = AUDIO_BLOCK_SIZE;
- format = media_raw_audio_format::wildcard;
- format.format = media_raw_audio_format::B_AUDIO_SHORT;
- format.byte_order = B_HOST_IS_LENDIAN ? B_MEDIA_LITTLE_ENDIAN : B_MEDIA_BIG_ENDIAN;
- format.channel_count = s->channels;
- format.buffer_size = s->frame_size;
- format.frame_rate = s->sample_rate;
- s->player = new BSoundPlayer(&format, "ffmpeg output", audioplay_callback);
- if (s->player->InitCheck() != B_OK) {
- delete s->player;
- s->player = NULL;
-#ifdef USE_RING_BUFFER
- if (s->input_sem)
- delete_sem(s->input_sem);
- if (s->output_sem)
- delete_sem(s->output_sem);
-#else
- close(s->fd);
- close(s->pipefd);
-#endif
- return -EIO;
- }
- s->player->SetCookie(s);
- s->player->SetVolume(1.0);
- s->player->Start();
- s->player->SetHasData(true);
- /* bump up the priority (avoid realtime though) */
- set_thread_priority(find_thread(NULL), B_DISPLAY_PRIORITY+1);
- return 0;
-}
-
-static int audio_close(AudioData *s)
-{
-#ifdef USE_RING_BUFFER
- if (s->input_sem)
- delete_sem(s->input_sem);
- if (s->output_sem)
- delete_sem(s->output_sem);
-#endif
- s->has_quit = 1;
- if (s->player) {
- s->player->Stop();
- }
- if (s->player)
- delete s->player;
-#ifndef USE_RING_BUFFER
- close(s->pipefd);
- close(s->fd);
-#endif
- destroy_bapp_if_needed();
- return 0;
-}
-
-/* sound output support */
-static int audio_write_header(AVFormatContext *s1)
-{
- AudioData *s = (AudioData *)s1->priv_data;
- AVStream *st;
- int ret;
-
- st = s1->streams[0];
- s->sample_rate = st->codec.sample_rate;
- s->channels = st->codec.channels;
- ret = audio_open(s, 1);
- if (ret < 0)
- return -EIO;
- return 0;
-}
-
-static int audio_write_packet(AVFormatContext *s1, int stream_index,
- UINT8 *buf, int size, int force_pts)
-{
- AudioData *s = (AudioData *)s1->priv_data;
- int len, ret;
-#ifdef PERF_CHECK
- bigtime_t t = s->starve_time;
- s->starve_time = 0;
- printf("starve_time: %lld \n", t);
-#endif
-#ifdef USE_RING_BUFFER
- while (size > 0) {
- int amount;
- len = MIN(size, AUDIO_BLOCK_SIZE);
- if (acquire_sem_etc(s->input_sem, len, B_CAN_INTERRUPT, 0LL) < B_OK)
- return -EIO;
- amount = MIN(len, (AUDIO_BUFFER_SIZE - s->input_index));
- memcpy(&s->buffer[s->input_index], buf, amount);
- s->input_index += amount;
- if (s->input_index >= AUDIO_BUFFER_SIZE) {
- s->input_index %= AUDIO_BUFFER_SIZE;
- memcpy(&s->buffer[s->input_index], buf + amount, len - amount);
- s->input_index += len - amount;
- }
- release_sem_etc(s->output_sem, len, 0);
- buf += len;
- size -= len;
- }
-#else
- while (size > 0) {
- len = AUDIO_BLOCK_SIZE - s->buffer_ptr;
- if (len > size)
- len = size;
- memcpy(s->buffer + s->buffer_ptr, buf, len);
- s->buffer_ptr += len;
- if (s->buffer_ptr >= AUDIO_BLOCK_SIZE) {
- for(;;) {
-//snooze(1000);
- ret = write(s->fd, s->buffer, AUDIO_BLOCK_SIZE);
- if (ret != 0)
- break;
- if (ret < 0 && (errno != EAGAIN && errno != EINTR))
- return -EIO;
- }
- s->buffer_ptr = 0;
- }
- buf += len;
- size -= len;
- }
-#endif
- return 0;
-}
-
-static int audio_write_trailer(AVFormatContext *s1)
-{
- AudioData *s = (AudioData *)s1->priv_data;
-
- audio_close(s);
- return 0;
-}
-
-/* grab support */
-
-static int audio_read_header(AVFormatContext *s1, AVFormatParameters *ap)
-{
- AudioData *s = (AudioData *)s1->priv_data;
- AVStream *st;
- int ret;
-
- if (!ap || ap->sample_rate <= 0 || ap->channels <= 0)
- return -1;
-
- st = av_new_stream(s1, 0);
- if (!st) {
- return -ENOMEM;
- }
- s->sample_rate = ap->sample_rate;
- s->channels = ap->channels;
-
- ret = audio_open(s, 0);
- if (ret < 0) {
- av_free(st);
- return -EIO;
- } else {
- /* take real parameters */
- st->codec.codec_type = CODEC_TYPE_AUDIO;
- st->codec.codec_id = s->codec_id;
- st->codec.sample_rate = s->sample_rate;
- st->codec.channels = s->channels;
- return 0;
- }
-}
-
-static int audio_read_packet(AVFormatContext *s1, AVPacket *pkt)
-{
- AudioData *s = (AudioData *)s1->priv_data;
- int ret;
-
- if (av_new_packet(pkt, s->frame_size) < 0)
- return -EIO;
- for(;;) {
- ret = read(s->fd, pkt->data, pkt->size);
- if (ret > 0)
- break;
- if (ret == -1 && (errno == EAGAIN || errno == EINTR)) {
- av_free_packet(pkt);
- pkt->size = 0;
- return 0;
- }
- if (!(ret == 0 || (ret == -1 && (errno == EAGAIN || errno == EINTR)))) {
- av_free_packet(pkt);
- return -EIO;
- }
- }
- pkt->size = ret;
- if (s->flip_left && s->channels == 2) {
- int i;
- short *p = (short *) pkt->data;
-
- for (i = 0; i < ret; i += 4) {
- *p = ~*p;
- p += 2;
- }
- }
- return 0;
-}
-
-static int audio_read_close(AVFormatContext *s1)
-{
- AudioData *s = (AudioData *)s1->priv_data;
-
- audio_close(s);
- return 0;
-}
-
-AVInputFormat audio_in_format = {
- "audio_device",
- "audio grab and output",
- sizeof(AudioData),
- NULL,
- audio_read_header,
- audio_read_packet,
- audio_read_close,
- NULL,
- AVFMT_NOFILE,
-};
-
-AVOutputFormat audio_out_format = {
- "audio_device",
- "audio grab and output",
- "",
- "",
- sizeof(AudioData),
-#ifdef WORDS_BIGENDIAN
- CODEC_ID_PCM_S16BE,
-#else
- CODEC_ID_PCM_S16LE,
-#endif
- CODEC_ID_NONE,
- audio_write_header,
- audio_write_packet,
- audio_write_trailer,
- AVFMT_NOFILE,
-};
-
-extern "C" {
-
-int audio_init(void)
-{
- main_thid = find_thread(NULL);
- av_register_input_format(&audio_in_format);
- av_register_output_format(&audio_out_format);
- return 0;
-}
-
-} // "C"
-
+++ /dev/null
-/*
- * CRC decoder (for codec/format testing)
- * Copyright (c) 2002 Fabrice Bellard.
- *
- * This library 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 of the License, or (at your option) any later version.
- *
- * This library 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 this library; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
-#include "avformat.h"
-
-/* adler32.c -- compute the Adler-32 checksum of a data stream
- * Copyright (C) 1995 Mark Adler
- * For conditions of distribution and use, see copyright notice in zlib.h
- */
-
-#define BASE 65521L /* largest prime smaller than 65536 */
-#define NMAX 5552
-/* NMAX is the largest n such that 255n(n+1)/2 + (n+1)(BASE-1) <= 2^32-1 */
-
-#define DO1(buf) {s1 += *buf++; s2 += s1;}
-#define DO2(buf) DO1(buf); DO1(buf);
-#define DO4(buf) DO2(buf); DO2(buf);
-#define DO8(buf) DO4(buf); DO4(buf);
-#define DO16(buf) DO8(buf); DO8(buf);
-
-static UINT32 adler32(UINT32 adler, UINT8 *buf, unsigned int len)
-{
- unsigned long s1 = adler & 0xffff;
- unsigned long s2 = (adler >> 16) & 0xffff;
- int k;
-
- if (buf == NULL) return 1L;
-
- while (len > 0) {
- k = len < NMAX ? len : NMAX;
- len -= k;
- while (k >= 16) {
- DO16(buf);
- k -= 16;
- }
- if (k != 0) do {
- DO1(buf);
- } while (--k);
- s1 %= BASE;
- s2 %= BASE;
- }
- return (s2 << 16) | s1;
-}
-
-typedef struct CRCState {
- UINT32 crcval;
-} CRCState;
-
-static int crc_write_header(struct AVFormatContext *s)
-{
- CRCState *crc = s->priv_data;
-
- /* init CRC */
- crc->crcval = adler32(0, NULL, 0);
-
- return 0;
-}
-
-static int crc_write_packet(struct AVFormatContext *s,
- int stream_index,
- unsigned char *buf, int size, int force_pts)
-{
- CRCState *crc = s->priv_data;
- crc->crcval = adler32(crc->crcval, buf, size);
- return 0;
-}
-
-static int crc_write_trailer(struct AVFormatContext *s)
-{
- CRCState *crc = s->priv_data;
- char buf[64];
-
- snprintf(buf, sizeof(buf), "CRC=%08x\n", crc->crcval);
- put_buffer(&s->pb, buf, strlen(buf));
- put_flush_packet(&s->pb);
- return 0;
-}
-
-static 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;
-}
+++ /dev/null
-/*
- * Various simple utilities for ffmpeg system
- * Copyright (c) 2000, 2001, 2002 Fabrice Bellard
- *
- * This library 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 of the License, or (at your option) any later version.
- *
- * This library 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 this library; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
-#include "avformat.h"
-#include <ctype.h>
-
-#if !defined(CONFIG_NOCUTILS)
-/**
- * Return TRUE if val is a prefix of str. If it returns TRUE, ptr is
- * set to the next character in 'str' after the prefix.
- *
- * @param str input string
- * @param val prefix to test
- * @param ptr updated after the prefix in str in there is a match
- * @return TRUE if there is a match
- */
-int strstart(const char *str, const char *val, const char **ptr)
-{
- const char *p, *q;
- p = str;
- q = val;
- while (*q != '\0') {
- if (*p != *q)
- return 0;
- p++;
- q++;
- }
- if (ptr)
- *ptr = p;
- return 1;
-}
-
-/**
- * Return TRUE if val is a prefix of str (case independent). If it
- * returns TRUE, ptr is set to the next character in 'str' after the
- * prefix.
- *
- * @param str input string
- * @param val prefix to test
- * @param ptr updated after the prefix in str in there is a match
- * @return TRUE if there is a match */
-int stristart(const char *str, const char *val, const char **ptr)
-{
- const char *p, *q;
- p = str;
- q = val;
- while (*q != '\0') {
- if (toupper(*(unsigned char *)p) != toupper(*(unsigned char *)q))
- return 0;
- p++;
- q++;
- }
- if (ptr)
- *ptr = p;
- return 1;
-}
-
-/**
- * Copy the string str to buf. If str length is bigger than buf_size -
- * 1 then it is clamped to buf_size - 1.
- * NOTE: this function does what strncpy should have done to be
- * useful. NEVER use strncpy.
- *
- * @param buf destination buffer
- * @param buf_size size of destination buffer
- * @param str source string
- */
-void pstrcpy(char *buf, int buf_size, const char *str)
-{
- int c;
- char *q = buf;
-
- if (buf_size <= 0)
- return;
-
- for(;;) {
- c = *str++;
- if (c == 0 || q >= buf + buf_size - 1)
- break;
- *q++ = c;
- }
- *q = '\0';
-}
-
-/* strcat and truncate. */
-char *pstrcat(char *buf, int buf_size, const char *s)
-{
- int len;
- len = strlen(buf);
- if (len < buf_size)
- pstrcpy(buf + len, buf_size - len, s);
- return buf;
-}
-
-#endif
+++ /dev/null
-/*
- * Raw DV format
- * Copyright (c) 2002 Fabrice Bellard.
- *
- * This library 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 of the License, or (at your option) any later version.
- *
- * This library 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 this library; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
-#include "avformat.h"
-
-#define NTSC_FRAME_SIZE 120000
-#define PAL_FRAME_SIZE 144000
-
-typedef struct DVDemuxContext {
- int is_audio;
-} DVDemuxContext;
-
-/* raw input */
-static int dv_read_header(AVFormatContext *s,
- AVFormatParameters *ap)
-{
- AVStream *vst, *ast;
-
- vst = av_new_stream(s, 0);
- if (!vst)
- return AVERROR_NOMEM;
- vst->codec.codec_type = CODEC_TYPE_VIDEO;
- vst->codec.codec_id = CODEC_ID_DVVIDEO;
-
-#if 0
- ast = av_new_stream(s, 1);
- if (!ast)
- return AVERROR_NOMEM;
-
- ast->codec.codec_type = CODEC_TYPE_AUDIO;
- ast->codec.codec_id = CODEC_ID_DVAUDIO;
-#endif
- return 0;
-}
-
-/* XXX: build fake audio stream when DV audio decoder will be finished */
-static int dv_read_packet(AVFormatContext *s, AVPacket *pkt)
-{
- int ret, size, dsf;
- uint8_t buf[4];
-
- ret = get_buffer(&s->pb, buf, 4);
- if (ret <= 0)
- return -EIO;
- dsf = buf[3] & 0x80;
- if (!dsf)
- size = NTSC_FRAME_SIZE;
- else
- size = PAL_FRAME_SIZE;
-
- if (av_new_packet(pkt, size) < 0)
- return -EIO;
-
- pkt->stream_index = 0;
- memcpy(pkt->data, buf, 4);
- ret = get_buffer(&s->pb, pkt->data + 4, size - 4);
- if (ret <= 0) {
- av_free_packet(pkt);
- return -EIO;
- }
- return ret;
-}
-
-static int dv_read_close(AVFormatContext *s)
-{
- return 0;
-}
-
-static AVInputFormat dv_iformat = {
- "dv",
- "DV video format",
- sizeof(DVDemuxContext),
- NULL,
- dv_read_header,
- dv_read_packet,
- dv_read_close,
- .extensions = "dv",
-};
-
-#if 0
-int dv_write_header(struct AVFormatContext *s)
-{
- return 0;
-}
-
-int dv_write_packet(struct AVFormatContext *s,
- int stream_index,
- unsigned char *buf, int size, int force_pts)
-{
- put_buffer(&s->pb, buf, size);
- put_flush_packet(&s->pb);
- return 0;
-}
-
-int dv_write_trailer(struct AVFormatContext *s)
-{
- return 0;
-}
-
-AVOutputFormat dv_oformat = {
- "dv",
- "DV video format",
- NULL,
- "dv",
- 0,
- CODEC_ID_DVVIDEO,
- CODEC_ID_DVAUDIO,
- dv_write_header,
- dv_write_packet,
- dv_write_trailer,
-};
-#endif
-
-int dv_init(void)
-{
- av_register_input_format(&dv_iformat);
- // av_register_output_format(&dv_oformat);
- return 0;
-}
+++ /dev/null
-/*
- * FFM (ffserver live feed) encoder and decoder
- * Copyright (c) 2001 Fabrice Bellard.
- *
- * This library 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 of the License, or (at your option) any later version.
- *
- * This library 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 this library; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
-#include "avformat.h"
-#include <unistd.h>
-
-/* The FFM file is made of blocks of fixed size */
-#define FFM_HEADER_SIZE 14
-#define PACKET_ID 0x666d
-
-/* each packet contains frames (which can span several packets */
-#define FRAME_HEADER_SIZE 8
-#define FLAG_KEY_FRAME 0x01
-
-typedef struct FFMStream {
- INT64 pts;
-} FFMStream;
-
-enum {
- READ_HEADER,
- READ_DATA,
-};
-
-typedef struct FFMContext {
- /* only reading mode */
- offset_t write_index, file_size;
- int read_state;
- UINT8 header[FRAME_HEADER_SIZE];
-
- /* read and write */
- int first_packet; /* true if first packet, needed to set the discontinuity tag */
- int packet_size;
- int frame_offset;
- INT64 pts;
- UINT8 *packet_ptr, *packet_end;
- UINT8 packet[FFM_PACKET_SIZE];
-} FFMContext;
-
-/* disable pts hack for testing */
-int ffm_nopts = 0;
-
-static void flush_packet(AVFormatContext *s)
-{
- FFMContext *ffm = s->priv_data;
- int fill_size, h;
- ByteIOContext *pb = &s->pb;
-
- fill_size = ffm->packet_end - ffm->packet_ptr;
- memset(ffm->packet_ptr, 0, fill_size);
-
- /* put header */
- put_be16(pb, PACKET_ID);
- put_be16(pb, fill_size);
- put_be64(pb, ffm->pts);
- h = ffm->frame_offset;
- if (ffm->first_packet)
- h |= 0x8000;
- put_be16(pb, h);
- put_buffer(pb, ffm->packet, ffm->packet_end - ffm->packet);
-
- /* prepare next packet */
- ffm->frame_offset = 0; /* no key frame */
- ffm->pts = 0; /* no pts */
- ffm->packet_ptr = ffm->packet;
- ffm->first_packet = 0;
-}
-
-/* 'first' is true if first data of a frame */
-static void ffm_write_data(AVFormatContext *s,
- UINT8 *buf, int size,
- INT64 pts, int first)
-{
- FFMContext *ffm = s->priv_data;
- int len;
-
- if (first && ffm->frame_offset == 0)
- ffm->frame_offset = ffm->packet_ptr - ffm->packet + FFM_HEADER_SIZE;
- if (first && ffm->pts == 0)
- ffm->pts = pts;
-
- /* write as many packets as needed */
- while (size > 0) {
- len = ffm->packet_end - ffm->packet_ptr;
- if (len > size)
- len = size;
- memcpy(ffm->packet_ptr, buf, len);
-
- ffm->packet_ptr += len;
- buf += len;
- size -= len;
- if (ffm->packet_ptr >= ffm->packet_end) {
- /* special case : no pts in packet : we leave the current one */
- if (ffm->pts == 0)
- ffm->pts = pts;
-
- flush_packet(s);
- }
- }
-}
-
-static int ffm_write_header(AVFormatContext *s)
-{
- FFMContext *ffm = s->priv_data;
- AVStream *st;
- FFMStream *fst;
- ByteIOContext *pb = &s->pb;
- AVCodecContext *codec;
- int bit_rate, i;
-
- ffm->packet_size = FFM_PACKET_SIZE;
-
- /* header */
- put_tag(pb, "FFM1");
- put_be32(pb, ffm->packet_size);
- /* XXX: store write position in other file ? */
- put_be64(pb, ffm->packet_size); /* current write position */
-
- put_be32(pb, s->nb_streams);
- bit_rate = 0;
- for(i=0;i<s->nb_streams;i++) {
- st = s->streams[i];
- bit_rate += st->codec.bit_rate;
- }
- put_be32(pb, bit_rate);
-
- /* list of streams */
- for(i=0;i<s->nb_streams;i++) {
- st = s->streams[i];
- fst = av_mallocz(sizeof(FFMStream));
- if (!fst)
- goto fail;
- st->priv_data = fst;
-
- codec = &st->codec;
- /* generic info */
- put_be32(pb, codec->codec_id);
- put_byte(pb, codec->codec_type);
- put_be32(pb, codec->bit_rate);
- put_be32(pb, codec->quality);
- put_be32(pb, codec->flags);
- /* specific info */
- switch(codec->codec_type) {
- case CODEC_TYPE_VIDEO:
- put_be32(pb, (codec->frame_rate * 1000) / FRAME_RATE_BASE);
- put_be16(pb, codec->width);
- put_be16(pb, codec->height);
- put_be16(pb, codec->gop_size);
- put_byte(pb, codec->qmin);
- put_byte(pb, codec->qmax);
- put_byte(pb, codec->max_qdiff);
- put_be16(pb, (int) (codec->qcompress * 10000.0));
- put_be16(pb, (int) (codec->qblur * 10000.0));
- put_be32(pb, codec->bit_rate_tolerance);
- put_strz(pb, codec->rc_eq);
- put_be32(pb, codec->rc_max_rate);
- put_be32(pb, codec->rc_min_rate);
- put_be32(pb, codec->rc_buffer_size);
- put_be64_double(pb, codec->i_quant_factor);
- put_be64_double(pb, codec->b_quant_factor);
- put_be64_double(pb, codec->i_quant_offset);
- put_be64_double(pb, codec->b_quant_offset);
- put_be32(pb, codec->dct_algo);
- break;
- case CODEC_TYPE_AUDIO:
- put_be32(pb, codec->sample_rate);
- put_le16(pb, codec->channels);
- put_le16(pb, codec->frame_size);
- break;
- default:
- av_abort();
- }
- /* hack to have real time */
- if (ffm_nopts)
- fst->pts = 0;
- else
- fst->pts = av_gettime();
- }
-
- /* flush until end of block reached */
- while ((url_ftell(pb) % ffm->packet_size) != 0)
- put_byte(pb, 0);
-
- put_flush_packet(pb);
-
- /* init packet mux */
- ffm->packet_ptr = ffm->packet;
- ffm->packet_end = ffm->packet + ffm->packet_size - FFM_HEADER_SIZE;
- ffm->frame_offset = 0;
- ffm->pts = 0;
- ffm->first_packet = 1;
-
- return 0;
- fail:
- for(i=0;i<s->nb_streams;i++) {
- st = s->streams[i];
- av_freep(&st->priv_data);
- }
- return -1;
-}
-
-static int ffm_write_packet(AVFormatContext *s, int stream_index,
- UINT8 *buf, int size, int force_pts)
-{
- AVStream *st = s->streams[stream_index];
- FFMStream *fst = st->priv_data;
- INT64 pts;
- UINT8 header[FRAME_HEADER_SIZE];
- int duration;
-
- if (st->codec.codec_type == CODEC_TYPE_AUDIO) {
- duration = ((float)st->codec.frame_size / st->codec.sample_rate * 1000000.0);
- } else {
- duration = (1000000.0 * FRAME_RATE_BASE / (float)st->codec.frame_rate);
- }
-
- pts = fst->pts;
- /* packet size & key_frame */
- header[0] = stream_index;
- header[1] = 0;
- if (st->codec.key_frame)
- header[1] |= FLAG_KEY_FRAME;
- header[2] = (size >> 16) & 0xff;
- header[3] = (size >> 8) & 0xff;
- header[4] = size & 0xff;
- header[5] = (duration >> 16) & 0xff;
- header[6] = (duration >> 8) & 0xff;
- header[7] = duration & 0xff;
- ffm_write_data(s, header, FRAME_HEADER_SIZE, pts, 1);
- ffm_write_data(s, buf, size, pts, 0);
-
- fst->pts += duration;
- return 0;
-}
-
-static int ffm_write_trailer(AVFormatContext *s)
-{
- ByteIOContext *pb = &s->pb;
- FFMContext *ffm = s->priv_data;
- int i;
-
- /* flush packets */
- if (ffm->packet_ptr > ffm->packet)
- flush_packet(s);
-
- put_flush_packet(pb);
-
- if (!url_is_streamed(pb)) {
- INT64 size;
- /* update the write offset */
- size = url_ftell(pb);
- url_fseek(pb, 8, SEEK_SET);
- put_be64(pb, size);
- put_flush_packet(pb);
- }
-
- for(i=0;i<s->nb_streams;i++)
- av_freep(&s->streams[i]->priv_data);
- return 0;
-}
-
-/* ffm demux */
-
-static int ffm_is_avail_data(AVFormatContext *s, int size)
-{
- FFMContext *ffm = s->priv_data;
- offset_t pos, avail_size;
- int len;
-
- len = ffm->packet_end - ffm->packet_ptr;
- if (!ffm_nopts) {
- /* XXX: I don't understand this test, so I disabled it for testing */
- if (size <= len)
- return 1;
- }
- pos = url_ftell(&s->pb);
- if (pos == ffm->write_index) {
- /* exactly at the end of stream */
- return 0;
- } else if (pos < ffm->write_index) {
- avail_size = ffm->write_index - pos;
- } else {
- avail_size = (ffm->file_size - pos) + (ffm->write_index - FFM_PACKET_SIZE);
- }
- avail_size = (avail_size / ffm->packet_size) * (ffm->packet_size - FFM_HEADER_SIZE) + len;
- if (size <= avail_size)
- return 1;
- else
- return 0;
-}
-
-/* first is true if we read the frame header */
-static int ffm_read_data(AVFormatContext *s,
- UINT8 *buf, int size, int first)
-{
- FFMContext *ffm = s->priv_data;
- ByteIOContext *pb = &s->pb;
- int len, fill_size, size1, frame_offset;
-
- size1 = size;
- while (size > 0) {
- redo:
- len = ffm->packet_end - ffm->packet_ptr;
- if (len > size)
- len = size;
- if (len == 0) {
- if (url_ftell(pb) == ffm->file_size)
- url_fseek(pb, ffm->packet_size, SEEK_SET);
- retry_read:
- get_be16(pb); /* PACKET_ID */
- fill_size = get_be16(pb);
- ffm->pts = get_be64(pb);
- frame_offset = get_be16(pb);
- get_buffer(pb, ffm->packet, ffm->packet_size - FFM_HEADER_SIZE);
- ffm->packet_end = ffm->packet + (ffm->packet_size - FFM_HEADER_SIZE - fill_size);
- /* if first packet or resynchronization packet, we must
- handle it specifically */
- if (ffm->first_packet || (frame_offset & 0x8000)) {
- if (!frame_offset) {
- /* This packet has no frame headers in it */
- if (url_ftell(pb) >= ffm->packet_size * 3) {
- url_fseek(pb, -ffm->packet_size * 2, SEEK_CUR);
- goto retry_read;
- }
- /* This is bad, we cannot find a valid frame header */
- return 0;
- }
- ffm->first_packet = 0;
- if ((frame_offset & 0x7ffff) < FFM_HEADER_SIZE)
- av_abort();
- ffm->packet_ptr = ffm->packet + (frame_offset & 0x7fff) - FFM_HEADER_SIZE;
- if (!first)
- break;
- } else {
- ffm->packet_ptr = ffm->packet;
- }
- goto redo;
- }
- memcpy(buf, ffm->packet_ptr, len);
- buf += len;
- ffm->packet_ptr += len;
- size -= len;
- first = 0;
- }
- return size1 - size;
-}
-
-
-static int ffm_read_header(AVFormatContext *s, AVFormatParameters *ap)
-{
- FFMContext *ffm = s->priv_data;
- AVStream *st;
- FFMStream *fst;
- ByteIOContext *pb = &s->pb;
- AVCodecContext *codec;
- int i;
- UINT32 tag;
-
- /* header */
- tag = get_le32(pb);
- if (tag != MKTAG('F', 'F', 'M', '1'))
- goto fail;
- ffm->packet_size = get_be32(pb);
- if (ffm->packet_size != FFM_PACKET_SIZE)
- goto fail;
- ffm->write_index = get_be64(pb);
- /* get also filesize */
- if (!url_is_streamed(pb)) {
- ffm->file_size = url_filesize(url_fileno(pb));
- } else {
- ffm->file_size = (UINT64_C(1) << 63) - 1;
- }
-
- s->nb_streams = get_be32(pb);
- get_be32(pb); /* total bitrate */
- /* read each stream */
- for(i=0;i<s->nb_streams;i++) {
- char rc_eq_buf[128];
-
- st = av_mallocz(sizeof(AVStream));
- if (!st)
- goto fail;
- s->streams[i] = st;
- fst = av_mallocz(sizeof(FFMStream));
- if (!fst)
- goto fail;
- st->priv_data = fst;
-
- codec = &st->codec;
- /* generic info */
- st->codec.codec_id = get_be32(pb);
- st->codec.codec_type = get_byte(pb); /* codec_type */
- codec->bit_rate = get_be32(pb);
- codec->quality = get_be32(pb);
- codec->flags = get_be32(pb);
- /* specific info */
- switch(codec->codec_type) {
- case CODEC_TYPE_VIDEO:
- codec->frame_rate = ((INT64)get_be32(pb) * FRAME_RATE_BASE) / 1000;
- codec->width = get_be16(pb);
- codec->height = get_be16(pb);
- codec->gop_size = get_be16(pb);
- codec->qmin = get_byte(pb);
- codec->qmax = get_byte(pb);
- codec->max_qdiff = get_byte(pb);
- codec->qcompress = get_be16(pb) / 10000.0;
- codec->qblur = get_be16(pb) / 10000.0;
- codec->bit_rate_tolerance = get_be32(pb);
- codec->rc_eq = strdup(get_strz(pb, rc_eq_buf, sizeof(rc_eq_buf)));
- codec->rc_max_rate = get_be32(pb);
- codec->rc_min_rate = get_be32(pb);
- codec->rc_buffer_size = get_be32(pb);
- codec->i_quant_factor = get_be64_double(pb);
- codec->b_quant_factor = get_be64_double(pb);
- codec->i_quant_offset = get_be64_double(pb);
- codec->b_quant_offset = get_be64_double(pb);
- codec->dct_algo = get_be32(pb);
- break;
- case CODEC_TYPE_AUDIO:
- codec->sample_rate = get_be32(pb);
- codec->channels = get_le16(pb);
- codec->frame_size = get_le16(pb);
- break;
- default:
- goto fail;
- }
-
- }
-
- /* get until end of block reached */
- while ((url_ftell(pb) % ffm->packet_size) != 0)
- get_byte(pb);
-
- /* init packet demux */
- ffm->packet_ptr = ffm->packet;
- ffm->packet_end = ffm->packet;
- ffm->frame_offset = 0;
- ffm->pts = 0;
- ffm->read_state = READ_HEADER;
- ffm->first_packet = 1;
- return 0;
- fail:
- for(i=0;i<s->nb_streams;i++) {
- st = s->streams[i];
- if (st) {
- av_freep(&st->priv_data);
- av_free(st);
- }
- }
- return -1;
-}
-
-/* return < 0 if eof */
-static int ffm_read_packet(AVFormatContext *s, AVPacket *pkt)
-{
- int size;
- FFMContext *ffm = s->priv_data;
- int duration;
-
- switch(ffm->read_state) {
- case READ_HEADER:
- if (!ffm_is_avail_data(s, FRAME_HEADER_SIZE)) {
- return -EAGAIN;
- }
-#if 0
- printf("pos=%08Lx spos=%Lx, write_index=%Lx size=%Lx\n",
- url_ftell(&s->pb), s->pb.pos, ffm->write_index, ffm->file_size);
-#endif
- if (ffm_read_data(s, ffm->header, FRAME_HEADER_SIZE, 1) !=
- FRAME_HEADER_SIZE)
- return -EAGAIN;
-#if 0
- {
- int i;
- for(i=0;i<FRAME_HEADER_SIZE;i++)
- printf("%02x ", ffm->header[i]);
- printf("\n");
- }
-#endif
- ffm->read_state = READ_DATA;
- /* fall thru */
- case READ_DATA:
- size = (ffm->header[2] << 16) | (ffm->header[3] << 8) | ffm->header[4];
- if (!ffm_is_avail_data(s, size)) {
- return -EAGAIN;
- }
-
- duration = (ffm->header[5] << 16) | (ffm->header[6] << 8) | ffm->header[7];
-
- av_new_packet(pkt, size);
- pkt->stream_index = ffm->header[0];
- if (ffm->header[1] & FLAG_KEY_FRAME)
- pkt->flags |= PKT_FLAG_KEY;
-
- ffm->read_state = READ_HEADER;
- if (ffm_read_data(s, pkt->data, size, 0) != size) {
- /* bad case: desynchronized packet. we cancel all the packet loading */
- av_free_packet(pkt);
- return -EAGAIN;
- }
- pkt->pts = ffm->pts;
- pkt->duration = duration;
- break;
- }
- return 0;
-}
-
-//#define DEBUG_SEEK
-
-/* pos is between 0 and file_size - FFM_PACKET_SIZE. It is translated
- by the write position inside this function */
-static void ffm_seek1(AVFormatContext *s, offset_t pos1)
-{
- FFMContext *ffm = s->priv_data;
- ByteIOContext *pb = &s->pb;
- offset_t pos;
-
- pos = pos1 + ffm->write_index;
- if (pos >= ffm->file_size)
- pos -= (ffm->file_size - FFM_PACKET_SIZE);
-#ifdef DEBUG_SEEK
- printf("seek to %Lx -> %Lx\n", pos1, pos);
-#endif
- url_fseek(pb, pos, SEEK_SET);
-}
-
-static INT64 get_pts(AVFormatContext *s, offset_t pos)
-{
- ByteIOContext *pb = &s->pb;
- INT64 pts;
-
- ffm_seek1(s, pos);
- url_fskip(pb, 4);
- pts = get_be64(pb);
-#ifdef DEBUG_SEEK
- printf("pts=%0.6f\n", pts / 1000000.0);
-#endif
- return pts;
-}
-
-/* seek to a given time in the file. The file read pointer is
- positionned at or before pts. XXX: the following code is quite
- approximative */
-static int ffm_seek(AVFormatContext *s, INT64 wanted_pts)
-{
- FFMContext *ffm = s->priv_data;
- offset_t pos_min, pos_max, pos;
- INT64 pts_min, pts_max, pts;
- double pos1;
-
-#ifdef DEBUG_SEEK
- printf("wanted_pts=%0.6f\n", wanted_pts / 1000000.0);
-#endif
- /* find the position using linear interpolation (better than
- dichotomy in typical cases) */
- pos_min = 0;
- pos_max = ffm->file_size - 2 * FFM_PACKET_SIZE;
- while (pos_min <= pos_max) {
- pts_min = get_pts(s, pos_min);
- pts_max = get_pts(s, pos_max);
- /* linear interpolation */
- pos1 = (double)(pos_max - pos_min) * (double)(wanted_pts - pts_min) /
- (double)(pts_max - pts_min);
- pos = (((INT64)pos1) / FFM_PACKET_SIZE) * FFM_PACKET_SIZE;
- if (pos <= pos_min)
- pos = pos_min;
- else if (pos >= pos_max)
- pos = pos_max;
- pts = get_pts(s, pos);
- /* check if we are lucky */
- if (pts == wanted_pts) {
- goto found;
- } else if (pts > wanted_pts) {
- pos_max = pos - FFM_PACKET_SIZE;
- } else {
- pos_min = pos + FFM_PACKET_SIZE;
- }
- }
- pos = pos_min;
- if (pos > 0)
- pos -= FFM_PACKET_SIZE;
- found:
- ffm_seek1(s, pos);
- return 0;
-}
-
-offset_t ffm_read_write_index(int fd)
-{
- UINT8 buf[8];
- offset_t pos;
- int i;
-
- lseek(fd, 8, SEEK_SET);
- read(fd, buf, 8);
- pos = 0;
- for(i=0;i<8;i++)
- pos |= buf[i] << (56 - i * 8);
- return pos;
-}
-
-void ffm_write_write_index(int fd, offset_t pos)
-{
- UINT8 buf[8];
- int i;
-
- for(i=0;i<8;i++)
- buf[i] = (pos >> (56 - i * 8)) & 0xff;
- lseek(fd, 8, SEEK_SET);
- write(fd, buf, 8);
-}
-
-void ffm_set_write_index(AVFormatContext *s, offset_t pos, offset_t file_size)
-{
- FFMContext *ffm = s->priv_data;
- ffm->write_index = pos;
- ffm->file_size = file_size;
-}
-
-static int ffm_read_close(AVFormatContext *s)
-{
- AVStream *st;
- int i;
-
- for(i=0;i<s->nb_streams;i++) {
- st = s->streams[i];
- av_freep(&st->priv_data);
- }
- return 0;
-}
-
-static int ffm_probe(AVProbeData *p)
-{
- if (p->buf_size >= 4 &&
- p->buf[0] == 'F' && p->buf[1] == 'F' && p->buf[2] == 'M' &&
- p->buf[3] == '1')
- return AVPROBE_SCORE_MAX + 1;
- return 0;
-}
-
-static AVInputFormat ffm_iformat = {
- "ffm",
- "ffm format",
- sizeof(FFMContext),
- ffm_probe,
- ffm_read_header,
- ffm_read_packet,
- ffm_read_close,
- ffm_seek,
-};
-
-static AVOutputFormat ffm_oformat = {
- "ffm",
- "ffm format",
- "",
- "ffm",
- sizeof(FFMContext),
- /* not really used */
- CODEC_ID_MP2,
- CODEC_ID_MPEG1VIDEO,
- ffm_write_header,
- ffm_write_packet,
- ffm_write_trailer,
-};
-
-int ffm_init(void)
-{
- av_register_input_format(&ffm_iformat);
- av_register_output_format(&ffm_oformat);
- return 0;
-}
+++ /dev/null
-/*
- * Buffered file io for ffmpeg system
- * Copyright (c) 2001 Fabrice Bellard
- *
- * This library 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 of the License, or (at your option) any later version.
- *
- * This library 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 this library; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
-#include "avformat.h"
-#include <fcntl.h>
-#ifndef CONFIG_WIN32
-#include <unistd.h>
-#include <sys/ioctl.h>
-#include <sys/time.h>
-#else
-#include <io.h>
-#define open(fname,oflag,pmode) _open(fname,oflag,pmode)
-#endif /* CONFIG_WIN32 */
-
-
-/* standard file protocol */
-
-static int file_open(URLContext *h, const char *filename, int flags)
-{
- int access;
- int fd;
-
- if (flags & URL_WRONLY) {
- access = O_CREAT | O_TRUNC | O_WRONLY;
- } else {
- access = O_RDONLY;
- }
-#ifdef CONFIG_WIN32
- access |= O_BINARY;
-#endif
- fd = open(filename, access, 0666);
- if (fd < 0)
- return -ENOENT;
- h->priv_data = (void *)fd;
- return 0;
-}
-
-static int file_read(URLContext *h, unsigned char *buf, int size)
-{
- int fd = (int)h->priv_data;
- return read(fd, buf, size);
-}
-
-static int file_write(URLContext *h, unsigned char *buf, int size)
-{
- int fd = (int)h->priv_data;
- return write(fd, buf, size);
-}
-
-/* XXX: use llseek */
-static offset_t file_seek(URLContext *h, offset_t pos, int whence)
-{
- int fd = (int)h->priv_data;
-#ifdef CONFIG_WIN32
- return _lseeki64(fd, pos, whence);
-#else
- return lseek(fd, pos, whence);
-#endif
-}
-
-static int file_close(URLContext *h)
-{
- int fd = (int)h->priv_data;
- return close(fd);
-}
-
-URLProtocol file_protocol = {
- "file",
- file_open,
- file_read,
- file_write,
- file_seek,
- file_close,
-};
-
-/* pipe protocol */
-
-static int pipe_open(URLContext *h, const char *filename, int flags)
-{
- int fd;
-
- if (flags & URL_WRONLY) {
- fd = 1;
- } else {
- fd = 0;
- }
- h->priv_data = (void *)fd;
- return 0;
-}
-
-static int pipe_read(URLContext *h, unsigned char *buf, int size)
-{
- int fd = (int)h->priv_data;
- return read(fd, buf, size);
-}
-
-static int pipe_write(URLContext *h, unsigned char *buf, int size)
-{
- int fd = (int)h->priv_data;
- return write(fd, buf, size);
-}
-
-static int pipe_close(URLContext *h)
-{
- return 0;
-}
-
-URLProtocol pipe_protocol = {
- "pipe",
- pipe_open,
- pipe_read,
- pipe_write,
- NULL,
- pipe_close,
-};
+++ /dev/null
-/*
- * Video processing hooks
- * Copyright (c) 2000, 2001 Fabrice Bellard.
- *
- * This library 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 of the License, or (at your option) any later version.
- *
- * This library 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 this library; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
-#include <errno.h>
-#include "config.h"
-#include "framehook.h"
-#include "avformat.h"
-
-#ifdef HAVE_VHOOK
-#include <dlfcn.h>
-#endif
-
-
-typedef struct _FrameHookEntry {
- struct _FrameHookEntry *next;
- FrameHookConfigureFn Configure;
- FrameHookProcessFn Process;
- void *ctx;
-} FrameHookEntry;
-
-static FrameHookEntry *first_hook;
-
-/* Returns 0 on OK */
-int frame_hook_add(int argc, char *argv[])
-{
-#ifdef HAVE_VHOOK
- void *loaded;
- FrameHookEntry *fhe, **fhep;
-
- if (argc < 1) {
- return ENOENT;
- }
-
- loaded = dlopen(argv[0], RTLD_NOW);
- if (!loaded) {
- fprintf(stderr, "%s\n", dlerror());
- return -1;
- }
-
- fhe = av_mallocz(sizeof(*fhe));
- if (!fhe) {
- return errno;
- }
-
- fhe->Configure = dlsym(loaded, "Configure");
- fhe->Process = dlsym(loaded, "Process");
-
- if (!fhe->Process) {
- fprintf(stderr, "Failed to find Process entrypoint in %s\n", argv[0]);
- return -1;
- }
-
- if (!fhe->Configure && argc > 1) {
- fprintf(stderr, "Failed to find Configure entrypoint in %s\n", argv[0]);
- return -1;
- }
-
- if (argc > 1 || fhe->Configure) {
- if (fhe->Configure(&fhe->ctx, argc, argv)) {
- fprintf(stderr, "Failed to Configure %s\n", argv[0]);
- return -1;
- }
- }
-
- for (fhep = &first_hook; *fhep; fhep = &((*fhep)->next)) {
- }
-
- *fhep = fhe;
-
- return 0;
-#else
- fprintf(stderr, "Video hooking not compiled into this version\n");
- return 1;
-#endif
-}
-
-void frame_hook_process(AVPicture *pict, enum PixelFormat pix_fmt, int width, int height)
-{
- if (first_hook) {
- FrameHookEntry *fhe;
- INT64 pts = av_gettime();
-
- for (fhe = first_hook; fhe; fhe = fhe->next) {
- fhe->Process(fhe->ctx, pict, pix_fmt, width, height, pts);
- }
- }
-}
+++ /dev/null
-#ifndef _FRAMEHOOK_H
-#define _FRAMEHOOK_H
-
-/*
- * Prototypes for interface to .so that implement a video processing hook
- */
-
-#include "avcodec.h"
-
-/* Function must be called 'Configure' */
-typedef int (*FrameHookConfigureFn)(void **ctxp, int argc, char *argv[]);
-
-/* Function must be called 'Process' */
-typedef void (*FrameHookProcessFn)(void *ctx, struct AVPicture *pict, enum PixelFormat pix_fmt, int width, int height, INT64 pts);
-
-extern int frame_hook_add(int argc, char *argv[]);
-extern void frame_hook_process(struct AVPicture *pict, enum PixelFormat pix_fmt, int width, int height);
-
-#endif
+++ /dev/null
-/*
- * Animated GIF encoder
- * Copyright (c) 2000 Fabrice Bellard.
- *
- * This library 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 of the License, or (at your option) any later version.
- *
- * This library 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 this library; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
-
-/*
- * First version by Francois Revol revol@free.fr
- *
- * Features and limitations:
- * - currently no compression is performed,
- * in fact the size of the data is 9/8 the size of the image in 8bpp
- * - uses only a global standard palette
- * - tested with IE 5.0, Opera for BeOS, NetPositive (BeOS), and Mozilla (BeOS).
- *
- * Reference documents:
- * http://www.goice.co.jp/member/mo/formats/gif.html
- * http://astronomy.swin.edu.au/pbourke/dataformats/gif/
- * http://www.dcs.ed.ac.uk/home/mxr/gfx/2d/GIF89a.txt
- *
- * this url claims to have an LZW algorithm not covered by Unisys patent:
- * http://www.msg.net/utility/whirlgif/gifencod.html
- * could help reduce the size of the files _a lot_...
- * some sites mentions an RLE type compression also.
- */
-
-#include "avformat.h"
-
-/* bitstream minipacket size */
-#define GIF_CHUNKS 100
-
-/* slows down the decoding (and some browsers doesn't like it) */
-/* #define GIF_ADD_APP_HEADER */
-
-typedef struct {
- unsigned char r;
- unsigned char g;
- unsigned char b;
-} rgb_triplet;
-
-/* we use the standard 216 color palette */
-
-/* this script was used to create the palette:
- * for r in 00 33 66 99 cc ff; do for g in 00 33 66 99 cc ff; do echo -n " "; for b in 00 33 66 99 cc ff; do
- * echo -n "{ 0x$r, 0x$g, 0x$b }, "; done; echo ""; done; done
- */
-
-static const rgb_triplet gif_clut[216] = {
- { 0x00, 0x00, 0x00 }, { 0x00, 0x00, 0x33 }, { 0x00, 0x00, 0x66 }, { 0x00, 0x00, 0x99 }, { 0x00, 0x00, 0xcc }, { 0x00, 0x00, 0xff },
- { 0x00, 0x33, 0x00 }, { 0x00, 0x33, 0x33 }, { 0x00, 0x33, 0x66 }, { 0x00, 0x33, 0x99 }, { 0x00, 0x33, 0xcc }, { 0x00, 0x33, 0xff },
- { 0x00, 0x66, 0x00 }, { 0x00, 0x66, 0x33 }, { 0x00, 0x66, 0x66 }, { 0x00, 0x66, 0x99 }, { 0x00, 0x66, 0xcc }, { 0x00, 0x66, 0xff },
- { 0x00, 0x99, 0x00 }, { 0x00, 0x99, 0x33 }, { 0x00, 0x99, 0x66 }, { 0x00, 0x99, 0x99 }, { 0x00, 0x99, 0xcc }, { 0x00, 0x99, 0xff },
- { 0x00, 0xcc, 0x00 }, { 0x00, 0xcc, 0x33 }, { 0x00, 0xcc, 0x66 }, { 0x00, 0xcc, 0x99 }, { 0x00, 0xcc, 0xcc }, { 0x00, 0xcc, 0xff },
- { 0x00, 0xff, 0x00 }, { 0x00, 0xff, 0x33 }, { 0x00, 0xff, 0x66 }, { 0x00, 0xff, 0x99 }, { 0x00, 0xff, 0xcc }, { 0x00, 0xff, 0xff },
- { 0x33, 0x00, 0x00 }, { 0x33, 0x00, 0x33 }, { 0x33, 0x00, 0x66 }, { 0x33, 0x00, 0x99 }, { 0x33, 0x00, 0xcc }, { 0x33, 0x00, 0xff },
- { 0x33, 0x33, 0x00 }, { 0x33, 0x33, 0x33 }, { 0x33, 0x33, 0x66 }, { 0x33, 0x33, 0x99 }, { 0x33, 0x33, 0xcc }, { 0x33, 0x33, 0xff },
- { 0x33, 0x66, 0x00 }, { 0x33, 0x66, 0x33 }, { 0x33, 0x66, 0x66 }, { 0x33, 0x66, 0x99 }, { 0x33, 0x66, 0xcc }, { 0x33, 0x66, 0xff },
- { 0x33, 0x99, 0x00 }, { 0x33, 0x99, 0x33 }, { 0x33, 0x99, 0x66 }, { 0x33, 0x99, 0x99 }, { 0x33, 0x99, 0xcc }, { 0x33, 0x99, 0xff },
- { 0x33, 0xcc, 0x00 }, { 0x33, 0xcc, 0x33 }, { 0x33, 0xcc, 0x66 }, { 0x33, 0xcc, 0x99 }, { 0x33, 0xcc, 0xcc }, { 0x33, 0xcc, 0xff },
- { 0x33, 0xff, 0x00 }, { 0x33, 0xff, 0x33 }, { 0x33, 0xff, 0x66 }, { 0x33, 0xff, 0x99 }, { 0x33, 0xff, 0xcc }, { 0x33, 0xff, 0xff },
- { 0x66, 0x00, 0x00 }, { 0x66, 0x00, 0x33 }, { 0x66, 0x00, 0x66 }, { 0x66, 0x00, 0x99 }, { 0x66, 0x00, 0xcc }, { 0x66, 0x00, 0xff },
- { 0x66, 0x33, 0x00 }, { 0x66, 0x33, 0x33 }, { 0x66, 0x33, 0x66 }, { 0x66, 0x33, 0x99 }, { 0x66, 0x33, 0xcc }, { 0x66, 0x33, 0xff },
- { 0x66, 0x66, 0x00 }, { 0x66, 0x66, 0x33 }, { 0x66, 0x66, 0x66 }, { 0x66, 0x66, 0x99 }, { 0x66, 0x66, 0xcc }, { 0x66, 0x66, 0xff },
- { 0x66, 0x99, 0x00 }, { 0x66, 0x99, 0x33 }, { 0x66, 0x99, 0x66 }, { 0x66, 0x99, 0x99 }, { 0x66, 0x99, 0xcc }, { 0x66, 0x99, 0xff },
- { 0x66, 0xcc, 0x00 }, { 0x66, 0xcc, 0x33 }, { 0x66, 0xcc, 0x66 }, { 0x66, 0xcc, 0x99 }, { 0x66, 0xcc, 0xcc }, { 0x66, 0xcc, 0xff },
- { 0x66, 0xff, 0x00 }, { 0x66, 0xff, 0x33 }, { 0x66, 0xff, 0x66 }, { 0x66, 0xff, 0x99 }, { 0x66, 0xff, 0xcc }, { 0x66, 0xff, 0xff },
- { 0x99, 0x00, 0x00 }, { 0x99, 0x00, 0x33 }, { 0x99, 0x00, 0x66 }, { 0x99, 0x00, 0x99 }, { 0x99, 0x00, 0xcc }, { 0x99, 0x00, 0xff },
- { 0x99, 0x33, 0x00 }, { 0x99, 0x33, 0x33 }, { 0x99, 0x33, 0x66 }, { 0x99, 0x33, 0x99 }, { 0x99, 0x33, 0xcc }, { 0x99, 0x33, 0xff },
- { 0x99, 0x66, 0x00 }, { 0x99, 0x66, 0x33 }, { 0x99, 0x66, 0x66 }, { 0x99, 0x66, 0x99 }, { 0x99, 0x66, 0xcc }, { 0x99, 0x66, 0xff },
- { 0x99, 0x99, 0x00 }, { 0x99, 0x99, 0x33 }, { 0x99, 0x99, 0x66 }, { 0x99, 0x99, 0x99 }, { 0x99, 0x99, 0xcc }, { 0x99, 0x99, 0xff },
- { 0x99, 0xcc, 0x00 }, { 0x99, 0xcc, 0x33 }, { 0x99, 0xcc, 0x66 }, { 0x99, 0xcc, 0x99 }, { 0x99, 0xcc, 0xcc }, { 0x99, 0xcc, 0xff },
- { 0x99, 0xff, 0x00 }, { 0x99, 0xff, 0x33 }, { 0x99, 0xff, 0x66 }, { 0x99, 0xff, 0x99 }, { 0x99, 0xff, 0xcc }, { 0x99, 0xff, 0xff },
- { 0xcc, 0x00, 0x00 }, { 0xcc, 0x00, 0x33 }, { 0xcc, 0x00, 0x66 }, { 0xcc, 0x00, 0x99 }, { 0xcc, 0x00, 0xcc }, { 0xcc, 0x00, 0xff },
- { 0xcc, 0x33, 0x00 }, { 0xcc, 0x33, 0x33 }, { 0xcc, 0x33, 0x66 }, { 0xcc, 0x33, 0x99 }, { 0xcc, 0x33, 0xcc }, { 0xcc, 0x33, 0xff },
- { 0xcc, 0x66, 0x00 }, { 0xcc, 0x66, 0x33 }, { 0xcc, 0x66, 0x66 }, { 0xcc, 0x66, 0x99 }, { 0xcc, 0x66, 0xcc }, { 0xcc, 0x66, 0xff },
- { 0xcc, 0x99, 0x00 }, { 0xcc, 0x99, 0x33 }, { 0xcc, 0x99, 0x66 }, { 0xcc, 0x99, 0x99 }, { 0xcc, 0x99, 0xcc }, { 0xcc, 0x99, 0xff },
- { 0xcc, 0xcc, 0x00 }, { 0xcc, 0xcc, 0x33 }, { 0xcc, 0xcc, 0x66 }, { 0xcc, 0xcc, 0x99 }, { 0xcc, 0xcc, 0xcc }, { 0xcc, 0xcc, 0xff },
- { 0xcc, 0xff, 0x00 }, { 0xcc, 0xff, 0x33 }, { 0xcc, 0xff, 0x66 }, { 0xcc, 0xff, 0x99 }, { 0xcc, 0xff, 0xcc }, { 0xcc, 0xff, 0xff },
- { 0xff, 0x00, 0x00 }, { 0xff, 0x00, 0x33 }, { 0xff, 0x00, 0x66 }, { 0xff, 0x00, 0x99 }, { 0xff, 0x00, 0xcc }, { 0xff, 0x00, 0xff },
- { 0xff, 0x33, 0x00 }, { 0xff, 0x33, 0x33 }, { 0xff, 0x33, 0x66 }, { 0xff, 0x33, 0x99 }, { 0xff, 0x33, 0xcc }, { 0xff, 0x33, 0xff },
- { 0xff, 0x66, 0x00 }, { 0xff, 0x66, 0x33 }, { 0xff, 0x66, 0x66 }, { 0xff, 0x66, 0x99 }, { 0xff, 0x66, 0xcc }, { 0xff, 0x66, 0xff },
- { 0xff, 0x99, 0x00 }, { 0xff, 0x99, 0x33 }, { 0xff, 0x99, 0x66 }, { 0xff, 0x99, 0x99 }, { 0xff, 0x99, 0xcc }, { 0xff, 0x99, 0xff },
- { 0xff, 0xcc, 0x00 }, { 0xff, 0xcc, 0x33 }, { 0xff, 0xcc, 0x66 }, { 0xff, 0xcc, 0x99 }, { 0xff, 0xcc, 0xcc }, { 0xff, 0xcc, 0xff },
- { 0xff, 0xff, 0x00 }, { 0xff, 0xff, 0x33 }, { 0xff, 0xff, 0x66 }, { 0xff, 0xff, 0x99 }, { 0xff, 0xff, 0xcc }, { 0xff, 0xff, 0xff },
-};
-
-/* The GIF format uses reversed order for bitstreams... */
-/* at least they don't use PDP_ENDIAN :) */
-/* so we 'extend' PutBitContext. hmmm, OOP :) */
-/* seems this thing changed slightly since I wrote it... */
-
-#ifdef ALT_BITSTREAM_WRITER
-# error no ALT_BITSTREAM_WRITER support for now
-#endif
-
-static void gif_put_bits_rev(PutBitContext *s, int n, unsigned int value)
-{
- unsigned int bit_buf;
- int bit_cnt;
-
-#ifdef STATS
- st_out_bit_counts[st_current_index] += n;
-#endif
- // printf("put_bits=%d %x\n", n, value);
- assert(n == 32 || value < (1U << n));
-
- bit_buf = s->bit_buf;
- bit_cnt = 32 - s->bit_left; /* XXX:lazyness... was = s->bit_cnt; */
-
- // printf("n=%d value=%x cnt=%d buf=%x\n", n, value, bit_cnt, bit_buf);
- /* XXX: optimize */
- if (n < (32-bit_cnt)) {
- bit_buf |= value << (bit_cnt);
- bit_cnt+=n;
- } else {
- bit_buf |= value << (bit_cnt);
-
- *s->buf_ptr = bit_buf & 0xff;
- s->buf_ptr[1] = (bit_buf >> 8) & 0xff;
- s->buf_ptr[2] = (bit_buf >> 16) & 0xff;
- s->buf_ptr[3] = (bit_buf >> 24) & 0xff;
-
- //printf("bitbuf = %08x\n", bit_buf);
- s->buf_ptr+=4;
- if (s->buf_ptr >= s->buf_end)
- puts("bit buffer overflow !!"); // should never happen ! who got rid of the callback ???
-// flush_buffer_rev(s);
- bit_cnt=bit_cnt + n - 32;
- if (bit_cnt == 0) {
- bit_buf = 0;
- } else {
- bit_buf = value >> (n - bit_cnt);
- }
- }
-
- s->bit_buf = bit_buf;
- s->bit_left = 32 - bit_cnt;
-}
-
-/* pad the end of the output stream with zeros */
-static void gif_flush_put_bits_rev(PutBitContext *s)
-{
- while (s->bit_left < 32) {
- /* XXX: should test end of buffer */
- *s->buf_ptr++=s->bit_buf & 0xff;
- s->bit_buf>>=8;
- s->bit_left+=8;
- }
-// flush_buffer_rev(s);
- s->bit_left=32;
- s->bit_buf=0;
-}
-
-/* !RevPutBitContext */
-
-typedef struct {
- UINT8 buffer[100]; /* data chunks */
- INT64 time, file_time;
-} GIFContext;
-
-static int gif_write_header(AVFormatContext *s)
-{
- GIFContext *gif = s->priv_data;
- ByteIOContext *pb = &s->pb;
- AVCodecContext *enc, *video_enc;
- int i, width, height, rate;
-
-/* XXX: do we reject audio streams or just ignore them ?
- if(s->nb_streams > 1)
- return -1;
-*/
- gif->time = 0;
- gif->file_time = 0;
-
- video_enc = NULL;
- for(i=0;i<s->nb_streams;i++) {
- enc = &s->streams[i]->codec;
- if (enc->codec_type != CODEC_TYPE_AUDIO)
- video_enc = enc;
- }
-
- if (!video_enc) {
- av_free(gif);
- return -1;
- } else {
- width = video_enc->width;
- height = video_enc->height;
- rate = video_enc->frame_rate;
- }
-
- /* XXX: is it allowed ? seems to work so far... */
- video_enc->pix_fmt = PIX_FMT_RGB24;
-
- /* GIF header */
-
- put_tag(pb, "GIF");
- put_tag(pb, "89a");
- put_le16(pb, width);
- put_le16(pb, height);
-
- put_byte(pb, 0xf7); /* flags: global clut, 256 entries */
- put_byte(pb, 0x1f); /* background color index */
- put_byte(pb, 0); /* aspect ratio */
-
- /* the global palette */
-
- put_buffer(pb, (unsigned char *)gif_clut, 216*3);
- for(i=0;i<((256-216)*3);i++)
- put_byte(pb, 0);
-
- /* application extension header */
- /* XXX: not really sure what to put in here... */
-#ifdef GIF_ADD_APP_HEADER
- put_byte(pb, 0x21);
- put_byte(pb, 0xff);
- put_byte(pb, 0x0b);
- put_tag(pb, "NETSCAPE2.0");
- put_byte(pb, 0x03);
- put_byte(pb, 0x01);
- put_byte(pb, 0x00);
- put_byte(pb, 0x00);
-#endif
-
- put_flush_packet(&s->pb);
- return 0;
-}
-
-/* this is maybe slow, but allows for extensions */
-static inline unsigned char gif_clut_index(rgb_triplet *clut, UINT8 r, UINT8 g, UINT8 b)
-{
- return ((((r)/47)%6)*6*6+(((g)/47)%6)*6+(((b)/47)%6));
-}
-
-/* chunk writer callback */
-/* !!! XXX:deprecated
-static void gif_put_chunk(void *pbctx, UINT8 *buffer, int count)
-{
- ByteIOContext *pb = (ByteIOContext *)pbctx;
- put_byte(pb, (UINT8)count);
- put_buffer(pb, buffer, count);
-}
-*/
-
-static int gif_write_video(AVFormatContext *s,
- AVCodecContext *enc, UINT8 *buf, int size)
-{
- ByteIOContext *pb = &s->pb;
- GIFContext *gif = s->priv_data;
- int i, left, jiffies;
- INT64 delay;
- PutBitContext p;
- UINT8 buffer[200]; /* 100 * 9 / 8 = 113 */
-
-
- /* graphic control extension block */
- put_byte(pb, 0x21);
- put_byte(pb, 0xf9);
- put_byte(pb, 0x04); /* block size */
- put_byte(pb, 0x04); /* flags */
-
- /* 1 jiffy is 1/70 s */
- /* the delay_time field indicates the number of jiffies - 1 */
- delay = gif->file_time - gif->time;
-
- /* XXX: should use delay, in order to be more accurate */
- /* instead of using the same rounded value each time */
- /* XXX: don't even remember if I really use it for now */
- jiffies = (70*FRAME_RATE_BASE/enc->frame_rate) - 1;
-
- put_le16(pb, jiffies);
-
- put_byte(pb, 0x1f); /* transparent color index */
- put_byte(pb, 0x00);
-
- /* image block */
-
- put_byte(pb, 0x2c);
- put_le16(pb, 0);
- put_le16(pb, 0);
- put_le16(pb, enc->width);
- put_le16(pb, enc->height);
- put_byte(pb, 0x00); /* flags */
- /* no local clut */
-
- put_byte(pb, 0x08);
-
- left=size/3;
-
- init_put_bits(&p, buffer, 130, NULL, NULL);
-
-/*
- * the thing here is the bitstream is written as little packets, with a size byte before
- * but it's still the same bitstream between packets (no flush !)
- */
-
- while(left>0) {
-
- gif_put_bits_rev(&p, 9, 0x0100); /* clear code */
-
- for(i=0;i<GIF_CHUNKS;i++) {
- gif_put_bits_rev(&p, 9, gif_clut_index(NULL, *buf, buf[1], buf[2]));
- buf+=3;
- }
-
- if(left<=GIF_CHUNKS) {
- gif_put_bits_rev(&p, 9, 0x101); /* end of stream */
- gif_flush_put_bits_rev(&p);
- }
- if(pbBufPtr(&p) - p.buf > 0) {
- put_byte(pb, pbBufPtr(&p) - p.buf); /* byte count of the packet */
- put_buffer(pb, p.buf, pbBufPtr(&p) - p.buf); /* the actual buffer */
- p.data_out_size += pbBufPtr(&p) - p.buf;
- p.buf_ptr = p.buf; /* dequeue the bytes off the bitstream */
- }
- if(left<=GIF_CHUNKS) {
- put_byte(pb, 0x00); /* end of image block */
- }
-
- left-=GIF_CHUNKS;
- }
-
- put_flush_packet(&s->pb);
- return 0;
-}
-
-static int gif_write_packet(AVFormatContext *s, int stream_index,
- UINT8 *buf, int size, int force_pts)
-{
- AVCodecContext *codec = &s->streams[stream_index]->codec;
- if (codec->codec_type == CODEC_TYPE_AUDIO)
- return 0; /* just ignore audio */
- else
- return gif_write_video(s, codec, buf, size);
-}
-
-static int gif_write_trailer(AVFormatContext *s)
-{
- ByteIOContext *pb = &s->pb;
-
- put_byte(pb, 0x3b);
- put_flush_packet(&s->pb);
- return 0;
-}
-
-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,
-};
-
-int gif_init(void)
-{
- av_register_output_format(&gif_oformat);
- return 0;
-}
+++ /dev/null
-/*
- * Linux video grab interface
- * Copyright (c) 2000,2001 Fabrice Bellard.
- *
- * This library 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 of the License, or (at your option) any later version.
- *
- * This library 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 this library; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
-#include "avformat.h"
-#include <linux/videodev.h>
-#include <unistd.h>
-#include <fcntl.h>
-#include <sys/ioctl.h>
-#include <sys/mman.h>
-#include <sys/time.h>
-#include <time.h>
-
-typedef struct {
- int fd;
- int frame_format; /* see VIDEO_PALETTE_xxx */
- int use_mmap;
- int width, height;
- int frame_rate;
- INT64 time_frame;
- int frame_size;
- struct video_capability video_cap;
- struct video_audio audio_saved;
- UINT8 *video_buf;
- struct video_mbuf gb_buffers;
- struct video_mmap gb_buf;
- int gb_frame;
-
- /* ATI All In Wonder specific stuff */
- /* XXX: remove and merge in libavcodec/imgconvert.c */
- int aiw_enabled;
- int deint;
- int halfw;
- UINT8 *src_mem;
- UINT8 *lum_m4_mem;
-} VideoData;
-
-static int aiw_init(VideoData *s);
-static int aiw_read_picture(VideoData *s, uint8_t *data);
-static int aiw_close(VideoData *s);
-
-const char *v4l_device = "/dev/video";
-
-static int grab_read_header(AVFormatContext *s1, AVFormatParameters *ap)
-{
- VideoData *s = s1->priv_data;
- AVStream *st;
- int width, height;
- int video_fd, frame_size;
- int ret, frame_rate;
- int desired_palette;
- struct video_audio audio;
-
- if (!ap || ap->width <= 0 || ap->height <= 0 || ap->frame_rate <= 0)
- return -1;
-
- width = ap->width;
- height = ap->height;
- frame_rate = ap->frame_rate;
-
- st = av_new_stream(s1, 0);
- if (!st)
- return -ENOMEM;
-
- s->width = width;
- s->height = height;
- s->frame_rate = frame_rate;
-
- video_fd = open(v4l_device, O_RDWR);
- if (video_fd < 0) {
- perror(v4l_device);
- goto fail;
- }
-
- if (ioctl(video_fd,VIDIOCGCAP, &s->video_cap) < 0) {
- perror("VIDIOCGCAP");
- goto fail;
- }
-
- if (!(s->video_cap.type & VID_TYPE_CAPTURE)) {
- fprintf(stderr, "Fatal: grab device does not handle capture\n");
- goto fail;
- }
-
- desired_palette = -1;
- if (st->codec.pix_fmt == PIX_FMT_YUV420P) {
- desired_palette = VIDEO_PALETTE_YUV420P;
- } else if (st->codec.pix_fmt == PIX_FMT_YUV422) {
- desired_palette = VIDEO_PALETTE_YUV422;
- } else if (st->codec.pix_fmt == PIX_FMT_BGR24) {
- desired_palette = VIDEO_PALETTE_RGB24;
- }
-
- /* unmute audio */
- audio.audio = 0;
- ioctl(video_fd, VIDIOCGAUDIO, &audio);
- memcpy(&s->audio_saved, &audio, sizeof(audio));
- audio.flags &= ~VIDEO_AUDIO_MUTE;
- ioctl(video_fd, VIDIOCSAUDIO, &audio);
-
- ret = ioctl(video_fd,VIDIOCGMBUF,&s->gb_buffers);
- if (ret < 0) {
- /* try to use read based access */
- struct video_window win;
- struct video_picture pict;
- int val;
-
- win.x = 0;
- win.y = 0;
- win.width = width;
- win.height = height;
- win.chromakey = -1;
- win.flags = 0;
-
- ioctl(video_fd, VIDIOCSWIN, &win);
-
- ioctl(video_fd, VIDIOCGPICT, &pict);
-#if 0
- printf("v4l: colour=%d hue=%d brightness=%d constrast=%d whiteness=%d\n",
- pict.colour,
- pict.hue,
- pict.brightness,
- pict.contrast,
- pict.whiteness);
-#endif
- /* try to choose a suitable video format */
- pict.palette = desired_palette;
- if (desired_palette == -1 || (ret = ioctl(video_fd, VIDIOCSPICT, &pict)) < 0) {
- pict.palette=VIDEO_PALETTE_YUV420P;
- ret = ioctl(video_fd, VIDIOCSPICT, &pict);
- if (ret < 0) {
- pict.palette=VIDEO_PALETTE_YUV422;
- ret = ioctl(video_fd, VIDIOCSPICT, &pict);
- if (ret < 0) {
- pict.palette=VIDEO_PALETTE_RGB24;
- ret = ioctl(video_fd, VIDIOCSPICT, &pict);
- if (ret < 0)
- goto fail1;
- }
- }
- }
-
- s->frame_format = pict.palette;
-
- val = 1;
- ioctl(video_fd, VIDIOCCAPTURE, &val);
-
- s->time_frame = av_gettime();
- s->use_mmap = 0;
-
- /* ATI All In Wonder automatic activation */
- if (!strcmp(s->video_cap.name, "Km")) {
- if (aiw_init(s) < 0)
- goto fail;
- s->aiw_enabled = 1;
- /* force 420P format because convertion from YUV422 to YUV420P
- is done in this driver (ugly) */
- s->frame_format = VIDEO_PALETTE_YUV420P;
- }
- } else {
- s->video_buf = mmap(0,s->gb_buffers.size,PROT_READ|PROT_WRITE,MAP_SHARED,video_fd,0);
- if ((unsigned char*)-1 == s->video_buf) {
- perror("mmap");
- goto fail;
- }
- s->gb_frame = 0;
- s->time_frame = av_gettime();
-
- /* start to grab the first frame */
- s->gb_buf.frame = s->gb_frame % s->gb_buffers.frames;
- s->gb_buf.height = height;
- s->gb_buf.width = width;
- s->gb_buf.format = desired_palette;
-
- if (desired_palette == -1 || (ret = ioctl(video_fd, VIDIOCMCAPTURE, &s->gb_buf)) < 0) {
- s->gb_buf.format = VIDEO_PALETTE_YUV420P;
-
- ret = ioctl(video_fd, VIDIOCMCAPTURE, &s->gb_buf);
- if (ret < 0 && errno != EAGAIN) {
- /* try YUV422 */
- s->gb_buf.format = VIDEO_PALETTE_YUV422;
-
- ret = ioctl(video_fd, VIDIOCMCAPTURE, &s->gb_buf);
- if (ret < 0 && errno != EAGAIN) {
- /* try RGB24 */
- s->gb_buf.format = VIDEO_PALETTE_RGB24;
- ret = ioctl(video_fd, VIDIOCMCAPTURE, &s->gb_buf);
- }
- }
- }
- if (ret < 0) {
- if (errno != EAGAIN) {
- fail1:
- fprintf(stderr, "Fatal: grab device does not support suitable format\n");
- } else {
- fprintf(stderr,"Fatal: grab device does not receive any video signal\n");
- }
- goto fail;
- }
- s->frame_format = s->gb_buf.format;
- s->use_mmap = 1;
- }
-
- switch(s->frame_format) {
- case VIDEO_PALETTE_YUV420P:
- frame_size = (width * height * 3) / 2;
- st->codec.pix_fmt = PIX_FMT_YUV420P;
- break;
- case VIDEO_PALETTE_YUV422:
- frame_size = width * height * 2;
- st->codec.pix_fmt = PIX_FMT_YUV422;
- break;
- case VIDEO_PALETTE_RGB24:
- frame_size = width * height * 3;
- st->codec.pix_fmt = PIX_FMT_BGR24; /* NOTE: v4l uses BGR24, not RGB24 ! */
- break;
- default:
- goto fail;
- }
- s->fd = video_fd;
- s->frame_size = frame_size;
-
- st->codec.codec_type = CODEC_TYPE_VIDEO;
- st->codec.codec_id = CODEC_ID_RAWVIDEO;
- st->codec.width = width;
- st->codec.height = height;
- st->codec.frame_rate = frame_rate;
-
- av_set_pts_info(s1, 48, 1, 1000000); /* 48 bits pts in us */
-
- return 0;
- fail:
- if (video_fd >= 0)
- close(video_fd);
- av_free(st);
- return -EIO;
-}
-
-static int v4l_mm_read_picture(VideoData *s, UINT8 *buf)
-{
- UINT8 *ptr;
-
- /* Setup to capture the next frame */
- s->gb_buf.frame = (s->gb_frame + 1) % s->gb_buffers.frames;
- if (ioctl(s->fd, VIDIOCMCAPTURE, &s->gb_buf) < 0) {
- if (errno == EAGAIN)
- fprintf(stderr,"Cannot Sync\n");
- else
- perror("VIDIOCMCAPTURE");
- return -EIO;
- }
-
- while (ioctl(s->fd, VIDIOCSYNC, &s->gb_frame) < 0 &&
- (errno == EAGAIN || errno == EINTR));
-
- ptr = s->video_buf + s->gb_buffers.offsets[s->gb_frame];
- memcpy(buf, ptr, s->frame_size);
-
- /* This is now the grabbing frame */
- s->gb_frame = s->gb_buf.frame;
-
- return s->frame_size;
-}
-
-static int grab_read_packet(AVFormatContext *s1, AVPacket *pkt)
-{
- VideoData *s = s1->priv_data;
- INT64 curtime, delay;
- struct timespec ts;
- INT64 per_frame = (INT64_C(1000000) * FRAME_RATE_BASE) / s->frame_rate;
-
- /* Calculate the time of the next frame */
- s->time_frame += per_frame;
-
- /* wait based on the frame rate */
- for(;;) {
- curtime = av_gettime();
- delay = s->time_frame - curtime;
- if (delay <= 0) {
- if (delay < -per_frame) {
- /* printf("grabbing is %d frames late (dropping)\n", (int) -(delay / 16666)); */
- s->time_frame += per_frame;
- }
- break;
- }
- ts.tv_sec = delay / 1000000;
- ts.tv_nsec = (delay % 1000000) * 1000;
- nanosleep(&ts, NULL);
- }
-
- if (av_new_packet(pkt, s->frame_size) < 0)
- return -EIO;
-
- pkt->pts = curtime & ((1LL << 48) - 1);
-
- /* read one frame */
- if (s->aiw_enabled) {
- return aiw_read_picture(s, pkt->data);
- } else if (s->use_mmap) {
- return v4l_mm_read_picture(s, pkt->data);
- } else {
- if (read(s->fd, pkt->data, pkt->size) != pkt->size)
- return -EIO;
- return s->frame_size;
- }
-}
-
-static int grab_read_close(AVFormatContext *s1)
-{
- VideoData *s = s1->priv_data;
-
- if (s->aiw_enabled)
- aiw_close(s);
-
- if (s->use_mmap)
- munmap(s->video_buf, s->gb_buffers.size);
-
- /* mute audio. we must force it because the BTTV driver does not
- return its state correctly */
- s->audio_saved.flags |= VIDEO_AUDIO_MUTE;
- ioctl(s->fd, VIDIOCSAUDIO, &s->audio_saved);
-
- close(s->fd);
- return 0;
-}
-
-static AVInputFormat video_grab_device_format = {
- "video_grab_device",
- "video grab",
- sizeof(VideoData),
- NULL,
- grab_read_header,
- grab_read_packet,
- grab_read_close,
- .flags = AVFMT_NOFILE,
-};
-
-/* All in Wonder specific stuff */
-/* XXX: remove and merge in libavcodec/imgconvert.c */
-
-static int aiw_init(VideoData *s)
-{
- int width, height;
-
- width = s->width;
- height = s->height;
-
- if ((width == s->video_cap.maxwidth && height == s->video_cap.maxheight) ||
- (width == s->video_cap.maxwidth && height == s->video_cap.maxheight*2) ||
- (width == s->video_cap.maxwidth/2 && height == s->video_cap.maxheight)) {
-
- s->deint=0;
- s->halfw=0;
- if (height == s->video_cap.maxheight*2) s->deint=1;
- if (width == s->video_cap.maxwidth/2) s->halfw=1;
- } else {
- fprintf(stderr,"\nIncorrect Grab Size Supplied - Supported Sizes Are:\n");
- fprintf(stderr," %dx%d %dx%d %dx%d\n\n",
- s->video_cap.maxwidth,s->video_cap.maxheight,
- s->video_cap.maxwidth,s->video_cap.maxheight*2,
- s->video_cap.maxwidth/2,s->video_cap.maxheight);
- goto fail;
- }
-
- if (s->halfw == 0) {
- s->src_mem = av_malloc(s->width*2);
- } else {
- s->src_mem = av_malloc(s->width*4);
- }
- if (!s->src_mem) goto fail;
-
- s->lum_m4_mem = av_malloc(s->width);
- if (!s->lum_m4_mem)
- goto fail;
- return 0;
- fail:
- av_freep(&s->src_mem);
- av_freep(&s->lum_m4_mem);
- return -1;
-}
-
-#ifdef HAVE_MMX
-#include "../libavcodec/i386/mmx.h"
-
-#define LINE_WITH_UV \
- movq_m2r(ptr[0],mm0); \
- movq_m2r(ptr[8],mm1); \
- movq_r2r(mm0, mm4); \
- punpcklbw_r2r(mm1,mm0); \
- punpckhbw_r2r(mm1,mm4); \
- movq_r2r(mm0,mm5); \
- punpcklbw_r2r(mm4,mm0); \
- punpckhbw_r2r(mm4,mm5); \
- movq_r2r(mm0,mm1); \
- punpcklbw_r2r(mm5,mm1); \
- movq_r2m(mm1,lum[0]); \
- movq_m2r(ptr[16],mm2); \
- movq_m2r(ptr[24],mm1); \
- movq_r2r(mm2,mm4); \
- punpcklbw_r2r(mm1,mm2); \
- punpckhbw_r2r(mm1,mm4); \
- movq_r2r(mm2,mm3); \
- punpcklbw_r2r(mm4,mm2); \
- punpckhbw_r2r(mm4,mm3); \
- movq_r2r(mm2,mm1); \
- punpcklbw_r2r(mm3,mm1); \
- movq_r2m(mm1,lum[8]); \
- punpckhdq_r2r(mm2,mm0); \
- punpckhdq_r2r(mm3,mm5); \
- movq_r2m(mm0,cb[0]); \
- movq_r2m(mm5,cr[0]);
-
-#define LINE_NO_UV \
- movq_m2r(ptr[0],mm0);\
- movq_m2r(ptr[8],mm1);\
- movq_r2r(mm0, mm4);\
- punpcklbw_r2r(mm1,mm0); \
- punpckhbw_r2r(mm1,mm4);\
- movq_r2r(mm0,mm5);\
- punpcklbw_r2r(mm4,mm0);\
- punpckhbw_r2r(mm4,mm5);\
- movq_r2r(mm0,mm1);\
- punpcklbw_r2r(mm5,mm1);\
- movq_r2m(mm1,lum[0]);\
- movq_m2r(ptr[16],mm2);\
- movq_m2r(ptr[24],mm1);\
- movq_r2r(mm2,mm4);\
- punpcklbw_r2r(mm1,mm2);\
- punpckhbw_r2r(mm1,mm4);\
- movq_r2r(mm2,mm3);\
- punpcklbw_r2r(mm4,mm2);\
- punpckhbw_r2r(mm4,mm3);\
- movq_r2r(mm2,mm1);\
- punpcklbw_r2r(mm3,mm1);\
- movq_r2m(mm1,lum[8]);
-
-#define LINE_WITHUV_AVG \
- movq_m2r(ptr[0], mm0);\
- movq_m2r(ptr[8], mm1);\
- movq_r2r(mm0, mm4);\
- punpcklbw_r2r(mm1,mm0);\
- punpckhbw_r2r(mm1,mm4);\
- movq_r2r(mm0,mm5);\
- punpcklbw_r2r(mm4,mm0);\
- punpckhbw_r2r(mm4,mm5);\
- movq_r2r(mm0,mm1);\
- movq_r2r(mm5,mm2);\
- punpcklbw_r2r(mm7,mm1);\
- punpcklbw_r2r(mm7,mm2);\
- paddw_r2r(mm6,mm1);\
- paddw_r2r(mm2,mm1);\
- psraw_i2r(1,mm1);\
- packuswb_r2r(mm7,mm1);\
- movd_r2m(mm1,lum[0]);\
- movq_m2r(ptr[16],mm2);\
- movq_m2r(ptr[24],mm1);\
- movq_r2r(mm2,mm4);\
- punpcklbw_r2r(mm1,mm2);\
- punpckhbw_r2r(mm1,mm4);\
- movq_r2r(mm2,mm3);\
- punpcklbw_r2r(mm4,mm2);\
- punpckhbw_r2r(mm4,mm3);\
- movq_r2r(mm2,mm1);\
- movq_r2r(mm3,mm4);\
- punpcklbw_r2r(mm7,mm1);\
- punpcklbw_r2r(mm7,mm4);\
- paddw_r2r(mm6,mm1);\
- paddw_r2r(mm4,mm1);\
- psraw_i2r(1,mm1);\
- packuswb_r2r(mm7,mm1);\
- movd_r2m(mm1,lum[4]);\
- punpckhbw_r2r(mm7,mm0);\
- punpckhbw_r2r(mm7,mm2);\
- paddw_r2r(mm6,mm0);\
- paddw_r2r(mm2,mm0);\
- psraw_i2r(1,mm0);\
- packuswb_r2r(mm7,mm0);\
- punpckhbw_r2r(mm7,mm5);\
- punpckhbw_r2r(mm7,mm3);\
- paddw_r2r(mm6,mm5);\
- paddw_r2r(mm3,mm5);\
- psraw_i2r(1,mm5);\
- packuswb_r2r(mm7,mm5);\
- movd_r2m(mm0,cb[0]);\
- movd_r2m(mm5,cr[0]);
-
-#define LINE_NOUV_AVG \
- movq_m2r(ptr[0],mm0);\
- movq_m2r(ptr[8],mm1);\
- pand_r2r(mm5,mm0);\
- pand_r2r(mm5,mm1);\
- pmaddwd_r2r(mm6,mm0);\
- pmaddwd_r2r(mm6,mm1);\
- packssdw_r2r(mm1,mm0);\
- paddw_r2r(mm6,mm0);\
- psraw_i2r(1,mm0);\
- movq_m2r(ptr[16],mm2);\
- movq_m2r(ptr[24],mm3);\
- pand_r2r(mm5,mm2);\
- pand_r2r(mm5,mm3);\
- pmaddwd_r2r(mm6,mm2);\
- pmaddwd_r2r(mm6,mm3);\
- packssdw_r2r(mm3,mm2);\
- paddw_r2r(mm6,mm2);\
- psraw_i2r(1,mm2);\
- packuswb_r2r(mm2,mm0);\
- movq_r2m(mm0,lum[0]);
-
-#define DEINT_LINE_LUM(ptroff) \
- movd_m2r(lum_m4[(ptroff)],mm0);\
- movd_m2r(lum_m3[(ptroff)],mm1);\
- movd_m2r(lum_m2[(ptroff)],mm2);\
- movd_m2r(lum_m1[(ptroff)],mm3);\
- movd_m2r(lum[(ptroff)],mm4);\
- punpcklbw_r2r(mm7,mm0);\
- movd_r2m(mm2,lum_m4[(ptroff)]);\
- punpcklbw_r2r(mm7,mm1);\
- punpcklbw_r2r(mm7,mm2);\
- punpcklbw_r2r(mm7,mm3);\
- punpcklbw_r2r(mm7,mm4);\
- psllw_i2r(2,mm1);\
- psllw_i2r(1,mm2);\
- paddw_r2r(mm6,mm1);\
- psllw_i2r(2,mm3);\
- paddw_r2r(mm2,mm1);\
- paddw_r2r(mm4,mm0);\
- paddw_r2r(mm3,mm1);\
- psubusw_r2r(mm0,mm1);\
- psrlw_i2r(3,mm1);\
- packuswb_r2r(mm7,mm1);\
- movd_r2m(mm1,lum_m2[(ptroff)]);
-
-#else
-#include "../libavcodec/dsputil.h"
-
-#define LINE_WITH_UV \
- lum[0]=ptr[0];lum[1]=ptr[2];lum[2]=ptr[4];lum[3]=ptr[6];\
- cb[0]=ptr[1];cb[1]=ptr[5];\
- cr[0]=ptr[3];cr[1]=ptr[7];\
- lum[4]=ptr[8];lum[5]=ptr[10];lum[6]=ptr[12];lum[7]=ptr[14];\
- cb[2]=ptr[9];cb[3]=ptr[13];\
- cr[2]=ptr[11];cr[3]=ptr[15];\
- lum[8]=ptr[16];lum[9]=ptr[18];lum[10]=ptr[20];lum[11]=ptr[22];\
- cb[4]=ptr[17];cb[5]=ptr[21];\
- cr[4]=ptr[19];cr[5]=ptr[23];\
- lum[12]=ptr[24];lum[13]=ptr[26];lum[14]=ptr[28];lum[15]=ptr[30];\
- cb[6]=ptr[25];cb[7]=ptr[29];\
- cr[6]=ptr[27];cr[7]=ptr[31];
-
-#define LINE_NO_UV \
- lum[0]=ptr[0];lum[1]=ptr[2];lum[2]=ptr[4];lum[3]=ptr[6];\
- lum[4]=ptr[8];lum[5]=ptr[10];lum[6]=ptr[12];lum[7]=ptr[14];\
- lum[8]=ptr[16];lum[9]=ptr[18];lum[10]=ptr[20];lum[11]=ptr[22];\
- lum[12]=ptr[24];lum[13]=ptr[26];lum[14]=ptr[28];lum[15]=ptr[30];
-
-#define LINE_WITHUV_AVG \
- sum=(ptr[0]+ptr[2]+1) >> 1;lum[0]=sum; \
- sum=(ptr[4]+ptr[6]+1) >> 1;lum[1]=sum; \
- sum=(ptr[1]+ptr[5]+1) >> 1;cb[0]=sum; \
- sum=(ptr[3]+ptr[7]+1) >> 1;cr[0]=sum; \
- sum=(ptr[8]+ptr[10]+1) >> 1;lum[2]=sum; \
- sum=(ptr[12]+ptr[14]+1) >> 1;lum[3]=sum; \
- sum=(ptr[9]+ptr[13]+1) >> 1;cb[1]=sum; \
- sum=(ptr[11]+ptr[15]+1) >> 1;cr[1]=sum; \
- sum=(ptr[16]+ptr[18]+1) >> 1;lum[4]=sum; \
- sum=(ptr[20]+ptr[22]+1) >> 1;lum[5]=sum; \
- sum=(ptr[17]+ptr[21]+1) >> 1;cb[2]=sum; \
- sum=(ptr[19]+ptr[23]+1) >> 1;cr[2]=sum; \
- sum=(ptr[24]+ptr[26]+1) >> 1;lum[6]=sum; \
- sum=(ptr[28]+ptr[30]+1) >> 1;lum[7]=sum; \
- sum=(ptr[25]+ptr[29]+1) >> 1;cb[3]=sum; \
- sum=(ptr[27]+ptr[31]+1) >> 1;cr[3]=sum;
-
-#define LINE_NOUV_AVG \
- sum=(ptr[0]+ptr[2]+1) >> 1;lum[0]=sum; \
- sum=(ptr[4]+ptr[6]+1) >> 1;lum[1]=sum; \
- sum=(ptr[8]+ptr[10]+1) >> 1;lum[2]=sum; \
- sum=(ptr[12]+ptr[14]+1) >> 1;lum[3]=sum; \
- sum=(ptr[16]+ptr[18]+1) >> 1;lum[4]=sum; \
- sum=(ptr[20]+ptr[22]+1) >> 1;lum[5]=sum; \
- sum=(ptr[24]+ptr[26]+1) >> 1;lum[6]=sum; \
- sum=(ptr[28]+ptr[30]+1) >> 1;lum[7]=sum;
-
-#define DEINT_LINE_LUM(ptroff) \
- sum=(-lum_m4[(ptroff)]+(lum_m3[(ptroff)]<<2)+(lum_m2[(ptroff)]<<1)+(lum_m1[(ptroff)]<<2)-lum[(ptroff)]); \
- lum_m4[(ptroff)]=lum_m2[(ptroff)];\
- lum_m2[(ptroff)]=cm[(sum+4)>>3];\
- sum=(-lum_m4[(ptroff)+1]+(lum_m3[(ptroff)+1]<<2)+(lum_m2[(ptroff)+1]<<1)+(lum_m1[(ptroff)+1]<<2)-lum[(ptroff)+1]); \
- lum_m4[(ptroff)+1]=lum_m2[(ptroff)+1];\
- lum_m2[(ptroff)+1]=cm[(sum+4)>>3];\
- sum=(-lum_m4[(ptroff)+2]+(lum_m3[(ptroff)+2]<<2)+(lum_m2[(ptroff)+2]<<1)+(lum_m1[(ptroff)+2]<<2)-lum[(ptroff)+2]); \
- lum_m4[(ptroff)+2]=lum_m2[(ptroff)+2];\
- lum_m2[(ptroff)+2]=cm[(sum+4)>>3];\
- sum=(-lum_m4[(ptroff)+3]+(lum_m3[(ptroff)+3]<<2)+(lum_m2[(ptroff)+3]<<1)+(lum_m1[(ptroff)+3]<<2)-lum[(ptroff)+3]); \
- lum_m4[(ptroff)+3]=lum_m2[(ptroff)+3];\
- lum_m2[(ptroff)+3]=cm[(sum+4)>>3];
-
-#endif
-
-
-/* Read two fields separately. */
-static int aiw_read_picture(VideoData *s, uint8_t *data)
-{
- UINT8 *ptr, *lum, *cb, *cr;
- int h;
-#ifndef HAVE_MMX
- int sum;
-#endif
- UINT8* src = s->src_mem;
- UINT8 *ptrend = &src[s->width*2];
- lum=data;
- cb=&lum[s->width*s->height];
- cr=&cb[(s->width*s->height)/4];
- if (s->deint == 0 && s->halfw == 0) {
- while (read(s->fd,src,s->width*2) < 0) {
- usleep(100);
- }
- for (h = 0; h < s->height-2; h+=2) {
- for (ptr = &src[0]; ptr < ptrend; ptr+=32, lum+=16, cb+=8, cr+=8) {
- LINE_WITH_UV
- }
- read(s->fd,src,s->width*2);
- for (ptr = &src[0]; ptr < ptrend; ptr+=32, lum+=16) {
- LINE_NO_UV
- }
- read(s->fd,src,s->width*2);
- }
- /*
- * Do last two lines
- */
- for (ptr = &src[0]; ptr < ptrend; ptr+=32, lum+=16, cb+=8, cr+=8) {
- LINE_WITH_UV
- }
- read(s->fd,src,s->width*2);
- for (ptr = &src[0]; ptr < ptrend; ptr+=32, lum+=16) {
- LINE_NO_UV
- }
- /* drop second field */
- while (read(s->fd,src,s->width*2) < 0) {
- usleep(100);
- }
- for (h = 0; h < s->height - 1; h++) {
- read(s->fd,src,s->width*2);
- }
- } else if (s->halfw == 1) {
-#ifdef HAVE_MMX
- mmx_t rounder;
- mmx_t masker;
- rounder.uw[0]=1;
- rounder.uw[1]=1;
- rounder.uw[2]=1;
- rounder.uw[3]=1;
- masker.ub[0]=0xff;
- masker.ub[1]=0;
- masker.ub[2]=0xff;
- masker.ub[3]=0;
- masker.ub[4]=0xff;
- masker.ub[5]=0;
- masker.ub[6]=0xff;
- masker.ub[7]=0;
- pxor_r2r(mm7,mm7);
- movq_m2r(rounder,mm6);
-#endif
- while (read(s->fd,src,s->width*4) < 0) {
- usleep(100);
- }
- ptrend = &src[s->width*4];
- for (h = 0; h < s->height-2; h+=2) {
- for (ptr = &src[0]; ptr < ptrend; ptr+=32, lum+=8, cb+=4, cr+=4) {
- LINE_WITHUV_AVG
- }
- read(s->fd,src,s->width*4);
-#ifdef HAVE_MMX
- movq_m2r(masker,mm5);
-#endif
- for (ptr = &src[0]; ptr < ptrend; ptr+=32, lum+=8) {
- LINE_NOUV_AVG
- }
- read(s->fd,src,s->width*4);
- }
- /*
- * Do last two lines
- */
- for (ptr = &src[0]; ptr < ptrend; ptr+=32, lum+=8, cb+=4, cr+=4) {
- LINE_WITHUV_AVG
- }
- read(s->fd,src,s->width*4);
-#ifdef HAVE_MMX
- movq_m2r(masker,mm5);
-#endif
- for (ptr = &src[0]; ptr < ptrend; ptr+=32, lum+=8) {
- LINE_NOUV_AVG
- }
- /* drop second field */
- while (read(s->fd,src,s->width*4) < 0) {
- usleep(100);
- }
- for (h = 0; h < s->height - 1; h++) {
- read(s->fd,src,s->width*4);
- }
- } else {
- UINT8 *lum_m1, *lum_m2, *lum_m3, *lum_m4;
-#ifdef HAVE_MMX
- mmx_t rounder;
- rounder.uw[0]=4;
- rounder.uw[1]=4;
- rounder.uw[2]=4;
- rounder.uw[3]=4;
- movq_m2r(rounder,mm6);
- pxor_r2r(mm7,mm7);
-#else
- UINT8 *cm = cropTbl + MAX_NEG_CROP;
-#endif
-
- /* read two fields and deinterlace them */
- while (read(s->fd,src,s->width*2) < 0) {
- usleep(100);
- }
- for (h = 0; h < (s->height/2)-2; h+=2) {
- for (ptr = &src[0]; ptr < ptrend; ptr+=32, lum+=16, cb+=8, cr+=8) {
- LINE_WITH_UV
- }
- read(s->fd,src,s->width*2);
- /* skip a luminance line - will be filled in later */
- lum += s->width;
- for (ptr = &src[0]; ptr < ptrend; ptr+=32, lum+=16, cb+=8, cr+=8) {
- LINE_WITH_UV
- }
- /* skip a luminance line - will be filled in later */
- lum += s->width;
- read(s->fd,src,s->width*2);
- }
- /*
- * Do last two lines
- */
- for (ptr = &src[0]; ptr < ptrend; ptr+=32, lum+=16, cb+=8, cr+=8) {
- LINE_WITH_UV
- }
- /* skip a luminance line - will be filled in later */
- lum += s->width;
- read(s->fd,src,s->width*2);
- for (ptr = &src[0]; ptr < ptrend; ptr+=32, lum+=16, cb+=8, cr+=8) {
- LINE_WITH_UV
- }
- /*
- *
- * SECOND FIELD
- *
- */
- lum=&data[s->width];
- while (read(s->fd,src,s->width*2) < 0) {
- usleep(10);
- }
- /* First (and last) two lines not interlaced */
- for (h = 0; h < 2; h++) {
- for (ptr = &src[0]; ptr < ptrend; ptr+=32, lum+=16) {
- LINE_NO_UV
- }
- read(s->fd,src,s->width*2);
- /* skip a luminance line */
- lum += s->width;
- }
- lum_m1=&lum[-s->width];
- lum_m2=&lum_m1[-s->width];
- lum_m3=&lum_m2[-s->width];
- memmove(s->lum_m4_mem,&lum_m3[-s->width],s->width);
- for (; h < (s->height/2)-1; h++) {
- lum_m4=s->lum_m4_mem;
- for (ptr = &src[0]; ptr < ptrend; ptr+=32, lum+=16,lum_m1+=16,lum_m2+=16,lum_m3+=16,lum_m4+=16) {
- LINE_NO_UV
-
- DEINT_LINE_LUM(0)
- DEINT_LINE_LUM(4)
- DEINT_LINE_LUM(8)
- DEINT_LINE_LUM(12)
- }
- read(s->fd,src,s->width*2);
- /* skip a luminance line */
- lum += s->width;
- lum_m1 += s->width;
- lum_m2 += s->width;
- lum_m3 += s->width;
- // lum_m4 += s->width;
- }
- /*
- * Do last line
- */
- lum_m4=s->lum_m4_mem;
- for (ptr = &src[0]; ptr < ptrend; ptr+=32, lum+=16, lum_m1+=16, lum_m2+=16, lum_m3+=16, lum_m4+=16) {
- LINE_NO_UV
-
- DEINT_LINE_LUM(0)
- DEINT_LINE_LUM(4)
- DEINT_LINE_LUM(8)
- DEINT_LINE_LUM(12)
- }
- }
-#ifdef HAVE_MMX
- emms();
-#endif
- return s->frame_size;
-}
-
-static int aiw_close(VideoData *s)
-{
- av_freep(&s->lum_m4_mem);
- av_freep(&s->src_mem);
- return 0;
-}
-
-int video_grab_init(void)
-{
- av_register_input_format(&video_grab_device_format);
- return 0;
-}
+++ /dev/null
-/*
- * HTTP protocol for ffmpeg client
- * Copyright (c) 2000, 2001 Fabrice Bellard.
- *
- * This library 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 of the License, or (at your option) any later version.
- *
- * This library 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 this library; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
-#include "avformat.h"
-#include <unistd.h>
-#include <ctype.h>
-#include <sys/types.h>
-#include <sys/socket.h>
-#include <netinet/in.h>
-#ifndef __BEOS__
-# include <arpa/inet.h>
-#else
-# include "barpainet.h"
-#endif
-#include <netdb.h>
-
-
-/* XXX: POST protocol is not completly implemented because ffmpeg use
- only a subset of it */
-
-//#define DEBUG
-
-/* used for protocol handling */
-#define BUFFER_SIZE 1024
-#define URL_SIZE 4096
-
-typedef struct {
- URLContext *hd;
- unsigned char buffer[BUFFER_SIZE], *buf_ptr, *buf_end;
- int line_count;
- int http_code;
- char location[URL_SIZE];
-} HTTPContext;
-
-static int http_connect(URLContext *h, const char *path, const char *hoststr);
-static int http_write(URLContext *h, UINT8 *buf, int size);
-
-
-/* return non zero if error */
-static int http_open(URLContext *h, const char *uri, int flags)
-{
- const char *path, *proxy_path;
- char hostname[1024], hoststr[1024];
- char path1[1024];
- char buf[1024];
- int port, use_proxy, err;
- HTTPContext *s;
- URLContext *hd = NULL;
-
- h->is_streamed = 1;
-
- s = av_malloc(sizeof(HTTPContext));
- if (!s) {
- return -ENOMEM;
- }
- h->priv_data = s;
-
- proxy_path = getenv("http_proxy");
- use_proxy = (proxy_path != NULL) && !getenv("no_proxy") &&
- strstart(proxy_path, "http://", NULL);
-
- /* fill the dest addr */
- redo:
- /* needed in any case to build the host string */
- url_split(NULL, 0, hostname, sizeof(hostname), &port,
- path1, sizeof(path1), uri);
- if (port > 0) {
- snprintf(hoststr, sizeof(hoststr), "%s:%d", hostname, port);
- } else {
- pstrcpy(hoststr, sizeof(hoststr), hostname);
- }
-
- if (use_proxy) {
- url_split(NULL, 0, hostname, sizeof(hostname), &port,
- NULL, 0, proxy_path);
- path = uri;
- } else {
- if (path1[0] == '\0')
- path = "/";
- else
- path = path1;
- }
- if (port < 0)
- port = 80;
-
- snprintf(buf, sizeof(buf), "tcp://%s:%d", hostname, port);
- err = url_open(&hd, buf, URL_RDWR);
- if (err < 0)
- goto fail;
-
- s->hd = hd;
- if (http_connect(h, path, hoststr) < 0)
- goto fail;
- if (s->http_code == 303 && s->location[0] != '\0') {
- /* url moved, get next */
- uri = s->location;
- url_close(hd);
- goto redo;
- }
- return 0;
- fail:
- if (hd)
- url_close(hd);
- av_free(s);
- return -EIO;
-}
-
-static int http_getc(HTTPContext *s)
-{
- int len;
- if (s->buf_ptr >= s->buf_end) {
- len = url_read(s->hd, s->buffer, BUFFER_SIZE);
- if (len < 0) {
- return -EIO;
- } else if (len == 0) {
- return -1;
- } else {
- s->buf_ptr = s->buffer;
- s->buf_end = s->buffer + len;
- }
- }
- return *s->buf_ptr++;
-}
-
-static int process_line(HTTPContext *s, char *line, int line_count)
-{
- char *tag, *p;
-
- /* end of header */
- if (line[0] == '\0')
- return 0;
-
- p = line;
- if (line_count == 0) {
- while (!isspace(*p) && *p != '\0')
- p++;
- while (isspace(*p))
- p++;
- s->http_code = strtol(p, NULL, 10);
-#ifdef DEBUG
- printf("http_code=%d\n", s->http_code);
-#endif
- } else {
- while (*p != '\0' && *p != ':')
- p++;
- if (*p != ':')
- return 1;
-
- *p = '\0';
- tag = line;
- p++;
- while (isspace(*p))
- p++;
- if (!strcmp(tag, "Location")) {
- strcpy(s->location, p);
- }
- }
- return 1;
-}
-
-static int http_connect(URLContext *h, const char *path, const char *hoststr)
-{
- HTTPContext *s = h->priv_data;
- int post, err, ch;
- char line[1024], *q;
-
-
- /* send http header */
- post = h->flags & URL_WRONLY;
-
- snprintf(s->buffer, sizeof(s->buffer),
- "%s %s HTTP/1.0\n"
- "User-Agent: FFmpeg %s\n"
- "Accept: */*\n"
- "Host: %s\n"
- "\n",
- post ? "POST" : "GET",
- path,
- FFMPEG_VERSION,
- hoststr);
-
- if (http_write(h, s->buffer, strlen(s->buffer)) < 0)
- return -EIO;
-
- /* init input buffer */
- s->buf_ptr = s->buffer;
- s->buf_end = s->buffer;
- s->line_count = 0;
- s->location[0] = '\0';
- if (post) {
- sleep(1);
- return 0;
- }
-
- /* wait for header */
- q = line;
- for(;;) {
- ch = http_getc(s);
- if (ch < 0)
- return -EIO;
- if (ch == '\n') {
- /* process line */
- if (q > line && q[-1] == '\r')
- q--;
- *q = '\0';
-#ifdef DEBUG
- printf("header='%s'\n", line);
-#endif
- err = process_line(s, line, s->line_count);
- if (err < 0)
- return err;
- if (err == 0)
- return 0;
- s->line_count++;
- q = line;
- } else {
- if ((q - line) < sizeof(line) - 1)
- *q++ = ch;
- }
- }
-}
-
-
-static int http_read(URLContext *h, UINT8 *buf, int size)
-{
- HTTPContext *s = h->priv_data;
- int size1, len;
-
- size1 = size;
- while (size > 0) {
- /* read bytes from input buffer first */
- len = s->buf_end - s->buf_ptr;
- if (len > 0) {
- if (len > size)
- len = size;
- memcpy(buf, s->buf_ptr, len);
- s->buf_ptr += len;
- } else {
- len = url_read (s->hd, buf, size);
- if (len < 0) {
- return len;
- } else if (len == 0) {
- break;
- }
- }
- size -= len;
- buf += len;
- }
- return size1 - size;
-}
-
-/* used only when posting data */
-static int http_write(URLContext *h, UINT8 *buf, int size)
-{
- HTTPContext *s = h->priv_data;
- return url_write(s->hd, buf, size);
-}
-
-static int http_close(URLContext *h)
-{
- HTTPContext *s = h->priv_data;
- url_close(s->hd);
- av_free(s);
- return 0;
-}
-
-URLProtocol http_protocol = {
- "http",
- http_open,
- http_read,
- http_write,
- NULL, /* seek */
- http_close,
-};
-
+++ /dev/null
-/*
- * Image format
- * Copyright (c) 2000, 2001, 2002 Fabrice Bellard.
- *
- * This library 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 of the License, or (at your option) any later version.
- *
- * This library 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 this library; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
-#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;
-extern AVOutputFormat yuv4mpegpipe_oformat;
-
-#define IMGFMT_YUV 1
-#define IMGFMT_PGMYUV 2
-#define IMGFMT_PGM 3
-#define IMGFMT_PPM 4
-#define IMGFMT_YUV4MPEG 5
-
-#define Y4M_MAGIC "YUV4MPEG2"
-#define Y4M_FRAME_MAGIC "FRAME"
-#define Y4M_LINE_MAX 256
-
-typedef struct {
- int width;
- int height;
- int img_number;
- int img_size;
- int img_fmt;
- int is_pipe;
- int header_written;
- char path[1024];
-} VideoData;
-
-static inline int pnm_space(int c)
-{
- return (c==' ' || c=='\n' || c=='\r' || c=='\t');
-}
-
-static void pnm_get(ByteIOContext *f, char *str, int buf_size)
-{
- char *s;
- int c;
-
- do {
- c=get_byte(f);
- if (c=='#') {
- do {
- c=get_byte(f);
- } while (c!='\n');
- c=get_byte(f);
- }
- } while (pnm_space(c));
-
- s=str;
- do {
- if (url_feof(f))
- break;
- if ((s - str) < buf_size - 1)
- *s++=c;
- c=get_byte(f);
- } while (!pnm_space(c));
- *s = '\0';
-}
-
-static int pgm_read(VideoData *s, ByteIOContext *f, UINT8 *buf, int size, int is_yuv)
-{
- int width, height, i;
- char buf1[32];
- UINT8 *picture[3];
-
- width = s->width;
- height = s->height;
-
- pnm_get(f, buf1, sizeof(buf1));
- if (strcmp(buf1, "P5")) {
- return -EIO;
- }
- pnm_get(f, buf1, sizeof(buf1));
- pnm_get(f, buf1, sizeof(buf1));
- pnm_get(f, buf1, sizeof(buf1));
-
- picture[0] = buf;
- picture[1] = buf + width * height;
- picture[2] = buf + width * height + (width * height / 4);
- get_buffer(f, picture[0], width * height);
-
- height>>=1;
- width>>=1;
- if (is_yuv) {
- for(i=0;i<height;i++) {
- get_buffer(f, picture[1] + i * width, width);
- get_buffer(f, picture[2] + i * width, width);
- }
- } else {
- for(i=0;i<height;i++) {
- memset(picture[1] + i * width, 128, width);
- memset(picture[2] + i * width, 128, width);
- }
- }
- return 0;
-}
-
-static int ppm_read(VideoData *s, ByteIOContext *f, UINT8 *buf, int size)
-{
- int width, height;
- char buf1[32];
- UINT8 *picture[3];
-
- width = s->width;
- height = s->height;
-
- pnm_get(f, buf1, sizeof(buf1));
- if (strcmp(buf1, "P6")) {
- return -EIO;
- }
-
- pnm_get(f, buf1, sizeof(buf1));
- pnm_get(f, buf1, sizeof(buf1));
- pnm_get(f, buf1, sizeof(buf1));
-
- picture[0] = buf;
- get_buffer(f, picture[0], width * height*3);
-
- return 0;
-
-}
-
-static int yuv_read(VideoData *s, const char *filename, UINT8 *buf, int size1)
-{
- ByteIOContext pb1, *pb = &pb1;
- char fname[1024], *p;
- int size;
-
- size = s->width * s->height;
-
- strcpy(fname, filename);
- p = strrchr(fname, '.');
- if (!p || p[1] != 'Y')
- return -EIO;
-
- if (url_fopen(pb, fname, URL_RDONLY) < 0)
- return -EIO;
-
- get_buffer(pb, buf, size);
- url_fclose(pb);
-
- p[1] = 'U';
- if (url_fopen(pb, fname, URL_RDONLY) < 0)
- return -EIO;
-
- get_buffer(pb, buf + size, size / 4);
- url_fclose(pb);
-
- p[1] = 'V';
- if (url_fopen(pb, fname, URL_RDONLY) < 0)
- return -EIO;
-
- get_buffer(pb, buf + size + (size / 4), size / 4);
- url_fclose(pb);
- return 0;
-}
-
-static int img_read_packet(AVFormatContext *s1, AVPacket *pkt)
-{
- VideoData *s = s1->priv_data;
- char filename[1024];
- int ret;
- ByteIOContext f1, *f;
-
-/*
- This if-statement destroys pipes - I do not see why it is necessary
- if (get_frame_filename(filename, sizeof(filename),
- s->path, s->img_number) < 0)
- return -EIO;
-*/
- get_frame_filename(filename, sizeof(filename),
- s->path, s->img_number);
- if (!s->is_pipe) {
- f = &f1;
- if (url_fopen(f, filename, URL_RDONLY) < 0)
- return -EIO;
- } else {
- f = &s1->pb;
- if (url_feof(f))
- return -EIO;
- }
-
- av_new_packet(pkt, s->img_size);
- pkt->stream_index = 0;
-
- switch(s->img_fmt) {
- case IMGFMT_PGMYUV:
- ret = pgm_read(s, f, pkt->data, pkt->size, 1);
- break;
- case IMGFMT_PGM:
- ret = pgm_read(s, f, pkt->data, pkt->size, 0);
- break;
- case IMGFMT_YUV:
- ret = yuv_read(s, filename, pkt->data, pkt->size);
- break;
- case IMGFMT_PPM:
- ret = ppm_read(s, f, pkt->data, pkt->size);
- break;
- default:
- return -EIO;
- }
-
- if (!s->is_pipe) {
- url_fclose(f);
- }
-
- if (ret < 0) {
- av_free_packet(pkt);
- return -EIO; /* signal EOF */
- } else {
- pkt->pts = ((INT64)s->img_number * s1->pts_den * FRAME_RATE_BASE) / (s1->streams[0]->codec.frame_rate * s1->pts_num);
- s->img_number++;
- return 0;
- }
-}
-
-static int sizes[][2] = {
- { 640, 480 },
- { 720, 480 },
- { 720, 576 },
- { 352, 288 },
- { 352, 240 },
- { 160, 128 },
- { 512, 384 },
- { 640, 352 },
- { 640, 240 },
-};
-
-static int infer_size(int *width_ptr, int *height_ptr, int size)
-{
- int i;
-
- for(i=0;i<sizeof(sizes)/sizeof(sizes[0]);i++) {
- if ((sizes[i][0] * sizes[i][1]) == size) {
- *width_ptr = sizes[i][0];
- *height_ptr = sizes[i][1];
- return 0;
- }
- }
- return -1;
-}
-
-static int img_read_header(AVFormatContext *s1, AVFormatParameters *ap)
-{
- VideoData *s = s1->priv_data;
- int i, h;
- char buf[1024];
- char buf1[32];
- ByteIOContext pb1, *f = &pb1;
- AVStream *st;
-
- st = av_new_stream(s1, 0);
- if (!st) {
- av_free(s);
- return -ENOMEM;
- }
-
- strcpy(s->path, s1->filename);
- s->img_number = 0;
-
- /* find format */
- if (s1->iformat->flags & AVFMT_NOFILE)
- s->is_pipe = 0;
- else
- s->is_pipe = 1;
-
- if (s1->iformat == &pgmyuvpipe_iformat ||
- s1->iformat == &pgmyuv_iformat)
- s->img_fmt = IMGFMT_PGMYUV;
- else if (s1->iformat == &pgmpipe_iformat ||
- s1->iformat == &pgm_iformat)
- s->img_fmt = IMGFMT_PGM;
- else if (s1->iformat == &imgyuv_iformat)
- s->img_fmt = IMGFMT_YUV;
- else if (s1->iformat == &ppmpipe_iformat ||
- s1->iformat == &ppm_iformat)
- s->img_fmt = IMGFMT_PPM;
- else
- goto fail;
-
- if (!s->is_pipe) {
- /* try to find the first image */
- for(i=0;i<5;i++) {
- if (get_frame_filename(buf, sizeof(buf), s->path, s->img_number) < 0)
- goto fail;
- if (url_fopen(f, buf, URL_RDONLY) >= 0)
- break;
- s->img_number++;
- }
- if (i == 5)
- goto fail;
- } else {
- f = &s1->pb;
- }
-
- /* find the image size */
- /* XXX: use generic file format guessing, as mpeg */
- switch(s->img_fmt) {
- case IMGFMT_PGM:
- case IMGFMT_PGMYUV:
- case IMGFMT_PPM:
- pnm_get(f, buf1, sizeof(buf1));
- pnm_get(f, buf1, sizeof(buf1));
- s->width = atoi(buf1);
- pnm_get(f, buf1, sizeof(buf1));
- h = atoi(buf1);
- if (s->img_fmt == IMGFMT_PGMYUV)
- h = (h * 2) / 3;
- s->height = h;
- if (s->width <= 0 ||
- s->height <= 0 ||
- (s->width % 2) != 0 ||
- (s->height % 2) != 0) {
- goto fail1;
- }
- break;
- case IMGFMT_YUV:
- /* infer size by using the file size. */
- {
- int img_size;
- URLContext *h;
-
- /* XXX: hack hack */
- h = url_fileno(f);
- img_size = url_seek(h, 0, SEEK_END);
- if (infer_size(&s->width, &s->height, img_size) < 0) {
- goto fail1;
- }
- }
- break;
- }
-
-
- if (!s->is_pipe) {
- url_fclose(f);
- } else {
- url_fseek(f, 0, SEEK_SET);
- }
-
-
- st->codec.codec_type = CODEC_TYPE_VIDEO;
- st->codec.codec_id = CODEC_ID_RAWVIDEO;
- st->codec.width = s->width;
- st->codec.height = s->height;
- if (s->img_fmt == IMGFMT_PPM) {
- st->codec.pix_fmt = PIX_FMT_RGB24;
- s->img_size = (s->width * s->height * 3);
- } else {
- st->codec.pix_fmt = PIX_FMT_YUV420P;
- s->img_size = (s->width * s->height * 3) / 2;
- }
- if (!ap || !ap->frame_rate)
- st->codec.frame_rate = 25 * FRAME_RATE_BASE;
- else
- st->codec.frame_rate = ap->frame_rate;
-
- return 0;
- fail1:
- if (!s->is_pipe)
- url_fclose(f);
- fail:
- av_free(s);
- return -EIO;
-}
-
-static int img_read_close(AVFormatContext *s1)
-{
- return 0;
-}
-
-/******************************************************/
-/* image output */
-
-static int pgm_save(AVPicture *picture, int width, int height, ByteIOContext *pb, int is_yuv)
-{
- int i, h;
- char buf[100];
- UINT8 *ptr, *ptr1, *ptr2;
-
- h = height;
- if (is_yuv)
- h = (height * 3) / 2;
- snprintf(buf, sizeof(buf),
- "P5\n%d %d\n%d\n",
- width, h, 255);
- put_buffer(pb, buf, strlen(buf));
-
- ptr = picture->data[0];
- for(i=0;i<height;i++) {
- put_buffer(pb, ptr, width);
- ptr += picture->linesize[0];
- }
-
- if (is_yuv) {
- height >>= 1;
- width >>= 1;
- ptr1 = picture->data[1];
- ptr2 = picture->data[2];
- for(i=0;i<height;i++) {
- put_buffer(pb, ptr1, width);
- put_buffer(pb, ptr2, width);
- ptr1 += picture->linesize[1];
- ptr2 += picture->linesize[2];
- }
- }
- put_flush_packet(pb);
- return 0;
-}
-
-static int ppm_save(AVPicture *picture, int width, int height, ByteIOContext *pb)
-{
- int i;
- char buf[100];
- UINT8 *ptr;
-
- snprintf(buf, sizeof(buf),
- "P6\n%d %d\n%d\n",
- width, height, 255);
- put_buffer(pb, buf, strlen(buf));
-
- ptr = picture->data[0];
- for(i=0;i<height;i++) {
- put_buffer(pb, ptr, width * 3);
- ptr += picture->linesize[0];
- }
-
- put_flush_packet(pb);
- return 0;
-}
-
-static int yuv_save(AVPicture *picture, int width, int height, const char *filename)
-{
- ByteIOContext pb1, *pb = &pb1;
- char fname[1024], *p;
- int i, j;
- UINT8 *ptr;
- static char *ext = "YUV";
-
- strcpy(fname, filename);
- p = strrchr(fname, '.');
- if (!p || p[1] != 'Y')
- return -EIO;
-
- for(i=0;i<3;i++) {
- if (i == 1) {
- width >>= 1;
- height >>= 1;
- }
-
- p[1] = ext[i];
- if (url_fopen(pb, fname, URL_WRONLY) < 0)
- return -EIO;
-
- ptr = picture->data[i];
- for(j=0;j<height;j++) {
- put_buffer(pb, ptr, width);
- ptr += picture->linesize[i];
- }
- put_flush_packet(pb);
- url_fclose(pb);
- }
- return 0;
-}
-
-static int yuv4mpeg_save(AVPicture *picture, int width, int height, ByteIOContext *pb, int need_stream_header,
- int is_yuv, int raten, int rated, int aspectn, int aspectd)
-{
- int i, n, m;
- char buf[Y4M_LINE_MAX+1], buf1[20];
- UINT8 *ptr, *ptr1, *ptr2;
-
- /* construct stream header, if this is the first frame */
- if(need_stream_header) {
- n = snprintf(buf, sizeof(buf), "%s W%d H%d F%d:%d I%s A%d:%d\n",
- Y4M_MAGIC,
- width,
- height,
- raten, rated,
- "p", /* ffmpeg seems to only output progressive video */
- aspectn, aspectd);
- if (n < 0) {
- fprintf(stderr, "Error. YUV4MPEG stream header write failed.\n");
- } else {
- fprintf(stderr, "YUV4MPEG stream header written. FPS is %d\n", raten);
- put_buffer(pb, buf, strlen(buf));
- }
- }
-
- /* construct frame header */
- m = snprintf(buf1, sizeof(buf1), "%s \n", Y4M_FRAME_MAGIC);
- if (m < 0) {
- fprintf(stderr, "Error. YUV4MPEG frame header write failed.\n");
- } else {
- /* fprintf(stderr, "YUV4MPEG frame header written.\n"); */
- put_buffer(pb, buf1, strlen(buf1));
- }
-
- ptr = picture->data[0];
- for(i=0;i<height;i++) {
- put_buffer(pb, ptr, width);
- ptr += picture->linesize[0];
- }
-
- if (is_yuv) {
- height >>= 1;
- width >>= 1;
- ptr1 = picture->data[1];
- ptr2 = picture->data[2];
- for(i=0;i<height;i++) { /* Cb */
- put_buffer(pb, ptr1, width);
- ptr1 += picture->linesize[1];
- }
- for(i=0;i<height;i++) { /* Cr */
- put_buffer(pb, ptr2, width);
- ptr2 += picture->linesize[2];
- }
- }
- put_flush_packet(pb);
- return 0;
-}
-
-static int img_write_header(AVFormatContext *s)
-{
- VideoData *img = s->priv_data;
-
- img->img_number = 1;
- strcpy(img->path, s->filename);
-
- /* find format */
- if (s->oformat->flags & AVFMT_NOFILE)
- img->is_pipe = 0;
- else
- img->is_pipe = 1;
-
- if (s->oformat == &pgmyuvpipe_oformat ||
- s->oformat == &pgmyuv_oformat) {
- img->img_fmt = IMGFMT_PGMYUV;
- } else if (s->oformat == &pgmpipe_oformat ||
- s->oformat == &pgm_oformat) {
- img->img_fmt = IMGFMT_PGM;
- } else if (s->oformat == &imgyuv_oformat) {
- img->img_fmt = IMGFMT_YUV;
- } else if (s->oformat == &ppmpipe_oformat ||
- s->oformat == &ppm_oformat) {
- img->img_fmt = IMGFMT_PPM;
- } else if (s->oformat == &yuv4mpegpipe_oformat) {
- img->img_fmt = IMGFMT_YUV4MPEG;
- img->header_written = 0;
- } else {
- goto fail;
- }
- return 0;
- fail:
- av_free(img);
- return -EIO;
-}
-
-static int img_write_packet(AVFormatContext *s, int stream_index,
- UINT8 *buf, int size, int force_pts)
-{
- VideoData *img = s->priv_data;
- AVStream *st = s->streams[stream_index];
- ByteIOContext pb1, *pb;
- AVPicture picture;
- int width, height, need_stream_header, ret, size1, raten, rated, aspectn, aspectd, fps, fps1;
- char filename[1024];
-
- width = st->codec.width;
- height = st->codec.height;
-
- if (img->img_number == 1) {
- need_stream_header = 1;
- } else {
- need_stream_header = 0;
- }
-
- fps = st->codec.frame_rate;
- fps1 = (((float)fps / FRAME_RATE_BASE) * 1000);
-
- /* Sorry about this messy code, but mpeg2enc is very picky about
- * the framerates it accepts. */
- switch(fps1) {
- case 23976:
- raten = 24000; /* turn the framerate into a ratio */
- rated = 1001;
- break;
- case 29970:
- raten = 30000;
- rated = 1001;
- break;
- case 25000:
- raten = 25;
- rated = 1;
- break;
- case 30000:
- raten = 30;
- rated = 1;
- break;
- case 24000:
- raten = 24;
- rated = 1;
- break;
- case 50000:
- raten = 50;
- rated = 1;
- break;
- case 59940:
- raten = 60000;
- rated = 1001;
- break;
- case 60000:
- raten = 60;
- rated = 1;
- break;
- default:
- raten = fps1; /* this setting should work, but often doesn't */
- rated = 1000;
- break;
- }
-
- aspectn = 1;
- aspectd = 1; /* ffmpeg always uses a 1:1 aspect ratio */
-
- switch(st->codec.pix_fmt) {
- case PIX_FMT_YUV420P:
- size1 = (width * height * 3) / 2;
- if (size != size1)
- return -EIO;
-
- picture.data[0] = buf;
- picture.data[1] = picture.data[0] + width * height;
- picture.data[2] = picture.data[1] + (width * height) / 4;
- picture.linesize[0] = width;
- picture.linesize[1] = width >> 1;
- picture.linesize[2] = width >> 1;
- break;
- case PIX_FMT_RGB24:
- size1 = (width * height * 3);
- if (size != size1)
- return -EIO;
- picture.data[0] = buf;
- picture.linesize[0] = width * 3;
- break;
- default:
- return -EIO;
- }
-
-/*
- This if-statement destroys pipes - I do not see why it is necessary
- if (get_frame_filename(filename, sizeof(filename),
- img->path, img->img_number) < 0)
- return -EIO;
-*/
- get_frame_filename(filename, sizeof(filename),
- img->path, img->img_number);
- if (!img->is_pipe) {
- pb = &pb1;
- if (url_fopen(pb, filename, URL_WRONLY) < 0)
- return -EIO;
- } else {
- pb = &s->pb;
- }
- switch(img->img_fmt) {
- case IMGFMT_PGMYUV:
- ret = pgm_save(&picture, width, height, pb, 1);
- break;
- case IMGFMT_PGM:
- ret = pgm_save(&picture, width, height, pb, 0);
- break;
- case IMGFMT_YUV:
- ret = yuv_save(&picture, width, height, filename);
- break;
- case IMGFMT_PPM:
- ret = ppm_save(&picture, width, height, pb);
- break;
- case IMGFMT_YUV4MPEG:
- ret = yuv4mpeg_save(&picture, width, height, pb,
- need_stream_header, 1, raten, rated, aspectn, aspectd);
- break;
- }
- if (!img->is_pipe) {
- url_fclose(pb);
- }
-
- img->img_number++;
- return 0;
-}
-
-static int img_write_trailer(AVFormatContext *s)
-{
- return 0;
-}
-
-static 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",
-};
-
-static 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,
-};
-
-static AVInputFormat pgmyuv_iformat = {
- "pgmyuv",
- "pgm with YUV content image format",
- sizeof(VideoData),
- NULL, /* no probe */
- img_read_header,
- img_read_packet,
- img_read_close,
- NULL,
- AVFMT_NOFILE | AVFMT_NEEDNUMBER,
-};
-
-static 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,
-};
-
-static 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_RGB24,
- .extensions = "ppm",
-};
-
-static 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,
-};
-
-static 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",
-};
-
-static 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,
-};
-
-static AVInputFormat pgmpipe_iformat = {
- "pgmpipe",
- "PGM pipe format",
- sizeof(VideoData),
- NULL, /* no probe */
- img_read_header,
- img_read_packet,
- img_read_close,
- NULL,
-};
-
-static 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,
-};
-
-static AVInputFormat pgmyuvpipe_iformat = {
- "pgmyuvpipe",
- "PGM YUV pipe format",
- sizeof(VideoData),
- NULL, /* no probe */
- img_read_header,
- img_read_packet,
- img_read_close,
- NULL,
-};
-
-static 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,
-};
-
-static 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,
-};
-
-static 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,
- .flags = AVFMT_RGB24,
-};
-
-
-static AVOutputFormat yuv4mpegpipe_oformat = {
- "yuv4mpegpipe",
- "YUV4MPEG pipe format",
- "",
- "yuv4mpeg",
- sizeof(VideoData),
- CODEC_ID_NONE,
- CODEC_ID_RAWVIDEO,
- img_write_header,
- img_write_packet,
- img_write_trailer,
-};
-
-
-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);
-
- av_register_output_format(&yuv4mpegpipe_oformat);
-
- return 0;
-}
+++ /dev/null
-/*
- * JPEG based formats
- * Copyright (c) 2000, 2001 Fabrice Bellard.
- *
- * This library 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 of the License, or (at your option) any later version.
- *
- * This library 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 this library; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
-#include "avformat.h"
-
-/* Multipart JPEG */
-
-#define BOUNDARY_TAG "ffserver"
-
-static int mpjpeg_write_header(AVFormatContext *s)
-{
- UINT8 buf1[256];
-
- snprintf(buf1, sizeof(buf1), "--%s\n", BOUNDARY_TAG);
- put_buffer(&s->pb, buf1, strlen(buf1));
- put_flush_packet(&s->pb);
- return 0;
-}
-
-static int mpjpeg_write_packet(AVFormatContext *s, int stream_index,
- UINT8 *buf, int size, int force_pts)
-{
- UINT8 buf1[256];
-
- snprintf(buf1, sizeof(buf1), "Content-type: image/jpeg\n\n");
- put_buffer(&s->pb, buf1, strlen(buf1));
- put_buffer(&s->pb, buf, size);
-
- snprintf(buf1, sizeof(buf1), "\n--%s\n", BOUNDARY_TAG);
- put_buffer(&s->pb, buf1, strlen(buf1));
- put_flush_packet(&s->pb);
- return 0;
-}
-
-static int mpjpeg_write_trailer(AVFormatContext *s)
-{
- return 0;
-}
-
-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,
- mpjpeg_write_packet,
- mpjpeg_write_trailer,
-};
-
-
-/*************************************/
-/* single frame JPEG */
-
-static int single_jpeg_write_header(AVFormatContext *s)
-{
- return 0;
-}
-
-static int single_jpeg_write_packet(AVFormatContext *s, int stream_index,
- UINT8 *buf, int size, int force_pts)
-{
- put_buffer(&s->pb, buf, size);
- put_flush_packet(&s->pb);
- return 1; /* no more data can be sent */
-}
-
-static int single_jpeg_write_trailer(AVFormatContext *s)
-{
- return 0;
-}
-
-static AVOutputFormat single_jpeg_format = {
- "singlejpeg",
- "single JPEG image",
- "image/jpeg",
- NULL, /* note: no extension to favorize jpeg multiple images match */
- 0,
- CODEC_ID_NONE,
- CODEC_ID_MJPEG,
- single_jpeg_write_header,
- single_jpeg_write_packet,
- single_jpeg_write_trailer,
-};
-
-/*************************************/
-/* multiple jpeg images */
-
-typedef struct JpegContext {
- char path[1024];
- int img_number;
-} JpegContext;
-
-static int jpeg_write_header(AVFormatContext *s1)
-{
- JpegContext *s;
-
- s = av_mallocz(sizeof(JpegContext));
- if (!s)
- return -1;
- s1->priv_data = s;
- pstrcpy(s->path, sizeof(s->path), s1->filename);
- s->img_number = 1;
- return 0;
-}
-
-static int jpeg_write_packet(AVFormatContext *s1, int stream_index,
- UINT8 *buf, int size, int force_pts)
-{
- JpegContext *s = s1->priv_data;
- char filename[1024];
- ByteIOContext f1, *pb = &f1;
-
- if (get_frame_filename(filename, sizeof(filename),
- s->path, s->img_number) < 0)
- return -EIO;
- if (url_fopen(pb, filename, URL_WRONLY) < 0)
- return -EIO;
-
- put_buffer(pb, buf, size);
- put_flush_packet(pb);
-
- url_fclose(pb);
- s->img_number++;
-
- return 0;
-}
-
-static int jpeg_write_trailer(AVFormatContext *s1)
-{
- return 0;
-}
-
-/***/
-
-static int jpeg_read_header(AVFormatContext *s1, AVFormatParameters *ap)
-{
- JpegContext *s;
- int i;
- char buf[1024];
- ByteIOContext pb1, *f = &pb1;
- AVStream *st;
-
- s = av_mallocz(sizeof(JpegContext));
- if (!s)
- return -1;
- s1->priv_data = s;
- pstrcpy(s->path, sizeof(s->path), s1->filename);
-
- s1->nb_streams = 1;
- st = av_mallocz(sizeof(AVStream));
- if (!st) {
- av_free(s);
- return -ENOMEM;
- }
- s1->streams[0] = st;
- s->img_number = 0;
-
- /* try to find the first image */
- for(i=0;i<5;i++) {
- if (get_frame_filename(buf, sizeof(buf), s->path, s->img_number) < 0)
- goto fail;
- if (url_fopen(f, buf, URL_RDONLY) >= 0)
- break;
- s->img_number++;
- }
- if (i == 5)
- goto fail;
- url_fclose(f);
- st->codec.codec_type = CODEC_TYPE_VIDEO;
- st->codec.codec_id = CODEC_ID_MJPEG;
-
- if (!ap || !ap->frame_rate)
- st->codec.frame_rate = 25 * FRAME_RATE_BASE;
- else
- st->codec.frame_rate = ap->frame_rate;
- return 0;
- fail:
- av_free(s);
- return -EIO;
-}
-
-static int jpeg_read_packet(AVFormatContext *s1, AVPacket *pkt)
-{
- JpegContext *s = s1->priv_data;
- char filename[1024];
- int size;
- ByteIOContext f1, *f = &f1;
-
- if (get_frame_filename(filename, sizeof(filename),
- s->path, s->img_number) < 0)
- return -EIO;
-
- f = &f1;
- if (url_fopen(f, filename, URL_RDONLY) < 0)
- return -EIO;
-
- size = url_seek(url_fileno(f), 0, SEEK_END);
- url_seek(url_fileno(f), 0, SEEK_SET);
-
- av_new_packet(pkt, size);
- pkt->stream_index = 0;
- get_buffer(f, pkt->data, size);
-
- url_fclose(f);
- s->img_number++;
- return 0;
-}
-
-static int jpeg_read_close(AVFormatContext *s1)
-{
- return 0;
-}
-
-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,
- .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;
-}
+++ /dev/null
-/*
- * MOV decoder.
- * Copyright (c) 2001 Fabrice Bellard.
- *
- * This library 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 of the License, or (at your option) any later version.
- *
- * This library 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 this library; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
-#include "avformat.h"
-#include "avi.h"
-
-#ifdef CONFIG_ZLIB
-#include <zlib.h>
-#endif
-
-/*
- * First version by Francois Revol revol@free.fr
- *
- * Features and limitations:
- * - reads most of the QT files I have (at least the structure),
- * the exceptions are .mov with zlib compressed headers ('cmov' section). It shouldn't be hard to implement.
- * FIXED, Francois Revol, 07/17/2002
- * - ffmpeg has nearly none of the usual QuickTime codecs,
- * although I succesfully dumped raw and mp3 audio tracks off .mov files.
- * Sample QuickTime files with mp3 audio can be found at: http://www.3ivx.com/showcase.html
- * - .mp4 parsing is still hazardous, although the format really is QuickTime with some minor changes
- * (to make .mov parser crash maybe ?), despite what they say in the MPEG FAQ at
- * http://mpeg.telecomitalialab.com/faq.htm
- * - the code is quite ugly... maybe I won't do it recursive next time :-)
- *
- * Funny I didn't know about http://sourceforge.net/projects/qt-ffmpeg/
- * when coding this :) (it's a writer anyway)
- *
- * Reference documents:
- * http://www.geocities.com/xhelmboyx/quicktime/formats/qtm-layout.txt
- * Apple:
- * http://developer.apple.com/techpubs/quicktime/qtdevdocs/QTFF/qtff.html
- * http://developer.apple.com/techpubs/quicktime/qtdevdocs/PDF/QTFileFormat.pdf
- * QuickTime is a trademark of Apple (AFAIK :))
- */
-
-//#define DEBUG
-
-/* allows chunk splitting - should work now... */
-/* in case you can't read a file, try commenting */
-#define MOV_SPLIT_CHUNKS
-
-#ifdef DEBUG
-/*
- * XXX: static sux, even more in a multithreaded environment...
- * Avoid them. This is here just to help debugging.
- */
-static int debug_indent = 0;
-void print_atom(const char *str, UINT32 type, UINT64 offset, UINT64 size)
-{
- unsigned int tag, i;
- tag = (unsigned int) type;
- i=debug_indent;
- if(tag == 0) tag = MKTAG('N', 'U', 'L', 'L');
- while(i--)
- printf("|");
- printf("parse:");
- printf(" %s: tag=%c%c%c%c offset=0x%x size=0x%x\n",
- str, tag & 0xff,
- (tag >> 8) & 0xff,
- (tag >> 16) & 0xff,
- (tag >> 24) & 0xff,
- (unsigned int)offset,
- (unsigned int)size);
-}
-#endif
-
-/* some streams in QT (and in MP4 mostly) aren't either video nor audio */
-/* so we first list them as this, then clean up the list of streams we give back, */
-/* getting rid of these */
-#define CODEC_TYPE_MOV_OTHER 2
-
-static const CodecTag mov_video_tags[] = {
-/* { CODEC_ID_, MKTAG('c', 'v', 'i', 'd') }, *//* Cinepak */
-/* { CODEC_ID_JPEG, MKTAG('j', 'p', 'e', 'g') }, *//* JPEG */
-/* { CODEC_ID_H263, MKTAG('r', 'a', 'w', ' ') }, *//* Uncompressed RGB */
-/* { CODEC_ID_H263, MKTAG('Y', 'u', 'v', '2') }, *//* Uncompressed YUV422 */
-/* Graphics */
-/* Animation */
-/* Apple video */
-/* Kodak Photo CD */
- { CODEC_ID_MJPEG, MKTAG('j', 'p', 'e', 'g') }, /* PhotoJPEG */
- { CODEC_ID_MPEG1VIDEO, MKTAG('m', 'p', 'e', 'g') }, /* MPEG */
- { CODEC_ID_MJPEG, MKTAG('m', 'j', 'p', 'a') }, /* Motion-JPEG (format A) */
- { CODEC_ID_MJPEG, MKTAG('m', 'j', 'p', 'b') }, /* Motion-JPEG (format B) */
-/* { CODEC_ID_GIF, MKTAG('g', 'i', 'f', ' ') }, *//* embedded gif files as frames (usually one "click to play movie" frame) */
-/* Sorenson video */
- { CODEC_ID_SVQ1, MKTAG('S', 'V', 'Q', '1') }, /* Sorenson Video v1 */
- { CODEC_ID_SVQ1, MKTAG('s', 'v', 'q', '1') }, /* Sorenson Video v1 */
- { CODEC_ID_SVQ1, MKTAG('s', 'v', 'q', 'i') }, /* Sorenson Video v1 (from QT specs)*/
- { CODEC_ID_MPEG4, MKTAG('m', 'p', '4', 'v') },
- { CODEC_ID_MPEG4, MKTAG('D', 'I', 'V', 'X') }, /* OpenDiVX *//* sample files at http://heroinewarrior.com/xmovie.php3 use this tag */
-/* { CODEC_ID_, MKTAG('I', 'V', '5', '0') }, *//* Indeo 5.0 */
- { CODEC_ID_H263, MKTAG('h', '2', '6', '3') }, /* H263 */
- { CODEC_ID_DVVIDEO, MKTAG('d', 'v', 'c', ' ') }, /* DV NTSC */
- { CODEC_ID_DVVIDEO, MKTAG('d', 'v', 'c', 'p') }, /* DV PAL */
- { 0, 0 },
-};
-
-static const CodecTag mov_audio_tags[] = {
-/* { CODEC_ID_PCM_S16BE, MKTAG('N', 'O', 'N', 'E') }, *//* uncompressed */
- { CODEC_ID_PCM_S16BE, MKTAG('t', 'w', 'o', 's') }, /* 16 bits */
- { CODEC_ID_PCM_S8, MKTAG('t', 'w', 'o', 's') }, /* 8 bits */
- { CODEC_ID_PCM_U8, 0x20776172 }, /* 8 bits unsigned */
- { CODEC_ID_PCM_S16LE, MKTAG('s', 'o', 'w', 't') }, /* */
- { CODEC_ID_PCM_MULAW, MKTAG('u', 'l', 'a', 'w') }, /* */
- { CODEC_ID_PCM_ALAW, MKTAG('a', 'l', 'a', 'w') }, /* */
- { CODEC_ID_ADPCM_IMA_QT, MKTAG('i', 'm', 'a', '4') }, /* IMA-4 ADPCM */
- { CODEC_ID_MACE3, MKTAG('M', 'A', 'C', '3') }, /* Macintosh Audio Compression and Expansion 3:1 */
- { CODEC_ID_MACE6, MKTAG('M', 'A', 'C', '6') }, /* Macintosh Audio Compression and Expansion 6:1 */
-
- { CODEC_ID_MP2, MKTAG('.', 'm', 'p', '3') }, /* MPEG layer 3 */ /* sample files at http://www.3ivx.com/showcase.html use this tag */
- { CODEC_ID_MP2, 0x6D730055 }, /* MPEG layer 3 */
- { CODEC_ID_MP2, 0x5500736D }, /* MPEG layer 3 *//* XXX: check endianness */
-/* { CODEC_ID_OGG_VORBIS, MKTAG('O', 'g', 'g', 'S') }, *//* sample files at http://heroinewarrior.com/xmovie.php3 use this tag */
-/* MP4 tags */
-/* { CODEC_ID_AAC, MKTAG('m', 'p', '4', 'a') }, *//* MPEG 4 AAC or audio ? */
- /* The standard for mpeg4 audio is still not normalised AFAIK anyway */
- { 0, 0 },
-};
-
-/* the QuickTime file format is quite convoluted...
- * it has lots of index tables, each indexing something in another one...
- * Here we just use what is needed to read the chunks
- */
-
-typedef struct MOV_sample_to_chunk_tbl {
- long first;
- long count;
- long id;
-} MOV_sample_to_chunk_tbl;
-
-typedef struct MOVStreamContext {
- int ffindex; /* the ffmpeg stream id */
- int is_ff_stream; /* Is this stream presented to ffmpeg ? i.e. is this an audio or video stream ? */
- long next_chunk;
- long chunk_count;
- INT64 *chunk_offsets;
- long sample_to_chunk_sz;
- MOV_sample_to_chunk_tbl *sample_to_chunk;
- long sample_to_chunk_index;
- long sample_size;
- long sample_count;
- long *sample_sizes;
- long time_scale;
- long current_sample;
- long left_in_chunk; /* how many samples before next chunk */
- /* specific MPEG4 header which is added at the beginning of the stream */
- int header_len;
- uint8_t *header_data;
-} MOVStreamContext;
-
-typedef struct MOVContext {
- int mp4; /* set to 1 as soon as we are sure that the file is an .mp4 file (even some header parsing depends on this) */
- AVFormatContext *fc;
- long time_scale;
- int found_moov; /* when both 'moov' and 'mdat' sections has been found */
- int found_mdat; /* we suppose we have enough data to read the file */
- INT64 mdat_size;
- INT64 mdat_offset;
- int total_streams;
- /* some streams listed here aren't presented to the ffmpeg API, since they aren't either video nor audio
- * but we need the info to be able to skip data from those streams in the 'mdat' section
- */
- MOVStreamContext *streams[MAX_STREAMS];
-
- INT64 next_chunk_offset;
- int partial; /* != 0 : there is still to read in the current chunk (=id of the stream + 1) */
-} MOVContext;
-
-
-struct MOVParseTableEntry;
-
-/* XXX: it's the first time I make a recursive parser I think... sorry if it's ugly :P */
-
-/* those functions parse an atom */
-/* return code:
- 1: found what I wanted, exit
- 0: continue to parse next atom
- -1: error occured, exit
- */
-typedef int (*mov_parse_function)(const struct MOVParseTableEntry *parse_table,
- ByteIOContext *pb,
- UINT32 atom_type,
- INT64 atom_offset, /* after the size and type field (and eventually the extended size) */
- INT64 atom_size, /* total size (excluding the size and type fields) */
- void *param);
-
-/* links atom IDs to parse functions */
-typedef struct MOVParseTableEntry {
- UINT32 type;
- mov_parse_function func;
-} MOVParseTableEntry;
-
-static int parse_leaf(const MOVParseTableEntry *parse_table, ByteIOContext *pb, UINT32 atom_type, INT64 atom_offset, INT64 atom_size, void *param)
-{
-#ifdef DEBUG
- print_atom("leaf", atom_type, atom_offset, atom_size);
-#endif
- if(atom_size>1)
- url_fskip(pb, atom_size);
-/* url_seek(pb, atom_offset+atom_size, SEEK_SET); */
- return 0;
-}
-
-
-static int parse_default(const MOVParseTableEntry *parse_table, ByteIOContext *pb, UINT32 atom_type, INT64 atom_offset, INT64 atom_size, void *param)
-{
- UINT32 type, foo=0;
- UINT64 offset, size;
- UINT64 total_size = 0;
- int i;
- int err = 0;
- foo=0;
-#ifdef DEBUG
- print_atom("default", atom_type, atom_offset, atom_size);
- debug_indent++;
-#endif
-
- offset = atom_offset;
-
- if(atom_size < 0)
- atom_size = 0x0FFFFFFFFFFFFFFF;
- while((total_size < atom_size) && !url_feof(pb) && !err) {
- size=atom_size;
- type=0L;
- if(atom_size >= 8) {
- size = get_be32(pb);
- type = get_le32(pb);
- }
- total_size += 8;
- offset+=8;
-// printf("type: %08lx sz: %08lx", type, size);
- if(size == 1) { /* 64 bit extended size */
- size = get_be64(pb);
- offset+=8;
- total_size+=8;
- size-=8;
- }
- if(size == 0)
- size = atom_size - total_size;
- size-=8;
- for(i=0; parse_table[i].type != 0L && parse_table[i].type != type; i++);
-
-// printf(" i=%ld\n", i);
- if (parse_table[i].type == 0) { /* skip leaf atoms data */
-// url_seek(pb, atom_offset+atom_size, SEEK_SET);
-#ifdef DEBUG
- print_atom("unknown", type, offset, size);
-#endif
- url_fskip(pb, size);
- } else
- err = (parse_table[i].func)(parse_table, pb, type, offset, size, param);
-
- offset+=size;
- total_size+=size;
- }
-
-#ifdef DEBUG
- debug_indent--;
-#endif
- return err;
-}
-
-static int parse_mvhd(const MOVParseTableEntry *parse_table, ByteIOContext *pb, UINT32 atom_type, INT64 atom_offset, INT64 atom_size, void *param)
-{
- MOVContext *c;
-#ifdef DEBUG
- print_atom("mvhd", atom_type, atom_offset, atom_size);
-#endif
- c = (MOVContext *)param;
-
- get_byte(pb); /* version */
- get_byte(pb); get_byte(pb); get_byte(pb); /* flags */
-
- get_be32(pb); /* creation time */
- get_be32(pb); /* modification time */
- c->time_scale = get_be32(pb); /* time scale */
-#ifdef DEBUG
- printf("time scale = %li\n", c->time_scale);
-#endif
- get_be32(pb); /* duration */
- get_be32(pb); /* preferred scale */
-
- get_be16(pb); /* preferred volume */
-
- url_fskip(pb, 10); /* reserved */
-
- url_fskip(pb, 36); /* display matrix */
-
- get_be32(pb); /* preview time */
- get_be32(pb); /* preview duration */
- get_be32(pb); /* poster time */
- get_be32(pb); /* selection time */
- get_be32(pb); /* selection duration */
- get_be32(pb); /* current time */
- get_be32(pb); /* next track ID */
-
- return 0;
-}
-
-/* this atom should contain all header atoms */
-static int parse_moov(const MOVParseTableEntry *parse_table, ByteIOContext *pb, UINT32 atom_type, INT64 atom_offset, INT64 atom_size, void *param)
-{
- int err;
- MOVContext *c;
-#ifdef DEBUG
- print_atom("moov", atom_type, atom_offset, atom_size);
-#endif
- c = (MOVContext *)param;
-
- err = parse_default(parse_table, pb, atom_type, atom_offset, atom_size, param);
- /* we parsed the 'moov' atom, we can terminate the parsing as soon as we find the 'mdat' */
- /* so we don't parse the whole file if over a network */
- c->found_moov=1;
- if(c->found_mdat)
- return 1; /* found both, just go */
- return 0; /* now go for mdat */
-}
-
-/* this atom contains actual media data */
-static int parse_mdat(const MOVParseTableEntry *parse_table, ByteIOContext *pb, UINT32 atom_type, INT64 atom_offset, INT64 atom_size, void *param)
-{
- MOVContext *c;
-#ifdef DEBUG
- print_atom("mdat", atom_type, atom_offset, atom_size);
-#endif
- c = (MOVContext *)param;
-
- if(atom_size == 0) /* wrong one (MP4) */
- return 0;
- c->found_mdat=1;
- c->mdat_offset = atom_offset;
- c->mdat_size = atom_size;
- if(c->found_moov)
- return 1; /* found both, just go */
- url_fskip(pb, atom_size);
- return 0; /* now go for moov */
-}
-
-/* this atom should be null (from specs), but some buggy files put the 'moov' atom inside it... */
-/* like the files created with Adobe Premiere 5.0, for samples see */
-/* http://graphics.tudelft.nl/~wouter/publications/soundtests/ */
-static int parse_wide(const MOVParseTableEntry *parse_table, ByteIOContext *pb, UINT32 atom_type, INT64 atom_offset, INT64 atom_size, void *param)
-{
- int err;
- UINT32 type;
-#ifdef DEBUG
- print_atom("wide", atom_type, atom_offset, atom_size);
- debug_indent++;
-#endif
- if (atom_size < 8)
- return 0; /* continue */
- if (get_be32(pb) != 0) { /* 0 sized mdat atom... use the 'wide' atom size */
- url_fskip(pb, atom_size - 4);
- return 0;
- }
- type = get_le32(pb);
- if (type != MKTAG('m', 'd', 'a', 't')) {
- url_fskip(pb, atom_size - 8);
- return 0;
- }
- err = parse_mdat(parse_table, pb, type, atom_offset + 8, atom_size - 8, param);
-#ifdef DEBUG
- debug_indent--;
-#endif
- return err;
-}
-
-static int parse_trak(const MOVParseTableEntry *parse_table, ByteIOContext *pb, UINT32 atom_type, INT64 atom_offset, INT64 atom_size, void *param)
-{
- MOVContext *c;
- AVStream *st;
- MOVStreamContext *sc;
-#ifdef DEBUG
- print_atom("trak", atom_type, atom_offset, atom_size);
-#endif
-
- c = (MOVContext *)param;
- st = av_new_stream(c->fc, c->fc->nb_streams);
- if (!st) return -2;
- sc = av_malloc(sizeof(MOVStreamContext));
- sc->sample_to_chunk_index = -1;
- st->priv_data = sc;
- st->codec.codec_type = CODEC_TYPE_MOV_OTHER;
- c->streams[c->fc->nb_streams-1] = sc;
- return parse_default(parse_table, pb, atom_type, atom_offset, atom_size, param);
-}
-
-static int parse_tkhd(const MOVParseTableEntry *parse_table, ByteIOContext *pb, UINT32 atom_type, INT64 atom_offset, INT64 atom_size, void *param)
-{
- MOVContext *c;
- AVStream *st;
-#ifdef DEBUG
- print_atom("tkhd", atom_type, atom_offset, atom_size);
-#endif
-
- c = (MOVContext *)param;
- st = c->fc->streams[c->fc->nb_streams-1];
-
- get_byte(pb); /* version */
-
- get_byte(pb); get_byte(pb);
- get_byte(pb); /* flags */
- /*
- MOV_TRACK_ENABLED 0x0001
- MOV_TRACK_IN_MOVIE 0x0002
- MOV_TRACK_IN_PREVIEW 0x0004
- MOV_TRACK_IN_POSTER 0x0008
- */
-
- get_be32(pb); /* creation time */
- get_be32(pb); /* modification time */
- st->id = (int)get_be32(pb); /* track id (NOT 0 !)*/
- get_be32(pb); /* reserved */
- get_be32(pb); /* duration */
- get_be32(pb); /* reserved */
- get_be32(pb); /* reserved */
-
- get_be16(pb); /* layer */
- get_be16(pb); /* alternate group */
- get_be16(pb); /* volume */
- get_be16(pb); /* reserved */
-
- url_fskip(pb, 36); /* display matrix */
-
- /* those are fixed-point */
- st->codec.width = get_be32(pb) >> 16; /* track width */
- st->codec.height = get_be32(pb) >> 16; /* track height */
-
- return 0;
-}
-
-static int parse_mdhd(const MOVParseTableEntry *parse_table, ByteIOContext *pb, UINT32 atom_type, INT64 atom_offset, INT64 atom_size, void *param)
-{
- MOVContext *c;
- AVStream *st;
-#ifdef DEBUG
- print_atom("mdhd", atom_type, atom_offset, atom_size);
-#endif
-
- c = (MOVContext *)param;
- st = c->fc->streams[c->fc->nb_streams-1];
-
- get_byte(pb); /* version */
-
- get_byte(pb); get_byte(pb);
- get_byte(pb); /* flags */
-
- get_be32(pb); /* creation time */
- get_be32(pb); /* modification time */
-
- c->streams[c->total_streams]->time_scale = get_be32(pb);
-
-#ifdef DEBUG
- printf("track[%i].time_scale = %li\n", c->fc->nb_streams-1, c->streams[c->total_streams]->time_scale); /* time scale */
-#endif
- get_be32(pb); /* duration */
-
- get_be16(pb); /* language */
- get_be16(pb); /* quality */
-
- return 0;
-}
-
-static int parse_hdlr(const MOVParseTableEntry *parse_table, ByteIOContext *pb, UINT32 atom_type, INT64 atom_offset, INT64 atom_size, void *param)
-{
- MOVContext *c;
- int len = 0;
- char *buf;
- UINT32 type;
- AVStream *st;
- UINT32 ctype;
-#ifdef DEBUG
- print_atom("hdlr", atom_type, atom_offset, atom_size);
-#endif
- c = (MOVContext *)param;
- st = c->fc->streams[c->fc->nb_streams-1];
-
- get_byte(pb); /* version */
- get_byte(pb); get_byte(pb); get_byte(pb); /* flags */
-
- /* component type */
- ctype = get_le32(pb);
- type = get_le32(pb); /* component subtype */
-
-#ifdef DEBUG
- printf("ctype= %c%c%c%c (0x%08lx)\n", *((char *)&ctype), ((char *)&ctype)[1], ((char *)&ctype)[2], ((char *)&ctype)[3], (long) ctype);
- printf("stype= %c%c%c%c\n", *((char *)&type), ((char *)&type)[1], ((char *)&type)[2], ((char *)&type)[3]);
-#endif
-#ifdef DEBUG
-/* XXX: yeah this is ugly... */
- if(ctype == MKTAG('m', 'h', 'l', 'r')) { /* MOV */
- if(type == MKTAG('v', 'i', 'd', 'e'))
- puts("hdlr: vide");
- else if(type == MKTAG('s', 'o', 'u', 'n'))
- puts("hdlr: soun");
- } else if(ctype == 0) { /* MP4 */
- if(type == MKTAG('v', 'i', 'd', 'e'))
- puts("hdlr: vide");
- else if(type == MKTAG('s', 'o', 'u', 'n'))
- puts("hdlr: soun");
- else if(type == MKTAG('o', 'd', 's', 'm'))
- puts("hdlr: odsm");
- else if(type == MKTAG('s', 'd', 's', 'm'))
- puts("hdlr: sdsm");
- } else puts("hdlr: meta");
-#endif
-
- if(ctype == MKTAG('m', 'h', 'l', 'r')) { /* MOV */
- /* helps parsing the string hereafter... */
- c->mp4 = 0;
- if(type == MKTAG('v', 'i', 'd', 'e'))
- st->codec.codec_type = CODEC_TYPE_VIDEO;
- else if(type == MKTAG('s', 'o', 'u', 'n'))
- st->codec.codec_type = CODEC_TYPE_AUDIO;
- } else if(ctype == 0) { /* MP4 */
- /* helps parsing the string hereafter... */
- c->mp4 = 1;
- if(type == MKTAG('v', 'i', 'd', 'e'))
- st->codec.codec_type = CODEC_TYPE_VIDEO;
- else if(type == MKTAG('s', 'o', 'u', 'n'))
- st->codec.codec_type = CODEC_TYPE_AUDIO;
- }
- get_be32(pb); /* component manufacture */
- get_be32(pb); /* component flags */
- get_be32(pb); /* component flags mask */
-
- if(atom_size <= 24)
- return 0; /* nothing left to read */
- /* XXX: MP4 uses a C string, not a pascal one */
- /* component name */
-
- if(c->mp4) {
- /* .mp4: C string */
- while(get_byte(pb) && (++len < (atom_size - 24)));
- } else {
- /* .mov: PASCAL string */
- len = get_byte(pb);
- buf = av_malloc(len+1);
- get_buffer(pb, buf, len);
- buf[len] = '\0';
-#ifdef DEBUG
- printf("**buf='%s'\n", buf);
-#endif
- av_free(buf);
- }
-#if 0
- len = get_byte(pb);
- /* 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
- printf("**buf='%s'\n", buf);
-#endif
- av_free(buf);
- } else {
- /* MP4 string */
- for(;;) {
- if (len == 0)
- break;
- len = get_byte(pb);
- }
- }
-#endif
-
- return 0;
-}
-
-static int mp4_read_descr_len(ByteIOContext *pb)
-{
- int c, len, count;
-
- len = 0;
- count = 0;
- for(;;) {
- c = get_byte(pb);
- len = (len << 7) | (c & 0x7f);
- if ((c & 0x80) == 0)
- break;
- if (++count == 4)
- break;
- }
- return len;
-}
-
-static int mp4_read_descr(ByteIOContext *pb, int *tag)
-{
- int len;
- *tag = get_byte(pb);
- len = mp4_read_descr_len(pb);
-#ifdef DEBUG
- printf("MPEG4 description: tag=0x%02x len=%d\n", *tag, len);
-#endif
- return len;
-}
-
-static int parse_stsd(const MOVParseTableEntry *parse_table, ByteIOContext *pb, UINT32 atom_type, INT64 atom_offset, INT64 atom_size, void *param)
-{
- MOVContext *c;
- int entries, size, samp_sz, frames_per_sample, id;
- UINT32 format;
- AVStream *st;
- MOVStreamContext *sc;
-#ifdef DEBUG
- print_atom("stsd", atom_type, atom_offset, atom_size);
-#endif
- c = (MOVContext *)param;
- st = c->fc->streams[c->fc->nb_streams-1];
- sc = (MOVStreamContext *)st->priv_data;
-
- get_byte(pb); /* version */
- get_byte(pb); get_byte(pb); get_byte(pb); /* flags */
-
- entries = get_be32(pb);
-
- while(entries--) {
- size = get_be32(pb); /* size */
- format = get_le32(pb); /* data format */
-
- get_be32(pb); /* reserved */
- get_be16(pb); /* reserved */
- get_be16(pb); /* index */
-
- /* for MPEG4: set codec type by looking for it */
- id = codec_get_id(mov_video_tags, format);
- if (id >= 0) {
- AVCodec *codec;
- codec = avcodec_find_decoder(id);
- if (codec)
- st->codec.codec_type = codec->type;
- }
-#ifdef DEBUG
- printf("size=%d 4CC= %c%c%c%c codec_type=%d\n",
- size,
- (format >> 0) & 0xff,
- (format >> 8) & 0xff,
- (format >> 16) & 0xff,
- (format >> 24) & 0xff,
- st->codec.codec_type);
-#endif
- if(st->codec.codec_type==CODEC_TYPE_VIDEO) {
- st->codec.codec_tag = format;
- st->codec.codec_id = codec_get_id(mov_video_tags, format);
- get_be16(pb); /* version */
- get_be16(pb); /* revision level */
- get_be32(pb); /* vendor */
- get_be32(pb); /* temporal quality */
- get_be32(pb); /* spacial quality */
- st->codec.width = get_be16(pb); /* width */
- st->codec.height = get_be16(pb); /* height */
-#if 1
- if (st->codec.codec_id == CODEC_ID_MPEG4) {
- /* in some MPEG4 the width/height are not correct, so
- we ignore this info */
- st->codec.width = 0;
- st->codec.height = 0;
- }
-#endif
- get_be32(pb); /* horiz resolution */
- get_be32(pb); /* vert resolution */
- get_be32(pb); /* data size, always 0 */
- frames_per_sample = get_be16(pb); /* frame per samples */
-#ifdef DEBUG
- printf("frames/samples = %d\n", frames_per_sample);
-#endif
- url_fskip(pb, 32); /* codec name */
-
- get_be16(pb); /* depth */
- get_be16(pb); /* colortable id */
-
- st->codec.frame_rate = 25 * FRAME_RATE_BASE;
-
- size -= (16+8*4+2+32+2*2);
- while (size >= 8) {
- int atom_size, atom_type;
- INT64 start_pos;
-
- atom_size = get_be32(pb);
- atom_type = get_le32(pb);
- size -= 8;
-#ifdef DEBUG
- printf("VIDEO: atom_type=%c%c%c%c atom_size=%d size_left=%d\n",
- (atom_type >> 0) & 0xff,
- (atom_type >> 8) & 0xff,
- (atom_type >> 16) & 0xff,
- (atom_type >> 24) & 0xff,
- atom_size, size);
-#endif
- start_pos = url_ftell(pb);
-
- switch(atom_type) {
- case MKTAG('e', 's', 'd', 's'):
- {
- int tag, len;
- /* Well, broken but suffisant for some MP4 streams */
- get_be32(pb); /* version + flags */
- len = mp4_read_descr(pb, &tag);
- if (tag == 0x03) {
- /* MP4ESDescrTag */
- get_be16(pb); /* ID */
- get_byte(pb); /* priority */
- len = mp4_read_descr(pb, &tag);
- if (tag != 0x04)
- goto fail;
- /* MP4DecConfigDescrTag */
- get_byte(pb); /* objectTypeId */
- get_be32(pb); /* streamType + buffer size */
- get_be32(pb); /* max bit rate */
- get_be32(pb); /* avg bit rate */
- len = mp4_read_descr(pb, &tag);
- if (tag != 0x05)
- goto fail;
- /* MP4DecSpecificDescrTag */
-#ifdef DEBUG
- printf("Specific MPEG4 header len=%d\n", len);
-#endif
- sc->header_data = av_mallocz(len);
- if (sc->header_data) {
- get_buffer(pb, sc->header_data, len);
- sc->header_len = len;
- }
- }
- /* in any case, skip garbage */
- }
- break;
- default:
- break;
- }
- fail:
- url_fskip(pb, (atom_size - 8) -
- ((url_ftell(pb) - start_pos)));
- size -= atom_size - 8;
- }
- if (size > 0) {
- /* unknown extension */
- url_fskip(pb, size);
- }
- } else {
- st->codec.codec_tag = format;
-
- get_be16(pb); /* version */
- get_be16(pb); /* revision level */
- get_be32(pb); /* vendor */
-
- st->codec.channels = get_be16(pb);/* channel count */
- samp_sz = get_be16(pb); /* sample size */
-#ifdef DEBUG
- if(samp_sz != 16)
- puts("!!! stsd: audio sample size is not 16 bit !");
-#endif
- st->codec.codec_id = codec_get_id(mov_audio_tags, format);
- /* handle specific s8 codec */
- if (st->codec.codec_id == CODEC_ID_PCM_S16BE && samp_sz == 8)
- st->codec.codec_id = CODEC_ID_PCM_S8;
-
- get_be16(pb); /* compression id = 0*/
- get_be16(pb); /* packet size = 0 */
-
- st->codec.sample_rate = ((get_be32(pb) >> 16));
- st->codec.bit_rate = 0;
-#if 0
-
- get_be16(pb); get_be16(pb); /* */
- get_be16(pb); /* */
- get_be16(pb); /* */
- get_be16(pb); /* */
- get_be16(pb); /* */
-#endif
- if(size > 16)
- url_fskip(pb, size-(16+20));
- }
- }
-/*
- if(len) {
- buf = av_malloc(len+1);
- get_buffer(pb, buf, len);
- buf[len] = '\0';
- puts(buf);
- av_free(buf);
- }
-*/
- return 0;
-}
-
-static int parse_stco(const MOVParseTableEntry *parse_table, ByteIOContext *pb, UINT32 atom_type, INT64 atom_offset, INT64 atom_size, void *param)
-{
- MOVContext *c;
- int entries, i;
- AVStream *st;
- MOVStreamContext *sc;
-#ifdef DEBUG
- print_atom("stco", atom_type, atom_offset, atom_size);
-#endif
- c = (MOVContext *)param;
- st = c->fc->streams[c->fc->nb_streams-1];
- sc = (MOVStreamContext *)st->priv_data;
-
- get_byte(pb); /* version */
- get_byte(pb); get_byte(pb); get_byte(pb); /* flags */
-
- entries = get_be32(pb);
- sc->chunk_count = entries;
- sc->chunk_offsets = av_malloc(entries * sizeof(INT64));
- if(atom_type == MKTAG('s', 't', 'c', 'o')) {
- for(i=0; i<entries; i++) {
- sc->chunk_offsets[i] = get_be32(pb);
- }
- } else if(atom_type == MKTAG('c', 'o', '6', '4')) {
- for(i=0; i<entries; i++) {
- sc->chunk_offsets[i] = get_be64(pb);
- }
- } else
- return -1;
-#ifdef DEBUG
-/*
- for(i=0; i<entries; i++) {
- printf("chunk offset=0x%Lx\n", sc->chunk_offsets[i]);
- }
-*/
-#endif
- return 0;
-}
-
-static int parse_stsc(const MOVParseTableEntry *parse_table, ByteIOContext *pb, UINT32 atom_type, INT64 atom_offset, INT64 atom_size, void *param)
-{
- MOVContext *c;
- int entries, i;
- AVStream *st;
- MOVStreamContext *sc;
-#ifdef DEBUG
- print_atom("stsc", atom_type, atom_offset, atom_size);
-#endif
- c = (MOVContext *)param;
- st = c->fc->streams[c->fc->nb_streams-1];
- sc = (MOVStreamContext *)st->priv_data;
-
- get_byte(pb); /* version */
- get_byte(pb); get_byte(pb); get_byte(pb); /* flags */
-
- entries = get_be32(pb);
-#ifdef DEBUG
-printf("track[%i].stsc.entries = %i\n", c->fc->nb_streams-1, entries);
-#endif
- sc->sample_to_chunk_sz = entries;
- sc->sample_to_chunk = av_malloc(entries * sizeof(MOV_sample_to_chunk_tbl));
- for(i=0; i<entries; i++) {
- sc->sample_to_chunk[i].first = get_be32(pb);
- sc->sample_to_chunk[i].count = get_be32(pb);
- sc->sample_to_chunk[i].id = get_be32(pb);
-#ifdef DEBUG
-/* printf("sample_to_chunk first=%ld count=%ld, id=%ld\n", sc->sample_to_chunk[i].first, sc->sample_to_chunk[i].count, sc->sample_to_chunk[i].id); */
-#endif
- }
- return 0;
-}
-
-static int parse_stsz(const MOVParseTableEntry *parse_table, ByteIOContext *pb, UINT32 atom_type, INT64 atom_offset, INT64 atom_size, void *param)
-{
- MOVContext *c;
- int entries, i;
- AVStream *st;
- MOVStreamContext *sc;
-#ifdef DEBUG
- print_atom("stsz", atom_type, atom_offset, atom_size);
-#endif
- c = (MOVContext *)param;
- st = c->fc->streams[c->fc->nb_streams-1];
- sc = (MOVStreamContext *)st->priv_data;
-
- get_byte(pb); /* version */
- get_byte(pb); get_byte(pb); get_byte(pb); /* flags */
-
- sc->sample_size = get_be32(pb);
- entries = get_be32(pb);
- sc->sample_count = entries;
-#ifdef DEBUG
- printf("sample_size = %ld sample_count = %ld\n", sc->sample_size, sc->sample_count);
-#endif
- if(sc->sample_size)
- return 0; /* there isn't any table following */
- sc->sample_sizes = av_malloc(entries * sizeof(long));
- for(i=0; i<entries; i++) {
- sc->sample_sizes[i] = get_be32(pb);
-#ifdef DEBUG
-/* printf("sample_sizes[]=%ld\n", sc->sample_sizes[i]); */
-#endif
- }
- return 0;
-}
-
-static int parse_stts(const MOVParseTableEntry *parse_table, ByteIOContext *pb, UINT32 atom_type, INT64 atom_offset, INT64 atom_size, void *param)
-{
- MOVContext *c;
- int entries, i;
- AVStream *st;
- MOVStreamContext *sc;
-#ifdef DEBUG
- print_atom("stts", atom_type, atom_offset, atom_size);
-#endif
- c = (MOVContext *)param;
- st = c->fc->streams[c->fc->nb_streams-1];
- sc = (MOVStreamContext *)st->priv_data;
-
- get_byte(pb); /* version */
- get_byte(pb); get_byte(pb); get_byte(pb); /* flags */
- entries = get_be32(pb);
-#ifdef DEBUG
-printf("track[%i].stts.entries = %i\n", c->fc->nb_streams-1, entries);
-#endif
- for(i=0; i<entries; i++) {
- int sample_duration;
-
- get_be32(pb);
- sample_duration = get_be32(pb);
-
- if (!i && st->codec.codec_type==CODEC_TYPE_VIDEO) {
- st->codec.frame_rate = FRAME_RATE_BASE * c->streams[c->total_streams]->time_scale;
- if (sample_duration)
- st->codec.frame_rate /= sample_duration;
-#ifdef DEBUG
- printf("VIDEO FRAME RATE= %i (sd= %i)\n", st->codec.frame_rate, sample_duration);
-#endif
- }
- }
- return 0;
-}
-
-#ifdef CONFIG_ZLIB
-static int null_read_packet(void *opaque, UINT8 *buf, int buf_size)
-{
- return -1;
-}
-
-static int parse_cmov(const MOVParseTableEntry *parse_table, ByteIOContext *pb, UINT32 atom_type, INT64 atom_offset, INT64 atom_size, void *param)
-{
- MOVContext *c;
- ByteIOContext ctx;
- char *cmov_data;
- unsigned char *moov_data; /* uncompressed data */
- long cmov_len, moov_len;
- int ret;
-#ifdef DEBUG
- print_atom("cmov", atom_type, atom_offset, atom_size);
-#endif
- c = (MOVContext *)param;
-
- get_be32(pb); /* dcom atom */
- if (get_le32(pb) != MKTAG( 'd', 'c', 'o', 'm' ))
- return -1;
- if (get_le32(pb) != MKTAG( 'z', 'l', 'i', 'b' )) {
- puts("unknown compression for cmov atom !");
- return -1;
- }
- get_be32(pb); /* cmvd atom */
- if (get_le32(pb) != MKTAG( 'c', 'm', 'v', 'd' ))
- return -1;
- moov_len = get_be32(pb); /* uncompressed size */
- cmov_len = atom_size - 6 * 4;
-
- cmov_data = av_malloc(cmov_len);
- if (!cmov_data)
- return -1;
- moov_data = av_malloc(moov_len);
- if (!moov_data) {
- av_free(cmov_data);
- return -1;
- }
- get_buffer(pb, cmov_data, cmov_len);
- if(uncompress (moov_data, &moov_len, (const Bytef *)cmov_data, cmov_len) != Z_OK)
- return -1;
- if(init_put_byte(&ctx, moov_data, moov_len, 0, NULL, null_read_packet, NULL, NULL) != 0)
- return -1;
- ctx.buf_end = ctx.buffer + moov_len;
- ret = parse_default(parse_table, &ctx, MKTAG( 'm', 'o', 'o', 'v' ), 0, moov_len, param);
- av_free(moov_data);
- av_free(cmov_data);
- return ret;
-}
-#endif
-
-static const MOVParseTableEntry mov_default_parse_table[] = {
-/* mp4 atoms */
-{ MKTAG( 'm', 'p', '4', 'a' ), parse_default },
-{ MKTAG( 'c', 'o', '6', '4' ), parse_stco },
-{ MKTAG( 's', 't', 'c', 'o' ), parse_stco },
-{ MKTAG( 'c', 'r', 'h', 'd' ), parse_default },
-{ MKTAG( 'c', 't', 't', 's' ), parse_leaf },
-{ MKTAG( 'c', 'p', 'r', 't' ), parse_default },
-{ MKTAG( 'u', 'r', 'l', ' ' ), parse_leaf },
-{ MKTAG( 'u', 'r', 'n', ' ' ), parse_leaf },
-{ MKTAG( 'd', 'i', 'n', 'f' ), parse_default },
-{ MKTAG( 'd', 'r', 'e', 'f' ), parse_leaf },
-{ MKTAG( 's', 't', 'd', 'p' ), parse_default },
-{ MKTAG( 'e', 's', 'd', 's' ), parse_default },
-{ MKTAG( 'e', 'd', 't', 's' ), parse_default },
-{ MKTAG( 'e', 'l', 's', 't' ), parse_leaf },
-{ MKTAG( 'u', 'u', 'i', 'd' ), parse_default },
-{ MKTAG( 'f', 'r', 'e', 'e' ), parse_leaf },
-{ MKTAG( 'h', 'd', 'l', 'r' ), parse_hdlr },
-{ MKTAG( 'h', 'm', 'h', 'd' ), parse_leaf },
-{ MKTAG( 'h', 'i', 'n', 't' ), parse_leaf },
-{ MKTAG( 'n', 'm', 'h', 'd' ), parse_leaf },
-{ MKTAG( 'm', 'p', '4', 's' ), parse_default },
-{ MKTAG( 'm', 'd', 'i', 'a' ), parse_default },
-{ MKTAG( 'm', 'd', 'a', 't' ), parse_mdat },
-{ MKTAG( 'm', 'd', 'h', 'd' ), parse_mdhd },
-{ MKTAG( 'm', 'i', 'n', 'f' ), parse_default },
-{ MKTAG( 'm', 'o', 'o', 'v' ), parse_moov },
-{ MKTAG( 'm', 'v', 'h', 'd' ), parse_mvhd },
-{ MKTAG( 'i', 'o', 'd', 's' ), parse_leaf },
-{ MKTAG( 'o', 'd', 'h', 'd' ), parse_default },
-{ MKTAG( 'm', 'p', 'o', 'd' ), parse_leaf },
-{ MKTAG( 's', 't', 's', 'd' ), parse_stsd },
-{ MKTAG( 's', 't', 's', 'z' ), parse_stsz },
-{ MKTAG( 's', 't', 'b', 'l' ), parse_default },
-{ MKTAG( 's', 't', 's', 'c' ), parse_stsc },
-{ MKTAG( 's', 'd', 'h', 'd' ), parse_default },
-{ MKTAG( 's', 't', 's', 'h' ), parse_default },
-{ MKTAG( 's', 'k', 'i', 'p' ), parse_default },
-{ MKTAG( 's', 'm', 'h', 'd' ), parse_leaf },
-{ MKTAG( 'd', 'p', 'n', 'd' ), parse_leaf },
-{ MKTAG( 's', 't', 's', 's' ), parse_leaf },
-{ MKTAG( 's', 't', 't', 's' ), parse_stts },
-{ MKTAG( 't', 'r', 'a', 'k' ), parse_trak },
-{ MKTAG( 't', 'k', 'h', 'd' ), parse_tkhd },
-{ MKTAG( 't', 'r', 'e', 'f' ), parse_default }, /* not really */
-{ MKTAG( 'u', 'd', 't', 'a' ), parse_leaf },
-{ MKTAG( 'v', 'm', 'h', 'd' ), parse_leaf },
-{ MKTAG( 'm', 'p', '4', 'v' ), parse_default },
-/* extra mp4 */
-{ MKTAG( 'M', 'D', 'E', 'S' ), parse_leaf },
-/* QT atoms */
-{ MKTAG( 'c', 'h', 'a', 'p' ), parse_leaf },
-{ MKTAG( 'c', 'l', 'i', 'p' ), parse_default },
-{ MKTAG( 'c', 'r', 'g', 'n' ), parse_leaf },
-{ MKTAG( 'k', 'm', 'a', 't' ), parse_leaf },
-{ MKTAG( 'm', 'a', 't', 't' ), parse_default },
-{ MKTAG( 'r', 'd', 'r', 'f' ), parse_leaf },
-{ MKTAG( 'r', 'm', 'd', 'a' ), parse_default },
-{ MKTAG( 'r', 'm', 'd', 'r' ), parse_leaf },
-//{ MKTAG( 'r', 'm', 'q', 'u' ), parse_leaf },
-{ MKTAG( 'r', 'm', 'r', 'a' ), parse_default },
-{ MKTAG( 's', 'c', 'p', 't' ), parse_leaf },
-{ MKTAG( 's', 'y', 'n', 'c' ), parse_leaf },
-{ MKTAG( 's', 's', 'r', 'c' ), parse_leaf },
-{ MKTAG( 't', 'c', 'm', 'd' ), parse_leaf },
-{ MKTAG( 'w', 'i', 'd', 'e' ), parse_wide }, /* place holder */
-#ifdef CONFIG_ZLIB
-{ MKTAG( 'c', 'm', 'o', 'v' ), parse_cmov },
-#else
-{ MKTAG( 'c', 'm', 'o', 'v' ), parse_leaf },
-#endif
-{ 0L, parse_leaf }
-};
-
-static void mov_free_stream_context(MOVStreamContext *sc)
-{
- if(sc) {
- av_free(sc->chunk_offsets);
- av_free(sc->sample_to_chunk);
- av_free(sc->header_data);
- av_free(sc);
- }
-}
-
-static uint32_t to_tag(uint8_t *buf)
-{
- return buf[0] | (buf[1] << 8) | (buf[2] << 16) | (buf[3] << 24);
-}
-
-static uint32_t to_be32(uint8_t *buf)
-{
- return (buf[0] << 24) | (buf[1] << 16) | (buf[2] << 8) | buf[3];
-}
-
-/* XXX: is it suffisant ? */
-static int mov_probe(AVProbeData *p)
-{
- unsigned int offset;
- uint32_t tag;
-
- /* check file header */
- if (p->buf_size <= 12)
- return 0;
- offset = 0;
- for(;;) {
- /* ignore invalid offset */
- if ((offset + 8) > (unsigned int)p->buf_size)
- return 0;
- tag = to_tag(p->buf + offset + 4);
- switch(tag) {
- case MKTAG( 'm', 'o', 'o', 'v' ):
- case MKTAG( 'w', 'i', 'd', 'e' ):
- case MKTAG( 'f', 'r', 'e', 'e' ):
- case MKTAG( 'm', 'd', 'a', 't'):
- return AVPROBE_SCORE_MAX;
- case MKTAG( 'f', 't', 'y', 'p' ):
- case MKTAG( 's', 'k', 'i', 'p' ):
- offset = to_be32(p->buf) + offset;
- break;
- default:
- /* unrecognized tag */
- return 0;
- }
- }
- return 0;
-}
-
-static int mov_read_header(AVFormatContext *s, AVFormatParameters *ap)
-{
- MOVContext *mov = s->priv_data;
- ByteIOContext *pb = &s->pb;
- int i, j, nb, err;
- INT64 size;
-
- mov->fc = s;
-#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
- size = 0x7FFFFFFFFFFFFFFF;
-
-#ifdef DEBUG
- printf("filesz=%Ld\n", size);
-#endif
-
- /* check MOV header */
- err = parse_default(mov_default_parse_table, pb, 0L, 0LL, size, mov);
- if(err<0 || (!mov->found_moov || !mov->found_mdat)) {
- puts("header not found !!!");
- exit(1);
- }
-#ifdef DEBUG
- printf("on_parse_exit_offset=%d\n", (int) url_ftell(pb));
-#endif
- /* some cleanup : make sure we are on the mdat atom */
- if(!url_is_streamed(pb) && (url_ftell(pb) != mov->mdat_offset))
- url_fseek(pb, mov->mdat_offset, SEEK_SET);
-
- mov->next_chunk_offset = mov->mdat_offset; /* initialise reading */
-
-#ifdef DEBUG
- printf("mdat_reset_offset=%d\n", (int) url_ftell(pb));
-#endif
-
-#ifdef DEBUG
- printf("streams= %d\n", s->nb_streams);
-#endif
- mov->total_streams = nb = s->nb_streams;
-
-#if 1
- for(i=0; i<s->nb_streams;) {
- if(s->streams[i]->codec.codec_type == CODEC_TYPE_MOV_OTHER) {/* not audio, not video, delete */
- av_free(s->streams[i]);
- for(j=i+1; j<s->nb_streams; j++)
- s->streams[j-1] = s->streams[j];
- s->nb_streams--;
- } else
- i++;
- }
- for(i=0; i<s->nb_streams;i++) {
- MOVStreamContext *sc;
- sc = (MOVStreamContext *)s->streams[i]->priv_data;
- sc->ffindex = i;
- sc->is_ff_stream = 1;
- }
-#endif
-#ifdef DEBUG
- printf("real streams= %d\n", s->nb_streams);
-#endif
- return 0;
-}
-
-/* Yes, this is ugly... I didn't write the specs of QT :p */
-/* XXX:remove useless commented code sometime */
-static int mov_read_packet(AVFormatContext *s, AVPacket *pkt)
-{
- MOVContext *mov = s->priv_data;
- MOVStreamContext *sc;
- INT64 offset = 0x0FFFFFFFFFFFFFFF;
- int i;
- int st_id = 0, size;
- size = 0x0FFFFFFF;
-
-#ifdef MOV_SPLIT_CHUNKS
- if (mov->partial) {
-
- int idx;
-
- st_id = mov->partial - 1;
- idx = mov->streams[st_id]->sample_to_chunk_index;
- if (idx < 0) return 0;
- size = mov->streams[st_id]->sample_sizes[mov->streams[st_id]->current_sample];
-
- mov->streams[st_id]->current_sample++;
- mov->streams[st_id]->left_in_chunk--;
-
- if(mov->streams[st_id]->left_in_chunk <= 0)
- mov->partial = 0;
- offset = mov->next_chunk_offset;
- /* extract the sample */
-
- goto readchunk;
- }
-#endif
-
-again:
- for(i=0; i<mov->total_streams; i++) {
- if((mov->streams[i]->next_chunk < mov->streams[i]->chunk_count)
- && (mov->streams[i]->chunk_offsets[mov->streams[i]->next_chunk] < offset)) {
- st_id = i;
- offset = mov->streams[i]->chunk_offsets[mov->streams[i]->next_chunk];
- }
- }
- mov->streams[st_id]->next_chunk++;
- if(offset==0x0FFFFFFFFFFFFFFF)
- return -1;
-
- if(mov->next_chunk_offset < offset) { /* some meta data */
- url_fskip(&s->pb, (offset - mov->next_chunk_offset));
- mov->next_chunk_offset = offset;
- }
-
-//printf("chunk: [%i] %lli -> %lli\n", st_id, mov->next_chunk_offset, offset);
- if(!mov->streams[st_id]->is_ff_stream) {
- url_fskip(&s->pb, (offset - mov->next_chunk_offset));
- mov->next_chunk_offset = offset;
- offset = 0x0FFFFFFFFFFFFFFF;
- goto again;
- }
-
- /* now get the chunk size... */
-
- for(i=0; i<mov->total_streams; i++) {
- if((mov->streams[i]->next_chunk < mov->streams[i]->chunk_count)
- && ((mov->streams[i]->chunk_offsets[mov->streams[i]->next_chunk] - offset) < size)) {
- size = mov->streams[i]->chunk_offsets[mov->streams[i]->next_chunk] - offset;
- }
- }
-#ifdef MOV_SPLIT_CHUNKS
- /* split chunks into samples */
- if(mov->streams[st_id]->sample_size == 0) {
- int idx;
- idx = mov->streams[st_id]->sample_to_chunk_index;
- if ((idx + 1 < mov->streams[st_id]->sample_to_chunk_sz)
- && (mov->streams[st_id]->next_chunk >= mov->streams[st_id]->sample_to_chunk[idx + 1].first))
- idx++;
- mov->streams[st_id]->sample_to_chunk_index = idx;
- if(idx >= 0 && mov->streams[st_id]->sample_to_chunk[idx].count != 1) {
- mov->partial = st_id+1;
- /* we'll have to get those samples before next chunk */
- mov->streams[st_id]->left_in_chunk = (mov->streams[st_id]->sample_to_chunk[idx].count) - 1;
- size = mov->streams[st_id]->sample_sizes[mov->streams[st_id]->current_sample];
- }
-
- mov->streams[st_id]->current_sample++;
- }
-#endif
-
-readchunk:
-//printf("chunk: [%i] %lli -> %lli (%i)\n", st_id, offset, offset + size, size);
- if(size == 0x0FFFFFFF)
- size = mov->mdat_size + mov->mdat_offset - offset;
- if(size < 0)
- return -1;
- if(size ==&n