aboutsummaryrefslogtreecommitdiffstats
path: root/libavformat
diff options
context:
space:
mode:
authorMichael Niedermayer <michaelni@gmx.at>2012-03-21 00:15:18 +0100
committerMichael Niedermayer <michaelni@gmx.at>2012-03-21 01:33:53 +0100
commit0ebd83617fe008b7e9766f659cc3d9618b2d80d2 (patch)
tree23bc388bf6b66cf58d7a90c0d2529e53ed984561 /libavformat
parent745a33a44318ad6d6f74835a417397cdd9dda9a9 (diff)
parentc9594fe0fb6dd123fa25cb27fe5bc976ff3a9051 (diff)
downloadffmpeg-0ebd83617fe008b7e9766f659cc3d9618b2d80d2.tar.gz
Merge remote-tracking branch 'qatar/master'
* qatar/master: (27 commits) avconv: free packet in write_frame() when discarding due to frame number limit FATE: use +/- flag option syntax for vp8 emu-edge tests lavf: make av_interleave_packet_per_dts() private. lavf: deprecate av_read_packet(). oggdec: output correct timestamps for Vorbis avconv: pass input stream timestamps to audio encoders lavc: shrink encoded audio packet size after encoding. xa: set correct bit rate xa: do not set bit_rate, block_align, or bits_per_coded_sample xa: fix end-of-file handling xa: fix timestamp calculation bink: fix typo in FFALIGN() argument bink: align plane width to 8 when calculating bundle sizes doc: pass -Idoc texi2html and texi2pod doc: texi2pod: add -I flag movenc: Add a min_frag_duration option rtsp: Set the default delay to 0.1 s for the RTSP/SDP/RTP demuxers libavformat: Set the default for the max_delay option to -1 Generate manpages for AV{Format,Codec}Context AVOptions. doc/avconv: remove entries for AVOptions. ... Conflicts: doc/Makefile doc/ffmpeg.texi doc/muxers.texi ffmpeg.c libavcodec/Makefile libavcodec/options.c libavcodec/vp8.c libavformat/options.c tests/fate/demux.mak tests/ref/fate/truemotion1-15 tests/ref/fate/truemotion1-24 Merged-by: Michael Niedermayer <michaelni@gmx.at>
Diffstat (limited to 'libavformat')
-rw-r--r--libavformat/avformat.h24
-rw-r--r--libavformat/avidec.c6
-rw-r--r--libavformat/gxfenc.c2
-rw-r--r--libavformat/id3v2.c1
-rw-r--r--libavformat/internal.h27
-rw-r--r--libavformat/movenc.c15
-rw-r--r--libavformat/movenc.h1
-rw-r--r--libavformat/mpegenc.c2
-rw-r--r--libavformat/mpegtsenc.c3
-rw-r--r--libavformat/oggparsevorbis.c83
-rw-r--r--libavformat/options.c50
-rw-r--r--libavformat/options_table.h73
-rw-r--r--libavformat/rtpdec_asf.c2
-rw-r--r--libavformat/rtpenc.c2
-rw-r--r--libavformat/rtsp.c7
-rw-r--r--libavformat/utils.c72
-rw-r--r--libavformat/version.h6
-rw-r--r--libavformat/xa.c20
18 files changed, 296 insertions, 100 deletions
diff --git a/libavformat/avformat.h b/libavformat/avformat.h
index 6fa1216ff1..e49e475e55 100644
--- a/libavformat/avformat.h
+++ b/libavformat/avformat.h
@@ -1332,7 +1332,11 @@ int av_find_best_stream(AVFormatContext *ic,
AVCodec **decoder_ret,
int flags);
+#if FF_API_READ_PACKET
/**
+ * @deprecated use AVFMT_FLAG_NOFILLIN | AVFMT_FLAG_NOPARSE to read raw
+ * unprocessed packets
+ *
* Read a transport packet from a media file.
*
* This function is obsolete and should never be used.
@@ -1342,7 +1346,9 @@ int av_find_best_stream(AVFormatContext *ic,
* @param pkt is filled
* @return 0 if OK, AVERROR_xxx on error
*/
+attribute_deprecated
int av_read_packet(AVFormatContext *s, AVPacket *pkt);
+#endif
/**
* Return the next frame of a stream.
@@ -1539,23 +1545,15 @@ int av_write_frame(AVFormatContext *s, AVPacket *pkt);
*/
int av_interleaved_write_frame(AVFormatContext *s, AVPacket *pkt);
+#if FF_API_INTERLEAVE_PACKET
/**
- * Interleave a packet per dts in an output media file.
- *
- * Packets with pkt->destruct == av_destruct_packet will be freed inside this
- * function, so they cannot be used after it. Note that calling av_free_packet()
- * on them is still safe.
- *
- * @param s media file handle
- * @param out the interleaved packet will be output here
- * @param pkt the input packet
- * @param flush 1 if no further packets are available as input and all
- * remaining packets should be output
- * @return 1 if a packet was output, 0 if no packet could be output,
- * < 0 if an error occurred
+ * @deprecated this function was never meant to be called by the user
+ * programs.
*/
+attribute_deprecated
int av_interleave_packet_per_dts(AVFormatContext *s, AVPacket *out,
AVPacket *pkt, int flush);
+#endif
/**
* Write the stream trailer to an output media file and free the
diff --git a/libavformat/avidec.c b/libavformat/avidec.c
index efa1bb5daf..9607828e42 100644
--- a/libavformat/avidec.c
+++ b/libavformat/avidec.c
@@ -838,7 +838,7 @@ static int read_gab2_sub(AVStream *st, AVPacket *pkt) {
ast->sub_ctx->pb = pb;
if (!avformat_open_input(&ast->sub_ctx, "", sub_demuxer, NULL)) {
- av_read_packet(ast->sub_ctx, &ast->sub_pkt);
+ ff_read_packet(ast->sub_ctx, &ast->sub_pkt);
*st->codec = *ast->sub_ctx->streams[0]->codec;
ast->sub_ctx->streams[0]->codec->extradata = NULL;
time_base = ast->sub_ctx->streams[0]->time_base;
@@ -880,7 +880,7 @@ static AVStream *get_subtitle_pkt(AVFormatContext *s, AVStream *next_st,
ast = sub_st->priv_data;
*pkt = ast->sub_pkt;
pkt->stream_index = sub_st->index;
- if (av_read_packet(ast->sub_ctx, &ast->sub_pkt) < 0)
+ if (ff_read_packet(ast->sub_ctx, &ast->sub_pkt) < 0)
ast->sub_pkt.data = NULL;
}
return sub_st;
@@ -1364,7 +1364,7 @@ static void seek_subtitle(AVStream *st, AVStream *st2, int64_t timestamp)
av_free_packet(&ast2->sub_pkt);
if (avformat_seek_file(ast2->sub_ctx, 0, INT64_MIN, ts2, ts2, 0) >= 0 ||
avformat_seek_file(ast2->sub_ctx, 0, ts2, ts2, INT64_MAX, 0) >= 0)
- av_read_packet(ast2->sub_ctx, &ast2->sub_pkt);
+ ff_read_packet(ast2->sub_ctx, &ast2->sub_pkt);
}
static int avi_read_seek(AVFormatContext *s, int stream_index, int64_t timestamp, int flags)
diff --git a/libavformat/gxfenc.c b/libavformat/gxfenc.c
index ef2fcbe42f..ffffa8bafd 100644
--- a/libavformat/gxfenc.c
+++ b/libavformat/gxfenc.c
@@ -991,7 +991,7 @@ static int gxf_interleave_packet(AVFormatContext *s, AVPacket *out, AVPacket *pk
if (pkt && s->streams[pkt->stream_index]->codec->codec_type == AVMEDIA_TYPE_VIDEO)
pkt->duration = 2; // enforce 2 fields
return ff_audio_rechunk_interleave(s, out, pkt, flush,
- av_interleave_packet_per_dts, gxf_compare_field_nb);
+ ff_interleave_packet_per_dts, gxf_compare_field_nb);
}
static const AVOption options[] = {
diff --git a/libavformat/id3v2.c b/libavformat/id3v2.c
index f14b13e92f..9ccd6e7b48 100644
--- a/libavformat/id3v2.c
+++ b/libavformat/id3v2.c
@@ -803,6 +803,7 @@ int ff_id3v2_parse_apic(AVFormatContext *s, ID3v2ExtraMeta **extra_meta)
st->attached_pic.size = apic->len;
st->attached_pic.destruct = av_destruct_packet;
st->attached_pic.stream_index = st->index;
+ st->attached_pic.flags |= AV_PKT_FLAG_KEY;
apic->data = NULL;
apic->len = 0;
diff --git a/libavformat/internal.h b/libavformat/internal.h
index 8bc34bdb9a..6007ecfead 100644
--- a/libavformat/internal.h
+++ b/libavformat/internal.h
@@ -317,4 +317,31 @@ int ff_add_param_change(AVPacket *pkt, int32_t channels,
*/
int ff_framehash_write_header(AVFormatContext *s);
+/**
+ * Read a transport packet from a media file.
+ *
+ * @param s media file handle
+ * @param pkt is filled
+ * @return 0 if OK, AVERROR_xxx on error
+ */
+int ff_read_packet(AVFormatContext *s, AVPacket *pkt);
+
+/**
+ * Interleave a packet per dts in an output media file.
+ *
+ * Packets with pkt->destruct == av_destruct_packet will be freed inside this
+ * function, so they cannot be used after it. Note that calling av_free_packet()
+ * on them is still safe.
+ *
+ * @param s media file handle
+ * @param out the interleaved packet will be output here
+ * @param pkt the input packet
+ * @param flush 1 if no further packets are available as input and all
+ * remaining packets should be output
+ * @return 1 if a packet was output, 0 if no packet could be output,
+ * < 0 if an error occurred
+ */
+int ff_interleave_packet_per_dts(AVFormatContext *s, AVPacket *out,
+ AVPacket *pkt, int flush);
+
#endif /* AVFORMAT_INTERNAL_H */
diff --git a/libavformat/movenc.c b/libavformat/movenc.c
index 7f970be35f..0b4ccbf257 100644
--- a/libavformat/movenc.c
+++ b/libavformat/movenc.c
@@ -57,6 +57,7 @@ static const AVOption options[] = {
{ "iods_audio_profile", "iods audio profile atom.", offsetof(MOVMuxContext, iods_audio_profile), AV_OPT_TYPE_INT, {.dbl = -1}, -1, 255, AV_OPT_FLAG_ENCODING_PARAM},
{ "iods_video_profile", "iods video profile atom.", offsetof(MOVMuxContext, iods_video_profile), AV_OPT_TYPE_INT, {.dbl = -1}, -1, 255, AV_OPT_FLAG_ENCODING_PARAM},
{ "frag_duration", "Maximum fragment duration", offsetof(MOVMuxContext, max_fragment_duration), AV_OPT_TYPE_INT, {.dbl = 0}, 0, INT_MAX, AV_OPT_FLAG_ENCODING_PARAM},
+ { "min_frag_duration", "Minimum fragment duration", offsetof(MOVMuxContext, min_fragment_duration), AV_OPT_TYPE_INT, {.dbl = 0}, 0, INT_MAX, AV_OPT_FLAG_ENCODING_PARAM},
{ "frag_size", "Maximum fragment size", offsetof(MOVMuxContext, max_fragment_size), AV_OPT_TYPE_INT, {.dbl = 0}, 0, INT_MAX, AV_OPT_FLAG_ENCODING_PARAM},
{ "ism_lookahead", "Number of lookahead entries for ISM files", offsetof(MOVMuxContext, ism_lookahead), AV_OPT_TYPE_INT, {.dbl = 0}, 0, INT_MAX, AV_OPT_FLAG_ENCODING_PARAM},
{ NULL },
@@ -2893,21 +2894,25 @@ static int mov_write_packet_internal(AVFormatContext *s, AVPacket *pkt)
unsigned int samples_in_chunk = 0;
int size= pkt->size;
uint8_t *reformatted_data = NULL;
+ int64_t frag_duration = 0;
if (!s->pb->seekable && !(mov->flags & FF_MOV_FLAG_EMPTY_MOOV))
return 0; /* Can't handle that */
if (!size) return 0; /* Discard 0 sized packets */
- if ((mov->max_fragment_duration && trk->entry &&
- av_rescale_q(pkt->dts - trk->cluster[0].dts,
- s->streams[pkt->stream_index]->time_base,
- AV_TIME_BASE_Q) >= mov->max_fragment_duration) ||
+ if (trk->entry)
+ frag_duration = av_rescale_q(pkt->dts - trk->cluster[0].dts,
+ s->streams[pkt->stream_index]->time_base,
+ AV_TIME_BASE_Q);
+ if ((mov->max_fragment_duration &&
+ frag_duration >= mov->max_fragment_duration) ||
(mov->max_fragment_size && mov->mdat_size + size >= mov->max_fragment_size) ||
(mov->flags & FF_MOV_FLAG_FRAG_KEYFRAME &&
enc->codec_type == AVMEDIA_TYPE_VIDEO &&
trk->entry && pkt->flags & AV_PKT_FLAG_KEY)) {
- mov_flush_fragment(s);
+ if (frag_duration >= mov->min_fragment_duration)
+ mov_flush_fragment(s);
}
if (mov->flags & FF_MOV_FLAG_FRAGMENT) {
diff --git a/libavformat/movenc.h b/libavformat/movenc.h
index 4cf40f231d..574de824ef 100644
--- a/libavformat/movenc.h
+++ b/libavformat/movenc.h
@@ -154,6 +154,7 @@ typedef struct MOVMuxContext {
int fragments;
int max_fragment_duration;
+ int min_fragment_duration;
int max_fragment_size;
int ism_lookahead;
AVIOContext *mdat_buf;
diff --git a/libavformat/mpegenc.c b/libavformat/mpegenc.c
index 098e076016..0df0149911 100644
--- a/libavformat/mpegenc.c
+++ b/libavformat/mpegenc.c
@@ -318,6 +318,8 @@ static int mpeg_mux_init(AVFormatContext *ctx)
s->packet_size = ctx->packet_size;
} else
s->packet_size = 2048;
+ if (ctx->max_delay < 0) /* Not set by the caller */
+ ctx->max_delay = 0;
s->vcd_padding_bytes_written = 0;
s->vcd_padding_bitrate=0;
diff --git a/libavformat/mpegtsenc.c b/libavformat/mpegtsenc.c
index b0047a216e..c3b3d5d69f 100644
--- a/libavformat/mpegtsenc.c
+++ b/libavformat/mpegtsenc.c
@@ -491,6 +491,9 @@ static int mpegts_write_header(AVFormatContext *s)
const char *provider_name;
int *pids;
+ if (s->max_delay < 0) /* Not set by the caller */
+ s->max_delay = 0;
+
// round up to a whole number of TS packets
ts->pes_payload_size = (ts->pes_payload_size + 14 + 183) / 184 * 184 - 14;
diff --git a/libavformat/oggparsevorbis.c b/libavformat/oggparsevorbis.c
index b9d9f575e0..f72fd26c4c 100644
--- a/libavformat/oggparsevorbis.c
+++ b/libavformat/oggparsevorbis.c
@@ -28,6 +28,7 @@
#include "libavutil/dict.h"
#include "libavcodec/get_bits.h"
#include "libavcodec/bytestream.h"
+#include "libavcodec/vorbis_parser.h"
#include "avformat.h"
#include "internal.h"
#include "oggdec.h"
@@ -162,6 +163,9 @@ ff_vorbis_comment(AVFormatContext * as, AVDictionary **m, const uint8_t *buf, in
struct oggvorbis_private {
unsigned int len[3];
unsigned char *packet[3];
+ VorbisParseContext vp;
+ int64_t final_pts;
+ int final_duration;
};
@@ -251,7 +255,6 @@ vorbis_header (AVFormatContext * s, int idx)
st->codec->codec_type = AVMEDIA_TYPE_AUDIO;
st->codec->codec_id = CODEC_ID_VORBIS;
- st->need_parsing = AVSTREAM_PARSE_HEADERS;
if (srate > 0) {
st->codec->sample_rate = srate;
@@ -269,15 +272,91 @@ vorbis_header (AVFormatContext * s, int idx)
}
}
} else {
+ int ret;
st->codec->extradata_size =
fixup_vorbis_headers(s, priv, &st->codec->extradata);
+ if ((ret = avpriv_vorbis_parse_extradata(st->codec, &priv->vp))) {
+ av_freep(&st->codec->extradata);
+ st->codec->extradata_size = 0;
+ return ret;
+ }
}
return 1;
}
+static int vorbis_packet(AVFormatContext *s, int idx)
+{
+ struct ogg *ogg = s->priv_data;
+ struct ogg_stream *os = ogg->streams + idx;
+ struct oggvorbis_private *priv = os->private;
+ int duration;
+
+ /* first packet handling
+ here we parse the duration of each packet in the first page and compare
+ the total duration to the page granule to find the encoder delay and
+ set the first timestamp */
+ if (!os->lastpts) {
+ int seg;
+ uint8_t *last_pkt = os->buf + os->pstart;
+ uint8_t *next_pkt = last_pkt;
+ int first_duration = 0;
+
+ avpriv_vorbis_parse_reset(&priv->vp);
+ duration = 0;
+ for (seg = 0; seg < os->nsegs; seg++) {
+ if (os->segments[seg] < 255) {
+ int d = avpriv_vorbis_parse_frame(&priv->vp, last_pkt, 1);
+ if (d < 0) {
+ duration = os->granule;
+ break;
+ }
+ if (!duration)
+ first_duration = d;
+ duration += d;
+ last_pkt = next_pkt + os->segments[seg];
+ }
+ next_pkt += os->segments[seg];
+ }
+ os->lastpts = os->lastdts = os->granule - duration;
+ s->streams[idx]->start_time = os->lastpts + first_duration;
+ if (s->streams[idx]->duration)
+ s->streams[idx]->duration -= s->streams[idx]->start_time;
+ s->streams[idx]->cur_dts = AV_NOPTS_VALUE;
+ priv->final_pts = AV_NOPTS_VALUE;
+ avpriv_vorbis_parse_reset(&priv->vp);
+ }
+
+ /* parse packet duration */
+ if (os->psize > 0) {
+ duration = avpriv_vorbis_parse_frame(&priv->vp, os->buf + os->pstart, 1);
+ if (duration <= 0) {
+ os->pflags |= AV_PKT_FLAG_CORRUPT;
+ return 0;
+ }
+ os->pduration = duration;
+ }
+
+ /* final packet handling
+ here we save the pts of the first packet in the final page, sum up all
+ packet durations in the final page except for the last one, and compare
+ to the page granule to find the duration of the final packet */
+ if (os->flags & OGG_FLAG_EOS) {
+ if (os->lastpts != AV_NOPTS_VALUE) {
+ priv->final_pts = os->lastpts;
+ priv->final_duration = 0;
+ }
+ if (os->segp == os->nsegs)
+ os->pduration = os->granule - priv->final_pts - priv->final_duration;
+ priv->final_duration += os->pduration;
+ }
+
+ return 0;
+}
+
const struct ogg_codec ff_vorbis_codec = {
.magic = "\001vorbis",
.magicsize = 7,
- .header = vorbis_header
+ .header = vorbis_header,
+ .packet = vorbis_packet,
};
diff --git a/libavformat/options.c b/libavformat/options.c
index 490c765666..c3056376d2 100644
--- a/libavformat/options.c
+++ b/libavformat/options.c
@@ -26,6 +26,8 @@
* Options definition for AVFormatContext.
*/
+#include "options_table.h"
+
static const char* format_to_name(void* ptr)
{
AVFormatContext* fc = (AVFormatContext*) ptr;
@@ -74,54 +76,6 @@ static const AVClass *format_child_class_next(const AVClass *prev)
return NULL;
}
-#define OFFSET(x) offsetof(AVFormatContext,x)
-#define DEFAULT 0 //should be NAN but it does not work as it is not a constant in glibc as required by ANSI/ISO C
-//these names are too long to be readable
-#define E AV_OPT_FLAG_ENCODING_PARAM
-#define D AV_OPT_FLAG_DECODING_PARAM
-
-static const AVOption options[]={
-{"probesize", "set probing size", OFFSET(probesize), AV_OPT_TYPE_INT, {.dbl = 5000000 }, 32, INT_MAX, D},
-{"packetsize", "set packet size", OFFSET(packet_size), AV_OPT_TYPE_INT, {.dbl = DEFAULT }, 0, INT_MAX, E},
-{"fflags", NULL, OFFSET(flags), AV_OPT_TYPE_FLAGS, {.dbl = DEFAULT }, INT_MIN, INT_MAX, D|E, "fflags"},
-{"ignidx", "ignore index", 0, AV_OPT_TYPE_CONST, {.dbl = AVFMT_FLAG_IGNIDX }, INT_MIN, INT_MAX, D, "fflags"},
-{"genpts", "generate pts", 0, AV_OPT_TYPE_CONST, {.dbl = AVFMT_FLAG_GENPTS }, INT_MIN, INT_MAX, D, "fflags"},
-{"nofillin", "do not fill in missing values that can be exactly calculated", 0, AV_OPT_TYPE_CONST, {.dbl = AVFMT_FLAG_NOFILLIN }, INT_MIN, INT_MAX, D, "fflags"},
-{"noparse", "disable AVParsers, this needs nofillin too", 0, AV_OPT_TYPE_CONST, {.dbl = AVFMT_FLAG_NOPARSE }, INT_MIN, INT_MAX, D, "fflags"},
-{"igndts", "ignore dts", 0, AV_OPT_TYPE_CONST, {.dbl = AVFMT_FLAG_IGNDTS }, INT_MIN, INT_MAX, D, "fflags"},
-{"discardcorrupt", "discard corrupted frames", 0, AV_OPT_TYPE_CONST, {.dbl = AVFMT_FLAG_DISCARD_CORRUPT }, INT_MIN, INT_MAX, D, "fflags"},
-{"sortdts", "try to interleave outputted packets by dts", 0, AV_OPT_TYPE_CONST, {.dbl = AVFMT_FLAG_SORT_DTS }, INT_MIN, INT_MAX, D, "fflags"},
-{"keepside", "dont merge side data", 0, AV_OPT_TYPE_CONST, {.dbl = AVFMT_FLAG_KEEP_SIDE_DATA }, INT_MIN, INT_MAX, D, "fflags"},
-{"latm", "enable RTP MP4A-LATM payload", 0, AV_OPT_TYPE_CONST, {.dbl = AVFMT_FLAG_MP4A_LATM }, INT_MIN, INT_MAX, E, "fflags"},
-{"analyzeduration", "how many microseconds are analyzed to estimate duration", OFFSET(max_analyze_duration), AV_OPT_TYPE_INT, {.dbl = 5*AV_TIME_BASE }, 0, INT_MAX, D},
-{"cryptokey", "decryption key", OFFSET(key), AV_OPT_TYPE_BINARY, {.dbl = 0}, 0, 0, D},
-{"indexmem", "max memory used for timestamp index (per stream)", OFFSET(max_index_size), AV_OPT_TYPE_INT, {.dbl = 1<<20 }, 0, INT_MAX, D},
-{"rtbufsize", "max memory used for buffering real-time frames", OFFSET(max_picture_buffer), AV_OPT_TYPE_INT, {.dbl = 3041280 }, 0, INT_MAX, D}, /* defaults to 1s of 15fps 352x288 YUYV422 video */
-{"fdebug", "print specific debug info", OFFSET(debug), AV_OPT_TYPE_FLAGS, {.dbl = DEFAULT }, 0, INT_MAX, E|D, "fdebug"},
-{"ts", NULL, 0, AV_OPT_TYPE_CONST, {.dbl = FF_FDEBUG_TS }, INT_MIN, INT_MAX, E|D, "fdebug"},
-{"max_delay", "maximum muxing or demuxing delay in microseconds", OFFSET(max_delay), AV_OPT_TYPE_INT, {.dbl = DEFAULT }, 0, INT_MAX, E|D},
-{"fpsprobesize", "number of frames used to probe fps", OFFSET(fps_probe_size), AV_OPT_TYPE_INT, {.dbl = -1}, -1, INT_MAX-1, D},
-{"audio_preload", "microseconds by which audio packets should be interleaved earlier", OFFSET(audio_preload), AV_OPT_TYPE_INT, {.dbl = 0}, 0, INT_MAX-1, E},
-{"chunk_duration", "microseconds for each chunk", OFFSET(max_chunk_duration), AV_OPT_TYPE_INT, {.dbl = 0}, 0, INT_MAX-1, E},
-{"chunk_size", "size in bytes for each chunk", OFFSET(max_chunk_size), AV_OPT_TYPE_INT, {.dbl = 0}, 0, INT_MAX-1, E},
-/* this is a crutch for avconv, since it cannot deal with identically named options in different contexts.
- * to be removed when avconv is fixed */
-{"f_err_detect", "set error detection flags (deprecated; use err_detect, save via avconv)", OFFSET(error_recognition), AV_OPT_TYPE_FLAGS, {.dbl = AV_EF_CRCCHECK }, INT_MIN, INT_MAX, D, "err_detect"},
-{"err_detect", "set error detection flags", OFFSET(error_recognition), AV_OPT_TYPE_FLAGS, {.dbl = AV_EF_CRCCHECK }, INT_MIN, INT_MAX, D, "err_detect"},
-{"crccheck", "verify embedded CRCs", 0, AV_OPT_TYPE_CONST, {.dbl = AV_EF_CRCCHECK }, INT_MIN, INT_MAX, D, "err_detect"},
-{"bitstream", "detect bitstream specification deviations", 0, AV_OPT_TYPE_CONST, {.dbl = AV_EF_BITSTREAM }, INT_MIN, INT_MAX, D, "err_detect"},
-{"buffer", "detect improper bitstream length", 0, AV_OPT_TYPE_CONST, {.dbl = AV_EF_BUFFER }, INT_MIN, INT_MAX, D, "err_detect"},
-{"explode", "abort decoding on minor error detection", 0, AV_OPT_TYPE_CONST, {.dbl = AV_EF_EXPLODE }, INT_MIN, INT_MAX, D, "err_detect"},
-{"careful", "consider things that violate the spec and have not been seen in the wild as errors", 0, AV_OPT_TYPE_CONST, {.dbl = AV_EF_CAREFUL }, INT_MIN, INT_MAX, D, "err_detect"},
-{"compliant", "consider all spec non compliancies as errors", 0, AV_OPT_TYPE_CONST, {.dbl = AV_EF_COMPLIANT }, INT_MIN, INT_MAX, D, "err_detect"},
-{"aggressive", "consider things that a sane encoder shouldnt do as an error", 0, AV_OPT_TYPE_CONST, {.dbl = AV_EF_AGGRESSIVE }, INT_MIN, INT_MAX, D, "err_detect"},
-{NULL},
-};
-
-#undef E
-#undef D
-#undef DEFAULT
-
static const AVClass av_format_context_class = {
.class_name = "AVFormatContext",
.item_name = format_to_name,
diff --git a/libavformat/options_table.h b/libavformat/options_table.h
new file mode 100644
index 0000000000..0313839046
--- /dev/null
+++ b/libavformat/options_table.h
@@ -0,0 +1,73 @@
+/*
+ * Copyright (c) 2000, 2001, 2002 Fabrice Bellard
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg 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.
+ *
+ * FFmpeg 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 FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#ifndef AVFORMAT_OPTIONS_TABLE
+#define AVFORMAT_OPTIONS_TABLE
+
+#define OFFSET(x) offsetof(AVFormatContext,x)
+#define DEFAULT 0 //should be NAN but it does not work as it is not a constant in glibc as required by ANSI/ISO C
+//these names are too long to be readable
+#define E AV_OPT_FLAG_ENCODING_PARAM
+#define D AV_OPT_FLAG_DECODING_PARAM
+
+static const AVOption options[]={
+{"probesize", "set probing size", OFFSET(probesize), AV_OPT_TYPE_INT, {.dbl = 5000000 }, 32, INT_MAX, D},
+{"packetsize", "set packet size", OFFSET(packet_size), AV_OPT_TYPE_INT, {.dbl = DEFAULT }, 0, INT_MAX, E},
+{"fflags", NULL, OFFSET(flags), AV_OPT_TYPE_FLAGS, {.dbl = DEFAULT }, INT_MIN, INT_MAX, D|E, "fflags"},
+{"ignidx", "ignore index", 0, AV_OPT_TYPE_CONST, {.dbl = AVFMT_FLAG_IGNIDX }, INT_MIN, INT_MAX, D, "fflags"},
+{"genpts", "generate pts", 0, AV_OPT_TYPE_CONST, {.dbl = AVFMT_FLAG_GENPTS }, INT_MIN, INT_MAX, D, "fflags"},
+{"nofillin", "do not fill in missing values that can be exactly calculated", 0, AV_OPT_TYPE_CONST, {.dbl = AVFMT_FLAG_NOFILLIN }, INT_MIN, INT_MAX, D, "fflags"},
+{"noparse", "disable AVParsers, this needs nofillin too", 0, AV_OPT_TYPE_CONST, {.dbl = AVFMT_FLAG_NOPARSE }, INT_MIN, INT_MAX, D, "fflags"},
+{"igndts", "ignore dts", 0, AV_OPT_TYPE_CONST, {.dbl = AVFMT_FLAG_IGNDTS }, INT_MIN, INT_MAX, D, "fflags"},
+{"discardcorrupt", "discard corrupted frames", 0, AV_OPT_TYPE_CONST, {.dbl = AVFMT_FLAG_DISCARD_CORRUPT }, INT_MIN, INT_MAX, D, "fflags"},
+{"sortdts", "try to interleave outputted packets by dts", 0, AV_OPT_TYPE_CONST, {.dbl = AVFMT_FLAG_SORT_DTS }, INT_MIN, INT_MAX, D, "fflags"},
+{"keepside", "dont merge side data", 0, AV_OPT_TYPE_CONST, {.dbl = AVFMT_FLAG_KEEP_SIDE_DATA }, INT_MIN, INT_MAX, D, "fflags"},
+{"latm", "enable RTP MP4A-LATM payload", 0, AV_OPT_TYPE_CONST, {.dbl = AVFMT_FLAG_MP4A_LATM }, INT_MIN, INT_MAX, E, "fflags"},
+{"analyzeduration", "how many microseconds are analyzed to estimate duration", OFFSET(max_analyze_duration), AV_OPT_TYPE_INT, {.dbl = 5*AV_TIME_BASE }, 0, INT_MAX, D},
+{"cryptokey", "decryption key", OFFSET(key), AV_OPT_TYPE_BINARY, {.dbl = 0}, 0, 0, D},
+{"indexmem", "max memory used for timestamp index (per stream)", OFFSET(max_index_size), AV_OPT_TYPE_INT, {.dbl = 1<<20 }, 0, INT_MAX, D},
+{"rtbufsize", "max memory used for buffering real-time frames", OFFSET(max_picture_buffer), AV_OPT_TYPE_INT, {.dbl = 3041280 }, 0, INT_MAX, D}, /* defaults to 1s of 15fps 352x288 YUYV422 video */
+{"fdebug", "print specific debug info", OFFSET(debug), AV_OPT_TYPE_FLAGS, {.dbl = DEFAULT }, 0, INT_MAX, E|D, "fdebug"},
+{"ts", NULL, 0, AV_OPT_TYPE_CONST, {.dbl = FF_FDEBUG_TS }, INT_MIN, INT_MAX, E|D, "fdebug"},
+{"max_delay", "maximum muxing or demuxing delay in microseconds", OFFSET(max_delay), AV_OPT_TYPE_INT, {.dbl = -1 }, -1, INT_MAX, E|D},
+{"fpsprobesize", "number of frames used to probe fps", OFFSET(fps_probe_size), AV_OPT_TYPE_INT, {.dbl = -1}, -1, INT_MAX-1, D},
+{"audio_preload", "microseconds by which audio packets should be interleaved earlier", OFFSET(audio_preload), AV_OPT_TYPE_INT, {.dbl = 0}, 0, INT_MAX-1, E},
+{"chunk_duration", "microseconds for each chunk", OFFSET(max_chunk_duration), AV_OPT_TYPE_INT, {.dbl = 0}, 0, INT_MAX-1, E},
+{"chunk_size", "size in bytes for each chunk", OFFSET(max_chunk_size), AV_OPT_TYPE_INT, {.dbl = 0}, 0, INT_MAX-1, E},
+/* this is a crutch for avconv, since it cannot deal with identically named options in different contexts.
+ * to be removed when avconv is fixed */
+{"f_err_detect", "set error detection flags (deprecated; use err_detect, save via avconv)", OFFSET(error_recognition), AV_OPT_TYPE_FLAGS, {.dbl = AV_EF_CRCCHECK }, INT_MIN, INT_MAX, D, "err_detect"},
+{"err_detect", "set error detection flags", OFFSET(error_recognition), AV_OPT_TYPE_FLAGS, {.dbl = AV_EF_CRCCHECK }, INT_MIN, INT_MAX, D, "err_detect"},
+{"crccheck", "verify embedded CRCs", 0, AV_OPT_TYPE_CONST, {.dbl = AV_EF_CRCCHECK }, INT_MIN, INT_MAX, D, "err_detect"},
+{"bitstream", "detect bitstream specification deviations", 0, AV_OPT_TYPE_CONST, {.dbl = AV_EF_BITSTREAM }, INT_MIN, INT_MAX, D, "err_detect"},
+{"buffer", "detect improper bitstream length", 0, AV_OPT_TYPE_CONST, {.dbl = AV_EF_BUFFER }, INT_MIN, INT_MAX, D, "err_detect"},
+{"explode", "abort decoding on minor error detection", 0, AV_OPT_TYPE_CONST, {.dbl = AV_EF_EXPLODE }, INT_MIN, INT_MAX, D, "err_detect"},
+{"careful", "consider things that violate the spec and have not been seen in the wild as errors", 0, AV_OPT_TYPE_CONST, {.dbl = AV_EF_CAREFUL }, INT_MIN, INT_MAX, D, "err_detect"},
+{"compliant", "consider all spec non compliancies as errors", 0, AV_OPT_TYPE_CONST, {.dbl = AV_EF_COMPLIANT }, INT_MIN, INT_MAX, D, "err_detect"},
+{"aggressive", "consider things that a sane encoder shouldnt do as an error", 0, AV_OPT_TYPE_CONST, {.dbl = AV_EF_AGGRESSIVE }, INT_MIN, INT_MAX, D, "err_detect"},
+{NULL},
+};
+
+#undef E
+#undef D
+#undef DEFAULT
+#undef OFFSET
+
+#endif // AVFORMAT_OPTIONS_TABLE
diff --git a/libavformat/rtpdec_asf.c b/libavformat/rtpdec_asf.c
index e6586b036a..53c2bcef71 100644
--- a/libavformat/rtpdec_asf.c
+++ b/libavformat/rtpdec_asf.c
@@ -256,7 +256,7 @@ static int asfrtp_parse_packet(AVFormatContext *s, PayloadContext *asf,
for (;;) {
int i;
- res = av_read_packet(rt->asf_ctx, pkt);
+ res = ff_read_packet(rt->asf_ctx, pkt);
rt->asf_pb_pos = avio_tell(pb);
if (res != 0)
break;
diff --git a/libavformat/rtpenc.c b/libavformat/rtpenc.c
index 49da08b4e1..d7b6b3f124 100644
--- a/libavformat/rtpenc.c
+++ b/libavformat/rtpenc.c
@@ -126,7 +126,7 @@ static int rtp_write_header(AVFormatContext *s1)
s->max_payload_size = s1->packet_size - 12;
s->max_frames_per_packet = 0;
- if (s1->max_delay) {
+ if (s1->max_delay > 0) {
if (st->codec->codec_type == AVMEDIA_TYPE_AUDIO) {
int frame_size = av_get_audio_frame_duration(st->codec, 0);
if (!frame_size)
diff --git a/libavformat/rtsp.c b/libavformat/rtsp.c
index dd3f9226db..a6cfd3af4a 100644
--- a/libavformat/rtsp.c
+++ b/libavformat/rtsp.c
@@ -56,6 +56,7 @@
#define MAX_TIMEOUTS READ_PACKET_TIMEOUT_S * 1000 / POLL_TIMEOUT_MS
#define SDP_MAX_SIZE 16384
#define RECVBUF_SIZE 10 * RTP_MAX_PACKET_LENGTH
+#define DEFAULT_REORDERING_DELAY 100000
#define OFFSET(x) offsetof(RTSPState, x)
#define DEC AV_OPT_FLAG_DECODING_PARAM
@@ -1421,6 +1422,9 @@ int ff_rtsp_connect(AVFormatContext *s)
if (!ff_network_init())
return AVERROR(EIO);
+ if (s->max_delay < 0) /* Not set by the caller */
+ s->max_delay = s->iformat ? DEFAULT_REORDERING_DELAY : 0;
+
rt->control_transport = RTSP_MODE_PLAIN;
if (rt->lower_transport_mask & (1 << RTSP_LOWER_TRANSPORT_HTTP)) {
rt->lower_transport_mask = 1 << RTSP_LOWER_TRANSPORT_TCP;
@@ -1861,6 +1865,9 @@ static int sdp_read_header(AVFormatContext *s)
if (!ff_network_init())
return AVERROR(EIO);
+ if (s->max_delay < 0) /* Not set by the caller */
+ s->max_delay = DEFAULT_REORDERING_DELAY;
+
/* read the whole sdp file */
/* XXX: better loading */
content = av_malloc(SDP_MAX_SIZE);
diff --git a/libavformat/utils.c b/libavformat/utils.c
index fd973a8330..2921e85c8f 100644
--- a/libavformat/utils.c
+++ b/libavformat/utils.c
@@ -568,10 +568,22 @@ static AVPacket *add_to_pktbuf(AVPacketList **packet_buffer, AVPacket *pkt,
return &pktl->pkt;
}
+static void queue_attached_pictures(AVFormatContext *s)
+{
+ int i;
+ for (i = 0; i < s->nb_streams; i++)
+ if (s->streams[i]->disposition & AV_DISPOSITION_ATTACHED_PIC &&
+ s->streams[i]->discard < AVDISCARD_ALL) {
+ AVPacket copy = s->streams[i]->attached_pic;
+ copy.destruct = NULL;
+ add_to_pktbuf(&s->raw_packet_buffer, &copy, &s->raw_packet_buffer_end);
+ }
+}
+
int avformat_open_input(AVFormatContext **ps, const char *filename, AVInputFormat *fmt, AVDictionary **options)
{
AVFormatContext *s = *ps;
- int i, ret = 0;
+ int ret = 0;
AVDictionary *tmp = NULL;
ID3v2ExtraMeta *id3v2_extra_meta = NULL;
@@ -627,13 +639,7 @@ int avformat_open_input(AVFormatContext **ps, const char *filename, AVInputForma
goto fail;
ff_id3v2_free_extra_meta(&id3v2_extra_meta);
- /* queue attached pictures */
- for (i = 0; i < s->nb_streams; i++)
- if (s->streams[i]->disposition & AV_DISPOSITION_ATTACHED_PIC) {
- AVPacket copy = s->streams[i]->attached_pic;
- copy.destruct = NULL;
- add_to_pktbuf(&s->raw_packet_buffer, &copy, &s->raw_packet_buffer_end);
- }
+ queue_attached_pictures(s);
if (!(s->flags&AVFMT_FLAG_PRIV_OPT) && s->pb && !s->data_offset)
s->data_offset = avio_tell(s->pb);
@@ -659,7 +665,7 @@ fail:
/*******************************************************/
-int av_read_packet(AVFormatContext *s, AVPacket *pkt)
+int ff_read_packet(AVFormatContext *s, AVPacket *pkt)
{
int ret, i;
AVStream *st;
@@ -756,6 +762,14 @@ int av_read_packet(AVFormatContext *s, AVPacket *pkt)
}
}
+#if FF_API_READ_PACKET
+int av_read_packet(AVFormatContext *s, AVPacket *pkt)
+{
+ return ff_read_packet(s, pkt);
+}
+#endif
+
+
/**********************************************************/
static int determinable_frame_size(AVCodecContext *avctx)
@@ -1228,7 +1242,7 @@ static int read_frame_internal(AVFormatContext *s, AVPacket *pkt)
AVPacket cur_pkt;
/* read next packet */
- ret = av_read_packet(s, &cur_pkt);
+ ret = ff_read_packet(s, &cur_pkt);
if (ret < 0) {
if (ret == AVERROR(EAGAIN))
return ret;
@@ -1255,7 +1269,7 @@ static int read_frame_internal(AVFormatContext *s, AVPacket *pkt)
cur_pkt.size);
}
if (s->debug & FF_FDEBUG_TS)
- av_log(s, AV_LOG_DEBUG, "av_read_packet stream=%d, pts=%"PRId64", dts=%"PRId64", size=%d, duration=%d, flags=%d\n",
+ av_log(s, AV_LOG_DEBUG, "ff_read_packet stream=%d, pts=%"PRId64", dts=%"PRId64", size=%d, duration=%d, flags=%d\n",
cur_pkt.stream_index,
cur_pkt.pts,
cur_pkt.dts,
@@ -1827,7 +1841,8 @@ static int seek_frame_generic(AVFormatContext *s,
return 0;
}
-int av_seek_frame(AVFormatContext *s, int stream_index, int64_t timestamp, int flags)
+static int seek_frame_internal(AVFormatContext *s, int stream_index,
+ int64_t timestamp, int flags)
{
int ret;
AVStream *st;
@@ -1872,14 +1887,29 @@ int av_seek_frame(AVFormatContext *s, int stream_index, int64_t timestamp, int f
return -1;
}
+int av_seek_frame(AVFormatContext *s, int stream_index, int64_t timestamp, int flags)
+{
+ int ret = seek_frame_internal(s, stream_index, timestamp, flags);
+
+ if (ret >= 0)
+ queue_attached_pictures(s);
+
+ return ret;
+}
+
int avformat_seek_file(AVFormatContext *s, int stream_index, int64_t min_ts, int64_t ts, int64_t max_ts, int flags)
{
if(min_ts > ts || max_ts < ts)
return -1;
if (s->iformat->read_seek2) {
+ int ret;
ff_read_frame_flush(s);
- return s->iformat->read_seek2(s, stream_index, min_ts, ts, max_ts, flags);
+ ret = s->iformat->read_seek2(s, stream_index, min_ts, ts, max_ts, flags);
+
+ if (ret >= 0)
+ queue_attached_pictures(s);
+ return ret;
}
if(s->iformat->read_timestamp){
@@ -2071,7 +2101,7 @@ static void estimate_timings_from_pts(AVFormatContext *ic, int64_t old_offset)
break;
do {
- ret = av_read_packet(ic, pkt);
+ ret = ff_read_packet(ic, pkt);
} while(ret == AVERROR(EAGAIN));
if (ret != 0)
break;
@@ -3354,7 +3384,9 @@ static int ff_interleave_compare_dts(AVFormatContext *s, AVPacket *next, AVPacke
return comp > 0;
}
-int av_interleave_packet_per_dts(AVFormatContext *s, AVPacket *out, AVPacket *pkt, int flush){
+int ff_interleave_packet_per_dts(AVFormatContext *s, AVPacket *out,
+ AVPacket *pkt, int flush)
+{
AVPacketList *pktl;
int stream_count=0, noninterleaved_count=0;
int64_t delta_dts_max = 0;
@@ -3413,6 +3445,14 @@ int av_interleave_packet_per_dts(AVFormatContext *s, AVPacket *out, AVPacket *pk
}
}
+#if FF_API_INTERLEAVE_PACKET
+int av_interleave_packet_per_dts(AVFormatContext *s, AVPacket *out,
+ AVPacket *pkt, int flush)
+{
+ return ff_interleave_packet_per_dts(s, out, pkt, flush);
+}
+#endif
+
/**
* Interleave an AVPacket correctly so it can be muxed.
* @param out the interleaved packet will be output here
@@ -3429,7 +3469,7 @@ static int interleave_packet(AVFormatContext *s, AVPacket *out, AVPacket *in, in
av_free_packet(in);
return ret;
} else
- return av_interleave_packet_per_dts(s, out, in, flush);
+ return ff_interleave_packet_per_dts(s, out, in, flush);
}
int av_interleaved_write_frame(AVFormatContext *s, AVPacket *pkt){
diff --git a/libavformat/version.h b/libavformat/version.h
index 0dc68152c3..5969f92fa7 100644
--- a/libavformat/version.h
+++ b/libavformat/version.h
@@ -71,5 +71,11 @@
#ifndef FF_API_APPLEHTTP_PROTO
#define FF_API_APPLEHTTP_PROTO (LIBAVFORMAT_VERSION_MAJOR < 55)
#endif
+#ifndef FF_API_READ_PACKET
+#define FF_API_READ_PACKET (LIBAVFORMAT_VERSION_MAJOR < 55)
+#endif
+#ifndef FF_API_INTERLEAVE_PACKET
+#define FF_API_INTERLEAVE_PACKET (LIBAVFORMAT_VERSION_MAJOR < 55)
+#endif
#endif /* AVFORMAT_VERSION_H */
diff --git a/libavformat/xa.c b/libavformat/xa.c
index 1e51eec934..c54d7f8b9c 100644
--- a/libavformat/xa.c
+++ b/libavformat/xa.c
@@ -38,7 +38,6 @@
typedef struct MaxisXADemuxContext {
uint32_t out_size;
uint32_t sent_bytes;
- uint32_t audio_frame_counter;
} MaxisXADemuxContext;
static int xa_probe(AVProbeData *p)
@@ -81,12 +80,15 @@ static int xa_read_header(AVFormatContext *s)
avio_skip(pb, 2); /* Skip the tag */
st->codec->channels = avio_rl16(pb);
st->codec->sample_rate = avio_rl32(pb);
- /* Value in file is average byte rate*/
- st->codec->bit_rate = avio_rl32(pb) * 8;
- st->codec->block_align = avio_rl16(pb);
- st->codec->bits_per_coded_sample = avio_rl16(pb);
+ avio_skip(pb, 4); /* Skip average byte rate */
+ avio_skip(pb, 2); /* Skip block align */
+ avio_skip(pb, 2); /* Skip bits-per-sample */
+
+ st->codec->bit_rate = av_clip(15LL * st->codec->channels * 8 *
+ st->codec->sample_rate / 28, 0, INT_MAX);
avpriv_set_pts_info(st, 64, 1, st->codec->sample_rate);
+ st->start_time = 0;
return 0;
}
@@ -100,8 +102,8 @@ static int xa_read_packet(AVFormatContext *s,
unsigned int packet_size;
int ret;
- if(xa->sent_bytes > xa->out_size)
- return AVERROR(EIO);
+ if (xa->sent_bytes >= xa->out_size)
+ return AVERROR_EOF;
/* 1 byte header and 14 bytes worth of samples * number channels per block */
packet_size = 15*st->codec->channels;
@@ -111,9 +113,7 @@ static int xa_read_packet(AVFormatContext *s,
pkt->stream_index = st->index;
xa->sent_bytes += packet_size;
- pkt->pts = xa->audio_frame_counter;
- /* 14 bytes Samples per channel with 2 samples per byte */
- xa->audio_frame_counter += 28 * st->codec->channels;
+ pkt->duration = 28;
return ret;
}