QTfrontend/util/LibavInteraction.cpp
branch1.0.0
changeset 15834 8fd36e1b66ed
parent 14631 92ebe33c5eb6
equal deleted inserted replaced
15816:b0fe8c8d0bb5 15834:8fd36e1b66ed
    71 
    71 
    72 QList<Codec> codecs;
    72 QList<Codec> codecs;
    73 QMap<QString,Format> formats;
    73 QMap<QString,Format> formats;
    74 
    74 
    75 // test if given format supports given codec
    75 // test if given format supports given codec
       
    76 #if LIBAVCODEC_VERSION_MAJOR >= 59
       
    77 bool FormatQueryCodec(const AVOutputFormat *ofmt, enum AVCodecID codec_id)
       
    78 #else
    76 bool FormatQueryCodec(AVOutputFormat *ofmt, enum AVCodecID codec_id)
    79 bool FormatQueryCodec(AVOutputFormat *ofmt, enum AVCodecID codec_id)
       
    80 #endif
    77 {
    81 {
    78 #if LIBAVFORMAT_VERSION_MAJOR >= 54
    82 #if LIBAVFORMAT_VERSION_MAJOR >= 54
    79     return avformat_query_codec(ofmt, codec_id, FF_COMPLIANCE_NORMAL) == 1;
    83     return avformat_query_codec(ofmt, codec_id, FF_COMPLIANCE_NORMAL) == 1;
    80 #else
    84 #else
    81     if (ofmt->codec_tag)
    85     if (ofmt->codec_tag)
    84 #endif
    88 #endif
    85 }
    89 }
    86 
    90 
    87 LibavInteraction::LibavInteraction() : QObject()
    91 LibavInteraction::LibavInteraction() : QObject()
    88 {
    92 {
       
    93 #if LIBAVCODEC_VERSION_MAJOR < 59
    89     // initialize libav and register all codecs and formats
    94     // initialize libav and register all codecs and formats
    90     av_register_all();
    95     av_register_all();
       
    96 #endif
    91 
    97 
    92     // get list of all codecs
    98     // get list of all codecs
       
    99 #if LIBAVCODEC_VERSION_MAJOR >= 59
       
   100     const AVCodec* pCodec = NULL;
       
   101     void* i = 0;
       
   102     while ((pCodec = av_codec_iterate(&i)))
       
   103 #else
    93     AVCodec* pCodec = NULL;
   104     AVCodec* pCodec = NULL;
    94     while ((pCodec = av_codec_next(pCodec)))
   105     while ((pCodec = av_codec_next(pCodec)))
       
   106 #endif
    95     {
   107     {
    96         if (!av_codec_is_encoder(pCodec))
   108         if (!av_codec_is_encoder(pCodec))
    97             continue;
   109             continue;
    98 
   110 
    99         if (pCodec->type != AVMEDIA_TYPE_VIDEO && pCodec->type != AVMEDIA_TYPE_AUDIO)
   111         if (pCodec->type != AVMEDIA_TYPE_VIDEO && pCodec->type != AVMEDIA_TYPE_AUDIO)
   177         if (strcmp(pCodec->name, "mpeg4") == 0 || strcmp(pCodec->name, "ac3_fixed") == 0)
   189         if (strcmp(pCodec->name, "mpeg4") == 0 || strcmp(pCodec->name, "ac3_fixed") == 0)
   178             codec.isRecommended = true;
   190             codec.isRecommended = true;
   179     }
   191     }
   180 
   192 
   181     // get list of all formats
   193     // get list of all formats
       
   194 #if LIBAVCODEC_VERSION_MAJOR >= 59
       
   195     const AVOutputFormat* pFormat = NULL;
       
   196     i = 0;
       
   197     while ((pFormat = av_muxer_iterate(&i)))
       
   198 #else
   182     AVOutputFormat* pFormat = NULL;
   199     AVOutputFormat* pFormat = NULL;
   183     while ((pFormat = av_oformat_next(pFormat)))
   200     while ((pFormat = av_oformat_next(pFormat)))
       
   201 #endif
   184     {
   202     {
   185         if (!pFormat->extensions)
   203         if (!pFormat->extensions)
   186             continue;
   204             continue;
   187 
   205 
   188         // skip some strange formats to not confuse users
   206         // skip some strange formats to not confuse users
   294     for (int i = 0; i < (int)pContext->nb_streams; i++)
   312     for (int i = 0; i < (int)pContext->nb_streams; i++)
   295     {
   313     {
   296         AVStream* pStream = pContext->streams[i];
   314         AVStream* pStream = pContext->streams[i];
   297         if (!pStream)
   315         if (!pStream)
   298             continue;
   316             continue;
       
   317 #if LIBAVCODEC_VERSION_MAJOR >= 59
       
   318         const AVCodec *st_codec = avcodec_find_decoder(pContext->streams[i]->codecpar->codec_id);
       
   319         AVCodecContext* pCodec = avcodec_alloc_context3(st_codec);
       
   320         avcodec_parameters_to_context(pCodec, pContext->streams[i]->codecpar);
       
   321 #else
   299         AVCodecContext* pCodec = pContext->streams[i]->codec;
   322         AVCodecContext* pCodec = pContext->streams[i]->codec;
       
   323 #endif
   300         if (!pCodec)
   324         if (!pCodec)
   301             continue;
   325             continue;
   302 
   326 
   303 
   327 
       
   328 #if LIBAVCODEC_VERSION_MAJOR >= 59
       
   329         const AVCodec* pDecoder = avcodec_find_decoder(pCodec->codec_id);
       
   330 #else
   304         AVCodec* pDecoder = avcodec_find_decoder(pCodec->codec_id);
   331         AVCodec* pDecoder = avcodec_find_decoder(pCodec->codec_id);
       
   332 #endif
   305         QString decoderName = pDecoder ? pDecoder->name : tr("unknown");
   333         QString decoderName = pDecoder ? pDecoder->name : tr("unknown");
   306         if (pCodec->codec_type == AVMEDIA_TYPE_VIDEO)
   334         if (pCodec->codec_type == AVMEDIA_TYPE_VIDEO)
   307         {
   335         {
   308             if (pStream->avg_frame_rate.den)
   336             if (pStream->avg_frame_rate.den)
   309             {
   337             {