X-Git-Url: http://git.cinelerra-gg.org/git/?a=blobdiff_plain;f=cinelerra-5.1%2Fcinelerra%2Fffmpeg.C;h=493be6abeace4e55e9eac4177964649a63c6fc2e;hb=3643286e2dbb3002604a62e3e6fd834716b4ae63;hp=a6f67d85eb3d54fcb804e28b85eb49ea73f18846;hpb=12d4e343f31707c899e6e4daa10c68b172433cff;p=goodguy%2Fcinelerra.git diff --git a/cinelerra-5.1/cinelerra/ffmpeg.C b/cinelerra-5.1/cinelerra/ffmpeg.C index a6f67d85..493be6ab 100644 --- a/cinelerra-5.1/cinelerra/ffmpeg.C +++ b/cinelerra-5.1/cinelerra/ffmpeg.C @@ -421,7 +421,6 @@ int FFStream::decode_activate() } if( ret >= 0 && hw_type != AV_HWDEVICE_TYPE_NONE ) { ret = decode_hw_format(decoder, hw_type); - if( !ret ) hw_type = AV_HWDEVICE_TYPE_NONE; } if( ret >= 0 ) { avcodec_parameters_to_context(avctx, st->codecpar); @@ -429,36 +428,35 @@ int FFStream::decode_activate() avctx->thread_count = ffmpeg->ff_cpus(); ret = avcodec_open2(avctx, decoder, &copts); } + AVFrame *hw_frame = 0; if( ret >= 0 && hw_type != AV_HWDEVICE_TYPE_NONE ) { - AVFrame *frame = av_frame_alloc(); - if( !frame ) { + if( !(hw_frame=av_frame_alloc()) ) { fprintf(stderr, "FFStream::decode_activate: av_frame_alloc failed\n"); ret = AVERROR(ENOMEM); } if( ret >= 0 ) - ret = decode(frame); - if( ret < 0 || hw_pix_fmt == AV_PIX_FMT_NONE ) { - ff_err(ret, "HW device init failed, using SW decode.\nfile:%s\n", - ffmpeg->fmt_ctx->url); - avcodec_close(avctx); - avcodec_free_context(&avctx); - av_buffer_unref(&hw_device_ctx); - hw_device_ctx = 0; - av_frame_free(&frame); - hw_type = AV_HWDEVICE_TYPE_NONE; - int flags = AVSEEK_FLAG_BACKWARD | AVSEEK_FLAG_ANY; - int idx = st->index; - av_seek_frame(fmt_ctx, idx, INT64_MIN, flags); - need_packet = 1; flushed = 0; - seeked = 1; st_eof(0); - ret = 0; - continue; - } - probe_frame = frame; + ret = decode(hw_frame); } - if( ret >= 0 ) { - reading = 1; + if( ret < 0 && hw_type != AV_HWDEVICE_TYPE_NONE ) { + ff_err(ret, "HW device init failed, using SW decode.\nfile:%s\n", + ffmpeg->fmt_ctx->url); + avcodec_close(avctx); + avcodec_free_context(&avctx); + av_buffer_unref(&hw_device_ctx); + hw_device_ctx = 0; + av_frame_free(&hw_frame); + hw_type = AV_HWDEVICE_TYPE_NONE; + int flags = AVSEEK_FLAG_BACKWARD | AVSEEK_FLAG_ANY; + int idx = st->index; + av_seek_frame(fmt_ctx, idx, 0, flags); + need_packet = 1; flushed = 0; + seeked = 1; st_eof(0); + ret = 0; + continue; } + probe_frame = hw_frame; + if( ret >= 0 ) + reading = 1; else eprintf(_("open decoder failed\n")); } @@ -1088,6 +1086,7 @@ int FFVideoStream::decode_hw_format(AVCodec *decoder, AVHWDeviceType type) if( !config ) { fprintf(stderr, "Decoder %s does not support device type %s.\n", decoder->name, av_hwdevice_get_type_name(type)); + ret = -1; break; } if( (config->methods & AV_CODEC_HW_CONFIG_METHOD_HW_DEVICE_CTX) != 0 && @@ -1104,9 +1103,11 @@ int FFVideoStream::decode_hw_format(AVCodec *decoder, AVHWDeviceType type) avctx->hw_device_ctx = av_buffer_ref(hw_device_ctx); ret = 1; } - else + else { ff_err(ret, "Failed HW device create.\ndev:%s\n", av_hwdevice_get_type_name(type)); + ret = -1; + } } return ret; }