+AVHWDeviceType FFVideoStream::decode_hw_activate()
+{
+ AVHWDeviceType type = AV_HWDEVICE_TYPE_NONE;
+ const char *hw_dev = getenv("CIN_HW_DEV");
+ if( hw_dev ) {
+ type = av_hwdevice_find_type_by_name(hw_dev);
+ if( type == AV_HWDEVICE_TYPE_NONE ) {
+ fprintf(stderr, "Device type %s is not supported.\n", hw_dev);
+ fprintf(stderr, "Available device types:");
+ while( (type = av_hwdevice_iterate_types(type)) != AV_HWDEVICE_TYPE_NONE )
+ fprintf(stderr, " %s", av_hwdevice_get_type_name(type));
+ fprintf(stderr, "\n");
+ }
+ }
+ return type;
+}
+
+void FFVideoStream::decode_hw_format(AVCodec *decoder, AVHWDeviceType type)
+{
+ hw_pix_fmt = AV_PIX_FMT_NONE;
+ for( int i=0; ; ++i ) {
+ const AVCodecHWConfig *config = avcodec_get_hw_config(decoder, i);
+ if( !config ) {
+ fprintf(stderr, "Decoder %s does not support device type %s.\n",
+ decoder->name, av_hwdevice_get_type_name(type));
+ break;
+ }
+ if( (config->methods & AV_CODEC_HW_CONFIG_METHOD_HW_DEVICE_CTX) != 0 &&
+ config->device_type == type ) {
+ hw_pix_fmt = config->pix_fmt;
+ break;
+ }
+ }
+ if( hw_pix_fmt >= 0 ) {
+ hw_pixfmt = hw_pix_fmt;
+ avctx->get_format = get_hw_format;
+ int ret = av_hwdevice_ctx_create(&hw_device_ctx, type, 0, 0, 0);
+ if( ret >= 0 )
+ avctx->hw_device_ctx = av_buffer_ref(hw_device_ctx);
+ else
+ ff_err(ret, "Failed HW device create.\ndev:%s\n",
+ av_hwdevice_get_type_name(type));
+ }
+}
+