annotate nutenc.c @ 2700:dfcac0102c34 libavformat

Add ff_ prefix to get_v()
author kostya
date Sat, 03 Nov 2007 18:29:16 +0000
parents 153d6efc05b8
children d52c718e83f9
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2324
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
1 /*
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
2 * nut muxer
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
3 * Copyright (c) 2004-2007 Michael Niedermayer
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
4 *
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
5 * This file is part of FFmpeg.
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
6 *
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
7 * FFmpeg is free software; you can redistribute it and/or
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
8 * modify it under the terms of the GNU Lesser General Public
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
9 * License as published by the Free Software Foundation; either
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
10 * version 2.1 of the License, or (at your option) any later version.
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
11 *
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
12 * FFmpeg is distributed in the hope that it will be useful,
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
15 * Lesser General Public License for more details.
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
16 *
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
17 * You should have received a copy of the GNU Lesser General Public
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
18 * License along with FFmpeg; if not, write to the Free Software
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
20 */
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
21
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
22 #include "nut.h"
2350
a0fb5ef1ec7c set back ptr properly
michael
parents: 2347
diff changeset
23 #include "tree.h"
2324
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
24
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
25 static void build_frame_code(AVFormatContext *s){
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
26 NUTContext *nut = s->priv_data;
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
27 int key_frame, index, pred, stream_id;
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
28 int start=1;
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
29 int end= 254;
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
30 int keyframe_0_esc= s->nb_streams > 2;
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
31 int pred_table[10];
2339
2c8579bcd287 add a universal fallback frame code for the case that no other applies
michael
parents: 2332
diff changeset
32 FrameCode *ft;
2c8579bcd287 add a universal fallback frame code for the case that no other applies
michael
parents: 2332
diff changeset
33
2c8579bcd287 add a universal fallback frame code for the case that no other applies
michael
parents: 2332
diff changeset
34 ft= &nut->frame_code[start];
2c8579bcd287 add a universal fallback frame code for the case that no other applies
michael
parents: 2332
diff changeset
35 ft->flags= FLAG_CODED;
2c8579bcd287 add a universal fallback frame code for the case that no other applies
michael
parents: 2332
diff changeset
36 ft->size_mul=1;
2c8579bcd287 add a universal fallback frame code for the case that no other applies
michael
parents: 2332
diff changeset
37 ft->pts_delta=1;
2c8579bcd287 add a universal fallback frame code for the case that no other applies
michael
parents: 2332
diff changeset
38 start++;
2324
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
39
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
40 if(keyframe_0_esc){
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
41 /* keyframe = 0 escape */
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
42 FrameCode *ft= &nut->frame_code[start];
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
43 ft->flags= FLAG_STREAM_ID | FLAG_SIZE_MSB | FLAG_CODED_PTS;
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
44 ft->size_mul=1;
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
45 start++;
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
46 }
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
47
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
48 for(stream_id= 0; stream_id<s->nb_streams; stream_id++){
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
49 int start2= start + (end-start)*stream_id / s->nb_streams;
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
50 int end2 = start + (end-start)*(stream_id+1) / s->nb_streams;
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
51 AVCodecContext *codec = s->streams[stream_id]->codec;
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
52 int is_audio= codec->codec_type == CODEC_TYPE_AUDIO;
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
53 int intra_only= /*codec->intra_only || */is_audio;
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
54 int pred_count;
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
55
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
56 for(key_frame=0; key_frame<2; key_frame++){
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
57 if(intra_only && keyframe_0_esc && key_frame==0)
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
58 continue;
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
59
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
60 {
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
61 FrameCode *ft= &nut->frame_code[start2];
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
62 ft->flags= FLAG_KEY*key_frame;
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
63 ft->flags|= FLAG_SIZE_MSB | FLAG_CODED_PTS;
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
64 ft->stream_id= stream_id;
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
65 ft->size_mul=1;
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
66 start2++;
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
67 }
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
68 }
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
69
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
70 key_frame= intra_only;
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
71 #if 1
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
72 if(is_audio){
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
73 int frame_bytes= codec->frame_size*(int64_t)codec->bit_rate / (8*codec->sample_rate);
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
74 int pts;
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
75 for(pts=0; pts<2; pts++){
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
76 for(pred=0; pred<2; pred++){
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
77 FrameCode *ft= &nut->frame_code[start2];
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
78 ft->flags= FLAG_KEY*key_frame;
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
79 ft->stream_id= stream_id;
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
80 ft->size_mul=frame_bytes + 2;
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
81 ft->size_lsb=frame_bytes + pred;
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
82 ft->pts_delta=pts;
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
83 start2++;
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
84 }
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
85 }
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
86 }else{
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
87 FrameCode *ft= &nut->frame_code[start2];
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
88 ft->flags= FLAG_KEY | FLAG_SIZE_MSB;
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
89 ft->stream_id= stream_id;
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
90 ft->size_mul=1;
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
91 ft->pts_delta=1;
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
92 start2++;
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
93 }
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
94 #endif
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
95
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
96 if(codec->has_b_frames){
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
97 pred_count=5;
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
98 pred_table[0]=-2;
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
99 pred_table[1]=-1;
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
100 pred_table[2]=1;
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
101 pred_table[3]=3;
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
102 pred_table[4]=4;
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
103 }else if(codec->codec_id == CODEC_ID_VORBIS){
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
104 pred_count=3;
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
105 pred_table[0]=2;
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
106 pred_table[1]=9;
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
107 pred_table[2]=16;
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
108 }else{
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
109 pred_count=1;
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
110 pred_table[0]=1;
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
111 }
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
112
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
113 for(pred=0; pred<pred_count; pred++){
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
114 int start3= start2 + (end2-start2)*pred / pred_count;
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
115 int end3 = start2 + (end2-start2)*(pred+1) / pred_count;
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
116
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
117 for(index=start3; index<end3; index++){
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
118 FrameCode *ft= &nut->frame_code[index];
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
119 ft->flags= FLAG_KEY*key_frame;
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
120 ft->flags|= FLAG_SIZE_MSB;
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
121 ft->stream_id= stream_id;
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
122 //FIXME use single byte size and pred from last
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
123 ft->size_mul= end3-start3;
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
124 ft->size_lsb= index - start3;
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
125 ft->pts_delta= pred_table[pred];
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
126 }
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
127 }
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
128 }
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
129 memmove(&nut->frame_code['N'+1], &nut->frame_code['N'], sizeof(FrameCode)*(255-'N'));
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
130 nut->frame_code[ 0].flags=
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
131 nut->frame_code[255].flags=
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
132 nut->frame_code['N'].flags= FLAG_INVALID;
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
133 }
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
134
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
135 /**
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
136 * Gets the length in bytes which is needed to store val as v.
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
137 */
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
138 static int get_length(uint64_t val){
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
139 int i=1;
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
140
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
141 while(val>>=7)
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
142 i++;
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
143
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
144 return i;
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
145 }
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
146
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
147 static void put_v(ByteIOContext *bc, uint64_t val){
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
148 int i= get_length(val);
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
149
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
150 while(--i>0)
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
151 put_byte(bc, 128 | (val>>(7*i)));
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
152
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
153 put_byte(bc, val&127);
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
154 }
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
155
2342
dfb3b2cff096 put_t()
michael
parents: 2341
diff changeset
156 static void put_t(NUTContext *nut, StreamContext *nus, ByteIOContext *bc, uint64_t val){
dfb3b2cff096 put_t()
michael
parents: 2341
diff changeset
157 val *= nut->time_base_count;
dfb3b2cff096 put_t()
michael
parents: 2341
diff changeset
158 val += nus->time_base - nut->time_base;
dfb3b2cff096 put_t()
michael
parents: 2341
diff changeset
159 put_v(bc, val);
dfb3b2cff096 put_t()
michael
parents: 2341
diff changeset
160 }
dfb3b2cff096 put_t()
michael
parents: 2341
diff changeset
161
2324
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
162 /**
2393
fc685315d568 spelling/wording cosmetics
diego
parents: 2372
diff changeset
163 * Stores a string as vb.
2324
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
164 */
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
165 static void put_str(ByteIOContext *bc, const char *string){
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
166 int len= strlen(string);
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
167
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
168 put_v(bc, len);
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
169 put_buffer(bc, string, len);
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
170 }
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
171
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
172 static void put_s(ByteIOContext *bc, int64_t val){
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
173 put_v(bc, 2*FFABS(val) - (val>0));
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
174 }
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
175
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
176 #ifdef TRACE
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
177 static inline void put_v_trace(ByteIOContext *bc, uint64_t v, char *file, char *func, int line){
2344
a7fd892b1a57 get rid of printf
michael
parents: 2343
diff changeset
178 av_log(NULL, AV_LOG_DEBUG, "put_v %5"PRId64" / %"PRIX64" in %s %s:%d\n", v, v, file, func, line);
2324
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
179
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
180 put_v(bc, v);
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
181 }
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
182
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
183 static inline void put_s_trace(ByteIOContext *bc, int64_t v, char *file, char *func, int line){
2344
a7fd892b1a57 get rid of printf
michael
parents: 2343
diff changeset
184 av_log(NULL, AV_LOG_DEBUG, "put_s %5"PRId64" / %"PRIX64" in %s %s:%d\n", v, v, file, func, line);
2324
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
185
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
186 put_s(bc, v);
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
187 }
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
188 #define put_v(bc, v) put_v_trace(bc, v, __FILE__, __PRETTY_FUNCTION__, __LINE__)
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
189 #define put_s(bc, v) put_s_trace(bc, v, __FILE__, __PRETTY_FUNCTION__, __LINE__)
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
190 #endif
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
191
2340
ab5509871fd2 2 FIXME comments
michael
parents: 2339
diff changeset
192 //FIXME remove calculate_checksum
2347
5c32dd0eafc6 fix header_checksum
michael
parents: 2346
diff changeset
193 static void put_packet(NUTContext *nut, ByteIOContext *bc, ByteIOContext *dyn_bc, int calculate_checksum, uint64_t startcode){
2331
4d1a56112d92 use a dynamic ByteIOContext instead of using the lavf buffer
michael
parents: 2330
diff changeset
194 uint8_t *dyn_buf=NULL;
4d1a56112d92 use a dynamic ByteIOContext instead of using the lavf buffer
michael
parents: 2330
diff changeset
195 int dyn_size= url_close_dyn_buf(dyn_bc, &dyn_buf);
2332
7dd23262372f forw_ptr CRC
michael
parents: 2331
diff changeset
196 int forw_ptr= dyn_size + 4*calculate_checksum;
2324
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
197
2332
7dd23262372f forw_ptr CRC
michael
parents: 2331
diff changeset
198 if(forw_ptr > 4096)
2683
153d6efc05b8 rename av_crc04C11DB7_update to ff_crc04C11DB7_update and move it to aviobuf.c so it can be reused by other (de)muxers
bcoudurier
parents: 2393
diff changeset
199 init_checksum(bc, ff_crc04C11DB7_update, 0);
2347
5c32dd0eafc6 fix header_checksum
michael
parents: 2346
diff changeset
200 put_be64(bc, startcode);
2332
7dd23262372f forw_ptr CRC
michael
parents: 2331
diff changeset
201 put_v(bc, forw_ptr);
7dd23262372f forw_ptr CRC
michael
parents: 2331
diff changeset
202 if(forw_ptr > 4096)
7dd23262372f forw_ptr CRC
michael
parents: 2331
diff changeset
203 put_le32(bc, get_checksum(bc));
7dd23262372f forw_ptr CRC
michael
parents: 2331
diff changeset
204
2324
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
205 if(calculate_checksum)
2683
153d6efc05b8 rename av_crc04C11DB7_update to ff_crc04C11DB7_update and move it to aviobuf.c so it can be reused by other (de)muxers
bcoudurier
parents: 2393
diff changeset
206 init_checksum(bc, ff_crc04C11DB7_update, 0);
2331
4d1a56112d92 use a dynamic ByteIOContext instead of using the lavf buffer
michael
parents: 2330
diff changeset
207 put_buffer(bc, dyn_buf, dyn_size);
2324
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
208 if(calculate_checksum)
2331
4d1a56112d92 use a dynamic ByteIOContext instead of using the lavf buffer
michael
parents: 2330
diff changeset
209 put_le32(bc, get_checksum(bc));
2324
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
210
2331
4d1a56112d92 use a dynamic ByteIOContext instead of using the lavf buffer
michael
parents: 2330
diff changeset
211 av_free(dyn_buf);
2324
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
212 }
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
213
2329
57a352c5b051 move main header writing into its own function
michael
parents: 2328
diff changeset
214 static void write_mainheader(NUTContext *nut, ByteIOContext *bc){
2324
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
215 int i, j, tmp_pts, tmp_flags, tmp_stream, tmp_mul, tmp_size, tmp_fields;
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
216
2360
b2eeaa4df665 muxer should now be spec compliant (though it likely still contains bugs!)
michael
parents: 2359
diff changeset
217 put_v(bc, 3); /* version */
2329
57a352c5b051 move main header writing into its own function
michael
parents: 2328
diff changeset
218 put_v(bc, nut->avf->nb_streams);
2324
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
219 put_v(bc, MAX_DISTANCE);
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
220 put_v(bc, nut->time_base_count);
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
221
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
222 for(i=0; i<nut->time_base_count; i++){
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
223 put_v(bc, nut->time_base[i].num);
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
224 put_v(bc, nut->time_base[i].den);
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
225 }
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
226
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
227 tmp_pts=0;
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
228 tmp_mul=1;
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
229 tmp_stream=0;
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
230 for(i=0; i<256;){
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
231 tmp_fields=0;
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
232 tmp_size=0;
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
233 // tmp_res=0;
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
234 if(tmp_pts != nut->frame_code[i].pts_delta) tmp_fields=1;
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
235 if(tmp_mul != nut->frame_code[i].size_mul ) tmp_fields=2;
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
236 if(tmp_stream != nut->frame_code[i].stream_id) tmp_fields=3;
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
237 if(tmp_size != nut->frame_code[i].size_lsb ) tmp_fields=4;
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
238 // if(tmp_res != nut->frame_code[i].res ) tmp_fields=5;
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
239
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
240 tmp_pts = nut->frame_code[i].pts_delta;
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
241 tmp_flags = nut->frame_code[i].flags;
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
242 tmp_stream= nut->frame_code[i].stream_id;
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
243 tmp_mul = nut->frame_code[i].size_mul;
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
244 tmp_size = nut->frame_code[i].size_lsb;
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
245 // tmp_res = nut->frame_code[i].res;
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
246
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
247 for(j=0; i<256; j++,i++){
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
248 if(i == 'N'){
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
249 j--;
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
250 continue;
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
251 }
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
252 if(nut->frame_code[i].pts_delta != tmp_pts ) break;
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
253 if(nut->frame_code[i].flags != tmp_flags ) break;
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
254 if(nut->frame_code[i].stream_id != tmp_stream) break;
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
255 if(nut->frame_code[i].size_mul != tmp_mul ) break;
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
256 if(nut->frame_code[i].size_lsb != tmp_size+j) break;
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
257 // if(nut->frame_code[i].res != tmp_res ) break;
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
258 }
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
259 if(j != tmp_mul - tmp_size) tmp_fields=6;
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
260
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
261 put_v(bc, tmp_flags);
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
262 put_v(bc, tmp_fields);
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
263 if(tmp_fields>0) put_s(bc, tmp_pts);
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
264 if(tmp_fields>1) put_v(bc, tmp_mul);
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
265 if(tmp_fields>2) put_v(bc, tmp_stream);
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
266 if(tmp_fields>3) put_v(bc, tmp_size);
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
267 if(tmp_fields>4) put_v(bc, 0 /*tmp_res*/);
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
268 if(tmp_fields>5) put_v(bc, j);
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
269 }
2329
57a352c5b051 move main header writing into its own function
michael
parents: 2328
diff changeset
270 }
2324
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
271
2330
c25f63f009a8 move stream header writing into its own function
michael
parents: 2329
diff changeset
272 static int write_streamheader(NUTContext *nut, ByteIOContext *bc, AVCodecContext *codec, int i){
c25f63f009a8 move stream header writing into its own function
michael
parents: 2329
diff changeset
273 put_v(bc, i);
c25f63f009a8 move stream header writing into its own function
michael
parents: 2329
diff changeset
274 switch(codec->codec_type){
c25f63f009a8 move stream header writing into its own function
michael
parents: 2329
diff changeset
275 case CODEC_TYPE_VIDEO: put_v(bc, 0); break;
c25f63f009a8 move stream header writing into its own function
michael
parents: 2329
diff changeset
276 case CODEC_TYPE_AUDIO: put_v(bc, 1); break;
c25f63f009a8 move stream header writing into its own function
michael
parents: 2329
diff changeset
277 // case CODEC_TYPE_TEXT : put_v(bc, 2); break;
c25f63f009a8 move stream header writing into its own function
michael
parents: 2329
diff changeset
278 default : put_v(bc, 3); break;
c25f63f009a8 move stream header writing into its own function
michael
parents: 2329
diff changeset
279 }
c25f63f009a8 move stream header writing into its own function
michael
parents: 2329
diff changeset
280 put_v(bc, 4);
c25f63f009a8 move stream header writing into its own function
michael
parents: 2329
diff changeset
281 if (codec->codec_tag){
c25f63f009a8 move stream header writing into its own function
michael
parents: 2329
diff changeset
282 put_le32(bc, codec->codec_tag);
c25f63f009a8 move stream header writing into its own function
michael
parents: 2329
diff changeset
283 }else
c25f63f009a8 move stream header writing into its own function
michael
parents: 2329
diff changeset
284 return -1;
c25f63f009a8 move stream header writing into its own function
michael
parents: 2329
diff changeset
285
2341
michael
parents: 2340
diff changeset
286 put_v(bc, nut->stream[i].time_base - nut->time_base);
2330
c25f63f009a8 move stream header writing into its own function
michael
parents: 2329
diff changeset
287 put_v(bc, nut->stream[i].msb_pts_shift);
c25f63f009a8 move stream header writing into its own function
michael
parents: 2329
diff changeset
288 put_v(bc, nut->stream[i].max_pts_distance);
c25f63f009a8 move stream header writing into its own function
michael
parents: 2329
diff changeset
289 put_v(bc, codec->has_b_frames);
c25f63f009a8 move stream header writing into its own function
michael
parents: 2329
diff changeset
290 put_byte(bc, 0); /* flags: 0x1 - fixed_fps, 0x2 - index_present */
c25f63f009a8 move stream header writing into its own function
michael
parents: 2329
diff changeset
291
c25f63f009a8 move stream header writing into its own function
michael
parents: 2329
diff changeset
292 put_v(bc, codec->extradata_size);
c25f63f009a8 move stream header writing into its own function
michael
parents: 2329
diff changeset
293 put_buffer(bc, codec->extradata, codec->extradata_size);
c25f63f009a8 move stream header writing into its own function
michael
parents: 2329
diff changeset
294
c25f63f009a8 move stream header writing into its own function
michael
parents: 2329
diff changeset
295 switch(codec->codec_type){
c25f63f009a8 move stream header writing into its own function
michael
parents: 2329
diff changeset
296 case CODEC_TYPE_AUDIO:
c25f63f009a8 move stream header writing into its own function
michael
parents: 2329
diff changeset
297 put_v(bc, codec->sample_rate);
c25f63f009a8 move stream header writing into its own function
michael
parents: 2329
diff changeset
298 put_v(bc, 1);
c25f63f009a8 move stream header writing into its own function
michael
parents: 2329
diff changeset
299 put_v(bc, codec->channels);
c25f63f009a8 move stream header writing into its own function
michael
parents: 2329
diff changeset
300 break;
c25f63f009a8 move stream header writing into its own function
michael
parents: 2329
diff changeset
301 case CODEC_TYPE_VIDEO:
c25f63f009a8 move stream header writing into its own function
michael
parents: 2329
diff changeset
302 put_v(bc, codec->width);
c25f63f009a8 move stream header writing into its own function
michael
parents: 2329
diff changeset
303 put_v(bc, codec->height);
2363
3f3a4b5fc5bb ensure that the aspect ratio is spec compliant
michael
parents: 2361
diff changeset
304
3f3a4b5fc5bb ensure that the aspect ratio is spec compliant
michael
parents: 2361
diff changeset
305 if(codec->sample_aspect_ratio.num<=0 || codec->sample_aspect_ratio.den<=0){
3f3a4b5fc5bb ensure that the aspect ratio is spec compliant
michael
parents: 2361
diff changeset
306 put_v(bc, 0);
3f3a4b5fc5bb ensure that the aspect ratio is spec compliant
michael
parents: 2361
diff changeset
307 put_v(bc, 0);
3f3a4b5fc5bb ensure that the aspect ratio is spec compliant
michael
parents: 2361
diff changeset
308 }else{
3f3a4b5fc5bb ensure that the aspect ratio is spec compliant
michael
parents: 2361
diff changeset
309 put_v(bc, codec->sample_aspect_ratio.num);
3f3a4b5fc5bb ensure that the aspect ratio is spec compliant
michael
parents: 2361
diff changeset
310 put_v(bc, codec->sample_aspect_ratio.den);
3f3a4b5fc5bb ensure that the aspect ratio is spec compliant
michael
parents: 2361
diff changeset
311 }
2330
c25f63f009a8 move stream header writing into its own function
michael
parents: 2329
diff changeset
312 put_v(bc, 0); /* csp type -- unknown */
c25f63f009a8 move stream header writing into its own function
michael
parents: 2329
diff changeset
313 break;
c25f63f009a8 move stream header writing into its own function
michael
parents: 2329
diff changeset
314 default:
c25f63f009a8 move stream header writing into its own function
michael
parents: 2329
diff changeset
315 break;
c25f63f009a8 move stream header writing into its own function
michael
parents: 2329
diff changeset
316 }
c25f63f009a8 move stream header writing into its own function
michael
parents: 2329
diff changeset
317 return 0;
c25f63f009a8 move stream header writing into its own function
michael
parents: 2329
diff changeset
318 }
c25f63f009a8 move stream header writing into its own function
michael
parents: 2329
diff changeset
319
2358
ed9b81f74317 info packet
michael
parents: 2355
diff changeset
320 static int add_info(ByteIOContext *bc, char *type, char *value){
ed9b81f74317 info packet
michael
parents: 2355
diff changeset
321 put_str(bc, type);
ed9b81f74317 info packet
michael
parents: 2355
diff changeset
322 put_s(bc, -1);
ed9b81f74317 info packet
michael
parents: 2355
diff changeset
323 put_str(bc, value);
ed9b81f74317 info packet
michael
parents: 2355
diff changeset
324 return 1;
ed9b81f74317 info packet
michael
parents: 2355
diff changeset
325 }
ed9b81f74317 info packet
michael
parents: 2355
diff changeset
326
ed9b81f74317 info packet
michael
parents: 2355
diff changeset
327 static void write_globalinfo(NUTContext *nut, ByteIOContext *bc){
ed9b81f74317 info packet
michael
parents: 2355
diff changeset
328 AVFormatContext *s= nut->avf;
ed9b81f74317 info packet
michael
parents: 2355
diff changeset
329 ByteIOContext dyn_bc;
ed9b81f74317 info packet
michael
parents: 2355
diff changeset
330 uint8_t *dyn_buf=NULL;
ed9b81f74317 info packet
michael
parents: 2355
diff changeset
331 int count=0, dyn_size;
ed9b81f74317 info packet
michael
parents: 2355
diff changeset
332
ed9b81f74317 info packet
michael
parents: 2355
diff changeset
333 url_open_dyn_buf(&dyn_bc);
ed9b81f74317 info packet
michael
parents: 2355
diff changeset
334
ed9b81f74317 info packet
michael
parents: 2355
diff changeset
335 if(s->title [0]) count+= add_info(&dyn_bc, "Title" , s->title);
ed9b81f74317 info packet
michael
parents: 2355
diff changeset
336 if(s->author [0]) count+= add_info(&dyn_bc, "Author" , s->author);
ed9b81f74317 info packet
michael
parents: 2355
diff changeset
337 if(s->copyright[0]) count+= add_info(&dyn_bc, "Copyright", s->copyright);
ed9b81f74317 info packet
michael
parents: 2355
diff changeset
338 if(!(s->streams[0]->codec->flags & CODEC_FLAG_BITEXACT))
ed9b81f74317 info packet
michael
parents: 2355
diff changeset
339 count+= add_info(&dyn_bc, "Encoder" , LIBAVFORMAT_IDENT);
ed9b81f74317 info packet
michael
parents: 2355
diff changeset
340
ed9b81f74317 info packet
michael
parents: 2355
diff changeset
341 put_v(bc, 0); //stream_if_plus1
ed9b81f74317 info packet
michael
parents: 2355
diff changeset
342 put_v(bc, 0); //chapter_id
ed9b81f74317 info packet
michael
parents: 2355
diff changeset
343 put_v(bc, 0); //timestamp_start
ed9b81f74317 info packet
michael
parents: 2355
diff changeset
344 put_v(bc, 0); //length
ed9b81f74317 info packet
michael
parents: 2355
diff changeset
345
ed9b81f74317 info packet
michael
parents: 2355
diff changeset
346 put_v(bc, count);
ed9b81f74317 info packet
michael
parents: 2355
diff changeset
347
ed9b81f74317 info packet
michael
parents: 2355
diff changeset
348 dyn_size= url_close_dyn_buf(&dyn_bc, &dyn_buf);
ed9b81f74317 info packet
michael
parents: 2355
diff changeset
349 put_buffer(bc, dyn_buf, dyn_size);
ed9b81f74317 info packet
michael
parents: 2355
diff changeset
350 av_free(dyn_buf);
ed9b81f74317 info packet
michael
parents: 2355
diff changeset
351 }
ed9b81f74317 info packet
michael
parents: 2355
diff changeset
352
2345
b73b443c43d0 move header writing into its own function
michael
parents: 2344
diff changeset
353 static void write_headers(NUTContext *nut, ByteIOContext *bc){
b73b443c43d0 move header writing into its own function
michael
parents: 2344
diff changeset
354 ByteIOContext dyn_bc;
b73b443c43d0 move header writing into its own function
michael
parents: 2344
diff changeset
355 int i;
b73b443c43d0 move header writing into its own function
michael
parents: 2344
diff changeset
356
b73b443c43d0 move header writing into its own function
michael
parents: 2344
diff changeset
357 url_open_dyn_buf(&dyn_bc);
b73b443c43d0 move header writing into its own function
michael
parents: 2344
diff changeset
358 write_mainheader(nut, &dyn_bc);
2347
5c32dd0eafc6 fix header_checksum
michael
parents: 2346
diff changeset
359 put_packet(nut, bc, &dyn_bc, 1, MAIN_STARTCODE);
2345
b73b443c43d0 move header writing into its own function
michael
parents: 2344
diff changeset
360
b73b443c43d0 move header writing into its own function
michael
parents: 2344
diff changeset
361 for (i=0; i < nut->avf->nb_streams; i++){
b73b443c43d0 move header writing into its own function
michael
parents: 2344
diff changeset
362 AVCodecContext *codec = nut->avf->streams[i]->codec;
b73b443c43d0 move header writing into its own function
michael
parents: 2344
diff changeset
363
b73b443c43d0 move header writing into its own function
michael
parents: 2344
diff changeset
364 url_open_dyn_buf(&dyn_bc);
b73b443c43d0 move header writing into its own function
michael
parents: 2344
diff changeset
365 write_streamheader(nut, &dyn_bc, codec, i);
2347
5c32dd0eafc6 fix header_checksum
michael
parents: 2346
diff changeset
366 put_packet(nut, bc, &dyn_bc, 1, STREAM_STARTCODE);
2345
b73b443c43d0 move header writing into its own function
michael
parents: 2344
diff changeset
367 }
2358
ed9b81f74317 info packet
michael
parents: 2355
diff changeset
368
ed9b81f74317 info packet
michael
parents: 2355
diff changeset
369 url_open_dyn_buf(&dyn_bc);
ed9b81f74317 info packet
michael
parents: 2355
diff changeset
370 write_globalinfo(nut, &dyn_bc);
ed9b81f74317 info packet
michael
parents: 2355
diff changeset
371 put_packet(nut, bc, &dyn_bc, 1, INFO_STARTCODE);
2359
1860d5b4be2e header repetition
michael
parents: 2358
diff changeset
372
1860d5b4be2e header repetition
michael
parents: 2358
diff changeset
373 nut->last_syncpoint_pos= INT_MIN;
1860d5b4be2e header repetition
michael
parents: 2358
diff changeset
374 nut->header_count++;
2345
b73b443c43d0 move header writing into its own function
michael
parents: 2344
diff changeset
375 }
b73b443c43d0 move header writing into its own function
michael
parents: 2344
diff changeset
376
2329
57a352c5b051 move main header writing into its own function
michael
parents: 2328
diff changeset
377 static int write_header(AVFormatContext *s){
57a352c5b051 move main header writing into its own function
michael
parents: 2328
diff changeset
378 NUTContext *nut = s->priv_data;
2345
b73b443c43d0 move header writing into its own function
michael
parents: 2344
diff changeset
379 ByteIOContext *bc = &s->pb;
2329
57a352c5b051 move main header writing into its own function
michael
parents: 2328
diff changeset
380 int i, j;
57a352c5b051 move main header writing into its own function
michael
parents: 2328
diff changeset
381
57a352c5b051 move main header writing into its own function
michael
parents: 2328
diff changeset
382 nut->avf= s;
57a352c5b051 move main header writing into its own function
michael
parents: 2328
diff changeset
383
57a352c5b051 move main header writing into its own function
michael
parents: 2328
diff changeset
384 nut->stream = av_mallocz(sizeof(StreamContext)*s->nb_streams);
57a352c5b051 move main header writing into its own function
michael
parents: 2328
diff changeset
385 nut->time_base= av_mallocz(sizeof(AVRational )*s->nb_streams);
57a352c5b051 move main header writing into its own function
michael
parents: 2328
diff changeset
386
57a352c5b051 move main header writing into its own function
michael
parents: 2328
diff changeset
387 for(i=0; i<s->nb_streams; i++){
57a352c5b051 move main header writing into its own function
michael
parents: 2328
diff changeset
388 AVStream *st= s->streams[i];
57a352c5b051 move main header writing into its own function
michael
parents: 2328
diff changeset
389 int ssize;
57a352c5b051 move main header writing into its own function
michael
parents: 2328
diff changeset
390 AVRational time_base;
57a352c5b051 move main header writing into its own function
michael
parents: 2328
diff changeset
391 ff_parse_specific_params(st->codec, &time_base.den, &ssize, &time_base.num);
57a352c5b051 move main header writing into its own function
michael
parents: 2328
diff changeset
392
57a352c5b051 move main header writing into its own function
michael
parents: 2328
diff changeset
393 av_set_pts_info(st, 64, time_base.num, time_base.den);
57a352c5b051 move main header writing into its own function
michael
parents: 2328
diff changeset
394
57a352c5b051 move main header writing into its own function
michael
parents: 2328
diff changeset
395 for(j=0; j<nut->time_base_count; j++){
57a352c5b051 move main header writing into its own function
michael
parents: 2328
diff changeset
396 if(!memcmp(&time_base, &nut->time_base[j], sizeof(AVRational))){
57a352c5b051 move main header writing into its own function
michael
parents: 2328
diff changeset
397 break;
57a352c5b051 move main header writing into its own function
michael
parents: 2328
diff changeset
398 }
57a352c5b051 move main header writing into its own function
michael
parents: 2328
diff changeset
399 }
57a352c5b051 move main header writing into its own function
michael
parents: 2328
diff changeset
400 nut->time_base[j]= time_base;
57a352c5b051 move main header writing into its own function
michael
parents: 2328
diff changeset
401 nut->stream[i].time_base= &nut->time_base[j];
57a352c5b051 move main header writing into its own function
michael
parents: 2328
diff changeset
402 if(j==nut->time_base_count)
57a352c5b051 move main header writing into its own function
michael
parents: 2328
diff changeset
403 nut->time_base_count++;
57a352c5b051 move main header writing into its own function
michael
parents: 2328
diff changeset
404
57a352c5b051 move main header writing into its own function
michael
parents: 2328
diff changeset
405 if(av_q2d(time_base) >= 0.001)
57a352c5b051 move main header writing into its own function
michael
parents: 2328
diff changeset
406 nut->stream[i].msb_pts_shift = 7;
57a352c5b051 move main header writing into its own function
michael
parents: 2328
diff changeset
407 else
57a352c5b051 move main header writing into its own function
michael
parents: 2328
diff changeset
408 nut->stream[i].msb_pts_shift = 14;
57a352c5b051 move main header writing into its own function
michael
parents: 2328
diff changeset
409 nut->stream[i].max_pts_distance= FFMAX(1/av_q2d(time_base), 1);
57a352c5b051 move main header writing into its own function
michael
parents: 2328
diff changeset
410 }
57a352c5b051 move main header writing into its own function
michael
parents: 2328
diff changeset
411
57a352c5b051 move main header writing into its own function
michael
parents: 2328
diff changeset
412 build_frame_code(s);
57a352c5b051 move main header writing into its own function
michael
parents: 2328
diff changeset
413 assert(nut->frame_code['N'].flags == FLAG_INVALID);
57a352c5b051 move main header writing into its own function
michael
parents: 2328
diff changeset
414
57a352c5b051 move main header writing into its own function
michael
parents: 2328
diff changeset
415 put_buffer(bc, ID_STRING, strlen(ID_STRING));
57a352c5b051 move main header writing into its own function
michael
parents: 2328
diff changeset
416 put_byte(bc, 0);
57a352c5b051 move main header writing into its own function
michael
parents: 2328
diff changeset
417
2345
b73b443c43d0 move header writing into its own function
michael
parents: 2344
diff changeset
418 write_headers(nut, bc);
2325
2829faf72879 write stream headers
michael
parents: 2324
diff changeset
419
2324
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
420 put_flush_packet(bc);
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
421
2359
1860d5b4be2e header repetition
michael
parents: 2358
diff changeset
422 //FIXME index
2324
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
423
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
424 return 0;
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
425 }
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
426
2343
c6a7a89a0cef write frames and syncpoints
michael
parents: 2342
diff changeset
427 static int get_needed_flags(NUTContext *nut, StreamContext *nus, FrameCode *fc, AVPacket *pkt){
c6a7a89a0cef write frames and syncpoints
michael
parents: 2342
diff changeset
428 int flags= 0;
c6a7a89a0cef write frames and syncpoints
michael
parents: 2342
diff changeset
429
c6a7a89a0cef write frames and syncpoints
michael
parents: 2342
diff changeset
430 if(pkt->flags & PKT_FLAG_KEY ) flags |= FLAG_KEY;
c6a7a89a0cef write frames and syncpoints
michael
parents: 2342
diff changeset
431 if(pkt->stream_index != fc->stream_id ) flags |= FLAG_STREAM_ID;
c6a7a89a0cef write frames and syncpoints
michael
parents: 2342
diff changeset
432 if(pkt->size / fc->size_mul ) flags |= FLAG_SIZE_MSB;
c6a7a89a0cef write frames and syncpoints
michael
parents: 2342
diff changeset
433 if(pkt->pts - nus->last_pts != fc->pts_delta) flags |= FLAG_CODED_PTS;
c6a7a89a0cef write frames and syncpoints
michael
parents: 2342
diff changeset
434 if(pkt->size > 2*nut->max_distance ) flags |= FLAG_CHECKSUM;
c6a7a89a0cef write frames and syncpoints
michael
parents: 2342
diff changeset
435 if(FFABS(pkt->pts - nus->last_pts)
c6a7a89a0cef write frames and syncpoints
michael
parents: 2342
diff changeset
436 > nus->max_pts_distance) flags |= FLAG_CHECKSUM;
c6a7a89a0cef write frames and syncpoints
michael
parents: 2342
diff changeset
437
2371
253901bf60b7 do not remove FLAG_CODED
michael
parents: 2370
diff changeset
438 return flags | (fc->flags & FLAG_CODED);
2343
c6a7a89a0cef write frames and syncpoints
michael
parents: 2342
diff changeset
439 }
c6a7a89a0cef write frames and syncpoints
michael
parents: 2342
diff changeset
440
2324
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
441 static int write_packet(AVFormatContext *s, AVPacket *pkt){
2343
c6a7a89a0cef write frames and syncpoints
michael
parents: 2342
diff changeset
442 NUTContext *nut = s->priv_data;
c6a7a89a0cef write frames and syncpoints
michael
parents: 2342
diff changeset
443 StreamContext *nus= &nut->stream[pkt->stream_index];
c6a7a89a0cef write frames and syncpoints
michael
parents: 2342
diff changeset
444 ByteIOContext *bc = &s->pb, dyn_bc;
c6a7a89a0cef write frames and syncpoints
michael
parents: 2342
diff changeset
445 FrameCode *fc;
c6a7a89a0cef write frames and syncpoints
michael
parents: 2342
diff changeset
446 int64_t coded_pts;
c6a7a89a0cef write frames and syncpoints
michael
parents: 2342
diff changeset
447 int best_length, frame_code, flags, needed_flags, i;
c6a7a89a0cef write frames and syncpoints
michael
parents: 2342
diff changeset
448 int key_frame = !!(pkt->flags & PKT_FLAG_KEY);
c6a7a89a0cef write frames and syncpoints
michael
parents: 2342
diff changeset
449 int store_sp=0;
c6a7a89a0cef write frames and syncpoints
michael
parents: 2342
diff changeset
450
2359
1860d5b4be2e header repetition
michael
parents: 2358
diff changeset
451 if(1LL<<(20+3*nut->header_count) <= url_ftell(bc))
1860d5b4be2e header repetition
michael
parents: 2358
diff changeset
452 write_headers(nut, bc);
1860d5b4be2e header repetition
michael
parents: 2358
diff changeset
453
2343
c6a7a89a0cef write frames and syncpoints
michael
parents: 2342
diff changeset
454 if(key_frame && !!(nus->last_flags & FLAG_KEY))
c6a7a89a0cef write frames and syncpoints
michael
parents: 2342
diff changeset
455 store_sp= 1;
c6a7a89a0cef write frames and syncpoints
michael
parents: 2342
diff changeset
456
c6a7a89a0cef write frames and syncpoints
michael
parents: 2342
diff changeset
457 if(pkt->size + 30/*FIXME check*/ + url_ftell(bc) >= nut->last_syncpoint_pos + nut->max_distance)
c6a7a89a0cef write frames and syncpoints
michael
parents: 2342
diff changeset
458 store_sp= 1;
c6a7a89a0cef write frames and syncpoints
michael
parents: 2342
diff changeset
459
2393
fc685315d568 spelling/wording cosmetics
diego
parents: 2372
diff changeset
460 //FIXME: Ensure store_sp is 1 in the first place.
2343
c6a7a89a0cef write frames and syncpoints
michael
parents: 2342
diff changeset
461
c6a7a89a0cef write frames and syncpoints
michael
parents: 2342
diff changeset
462 if(store_sp){
2350
a0fb5ef1ec7c set back ptr properly
michael
parents: 2347
diff changeset
463 syncpoint_t *sp, dummy= {.pos= INT64_MAX};
a0fb5ef1ec7c set back ptr properly
michael
parents: 2347
diff changeset
464
2343
c6a7a89a0cef write frames and syncpoints
michael
parents: 2342
diff changeset
465 ff_nut_reset_ts(nut, *nus->time_base, pkt->dts);
2350
a0fb5ef1ec7c set back ptr properly
michael
parents: 2347
diff changeset
466 for(i=0; i<s->nb_streams; i++){
a0fb5ef1ec7c set back ptr properly
michael
parents: 2347
diff changeset
467 AVStream *st= s->streams[i];
a0fb5ef1ec7c set back ptr properly
michael
parents: 2347
diff changeset
468 int index= av_index_search_timestamp(st, pkt->dts, AVSEEK_FLAG_BACKWARD);
a0fb5ef1ec7c set back ptr properly
michael
parents: 2347
diff changeset
469 if(index<0) dummy.pos=0;
a0fb5ef1ec7c set back ptr properly
michael
parents: 2347
diff changeset
470 else dummy.pos= FFMIN(dummy.pos, st->index_entries[index].pos);
a0fb5ef1ec7c set back ptr properly
michael
parents: 2347
diff changeset
471 }
a0fb5ef1ec7c set back ptr properly
michael
parents: 2347
diff changeset
472 sp= av_tree_find(nut->syncpoints, &dummy, ff_nut_sp_pos_cmp, NULL);
2343
c6a7a89a0cef write frames and syncpoints
michael
parents: 2342
diff changeset
473
c6a7a89a0cef write frames and syncpoints
michael
parents: 2342
diff changeset
474 nut->last_syncpoint_pos= url_ftell(bc);
c6a7a89a0cef write frames and syncpoints
michael
parents: 2342
diff changeset
475 url_open_dyn_buf(&dyn_bc);
c6a7a89a0cef write frames and syncpoints
michael
parents: 2342
diff changeset
476 put_t(nut, nus, &dyn_bc, pkt->dts);
2350
a0fb5ef1ec7c set back ptr properly
michael
parents: 2347
diff changeset
477 put_v(&dyn_bc, sp ? (nut->last_syncpoint_pos - sp->pos)>>4 : 0);
2347
5c32dd0eafc6 fix header_checksum
michael
parents: 2346
diff changeset
478 put_packet(nut, bc, &dyn_bc, 1, SYNCPOINT_STARTCODE);
2350
a0fb5ef1ec7c set back ptr properly
michael
parents: 2347
diff changeset
479
a0fb5ef1ec7c set back ptr properly
michael
parents: 2347
diff changeset
480 ff_nut_add_sp(nut, nut->last_syncpoint_pos, 0/*unused*/, pkt->dts);
2343
c6a7a89a0cef write frames and syncpoints
michael
parents: 2342
diff changeset
481 }
c6a7a89a0cef write frames and syncpoints
michael
parents: 2342
diff changeset
482 assert(nus->last_pts != AV_NOPTS_VALUE);
c6a7a89a0cef write frames and syncpoints
michael
parents: 2342
diff changeset
483
c6a7a89a0cef write frames and syncpoints
michael
parents: 2342
diff changeset
484 coded_pts = pkt->pts & ((1<<nus->msb_pts_shift)-1);
c6a7a89a0cef write frames and syncpoints
michael
parents: 2342
diff changeset
485 if(ff_lsb2full(nus, coded_pts) != pkt->pts)
c6a7a89a0cef write frames and syncpoints
michael
parents: 2342
diff changeset
486 coded_pts= pkt->pts + (1<<nus->msb_pts_shift);
c6a7a89a0cef write frames and syncpoints
michael
parents: 2342
diff changeset
487
c6a7a89a0cef write frames and syncpoints
michael
parents: 2342
diff changeset
488 best_length=INT_MAX;
c6a7a89a0cef write frames and syncpoints
michael
parents: 2342
diff changeset
489 frame_code= -1;
c6a7a89a0cef write frames and syncpoints
michael
parents: 2342
diff changeset
490 for(i=0; i<256; i++){
c6a7a89a0cef write frames and syncpoints
michael
parents: 2342
diff changeset
491 int length= 0;
c6a7a89a0cef write frames and syncpoints
michael
parents: 2342
diff changeset
492 FrameCode *fc= &nut->frame_code[i];
c6a7a89a0cef write frames and syncpoints
michael
parents: 2342
diff changeset
493 int flags= fc->flags;
c6a7a89a0cef write frames and syncpoints
michael
parents: 2342
diff changeset
494
c6a7a89a0cef write frames and syncpoints
michael
parents: 2342
diff changeset
495 if(flags & FLAG_INVALID)
c6a7a89a0cef write frames and syncpoints
michael
parents: 2342
diff changeset
496 continue;
c6a7a89a0cef write frames and syncpoints
michael
parents: 2342
diff changeset
497 needed_flags= get_needed_flags(nut, nus, fc, pkt);
c6a7a89a0cef write frames and syncpoints
michael
parents: 2342
diff changeset
498
c6a7a89a0cef write frames and syncpoints
michael
parents: 2342
diff changeset
499 if(flags & FLAG_CODED){
c6a7a89a0cef write frames and syncpoints
michael
parents: 2342
diff changeset
500 length++;
2372
5c3d8e112e79 simplify
michael
parents: 2371
diff changeset
501 flags = needed_flags;
2343
c6a7a89a0cef write frames and syncpoints
michael
parents: 2342
diff changeset
502 }
c6a7a89a0cef write frames and syncpoints
michael
parents: 2342
diff changeset
503
c6a7a89a0cef write frames and syncpoints
michael
parents: 2342
diff changeset
504 if((flags & needed_flags) != needed_flags)
c6a7a89a0cef write frames and syncpoints
michael
parents: 2342
diff changeset
505 continue;
c6a7a89a0cef write frames and syncpoints
michael
parents: 2342
diff changeset
506
c6a7a89a0cef write frames and syncpoints
michael
parents: 2342
diff changeset
507 if((flags ^ needed_flags) & FLAG_KEY)
c6a7a89a0cef write frames and syncpoints
michael
parents: 2342
diff changeset
508 continue;
c6a7a89a0cef write frames and syncpoints
michael
parents: 2342
diff changeset
509
c6a7a89a0cef write frames and syncpoints
michael
parents: 2342
diff changeset
510 if(flags & FLAG_STREAM_ID)
c6a7a89a0cef write frames and syncpoints
michael
parents: 2342
diff changeset
511 length+= get_length(pkt->stream_index);
c6a7a89a0cef write frames and syncpoints
michael
parents: 2342
diff changeset
512
c6a7a89a0cef write frames and syncpoints
michael
parents: 2342
diff changeset
513 if(pkt->size % fc->size_mul != fc->size_lsb)
c6a7a89a0cef write frames and syncpoints
michael
parents: 2342
diff changeset
514 continue;
c6a7a89a0cef write frames and syncpoints
michael
parents: 2342
diff changeset
515 if(flags & FLAG_SIZE_MSB)
c6a7a89a0cef write frames and syncpoints
michael
parents: 2342
diff changeset
516 length += get_length(pkt->size / fc->size_mul);
c6a7a89a0cef write frames and syncpoints
michael
parents: 2342
diff changeset
517
c6a7a89a0cef write frames and syncpoints
michael
parents: 2342
diff changeset
518 if(flags & FLAG_CHECKSUM)
c6a7a89a0cef write frames and syncpoints
michael
parents: 2342
diff changeset
519 length+=4;
c6a7a89a0cef write frames and syncpoints
michael
parents: 2342
diff changeset
520
c6a7a89a0cef write frames and syncpoints
michael
parents: 2342
diff changeset
521 if(flags & FLAG_CODED_PTS)
c6a7a89a0cef write frames and syncpoints
michael
parents: 2342
diff changeset
522 length += get_length(coded_pts);
c6a7a89a0cef write frames and syncpoints
michael
parents: 2342
diff changeset
523
c6a7a89a0cef write frames and syncpoints
michael
parents: 2342
diff changeset
524 length*=4;
c6a7a89a0cef write frames and syncpoints
michael
parents: 2342
diff changeset
525 length+= !(flags & FLAG_CODED_PTS);
c6a7a89a0cef write frames and syncpoints
michael
parents: 2342
diff changeset
526 length+= !(flags & FLAG_CHECKSUM);
c6a7a89a0cef write frames and syncpoints
michael
parents: 2342
diff changeset
527
c6a7a89a0cef write frames and syncpoints
michael
parents: 2342
diff changeset
528 if(length < best_length){
c6a7a89a0cef write frames and syncpoints
michael
parents: 2342
diff changeset
529 best_length= length;
c6a7a89a0cef write frames and syncpoints
michael
parents: 2342
diff changeset
530 frame_code=i;
c6a7a89a0cef write frames and syncpoints
michael
parents: 2342
diff changeset
531 }
c6a7a89a0cef write frames and syncpoints
michael
parents: 2342
diff changeset
532 }
c6a7a89a0cef write frames and syncpoints
michael
parents: 2342
diff changeset
533 assert(frame_code != -1);
c6a7a89a0cef write frames and syncpoints
michael
parents: 2342
diff changeset
534 fc= &nut->frame_code[frame_code];
c6a7a89a0cef write frames and syncpoints
michael
parents: 2342
diff changeset
535 flags= fc->flags;
c6a7a89a0cef write frames and syncpoints
michael
parents: 2342
diff changeset
536 needed_flags= get_needed_flags(nut, nus, fc, pkt);
c6a7a89a0cef write frames and syncpoints
michael
parents: 2342
diff changeset
537
2683
153d6efc05b8 rename av_crc04C11DB7_update to ff_crc04C11DB7_update and move it to aviobuf.c so it can be reused by other (de)muxers
bcoudurier
parents: 2393
diff changeset
538 init_checksum(bc, ff_crc04C11DB7_update, 0);
2343
c6a7a89a0cef write frames and syncpoints
michael
parents: 2342
diff changeset
539 put_byte(bc, frame_code);
c6a7a89a0cef write frames and syncpoints
michael
parents: 2342
diff changeset
540 if(flags & FLAG_CODED){
c6a7a89a0cef write frames and syncpoints
michael
parents: 2342
diff changeset
541 put_v(bc, (flags^needed_flags) & ~(FLAG_CODED));
c6a7a89a0cef write frames and syncpoints
michael
parents: 2342
diff changeset
542 flags = needed_flags;
c6a7a89a0cef write frames and syncpoints
michael
parents: 2342
diff changeset
543 }
c6a7a89a0cef write frames and syncpoints
michael
parents: 2342
diff changeset
544 if(flags & FLAG_STREAM_ID) put_v(bc, pkt->stream_index);
c6a7a89a0cef write frames and syncpoints
michael
parents: 2342
diff changeset
545 if(flags & FLAG_CODED_PTS) put_v(bc, coded_pts);
c6a7a89a0cef write frames and syncpoints
michael
parents: 2342
diff changeset
546 if(flags & FLAG_SIZE_MSB) put_v(bc, pkt->size / fc->size_mul);
c6a7a89a0cef write frames and syncpoints
michael
parents: 2342
diff changeset
547
c6a7a89a0cef write frames and syncpoints
michael
parents: 2342
diff changeset
548 if(flags & FLAG_CHECKSUM) put_le32(bc, get_checksum(bc));
c6a7a89a0cef write frames and syncpoints
michael
parents: 2342
diff changeset
549 else get_checksum(bc);
c6a7a89a0cef write frames and syncpoints
michael
parents: 2342
diff changeset
550
c6a7a89a0cef write frames and syncpoints
michael
parents: 2342
diff changeset
551 put_buffer(bc, pkt->data, pkt->size);
c6a7a89a0cef write frames and syncpoints
michael
parents: 2342
diff changeset
552 nus->last_flags= flags;
2350
a0fb5ef1ec7c set back ptr properly
michael
parents: 2347
diff changeset
553
a0fb5ef1ec7c set back ptr properly
michael
parents: 2347
diff changeset
554 //FIXME just store one per syncpoint
a0fb5ef1ec7c set back ptr properly
michael
parents: 2347
diff changeset
555 if(flags & FLAG_KEY)
a0fb5ef1ec7c set back ptr properly
michael
parents: 2347
diff changeset
556 av_add_index_entry(
a0fb5ef1ec7c set back ptr properly
michael
parents: 2347
diff changeset
557 s->streams[pkt->stream_index],
a0fb5ef1ec7c set back ptr properly
michael
parents: 2347
diff changeset
558 nut->last_syncpoint_pos,
a0fb5ef1ec7c set back ptr properly
michael
parents: 2347
diff changeset
559 pkt->pts,
a0fb5ef1ec7c set back ptr properly
michael
parents: 2347
diff changeset
560 0,
a0fb5ef1ec7c set back ptr properly
michael
parents: 2347
diff changeset
561 0,
a0fb5ef1ec7c set back ptr properly
michael
parents: 2347
diff changeset
562 AVINDEX_KEYFRAME);
a0fb5ef1ec7c set back ptr properly
michael
parents: 2347
diff changeset
563
2324
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
564 return 0;
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
565 }
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
566
2346
cbcd840cf971 store headers twice (getting closer to spec compliance ...)
michael
parents: 2345
diff changeset
567 static int write_trailer(AVFormatContext *s){
cbcd840cf971 store headers twice (getting closer to spec compliance ...)
michael
parents: 2345
diff changeset
568 NUTContext *nut= s->priv_data;
cbcd840cf971 store headers twice (getting closer to spec compliance ...)
michael
parents: 2345
diff changeset
569 ByteIOContext *bc= &s->pb;
cbcd840cf971 store headers twice (getting closer to spec compliance ...)
michael
parents: 2345
diff changeset
570
2359
1860d5b4be2e header repetition
michael
parents: 2358
diff changeset
571 while(nut->header_count<3)
1860d5b4be2e header repetition
michael
parents: 2358
diff changeset
572 write_headers(nut, bc);
2346
cbcd840cf971 store headers twice (getting closer to spec compliance ...)
michael
parents: 2345
diff changeset
573 put_flush_packet(bc);
cbcd840cf971 store headers twice (getting closer to spec compliance ...)
michael
parents: 2345
diff changeset
574
cbcd840cf971 store headers twice (getting closer to spec compliance ...)
michael
parents: 2345
diff changeset
575 return 0;
cbcd840cf971 store headers twice (getting closer to spec compliance ...)
michael
parents: 2345
diff changeset
576 }
cbcd840cf971 store headers twice (getting closer to spec compliance ...)
michael
parents: 2345
diff changeset
577
2324
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
578 AVOutputFormat nut_muxer = {
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
579 "nut",
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
580 "nut format",
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
581 "video/x-nut",
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
582 "nut",
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
583 sizeof(NUTContext),
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
584 #ifdef CONFIG_LIBVORBIS
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
585 CODEC_ID_VORBIS,
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
586 #elif defined(CONFIG_LIBMP3LAME)
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
587 CODEC_ID_MP3,
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
588 #else
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
589 CODEC_ID_MP2, /* AC3 needs liba52 decoder */
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
590 #endif
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
591 CODEC_ID_MPEG4,
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
592 write_header,
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
593 write_packet,
2346
cbcd840cf971 store headers twice (getting closer to spec compliance ...)
michael
parents: 2345
diff changeset
594 write_trailer,
2324
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
595 .flags = AVFMT_GLOBALHEADER,
2325
2829faf72879 write stream headers
michael
parents: 2324
diff changeset
596 .codec_tag= (const AVCodecTag*[]){codec_bmp_tags, codec_wav_tags, 0},
2324
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
597 };