Skip to content

Commit

Permalink
add hw_device_ctx
Browse files Browse the repository at this point in the history
  • Loading branch information
kingslay committed Dec 9, 2023
1 parent f7af060 commit 5c5f45b
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 15 deletions.
30 changes: 16 additions & 14 deletions Sources/KSPlayer/MEPlayer/AVFFmpegExtension.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,20 +28,22 @@ extension UnsafeMutablePointer where Pointee == AVCodecContext {
if deviceCtx == nil {
break
}
var framesCtx = av_hwframe_ctx_alloc(deviceCtx)
if let framesCtx {
let framesCtxData = UnsafeMutableRawPointer(framesCtx.pointee.data)
.bindMemory(to: AVHWFramesContext.self, capacity: 1)
framesCtxData.pointee.format = AV_PIX_FMT_VIDEOTOOLBOX
framesCtxData.pointee.sw_format = ctx.pointee.pix_fmt.bestPixelFormat
framesCtxData.pointee.width = ctx.pointee.width
framesCtxData.pointee.height = ctx.pointee.height
}
if av_hwframe_ctx_init(framesCtx) != 0 {
av_buffer_unref(&framesCtx)
break
}
ctx.pointee.hw_frames_ctx = framesCtx
// 只要有hw_device_ctx就可以了。不需要hw_frames_ctx
ctx.pointee.hw_device_ctx = deviceCtx
// var framesCtx = av_hwframe_ctx_alloc(deviceCtx)
// if let framesCtx {
// let framesCtxData = UnsafeMutableRawPointer(framesCtx.pointee.data)
// .bindMemory(to: AVHWFramesContext.self, capacity: 1)
// framesCtxData.pointee.format = AV_PIX_FMT_VIDEOTOOLBOX
// framesCtxData.pointee.sw_format = ctx.pointee.pix_fmt.bestPixelFormat
// framesCtxData.pointee.width = ctx.pointee.width
// framesCtxData.pointee.height = ctx.pointee.height
// }
// if av_hwframe_ctx_init(framesCtx) != 0 {
// av_buffer_unref(&framesCtx)
// break
// }
// ctx.pointee.hw_frames_ctx = framesCtx
return fmt[i]
}
i += 1
Expand Down
7 changes: 7 additions & 0 deletions Sources/KSPlayer/MEPlayer/Filter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,13 @@ class MEFilter {
guard ret >= 0 else { return false }
ret = avfilter_link(bufferSrcContext, 0, inputs.pointee.filter_ctx, UInt32(inputs.pointee.pad_idx))
guard ret >= 0 else { return false }
if let ctx = params.hw_frames_ctx {
let framesCtxData = UnsafeMutableRawPointer(ctx.pointee.data).bindMemory(to: AVHWFramesContext.self, capacity: 1)
inputs.pointee.filter_ctx.pointee.hw_device_ctx = framesCtxData.pointee.device_ref
// outputs.pointee.filter_ctx.pointee.hw_device_ctx = framesCtxData.pointee.device_ref
// bufferSrcContext?.pointee.hw_device_ctx = framesCtxData.pointee.device_ref
// bufferSinkContext?.pointee.hw_device_ctx = framesCtxData.pointee.device_ref
}
ret = avfilter_graph_config(graph, nil)
guard ret >= 0 else { return false }
return true
Expand Down

0 comments on commit 5c5f45b

Please sign in to comment.