This removes all remaining device-type specificity.
| ... | ... |
@@ -44,34 +44,6 @@ static AVBufferRef *hw_device_ctx = NULL; |
| 44 | 44 |
static enum AVPixelFormat hw_pix_fmt; |
| 45 | 45 |
static FILE *output_file = NULL; |
| 46 | 46 |
|
| 47 |
-static enum AVPixelFormat find_fmt_by_hw_type(const enum AVHWDeviceType type) |
|
| 48 |
-{
|
|
| 49 |
- enum AVPixelFormat fmt; |
|
| 50 |
- |
|
| 51 |
- switch (type) {
|
|
| 52 |
- case AV_HWDEVICE_TYPE_VAAPI: |
|
| 53 |
- fmt = AV_PIX_FMT_VAAPI; |
|
| 54 |
- break; |
|
| 55 |
- case AV_HWDEVICE_TYPE_DXVA2: |
|
| 56 |
- fmt = AV_PIX_FMT_DXVA2_VLD; |
|
| 57 |
- break; |
|
| 58 |
- case AV_HWDEVICE_TYPE_D3D11VA: |
|
| 59 |
- fmt = AV_PIX_FMT_D3D11; |
|
| 60 |
- break; |
|
| 61 |
- case AV_HWDEVICE_TYPE_VDPAU: |
|
| 62 |
- fmt = AV_PIX_FMT_VDPAU; |
|
| 63 |
- break; |
|
| 64 |
- case AV_HWDEVICE_TYPE_VIDEOTOOLBOX: |
|
| 65 |
- fmt = AV_PIX_FMT_VIDEOTOOLBOX; |
|
| 66 |
- break; |
|
| 67 |
- default: |
|
| 68 |
- fmt = AV_PIX_FMT_NONE; |
|
| 69 |
- break; |
|
| 70 |
- } |
|
| 71 |
- |
|
| 72 |
- return fmt; |
|
| 73 |
-} |
|
| 74 |
- |
|
| 75 | 47 |
static int hw_decoder_init(AVCodecContext *ctx, const enum AVHWDeviceType type) |
| 76 | 48 |
{
|
| 77 | 49 |
int err = 0; |
| ... | ... |
@@ -184,18 +156,22 @@ int main(int argc, char *argv[]) |
| 184 | 184 |
AVCodec *decoder = NULL; |
| 185 | 185 |
AVPacket packet; |
| 186 | 186 |
enum AVHWDeviceType type; |
| 187 |
+ int i; |
|
| 187 | 188 |
|
| 188 | 189 |
if (argc < 4) {
|
| 189 |
- fprintf(stderr, "Usage: %s <vaapi|vdpau|dxva2|d3d11va> <input file> <output file>\n", argv[0]); |
|
| 190 |
+ fprintf(stderr, "Usage: %s <device type> <input file> <output file>\n", argv[0]); |
|
| 190 | 191 |
return -1; |
| 191 | 192 |
} |
| 192 | 193 |
|
| 193 | 194 |
av_register_all(); |
| 194 | 195 |
|
| 195 | 196 |
type = av_hwdevice_find_type_by_name(argv[1]); |
| 196 |
- hw_pix_fmt = find_fmt_by_hw_type(type); |
|
| 197 |
- if (hw_pix_fmt == -1) {
|
|
| 198 |
- fprintf(stderr, "Cannot support '%s' in this example.\n", argv[1]); |
|
| 197 |
+ if (type == AV_HWDEVICE_TYPE_NONE) {
|
|
| 198 |
+ fprintf(stderr, "Device type %s is not supported.\n", argv[1]); |
|
| 199 |
+ fprintf(stderr, "Available device types:"); |
|
| 200 |
+ while((type = av_hwdevice_iterate_types(type)) != AV_HWDEVICE_TYPE_NONE) |
|
| 201 |
+ fprintf(stderr, " %s", av_hwdevice_get_type_name(type)); |
|
| 202 |
+ fprintf(stderr, "\n"); |
|
| 199 | 203 |
return -1; |
| 200 | 204 |
} |
| 201 | 205 |
|
| ... | ... |
@@ -218,6 +194,20 @@ int main(int argc, char *argv[]) |
| 218 | 218 |
} |
| 219 | 219 |
video_stream = ret; |
| 220 | 220 |
|
| 221 |
+ for (i = 0;; i++) {
|
|
| 222 |
+ const AVCodecHWConfig *config = avcodec_get_hw_config(decoder, i); |
|
| 223 |
+ if (!config) {
|
|
| 224 |
+ fprintf(stderr, "Decoder %s does not support device type %s.\n", |
|
| 225 |
+ decoder->name, av_hwdevice_get_type_name(type)); |
|
| 226 |
+ return -1; |
|
| 227 |
+ } |
|
| 228 |
+ if (config->methods & AV_CODEC_HW_CONFIG_METHOD_HW_DEVICE_CTX && |
|
| 229 |
+ config->device_type == type) {
|
|
| 230 |
+ hw_pix_fmt = config->pix_fmt; |
|
| 231 |
+ break; |
|
| 232 |
+ } |
|
| 233 |
+ } |
|
| 234 |
+ |
|
| 221 | 235 |
if (!(decoder_ctx = avcodec_alloc_context3(decoder))) |
| 222 | 236 |
return AVERROR(ENOMEM); |
| 223 | 237 |
|