lavc/videotoolboxenc: simplify frame creation logic between OS X and iOS.

Signed-off-by: Rick Kern <kernrj@gmail.com>
This commit is contained in:
Rick Kern 2019-05-12 16:04:37 -04:00 committed by Rick Kern
parent 247bda442f
commit 714c8b0766
1 changed files with 0 additions and 62 deletions

View File

@ -2011,19 +2011,6 @@ static int get_cv_pixel_info(
return 0;
}
#if !TARGET_OS_IPHONE
//Not used on iOS - frame is always copied.
static void free_avframe(
void *release_ctx,
const void *data,
size_t size,
size_t plane_count,
const void *plane_addresses[])
{
AVFrame *frame = release_ctx;
av_frame_free(&frame);
}
#else
//Not used on OSX - frame is never copied.
static int copy_avframe_to_pixel_buffer(AVCodecContext *avctx,
const AVFrame *frame,
@ -2116,7 +2103,6 @@ static int copy_avframe_to_pixel_buffer(AVCodecContext *avctx,
return 0;
}
#endif //!TARGET_OS_IPHONE
static int create_cv_pixel_buffer(AVCodecContext *avctx,
const AVFrame *frame,
@ -2129,18 +2115,8 @@ static int create_cv_pixel_buffer(AVCodecContext *avctx,
size_t strides[AV_NUM_DATA_POINTERS];
int status;
size_t contiguous_buf_size;
#if TARGET_OS_IPHONE
CVPixelBufferPoolRef pix_buf_pool;
VTEncContext* vtctx = avctx->priv_data;
#else
CFMutableDictionaryRef pix_buf_attachments = CFDictionaryCreateMutable(
kCFAllocatorDefault,
10,
&kCFCopyStringDictionaryKeyCallBacks,
&kCFTypeDictionaryValueCallBacks);
if (!pix_buf_attachments) return AVERROR(ENOMEM);
#endif
if (avctx->pix_fmt == AV_PIX_FMT_VIDEOTOOLBOX) {
av_assert0(frame->format == AV_PIX_FMT_VIDEOTOOLBOX);
@ -2180,7 +2156,6 @@ static int create_cv_pixel_buffer(AVCodecContext *avctx,
return AVERROR_EXTERNAL;
}
#if TARGET_OS_IPHONE
pix_buf_pool = VTCompressionSessionGetPixelBufferPool(vtctx->session);
if (!pix_buf_pool) {
/* On iOS, the VT session is invalidated when the APP switches from
@ -2222,43 +2197,6 @@ static int create_cv_pixel_buffer(AVCodecContext *avctx,
*cv_img = NULL;
return status;
}
#else
AVFrame *enc_frame = av_frame_alloc();
if (!enc_frame) return AVERROR(ENOMEM);
status = av_frame_ref(enc_frame, frame);
if (status) {
av_frame_free(&enc_frame);
return status;
}
status = CVPixelBufferCreateWithPlanarBytes(
kCFAllocatorDefault,
enc_frame->width,
enc_frame->height,
color,
NULL,
contiguous_buf_size,
plane_count,
(void **)enc_frame->data,
widths,
heights,
strides,
free_avframe,
enc_frame,
NULL,
cv_img
);
add_color_attr(avctx, pix_buf_attachments);
CVBufferSetAttachments(*cv_img, pix_buf_attachments, kCVAttachmentMode_ShouldPropagate);
CFRelease(pix_buf_attachments);
if (status) {
av_log(avctx, AV_LOG_ERROR, "Error: Could not create CVPixelBuffer: %d\n", status);
return AVERROR_EXTERNAL;
}
#endif
return 0;
}