Lines Matching refs:nut
89 static int get_packetheader(NUTContext *nut, AVIOContext *bc, in get_packetheader() argument
192 static int decode_main_header(NUTContext *nut) in decode_main_header() argument
194 AVFormatContext *s = nut->avf; in decode_main_header()
201 length = get_packetheader(nut, bc, 1, MAIN_STARTCODE); in decode_main_header()
204 nut->version = ffio_read_varlen(bc); in decode_main_header()
205 if (nut->version < NUT_MIN_VERSION || in decode_main_header()
206 nut->version > NUT_MAX_VERSION) { in decode_main_header()
208 nut->version); in decode_main_header()
211 if (nut->version > 3) in decode_main_header()
212 nut->minor_version = ffio_read_varlen(bc); in decode_main_header()
216 nut->max_distance = ffio_read_varlen(bc); in decode_main_header()
217 if (nut->max_distance > 65536) { in decode_main_header()
218 av_log(s, AV_LOG_DEBUG, "max_distance %d\n", nut->max_distance); in decode_main_header()
219 nut->max_distance = 65536; in decode_main_header()
222 GET_V(nut->time_base_count, tmp > 0 && tmp < INT_MAX / sizeof(AVRational) && tmp < length/2); in decode_main_header()
223 nut->time_base = av_malloc_array(nut->time_base_count, sizeof(AVRational)); in decode_main_header()
224 if (!nut->time_base) in decode_main_header()
227 for (i = 0; i < nut->time_base_count; i++) { in decode_main_header()
228 GET_V(nut->time_base[i].num, tmp > 0 && tmp < (1ULL << 31)); in decode_main_header()
229 GET_V(nut->time_base[i].den, tmp > 0 && tmp < (1ULL << 31)); in decode_main_header()
230 if (av_gcd(nut->time_base[i].num, nut->time_base[i].den) != 1) { in decode_main_header()
232 nut->time_base[i].num, in decode_main_header()
233 nut->time_base[i].den); in decode_main_header()
297 nut->frame_code[i].flags = FLAG_INVALID; in decode_main_header()
301 nut->frame_code[i].flags = tmp_flags; in decode_main_header()
302 nut->frame_code[i].pts_delta = tmp_pts; in decode_main_header()
303 nut->frame_code[i].stream_id = tmp_stream; in decode_main_header()
304 nut->frame_code[i].size_mul = tmp_mul; in decode_main_header()
305 nut->frame_code[i].size_lsb = tmp_size + j; in decode_main_header()
306 nut->frame_code[i].reserved_count = tmp_res; in decode_main_header()
307 nut->frame_code[i].header_idx = tmp_head_idx; in decode_main_header()
310 av_assert0(nut->frame_code['N'].flags == FLAG_INVALID); in decode_main_header()
314 GET_V(nut->header_count, tmp < 128U); in decode_main_header()
315 nut->header_count++; in decode_main_header()
316 for (i = 1; i < nut->header_count; i++) { in decode_main_header()
318 GET_V(nut->header_len[i], tmp > 0 && tmp < 256); in decode_main_header()
319 if (rem < nut->header_len[i]) { in decode_main_header()
322 i, nut->header_len[i], rem); in decode_main_header()
326 rem -= nut->header_len[i]; in decode_main_header()
327 hdr = av_malloc(nut->header_len[i]); in decode_main_header()
332 avio_read(bc, hdr, nut->header_len[i]); in decode_main_header()
333 nut->header[i] = hdr; in decode_main_header()
335 av_assert0(nut->header_len[0] == 0); in decode_main_header()
339 if (nut->version > 3 && end > avio_tell(bc) + 4) { in decode_main_header()
340 nut->flags = ffio_read_varlen(bc); in decode_main_header()
349 nut->stream = av_calloc(stream_count, sizeof(StreamContext)); in decode_main_header()
350 if (!nut->stream) { in decode_main_header()
363 av_freep(&nut->time_base); in decode_main_header()
364 for (i = 1; i < nut->header_count; i++) { in decode_main_header()
365 av_freep(&nut->header[i]); in decode_main_header()
367 nut->header_count = 0; in decode_main_header()
371 static int decode_stream_header(NUTContext *nut) in decode_stream_header() argument
373 AVFormatContext *s = nut->avf; in decode_stream_header()
380 end = get_packetheader(nut, bc, 1, STREAM_STARTCODE); in decode_stream_header()
383 GET_V(stream_id, tmp < s->nb_streams && !nut->stream[tmp].time_base); in decode_stream_header()
384 stc = &nut->stream[stream_id]; in decode_stream_header()
430 GET_V(stc->time_base_id, tmp < nut->time_base_count); in decode_stream_header()
468 stc->time_base = &nut->time_base[stc->time_base_id]; in decode_stream_header()
495 static int decode_info_header(NUTContext *nut) in decode_info_header() argument
497 AVFormatContext *s = nut->avf; in decode_info_header()
511 end = get_packetheader(nut, bc, 1, INFO_STARTCODE); in decode_info_header()
521 int64_t start = chapter_start / nut->time_base_count; in decode_info_header()
523 nut->time_base[chapter_start % in decode_info_header()
524 nut->time_base_count], in decode_info_header()
618 static int decode_syncpoint(NUTContext *nut, int64_t *ts, int64_t *back_ptr) in decode_syncpoint() argument
620 AVFormatContext *s = nut->avf; in decode_syncpoint()
626 nut->last_syncpoint_pos = avio_tell(bc) - 8; in decode_syncpoint()
628 end = get_packetheader(nut, bc, 1, SYNCPOINT_STARTCODE); in decode_syncpoint()
632 *back_ptr = nut->last_syncpoint_pos - 16 * ffio_read_varlen(bc); in decode_syncpoint()
636 ff_nut_reset_ts(nut, nut->time_base[tmp % nut->time_base_count], in decode_syncpoint()
637 tmp / nut->time_base_count); in decode_syncpoint()
639 if (nut->flags & NUT_BROADCAST) { in decode_syncpoint()
642 av_rescale_q(tmp / nut->time_base_count, in decode_syncpoint()
643 nut->time_base[tmp % nut->time_base_count], in decode_syncpoint()
652 *ts = tmp / nut->time_base_count * in decode_syncpoint()
653 av_q2d(nut->time_base[tmp % nut->time_base_count]) * AV_TIME_BASE; in decode_syncpoint()
655 if ((ret = ff_nut_add_sp(nut, nut->last_syncpoint_pos, *back_ptr, *ts)) < 0) in decode_syncpoint()
662 static int64_t find_duration(NUTContext *nut, int64_t filesize) in find_duration() argument
664 AVFormatContext *s = nut->avf; in find_duration()
674 static int find_and_decode_index(NUTContext *nut) in find_and_decode_index() argument
676 AVFormatContext *s = nut->avf; in find_and_decode_index()
695 s->duration = find_duration(nut, filesize); in find_and_decode_index()
699 end = get_packetheader(nut, bc, 1, INDEX_STARTCODE); in find_and_decode_index()
703 s->duration = av_rescale_q(max_pts / nut->time_base_count, in find_and_decode_index()
704 nut->time_base[max_pts % nut->time_base_count], in find_and_decode_index()
790 NUTContext *nut = s->priv_data; in nut_read_close() local
793 av_freep(&nut->time_base); in nut_read_close()
794 av_freep(&nut->stream); in nut_read_close()
795 ff_nut_free_sp(nut); in nut_read_close()
796 for (i = 1; i < nut->header_count; i++) in nut_read_close()
797 av_freep(&nut->header[i]); in nut_read_close()
804 NUTContext *nut = s->priv_data; in nut_read_header() local
809 nut->avf = s; in nut_read_header()
823 } while ((ret = decode_main_header(nut)) < 0); in nut_read_header()
833 if (decode_stream_header(nut) >= 0) in nut_read_header()
847 nut->next_startcode = startcode; in nut_read_header()
853 decode_info_header(nut); in nut_read_header()
860 find_and_decode_index(nut); in nut_read_header()
863 av_assert0(nut->next_startcode == SYNCPOINT_STARTCODE); in nut_read_header()
1000 static int decode_frame_header(NUTContext *nut, int64_t *pts, int *stream_id, in decode_frame_header() argument
1003 AVFormatContext *s = nut->avf; in decode_frame_header()
1009 if (!(nut->flags & NUT_PIPE) && in decode_frame_header()
1010 avio_tell(bc) > nut->last_syncpoint_pos + nut->max_distance) { in decode_frame_header()
1013 avio_tell(bc), nut->last_syncpoint_pos, nut->max_distance); in decode_frame_header()
1017 flags = nut->frame_code[frame_code].flags; in decode_frame_header()
1018 size_mul = nut->frame_code[frame_code].size_mul; in decode_frame_header()
1019 size = nut->frame_code[frame_code].size_lsb; in decode_frame_header()
1020 *stream_id = nut->frame_code[frame_code].stream_id; in decode_frame_header()
1021 pts_delta = nut->frame_code[frame_code].pts_delta; in decode_frame_header()
1022 reserved_count = nut->frame_code[frame_code].reserved_count; in decode_frame_header()
1023 *header_idx = nut->frame_code[frame_code].header_idx; in decode_frame_header()
1032 stc = &nut->stream[*stream_id]; in decode_frame_header()
1058 if (*header_idx >= (unsigned)nut->header_count) { in decode_frame_header()
1064 size -= nut->header_len[*header_idx]; in decode_frame_header()
1068 } else if (!(nut->flags & NUT_PIPE) && in decode_frame_header()
1069 size > 2 * nut->max_distance || in decode_frame_header()
1083 static int decode_frame(NUTContext *nut, AVPacket *pkt, int frame_code) in decode_frame() argument
1085 AVFormatContext *s = nut->avf; in decode_frame()
1092 size = decode_frame_header(nut, &pts, &stream_id, &header_idx, frame_code); in decode_frame()
1096 stc = &nut->stream[stream_id]; in decode_frame()
1112 ret = av_new_packet(pkt, size + nut->header_len[header_idx]); in decode_frame()
1115 if (nut->header[header_idx]) in decode_frame()
1116 memcpy(pkt->data, nut->header[header_idx], nut->header_len[header_idx]); in decode_frame()
1133 ret = avio_read(bc, pkt->data + nut->header_len[header_idx], size); in decode_frame()
1138 av_shrink_packet(pkt, nut->header_len[header_idx] + ret); in decode_frame()
1153 NUTContext *nut = s->priv_data; in nut_read_packet() local
1160 uint64_t tmp = nut->next_startcode; in nut_read_packet()
1161 nut->next_startcode = 0; in nut_read_packet()
1179 skip = get_packetheader(nut, bc, 0, tmp); in nut_read_packet()
1183 if (decode_info_header(nut) < 0) in nut_read_packet()
1187 if (decode_syncpoint(nut, &ts, &back_ptr) < 0) in nut_read_packet()
1191 ret = decode_frame(nut, pkt, frame_code); in nut_read_packet()
1199 tmp = find_any_startcode(bc, FFMAX(nut->last_syncpoint_pos, nut->last_resync_pos) + 1); in nut_read_packet()
1200 nut->last_resync_pos = avio_tell(bc); in nut_read_packet()
1204 nut->next_startcode = tmp; in nut_read_packet()
1212 NUTContext *nut = s->priv_data; in nut_read_timestamp() local
1225 } while (decode_syncpoint(nut, &pts, &back_ptr) < 0); in nut_read_timestamp()
1227 av_assert0(nut->last_syncpoint_pos == *pos_arg); in nut_read_timestamp()
1239 NUTContext *nut = s->priv_data; in read_seek() local
1247 if (nut->flags & NUT_PIPE) { in read_seek()
1261 av_tree_find(nut->syncpoints, &dummy, ff_nut_sp_pts_cmp, in read_seek()
1276 av_tree_find(nut->syncpoints, &dummy, ff_nut_sp_pos_cmp, in read_seek()
1287 sp = av_tree_find(nut->syncpoints, &dummy, ff_nut_sp_pos_cmp, in read_seek()
1296 nut->last_syncpoint_pos = pos; in read_seek()
1301 nut->stream[i].skip_until_key_frame = 1; in read_seek()
1303 nut->last_resync_pos = 0; in read_seek()