Revision 01f4895c libavformat/utils.c

View differences:

libavformat/utils.c
683 683

  
684 684
    *pnum = 0;
685 685
    *pden = 0;
686
    switch(st->codec.codec_type) {
686
    switch(st->codec->codec_type) {
687 687
    case CODEC_TYPE_VIDEO:
688 688
        if(st->time_base.num*1000LL > st->time_base.den){
689 689
            *pnum = st->time_base.num;
690 690
            *pden = st->time_base.den;
691
        }else if(st->codec.time_base.num*1000LL > st->codec.time_base.den){
692
            *pnum = st->codec.time_base.num;
693
            *pden = st->codec.time_base.den;
691
        }else if(st->codec->time_base.num*1000LL > st->codec->time_base.den){
692
            *pnum = st->codec->time_base.num;
693
            *pden = st->codec->time_base.den;
694 694
            if (pc && pc->repeat_pict) {
695 695
                *pden *= 2;
696 696
                *pnum = (*pnum) * (2 + pc->repeat_pict);
......
698 698
        }
699 699
        break;
700 700
    case CODEC_TYPE_AUDIO:
701
        frame_size = get_audio_frame_size(&st->codec, pkt->size);
701
        frame_size = get_audio_frame_size(st->codec, pkt->size);
702 702
        if (frame_size < 0)
703 703
            break;
704 704
        *pnum = frame_size;
705
        *pden = st->codec.sample_rate;
705
        *pden = st->codec->sample_rate;
706 706
        break;
707 707
    default:
708 708
        break;
......
756 756
        }
757 757
    }
758 758

  
759
    if(is_intra_only(&st->codec))
759
    if(is_intra_only(st->codec))
760 760
        pkt->flags |= PKT_FLAG_KEY;
761 761

  
762 762
    /* do we have a video B frame ? */
763 763
    presentation_delayed = 0;
764
    if (st->codec.codec_type == CODEC_TYPE_VIDEO) {
764
    if (st->codec->codec_type == CODEC_TYPE_VIDEO) {
765 765
        /* XXX: need has_b_frame, but cannot get it if the codec is
766 766
           not initialized */
767
        if ((   st->codec.codec_id == CODEC_ID_H264 
768
             || st->codec.has_b_frames) && 
767
        if ((   st->codec->codec_id == CODEC_ID_H264 
768
             || st->codec->has_b_frames) && 
769 769
            pc && pc->pict_type != FF_B_TYPE)
770 770
            presentation_delayed = 1;
771 771
        /* this may be redundant, but it shouldnt hurt */
......
834 834
    if (pc) {
835 835
        pkt->flags = 0;
836 836
        /* key frame computation */
837
        switch(st->codec.codec_type) {
837
        switch(st->codec->codec_type) {
838 838
        case CODEC_TYPE_VIDEO:
839 839
            if (pc->pict_type == FF_I_TYPE)
840 840
                pkt->flags |= PKT_FLAG_KEY;
......
870 870
                s->cur_st = NULL;
871 871
                return 0;
872 872
            } else if (s->cur_len > 0 && st->discard < AVDISCARD_ALL) {
873
                len = av_parser_parse(st->parser, &st->codec, &pkt->data, &pkt->size, 
873
                len = av_parser_parse(st->parser, st->codec, &pkt->data, &pkt->size, 
874 874
                                      s->cur_ptr, s->cur_len,
875 875
                                      s->cur_pkt.pts, s->cur_pkt.dts);
876 876
                s->cur_pkt.pts = AV_NOPTS_VALUE;
......
905 905
                for(i = 0; i < s->nb_streams; i++) {
906 906
                    st = s->streams[i];
907 907
                    if (st->parser && st->need_parsing) {
908
                        av_parser_parse(st->parser, &st->codec, 
908
                        av_parser_parse(st->parser, st->codec, 
909 909
                                        &pkt->data, &pkt->size, 
910 910
                                        NULL, 0, 
911 911
                                        AV_NOPTS_VALUE, AV_NOPTS_VALUE);
......
923 923
            s->cur_ptr = s->cur_pkt.data;
924 924
            s->cur_len = s->cur_pkt.size;
925 925
            if (st->need_parsing && !st->parser) {
926
                st->parser = av_parser_init(st->codec.codec_id);
926
                st->parser = av_parser_init(st->codec->codec_id);
927 927
                if (!st->parser) {
928 928
                    /* no parser available : just output the raw packets */
929 929
                    st->need_parsing = 0;
......
995 995
        return -1;
996 996
    for(i = 0; i < s->nb_streams; i++) {
997 997
        st = s->streams[i];
998
        if (st->codec.codec_type == CODEC_TYPE_VIDEO) {
998
        if (st->codec->codec_type == CODEC_TYPE_VIDEO) {
999 999
            return i;
1000 1000
        }
1001 1001
    }
......
1537 1537
        bit_rate = 0;
1538 1538
        for(i=0;i<ic->nb_streams;i++) {
1539 1539
            st = ic->streams[i];
1540
            bit_rate += st->codec.bit_rate;
1540
            bit_rate += st->codec->bit_rate;
1541 1541
        }
1542 1542
        ic->bit_rate = bit_rate;
1543 1543
    }
......
1728 1728
    int got_picture, ret=0;
1729 1729
    AVFrame picture;
1730 1730
    
1731
  if(!st->codec.codec){
1732
    codec = avcodec_find_decoder(st->codec.codec_id);
1731
  if(!st->codec->codec){
1732
    codec = avcodec_find_decoder(st->codec->codec_id);
1733 1733
    if (!codec)
1734 1734
        return -1;
1735
    ret = avcodec_open(&st->codec, codec);
1735
    ret = avcodec_open(st->codec, codec);
1736 1736
    if (ret < 0)
1737 1737
        return ret;
1738 1738
  }
1739 1739

  
1740
  if(!has_codec_parameters(&st->codec)){
1741
    switch(st->codec.codec_type) {
1740
  if(!has_codec_parameters(st->codec)){
1741
    switch(st->codec->codec_type) {
1742 1742
    case CODEC_TYPE_VIDEO:
1743
        ret = avcodec_decode_video(&st->codec, &picture, 
1743
        ret = avcodec_decode_video(st->codec, &picture, 
1744 1744
                                   &got_picture, (uint8_t *)data, size);
1745 1745
        break;
1746 1746
    case CODEC_TYPE_AUDIO:
1747 1747
        samples = av_malloc(AVCODEC_MAX_AUDIO_FRAME_SIZE);
1748 1748
        if (!samples)
1749 1749
            goto fail;
1750
        ret = avcodec_decode_audio(&st->codec, samples, 
1750
        ret = avcodec_decode_audio(st->codec, samples, 
1751 1751
                                   &got_picture, (uint8_t *)data, size);
1752 1752
        av_free(samples);
1753 1753
        break;
......
1787 1787

  
1788 1788
    for(i=0;i<ic->nb_streams;i++) {
1789 1789
        st = ic->streams[i];
1790
        if(st->codec.codec_type == CODEC_TYPE_VIDEO){
1790
        if(st->codec->codec_type == CODEC_TYPE_VIDEO){
1791 1791
/*            if(!st->time_base.num)
1792 1792
                st->time_base= */
1793
            if(!st->codec.time_base.num)
1794
                st->codec.time_base= st->time_base;
1793
            if(!st->codec->time_base.num)
1794
                st->codec->time_base= st->time_base;
1795 1795
        }
1796 1796
        //only for the split stuff
1797 1797
        if (!st->parser) {
1798
            st->parser = av_parser_init(st->codec.codec_id);
1798
            st->parser = av_parser_init(st->codec->codec_id);
1799 1799
        }
1800 1800
    }
1801 1801

  
......
1811 1811
        /* check if one codec still needs to be handled */
1812 1812
        for(i=0;i<ic->nb_streams;i++) {
1813 1813
            st = ic->streams[i];
1814
            if (!has_codec_parameters(&st->codec))
1814
            if (!has_codec_parameters(st->codec))
1815 1815
                break;
1816 1816
            /* variable fps and no guess at the real fps */
1817
            if(   st->codec.time_base.den >= 1000LL*st->codec.time_base.num
1818
               && duration_count[i]<20 && st->codec.codec_type == CODEC_TYPE_VIDEO)
1817
            if(   st->codec->time_base.den >= 1000LL*st->codec->time_base.num
1818
               && duration_count[i]<20 && st->codec->codec_type == CODEC_TYPE_VIDEO)
1819 1819
                break;
1820
            if(st->parser && st->parser->parser->split && !st->codec.extradata)
1820
            if(st->parser && st->parser->parser->split && !st->codec->extradata)
1821 1821
                break;
1822 1822
        }
1823 1823
        if (i == ic->nb_streams) {
......
1845 1845
            ret = -1; /* we could not have all the codec parameters before EOF */
1846 1846
            for(i=0;i<ic->nb_streams;i++) {
1847 1847
                st = ic->streams[i];
1848
                if (!has_codec_parameters(&st->codec))
1848
                if (!has_codec_parameters(st->codec))
1849 1849
                    break;
1850 1850
            }
1851 1851
            if (i == ic->nb_streams)
......
1898 1898
            }
1899 1899
            last_dts[pkt->stream_index]= pkt->dts;
1900 1900
        }
1901
        if(st->parser && st->parser->parser->split && !st->codec.extradata){
1902
            int i= st->parser->parser->split(&st->codec, pkt->data, pkt->size);
1901
        if(st->parser && st->parser->parser->split && !st->codec->extradata){
1902
            int i= st->parser->parser->split(st->codec, pkt->data, pkt->size);
1903 1903
            if(i){
1904
                st->codec.extradata_size= i;
1905
                st->codec.extradata= av_malloc(st->codec.extradata_size);
1906
                memcpy(st->codec.extradata, pkt->data, st->codec.extradata_size);
1904
                st->codec->extradata_size= i;
1905
                st->codec->extradata= av_malloc(st->codec->extradata_size);
1906
                memcpy(st->codec->extradata, pkt->data, st->codec->extradata_size);
1907 1907
            }
1908 1908
        }
1909 1909
        
......
1911 1911
           decompress the frame. We try to avoid that in most cases as
1912 1912
           it takes longer and uses more memory. For MPEG4, we need to
1913 1913
           decompress for Quicktime. */
1914
        if (!has_codec_parameters(&st->codec) /*&&
1915
            (st->codec.codec_id == CODEC_ID_FLV1 ||
1916
             st->codec.codec_id == CODEC_ID_H264 ||
1917
             st->codec.codec_id == CODEC_ID_H263 ||
1918
             st->codec.codec_id == CODEC_ID_H261 ||
1919
             st->codec.codec_id == CODEC_ID_VORBIS ||
1920
             st->codec.codec_id == CODEC_ID_MJPEG ||
1921
             st->codec.codec_id == CODEC_ID_PNG ||
1922
             st->codec.codec_id == CODEC_ID_PAM ||
1923
             st->codec.codec_id == CODEC_ID_PGM ||
1924
             st->codec.codec_id == CODEC_ID_PGMYUV ||
1925
             st->codec.codec_id == CODEC_ID_PBM ||
1926
             st->codec.codec_id == CODEC_ID_PPM ||
1927
             st->codec.codec_id == CODEC_ID_SHORTEN ||
1928
             (st->codec.codec_id == CODEC_ID_MPEG4 && !st->need_parsing))*/)
1914
        if (!has_codec_parameters(st->codec) /*&&
1915
            (st->codec->codec_id == CODEC_ID_FLV1 ||
1916
             st->codec->codec_id == CODEC_ID_H264 ||
1917
             st->codec->codec_id == CODEC_ID_H263 ||
1918
             st->codec->codec_id == CODEC_ID_H261 ||
1919
             st->codec->codec_id == CODEC_ID_VORBIS ||
1920
             st->codec->codec_id == CODEC_ID_MJPEG ||
1921
             st->codec->codec_id == CODEC_ID_PNG ||
1922
             st->codec->codec_id == CODEC_ID_PAM ||
1923
             st->codec->codec_id == CODEC_ID_PGM ||
1924
             st->codec->codec_id == CODEC_ID_PGMYUV ||
1925
             st->codec->codec_id == CODEC_ID_PBM ||
1926
             st->codec->codec_id == CODEC_ID_PPM ||
1927
             st->codec->codec_id == CODEC_ID_SHORTEN ||
1928
             (st->codec->codec_id == CODEC_ID_MPEG4 && !st->need_parsing))*/)
1929 1929
            try_decode_frame(st, pkt->data, pkt->size);
1930 1930
        
1931 1931
        if (av_rescale_q(st->codec_info_duration, st->time_base, AV_TIME_BASE_Q) >= MAX_STREAM_DURATION) {
......
1937 1937
    // close codecs which where opened in try_decode_frame()
1938 1938
    for(i=0;i<ic->nb_streams;i++) {
1939 1939
        st = ic->streams[i];
1940
        if(st->codec.codec)
1941
            avcodec_close(&st->codec);
1940
        if(st->codec->codec)
1941
            avcodec_close(st->codec);
1942 1942
    }
1943 1943
    for(i=0;i<ic->nb_streams;i++) {
1944 1944
        st = ic->streams[i];
1945
        if (st->codec.codec_type == CODEC_TYPE_VIDEO) {
1946
            if(st->codec.codec_id == CODEC_ID_RAWVIDEO && !st->codec.codec_tag && !st->codec.bits_per_sample)
1947
                st->codec.codec_tag= avcodec_pix_fmt_to_codec_tag(st->codec.pix_fmt);
1945
        if (st->codec->codec_type == CODEC_TYPE_VIDEO) {
1946
            if(st->codec->codec_id == CODEC_ID_RAWVIDEO && !st->codec->codec_tag && !st->codec->bits_per_sample)
1947
                st->codec->codec_tag= avcodec_pix_fmt_to_codec_tag(st->codec->pix_fmt);
1948 1948

  
1949
            if(duration_count[i] && st->codec.time_base.num*1000LL <= st->codec.time_base.den &&
1949
            if(duration_count[i] && st->codec->time_base.num*1000LL <= st->codec->time_base.den &&
1950 1950
               st->time_base.num*duration_sum[i]/duration_count[i]*1000LL > st->time_base.den){
1951 1951
                AVRational fps1;
1952 1952
                int64_t num, den;
......
1964 1964

  
1965 1965
            /* set real frame rate info */
1966 1966
            /* compute the real frame rate for telecine */
1967
            if ((st->codec.codec_id == CODEC_ID_MPEG1VIDEO ||
1968
                 st->codec.codec_id == CODEC_ID_MPEG2VIDEO) &&
1969
                st->codec.sub_id == 2) {
1967
            if ((st->codec->codec_id == CODEC_ID_MPEG1VIDEO ||
1968
                 st->codec->codec_id == CODEC_ID_MPEG2VIDEO) &&
1969
                st->codec->sub_id == 2) {
1970 1970
                if (st->codec_info_nb_frames >= 20) {
1971 1971
                    float coded_frame_rate, est_frame_rate;
1972 1972
                    est_frame_rate = ((double)st->codec_info_nb_frames * AV_TIME_BASE) / 
1973 1973
                        (double)st->codec_info_duration ;
1974
                    coded_frame_rate = 1.0/av_q2d(st->codec.time_base);
1974
                    coded_frame_rate = 1.0/av_q2d(st->codec->time_base);
1975 1975
#if 0
1976 1976
                    printf("telecine: coded_frame_rate=%0.3f est_frame_rate=%0.3f\n", 
1977 1977
                           coded_frame_rate, est_frame_rate);
......
1987 1987
            }
1988 1988
            /* if no real frame rate, use the codec one */
1989 1989
            if (!st->r_frame_rate.num){
1990
                st->r_frame_rate.num = st->codec.time_base.den;
1991
                st->r_frame_rate.den = st->codec.time_base.num;
1990
                st->r_frame_rate.num = st->codec->time_base.den;
1991
                st->r_frame_rate.den = st->codec->time_base.num;
1992 1992
            }
1993 1993
        }
1994 1994
    }
......
1998 1998
    /* correct DTS for b frame streams with no timestamps */
1999 1999
    for(i=0;i<ic->nb_streams;i++) {
2000 2000
        st = ic->streams[i];
2001
        if (st->codec.codec_type == CODEC_TYPE_VIDEO) {
2001
        if (st->codec->codec_type == CODEC_TYPE_VIDEO) {
2002 2002
            if(b-frames){
2003 2003
                ppktl = &ic->packet_buffer;
2004 2004
                while(ppkt1){
......
2069 2069
            av_parser_close(st->parser);
2070 2070
        }
2071 2071
        av_free(st->index_entries);
2072
        av_free(st->codec);
2072 2073
        av_free(st);
2073 2074
    }
2074 2075
    flush_packet_queue(s);
......
2103 2104
    st = av_mallocz(sizeof(AVStream));
2104 2105
    if (!st)
2105 2106
        return NULL;
2106
    avcodec_get_context_defaults(&st->codec);
2107
    
2108
    st->codec= avcodec_alloc_context();
2107 2109
    if (s->iformat) {
2108 2110
        /* no default bitrate if decoding */
2109
        st->codec.bit_rate = 0;
2111
        st->codec->bit_rate = 0;
2110 2112
    }
2111 2113
    st->index = s->nb_streams;
2112 2114
    st->id = id;
......
2164 2166
    for(i=0;i<s->nb_streams;i++) {
2165 2167
        st = s->streams[i];
2166 2168

  
2167
        switch (st->codec.codec_type) {
2169
        switch (st->codec->codec_type) {
2168 2170
        case CODEC_TYPE_AUDIO:
2169 2171
            av_frac_init(&st->pts, 0, 0, 
2170
                         (int64_t)st->time_base.num * st->codec.sample_rate);
2172
                         (int64_t)st->time_base.num * st->codec->sample_rate);
2171 2173
            break;
2172 2174
        case CODEC_TYPE_VIDEO:
2173 2175
            av_frac_init(&st->pts, 0, 0, 
2174
                         (int64_t)st->time_base.num * st->codec.time_base.den);
2176
                         (int64_t)st->time_base.num * st->codec->time_base.den);
2175 2177
            break;
2176 2178
        default:
2177 2179
            break;
......
2182 2184

  
2183 2185
//FIXME merge with compute_pkt_fields
2184 2186
static int compute_pkt_fields2(AVStream *st, AVPacket *pkt){
2185
    int b_frames = FFMAX(st->codec.has_b_frames, st->codec.max_b_frames);
2187
    int b_frames = FFMAX(st->codec->has_b_frames, st->codec->max_b_frames);
2186 2188
    int num, den, frame_size;
2187 2189

  
2188 2190
//    av_log(NULL, AV_LOG_DEBUG, "av_write_frame: pts:%lld dts:%lld cur_dts:%lld b:%d size:%d st:%d\n", pkt->pts, pkt->dts, st->cur_dts, b_frames, pkt->size, pkt->stream_index);
......
2234 2236
    st->pts.val= pkt->dts;
2235 2237

  
2236 2238
    /* update pts */
2237
    switch (st->codec.codec_type) {
2239
    switch (st->codec->codec_type) {
2238 2240
    case CODEC_TYPE_AUDIO:
2239
        frame_size = get_audio_frame_size(&st->codec, pkt->size);
2241
        frame_size = get_audio_frame_size(st->codec, pkt->size);
2240 2242

  
2241 2243
        /* HACK/FIXME, we skip the initial 0-size packets as they are most likely equal to the encoder delay,
2242 2244
           but it would be better if we had the real timestamps from the encoder */
......
2245 2247
        }
2246 2248
        break;
2247 2249
    case CODEC_TYPE_VIDEO:
2248
        av_frac_add(&st->pts, (int64_t)st->time_base.den * st->codec.time_base.num);
2250
        av_frac_add(&st->pts, (int64_t)st->time_base.den * st->codec->time_base.num);
2249 2251
        break;
2250 2252
    default:
2251 2253
        break;
......
2380 2382
    AVStream *st= s->streams[ pkt->stream_index];
2381 2383

  
2382 2384
    //FIXME/XXX/HACK drop zero sized packets
2383
    if(st->codec.codec_type == CODEC_TYPE_AUDIO && pkt->size==0)
2385
    if(st->codec->codec_type == CODEC_TYPE_AUDIO && pkt->size==0)
2384 2386
        return 0;
2385 2387

  
2386 2388
//av_log(NULL, AV_LOG_DEBUG, "av_interleaved_write_frame %d %Ld %Ld\n", pkt->size, pkt->dts, pkt->pts);
......
2497 2499
    }
2498 2500
    for(i=0;i<ic->nb_streams;i++) {
2499 2501
        AVStream *st = ic->streams[i];
2500
        avcodec_string(buf, sizeof(buf), &st->codec, is_output);
2502
        avcodec_string(buf, sizeof(buf), st->codec, is_output);
2501 2503
        av_log(NULL, AV_LOG_INFO, "  Stream #%d.%d", index, i);
2502 2504
        /* the pid is an important information, so we display it */
2503 2505
        /* XXX: add a generic system */

Also available in: Unified diff