Revision 97d5eb11 libavformat/nutenc.c

View differences:

libavformat/nutenc.c
223 223
    return 0;
224 224
}
225 225

  
226
static int write_header(AVFormatContext *s){
227
    NUTContext *nut = s->priv_data;
228
    ByteIOContext *bc = &s->pb;
229
    AVCodecContext *codec;
226
static void write_mainheader(NUTContext *nut, ByteIOContext *bc){
230 227
    int i, j, tmp_pts, tmp_flags, tmp_stream, tmp_mul, tmp_size, tmp_fields;
231 228

  
232
    nut->avf= s;
233

  
234
    nut->stream   = av_mallocz(sizeof(StreamContext)*s->nb_streams);
235
    nut->time_base= av_mallocz(sizeof(AVRational   )*s->nb_streams);
236

  
237
    for(i=0; i<s->nb_streams; i++){
238
        AVStream *st= s->streams[i];
239
        int ssize;
240
        AVRational time_base;
241
        ff_parse_specific_params(st->codec, &time_base.den, &ssize, &time_base.num);
242

  
243
        av_set_pts_info(st, 64, time_base.num, time_base.den);
244

  
245
        for(j=0; j<nut->time_base_count; j++){
246
            if(!memcmp(&time_base, &nut->time_base[j], sizeof(AVRational))){
247
                break;
248
            }
249
        }
250
        nut->time_base[j]= time_base;
251
        nut->stream[i].time_base= &nut->time_base[j];
252
        if(j==nut->time_base_count)
253
            nut->time_base_count++;
254

  
255
        if(av_q2d(time_base) >= 0.001)
256
            nut->stream[i].msb_pts_shift = 7;
257
        else
258
            nut->stream[i].msb_pts_shift = 14;
259
        nut->stream[i].max_pts_distance= FFMAX(1/av_q2d(time_base), 1);
260
    }
261

  
262
    put_buffer(bc, ID_STRING, strlen(ID_STRING));
263
    put_byte(bc, 0);
264

  
265
    /* main header */
266
    put_be64(bc, MAIN_STARTCODE);
267
    put_packetheader(nut, bc, 120+5*256/*FIXME check*/, 1);
268

  
269 229
    put_v(bc, 2); /* version */
270
    put_v(bc, s->nb_streams);
230
    put_v(bc, nut->avf->nb_streams);
271 231
    put_v(bc, MAX_DISTANCE);
272 232
    put_v(bc, nut->time_base_count);
273 233

  
......
276 236
        put_v(bc, nut->time_base[i].den);
277 237
    }
278 238

  
279
    build_frame_code(s);
280
    assert(nut->frame_code['N'].flags == FLAG_INVALID);
281

  
282 239
    tmp_pts=0;
283 240
    tmp_mul=1;
284 241
    tmp_stream=0;
......
322 279
        if(tmp_fields>4) put_v(bc, 0 /*tmp_res*/);
323 280
        if(tmp_fields>5) put_v(bc, j);
324 281
    }
282
}
325 283

  
284
static int write_header(AVFormatContext *s){
285
    NUTContext *nut = s->priv_data;
286
    ByteIOContext *bc = &s->pb;
287
    AVCodecContext *codec;
288
    int i, j;
289

  
290
    nut->avf= s;
291

  
292
    nut->stream   = av_mallocz(sizeof(StreamContext)*s->nb_streams);
293
    nut->time_base= av_mallocz(sizeof(AVRational   )*s->nb_streams);
294

  
295
    for(i=0; i<s->nb_streams; i++){
296
        AVStream *st= s->streams[i];
297
        int ssize;
298
        AVRational time_base;
299
        ff_parse_specific_params(st->codec, &time_base.den, &ssize, &time_base.num);
300

  
301
        av_set_pts_info(st, 64, time_base.num, time_base.den);
302

  
303
        for(j=0; j<nut->time_base_count; j++){
304
            if(!memcmp(&time_base, &nut->time_base[j], sizeof(AVRational))){
305
                break;
306
            }
307
        }
308
        nut->time_base[j]= time_base;
309
        nut->stream[i].time_base= &nut->time_base[j];
310
        if(j==nut->time_base_count)
311
            nut->time_base_count++;
312

  
313
        if(av_q2d(time_base) >= 0.001)
314
            nut->stream[i].msb_pts_shift = 7;
315
        else
316
            nut->stream[i].msb_pts_shift = 14;
317
        nut->stream[i].max_pts_distance= FFMAX(1/av_q2d(time_base), 1);
318
    }
319

  
320
    build_frame_code(s);
321
    assert(nut->frame_code['N'].flags == FLAG_INVALID);
322

  
323
    put_buffer(bc, ID_STRING, strlen(ID_STRING));
324
    put_byte(bc, 0);
325

  
326
    /* main header */
327
    put_be64(bc, MAIN_STARTCODE);
328
    put_packetheader(nut, bc, 120+5*256/*FIXME check*/, 1);
329
    write_mainheader(nut, bc);
326 330
    update_packetheader(nut, bc, 0, 1);
327 331

  
328 332
    for (i=0; i < s->nb_streams; i++){

Also available in: Unified diff