60 int lsf, mpeg25, sample_rate_index, bitrate_index,
frame_size;
62 unsigned int header = 0xFFF00000;
64 lsf = sample_rate < (24000 + 32000) / 2;
65 mpeg25 = sample_rate < (12000 + 16000) / 2;
66 sample_rate <<= lsf + mpeg25;
67 if (sample_rate < (32000 + 44100) / 2) sample_rate_index = 2;
68 else if (sample_rate < (44100 + 48000) / 2) sample_rate_index = 0;
69 else sample_rate_index = 1;
73 for (bitrate_index = 2; bitrate_index < 30; bitrate_index++) {
76 frame_size = (frame_size * 144000) / (sample_rate << lsf) +
79 if (frame_size == size)
83 header |= (!lsf) << 19;
84 header |= (4 - layer) << 17;
89 if (bitrate_index == 30)
92 header |= (bitrate_index >> 1) << 12;
93 header |= sample_rate_index << 10;
94 header |= (bitrate_index & 1) << 9;
125 static const uint8_t headers[][5] = {
126 { 3, 0x00, 0x00, 0x01 },
127 { 4, 0x00, 0x00, 0x01, 0xB6},
137 nut->
header[i] = &headers[i - 1][1];
157 if (keyframe_0_esc) {
165 for (stream_id = 0; stream_id < s->
nb_streams; stream_id++) {
167 int end2 = start + (end - start) * (stream_id + 1) / s->
nb_streams;
180 if (f.
den == 1 && f.
num>0)
186 for (key_frame = 0; key_frame < 2; key_frame++) {
187 if (!
intra_only || !keyframe_0_esc || key_frame != 0) {
202 int frame_bytes = codec->frame_size * (int64_t)codec->bit_rate /
203 (8 * codec->sample_rate);
205 for (pts = 0; pts < 2; pts++) {
206 for (pred = 0; pred < 2; pred++) {
227 if (codec->has_b_frames) {
244 for (pred = 0; pred < pred_count; pred++) {
245 int start3 = start2 + (end2 - start2) * pred / pred_count;
246 int end3 = start2 + (end2 - start2) * (pred + 1) / pred_count;
250 for (index = start3; index < end3; index++) {
281 int len = strlen(
string);
293 static inline void ff_put_v_trace(
AVIOContext *bc, uint64_t
v,
const char *file,
296 av_log(NULL,
AV_LOG_DEBUG,
"ff_put_v %5"PRId64
" / %"PRIX64
" in %s %s:%d\n", v, v, file, func, line);
301 static inline void put_s_trace(
AVIOContext *bc, int64_t
v,
const char *file,
const char *
func,
int line)
303 av_log(NULL,
AV_LOG_DEBUG,
"put_s %5"PRId64
" / %"PRIX64
" in %s %s:%d\n", v, v, file, func, line);
307 #define ff_put_v(bc, v) ff_put_v_trace(bc, v, __FILE__, __PRETTY_FUNCTION__, __LINE__)
308 #define put_s(bc, v) put_s_trace(bc, v, __FILE__, __PRETTY_FUNCTION__, __LINE__)
313 int calculate_checksum, uint64_t startcode)
317 int forw_ptr = dyn_size + 4 * calculate_checksum;
326 if (calculate_checksum)
329 if (calculate_checksum)
337 int i, j, tmp_pts, tmp_flags, tmp_stream, tmp_mul, tmp_size, tmp_fields,
356 tmp_match = 1 - (1LL << 62);
358 for (i = 0; i < 256; ) {
377 for (j = 0; i < 256; j++, i++) {
391 if (j != tmp_mul - tmp_size)
396 if (tmp_fields > 0)
put_s(bc, tmp_pts);
397 if (tmp_fields > 1)
ff_put_v(bc, tmp_mul);
398 if (tmp_fields > 2)
ff_put_v(bc, tmp_stream);
399 if (tmp_fields > 3)
ff_put_v(bc, tmp_size);
400 if (tmp_fields > 4)
ff_put_v(bc, 0 );
401 if (tmp_fields > 5)
ff_put_v(bc, j);
402 if (tmp_fields > 6)
ff_put_v(bc, tmp_match);
403 if (tmp_fields > 7)
ff_put_v(bc, tmp_head_idx);
482 int count = 0, dyn_size;
509 int count=0, dyn_size, i;
523 count +=
add_info(dyn_bc,
"r_frame_rate", buf);
575 int64_t payload_size;
583 ff_put_v(bc, (next_node[1]->pos >> 4) - (dummy.
pos>>4));
584 dummy.
pos = next_node[1]->
pos;
605 for (k= j - n; k<=j && k<nut->
sp_count; k++) {
615 payload_size =
avio_tell(bc) - startpos + 8 + 4;
617 avio_wb64(bc, 8 + payload_size +
av_log2(payload_size) / 7 + 1 + 4*(payload_size > 4096));
729 if (INT64_C(1000) * time_base.
num >= time_base.
den)
803 if (pkt->
size > 4096)
819 int ret, i, dyn_size;
822 int sm_data_count = 0;
838 if (!size || data[size-1])
840 while (data < data_end) {
849 data = val + strlen(val) + 1;
864 snprintf(tmp,
sizeof(tmp),
"CodecSpecificSide%"PRId64
"",
AV_RB64(data));
867 snprintf(tmp,
sizeof(tmp),
"UserData%s-SD-%d",
879 flags = bytestream_get_le32(&data);
882 put_s(dyn_bc, bytestream_get_le32(&data));
886 put_str(dyn_bc,
"ChannelLayout");
895 put_s(dyn_bc, bytestream_get_le32(&data));
900 put_s(dyn_bc, bytestream_get_le32(&data));
902 put_s(dyn_bc, bytestream_get_le32(&data));
941 int best_length, frame_code,
flags, needed_flags, i, header_idx;
952 "Negative pts not supported stream %d, pts %"PRId64
"\n",
964 data_size += sm_size;
993 if (dummy.
pos == INT64_MAX)
1009 if ((1ll<<60) % nut->
sp_count == 0)
1028 best_length = INT_MAX;
1030 for (i = 0; i < 256; i++) {
1033 int flags = fc->
flags;
1041 flags = needed_flags;
1044 if ((flags & needed_flags) != needed_flags)
1047 if ((flags ^ needed_flags) &
FLAG_KEY)
1064 if ( (flags & FLAG_CODED)
1070 length += 1 - nut->
header_len[best_header_idx];
1079 if (length < best_length) {
1093 ff_put_v(bc, (flags ^ needed_flags) & ~(FLAG_CODED));
1094 flags = needed_flags;
1163 .mime_type =
"video/x-nut",
1164 .extensions =
"nut",