-
Notifications
You must be signed in to change notification settings - Fork 52
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix error of opencamera()
#345
Conversation
Codecov Report
@@ Coverage Diff @@
## master #345 +/- ##
==========================================
+ Coverage 82.00% 82.16% +0.16%
==========================================
Files 10 10
Lines 1239 1245 +6
==========================================
+ Hits 1016 1023 +7
+ Misses 223 222 -1
Continue to review full report at Codecov.
|
Just a little comment: do you need to import |
Very true, importing is not needed. I shall change that. |
Hm. I just read through the Julia docs and found this:
What struck out to me "Neither convert nor cconvert should take a Julia object and turn it into a Ptr." You can see it in julia/essentials.jl, as well as check what I'm not really sure how I'd personally solve this problem. |
Hm, although I went through the docs that you mentioned before I submitted the PR it seems that I hadn't completely understood how cconvert and unsafe_convert should be used. |
Sorry, some more thoughts. (I'm not the C-API guy). The cconvert implementation is probably correct, as doesn't return a Ptr but the Ref of a ptr. An unsafe_convert will probably follow and do the Ptr conversion. Anyone here, who knows more details? Always happy to learn new things ... |
This might be unrelated, but I tested this on a Raspberry Pi and it still errored with: (tmp) pkg> st
Status `~/tmp/Project.toml`
[d6d074c3] VideoIO v0.9.6 `https://github.com/hhaensel/VideoIO.jl#hh-patch-opencamera`
julia> using VideoIO
julia> cam = VideoIO.opencamera()
ERROR: video stream 1 not found
Stacktrace:
[1] error(s::String)
@ Base ./error.jl:33
[2] VideoIO.VideoReader(avin::VideoIO.AVInput{String}, video_stream::Int32; transcode::Bool, target_format::Nothing, pix_fmt_loss_flags::Int32, target_colorspace_details::Nothing, allow_vio_gray_transform::Bool, swscale_options::NamedTuple{(), Tuple{}}, sws_color_options::NamedTuple{(), Tuple{}}, thread_count::Int32)
@ VideoIO ~/.julia/packages/VideoIO/8OFog/src/avio.jl:257
[3] VideoIO.VideoReader(avin::VideoIO.AVInput{String}, video_stream::Int32) (repeats 2 times)
@ VideoIO ~/.julia/packages/VideoIO/8OFog/src/avio.jl:253
[4] #opencamera#26
@ ~/.julia/packages/VideoIO/8OFog/src/avio.jl:1017 [inlined]
[5] opencamera(::String, ::Ptr{VideoIO.libffmpeg.AVInputFormat}, ::VideoIO.AVDict) (repeats 2 times)
@ VideoIO ~/.julia/packages/VideoIO/8OFog/src/avio.jl:1016
[6] top-level scope
@ REPL[6]:1
See issue #346 |
IIRC, the rules for |
Ok, thanks. I tried defining
From the
https://docs.julialang.org/en/v1/base/c/#Core.Ref So it's not clear to me what the fix is |
To clarify a bit, you could use the following mental model when working with
In the case of
But if
|
As explained above,
|
src/avdictionary.jl
Outdated
@@ -29,6 +29,7 @@ end | |||
Base.empty!(d::AVDict) = libffmpeg.av_dict_free(d.ref_ptr_dict) | |||
|
|||
Base.convert(::Type{Ref{Ptr{AVDictionary}}}, d::AVDict) = d.ref_ptr_dict |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If this method is not used anywhere, it's better to remove it to avoid further confusion.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point. Without it tests pass, and VideoIO.opencamera()
works locally.
This comment was marked as resolved.
This comment was marked as resolved.
Thanks all. Sorry for the delay |
I doubt whether it is the case here. If we define |
It's wrong to let As mentioned in #345 (comment), the simple mental model is that the Julia object returned by
Returning a
The finalizer will not be triggered because |
I assume this is because you want to preserve the dict object through a reference to its field, since it is totally valid for
What counts as a reference to an object is beyond my knowledge, can you recommend some materials on this? |
In the example below, the field
|
This PR addresses #341.
I compared both solutions proposed in the chat and found that
cconvert()
is preferred overunsafe_convert()
as I assumed, so I implemented the solution forcconvert()
.I was not completely sure whether
convert()
is needed somewhere in the code - although I couldn't find any evidence in the code - so I kept it.EDIT: added "not" in the phrase above...