+ tmp_pts = nut->frame_code[i].pts_delta;
+ tmp_flags = nut->frame_code[i].flags;
+ tmp_stream= nut->frame_code[i].stream_id;
+ tmp_mul = nut->frame_code[i].size_mul;
+ tmp_size = nut->frame_code[i].size_lsb;
+// tmp_res = nut->frame_code[i].res;
+ tmp_head_idx= nut->frame_code[i].header_idx;
+
+ for(j=0; i<256; j++,i++){
+ if(i == 'N'){
+ j--;
+ continue;
+ }
+ if(nut->frame_code[i].pts_delta != tmp_pts ) break;
+ if(nut->frame_code[i].flags != tmp_flags ) break;
+ if(nut->frame_code[i].stream_id != tmp_stream) break;
+ if(nut->frame_code[i].size_mul != tmp_mul ) break;
+ if(nut->frame_code[i].size_lsb != tmp_size+j) break;
+// if(nut->frame_code[i].res != tmp_res ) break;
+ if(nut->frame_code[i].header_idx!= tmp_head_idx) break;
+ }
+ if(j != tmp_mul - tmp_size) tmp_fields=6;
+
+ ff_put_v(bc, tmp_flags);
+ ff_put_v(bc, tmp_fields);
+ if(tmp_fields>0) put_s(bc, tmp_pts);
+ if(tmp_fields>1) ff_put_v(bc, tmp_mul);
+ if(tmp_fields>2) ff_put_v(bc, tmp_stream);
+ if(tmp_fields>3) ff_put_v(bc, tmp_size);
+ if(tmp_fields>4) ff_put_v(bc, 0 /*tmp_res*/);
+ if(tmp_fields>5) ff_put_v(bc, j);
+ if(tmp_fields>6) ff_put_v(bc, tmp_match);
+ if(tmp_fields>7) ff_put_v(bc, tmp_head_idx);
+ }
+ ff_put_v(bc, nut->header_count-1);
+ for(i=1; i<nut->header_count; i++){
+ ff_put_v(bc, nut->header_len[i]);
+ avio_write(bc, nut->header[i], nut->header_len[i]);
+ }
+}
+
+static int write_streamheader(AVFormatContext *avctx, AVIOContext *bc, AVStream *st, int i){
+ NUTContext *nut = avctx->priv_data;
+ AVCodecContext *codec = st->codec;
+ ff_put_v(bc, i);
+ switch(codec->codec_type){
+ case AVMEDIA_TYPE_VIDEO: ff_put_v(bc, 0); break;
+ case AVMEDIA_TYPE_AUDIO: ff_put_v(bc, 1); break;
+ case AVMEDIA_TYPE_SUBTITLE: ff_put_v(bc, 2); break;
+ default : ff_put_v(bc, 3); break;
+ }
+ ff_put_v(bc, 4);
+ if (codec->codec_tag){
+ avio_wl32(bc, codec->codec_tag);
+ } else {
+ av_log(avctx, AV_LOG_ERROR, "No codec tag defined for stream %d\n", i);
+ return AVERROR(EINVAL);
+ }
+
+ ff_put_v(bc, nut->stream[i].time_base - nut->time_base);
+ ff_put_v(bc, nut->stream[i].msb_pts_shift);
+ ff_put_v(bc, nut->stream[i].max_pts_distance);
+ ff_put_v(bc, codec->has_b_frames);
+ avio_w8(bc, 0); /* flags: 0x1 - fixed_fps, 0x2 - index_present */
+
+ ff_put_v(bc, codec->extradata_size);
+ avio_write(bc, codec->extradata, codec->extradata_size);
+
+ switch(codec->codec_type){
+ case AVMEDIA_TYPE_AUDIO:
+ ff_put_v(bc, codec->sample_rate);
+ ff_put_v(bc, 1);
+ ff_put_v(bc, codec->channels);
+ break;
+ case AVMEDIA_TYPE_VIDEO:
+ ff_put_v(bc, codec->width);
+ ff_put_v(bc, codec->height);
+
+ if(st->sample_aspect_ratio.num<=0 || st->sample_aspect_ratio.den<=0){
+ ff_put_v(bc, 0);
+ ff_put_v(bc, 0);
+ }else{
+ ff_put_v(bc, st->sample_aspect_ratio.num);
+ ff_put_v(bc, st->sample_aspect_ratio.den);
+ }
+ ff_put_v(bc, 0); /* csp type -- unknown */
+ break;
+ default:
+ break;
+ }