Revision 01f4895c

View differences:

ffmpeg.c
493 493
    const int audio_out_size= 4*MAX_AUDIO_PACKET_SIZE;
494 494

  
495 495
    int size_out, frame_bytes, ret;
496
    AVCodecContext *enc= &ost->st->codec;
496
    AVCodecContext *enc= ost->st->codec;
497 497

  
498 498
    /* SC: dynamic allocation of buffers */
499 499
    if (!audio_buf)
......
505 505

  
506 506
    if(audio_sync_method){
507 507
        double delta = get_sync_ipts(ost) * enc->sample_rate - ost->sync_opts 
508
                - fifo_size(&ost->fifo, ost->fifo.rptr)/(ost->st->codec.channels * 2);
509
        double idelta= delta*ist->st->codec.sample_rate / enc->sample_rate;
510
        int byte_delta= ((int)idelta)*2*ist->st->codec.channels;
508
                - fifo_size(&ost->fifo, ost->fifo.rptr)/(ost->st->codec->channels * 2);
509
        double idelta= delta*ist->st->codec->sample_rate / enc->sample_rate;
510
        int byte_delta= ((int)idelta)*2*ist->st->codec->channels;
511 511

  
512 512
        //FIXME resample delay
513 513
        if(fabs(delta) > 50){
......
542 542
                assert(ost->audio_resample);
543 543
                if(verbose > 2)
544 544
                    fprintf(stderr, "compensating audio timestamp drift:%f compensation:%d in:%d\n", delta, comp, enc->sample_rate);
545
//                fprintf(stderr, "drift:%f len:%d opts:%lld ipts:%lld fifo:%d\n", delta, -1, ost->sync_opts, (int64_t)(get_sync_ipts(ost) * enc->sample_rate), fifo_size(&ost->fifo, ost->fifo.rptr)/(ost->st->codec.channels * 2));
545
//                fprintf(stderr, "drift:%f len:%d opts:%lld ipts:%lld fifo:%d\n", delta, -1, ost->sync_opts, (int64_t)(get_sync_ipts(ost) * enc->sample_rate), fifo_size(&ost->fifo, ost->fifo.rptr)/(ost->st->codec->channels * 2));
546 546
                av_resample_compensate(*(struct AVResampleContext**)ost->resample, comp, enc->sample_rate);
547 547
            }
548 548
        } 
549 549
    }else
550 550
        ost->sync_opts= lrintf(get_sync_ipts(ost) * enc->sample_rate)
551
                        - fifo_size(&ost->fifo, ost->fifo.rptr)/(ost->st->codec.channels * 2); //FIXME wrong
551
                        - fifo_size(&ost->fifo, ost->fifo.rptr)/(ost->st->codec->channels * 2); //FIXME wrong
552 552

  
553 553
    if (ost->audio_resample) {
554 554
        buftmp = audio_buf;
555 555
        size_out = audio_resample(ost->resample, 
556 556
                                  (short *)buftmp, (short *)buf,
557
                                  size / (ist->st->codec.channels * 2));
557
                                  size / (ist->st->codec->channels * 2));
558 558
        size_out = size_out * enc->channels * 2;
559 559
    } else {
560 560
        buftmp = buf;
......
625 625
    AVPicture picture_tmp;
626 626
    uint8_t *buf = 0;
627 627

  
628
    dec = &ist->st->codec;
628
    dec = ist->st->codec;
629 629

  
630 630
    /* deinterlace : must be done before any resize */
631 631
    if (do_deinterlace || using_vhook) {
......
721 721
        return;
722 722
    }
723 723

  
724
    enc = &ost->st->codec;
724
    enc = ost->st->codec;
725 725

  
726 726
    if (!subtitle_out) {
727 727
        subtitle_out = av_malloc(subtitle_out_max_size);
......
775 775
    avcodec_get_frame_defaults(&picture_format_temp);
776 776
    avcodec_get_frame_defaults(&picture_crop_temp);
777 777

  
778
    enc = &ost->st->codec;
779
    dec = &ist->st->codec;
778
    enc = ost->st->codec;
779
    dec = ist->st->codec;
780 780

  
781 781
    /* by default, we output a single frame */
782 782
    nb_frames = 1;
......
1049 1049
    }
1050 1050
    
1051 1051
    ti = MAXINT64;
1052
    enc = &ost->st->codec;
1052
    enc = ost->st->codec;
1053 1053
    if (enc->codec_type == CODEC_TYPE_VIDEO) {
1054 1054
        frame_number = ost->frame_number;
1055 1055
        fprintf(fvstats, "frame= %5d q= %2.1f ", frame_number, enc->coded_frame->quality/(float)FF_QP2LAMBDA);
......
1107 1107
    for(i=0;i<nb_ostreams;i++) {
1108 1108
        ost = ost_table[i];
1109 1109
        os = output_files[ost->file_index];
1110
        enc = &ost->st->codec;
1110
        enc = ost->st->codec;
1111 1111
        if (vid && enc->codec_type == CODEC_TYPE_VIDEO) {
1112 1112
            snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf), "q=%2.1f ",
1113 1113
                    enc->coded_frame->quality/(float)FF_QP2LAMBDA);
......
1220 1220
        data_size = 0;
1221 1221
        subtitle_to_free = NULL;
1222 1222
        if (ist->decoding_needed) {
1223
            switch(ist->st->codec.codec_type) {
1223
            switch(ist->st->codec->codec_type) {
1224 1224
            case CODEC_TYPE_AUDIO:{
1225 1225
                if(pkt) 
1226 1226
                    samples= av_fast_realloc(samples, &samples_size, FFMAX(pkt->size, AVCODEC_MAX_AUDIO_FRAME_SIZE));
1227 1227
                    /* XXX: could avoid copy if PCM 16 bits with same
1228 1228
                       endianness as CPU */
1229
                ret = avcodec_decode_audio(&ist->st->codec, samples, &data_size,
1229
                ret = avcodec_decode_audio(ist->st->codec, samples, &data_size,
1230 1230
                                           ptr, len);
1231 1231
                if (ret < 0)
1232 1232
                    goto fail_decode;
......
1240 1240
                }
1241 1241
                data_buf = (uint8_t *)samples;
1242 1242
                ist->next_pts += ((int64_t)AV_TIME_BASE/2 * data_size) / 
1243
                    (ist->st->codec.sample_rate * ist->st->codec.channels);
1243
                    (ist->st->codec->sample_rate * ist->st->codec->channels);
1244 1244
                break;}
1245 1245
            case CODEC_TYPE_VIDEO:
1246
                    data_size = (ist->st->codec.width * ist->st->codec.height * 3) / 2;
1246
                    data_size = (ist->st->codec->width * ist->st->codec->height * 3) / 2;
1247 1247
                    /* XXX: allocate picture correctly */
1248 1248
                    avcodec_get_frame_defaults(&picture);
1249 1249

  
1250
                    ret = avcodec_decode_video(&ist->st->codec, 
1250
                    ret = avcodec_decode_video(ist->st->codec, 
1251 1251
                                               &picture, &got_picture, ptr, len);
1252 1252
                    ist->st->quality= picture.quality;
1253 1253
                    if (ret < 0) 
......
1256 1256
                        /* no picture yet */
1257 1257
                        goto discard_packet;
1258 1258
                    }
1259
                    if (ist->st->codec.time_base.num != 0) {
1259
                    if (ist->st->codec->time_base.num != 0) {
1260 1260
                        ist->next_pts += ((int64_t)AV_TIME_BASE * 
1261
                                          ist->st->codec.time_base.num) /
1262
                            ist->st->codec.time_base.den;
1261
                                          ist->st->codec->time_base.num) /
1262
                            ist->st->codec->time_base.den;
1263 1263
                    }
1264 1264
                    len = 0;
1265 1265
                    break;
1266 1266
            case CODEC_TYPE_SUBTITLE:
1267
                ret = avcodec_decode_subtitle(&ist->st->codec, 
1267
                ret = avcodec_decode_subtitle(ist->st->codec, 
1268 1268
                                              &subtitle, &got_subtitle, ptr, len);
1269 1269
                if (ret < 0)
1270 1270
                    goto fail_decode;
......
1278 1278
                goto fail_decode;
1279 1279
            }
1280 1280
        } else {
1281
                switch(ist->st->codec.codec_type) {
1281
                switch(ist->st->codec->codec_type) {
1282 1282
                case CODEC_TYPE_AUDIO:
1283
                    ist->next_pts += ((int64_t)AV_TIME_BASE * ist->st->codec.frame_size) / 
1284
                        (ist->st->codec.sample_rate * ist->st->codec.channels);
1283
                    ist->next_pts += ((int64_t)AV_TIME_BASE * ist->st->codec->frame_size) / 
1284
                        (ist->st->codec->sample_rate * ist->st->codec->channels);
1285 1285
                    break;
1286 1286
                case CODEC_TYPE_VIDEO:
1287
                    if (ist->st->codec.time_base.num != 0) {
1287
                    if (ist->st->codec->time_base.num != 0) {
1288 1288
                        ist->next_pts += ((int64_t)AV_TIME_BASE * 
1289
                                          ist->st->codec.time_base.num) /
1290
                            ist->st->codec.time_base.den;
1289
                                          ist->st->codec->time_base.num) /
1290
                            ist->st->codec->time_base.den;
1291 1291
                    }
1292 1292
                    break;
1293 1293
                }
......
1298 1298
            }
1299 1299

  
1300 1300
            buffer_to_free = NULL;
1301
            if (ist->st->codec.codec_type == CODEC_TYPE_VIDEO) {
1301
            if (ist->st->codec->codec_type == CODEC_TYPE_VIDEO) {
1302 1302
                pre_process_video_frame(ist, (AVPicture *)&picture, 
1303 1303
                                        &buffer_to_free);
1304 1304
            }
1305 1305

  
1306 1306
            // preprocess audio (volume)
1307
            if (ist->st->codec.codec_type == CODEC_TYPE_AUDIO) {
1307
            if (ist->st->codec->codec_type == CODEC_TYPE_AUDIO) {
1308 1308
                if (audio_volume != 256) {
1309 1309
                    short *volp;
1310 1310
                    volp = samples;
......
1318 1318
            }
1319 1319

  
1320 1320
            /* frame rate emulation */
1321
            if (ist->st->codec.rate_emu) {
1322
                int64_t pts = av_rescale((int64_t) ist->frame * ist->st->codec.time_base.num, 1000000, ist->st->codec.time_base.den);
1321
            if (ist->st->codec->rate_emu) {
1322
                int64_t pts = av_rescale((int64_t) ist->frame * ist->st->codec->time_base.num, 1000000, ist->st->codec->time_base.den);
1323 1323
                int64_t now = av_gettime() - ist->start;
1324 1324
                if (pts > now)
1325 1325
                    usleep(pts - now);
......
1331 1331
            /* mpeg PTS deordering : if it is a P or I frame, the PTS
1332 1332
               is the one of the next displayed one */
1333 1333
            /* XXX: add mpeg4 too ? */
1334
            if (ist->st->codec.codec_id == CODEC_ID_MPEG1VIDEO) {
1335
                if (ist->st->codec.pict_type != B_TYPE) {
1334
            if (ist->st->codec->codec_id == CODEC_ID_MPEG1VIDEO) {
1335
                if (ist->st->codec->pict_type != B_TYPE) {
1336 1336
                    int64_t tmp;
1337 1337
                    tmp = ist->last_ip_pts;
1338 1338
                    ist->last_ip_pts  = ist->frac_pts.val;
......
1360 1360
                        //ost->sync_ipts = (double)(ist->pts + input_files_ts_offset[ist->file_index] - start_time)/ AV_TIME_BASE;
1361 1361

  
1362 1362
                        if (ost->encoding_needed) {
1363
                            switch(ost->st->codec.codec_type) {
1363
                            switch(ost->st->codec->codec_type) {
1364 1364
                            case CODEC_TYPE_AUDIO:
1365 1365
                                do_audio_out(os, ost, ist, data_buf, data_size);
1366 1366
                                break;
......
1386 1386
                            /* force the input stream PTS */
1387 1387
                        
1388 1388
                            avcodec_get_frame_defaults(&avframe);
1389
                            ost->st->codec.coded_frame= &avframe;
1389
                            ost->st->codec->coded_frame= &avframe;
1390 1390
                            avframe.key_frame = pkt->flags & PKT_FLAG_KEY; 
1391 1391

  
1392
                            if(ost->st->codec.codec_type == CODEC_TYPE_AUDIO)
1392
                            if(ost->st->codec->codec_type == CODEC_TYPE_AUDIO)
1393 1393
                                audio_size += data_size;
1394
                            else if (ost->st->codec.codec_type == CODEC_TYPE_VIDEO) {
1394
                            else if (ost->st->codec->codec_type == CODEC_TYPE_VIDEO) {
1395 1395
                                video_size += data_size;
1396 1396
                                ost->sync_opts++;
1397 1397
                            }
......
1411 1411
                                opkt.dts= av_rescale_q(dts + input_files_ts_offset[ist->file_index], AV_TIME_BASE_Q,  ost->st->time_base);
1412 1412
                            }
1413 1413
                            opkt.flags= pkt->flags;
1414
                            if(av_parser_change(ist->st->parser, &ost->st->codec, &opkt.data, &opkt.size, data_buf, data_size, pkt->flags & PKT_FLAG_KEY))
1414
                            if(av_parser_change(ist->st->parser, ost->st->codec, &opkt.data, &opkt.size, data_buf, data_size, pkt->flags & PKT_FLAG_KEY))
1415 1415
                                opkt.destruct= av_destruct_packet;
1416 1416
                            av_interleaved_write_frame(os, &opkt);
1417
                            ost->st->codec.frame_number++;
1417
                            ost->st->codec->frame_number++;
1418 1418
                            ost->frame_number++;
1419 1419
                            av_free_packet(&opkt);
1420 1420
                        }
......
1441 1441
        for(i=0;i<nb_ostreams;i++) {
1442 1442
            ost = ost_table[i];
1443 1443
            if (ost->source_index == ist_index) {
1444
                AVCodecContext *enc= &ost->st->codec;
1444
                AVCodecContext *enc= ost->st->codec;
1445 1445
                os = output_files[ost->file_index];
1446 1446
                
1447
                if(ost->st->codec.codec_type == CODEC_TYPE_AUDIO && enc->frame_size <=1)
1447
                if(ost->st->codec->codec_type == CODEC_TYPE_AUDIO && enc->frame_size <=1)
1448 1448
                    continue;
1449
                if(ost->st->codec.codec_type == CODEC_TYPE_VIDEO && (os->oformat->flags & AVFMT_RAWPICTURE))
1449
                if(ost->st->codec->codec_type == CODEC_TYPE_VIDEO && (os->oformat->flags & AVFMT_RAWPICTURE))
1450 1450
                    continue;
1451 1451

  
1452 1452
                if (ost->encoding_needed) {
......
1455 1455
                        av_init_packet(&pkt);
1456 1456
                        pkt.stream_index= ost->index;
1457 1457
 
1458
                        switch(ost->st->codec.codec_type) {
1458
                        switch(ost->st->codec->codec_type) {
1459 1459
                        case CODEC_TYPE_AUDIO:        
1460 1460
                            ret = avcodec_encode_audio(enc, bit_buffer, bit_buffer_size, NULL);
1461 1461
                            audio_size += ret;
......
1546 1546
            ist->discard = 1; /* the stream is discarded by default
1547 1547
                                 (changed later) */
1548 1548

  
1549
            if (ist->st->codec.rate_emu) {
1549
            if (ist->st->codec->rate_emu) {
1550 1550
                ist->start = av_gettime();
1551 1551
                ist->frame = 0;
1552 1552
            }
......
1607 1607
                    stream_maps[n-1].stream_index;
1608 1608
                    
1609 1609
                /* Sanity check that the stream types match */
1610
                if (ist_table[ost->source_index]->st->codec.codec_type != ost->st->codec.codec_type) {
1610
                if (ist_table[ost->source_index]->st->codec->codec_type != ost->st->codec->codec_type) {
1611 1611
                    fprintf(stderr, "Codec type mismatch for mapping #%d.%d -> #%d.%d\n",
1612 1612
                        stream_maps[n-1].file_index, stream_maps[n-1].stream_index,
1613 1613
                        ost->file_index, ost->index);
......
1620 1620
                for(j=0;j<nb_istreams;j++) {
1621 1621
                    ist = ist_table[j];
1622 1622
                    if (ist->discard && 
1623
                        ist->st->codec.codec_type == ost->st->codec.codec_type) {
1623
                        ist->st->codec->codec_type == ost->st->codec->codec_type) {
1624 1624
                        ost->source_index = j;
1625 1625
                        found = 1;
1626 1626
                        break;
......
1631 1631
                    /* try again and reuse existing stream */
1632 1632
                    for(j=0;j<nb_istreams;j++) {
1633 1633
                        ist = ist_table[j];
1634
                        if (ist->st->codec.codec_type == ost->st->codec.codec_type) {
1634
                        if (ist->st->codec->codec_type == ost->st->codec->codec_type) {
1635 1635
                            ost->source_index = j;
1636 1636
                            found = 1;
1637 1637
                        }
......
1656 1656
        ost = ost_table[i];
1657 1657
        ist = ist_table[ost->source_index];
1658 1658

  
1659
        codec = &ost->st->codec;
1660
        icodec = &ist->st->codec;
1659
        codec = ost->st->codec;
1660
        icodec = ist->st->codec;
1661 1661

  
1662 1662
        if (ost->st->stream_copy) {
1663 1663
            /* if stream_copy is selected, no need to decode or encode */
......
1773 1773
                        goto fail;
1774 1774

  
1775 1775
                    ost->img_resample_ctx = img_resample_full_init( 
1776
                                      ost->st->codec.width, ost->st->codec.height,
1777
                                      ist->st->codec.width, ist->st->codec.height,
1776
                                      ost->st->codec->width, ost->st->codec->height,
1777
                                      ist->st->codec->width, ist->st->codec->height,
1778 1778
                                      frame_topBand, frame_bottomBand,
1779 1779
                            frame_leftBand, frame_rightBand, 
1780 1780
                            frame_padtop, frame_padbottom, 
......
1877 1877
        ost = ost_table[i];
1878 1878
        if (ost->encoding_needed) {
1879 1879
            AVCodec *codec;
1880
            codec = avcodec_find_encoder(ost->st->codec.codec_id);
1880
            codec = avcodec_find_encoder(ost->st->codec->codec_id);
1881 1881
            if (!codec) {
1882 1882
                fprintf(stderr, "Unsupported codec for output stream #%d.%d\n", 
1883 1883
                        ost->file_index, ost->index);
1884 1884
                exit(1);
1885 1885
            }
1886
            if (avcodec_open(&ost->st->codec, codec) < 0) {
1886
            if (avcodec_open(ost->st->codec, codec) < 0) {
1887 1887
                fprintf(stderr, "Error while opening codec for output stream #%d.%d - maybe incorrect parameters such as bit_rate, rate, width or height\n", 
1888 1888
                        ost->file_index, ost->index);
1889 1889
                exit(1);
1890 1890
            }
1891
            extra_size += ost->st->codec.extradata_size;
1891
            extra_size += ost->st->codec->extradata_size;
1892 1892
        }
1893 1893
    }
1894 1894

  
......
1897 1897
        ist = ist_table[i];
1898 1898
        if (ist->decoding_needed) {
1899 1899
            AVCodec *codec;
1900
            codec = avcodec_find_decoder(ist->st->codec.codec_id);
1900
            codec = avcodec_find_decoder(ist->st->codec->codec_id);
1901 1901
            if (!codec) {
1902 1902
                fprintf(stderr, "Unsupported codec (id=%d) for input stream #%d.%d\n", 
1903
                        ist->st->codec.codec_id, ist->file_index, ist->index);
1903
                        ist->st->codec->codec_id, ist->file_index, ist->index);
1904 1904
                exit(1);
1905 1905
            }
1906
            if (avcodec_open(&ist->st->codec, codec) < 0) {
1906
            if (avcodec_open(ist->st->codec, codec) < 0) {
1907 1907
                fprintf(stderr, "Error while opening codec for input stream #%d.%d\n", 
1908 1908
                        ist->file_index, ist->index);
1909 1909
                exit(1);
1910 1910
            }
1911
            //if (ist->st->codec.codec_type == CODEC_TYPE_VIDEO)
1912
            //    ist->st->codec.flags |= CODEC_FLAG_REPEAT_FIELD;
1911
            //if (ist->st->codec->codec_type == CODEC_TYPE_VIDEO)
1912
            //    ist->st->codec->flags |= CODEC_FLAG_REPEAT_FIELD;
1913 1913
        }
1914 1914
    }
1915 1915

  
......
2010 2010
            ost = ost_table[i];
2011 2011
            os = output_files[ost->file_index];
2012 2012
            ist = ist_table[ost->source_index];
2013
            if(ost->st->codec.codec_type == CODEC_TYPE_VIDEO)
2014
                opts = ost->sync_opts * av_q2d(ost->st->codec.time_base);
2013
            if(ost->st->codec->codec_type == CODEC_TYPE_VIDEO)
2014
                opts = ost->sync_opts * av_q2d(ost->st->codec->time_base);
2015 2015
            else
2016 2016
                opts = ost->st->pts.val * av_q2d(ost->st->time_base);
2017 2017
            ipts = (double)ist->pts;
......
2025 2025
                    if(!input_sync) file_index = ist->file_index;
2026 2026
                }
2027 2027
            }
2028
            if(ost->frame_number >= max_frames[ost->st->codec.codec_type]){
2028
            if(ost->frame_number >= max_frames[ost->st->codec->codec_type]){
2029 2029
                file_index= -1;
2030 2030
                break;
2031 2031
            }
......
2067 2067
        if (ist->discard)
2068 2068
            goto discard_packet;
2069 2069

  
2070
//        fprintf(stderr, "next:%lld dts:%lld off:%lld %d\n", ist->next_pts, pkt.dts, input_files_ts_offset[ist->file_index], ist->st->codec.codec_type);
2070
//        fprintf(stderr, "next:%lld dts:%lld off:%lld %d\n", ist->next_pts, pkt.dts, input_files_ts_offset[ist->file_index], ist->st->codec->codec_type);
2071 2071
        if (pkt.dts != AV_NOPTS_VALUE && ist->next_pts != AV_NOPTS_VALUE) {
2072 2072
            int64_t delta= av_rescale_q(pkt.dts, ist->st->time_base, AV_TIME_BASE_Q) - ist->next_pts;
2073 2073
            if(ABS(delta) > 10LL*AV_TIME_BASE && !copy_ts){
......
2123 2123
    for(i=0;i<nb_ostreams;i++) {
2124 2124
        ost = ost_table[i];
2125 2125
        if (ost->encoding_needed) {
2126
            av_freep(&ost->st->codec.stats_in);
2127
            avcodec_close(&ost->st->codec);
2126
            av_freep(&ost->st->codec->stats_in);
2127
            avcodec_close(ost->st->codec);
2128 2128
        }
2129 2129
    }
2130 2130
    
......
2132 2132
    for(i=0;i<nb_istreams;i++) {
2133 2133
        ist = ist_table[i];
2134 2134
        if (ist->decoding_needed) {
2135
            avcodec_close(&ist->st->codec);
2135
            avcodec_close(ist->st->codec);
2136 2136
        }
2137 2137
    }
2138 2138

  
......
3058 3058

  
3059 3059
    /* update the current parameters so that they match the one of the input stream */
3060 3060
    for(i=0;i<ic->nb_streams;i++) {
3061
        AVCodecContext *enc = &ic->streams[i]->codec;
3061
        AVCodecContext *enc = ic->streams[i]->codec;
3062 3062
#if defined(HAVE_THREADS)
3063 3063
        if(thread_count>1)
3064 3064
            avcodec_thread_init(enc, thread_count);
......
3154 3154
    for(j=0;j<nb_input_files;j++) {
3155 3155
        ic = input_files[j];
3156 3156
        for(i=0;i<ic->nb_streams;i++) {
3157
            AVCodecContext *enc = &ic->streams[i]->codec;
3157
            AVCodecContext *enc = ic->streams[i]->codec;
3158 3158
            switch(enc->codec_type) {
3159 3159
            case CODEC_TYPE_AUDIO:
3160 3160
                has_audio = 1;
......
3187 3187
    }
3188 3188
#if defined(HAVE_THREADS)
3189 3189
    if(thread_count>1)
3190
        avcodec_thread_init(&st->codec, thread_count);
3190
        avcodec_thread_init(st->codec, thread_count);
3191 3191
#endif
3192 3192
    
3193
    video_enc = &st->codec;
3193
    video_enc = st->codec;
3194 3194
    
3195 3195
    if(video_codec_tag)
3196 3196
        video_enc->codec_tag= video_codec_tag;
......
3473 3473
    }
3474 3474
#if defined(HAVE_THREADS)
3475 3475
    if(thread_count>1)
3476
        avcodec_thread_init(&st->codec, thread_count);
3476
        avcodec_thread_init(st->codec, thread_count);
3477 3477
#endif
3478 3478
    
3479
    audio_enc = &st->codec;
3479
    audio_enc = st->codec;
3480 3480
    audio_enc->codec_type = CODEC_TYPE_AUDIO;
3481 3481
    
3482 3482
    if(audio_codec_tag)
......
3535 3535
        exit(1);
3536 3536
    }
3537 3537

  
3538
    subtitle_enc = &st->codec;
3538
    subtitle_enc = st->codec;
3539 3539
    subtitle_enc->codec_type = CODEC_TYPE_SUBTITLE;
3540 3540
    if (subtitle_stream_copy) {
3541 3541
        st->stream_copy = 1;
......
3732 3732
    for(j=0;j<nb_output_files;j++) {
3733 3733
        oc = output_files[j];
3734 3734
        for(i=0;i<oc->nb_streams;i++) {
3735
            AVCodecContext *enc = &oc->streams[i]->codec;
3735
            AVCodecContext *enc = oc->streams[i]->codec;
3736 3736
            switch(enc->codec_type) {
3737 3737
            case CODEC_TYPE_AUDIO:
3738 3738
                if (enc->sample_rate > ap->sample_rate)
......
4041 4041
                int i, j;
4042 4042
                for(j = 0; j < nb_input_files; j++) {
4043 4043
                    for(i = 0; i < input_files[j]->nb_streams; i++) {
4044
                        AVCodecContext *c = &input_files[j]->streams[i]->codec;
4044
                        AVCodecContext *c = input_files[j]->streams[i]->codec;
4045 4045
                        if(c->codec_type != CODEC_TYPE_VIDEO)
4046 4046
                            continue;
4047 4047
                        fr = c->time_base.den * 1000 / c->time_base.num;
ffplay.c
381 381
    vp = &is->pictq[is->pictq_rindex];
382 382
    if (vp->bmp) {
383 383
        /* XXX: use variable in the frame */
384
        if (is->video_st->codec.sample_aspect_ratio.num == 0) 
384
        if (is->video_st->codec->sample_aspect_ratio.num == 0) 
385 385
            aspect_ratio = 0;
386 386
        else
387
            aspect_ratio = av_q2d(is->video_st->codec.sample_aspect_ratio) 
388
                * is->video_st->codec.width / is->video_st->codec.height;;
387
            aspect_ratio = av_q2d(is->video_st->codec->sample_aspect_ratio) 
388
                * is->video_st->codec->width / is->video_st->codec->height;;
389 389
        if (aspect_ratio <= 0.0)
390
            aspect_ratio = (float)is->video_st->codec.width / 
391
                (float)is->video_st->codec.height;
390
            aspect_ratio = (float)is->video_st->codec->width / 
391
                (float)is->video_st->codec->height;
392 392
        /* if an active format is indicated, then it overrides the
393 393
           mpeg format */
394 394
#if 0
395
        if (is->video_st->codec.dtg_active_format != is->dtg_active_format) {
396
            is->dtg_active_format = is->video_st->codec.dtg_active_format;
395
        if (is->video_st->codec->dtg_active_format != is->dtg_active_format) {
396
            is->dtg_active_format = is->video_st->codec->dtg_active_format;
397 397
            printf("dtg_active_format=%d\n", is->dtg_active_format);
398 398
        }
399 399
#endif
400 400
#if 0
401
        switch(is->video_st->codec.dtg_active_format) {
401
        switch(is->video_st->codec->dtg_active_format) {
402 402
        case FF_DTG_AFD_SAME:
403 403
        default:
404 404
            /* nothing to do */
......
469 469
    int16_t time_diff;
470 470
    
471 471
    /* compute display index : center on currently output samples */
472
    channels = s->audio_st->codec.channels;
472
    channels = s->audio_st->codec->channels;
473 473
    nb_display_channels = channels;
474 474
    if (!s->paused) {
475 475
        n = 2 * channels;
......
480 480
           the last buffer computation */
481 481
        if (audio_callback_time) {
482 482
            time_diff = av_gettime() - audio_callback_time;
483
            delay += (time_diff * s->audio_st->codec.sample_rate) / 1000000;
483
            delay += (time_diff * s->audio_st->codec->sample_rate) / 1000000;
484 484
        }
485 485
        
486 486
        delay -= s->width / 2;
......
567 567
    hw_buf_size = audio_write_get_buf_size(is);
568 568
    bytes_per_sec = 0;
569 569
    if (is->audio_st) {
570
        bytes_per_sec = is->audio_st->codec.sample_rate * 
571
            2 * is->audio_st->codec.channels;
570
        bytes_per_sec = is->audio_st->codec->sample_rate * 
571
            2 * is->audio_st->codec->channels;
572 572
    }
573 573
    if (bytes_per_sec)
574 574
        pts -= (double)hw_buf_size / bytes_per_sec;
......
767 767
#if 0
768 768
    /* XXX: use generic function */
769 769
    /* XXX: disable overlay if no hardware acceleration or if RGB format */
770
    switch(is->video_st->codec.pix_fmt) {
770
    switch(is->video_st->codec->pix_fmt) {
771 771
    case PIX_FMT_YUV420P:
772 772
    case PIX_FMT_YUV422P:
773 773
    case PIX_FMT_YUV444P:
......
781 781
        break;
782 782
    }
783 783
#endif
784
    vp->bmp = SDL_CreateYUVOverlay(is->video_st->codec.width,
785
                                   is->video_st->codec.height,
784
    vp->bmp = SDL_CreateYUVOverlay(is->video_st->codec->width,
785
                                   is->video_st->codec->height,
786 786
                                   SDL_YV12_OVERLAY, 
787 787
                                   screen);
788
    vp->width = is->video_st->codec.width;
789
    vp->height = is->video_st->codec.height;
788
    vp->width = is->video_st->codec->width;
789
    vp->height = is->video_st->codec->height;
790 790

  
791 791
    SDL_LockMutex(is->pictq_mutex);
792 792
    vp->allocated = 1;
......
815 815

  
816 816
    /* alloc or resize hardware picture buffer */
817 817
    if (!vp->bmp || 
818
        vp->width != is->video_st->codec.width ||
819
        vp->height != is->video_st->codec.height) {
818
        vp->width != is->video_st->codec->width ||
819
        vp->height != is->video_st->codec->height) {
820 820
        SDL_Event event;
821 821

  
822 822
        vp->allocated = 0;
......
852 852
        pict.linesize[1] = vp->bmp->pitches[2];
853 853
        pict.linesize[2] = vp->bmp->pitches[1];
854 854
        img_convert(&pict, dst_pix_fmt, 
855
                    (AVPicture *)src_frame, is->video_st->codec.pix_fmt, 
856
                    is->video_st->codec.width, is->video_st->codec.height);
855
                    (AVPicture *)src_frame, is->video_st->codec->pix_fmt, 
856
                    is->video_st->codec->width, is->video_st->codec->height);
857 857
        /* update the bitmap content */
858 858
        SDL_UnlockYUVOverlay(vp->bmp);
859 859

  
......
883 883
        pts = is->video_clock;
884 884
    }
885 885
    /* update video clock for next frame */
886
    frame_delay = av_q2d(is->video_st->codec.time_base);
886
    frame_delay = av_q2d(is->video_st->codec->time_base);
887 887
    /* for MPEG2, the frame can be repeated, so we update the
888 888
       clock accordingly */
889 889
    if (src_frame->repeat_pict) {
......
928 928
            pts = av_q2d(is->video_st->time_base)*pkt->dts;
929 929

  
930 930
            SDL_LockMutex(is->video_decoder_mutex);
931
            len1 = avcodec_decode_video(&is->video_st->codec, 
931
            len1 = avcodec_decode_video(is->video_st->codec, 
932 932
                                        frame, &got_picture, 
933 933
                                        pkt->data, pkt->size);
934 934
            SDL_UnlockMutex(is->video_decoder_mutex);
......
953 953
{
954 954
    int size, len, channels;
955 955

  
956
    channels = is->audio_st->codec.channels;
956
    channels = is->audio_st->codec->channels;
957 957

  
958 958
    size = samples_size / sizeof(short);
959 959
    while (size > 0) {
......
977 977
    int n, samples_size;
978 978
    double ref_clock;
979 979
    
980
    n = 2 * is->audio_st->codec.channels;
980
    n = 2 * is->audio_st->codec->channels;
981 981
    samples_size = samples_size1;
982 982

  
983 983
    /* if not master, then we try to remove or add samples to correct the clock */
......
999 999
                avg_diff = is->audio_diff_cum * (1.0 - is->audio_diff_avg_coef);
1000 1000

  
1001 1001
                if (fabs(avg_diff) >= is->audio_diff_threshold) {
1002
                    wanted_size = samples_size + ((int)(diff * is->audio_st->codec.sample_rate) * n);
1002
                    wanted_size = samples_size + ((int)(diff * is->audio_st->codec->sample_rate) * n);
1003 1003
                    nb_samples = samples_size / n;
1004 1004
                
1005 1005
                    min_size = ((nb_samples * (100 - SAMPLE_CORRECTION_PERCENT_MAX)) / 100) * n;
......
1057 1057
        /* NOTE: the audio packet can contain several frames */
1058 1058
        while (is->audio_pkt_size > 0) {
1059 1059
            SDL_LockMutex(is->audio_decoder_mutex);
1060
            len1 = avcodec_decode_audio(&is->audio_st->codec, 
1060
            len1 = avcodec_decode_audio(is->audio_st->codec, 
1061 1061
                                        (int16_t *)audio_buf, &data_size, 
1062 1062
                                        is->audio_pkt_data, is->audio_pkt_size);
1063 1063
            SDL_UnlockMutex(is->audio_decoder_mutex);
......
1074 1074
            /* if no pts, then compute it */
1075 1075
            pts = is->audio_clock;
1076 1076
            *pts_ptr = pts;
1077
            n = 2 * is->audio_st->codec.channels;
1077
            n = 2 * is->audio_st->codec->channels;
1078 1078
            is->audio_clock += (double)data_size / 
1079
                (double)(n * is->audio_st->codec.sample_rate);
1079
                (double)(n * is->audio_st->codec->sample_rate);
1080 1080
#if defined(DEBUG_SYNC)
1081 1081
            {
1082 1082
                static double last_clock;
......
1164 1164

  
1165 1165
    if (stream_index < 0 || stream_index >= ic->nb_streams)
1166 1166
        return -1;
1167
    enc = &ic->streams[stream_index]->codec;
1167
    enc = ic->streams[stream_index]->codec;
1168 1168
    
1169 1169
    /* prepare audio output */
1170 1170
    if (enc->codec_type == CODEC_TYPE_AUDIO) {
......
1248 1248
    AVFormatContext *ic = is->ic;
1249 1249
    AVCodecContext *enc;
1250 1250
    
1251
    enc = &ic->streams[stream_index]->codec;
1251
    enc = ic->streams[stream_index]->codec;
1252 1252

  
1253 1253
    switch(enc->codec_type) {
1254 1254
    case CODEC_TYPE_AUDIO:
......
1387 1387
    }
1388 1388

  
1389 1389
    for(i = 0; i < ic->nb_streams; i++) {
1390
        AVCodecContext *enc = &ic->streams[i]->codec;
1390
        AVCodecContext *enc = ic->streams[i]->codec;
1391 1391
        switch(enc->codec_type) {
1392 1392
        case CODEC_TYPE_AUDIO:
1393 1393
            if (audio_index < 0 && !audio_disable)
......
1455 1455
                }
1456 1456
                if (is->video_stream >= 0) {
1457 1457
                    packet_queue_flush(&is->videoq);
1458
                    avcodec_flush_buffers(&ic->streams[video_index]->codec);
1458
                    avcodec_flush_buffers(ic->streams[video_index]->codec);
1459 1459
                }
1460 1460
            }
1461 1461
            SDL_UnlockMutex(is->audio_decoder_mutex);
......
1594 1594
        if (stream_index == start_index)
1595 1595
            return;
1596 1596
        st = ic->streams[stream_index];
1597
        if (st->codec.codec_type == codec_type) {
1597
        if (st->codec->codec_type == codec_type) {
1598 1598
            /* check that parameters are OK */
1599 1599
            switch(codec_type) {
1600 1600
            case CODEC_TYPE_AUDIO:
1601
                if (st->codec.sample_rate != 0 &&
1602
                    st->codec.channels != 0)
1601
                if (st->codec->sample_rate != 0 &&
1602
                    st->codec->channels != 0)
1603 1603
                    goto the_end;
1604 1604
                break;
1605 1605
            case CODEC_TYPE_VIDEO:
ffserver.c
728 728
        /* close each frame parser */
729 729
        for(i=0;i<c->fmt_in->nb_streams;i++) {
730 730
            st = c->fmt_in->streams[i];
731
            if (st->codec.codec) {
732
                avcodec_close(&st->codec);
731
            if (st->codec->codec) {
732
                avcodec_close(st->codec);
733 733
            }
734 734
        }
735 735
        av_close_input_file(c->fmt_in);
......
1002 1002
    int best = -1;
1003 1003

  
1004 1004
    for (i = 0; i < feed->nb_streams; i++) {
1005
        AVCodecContext *feed_codec = &feed->streams[i]->codec;
1005
        AVCodecContext *feed_codec = feed->streams[i]->codec;
1006 1006

  
1007 1007
        if (feed_codec->codec_id != codec->codec_id ||
1008 1008
            feed_codec->sample_rate != codec->sample_rate ||
......
1044 1044
        return 0;
1045 1045

  
1046 1046
    for (i = 0; i < req->nb_streams; i++) {
1047
        AVCodecContext *codec = &req->streams[i]->codec;
1047
        AVCodecContext *codec = req->streams[i]->codec;
1048 1048

  
1049 1049
        switch(rates[i]) {
1050 1050
            case 0:
......
1659 1659

  
1660 1660
                    for(i=0;i<stream->nb_streams;i++) {
1661 1661
                        AVStream *st = stream->streams[i];
1662
                        AVCodec *codec = avcodec_find_encoder(st->codec.codec_id);
1663
                        switch(st->codec.codec_type) {
1662
                        AVCodec *codec = avcodec_find_encoder(st->codec->codec_id);
1663
                        switch(st->codec->codec_type) {
1664 1664
                        case CODEC_TYPE_AUDIO:
1665
                            audio_bit_rate += st->codec.bit_rate;
1665
                            audio_bit_rate += st->codec->bit_rate;
1666 1666
                            if (codec) {
1667 1667
                                if (*audio_codec_name)
1668 1668
                                    audio_codec_name_extra = "...";
......
1670 1670
                            }
1671 1671
                            break;
1672 1672
                        case CODEC_TYPE_VIDEO:
1673
                            video_bit_rate += st->codec.bit_rate;
1673
                            video_bit_rate += st->codec->bit_rate;
1674 1674
                            if (codec) {
1675 1675
                                if (*video_codec_name)
1676 1676
                                    video_codec_name_extra = "...";
......
1678 1678
                            }
1679 1679
                            break;
1680 1680
                        case CODEC_TYPE_DATA:
1681
                            video_bit_rate += st->codec.bit_rate;
1681
                            video_bit_rate += st->codec->bit_rate;
1682 1682
                            break;
1683 1683
                        default:
1684 1684
                            av_abort();
......
1744 1744

  
1745 1745
            for (i = 0; i < stream->nb_streams; i++) {
1746 1746
                AVStream *st = stream->streams[i];
1747
                AVCodec *codec = avcodec_find_encoder(st->codec.codec_id);
1747
                AVCodec *codec = avcodec_find_encoder(st->codec->codec_id);
1748 1748
                const char *type = "unknown";
1749 1749
                char parameters[64];
1750 1750

  
1751 1751
                parameters[0] = 0;
1752 1752

  
1753
                switch(st->codec.codec_type) {
1753
                switch(st->codec->codec_type) {
1754 1754
                case CODEC_TYPE_AUDIO:
1755 1755
                    type = "audio";
1756 1756
                    break;
1757 1757
                case CODEC_TYPE_VIDEO:
1758 1758
                    type = "video";
1759
                    snprintf(parameters, sizeof(parameters), "%dx%d, q=%d-%d, fps=%d", st->codec.width, st->codec.height,
1760
                                st->codec.qmin, st->codec.qmax, st->codec.time_base.den / st->codec.time_base.num);
1759
                    snprintf(parameters, sizeof(parameters), "%dx%d, q=%d-%d, fps=%d", st->codec->width, st->codec->height,
1760
                                st->codec->qmin, st->codec->qmax, st->codec->time_base.den / st->codec->time_base.num);
1761 1761
                    break;
1762 1762
                default:
1763 1763
                    av_abort();
1764 1764
                }
1765 1765
                url_fprintf(pb, "<tr><td align=right>%d<td>%s<td align=right>%d<td>%s<td>%s\n",
1766
                        i, type, st->codec.bit_rate/1000, codec ? codec->name : "", parameters);
1766
                        i, type, st->codec->bit_rate/1000, codec ? codec->name : "", parameters);
1767 1767
            }
1768 1768
            url_fprintf(pb, "</table>\n");
1769 1769

  
......
1786 1786
            for(i=0;i<stream->nb_streams;i++) {
1787 1787
                AVStream *st = stream->streams[i];
1788 1788
                FeedData *fdata = st->priv_data;
1789
                enc = &st->codec;
1789
                enc = st->codec;
1790 1790
            
1791 1791
                avcodec_string(buf, sizeof(buf), enc);
1792 1792
                avg = fdata->avg_frame_size * (float)enc->rate * 8.0;
......
1822 1822
        if (c1->stream) {
1823 1823
            for (j = 0; j < c1->stream->nb_streams; j++) {
1824 1824
                if (!c1->stream->feed) {
1825
                    bitrate += c1->stream->streams[j]->codec.bit_rate;
1825
                    bitrate += c1->stream->streams[j]->codec->bit_rate;
1826 1826
                } else {
1827 1827
                    if (c1->feed_streams[j] >= 0) {
1828
                        bitrate += c1->stream->feed->streams[c1->feed_streams[j]]->codec.bit_rate;
1828
                        bitrate += c1->stream->feed->streams[c1->feed_streams[j]]->codec->bit_rate;
1829 1829
                    }
1830 1830
                }
1831 1831
            }
......
1867 1867
    AVStream *st = s->streams[i];
1868 1868
    AVCodec *codec;
1869 1869

  
1870
    if (!st->codec.codec) {
1871
        codec = avcodec_find_decoder(st->codec.codec_id);
1870
    if (!st->codec->codec) {
1871
        codec = avcodec_find_decoder(st->codec->codec_id);
1872 1872
        if (codec && (codec->capabilities & CODEC_CAP_PARSE_ONLY)) {
1873
            st->codec.parse_only = 1;
1874
            if (avcodec_open(&st->codec, codec) < 0) {
1875
                st->codec.parse_only = 0;
1873
            st->codec->parse_only = 1;
1874
            if (avcodec_open(st->codec, codec) < 0) {
1875
                st->codec->parse_only = 0;
1876 1876
            }
1877 1877
        }
1878 1878
    }
......
1935 1935
    c->pts_stream_index = 0;
1936 1936
    for(i=0;i<c->stream->nb_streams;i++) {
1937 1937
        if (c->pts_stream_index == 0 && 
1938
            c->stream->streams[i]->codec.codec_type == CODEC_TYPE_VIDEO) {
1938
            c->stream->streams[i]->codec->codec_type == CODEC_TYPE_VIDEO) {
1939 1939
            c->pts_stream_index = i;
1940 1940
        }
1941 1941
    }
......
2010 2010

  
2011 2011
	    *st = *src;
2012 2012
	    st->priv_data = 0;
2013
            st->codec.frame_number = 0; /* XXX: should be done in
2013
            st->codec->frame_number = 0; /* XXX: should be done in
2014 2014
                                           AVStream, not in codec */
2015 2015
            /* I'm pretty sure that this is not correct...
2016 2016
             * However, without it, we crash
2017 2017
             */
2018
            st->codec.coded_frame = &dummy_frame;
2018
            st->codec->coded_frame = &dummy_frame;
2019 2019
        }
2020 2020
        c->got_key_frame = 0;
2021 2021

  
......
2144 2144
                              av_free_packet(&pkt);
2145 2145
                              break;
2146 2146
                            }
2147
                            codec = &ctx->streams[0]->codec;
2147
                            codec = ctx->streams[0]->codec;
2148 2148
                            /* only one stream per RTP connection */
2149 2149
                            pkt.stream_index = 0;
2150 2150
                        } else {
2151 2151
                            ctx = &c->fmt_ctx;
2152 2152
                            /* Fudge here */
2153
                            codec = &ctx->streams[pkt.stream_index]->codec;
2153
                            codec = ctx->streams[pkt.stream_index]->codec;
2154 2154
                        }
2155 2155
                        
2156 2156
                        codec->coded_frame->key_frame = ((pkt.flags & PKT_FLAG_KEY) != 0);
......
2462 2462
                goto fail;
2463 2463
            }
2464 2464
            for (i = 0; i < s.nb_streams; i++) {
2465
                memcpy(&feed->streams[i]->codec, 
2466
                       &s.streams[i]->codec, sizeof(AVCodecContext));
2465
                memcpy(feed->streams[i]->codec, 
2466
                       s.streams[i]->codec, sizeof(AVCodecContext));
2467 2467
            } 
2468 2468
            av_freep(&s.priv_data);
2469 2469
        }
......
2638 2638
    private_payload_type = RTP_PT_PRIVATE;
2639 2639
    for(i = 0; i < stream->nb_streams; i++) {
2640 2640
        st = stream->streams[i];
2641
        if (st->codec.codec_id == CODEC_ID_MPEG2TS) {
2641
        if (st->codec->codec_id == CODEC_ID_MPEG2TS) {
2642 2642
            mediatype = "video";
2643 2643
        } else {
2644
            switch(st->codec.codec_type) {
2644
            switch(st->codec->codec_type) {
2645 2645
            case CODEC_TYPE_AUDIO:
2646 2646
                mediatype = "audio";
2647 2647
                break;
......
2655 2655
        }
2656 2656
        /* NOTE: the port indication is not correct in case of
2657 2657
           unicast. It is not an issue because RTSP gives it */
2658
        payload_type = rtp_get_payload_type(&st->codec);
2658
        payload_type = rtp_get_payload_type(st->codec);
2659 2659
        if (payload_type < 0)
2660 2660
            payload_type = private_payload_type++;
2661 2661
        if (stream->is_multicast) {
......
2667 2667
                    mediatype, port, payload_type);
2668 2668
        if (payload_type >= RTP_PT_PRIVATE) {
2669 2669
            /* for private payload type, we need to give more info */
2670
            switch(st->codec.codec_id) {
2670
            switch(st->codec->codec_id) {
2671 2671
            case CODEC_ID_MPEG4:
2672 2672
                {
2673 2673
                    uint8_t *data;
2674 2674
                    url_fprintf(pb, "a=rtpmap:%d MP4V-ES/%d\n", 
2675 2675
                                payload_type, 90000);
2676 2676
                    /* we must also add the mpeg4 header */
2677
                    data = st->codec.extradata;
2677
                    data = st->codec->extradata;
2678 2678
                    if (data) {
2679 2679
                        url_fprintf(pb, "a=fmtp:%d config=", payload_type);
2680
                        for(j=0;j<st->codec.extradata_size;j++) {
2680
                        for(j=0;j<st->codec->extradata_size;j++) {
2681 2681
                            url_fprintf(pb, "%02x", data[j]);
2682 2682
                        }
2683 2683
                        url_fprintf(pb, "\n");
......
3222 3222
    if (!fst)
3223 3223
        return NULL;
3224 3224
    fst->priv_data = av_mallocz(sizeof(FeedData));
3225
    memcpy(&fst->codec, codec, sizeof(AVCodecContext));
3226
    fst->codec.coded_frame = &dummy_frame;
3225
    memcpy(fst->codec, codec, sizeof(AVCodecContext));
3226
    fst->codec->coded_frame = &dummy_frame;
3227 3227
    fst->index = stream->nb_streams;
3228 3228
    av_set_pts_info(fst, 33, 1, 90000);
3229 3229
    stream->streams[stream->nb_streams++] = fst;
......
3237 3237
    AVCodecContext *av, *av1;
3238 3238
    int i;
3239 3239

  
3240
    av = &st->codec;
3240
    av = st->codec;
3241 3241
    for(i=0;i<feed->nb_streams;i++) {
3242 3242
        st = feed->streams[i];
3243
        av1 = &st->codec;
3243
        av1 = st->codec;
3244 3244
        if (av1->codec_id == av->codec_id &&
3245 3245
            av1->codec_type == av->codec_type &&
3246 3246
            av1->bit_rate == av->bit_rate) {
......
3297 3297
    mpeg4_count = 0;
3298 3298
    for(i=0;i<infile->nb_streams;i++) {
3299 3299
        st = infile->streams[i];
3300
        if (st->codec.codec_id == CODEC_ID_MPEG4 &&
3301
            st->codec.extradata_size == 0) {
3300
        if (st->codec->codec_id == CODEC_ID_MPEG4 &&
3301
            st->codec->extradata_size == 0) {
3302 3302
            mpeg4_count++;
3303 3303
        }
3304 3304
    }
......
3310 3310
        if (av_read_packet(infile, &pkt) < 0)
3311 3311
            break;
3312 3312
        st = infile->streams[pkt.stream_index];
3313
        if (st->codec.codec_id == CODEC_ID_MPEG4 &&
3314
            st->codec.extradata_size == 0) {
3315
            av_freep(&st->codec.extradata);
3313
        if (st->codec->codec_id == CODEC_ID_MPEG4 &&
3314
            st->codec->extradata_size == 0) {
3315
            av_freep(&st->codec->extradata);
3316 3316
            /* fill extradata with the header */
3317 3317
            /* XXX: we make hard suppositions here ! */
3318 3318
            p = pkt.data;
......
3322 3322
                    p[2] == 0x01 && p[3] == 0xb6) {
3323 3323
                    size = p - pkt.data;
3324 3324
                    //                    av_hex_dump(pkt.data, size);
3325
                    st->codec.extradata = av_malloc(size);
3326
                    st->codec.extradata_size = size;
3327
                    memcpy(st->codec.extradata, pkt.data, size);
3325
                    st->codec->extradata = av_malloc(size);
3326
                    st->codec->extradata_size = size;
3327
                    memcpy(st->codec->extradata, pkt.data, size);
3328 3328
                    break;
3329 3329
                }
3330 3330
                p++;
......
3376 3376
                extract_mpeg4_header(infile);
3377 3377

  
3378 3378
                for(i=0;i<infile->nb_streams;i++) {
3379
                    add_av_stream1(stream, &infile->streams[i]->codec);
3379
                    add_av_stream1(stream, infile->streams[i]->codec);
3380 3380
                }
3381 3381
                av_close_input_file(infile);
3382 3382
            }
......
3441 3441
                        } else {
3442 3442
                            AVCodecContext *ccf, *ccs;
3443 3443

  
3444
                            ccf = &sf->codec;
3445
                            ccs = &ss->codec;
3444
                            ccf = sf->codec;
3445
                            ccs = ss->codec;
3446 3446
#define CHECK_CODEC(x)  (ccf->x != ccs->x)
3447 3447

  
3448 3448
                            if (CHECK_CODEC(codec) || CHECK_CODEC(codec_type)) {
......
3550 3550
        bandwidth = 0;
3551 3551
        for(i=0;i<stream->nb_streams;i++) {
3552 3552
            AVStream *st = stream->streams[i];
3553
            switch(st->codec.codec_type) {
3553
            switch(st->codec->codec_type) {
3554 3554
            case CODEC_TYPE_AUDIO:
3555 3555
            case CODEC_TYPE_VIDEO:
3556
                bandwidth += st->codec.bit_rate;
3556
                bandwidth += st->codec->bit_rate;
3557 3557
                break;
3558 3558
            default:
3559 3559
                break;
......
3665 3665
    if (!st)
3666 3666
        return;
3667 3667
    stream->streams[stream->nb_streams++] = st;
3668
    memcpy(&st->codec, av, sizeof(AVCodecContext));
3668
    memcpy(st->codec, av, sizeof(AVCodecContext));
3669 3669
}
3670 3670

  
3671 3671
static int opt_audio_codec(const char *arg)
libavformat/4xm.c
166 166

  
167 167
            fourxm->video_stream_index = st->index;
168 168

  
169
            st->codec.codec_type = CODEC_TYPE_VIDEO;
170
            st->codec.codec_id = CODEC_ID_4XM;
171
            st->codec.codec_tag = 0;  /* no fourcc */
172
            st->codec.width = fourxm->width;
173
            st->codec.height = fourxm->height;
169
            st->codec->codec_type = CODEC_TYPE_VIDEO;
170
            st->codec->codec_id = CODEC_ID_4XM;
171
            st->codec->codec_tag = 0;  /* no fourcc */
172
            st->codec->width = fourxm->width;
173
            st->codec->height = fourxm->height;
174 174

  
175 175
        } else if (fourcc_tag == strk_TAG) {
176 176
            /* check that there is enough data */
......
205 205

  
206 206
            fourxm->tracks[current_track].stream_index = st->index;
207 207

  
208
            st->codec.codec_type = CODEC_TYPE_AUDIO;
209
            st->codec.codec_tag = 1;
210
            st->codec.channels = fourxm->tracks[current_track].channels;
211
            st->codec.sample_rate = fourxm->tracks[current_track].sample_rate;
212
            st->codec.bits_per_sample = fourxm->tracks[current_track].bits;
213
            st->codec.bit_rate = st->codec.channels * st->codec.sample_rate *
214
                st->codec.bits_per_sample;
215
            st->codec.block_align = st->codec.channels * st->codec.bits_per_sample;
208
            st->codec->codec_type = CODEC_TYPE_AUDIO;
209
            st->codec->codec_tag = 1;
210
            st->codec->channels = fourxm->tracks[current_track].channels;
211
            st->codec->sample_rate = fourxm->tracks[current_track].sample_rate;
212
            st->codec->bits_per_sample = fourxm->tracks[current_track].bits;
213
            st->codec->bit_rate = st->codec->channels * st->codec->sample_rate *
214
                st->codec->bits_per_sample;
215
            st->codec->block_align = st->codec->channels * st->codec->bits_per_sample;
216 216
            if (fourxm->tracks[current_track].adpcm)
217
                st->codec.codec_id = CODEC_ID_ADPCM_4XM;
218
            else if (st->codec.bits_per_sample == 8)
219
                st->codec.codec_id = CODEC_ID_PCM_U8;
217
                st->codec->codec_id = CODEC_ID_ADPCM_4XM;
218
            else if (st->codec->bits_per_sample == 8)
219
                st->codec->codec_id = CODEC_ID_PCM_U8;
220 220
            else
221
                st->codec.codec_id = CODEC_ID_PCM_S16LE;
221
                st->codec->codec_id = CODEC_ID_PCM_S16LE;
222 222
        }
223 223
    }
224 224

  
libavformat/amr.c
31 31
static int amr_write_header(AVFormatContext *s)
32 32
{
33 33
    ByteIOContext *pb = &s->pb;
34
    AVCodecContext *enc = &s->streams[0]->codec;
34
    AVCodecContext *enc = s->streams[0]->codec;
35 35

  
36 36
    s->priv_data = NULL;
37 37

  
......
100 100
            return AVERROR_NOMEM;
101 101
        }
102 102
    
103
        st->codec.codec_type = CODEC_TYPE_AUDIO;
104
        st->codec.codec_tag = MKTAG('s', 'a', 'w', 'b');
105
        st->codec.codec_id = CODEC_ID_AMR_WB;
106
        st->codec.channels = 1;
107
        st->codec.sample_rate = 16000;
103
        st->codec->codec_type = CODEC_TYPE_AUDIO;
104
        st->codec->codec_tag = MKTAG('s', 'a', 'w', 'b');
105
        st->codec->codec_id = CODEC_ID_AMR_WB;
106
        st->codec->channels = 1;
107
        st->codec->sample_rate = 16000;
108 108
    }
109 109
    else
110 110
    {
......
114 114
            return AVERROR_NOMEM;
115 115
        }
116 116
    
117
        st->codec.codec_type = CODEC_TYPE_AUDIO;
118
        st->codec.codec_tag = MKTAG('s', 'a', 'm', 'r');
119
        st->codec.codec_id = CODEC_ID_AMR_NB;
120
        st->codec.channels = 1;
121
        st->codec.sample_rate = 8000;
117
        st->codec->codec_type = CODEC_TYPE_AUDIO;
118
        st->codec->codec_tag = MKTAG('s', 'a', 'm', 'r');
119
        st->codec->codec_id = CODEC_ID_AMR_NB;
120
        st->codec->channels = 1;
121
        st->codec->sample_rate = 8000;
122 122
    }
123 123

  
124 124
    return 0;
......
129 129
static int amr_read_packet(AVFormatContext *s,
130 130
                          AVPacket *pkt)
131 131
{
132
    AVCodecContext *enc = &s->streams[0]->codec;
132
    AVCodecContext *enc = s->streams[0]->codec;
133 133

  
134 134
    if (enc->codec_id == CODEC_ID_AMR_NB)
135 135
    {
libavformat/asf-enc.c
289 289

  
290 290
    bit_rate = 0;
291 291
    for(n=0;n<s->nb_streams;n++) {
292
        enc = &s->streams[n]->codec;
292
        enc = s->streams[n]->codec;
293 293

  
294 294
        av_set_pts_info(s->streams[n], 32, 1, 1000); /* 32 bit pts in ms */
295 295

  
......
353 353
        int er_spr_len = 0;
354 354
        //        ASFStream *stream = &asf->streams[n];
355 355

  
356
        enc = &s->streams[n]->codec;
356
        enc = s->streams[n]->codec;
357 357
        asf->streams[n].num = n + 1;
358 358
        asf->streams[n].seq = 0;
359 359

  
......
437 437
    for(n=0;n<s->nb_streams;n++) {
438 438
        AVCodec *p;
439 439

  
440
        enc = &s->streams[n]->codec;
440
        enc = s->streams[n]->codec;
441 441
        p = avcodec_find_encoder(enc->codec_id);
442 442

  
443 443
        put_le16(pb, asf->streams[n].num);
......
730 730
    int64_t packet_st,pts; 
731 731
    int start_sec,i;
732 732

  
733
    codec = &s->streams[pkt->stream_index]->codec;
733
    codec = s->streams[pkt->stream_index]->codec;
734 734
    stream = &asf->streams[pkt->stream_index];
735 735

  
736 736
    //XXX /FIXME use duration from AVPacket (quick hack by)
libavformat/asf.c
216 216
            asf->asfid2avid[st->id] = s->nb_streams - 1;
217 217

  
218 218
            get_le32(pb);
219
	    st->codec.codec_type = type;
219
	    st->codec->codec_type = type;
220 220
            if (type == CODEC_TYPE_AUDIO) {
221
                get_wav_header(pb, &st->codec, type_specific_size);
221
                get_wav_header(pb, st->codec, type_specific_size);
222 222
                st->need_parsing = 1;
223 223
		/* We have to init the frame size at some point .... */
224 224
		pos2 = url_ftell(pb);
......
237 237
			|| (asf_st->ds_packet_size/asf_st->ds_chunk_size <= 1))
238 238
			asf_st->ds_span = 0; // disable descrambling
239 239
		}
240
                switch (st->codec.codec_id) {
240
                switch (st->codec->codec_id) {
241 241
                case CODEC_ID_MP3:
242
                    st->codec.frame_size = MPA_FRAME_SIZE;
242
                    st->codec->frame_size = MPA_FRAME_SIZE;
243 243
                    break;
244 244
                case CODEC_ID_PCM_S16LE:
245 245
                case CODEC_ID_PCM_S16BE:
......
249 249
                case CODEC_ID_PCM_U8:
250 250
                case CODEC_ID_PCM_ALAW:
251 251
                case CODEC_ID_PCM_MULAW:
252
                    st->codec.frame_size = 1;
252
                    st->codec->frame_size = 1;
253 253
                    break;
254 254
                default:
255 255
                    /* This is probably wrong, but it prevents a crash later */
256
                    st->codec.frame_size = 1;
256
                    st->codec->frame_size = 1;
257 257
                    break;
258 258
                }
259 259
            } else {
......
262 262
                get_byte(pb);
263 263
                size = get_le16(pb); /* size */
264 264
                sizeX= get_le32(pb); /* size */
265
                st->codec.width = get_le32(pb);
266
		st->codec.height = get_le32(pb);
265
                st->codec->width = get_le32(pb);
266
		st->codec->height = get_le32(pb);
267 267
                /* not available for asf */
268 268
                get_le16(pb); /* panes */
269
		st->codec.bits_per_sample = get_le16(pb); /* depth */
269
		st->codec->bits_per_sample = get_le16(pb); /* depth */
270 270
                tag1 = get_le32(pb);
271 271
		url_fskip(pb, 20);
272 272
//                av_log(NULL, AV_LOG_DEBUG, "size:%d tsize:%d sizeX:%d\n", size, total_size, sizeX);
273 273
                size= sizeX;
274 274
		if (size > 40) {
275
		    st->codec.extradata_size = size - 40;
276
		    st->codec.extradata = av_mallocz(st->codec.extradata_size + FF_INPUT_BUFFER_PADDING_SIZE);
277
		    get_buffer(pb, st->codec.extradata, st->codec.extradata_size);
275
		    st->codec->extradata_size = size - 40;
276
		    st->codec->extradata = av_mallocz(st->codec->extradata_size + FF_INPUT_BUFFER_PADDING_SIZE);
277
		    get_buffer(pb, st->codec->extradata, st->codec->extradata_size);
278 278
		}
279 279

  
280 280
        /* Extract palette from extradata if bpp <= 8 */
281 281
        /* This code assumes that extradata contains only palette */
282 282
        /* This is true for all paletted codecs implemented in ffmpeg */
283
        if (st->codec.extradata_size && (st->codec.bits_per_sample <= 8)) {
284
            st->codec.palctrl = av_mallocz(sizeof(AVPaletteControl));
283
        if (st->codec->extradata_size && (st->codec->bits_per_sample <= 8)) {
284
            st->codec->palctrl = av_mallocz(sizeof(AVPaletteControl));
285 285
#ifdef WORDS_BIGENDIAN
286
            for (i = 0; i < FFMIN(st->codec.extradata_size, AVPALETTE_SIZE)/4; i++)
287
                st->codec.palctrl->palette[i] = bswap_32(((uint32_t*)st->codec.extradata)[i]);
286
            for (i = 0; i < FFMIN(st->codec->extradata_size, AVPALETTE_SIZE)/4; i++)
287
                st->codec->palctrl->palette[i] = bswap_32(((uint32_t*)st->codec->extradata)[i]);
288 288
#else
289
            memcpy(st->codec.palctrl->palette, st->codec.extradata,
290
                   FFMIN(st->codec.extradata_size, AVPALETTE_SIZE));
289
            memcpy(st->codec->palctrl->palette, st->codec->extradata,
290
                   FFMIN(st->codec->extradata_size, AVPALETTE_SIZE));
291 291
#endif
292
            st->codec.palctrl->palette_changed = 1;
292
            st->codec->palctrl->palette_changed = 1;
293 293
        }
294 294

  
295
                st->codec.codec_tag = tag1;
296
		st->codec.codec_id = codec_get_id(codec_bmp_tags, tag1);
295
                st->codec->codec_tag = tag1;
296
		st->codec->codec_id = codec_get_id(codec_bmp_tags, tag1);
297 297
                if(tag1 == MKTAG('D', 'V', 'R', ' '))
298 298
                    st->need_parsing = 1;
299 299
            }
......
398 398
        AVStream *st = s->streams[i];
399 399
	if (st) {
400 400
	    av_free(st->priv_data);
401
            av_free(st->codec.extradata);
401
            av_free(st->codec->extradata);
402 402
	}
403 403
        av_free(st);
404 404
    }
......
608 608
            asf_st->packet_pos= asf->packet_pos;            
609 609
//printf("new packet: stream:%d key:%d packet_key:%d audio:%d size:%d\n", 
610 610
//asf->stream_index, asf->packet_key_frame, asf_st->pkt.flags & PKT_FLAG_KEY,
611
//s->streams[asf->stream_index]->codec.codec_type == CODEC_TYPE_AUDIO, asf->packet_obj_size);
612
	    if (s->streams[asf->stream_index]->codec.codec_type == CODEC_TYPE_AUDIO) 
611
//s->streams[asf->stream_index]->codec->codec_type == CODEC_TYPE_AUDIO, asf->packet_obj_size);
612
	    if (s->streams[asf->stream_index]->codec->codec_type == CODEC_TYPE_AUDIO) 
613 613
		asf->packet_key_frame = 1;
614 614
	    if (asf->packet_key_frame)
615 615
		asf_st->pkt.flags |= PKT_FLAG_KEY;
......
666 666
    for(i=0;i<s->nb_streams;i++) {
667 667
	AVStream *st = s->streams[i];
668 668
	av_free(st->priv_data);
669
	av_free(st->codec.extradata);
670
    av_free(st->codec.palctrl);
669
	av_free(st->codec->extradata);
670
    av_free(st->codec->palctrl);
671 671
    }
672 672
    return 0;
673 673
}
libavformat/au.c
63 63
    s->priv_data = NULL;
64 64

  
65 65
    /* format header */
66
    if (put_au_header(pb, &s->streams[0]->codec) < 0) {
66
    if (put_au_header(pb, s->streams[0]->codec) < 0) {
67 67
        return -1;
68 68
    }
69 69

  
......
143 143
    st = av_new_stream(s, 0);
144 144
    if (!st)
145 145
        return -1;
146
    st->codec.codec_type = CODEC_TYPE_AUDIO;
147
    st->codec.codec_tag = id;
148
    st->codec.codec_id = codec;
149
    st->codec.channels = channels;
150
    st->codec.sample_rate = rate;
146
    st->codec->codec_type = CODEC_TYPE_AUDIO;
147
    st->codec->codec_tag = id;
148
    st->codec->codec_id = codec;
149
    st->codec->channels = channels;
150
    st->codec->sample_rate = rate;
151 151
    av_set_pts_info(st, 64, 1, rate);
152 152
    return 0;
153 153
}
libavformat/audio.c
162 162
    int ret;
163 163

  
164 164
    st = s1->streams[0];
165
    s->sample_rate = st->codec.sample_rate;
166
    s->channels = st->codec.channels;
165
    s->sample_rate = st->codec->sample_rate;
166
    s->channels = st->codec->channels;
167 167
    ret = audio_open(s, 1, NULL);
168 168
    if (ret < 0) {
169 169
        return AVERROR_IO;
......
234 234
    }
235 235

  
236 236
    /* take real parameters */
237
    st->codec.codec_type = CODEC_TYPE_AUDIO;
238
    st->codec.codec_id = s->codec_id;
239
    st->codec.sample_rate = s->sample_rate;
240
    st->codec.channels = s->channels;
237
    st->codec->codec_type = CODEC_TYPE_AUDIO;
238
    st->codec->codec_id = s->codec_id;
239
    st->codec->sample_rate = s->sample_rate;
240
    st->codec->channels = s->channels;
241 241

  
242 242
    av_set_pts_info(st, 48, 1, 1000000);  /* 48 bits pts in us */
243 243
    return 0;
libavformat/avformat.h
5 5
extern "C" {
6 6
#endif
7 7

  
8
#define LIBAVFORMAT_BUILD       4628
8
#define LIBAVFORMAT_BUILD       4629
9 9

  
10 10
#define LIBAVFORMAT_VERSION_INT FFMPEG_VERSION_INT
11 11
#define LIBAVFORMAT_VERSION     FFMPEG_VERSION
......
216 216
typedef struct AVStream {
217 217
    int index;    /* stream index in AVFormatContext */
218 218
    int id;       /* format specific stream id */
219
    AVCodecContext codec; /* codec context */
219
    AVCodecContext *codec; /* codec context */
220 220
    /**
221 221
     * real base frame rate of the stream.
222 222
     * for example if the timebase is 1/90000 and all frames have either 
libavformat/avidec.c
178 178
	           goto fail;
179 179
                
180 180
		ast = s->streams[0]->priv_data;
181
		av_freep(&s->streams[0]->codec.extradata);
181
		av_freep(&s->streams[0]->codec->extradata);
182 182
		av_freep(&s->streams[0]);
183 183
		s->nb_streams = 0;
184 184
	        avi->dv_demux = dv_init_demux(s);
......
199 199
            } 
200 200
            st = s->streams[stream_index];
201 201
            ast = st->priv_data;
202
            st->codec.stream_codec_tag= handler;
202
            st->codec->stream_codec_tag= handler;
203 203

  
204 204
            get_le32(pb); /* flags */
205 205
            get_le16(pb); /* priority */
......
259 259
                switch(codec_type) {
260 260
                case CODEC_TYPE_VIDEO:
261 261
                    get_le32(pb); /* size */
262
                    st->codec.width = get_le32(pb);
263
                    st->codec.height = get_le32(pb);
262
                    st->codec->width = get_le32(pb);
263
                    st->codec->height = get_le32(pb);
264 264
                    get_le16(pb); /* panes */
265
                    st->codec.bits_per_sample= get_le16(pb); /* depth */
265
                    st->codec->bits_per_sample= get_le16(pb); /* depth */
266 266
                    tag1 = get_le32(pb);
267 267
                    get_le32(pb); /* ImageSize */
268 268
                    get_le32(pb); /* XPelsPerMeter */
......
271 271
                    get_le32(pb); /* ClrImportant */
272 272

  
273 273
                 if(size > 10*4 && size<(1<<30)){
274
                    st->codec.extradata_size= size - 10*4;
275
                    st->codec.extradata= av_malloc(st->codec.extradata_size + FF_INPUT_BUFFER_PADDING_SIZE);
276
                    get_buffer(pb, st->codec.extradata, st->codec.extradata_size);
274
                    st->codec->extradata_size= size - 10*4;
275
                    st->codec->extradata= av_malloc(st->codec->extradata_size + FF_INPUT_BUFFER_PADDING_SIZE);
276
                    get_buffer(pb, st->codec->extradata, st->codec->extradata_size);
277 277
                 }
278 278
                    
279
                    if(st->codec.extradata_size & 1) //FIXME check if the encoder really did this correctly
279
                    if(st->codec->extradata_size & 1) //FIXME check if the encoder really did this correctly
280 280
                        get_byte(pb);
281 281

  
282 282
                    /* Extract palette from extradata if bpp <= 8 */
283 283
                    /* This code assumes that extradata contains only palette */
284 284
                    /* This is true for all paletted codecs implemented in ffmpeg */
285
                    if (st->codec.extradata_size && (st->codec.bits_per_sample <= 8)) {
286
                        st->codec.palctrl = av_mallocz(sizeof(AVPaletteControl));
285
                    if (st->codec->extradata_size && (st->codec->bits_per_sample <= 8)) {
286
                        st->codec->palctrl = av_mallocz(sizeof(AVPaletteControl));
287 287
#ifdef WORDS_BIGENDIAN
288
                        for (i = 0; i < FFMIN(st->codec.extradata_size, AVPALETTE_SIZE)/4; i++)
289
                            st->codec.palctrl->palette[i] = bswap_32(((uint32_t*)st->codec.extradata)[i]);
288
                        for (i = 0; i < FFMIN(st->codec->extradata_size, AVPALETTE_SIZE)/4; i++)
289
                            st->codec->palctrl->palette[i] = bswap_32(((uint32_t*)st->codec->extradata)[i]);
290 290
#else
291
                        memcpy(st->codec.palctrl->palette, st->codec.extradata,
292
                               FFMIN(st->codec.extradata_size, AVPALETTE_SIZE));
291
                        memcpy(st->codec->palctrl->palette, st->codec->extradata,
292
                               FFMIN(st->codec->extradata_size, AVPALETTE_SIZE));
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff