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,
303 static inline void put_s_trace(
AVIOContext *bc, int64_t
v,
const char *file,
const char *
func,
int 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;
531 count +=
add_info(dyn_bc,
"r_frame_rate", buf);
583 int64_t payload_size;
591 ff_put_v(bc, (next_node[1]->pos >> 4) - (dummy.
pos>>4));
592 dummy.
pos = next_node[1]->
pos;
613 for (k= j - n; k<=j && k<nut->
sp_count; k++) {
623 payload_size =
avio_tell(bc) - startpos + 8 + 4;
625 avio_wb64(bc, 8 + payload_size +
av_log2(payload_size) / 7 + 1 + 4*(payload_size > 4096));
701 "The additional syncpoint modes require version %d, "
702 "that is currently not finalized, "
703 "please set -f_strict experimental in order to enable it.\n",
742 if (INT64_C(1000) * time_base.
num >= time_base.
den)
816 if (pkt->
size > 4096)
831 int ret, i, dyn_size;
834 int sm_data_count = 0;
850 if (!size || data[size-1]) {
854 while (data < data_end) {
858 if(val >= data_end) {
865 data = val + strlen(val) + 1;
880 snprintf(tmp,
sizeof(tmp),
"CodecSpecificSide%"PRId64
"",
AV_RB64(data));
883 snprintf(tmp,
sizeof(tmp),
"UserData%s-SD-%d",
895 flags = bytestream_get_le32(&data);
898 put_s(dyn_bc, bytestream_get_le32(&data));
902 put_str(dyn_bc,
"ChannelLayout");
911 put_s(dyn_bc, bytestream_get_le32(&data));
916 put_s(dyn_bc, bytestream_get_le32(&data));
918 put_s(dyn_bc, bytestream_get_le32(&data));
958 int best_length, frame_code,
flags, needed_flags, i, header_idx;
964 int data_size = pkt->
size;
969 "Negative pts not supported stream %d, pts %"PRId64
"\n",
986 data_size += sm_size;
1002 int64_t sp_pos = INT64_MAX;
1041 if ((1ll<<60) % nut->
sp_count == 0)
1063 best_length = INT_MAX;
1065 for (i = 0; i < 256; i++) {
1068 int flags = fc->
flags;
1076 flags = needed_flags;
1079 if ((flags & needed_flags) != needed_flags)
1082 if ((flags ^ needed_flags) &
FLAG_KEY)
1099 if ( (flags & FLAG_CODED)
1105 length += 1 - nut->
header_len[best_header_idx];
1114 if (length < best_length) {
1129 ff_put_v(bc, (flags ^ needed_flags) & ~(FLAG_CODED));
1130 flags = needed_flags;
1199 #define OFFSET(x) offsetof(NUTContext, x)
1200 #define E AV_OPT_FLAG_ENCODING_PARAM
1203 {
"default",
"", 0,
AV_OPT_TYPE_CONST, {.i64 = 0}, INT_MIN, INT_MAX,
E,
"syncpoints" },
1204 {
"none",
"Disable syncpoints, low overhead and unseekable", 0,
AV_OPT_TYPE_CONST, {.i64 =
NUT_PIPE}, INT_MIN, INT_MAX,
E,
"syncpoints" },
1210 static const AVClass class = {
1220 .mime_type =
"video/x-nut",
1221 .extensions =
"nut",
1231 .priv_class = &
class,