Skip to content

Commit

Permalink
Replace sigatomic_(begin|end) with disable_sigint() do ... end (#372)
Browse files Browse the repository at this point in the history
Co-authored-by: Ian Butterworth <[email protected]>
  • Loading branch information
mrufsvold and IanButterworth authored Jul 20, 2022
1 parent 7c8cc7f commit e4f619a
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 35 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
matrix:
os: [ubuntu-latest, windows-latest, macOS-latest]
julia-arch: [x64, x86]
julia-version: ['1.6','1','nightly']
julia-version: ['1.6','1','1.8-nightly','nightly']
exclude:
- os: macOS-latest
julia-arch: x86
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ test/precisiontest_gray_test.mp4
test/ordertest_gray_test.mp4
docs/build/
test/temp.stream
.vscode/
2 changes: 1 addition & 1 deletion src/VideoIO.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ using ImageCore: channelview, rawview
using ColorTypes: RGB, Gray, N0f8, N6f10, YCbCr, Normed, red, green, blue
using FileIO: File

using Base: fieldindex, RefValue, sigatomic_begin, sigatomic_end, cconvert
using Base: fieldindex, RefValue, cconvert
using Base.GC: @preserve
import Base:
iterate,
Expand Down
35 changes: 18 additions & 17 deletions src/avio.jl
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,10 @@ convert(::Type{AVRational}, r::Rational) = AVRational(numerator(r), denominator(
# Pump input for data
function pump(avin::AVInput)
while avin.isopen && !avin.finished
sigatomic_begin()
ret = av_read_frame(avin.format_context, avin.packet)
sigatomic_end()
ret = disable_sigint() do
av_read_frame(avin.format_context, avin.packet)
end

if ret < 0
avin.finished = true
break
Expand Down Expand Up @@ -296,11 +297,11 @@ function VideoReader(
codec_context.pix_fmt < 0 && error("Unknown pixel format")

# Open the decoder
sigatomic_begin()
lock(VIO_LOCK)
ret = avcodec_open2(codec_context, codec, C_NULL)
unlock(VIO_LOCK)
sigatomic_end()
ret = disable_sigint() do
lock(VIO_LOCK) do
avcodec_open2(codec_context, codec, C_NULL)
end
end
ret < 0 && error("Could not open codec")

if target_format === nothing # automatically determine format
Expand Down Expand Up @@ -960,20 +961,20 @@ function close(avin::AVInput)
if check_ptr_valid(avin.format_context, false)
# Replace the existing object in avin with a null pointer. The finalizer
# for AVFormatContextPtr will close it and clean up its memory
sigatomic_begin()
avformat_close_input(avin.format_context) # This is also done in the finalizer,
# but closing the input here means users won't have to wait for the GC to run
# before trying to remove the file
avin.format_context = AVFormatContextPtr(Ptr{AVFormatContext}(C_NULL))
sigatomic_end()
disable_sigint() do
avformat_close_input(avin.format_context) # This is also done in the finalizer,
# but closing the input here means users won't have to wait for the GC to run
# before trying to remove the file
avin.format_context = AVFormatContextPtr(Ptr{AVFormatContext}(C_NULL))
end
end

if check_ptr_valid(avin.avio_context, false)
# Replace the existing object in avin with a null pointer. The finalizer
# will close it and clean up its memory
sigatomic_begin()
avin.avio_context = AVIOContextPtr(Ptr{AVIOContext}(C_NULL))
sigatomic_end()
disable_sigint() do
avin.avio_context = AVIOContextPtr(Ptr{AVIOContext}(C_NULL))
end
end
return nothing
end
Expand Down
10 changes: 5 additions & 5 deletions src/encoding.jl
Original file line number Diff line number Diff line change
Expand Up @@ -324,11 +324,11 @@ options, or pass the private options to `encoder_private_options` explicitly""",
set_class_options(codec_context, encoder_options)
set_class_options(codec_context.priv_data, encoder_private_options)

sigatomic_begin()
lock(VIO_LOCK)
ret = avcodec_open2(codec_context, codec, C_NULL)
unlock(VIO_LOCK)
sigatomic_end()
ret = disable_sigint() do
lock(VIO_LOCK) do
avcodec_open2(codec_context, codec, C_NULL)
end
end
ret < 0 && error("Could not open codec: Return code $(ret)")

stream_p = avformat_new_stream(format_context, C_NULL)
Expand Down
22 changes: 11 additions & 11 deletions src/frame_graph.jl
Original file line number Diff line number Diff line change
Expand Up @@ -134,17 +134,17 @@ function exec!(s::SwsTransform)
dst_data_ptr = field_ptr(dst_ptr, :data)
dst_linesize_ptr = field_ptr(dst_ptr, :linesize)

sigatomic_begin()
ret = sws_scale(
s.sws_context,
src_data_ptr,
src_linesize_ptr,
0,
s.dstframe.height,
dst_data_ptr,
dst_linesize_ptr,
)
sigatomic_end()
ret = disable_sigint() do
sws_scale(
s.sws_context,
src_data_ptr,
src_linesize_ptr,
0,
s.dstframe.height,
dst_data_ptr,
dst_linesize_ptr,
)
end
ret <= 0 && error("Could not scale frame")
end
return nothing
Expand Down

0 comments on commit e4f619a

Please sign in to comment.