This was almost completely redundant. The only functionality that's no longer available after this removal is the videotoolbox_pixfmt arg, which has been obsolete for several years.
Unified · Split
| @@ -10,10 +10,6 @@ ALLAVPROGS = $(AVBASENAMES:%=%$(PROGSSUF)$(EXESUF)) · 9 unmodified lines | |||
| 10 | ALLAVPROGS_G = $(AVBASENAMES:%=%$(PROGSSUF)_g$(EXESUF)) | 10 | ALLAVPROGS_G = $(AVBASENAMES:%=%$(PROGSSUF)_g$(EXESUF)) |
| 11 | 11 | ||
| 12 | OBJS-ffmpeg += fftools/ffmpeg_opt.o fftools/ffmpeg_filter.o fftools/ffmpeg_hw.o | 12 | OBJS-ffmpeg += fftools/ffmpeg_opt.o fftools/ffmpeg_filter.o fftools/ffmpeg_hw.o |
| 13 | ifndef CONFIG_VIDEOTOOLBOX | ||
| 14 | OBJS-ffmpeg-$(CONFIG_VDA) += fftools/ffmpeg_videotoolbox.o | ||
| 15 | endif | ||
| 16 | OBJS-ffmpeg-$(CONFIG_VIDEOTOOLBOX) += fftools/ffmpeg_videotoolbox.o | ||
| 17 | 13 | ||
| 18 | define DOFFTOOL | 14 | define DOFFTOOL |
| 19 | OBJS-$(1) += fftools/cmdutils.o fftools/$(1).o $(OBJS-$(1)-yes) | 15 | OBJS-$(1) += fftools/cmdutils.o fftools/$(1).o $(OBJS-$(1)-yes) |
| @@ -2858,12 +2858,7 @@ static enum AVPixelFormat get_format(AVCodecContext *s, const enum AVPixelFormat · 2857 unmodified lines | |||
| 2858 | break; | 2858 | break; |
| 2859 | } | 2859 | } |
| 2860 | } | 2860 | } |
| 2861 | if (config) { | 2861 | if (config && config->device_type == ist->hwaccel_device_type) { |
| 2862 | if (config->device_type != ist->hwaccel_device_type) { | ||
| 2863 | // Different hwaccel offered, ignore. | ||
| 2864 | continue; | ||
| 2865 | } | ||
| 2866 | |||
| 2867 | ret = hwaccel_decode_init(s); | 2862 | ret = hwaccel_decode_init(s); |
| 2868 | if (ret < 0) { | 2863 | if (ret < 0) { |
| 2869 | if (ist->hwaccel_id == HWACCEL_GENERIC) { | 2864 | if (ist->hwaccel_id == HWACCEL_GENERIC) { |
| @@ -2876,36 +2871,10 @@ static enum AVPixelFormat get_format(AVCodecContext *s, const enum AVPixelFormat · 6 unmodified lines | |||
| 2876 | } | 2871 | } |
| 2877 | continue; | 2872 | continue; |
| 2878 | } | 2873 | } |
| 2879 | } else { | ||
| 2880 | const HWAccel *hwaccel = NULL; | ||
| 2881 | int i; | ||
| 2882 | for (i = 0; hwaccels[i].name; i++) { | ||
| 2883 | if (hwaccels[i].pix_fmt == *p) { | ||
| 2884 | hwaccel = &hwaccels[i]; | ||
| 2885 | break; | ||
| 2886 | } | ||
| 2887 | } | ||
| 2888 | if (!hwaccel) { | ||
| 2889 | // No hwaccel supporting this pixfmt. | ||
| 2890 | continue; | ||
| 2891 | } | ||
| 2892 | if (hwaccel->id != ist->hwaccel_id) { | ||
| 2893 | // Does not match requested hwaccel. | ||
| 2894 | continue; | ||
| 2895 | } | ||
| 2896 | 2874 | ||
| 2897 | ret = hwaccel->init(s); | 2875 | ist->hwaccel_pix_fmt = *p; |
| 2898 | if (ret < 0) { | 2876 | break; |
| 2899 | av_log(NULL, AV_LOG_FATAL, | ||
| 2900 | "%s hwaccel requested for input stream #%d:%d, " | ||
| 2901 | "but cannot be initialized.\n", hwaccel->name, | ||
| 2902 | ist->file_index, ist->st->index); | ||
| 2903 | return AV_PIX_FMT_NONE; | ||
| 2904 | } | ||
| 2905 | } | 2877 | } |
| 2906 | |||
| 2907 | ist->hwaccel_pix_fmt = *p; | ||
| 2908 | break; | ||
| 2909 | } | 2878 | } |
| 2910 | 2879 | ||
| 2911 | return *p; | 2880 | return *p; |
| @@ -60,16 +60,8 @@ enum HWAccelID { · 59 unmodified lines | |||
| 60 | HWACCEL_NONE = 0, | 60 | HWACCEL_NONE = 0, |
| 61 | HWACCEL_AUTO, | 61 | HWACCEL_AUTO, |
| 62 | HWACCEL_GENERIC, | 62 | HWACCEL_GENERIC, |
| 63 | HWACCEL_VIDEOTOOLBOX, | ||
| 64 | }; | 63 | }; |
| 65 | 64 | ||
| 66 | typedef struct HWAccel { | ||
| 67 | const char *name; | ||
| 68 | int (*init)(AVCodecContext *s); | ||
| 69 | enum HWAccelID id; | ||
| 70 | enum AVPixelFormat pix_fmt; | ||
| 71 | } HWAccel; | ||
| 72 | |||
| 73 | typedef struct HWDevice { | 65 | typedef struct HWDevice { |
| 74 | const char *name; | 66 | const char *name; |
| 75 | enum AVHWDeviceType type; | 67 | enum AVHWDeviceType type; |
| @@ -626,7 +618,6 @@ extern int stdin_interaction; · 550 unmodified lines | |||
| 626 | extern int frame_bits_per_raw_sample; | 618 | extern int frame_bits_per_raw_sample; |
| 627 | extern AVIOContext *progress_avio; | 619 | extern AVIOContext *progress_avio; |
| 628 | extern float max_error_rate; | 620 | extern float max_error_rate; |
| 629 | extern char *videotoolbox_pixfmt; | ||
| 630 | 621 | ||
| 631 | extern char *filter_nbthreads; | 622 | extern char *filter_nbthreads; |
| 632 | extern int filter_complex_nbthreads; | 623 | extern int filter_complex_nbthreads; |
| @@ -636,7 +627,6 @@ extern int auto_conversion_filters; · 3 unmodified lines | |||
| 636 | extern const AVIOInterruptCB int_cb; | 627 | extern const AVIOInterruptCB int_cb; |
| 637 | 628 | ||
| 638 | extern const OptionDef options[]; | 629 | extern const OptionDef options[]; |
| 639 | extern const HWAccel hwaccels[]; | ||
| 640 | #if CONFIG_QSV | 630 | #if CONFIG_QSV |
| 641 | extern char *qsv_device; | 631 | extern char *qsv_device; |
| 642 | #endif | 632 | #endif |
| @@ -134,12 +134,6 @@ static const char *const opt_name_enc_time_bases[] = {"enc_time_base" · 133 unmodified lines | |||
| 134 | }\ | 134 | }\ |
| 135 | } | 135 | } |
| 136 | 136 | ||
| 137 | const HWAccel hwaccels[] = { | ||
| 138 | #if CONFIG_VIDEOTOOLBOX | ||
| 139 | { "videotoolbox", videotoolbox_init, HWACCEL_VIDEOTOOLBOX, AV_PIX_FMT_VIDEOTOOLBOX }, | ||
| 140 | #endif | ||
| 141 | { 0 }, | ||
| 142 | }; | ||
| 143 | HWDevice *filter_hw_device; | 137 | HWDevice *filter_hw_device; |
| 144 | 138 | ||
| 145 | char *vstats_filename; | 139 | char *vstats_filename; |
| @@ -931,21 +925,10 @@ static void add_input_streams(OptionsContext *o, AVFormatContext *ic) · 785 unmodified lines | |||
| 931 | else if (!strcmp(hwaccel, "auto")) | 925 | else if (!strcmp(hwaccel, "auto")) |
| 932 | ist->hwaccel_id = HWACCEL_AUTO; | 926 | ist->hwaccel_id = HWACCEL_AUTO; |
| 933 | else { | 927 | else { |
| 934 | enum AVHWDeviceType type; | 928 | enum AVHWDeviceType type = av_hwdevice_find_type_by_name(hwaccel); |
| 935 | int i; | 929 | if (type != AV_HWDEVICE_TYPE_NONE) { |
| 936 | for (i = 0; hwaccels[i].name; i++) { | 930 | ist->hwaccel_id = HWACCEL_GENERIC; |
| 937 | if (!strcmp(hwaccels[i].name, hwaccel)) { | 931 | ist->hwaccel_device_type = type; |
| 938 | ist->hwaccel_id = hwaccels[i].id; | ||
| 939 | break; | ||
| 940 | } | ||
| 941 | } | ||
| 942 | |||
| 943 | if (!ist->hwaccel_id) { | ||
| 944 | type = av_hwdevice_find_type_by_name(hwaccel); | ||
| 945 | if (type != AV_HWDEVICE_TYPE_NONE) { | ||
| 946 | ist->hwaccel_id = HWACCEL_GENERIC; | ||
| 947 | ist->hwaccel_device_type = type; | ||
| 948 | } | ||
| 949 | } | 932 | } |
| 950 | 933 | ||
| 951 | if (!ist->hwaccel_id) { | 934 | if (!ist->hwaccel_id) { |
| @@ -3811,9 +3794,6 @@ const OptionDef options[] = { · 2859 unmodified lines | |||
| 3811 | { "hwaccel_output_format", OPT_VIDEO | OPT_STRING | HAS_ARG | OPT_EXPERT | | 3794 | { "hwaccel_output_format", OPT_VIDEO | OPT_STRING | HAS_ARG | OPT_EXPERT | |
| 3812 | OPT_SPEC | OPT_INPUT, { .off = OFFSET(hwaccel_output_formats) }, | 3795 | OPT_SPEC | OPT_INPUT, { .off = OFFSET(hwaccel_output_formats) }, |
| 3813 | "select output format used with HW accelerated decoding", "format" }, | 3796 | "select output format used with HW accelerated decoding", "format" }, |
| 3814 | #if CONFIG_VIDEOTOOLBOX | ||
| 3815 | { "videotoolbox_pixfmt", HAS_ARG | OPT_STRING | OPT_EXPERT, { &videotoolbox_pixfmt}, "" }, | ||
| 3816 | #endif | ||
| 3817 | { "hwaccels", OPT_EXIT, { .func_arg = show_hwaccels }, | 3797 | { "hwaccels", OPT_EXIT, { .func_arg = show_hwaccels }, |
| 3818 | "show available HW acceleration methods" }, | 3798 | "show available HW acceleration methods" }, |
| 3819 | { "autorotate", HAS_ARG | OPT_BOOL | OPT_SPEC | | 3799 | { "autorotate", HAS_ARG | OPT_BOOL | OPT_SPEC | |
| @@ -1,177 +0,0 @@ | |||
| 1 | /* | ||
| 2 | * This file is part of FFmpeg. | ||
| 3 | * | ||
| 4 | * FFmpeg is free software; you can redistribute it and/or | ||
| 5 | * modify it under the terms of the GNU Lesser General Public | ||
| 6 | * License as published by the Free Software Foundation; either | ||
| 7 | * version 2.1 of the License, or (at your option) any later version. | ||
| 8 | * | ||
| 9 | * FFmpeg is distributed in the hope that it will be useful, | ||
| 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
| 12 | * Lesser General Public License for more details. | ||
| 13 | * | ||
| 14 | * You should have received a copy of the GNU Lesser General Public | ||
| 15 | * License along with FFmpeg; if not, write to the Free Software | ||
| 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | ||
| 17 | */ | ||
| 18 | |||
| 19 | #include "config.h" | ||
| 20 | |||
| 21 | #if HAVE_UTGETOSTYPEFROMSTRING | ||
| 22 | #include <CoreServices/CoreServices.h> | ||
| 23 | #endif | ||
| 24 | |||
| 25 | #include "libavcodec/avcodec.h" | ||
| 26 | #include "libavcodec/videotoolbox.h" | ||
| 27 | #include "libavutil/imgutils.h" | ||
| 28 | #include "ffmpeg.h" | ||
| 29 | |||
| 30 | typedef struct VTContext { | ||
| 31 | AVFrame *tmp_frame; | ||
| 32 | int log_once; | ||
| 33 | } VTContext; | ||
| 34 | |||
| 35 | char *videotoolbox_pixfmt; | ||
| 36 | |||
| 37 | static int videotoolbox_retrieve_data(AVCodecContext *s, AVFrame *frame) | ||
| 38 | { | ||
| 39 | InputStream *ist = s->opaque; | ||
| 40 | VTContext *vt = ist->hwaccel_ctx; | ||
| 41 | CVPixelBufferRef pixbuf = (CVPixelBufferRef)frame->data[3]; | ||
| 42 | OSType pixel_format = CVPixelBufferGetPixelFormatType(pixbuf); | ||
| 43 | CVReturn err; | ||
| 44 | uint8_t *data[4] = { 0 }; | ||
| 45 | int linesize[4] = { 0 }; | ||
| 46 | int planes, ret, i; | ||
| 47 | |||
| 48 | if (frame->format == ist->hwaccel_output_format) { | ||
| 49 | av_log_once(s, AV_LOG_INFO, AV_LOG_TRACE, &vt->log_once, | ||
| 50 | "There is no video filter for videotoolbox pix_fmt now, remove the " | ||
| 51 | "-hwaccel_output_format option if video filter doesn't work\n"); | ||
| 52 | return 0; | ||
| 53 | } | ||
| 54 | |||
| 55 | av_frame_unref(vt->tmp_frame); | ||
| 56 | |||
| 57 | switch (pixel_format) { | ||
| 58 | case kCVPixelFormatType_420YpCbCr8Planar: vt->tmp_frame->format = AV_PIX_FMT_YUV420P; break; | ||
| 59 | case kCVPixelFormatType_422YpCbCr8: vt->tmp_frame->format = AV_PIX_FMT_UYVY422; break; | ||
| 60 | case kCVPixelFormatType_32BGRA: vt->tmp_frame->format = AV_PIX_FMT_BGRA; break; | ||
| 61 | #ifdef kCFCoreFoundationVersionNumber10_7 | ||
| 62 | case kCVPixelFormatType_420YpCbCr8BiPlanarVideoRange: | ||
| 63 | case kCVPixelFormatType_420YpCbCr8BiPlanarFullRange: vt->tmp_frame->format = AV_PIX_FMT_NV12; break; | ||
| 64 | #endif | ||
| 65 | #if HAVE_KCVPIXELFORMATTYPE_420YPCBCR10BIPLANARVIDEORANGE | ||
| 66 | case kCVPixelFormatType_420YpCbCr10BiPlanarVideoRange: | ||
| 67 | case kCVPixelFormatType_420YpCbCr10BiPlanarFullRange: vt->tmp_frame->format = AV_PIX_FMT_P010; break; | ||
| 68 | #endif | ||
| 69 | default: | ||
| 70 | av_log(NULL, AV_LOG_ERROR, | ||
| 71 | "%s: Unsupported pixel format: %s\n", | ||
| 72 | av_fourcc2str(s->codec_tag), videotoolbox_pixfmt); | ||
| 73 | return AVERROR(ENOSYS); | ||
| 74 | } | ||
| 75 | |||
| 76 | vt->tmp_frame->width = frame->width; | ||
| 77 | vt->tmp_frame->height = frame->height; | ||
| 78 | ret = av_frame_get_buffer(vt->tmp_frame, 0); | ||
| 79 | if (ret < 0) | ||
| 80 | return ret; | ||
| 81 | |||
| 82 | err = CVPixelBufferLockBaseAddress(pixbuf, kCVPixelBufferLock_ReadOnly); | ||
| 83 | if (err != kCVReturnSuccess) { | ||
| 84 | av_log(NULL, AV_LOG_ERROR, "Error locking the pixel buffer.\n"); | ||
| 85 | return AVERROR_UNKNOWN; | ||
| 86 | } | ||
| 87 | |||
| 88 | if (CVPixelBufferIsPlanar(pixbuf)) { | ||
| 89 | |||
| 90 | planes = CVPixelBufferGetPlaneCount(pixbuf); | ||
| 91 | for (i = 0; i < planes; i++) { | ||
| 92 | data[i] = CVPixelBufferGetBaseAddressOfPlane(pixbuf, i); | ||
| 93 | linesize[i] = CVPixelBufferGetBytesPerRowOfPlane(pixbuf, i); | ||
| 94 | } | ||
| 95 | } else { | ||
| 96 | data[0] = CVPixelBufferGetBaseAddress(pixbuf); | ||
| 97 | linesize[0] = CVPixelBufferGetBytesPerRow(pixbuf); | ||
| 98 | } | ||
| 99 | |||
| 100 | av_image_copy(vt->tmp_frame->data, vt->tmp_frame->linesize, | ||
| 101 | (const uint8_t **)data, linesize, vt->tmp_frame->format, | ||
| 102 | frame->width, frame->height); | ||
| 103 | |||
| 104 | ret = av_frame_copy_props(vt->tmp_frame, frame); | ||
| 105 | CVPixelBufferUnlockBaseAddress(pixbuf, kCVPixelBufferLock_ReadOnly); | ||
| 106 | if (ret < 0) | ||
| 107 | return ret; | ||
| 108 | |||
| 109 | av_frame_unref(frame); | ||
| 110 | av_frame_move_ref(frame, vt->tmp_frame); | ||
| 111 | |||
| 112 | return 0; | ||
| 113 | } | ||
| 114 | |||
| 115 | static void videotoolbox_uninit(AVCodecContext *s) | ||
| 116 | { | ||
| 117 | InputStream *ist = s->opaque; | ||
| 118 | VTContext *vt = ist->hwaccel_ctx; | ||
| 119 | |||
| 120 | ist->hwaccel_uninit = NULL; | ||
| 121 | ist->hwaccel_retrieve_data = NULL; | ||
| 122 | |||
| 123 | av_frame_free(&vt->tmp_frame); | ||
| 124 | |||
| 125 | av_videotoolbox_default_free(s); | ||
| 126 | av_freep(&ist->hwaccel_ctx); | ||
| 127 | } | ||
| 128 | |||
| 129 | int videotoolbox_init(AVCodecContext *s) | ||
| 130 | { | ||
| 131 | InputStream *ist = s->opaque; | ||
| 132 | int loglevel = (ist->hwaccel_id == HWACCEL_AUTO) ? AV_LOG_VERBOSE : AV_LOG_ERROR; | ||
| 133 | int ret = 0; | ||
| 134 | VTContext *vt; | ||
| 135 | |||
| 136 | vt = av_mallocz(sizeof(*vt)); | ||
| 137 | if (!vt) | ||
| 138 | return AVERROR(ENOMEM); | ||
| 139 | |||
| 140 | ist->hwaccel_ctx = vt; | ||
| 141 | ist->hwaccel_uninit = videotoolbox_uninit; | ||
| 142 | ist->hwaccel_retrieve_data = videotoolbox_retrieve_data; | ||
| 143 | |||
| 144 | vt->tmp_frame = av_frame_alloc(); | ||
| 145 | if (!vt->tmp_frame) { | ||
| 146 | ret = AVERROR(ENOMEM); | ||
| 147 | goto fail; | ||
| 148 | } | ||
| 149 | |||
| 150 | // TODO: reindent | ||
| 151 | if (!videotoolbox_pixfmt) { | ||
| 152 | ret = av_videotoolbox_default_init(s); | ||
| 153 | } else { | ||
| 154 | AVVideotoolboxContext *vtctx = av_videotoolbox_alloc_context(); | ||
| 155 | CFStringRef pixfmt_str = CFStringCreateWithCString(kCFAllocatorDefault, | ||
| 156 | videotoolbox_pixfmt, | ||
| 157 | kCFStringEncodingUTF8); | ||
| 158 | #if HAVE_UTGETOSTYPEFROMSTRING | ||
| 159 | vtctx->cv_pix_fmt_type = UTGetOSTypeFromString(pixfmt_str); | ||
| 160 | #else | ||
| 161 | av_log(s, loglevel, "UTGetOSTypeFromString() is not available " | ||
| 162 | "on this platform, %s pixel format can not be honored from " | ||
| 163 | "the command line\n", videotoolbox_pixfmt); | ||
| 164 | #endif | ||
| 165 | ret = av_videotoolbox_default_init2(s, vtctx); | ||
| 166 | CFRelease(pixfmt_str); | ||
| 167 | } | ||
| 168 | if (ret < 0) { | ||
| 169 | av_log(NULL, loglevel, "Error creating Videotoolbox decoder.\n"); | ||
| 170 | goto fail; | ||
| 171 | } | ||
| 172 | |||
| 173 | return 0; | ||
| 174 | fail: | ||
| 175 | videotoolbox_uninit(s); | ||
| 176 | return ret; | ||
| 177 | } | ||