summaryrefslogtreecommitdiff
path: root/libavformat
diff options
context:
space:
mode:
authorAnton Khirnov <anton@khirnov.net>2014-06-09 14:21:56 +0200
committerAnton Khirnov <anton@khirnov.net>2014-06-18 14:55:28 +0200
commit894682a9739eb8d4bfc024b0d4e5757fcfe47378 (patch)
tree90ef81afc38381df7e8c54bd7e5d4c34b1b364e7 /libavformat
parentf2ce63246f5c934429f9cb857a794e07624d7912 (diff)
Remove avserver.
It has not been properly maintained for years and there is little hope of that changing in the future. It appears simpler to write a new replacement from scratch than unbreaking it.
Diffstat (limited to 'libavformat')
-rw-r--r--libavformat/Makefile2
-rw-r--r--libavformat/allformats.c1
-rw-r--r--libavformat/ffm.h59
-rw-r--r--libavformat/ffmdec.c483
-rw-r--r--libavformat/ffmenc.c249
5 files changed, 0 insertions, 794 deletions
diff --git a/libavformat/Makefile b/libavformat/Makefile
index b6957f60ec..a7ff117f9e 100644
--- a/libavformat/Makefile
+++ b/libavformat/Makefile
@@ -107,8 +107,6 @@ OBJS-$(CONFIG_EA_CDATA_DEMUXER) += eacdata.o
OBJS-$(CONFIG_EA_DEMUXER) += electronicarts.o
OBJS-$(CONFIG_EAC3_DEMUXER) += ac3dec.o rawdec.o
OBJS-$(CONFIG_EAC3_MUXER) += rawenc.o
-OBJS-$(CONFIG_FFM_DEMUXER) += ffmdec.o
-OBJS-$(CONFIG_FFM_MUXER) += ffmenc.o
OBJS-$(CONFIG_FFMETADATA_DEMUXER) += ffmetadec.o
OBJS-$(CONFIG_FFMETADATA_MUXER) += ffmetaenc.o
OBJS-$(CONFIG_FILMSTRIP_DEMUXER) += filmstripdec.o
diff --git a/libavformat/allformats.c b/libavformat/allformats.c
index 40962f8971..8083ef3e97 100644
--- a/libavformat/allformats.c
+++ b/libavformat/allformats.c
@@ -100,7 +100,6 @@ void av_register_all(void)
REGISTER_DEMUXER (EA_CDATA, ea_cdata);
REGISTER_MUXDEMUX(EAC3, eac3);
REGISTER_MUXER (F4V, f4v);
- REGISTER_MUXDEMUX(FFM, ffm);
REGISTER_MUXDEMUX(FFMETADATA, ffmetadata);
REGISTER_MUXDEMUX(FILMSTRIP, filmstrip);
REGISTER_MUXDEMUX(FLAC, flac);
diff --git a/libavformat/ffm.h b/libavformat/ffm.h
deleted file mode 100644
index 70c3e887a0..0000000000
--- a/libavformat/ffm.h
+++ /dev/null
@@ -1,59 +0,0 @@
-/*
- * FFM (avserver live feed) common header
- * Copyright (c) 2001 Fabrice Bellard
- *
- * This file is part of Libav.
- *
- * Libav 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.1 of the License, or (at your option) any later version.
- *
- * Libav 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 Libav; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- */
-
-#ifndef AVFORMAT_FFM_H
-#define AVFORMAT_FFM_H
-
-#include <stdint.h>
-#include "avformat.h"
-#include "avio.h"
-
-/* The FFM file is made of blocks of fixed size */
-#define FFM_HEADER_SIZE 14
-#define FFM_PACKET_SIZE 4096
-#define PACKET_ID 0x666d
-
-/* each packet contains frames (which can span several packets */
-#define FRAME_HEADER_SIZE 16
-#define FLAG_KEY_FRAME 0x01
-#define FLAG_DTS 0x02
-
-enum {
- READ_HEADER,
- READ_DATA,
-};
-
-typedef struct FFMContext {
- /* only reading mode */
- int64_t write_index, file_size;
- int read_state;
- uint8_t header[FRAME_HEADER_SIZE+4];
-
- /* read and write */
- int first_packet; /* true if first packet, needed to set the discontinuity tag */
- int packet_size;
- int frame_offset;
- int64_t dts;
- uint8_t *packet_ptr, *packet_end;
- uint8_t packet[FFM_PACKET_SIZE];
-} FFMContext;
-
-#endif /* AVFORMAT_FFM_H */
diff --git a/libavformat/ffmdec.c b/libavformat/ffmdec.c
deleted file mode 100644
index acc1dc4110..0000000000
--- a/libavformat/ffmdec.c
+++ /dev/null
@@ -1,483 +0,0 @@
-/*
- * FFM (avserver live feed) demuxer
- * Copyright (c) 2001 Fabrice Bellard
- *
- * This file is part of Libav.
- *
- * Libav 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.1 of the License, or (at your option) any later version.
- *
- * Libav 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 Libav; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- */
-
-#include <stdint.h>
-
-#include "libavutil/intreadwrite.h"
-#include "libavutil/intfloat.h"
-#include "avformat.h"
-#include "internal.h"
-#include "ffm.h"
-
-static int ffm_is_avail_data(AVFormatContext *s, int size)
-{
- FFMContext *ffm = s->priv_data;
- int64_t pos, avail_size;
- int len;
-
- len = ffm->packet_end - ffm->packet_ptr;
- if (size <= len)
- return 1;
- pos = avio_tell(s->pb);
- if (!ffm->write_index) {
- if (pos == ffm->file_size)
- return AVERROR_EOF;
- avail_size = ffm->file_size - pos;
- } else {
- if (pos == ffm->write_index) {
- /* exactly at the end of stream */
- return AVERROR(EAGAIN);
- } 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 AVERROR(EAGAIN);
-}
-
-static int ffm_resync(AVFormatContext *s, int state)
-{
- av_log(s, AV_LOG_ERROR, "resyncing\n");
- while (state != PACKET_ID) {
- if (s->pb->eof_reached) {
- av_log(s, AV_LOG_ERROR, "cannot find FFM syncword\n");
- return -1;
- }
- state = (state << 8) | avio_r8(s->pb);
- }
- return 0;
-}
-
-/* first is true if we read the frame header */
-static int ffm_read_data(AVFormatContext *s,
- uint8_t *buf, int size, int header)
-{
- FFMContext *ffm = s->priv_data;
- AVIOContext *pb = s->pb;
- int len, fill_size, size1, frame_offset, id;
-
- size1 = size;
- while (size > 0) {
- redo:
- len = ffm->packet_end - ffm->packet_ptr;
- if (len < 0)
- return -1;
- if (len > size)
- len = size;
- if (len == 0) {
- if (avio_tell(pb) == ffm->file_size)
- avio_seek(pb, ffm->packet_size, SEEK_SET);
- retry_read:
- id = avio_rb16(pb); /* PACKET_ID */
- if (id != PACKET_ID)
- if (ffm_resync(s, id) < 0)
- return -1;
- fill_size = avio_rb16(pb);
- ffm->dts = avio_rb64(pb);
- frame_offset = avio_rb16(pb);
- avio_read(pb, ffm->packet, ffm->packet_size - FFM_HEADER_SIZE);
- ffm->packet_end = ffm->packet + (ffm->packet_size - FFM_HEADER_SIZE - fill_size);
- if (ffm->packet_end < ffm->packet || frame_offset < 0)
- return -1;
- /* 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 (avio_tell(pb) >= ffm->packet_size * 3) {
- avio_seek(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 & 0x7fff) < FFM_HEADER_SIZE)
- return -1;
- ffm->packet_ptr = ffm->packet + (frame_offset & 0x7fff) - FFM_HEADER_SIZE;
- if (!header)
- break;
- } else {
- ffm->packet_ptr = ffm->packet;
- }
- goto redo;
- }
- memcpy(buf, ffm->packet_ptr, len);
- buf += len;
- ffm->packet_ptr += len;
- size -= len;
- header = 0;
- }
- return size1 - size;
-}
-
-/* ensure that acutal seeking happens between FFM_PACKET_SIZE
- and file_size - FFM_PACKET_SIZE */
-static int64_t ffm_seek1(AVFormatContext *s, int64_t pos1)
-{
- FFMContext *ffm = s->priv_data;
- AVIOContext *pb = s->pb;
- int64_t pos;
-
- pos = FFMIN(pos1, ffm->file_size - FFM_PACKET_SIZE);
- pos = FFMAX(pos, FFM_PACKET_SIZE);
- av_dlog(s, "seek to %"PRIx64" -> %"PRIx64"\n", pos1, pos);
- return avio_seek(pb, pos, SEEK_SET);
-}
-
-static int64_t get_dts(AVFormatContext *s, int64_t pos)
-{
- AVIOContext *pb = s->pb;
- int64_t dts;
-
- ffm_seek1(s, pos);
- avio_skip(pb, 4);
- dts = avio_rb64(pb);
- av_dlog(s, "dts=%0.6f\n", dts / 1000000.0);
- return dts;
-}
-
-static void adjust_write_index(AVFormatContext *s)
-{
- FFMContext *ffm = s->priv_data;
- AVIOContext *pb = s->pb;
- int64_t pts;
- //int64_t orig_write_index = ffm->write_index;
- int64_t pos_min, pos_max;
- int64_t pts_start;
- int64_t ptr = avio_tell(pb);
-
-
- pos_min = 0;
- pos_max = ffm->file_size - 2 * FFM_PACKET_SIZE;
-
- pts_start = get_dts(s, pos_min);
-
- pts = get_dts(s, pos_max);
-
- if (pts - 100000 > pts_start)
- goto end;
-
- ffm->write_index = FFM_PACKET_SIZE;
-
- pts_start = get_dts(s, pos_min);
-
- pts = get_dts(s, pos_max);
-
- if (pts - 100000 <= pts_start) {
- while (1) {
- int64_t newpos;
- int64_t newpts;
-
- newpos = ((pos_max + pos_min) / (2 * FFM_PACKET_SIZE)) * FFM_PACKET_SIZE;
-
- if (newpos == pos_min)
- break;
-
- newpts = get_dts(s, newpos);
-
- if (newpts - 100000 <= pts) {
- pos_max = newpos;
- pts = newpts;
- } else {
- pos_min = newpos;
- }
- }
- ffm->write_index += pos_max;
- }
-
- end:
- avio_seek(pb, ptr, SEEK_SET);
-}
-
-
-static int ffm_close(AVFormatContext *s)
-{
- int i;
-
- for (i = 0; i < s->nb_streams; i++)
- av_freep(&s->streams[i]->codec->rc_eq);
-
- return 0;
-}
-
-
-static int ffm_read_header(AVFormatContext *s)
-{
- FFMContext *ffm = s->priv_data;
- AVStream *st;
- AVIOContext *pb = s->pb;
- AVCodecContext *codec;
- int i, nb_streams;
- uint32_t tag;
-
- /* header */
- tag = avio_rl32(pb);
- if (tag != MKTAG('F', 'F', 'M', '1'))
- goto fail;
- ffm->packet_size = avio_rb32(pb);
- if (ffm->packet_size != FFM_PACKET_SIZE)
- goto fail;
- ffm->write_index = avio_rb64(pb);
- /* get also filesize */
- if (pb->seekable) {
- ffm->file_size = avio_size(pb);
- if (ffm->write_index)
- adjust_write_index(s);
- } else {
- ffm->file_size = (UINT64_C(1) << 63) - 1;
- }
-
- nb_streams = avio_rb32(pb);
- avio_rb32(pb); /* total bitrate */
- /* read each stream */
- for(i=0;i<nb_streams;i++) {
- char rc_eq_buf[128];
-
- st = avformat_new_stream(s, NULL);
- if (!st)
- goto fail;
-
- avpriv_set_pts_info(st, 64, 1, 1000000);
-
- codec = st->codec;
- /* generic info */
- codec->codec_id = avio_rb32(pb);
- codec->codec_type = avio_r8(pb); /* codec_type */
- codec->bit_rate = avio_rb32(pb);
- codec->flags = avio_rb32(pb);
- codec->flags2 = avio_rb32(pb);
- codec->debug = avio_rb32(pb);
- /* specific info */
- switch(codec->codec_type) {
- case AVMEDIA_TYPE_VIDEO:
- codec->time_base.num = avio_rb32(pb);
- codec->time_base.den = avio_rb32(pb);
- codec->width = avio_rb16(pb);
- codec->height = avio_rb16(pb);
- codec->gop_size = avio_rb16(pb);
- codec->pix_fmt = avio_rb32(pb);
- codec->qmin = avio_r8(pb);
- codec->qmax = avio_r8(pb);
- codec->max_qdiff = avio_r8(pb);
- codec->qcompress = avio_rb16(pb) / 10000.0;
- codec->qblur = avio_rb16(pb) / 10000.0;
- codec->bit_rate_tolerance = avio_rb32(pb);
- avio_get_str(pb, INT_MAX, rc_eq_buf, sizeof(rc_eq_buf));
- codec->rc_eq = av_strdup(rc_eq_buf);
- codec->rc_max_rate = avio_rb32(pb);
- codec->rc_min_rate = avio_rb32(pb);
- codec->rc_buffer_size = avio_rb32(pb);
- codec->i_quant_factor = av_int2double(avio_rb64(pb));
- codec->b_quant_factor = av_int2double(avio_rb64(pb));
- codec->i_quant_offset = av_int2double(avio_rb64(pb));
- codec->b_quant_offset = av_int2double(avio_rb64(pb));
- codec->dct_algo = avio_rb32(pb);
- codec->strict_std_compliance = avio_rb32(pb);
- codec->max_b_frames = avio_rb32(pb);
- codec->mpeg_quant = avio_rb32(pb);
- codec->intra_dc_precision = avio_rb32(pb);
- codec->me_method = avio_rb32(pb);
- codec->mb_decision = avio_rb32(pb);
- codec->nsse_weight = avio_rb32(pb);
- codec->frame_skip_cmp = avio_rb32(pb);
- codec->rc_buffer_aggressivity = av_int2double(avio_rb64(pb));
- codec->codec_tag = avio_rb32(pb);
- codec->thread_count = avio_r8(pb);
- codec->coder_type = avio_rb32(pb);
- codec->me_cmp = avio_rb32(pb);
- codec->me_subpel_quality = avio_rb32(pb);
- codec->me_range = avio_rb32(pb);
- codec->keyint_min = avio_rb32(pb);
- codec->scenechange_threshold = avio_rb32(pb);
- codec->b_frame_strategy = avio_rb32(pb);
- codec->qcompress = av_int2double(avio_rb64(pb));
- codec->qblur = av_int2double(avio_rb64(pb));
- codec->max_qdiff = avio_rb32(pb);
- codec->refs = avio_rb32(pb);
- break;
- case AVMEDIA_TYPE_AUDIO:
- codec->sample_rate = avio_rb32(pb);
- codec->channels = avio_rl16(pb);
- codec->frame_size = avio_rl16(pb);
- break;
- default:
- goto fail;
- }
- if (codec->flags & CODEC_FLAG_GLOBAL_HEADER) {
- codec->extradata_size = avio_rb32(pb);
- codec->extradata = av_malloc(codec->extradata_size);
- if (!codec->extradata)
- return AVERROR(ENOMEM);
- avio_read(pb, codec->extradata, codec->extradata_size);
- }
- }
-
- /* get until end of block reached */
- while ((avio_tell(pb) % ffm->packet_size) != 0)
- avio_r8(pb);
-
- /* init packet demux */
- ffm->packet_ptr = ffm->packet;
- ffm->packet_end = ffm->packet;
- ffm->frame_offset = 0;
- ffm->dts = 0;
- ffm->read_state = READ_HEADER;
- ffm->first_packet = 1;
- return 0;
- fail:
- ffm_close(s);
- return -1;
-}
-
-/* return < 0 if eof */
-static int ffm_read_packet(AVFormatContext *s, AVPacket *pkt)
-{
- int size;
- FFMContext *ffm = s->priv_data;
- int duration, ret;
-
- switch(ffm->read_state) {
- case READ_HEADER:
- if ((ret = ffm_is_avail_data(s, FRAME_HEADER_SIZE+4)) < 0)
- return ret;
-
- av_dlog(s, "pos=%08"PRIx64" spos=%"PRIx64", write_index=%"PRIx64" size=%"PRIx64"\n",
- avio_tell(s->pb), s->pb->pos, ffm->write_index, ffm->file_size);
- if (ffm_read_data(s, ffm->header, FRAME_HEADER_SIZE, 1) !=
- FRAME_HEADER_SIZE)
- return -1;
- if (ffm->header[1] & FLAG_DTS)
- if (ffm_read_data(s, ffm->header+16, 4, 1) != 4)
- return -1;
- ffm->read_state = READ_DATA;
- /* fall thru */
- case READ_DATA:
- size = AV_RB24(ffm->header + 2);
- if ((ret = ffm_is_avail_data(s, size)) < 0)
- return ret;
-
- duration = AV_RB24(ffm->header + 5);
-
- av_new_packet(pkt, size);
- pkt->stream_index = ffm->header[0];
- if ((unsigned)pkt->stream_index >= s->nb_streams) {
- av_log(s, AV_LOG_ERROR, "invalid stream index %d\n", pkt->stream_index);
- av_free_packet(pkt);
- ffm->read_state = READ_HEADER;
- return -1;
- }
- pkt->pos = avio_tell(s->pb);
- if (ffm->header[1] & FLAG_KEY_FRAME)
- pkt->flags |= AV_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 -1;
- }
- pkt->pts = AV_RB64(ffm->header+8);
- if (ffm->header[1] & FLAG_DTS)
- pkt->dts = pkt->pts - AV_RB32(ffm->header+16);
- else
- pkt->dts = pkt->pts;
- pkt->duration = duration;
- break;
- }
- return 0;
-}
-
-/* seek to a given time in the file. The file read pointer is
- positioned at or before pts. XXX: the following code is quite
- approximative */
-static int ffm_seek(AVFormatContext *s, int stream_index, int64_t wanted_pts, int flags)
-{
- FFMContext *ffm = s->priv_data;
- int64_t pos_min, pos_max, pos;
- int64_t pts_min, pts_max, pts;
- double pos1;
-
- av_dlog(s, "wanted_pts=%0.6f\n", wanted_pts / 1000000.0);
- /* find the position using linear interpolation (better than
- dichotomy in typical cases) */
- pos_min = FFM_PACKET_SIZE;
- pos_max = ffm->file_size - FFM_PACKET_SIZE;
- while (pos_min <= pos_max) {
- pts_min = get_dts(s, pos_min);
- pts_max = get_dts(s, pos_max);
- /* linear interpolation */
- pos1 = (double)(pos_max - pos_min) * (double)(wanted_pts - pts_min) /
- (double)(pts_max - pts_min);
- pos = (((int64_t)pos1) / FFM_PACKET_SIZE) * FFM_PACKET_SIZE;
- if (pos <= pos_min)
- pos = pos_min;
- else if (pos >= pos_max)
- pos = pos_max;
- pts = get_dts(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 = (flags & AVSEEK_FLAG_BACKWARD) ? pos_min : pos_max;
-
- found:
- if (ffm_seek1(s, pos) < 0)
- return -1;
-
- /* reset read state */
- ffm->read_state = READ_HEADER;
- ffm->packet_ptr = ffm->packet;
- ffm->packet_end = ffm->packet;
- ffm->first_packet = 1;
-
- return 0;
-}
-
-static int ffm_probe(AVProbeData *p)
-{
- if (
- p->buf[0] == 'F' && p->buf[1] == 'F' && p->buf[2] == 'M' &&
- p->buf[3] == '1')
- return AVPROBE_SCORE_MAX + 1;
- return 0;
-}
-
-AVInputFormat ff_ffm_demuxer = {
- .name = "ffm",
- .long_name = NULL_IF_CONFIG_SMALL("FFM (AVserver live feed)"),
- .priv_data_size = sizeof(FFMContext),
- .read_probe = ffm_probe,
- .read_header = ffm_read_header,
- .read_packet = ffm_read_packet,
- .read_close = ffm_close,
- .read_seek = ffm_seek,
-};
diff --git a/libavformat/ffmenc.c b/libavformat/ffmenc.c
deleted file mode 100644
index 91658e12dd..0000000000
--- a/libavformat/ffmenc.c
+++ /dev/null
@@ -1,249 +0,0 @@
-/*
- * FFM (avserver live feed) muxer
- * Copyright (c) 2001 Fabrice Bellard
- *
- * This file is part of Libav.
- *
- * Libav 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.1 of the License, or (at your option) any later version.
- *
- * Libav 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 Libav; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- */
-
-#include <assert.h>
-
-#include "libavutil/intreadwrite.h"
-#include "libavutil/intfloat.h"
-#include "avformat.h"
-#include "internal.h"
-#include "ffm.h"
-
-static void flush_packet(AVFormatContext *s)
-{
- FFMContext *ffm = s->priv_data;
- int fill_size, h;
- AVIOContext *pb = s->pb;
-
- fill_size = ffm->packet_end - ffm->packet_ptr;
- memset(ffm->packet_ptr, 0, fill_size);
-
- assert(avio_tell(pb) % ffm->packet_size == 0);
-
- /* put header */
- avio_wb16(pb, PACKET_ID);
- avio_wb16(pb, fill_size);
- avio_wb64(pb, ffm->dts);
- h = ffm->frame_offset;
- if (ffm->first_packet)
- h |= 0x8000;
- avio_wb16(pb, h);
- avio_write(pb, ffm->packet, ffm->packet_end - ffm->packet);
- avio_flush(pb);
-
- /* prepare next packet */
- ffm->frame_offset = 0; /* no key frame */
- 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,
- const uint8_t *buf, int size,
- int64_t dts, int header)
-{
- FFMContext *ffm = s->priv_data;
- int len;
-
- if (header && ffm->frame_offset == 0) {
- ffm->frame_offset = ffm->packet_ptr - ffm->packet + FFM_HEADER_SIZE;
- ffm->dts = dts;
- }
-
- /* 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)
- flush_packet(s);
- }
-}
-
-static int ffm_write_header(AVFormatContext *s)
-{
- FFMContext *ffm = s->priv_data;
- AVStream *st;
- AVIOContext *pb = s->pb;
- AVCodecContext *codec;
- int bit_rate, i;
-
- ffm->packet_size = FFM_PACKET_SIZE;
-
- /* header */
- avio_wl32(pb, MKTAG('F', 'F', 'M', '1'));
- avio_wb32(pb, ffm->packet_size);
- avio_wb64(pb, 0); /* current write position */
-
- avio_wb32(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;
- }
- avio_wb32(pb, bit_rate);
-
- /* list of streams */
- for(i=0;i<s->nb_streams;i++) {
- st = s->streams[i];
- avpriv_set_pts_info(st, 64, 1, 1000000);
-
- codec = st->codec;
- /* generic info */
- avio_wb32(pb, codec->codec_id);
- avio_w8(pb, codec->codec_type);
- avio_wb32(pb, codec->bit_rate);
- avio_wb32(pb, codec->flags);
- avio_wb32(pb, codec->flags2);
- avio_wb32(pb, codec->debug);
- /* specific info */
- switch(codec->codec_type) {
- case AVMEDIA_TYPE_VIDEO:
- avio_wb32(pb, codec->time_base.num);
- avio_wb32(pb, codec->time_base.den);
- avio_wb16(pb, codec->width);
- avio_wb16(pb, codec->height);
- avio_wb16(pb, codec->gop_size);
- avio_wb32(pb, codec->pix_fmt);
- avio_w8(pb, codec->qmin);
- avio_w8(pb, codec->qmax);
- avio_w8(pb, codec->max_qdiff);
- avio_wb16(pb, (int) (codec->qcompress * 10000.0));
- avio_wb16(pb, (int) (codec->qblur * 10000.0));
- avio_wb32(pb, codec->bit_rate_tolerance);
- avio_put_str(pb, codec->rc_eq ? codec->rc_eq : "tex^qComp");
- avio_wb32(pb, codec->rc_max_rate);
- avio_wb32(pb, codec->rc_min_rate);
- avio_wb32(pb, codec->rc_buffer_size);
- avio_wb64(pb, av_double2int(codec->i_quant_factor));
- avio_wb64(pb, av_double2int(codec->b_quant_factor));
- avio_wb64(pb, av_double2int(codec->i_quant_offset));
- avio_wb64(pb, av_double2int(codec->b_quant_offset));
- avio_wb32(pb, codec->dct_algo);
- avio_wb32(pb, codec->strict_std_compliance);
- avio_wb32(pb, codec->max_b_frames);
- avio_wb32(pb, codec->mpeg_quant);
- avio_wb32(pb, codec->intra_dc_precision);
- avio_wb32(pb, codec->me_method);
- avio_wb32(pb, codec->mb_decision);
- avio_wb32(pb, codec->nsse_weight);
- avio_wb32(pb, codec->frame_skip_cmp);
- avio_wb64(pb, av_double2int(codec->rc_buffer_aggressivity));
- avio_wb32(pb, codec->codec_tag);
- avio_w8(pb, codec->thread_count);
- avio_wb32(pb, codec->coder_type);
- avio_wb32(pb, codec->me_cmp);
- avio_wb32(pb, codec->me_subpel_quality);
- avio_wb32(pb, codec->me_range);
- avio_wb32(pb, codec->keyint_min);
- avio_wb32(pb, codec->scenechange_threshold);
- avio_wb32(pb, codec->b_frame_strategy);
- avio_wb64(pb, av_double2int(codec->qcompress));
- avio_wb64(pb, av_double2int(codec->qblur));
- avio_wb32(pb, codec->max_qdiff);
- avio_wb32(pb, codec->refs);
- break;
- case AVMEDIA_TYPE_AUDIO:
- avio_wb32(pb, codec->sample_rate);
- avio_wl16(pb, codec->channels);
- avio_wl16(pb, codec->frame_size);
- break;
- default:
- return -1;
- }
- if (codec->flags & CODEC_FLAG_GLOBAL_HEADER) {
- avio_wb32(pb, codec->extradata_size);
- avio_write(pb, codec->extradata, codec->extradata_size);
- }
- }
-
- /* flush until end of block reached */
- while ((avio_tell(pb) % ffm->packet_size) != 0)
- avio_w8(pb, 0);
-
- avio_flush(pb);
-
- /* init packet mux */
- ffm->packet_ptr = ffm->packet;
- ffm->packet_end = ffm->packet + ffm->packet_size - FFM_HEADER_SIZE;
- assert(ffm->packet_end >= ffm->packet);
- ffm->frame_offset = 0;
- ffm->dts = 0;
- ffm->first_packet = 1;
-
- return 0;
-}
-
-static int ffm_write_packet(AVFormatContext *s, AVPacket *pkt)
-{
- int64_t dts;
- uint8_t header[FRAME_HEADER_SIZE+4];
- int header_size = FRAME_HEADER_SIZE;
-
- dts = pkt->dts;
- /* packet size & key_frame */
- header[0] = pkt->stream_index;
- header[1] = 0;
- if (pkt->flags & AV_PKT_FLAG_KEY)
- header[1] |= FLAG_KEY_FRAME;
- AV_WB24(header+2, pkt->size);
- AV_WB24(header+5, pkt->duration);
- AV_WB64(header+8, pkt->pts);
- if (pkt->pts != pkt->dts) {
- header[1] |= FLAG_DTS;
- AV_WB32(header+16, pkt->pts - pkt->dts);
- header_size += 4;
- }
- ffm_write_data(s, header, header_size, dts, 1);
- ffm_write_data(s, pkt->data, pkt->size, dts, 0);
-
- return 0;
-}
-
-static int ffm_write_trailer(AVFormatContext *s)
-{
- FFMContext *ffm = s->priv_data;
-
- /* flush packets */
- if (ffm->packet_ptr > ffm->packet)
- flush_packet(s);
-
- return 0;
-}
-
-AVOutputFormat ff_ffm_muxer = {
- .name = "ffm",
- .long_name = NULL_IF_CONFIG_SMALL("FFM (AVserver live feed)"),
- .mime_type = "",
- .extensions = "ffm",
- .priv_data_size = sizeof(FFMContext),
- .audio_codec = AV_CODEC_ID_MP2,
- .video_codec = AV_CODEC_ID_MPEG1VIDEO,
- .write_header = ffm_write_header,
- .write_packet = ffm_write_packet,
- .write_trailer = ffm_write_trailer,
- .flags = AVFMT_TS_NEGATIVE,
-};