25
25
#include "libavutil/mathematics.h"
26
26
#include "libavutil/tree.h"
27
27
#include "libavutil/dict.h"
28
#include "libavutil/time.h"
29
#include "libavutil/opt.h"
28
30
#include "libavcodec/mpegaudiodata.h"
30
32
#include "internal.h"
326
328
int64_t tmp_match;
328
ff_put_v(bc, NUT_VERSION);
330
ff_put_v(bc, nut->version);
329
331
ff_put_v(bc, nut->avf->nb_streams);
330
332
ff_put_v(bc, nut->max_distance);
331
333
ff_put_v(bc, nut->time_base_count);
405
407
ff_put_v(bc, nut->header_len[i]);
406
408
avio_write(bc, nut->header[i], nut->header_len[i]);
410
// flags had been effectively introduced in version 4
411
if (nut->version > NUT_STABLE_VERSION)
412
ff_put_v(bc, nut->flags);
410
415
static int write_streamheader(AVFormatContext *avctx, AVIOContext *bc,
651
nut->version = NUT_STABLE_VERSION + !!nut->flags;
652
if (nut->flags && s->strict_std_compliance > FF_COMPLIANCE_EXPERIMENTAL) {
653
av_log(s, AV_LOG_ERROR,
654
"The additional syncpoint modes require version %d, "
655
"that is currently not finalized, "
656
"please set -f_strict experimental in order to enable it.\n",
658
return AVERROR_EXPERIMENTAL;
646
661
nut->stream = av_mallocz(sizeof(StreamContext) * s->nb_streams);
647
662
if (s->nb_chapters)
648
663
nut->chapter = av_mallocz(sizeof(ChapterContext) * s->nb_chapters);
659
674
AVStream *st = s->streams[i];
661
676
AVRational time_base;
662
ff_parse_specific_params(st->codec, &time_base.den, &ssize,
677
ff_parse_specific_params(st, &time_base.den, &ssize,
665
680
avpriv_set_pts_info(st, 64, time_base.num, time_base.den);
790
805
//FIXME: Ensure store_sp is 1 in the first place.
808
(!(nut->flags & NUT_PIPE) || nut->last_syncpoint_pos == INT_MIN)) {
793
809
Syncpoint *sp, dummy = { .pos = INT64_MAX };
795
811
ff_nut_reset_ts(nut, *nus->time_base, pkt->dts);
816
832
put_tt(nut, nus->time_base, dyn_bc, pkt->dts);
817
833
ff_put_v(dyn_bc, sp ? (nut->last_syncpoint_pos - sp->pos) >> 4 : 0);
835
if (nut->flags & NUT_BROADCAST) {
836
put_tt(nut, nus->time_base, dyn_bc,
837
av_rescale_q(av_gettime(), AV_TIME_BASE_Q, *nus->time_base));
818
839
put_packet(nut, bc, dyn_bc, 1, SYNCPOINT_STARTCODE);
820
841
if ((ret = ff_nut_add_sp(nut, nut->last_syncpoint_pos, 0 /*unused*/, pkt->dts)) < 0)
917
938
nus->last_pts = pkt->pts;
919
940
//FIXME just store one per syncpoint
920
if (flags & FLAG_KEY)
941
if (flags & FLAG_KEY && !(nut->flags & NUT_PIPE))
921
942
av_add_index_entry(
922
943
s->streams[pkt->stream_index],
923
944
nut->last_syncpoint_pos,
969
#define OFFSET(x) offsetof(NUTContext, x)
970
#define E AV_OPT_FLAG_ENCODING_PARAM
971
static const AVOption options[] = {
972
{ "syncpoints", "NUT syncpoint behaviour", OFFSET(flags), AV_OPT_TYPE_FLAGS, {.i64 = 0}, INT_MIN, INT_MAX, E, "syncpoints" },
973
{ "default", "", 0, AV_OPT_TYPE_CONST, {.i64 = 0}, INT_MIN, INT_MAX, E, "syncpoints" },
974
{ "none", "Disable syncpoints, low overhead and unseekable", 0, AV_OPT_TYPE_CONST, {.i64 = NUT_PIPE}, INT_MIN, INT_MAX, E, "syncpoints" },
975
{ "timestamped", "Extend syncpoints with a wallclock timestamp", 0, AV_OPT_TYPE_CONST, {.i64 = NUT_BROADCAST}, INT_MIN, INT_MAX, E, "syncpoints" },
979
static const AVClass class = {
980
.class_name = "nutenc",
981
.item_name = av_default_item_name,
983
.version = LIBAVUTIL_VERSION_INT,
948
986
AVOutputFormat ff_nut_muxer = {
950
988
.long_name = NULL_IF_CONFIG_SMALL("NUT"),
959
997
.write_trailer = nut_write_trailer,
960
998
.flags = AVFMT_GLOBALHEADER | AVFMT_VARIABLE_FPS,
961
999
.codec_tag = ff_nut_codec_tags,
1000
.priv_class = &class,