Commit 611c2214 authored by Hendrik Leppkes's avatar Hendrik Leppkes

Merge commit '8de1ee9f'

* commit '8de1ee9f':
  lavf: deprecate compute_pkt_fields2
Merged-by: 's avatarHendrik Leppkes <h.leppkes@gmail.com>
parents c03ffe17 8de1ee9f
...@@ -807,6 +807,8 @@ typedef struct AVIndexEntry { ...@@ -807,6 +807,8 @@ typedef struct AVIndexEntry {
*/ */
#define AV_DISPOSITION_ATTACHED_PIC 0x0400 #define AV_DISPOSITION_ATTACHED_PIC 0x0400
typedef struct AVStreamInternal AVStreamInternal;
/** /**
* To specify text track kind (different from subtitles default). * To specify text track kind (different from subtitles default).
*/ */
...@@ -1169,6 +1171,12 @@ typedef struct AVStream { ...@@ -1169,6 +1171,12 @@ typedef struct AVStream {
AVRational display_aspect_ratio; AVRational display_aspect_ratio;
struct FFFrac *priv_pts; struct FFFrac *priv_pts;
/**
* An opaque field for libavformat internal usage.
* Must not be accessed in any way by callers.
*/
AVStreamInternal *internal;
} AVStream; } AVStream;
AVRational av_stream_get_r_frame_rate(const AVStream *s); AVRational av_stream_get_r_frame_rate(const AVStream *s);
......
...@@ -110,11 +110,23 @@ struct AVFormatInternal { ...@@ -110,11 +110,23 @@ struct AVFormatInternal {
*/ */
AVRational offset_timebase; AVRational offset_timebase;
#if FF_API_COMPUTE_PKT_FIELDS2
int missing_ts_warning;
#endif
int inject_global_side_data; int inject_global_side_data;
int avoid_negative_ts_use_pts; int avoid_negative_ts_use_pts;
}; };
struct AVStreamInternal {
/**
* Set to 1 if the codec allows reordering, so pts can be different
* from dts.
*/
int reorder;
};
#ifdef __GNUC__ #ifdef __GNUC__
#define dynarray_add(tab, nb_ptr, elem)\ #define dynarray_add(tab, nb_ptr, elem)\
do {\ do {\
......
...@@ -239,6 +239,7 @@ static int init_muxer(AVFormatContext *s, AVDictionary **options) ...@@ -239,6 +239,7 @@ static int init_muxer(AVFormatContext *s, AVDictionary **options)
AVDictionary *tmp = NULL; AVDictionary *tmp = NULL;
AVCodecContext *codec = NULL; AVCodecContext *codec = NULL;
AVOutputFormat *of = s->oformat; AVOutputFormat *of = s->oformat;
const AVCodecDescriptor *desc;
AVDictionaryEntry *e; AVDictionaryEntry *e;
if (options) if (options)
...@@ -335,6 +336,10 @@ FF_ENABLE_DEPRECATION_WARNINGS ...@@ -335,6 +336,10 @@ FF_ENABLE_DEPRECATION_WARNINGS
break; break;
} }
desc = avcodec_descriptor_get(codec->codec_id);
if (desc && desc->props & AV_CODEC_PROP_REORDER)
st->internal->reorder = 1;
if (of->codec_tag) { if (of->codec_tag) {
if ( codec->codec_tag if ( codec->codec_tag
&& codec->codec_id == AV_CODEC_ID_RAWVIDEO && codec->codec_id == AV_CODEC_ID_RAWVIDEO
...@@ -484,6 +489,7 @@ int avformat_write_header(AVFormatContext *s, AVDictionary **options) ...@@ -484,6 +489,7 @@ int avformat_write_header(AVFormatContext *s, AVDictionary **options)
#define UNCODED_FRAME_PACKET_SIZE (INT_MIN / 3 * 2 + (int)sizeof(AVFrame)) #define UNCODED_FRAME_PACKET_SIZE (INT_MIN / 3 * 2 + (int)sizeof(AVFrame))
#if FF_API_COMPUTE_PKT_FIELDS2
//FIXME merge with compute_pkt_fields //FIXME merge with compute_pkt_fields
static int compute_pkt_fields2(AVFormatContext *s, AVStream *st, AVPacket *pkt) static int compute_pkt_fields2(AVFormatContext *s, AVStream *st, AVPacket *pkt)
{ {
...@@ -491,6 +497,16 @@ static int compute_pkt_fields2(AVFormatContext *s, AVStream *st, AVPacket *pkt) ...@@ -491,6 +497,16 @@ static int compute_pkt_fields2(AVFormatContext *s, AVStream *st, AVPacket *pkt)
int num, den, i; int num, den, i;
int frame_size; int frame_size;
if (!s->internal->missing_ts_warning &&
!(s->oformat->flags & AVFMT_NOTIMESTAMPS) &&
(pkt->pts == AV_NOPTS_VALUE || pkt->dts == AV_NOPTS_VALUE)) {
av_log(s, AV_LOG_WARNING,
"Timestamps are unset in a packet for stream %d. "
"This is deprecated and will stop working in the future. "
"Fix your code to set the timestamps properly\n", st->index);
s->internal->missing_ts_warning = 1;
}
if (s->debug & FF_FDEBUG_TS) if (s->debug & FF_FDEBUG_TS)
av_log(s, AV_LOG_TRACE, "compute_pkt_fields2: pts:%s dts:%s cur_dts:%s b:%d size:%d st:%d\n", av_log(s, AV_LOG_TRACE, "compute_pkt_fields2: pts:%s dts:%s cur_dts:%s b:%d size:%d st:%d\n",
av_ts2str(pkt->pts), av_ts2str(pkt->dts), av_ts2str(st->cur_dts), delay, pkt->size, pkt->stream_index); av_ts2str(pkt->pts), av_ts2str(pkt->dts), av_ts2str(st->cur_dts), delay, pkt->size, pkt->stream_index);
...@@ -579,6 +595,7 @@ static int compute_pkt_fields2(AVFormatContext *s, AVStream *st, AVPacket *pkt) ...@@ -579,6 +595,7 @@ static int compute_pkt_fields2(AVFormatContext *s, AVStream *st, AVPacket *pkt)
} }
return 0; return 0;
} }
#endif
/** /**
* Make timestamps non negative, move side data from payload to internal struct, call muxer, and restore * Make timestamps non negative, move side data from payload to internal struct, call muxer, and restore
...@@ -693,7 +710,7 @@ static int check_packet(AVFormatContext *s, AVPacket *pkt) ...@@ -693,7 +710,7 @@ static int check_packet(AVFormatContext *s, AVPacket *pkt)
return 0; return 0;
} }
int av_write_frame(AVFormatContext *s, AVPacket *pkt) static int prepare_input_packet(AVFormatContext *s, AVPacket *pkt)
{ {
int ret; int ret;
...@@ -701,6 +718,58 @@ int av_write_frame(AVFormatContext *s, AVPacket *pkt) ...@@ -701,6 +718,58 @@ int av_write_frame(AVFormatContext *s, AVPacket *pkt)
if (ret < 0) if (ret < 0)
return ret; return ret;
#if !FF_API_COMPUTE_PKT_FIELDS2
/* sanitize the timestamps */
if (!(s->oformat->flags & AVFMT_NOTIMESTAMPS)) {
AVStream *st = s->streams[pkt->stream_index];
/* when there is no reordering (so dts is equal to pts), but
* only one of them is set, set the other as well */
if (!st->internal->reorder) {
if (pkt->pts == AV_NOPTS_VALUE && pkt->dts != AV_NOPTS_VALUE)
pkt->pts = pkt->dts;
if (pkt->dts == AV_NOPTS_VALUE && pkt->pts != AV_NOPTS_VALUE)
pkt->dts = pkt->pts;
}
/* check that the timestamps are set */
if (pkt->pts == AV_NOPTS_VALUE || pkt->dts == AV_NOPTS_VALUE) {
av_log(s, AV_LOG_ERROR,
"Timestamps are unset in a packet for stream %d\n", st->index);
return AVERROR(EINVAL);
}
/* check that the dts are increasing (or at least non-decreasing,
* if the format allows it */
if (st->cur_dts != AV_NOPTS_VALUE &&
((!(s->oformat->flags & AVFMT_TS_NONSTRICT) && st->cur_dts >= pkt->dts) ||
st->cur_dts > pkt->dts)) {
av_log(s, AV_LOG_ERROR,
"Application provided invalid, non monotonically increasing "
"dts to muxer in stream %d: %" PRId64 " >= %" PRId64 "\n",
st->index, st->cur_dts, pkt->dts);
return AVERROR(EINVAL);
}
if (pkt->pts < pkt->dts) {
av_log(s, AV_LOG_ERROR, "pts %" PRId64 " < dts %" PRId64 " in stream %d\n",
pkt->pts, pkt->dts, st->index);
return AVERROR(EINVAL);
}
}
#endif
return 0;
}
int av_write_frame(AVFormatContext *s, AVPacket *pkt)
{
int ret;
ret = prepare_input_packet(s, pkt);
if (ret < 0)
return ret;
if (!pkt) { if (!pkt) {
if (s->oformat->flags & AVFMT_ALLOW_FLUSH) { if (s->oformat->flags & AVFMT_ALLOW_FLUSH) {
ret = s->oformat->write_packet(s, NULL); ret = s->oformat->write_packet(s, NULL);
...@@ -713,10 +782,12 @@ int av_write_frame(AVFormatContext *s, AVPacket *pkt) ...@@ -713,10 +782,12 @@ int av_write_frame(AVFormatContext *s, AVPacket *pkt)
return 1; return 1;
} }
#if FF_API_COMPUTE_PKT_FIELDS2
ret = compute_pkt_fields2(s, s->streams[pkt->stream_index], pkt); ret = compute_pkt_fields2(s, s->streams[pkt->stream_index], pkt);
if (ret < 0 && !(s->oformat->flags & AVFMT_NOTIMESTAMPS)) if (ret < 0 && !(s->oformat->flags & AVFMT_NOTIMESTAMPS))
return ret; return ret;
#endif
ret = write_packet(s, pkt); ret = write_packet(s, pkt);
if (ret >= 0 && s->pb && s->pb->error < 0) if (ret >= 0 && s->pb && s->pb->error < 0)
...@@ -930,7 +1001,7 @@ int av_interleaved_write_frame(AVFormatContext *s, AVPacket *pkt) ...@@ -930,7 +1001,7 @@ int av_interleaved_write_frame(AVFormatContext *s, AVPacket *pkt)
{ {
int ret, flush = 0; int ret, flush = 0;
ret = check_packet(s, pkt); ret = prepare_input_packet(s, pkt);
if (ret < 0) if (ret < 0)
goto fail; goto fail;
...@@ -941,8 +1012,10 @@ int av_interleaved_write_frame(AVFormatContext *s, AVPacket *pkt) ...@@ -941,8 +1012,10 @@ int av_interleaved_write_frame(AVFormatContext *s, AVPacket *pkt)
av_log(s, AV_LOG_TRACE, "av_interleaved_write_frame size:%d dts:%s pts:%s\n", av_log(s, AV_LOG_TRACE, "av_interleaved_write_frame size:%d dts:%s pts:%s\n",
pkt->size, av_ts2str(pkt->dts), av_ts2str(pkt->pts)); pkt->size, av_ts2str(pkt->dts), av_ts2str(pkt->pts));
#if FF_API_COMPUTE_PKT_FIELDS2
if ((ret = compute_pkt_fields2(s, st, pkt)) < 0 && !(s->oformat->flags & AVFMT_NOTIMESTAMPS)) if ((ret = compute_pkt_fields2(s, st, pkt)) < 0 && !(s->oformat->flags & AVFMT_NOTIMESTAMPS))
goto fail; goto fail;
#endif
if (pkt->dts == AV_NOPTS_VALUE && !(s->oformat->flags & AVFMT_NOTIMESTAMPS)) { if (pkt->dts == AV_NOPTS_VALUE && !(s->oformat->flags & AVFMT_NOTIMESTAMPS)) {
ret = AVERROR(EINVAL); ret = AVERROR(EINVAL);
......
...@@ -3669,6 +3669,8 @@ static void free_stream(AVStream **pst) ...@@ -3669,6 +3669,8 @@ static void free_stream(AVStream **pst)
if (st->attached_pic.data) if (st->attached_pic.data)
av_packet_unref(&st->attached_pic); av_packet_unref(&st->attached_pic);
av_freep(&st->internal);
av_dict_free(&st->metadata); av_dict_free(&st->metadata);
av_freep(&st->probe_data.buf); av_freep(&st->probe_data.buf);
av_freep(&st->index_entries); av_freep(&st->index_entries);
...@@ -3785,6 +3787,11 @@ AVStream *avformat_new_stream(AVFormatContext *s, const AVCodec *c) ...@@ -3785,6 +3787,11 @@ AVStream *avformat_new_stream(AVFormatContext *s, const AVCodec *c)
av_free(st); av_free(st);
return NULL; return NULL;
} }
st->internal = av_mallocz(sizeof(*st->internal));
if (!st->internal)
goto fail;
if (s->iformat) { if (s->iformat) {
/* no default bitrate if decoding */ /* no default bitrate if decoding */
st->codec->bit_rate = 0; st->codec->bit_rate = 0;
...@@ -3825,6 +3832,9 @@ AVStream *avformat_new_stream(AVFormatContext *s, const AVCodec *c) ...@@ -3825,6 +3832,9 @@ AVStream *avformat_new_stream(AVFormatContext *s, const AVCodec *c)
s->streams[s->nb_streams++] = st; s->streams[s->nb_streams++] = st;
return st; return st;
fail:
free_stream(&st);
return NULL;
} }
AVProgram *av_new_program(AVFormatContext *ac, int id) AVProgram *av_new_program(AVFormatContext *ac, int id)
......
...@@ -68,6 +68,9 @@ ...@@ -68,6 +68,9 @@
#ifndef FF_API_LAVF_FMT_RAWPICTURE #ifndef FF_API_LAVF_FMT_RAWPICTURE
#define FF_API_LAVF_FMT_RAWPICTURE (LIBAVFORMAT_VERSION_MAJOR < 58) #define FF_API_LAVF_FMT_RAWPICTURE (LIBAVFORMAT_VERSION_MAJOR < 58)
#endif #endif
#ifndef FF_API_COMPUTE_PKT_FIELDS2
#define FF_API_COMPUTE_PKT_FIELDS2 (LIBAVFORMAT_VERSION_MAJOR < 58)
#endif
#ifndef FF_API_R_FRAME_RATE #ifndef FF_API_R_FRAME_RATE
#define FF_API_R_FRAME_RATE 1 #define FF_API_R_FRAME_RATE 1
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment