62 int lsf, mpeg25, sample_rate_index, bitrate_index,
frame_size;
64 unsigned int header = 0xFFF00000;
66 lsf = sample_rate < (24000 + 32000) / 2;
67 mpeg25 = sample_rate < (12000 + 16000) / 2;
68 sample_rate <<= lsf + mpeg25;
69 if (sample_rate < (32000 + 44100) / 2) sample_rate_index = 2;
70 else if (sample_rate < (44100 + 48000) / 2) sample_rate_index = 0;
71 else sample_rate_index = 1;
75 for (bitrate_index = 2; bitrate_index < 30; bitrate_index++) {
78 frame_size = (frame_size * 144000) / (sample_rate << lsf) +
81 if (frame_size == size)
85 header |= (!lsf) << 19;
86 header |= (4 - layer) << 17;
91 if (bitrate_index == 30)
94 header |= (bitrate_index >> 1) << 12;
95 header |= sample_rate_index << 10;
96 header |= (bitrate_index & 1) << 9;
127 static const uint8_t headers[][5] = {
128 { 3, 0x00, 0x00, 0x01 },
129 { 4, 0x00, 0x00, 0x01, 0xB6},
139 nut->
header[i] = &headers[i - 1][1];
159 if (keyframe_0_esc) {
167 for (stream_id = 0; stream_id < s->
nb_streams; stream_id++) {
169 int end2 = start + (end - start) * (stream_id + 1) / s->
nb_streams;
182 if (f.
den == 1 && f.
num>0)
188 for (key_frame = 0; key_frame < 2; key_frame++) {
189 if (!
intra_only || !keyframe_0_esc || key_frame != 0) {
204 int frame_bytes = codec->frame_size * (int64_t)codec->bit_rate /
205 (8 * codec->sample_rate);
207 for (pts = 0; pts < 2; pts++) {
208 for (pred = 0; pred < 2; pred++) {
229 if (codec->has_b_frames) {
246 for (pred = 0; pred < pred_count; pred++) {
247 int start3 = start2 + (end2 - start2) * pred / pred_count;
248 int end3 = start2 + (end2 - start2) * (pred + 1) / pred_count;
252 for (index = start3; index < end3; index++) {
283 int len = strlen(
string);
295 static inline void ff_put_v_trace(
AVIOContext *bc, uint64_t
v,
const char *file,
298 av_log(NULL,
AV_LOG_DEBUG,
"ff_put_v %5"PRId64
" / %"PRIX64
" in %s %s:%d\n", v, v, file, func, line);
303 static inline void put_s_trace(
AVIOContext *bc, int64_t
v,
const char *file,
const char *
func,
int line)
305 av_log(NULL,
AV_LOG_DEBUG,
"put_s %5"PRId64
" / %"PRIX64
" in %s %s:%d\n", v, v, file, func, line);
309 #define ff_put_v(bc, v) ff_put_v_trace(bc, v, __FILE__, __PRETTY_FUNCTION__, __LINE__)
310 #define put_s(bc, v) put_s_trace(bc, v, __FILE__, __PRETTY_FUNCTION__, __LINE__)
315 int calculate_checksum, uint64_t startcode)
319 int forw_ptr = dyn_size + 4 * calculate_checksum;
328 if (calculate_checksum)
331 if (calculate_checksum)
339 int i, j, tmp_pts, tmp_flags, tmp_stream, tmp_mul, tmp_size, tmp_fields,
358 tmp_match = 1 - (1LL << 62);
360 for (i = 0; i < 256; ) {
379 for (j = 0; i < 256; j++, i++) {
393 if (j != tmp_mul - tmp_size)
398 if (tmp_fields > 0)
put_s(bc, tmp_pts);
399 if (tmp_fields > 1)
ff_put_v(bc, tmp_mul);
400 if (tmp_fields > 2)
ff_put_v(bc, tmp_stream);
401 if (tmp_fields > 3)
ff_put_v(bc, tmp_size);
402 if (tmp_fields > 4)
ff_put_v(bc, 0 );
403 if (tmp_fields > 5)
ff_put_v(bc, j);
404 if (tmp_fields > 6)
ff_put_v(bc, tmp_match);
405 if (tmp_fields > 7)
ff_put_v(bc, tmp_head_idx);
487 int count = 0, dyn_size;
514 int count=0, dyn_size, i;
528 count +=
add_info(dyn_bc,
"r_frame_rate", buf);
580 int64_t payload_size;
588 ff_put_v(bc, (next_node[1]->pos >> 4) - (dummy.
pos>>4));
589 dummy.
pos = next_node[1]->
pos;
610 for (k= j - n; k<=j && k<nut->
sp_count; k++) {
620 payload_size =
avio_tell(bc) - startpos + 8 + 4;
622 avio_wb64(bc, 8 + payload_size +
av_log2(payload_size) / 7 + 1 + 4*(payload_size > 4096));
703 "The additional syncpoint modes require version %d, "
704 "that is currently not finalized, "
705 "please set -f_strict experimental in order to enable it.\n",
744 if (INT64_C(1000) * time_base.
num >= time_base.
den)
818 if (pkt->
size > 4096)
833 int ret, i, dyn_size;
836 int sm_data_count = 0;
852 if (!size || data[size-1]) {
856 while (data < data_end) {
860 if(val >= data_end) {
867 data = val + strlen(val) + 1;
882 snprintf(tmp,
sizeof(tmp),
"CodecSpecificSide%"PRId64
"",
AV_RB64(data));
885 snprintf(tmp,
sizeof(tmp),
"UserData%s-SD-%d",
897 flags = bytestream_get_le32(&data);
900 put_s(dyn_bc, bytestream_get_le32(&data));
904 put_str(dyn_bc,
"ChannelLayout");
913 put_s(dyn_bc, bytestream_get_le32(&data));
918 put_s(dyn_bc, bytestream_get_le32(&data));
920 put_s(dyn_bc, bytestream_get_le32(&data));
960 int best_length, frame_code,
flags, needed_flags, i, header_idx;
966 int data_size = pkt->
size;
971 "Negative pts not supported stream %d, pts %"PRId64
"\n",
988 data_size += sm_size;
1004 int64_t sp_pos = INT64_MAX;
1043 if ((1ll<<60) % nut->
sp_count == 0)
1065 best_length = INT_MAX;
1067 for (i = 0; i < 256; i++) {
1070 int flags = fc->
flags;
1078 flags = needed_flags;
1081 if ((flags & needed_flags) != needed_flags)
1084 if ((flags ^ needed_flags) &
FLAG_KEY)
1101 if ( (flags & FLAG_CODED)
1107 length += 1 - nut->
header_len[best_header_idx];
1116 if (length < best_length) {
1130 ff_put_v(bc, (flags ^ needed_flags) & ~(FLAG_CODED));
1131 flags = needed_flags;
1200 #define OFFSET(x) offsetof(NUTContext, x)
1201 #define E AV_OPT_FLAG_ENCODING_PARAM
1204 {
"default",
"", 0,
AV_OPT_TYPE_CONST, {.i64 = 0}, INT_MIN, INT_MAX,
E,
"syncpoints" },
1205 {
"none",
"Disable syncpoints, low overhead and unseekable", 0,
AV_OPT_TYPE_CONST, {.i64 =
NUT_PIPE}, INT_MIN, INT_MAX,
E,
"syncpoints" },
1211 static const AVClass class = {
1221 .mime_type =
"video/x-nut",
1222 .extensions =
"nut",
1232 .priv_class = &
class,