IJKPlayer获取实时数据(下)- 添加硬解码输出纹理

1、进入到IJKVideoToolBoxAsync.m和IJKVideoToolBoxSync.h

1-1、查找函数

void VTDecoderCallback(void *decompressionOutputRefCon,
                       void *sourceFrameRefCon,
                       OSStatus status,
                       VTDecodeInfoFlags infoFlags,
                       CVImageBufferRef imageBuffer,
                       CMTime presentationTimeStamp,
                       CMTime presentationDuration)
{

替换

        OSType format_type = CVPixelBufferGetPixelFormatType(imageBuffer);
        if (format_type != kCVPixelFormatType_420YpCbCr8BiPlanarVideoRange) {
            ALOGI("format_type error \n");
            goto failed;
        }

把kCVPixelFormatType_420YpCbCr8BiPlanarVideoRange替换成kCVPixelFormatType_32BGRA

1-2、查找函数

static VTDecompressionSessionRef vtbsession_create(Ijk_VideoToolBox_Opaque* context)

替换

CFDictionarySetSInt32(destinationPixelBufferAttributes,
                          kCVPixelBufferPixelFormatTypeKey, kCVPixelFormatType_420YpCbCr8BiPlanarVideoRange);

把kCVPixelFormatType_420YpCbCr8BiPlanarVideoRange替换成kCVPixelFormatType_32BGRA

2、进入到ff_ffplay.c

查找函数

static int queue_picture(FFPlayer *ffp, AVFrame *src_frame, double pts, double duration, int64_t pos, int serial)

《IJKPlayer获取实时数据(下)- 添加硬解码输出纹理》 image.png

// 需要添加头文件
#include "ijksdl_vout_overlay_videotoolbox.h"

添加这段代码:  (可以查找SDL_VoutUnlockYUVOverlay(vp->bmp);)
          if (ffp -> videotoolbox) {
            // TODO edit
            ffp_pixelbuffer_lock(ffp);
            ffp->szt_pixelbuffer = SDL_VoutOverlayVideoToolBox_GetCVPixelBufferRef(vp->bmp);  // picture->opaque;
            ffp_pixelbuffer_unlock(ffp);
            
            if (!ffp->szt_pixelbuffer) {
                ALOGE("nil pixelBuffer in overlay\n");
            }
        }
3、屏蔽SDLView获取纹理渲染的接口

进入到ff_ffplay.c, 查找函数

static void video_image_display2(FFPlayer *ffp)

注释掉以下代码

// SDL_VoutDisplayYUVOverlay(ffp->vout, vp->bmp); 

《IJKPlayer获取实时数据(下)- 添加硬解码输出纹理》 image.png

4、添加参数设置

4-1、进入ff_ffplay_def.h
在FFPlayer数据结构中添加

int vtb_frame_width_default;

《IJKPlayer获取实时数据(下)- 添加硬解码输出纹理》 image.png

查找:ffp->vtb_max_frame_width            = 0; 
在这个后面添加
ffp->vtb_frame_width_default        = 0;

《IJKPlayer获取实时数据(下)- 添加硬解码输出纹理》 image.png

4-2、进入ff_ffplay_options.h

查找"videotoolbox-max-frame-width"
在这个后面添加
{ "video-max-frame-width-default",      "max width of output frame default",
        OPTION_OFFSET(vtb_frame_width_default), OPTION_INT(0, 0, INT_MAX) },

《IJKPlayer获取实时数据(下)- 添加硬解码输出纹理》 image.png

4-3、进入IJKOptions.m
在+ (IJKFFOptions *)optionsByDefault{}内添加:

[options setPlayerOptionIntValue:1      forKey:@"video-max-frame-width-default"];

《IJKPlayer获取实时数据(下)- 添加硬解码输出纹理》 image.png

5、进入到IJKVideoToolBoxAsync.m和IJKVideoToolBoxSync.h

查找

static VTDecompressionSessionRef vtbsession_create(Ijk_VideoToolBox_Opaque* context)
将代码
if (ffp->vtb_max_frame_width > 0 && width > ffp->vtb_max_frame_width) {
        double w_scaler = (float)ffp->vtb_max_frame_width / width;
        width = ffp->vtb_max_frame_width;
        height = height * w_scaler;
    }
替换为
if (ffp->vtb_frame_width_default > 0 && ffp->vtb_max_frame_width > 0 && width > ffp->vtb_max_frame_width) {
        double w_scaler = (float)ffp->vtb_max_frame_width / width;
        width = ffp->vtb_max_frame_width;
        height = height * w_scaler;
    }
    原文作者:ARVRSchool
    原文地址: https://www.jianshu.com/p/1802b45ed612
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞