Changeset 4083 for pjproject


Ignore:
Timestamp:
Apr 25, 2012 5:12:55 AM (13 years ago)
Author:
nanang
Message:

Misc (re #1446): more support newer libavcodec version (major: 54) which deprecated AVCodec::encode and avcodec_encode_video().

File:
1 edited

Legend:

Unmodified
Added
Removed
  • pjproject/trunk/pjmedia/src/pjmedia-codec/ffmpeg_vid_codecs.c

    r4081 r4083  
    6464#endif 
    6565 
     66#if LIBAVCODEC_VER_AT_LEAST(53,61) 
     67/* Not sure when AVCodec::encode2 is introduced. It appears in  
     68 * libavcodec 53.61 where some codecs actually still use AVCodec::encode 
     69 * (e.g: H263, H264). 
     70 */ 
     71#  define AVCODEC_HAS_ENCODE(c)         (c->encode || c->encode2) 
     72#else 
     73#  define AVCODEC_HAS_ENCODE(c)         (c->encode) 
     74#endif 
     75#define AVCODEC_HAS_DECODE(c)           (c->decode) 
     76 
    6677 
    6778/* Prototypes for FFMPEG codecs factory */ 
     
    644655 
    645656        /* Skip duplicated codec implementation */ 
    646         if ((c->encode && (desc->info.dir & PJMEDIA_DIR_ENCODING)) || 
    647             (c->decode && (desc->info.dir & PJMEDIA_DIR_DECODING))) 
     657        if ((AVCODEC_HAS_ENCODE(c) && (desc->info.dir & PJMEDIA_DIR_ENCODING)) 
     658            || 
     659            (AVCODEC_HAS_DECODE(c) && (desc->info.dir & PJMEDIA_DIR_DECODING))) 
    648660        { 
    649661            continue; 
     
    651663 
    652664        /* Get raw/decoded format ids in the encoder */ 
    653         if (c->pix_fmts && c->encode) { 
     665        if (c->pix_fmts && AVCODEC_HAS_ENCODE(c)) { 
    654666            pjmedia_format_id raw_fmt[PJMEDIA_VID_CODEC_MAX_DEC_FMT_CNT]; 
    655667            unsigned raw_fmt_cnt = 0; 
     
    716728 
    717729        /* Get ffmpeg encoder instance */ 
    718         if (c->encode && !desc->enc) { 
     730        if (AVCODEC_HAS_ENCODE(c) && !desc->enc) { 
    719731            desc->info.dir |= PJMEDIA_DIR_ENCODING; 
    720732            desc->enc = c; 
     
    722734         
    723735        /* Get ffmpeg decoder instance */ 
    724         if (c->decode && !desc->dec) { 
     736        if (AVCODEC_HAS_DECODE(c) && !desc->dec) { 
    725737            desc->info.dir |= PJMEDIA_DIR_DECODING; 
    726738            desc->dec = c; 
     
    13931405    pj_uint8_t *p = (pj_uint8_t*)input->buf; 
    13941406    AVFrame avframe; 
    1395     pj_uint8_t *out_buf = (pj_uint8_t*)output->buf; 
    1396     int out_buf_len = output_buf_len; 
    1397     int err; 
     1407    AVPacket avpacket; 
     1408    int err, got_packet; 
    13981409    //AVRational src_timebase; 
    13991410    /* For some reasons (e.g: SSE/MMX usage), the avcodec_encode_video() must 
     
    14351446    } 
    14361447 
    1437     err = avcodec_encode_video(ff->enc_ctx, out_buf, out_buf_len, &avframe); 
     1448    av_init_packet(&avpacket); 
     1449    avpacket.data = (pj_uint8_t*)output->buf; 
     1450    avpacket.size = output_buf_len; 
     1451 
     1452#if LIBAVCODEC_VER_AT_LEAST(54,15) 
     1453    err = avcodec_encode_video2(ff->enc_ctx, &avpacket, &avframe, &got_packet); 
     1454    if (!err && got_packet) 
     1455        err = avpacket.size; 
     1456#else 
     1457    PJ_UNUSED_ARG(got_packet); 
     1458    err = avcodec_encode_video(ff->enc_ctx, avpacket.data, avpacket.size, &avframe); 
     1459#endif 
     1460 
    14381461    if (err < 0) { 
    14391462        print_ffmpeg_err(err); 
Note: See TracChangeset for help on using the changeset viewer.