-
Notifications
You must be signed in to change notification settings - Fork 41
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
multiple levels of pointers #82
Comments
This is generally where the plus-c stuff is meant to help out, so instead of a large inverted chain of accessors, you have something like: (c-with ((x some-type)
(y some-type))
(setf (x :ref1 :ref2) 0)
(setf (y :array 3 :ref2) 1)
(some-function (x &))) This works mostly like C, but note the few cases where the "unified" syntax has different semantics. |
Thanks for the response!! Sorry, still a bit confused. Here are some excerpts from a tutorial to ffplay. The code was fixed a bit since I am using a later version of ffmpeg. Here are some Declarations
Now I already have wrapped the Easy code to imitate in Common Lisp (using autowrap)Here is the first part of the code I am trying to imitate within Common Lisp that is very straightforward.
Lisp Imitation of "easy part"
Harder part to ImitateNow for the first part of the problematic part:
The hard part for me is this part: |
Try something like the following; of course I'm making assumptions about constant/field/type naming and similar based on autowrap conventions: ;;; Note this uses :ptr to use the allocation right here; you could
;;; pass around a wrapper and use :from or `c-val`, see the docs
(let ((video-stream-idx -1))
(c-let ((p-format-ctx av-format-context :ptr (avformat-alloc-context)))
(loop for i from 0 below (p-format-ctx :nb-streams)
do (when (eql
(p-format-ctx :streams i :codecpar :codec-type)
+AVMEDIA-TYPE-VIDEO+)
(setf video-stream-idx i)
(return)))
(format t "I found ~A" video-stream-idx)))
;;; As a function, presumably:
(defun find-video-stream-idx (ctx)
(c-val ((ctx av-format-context))
(loop for i from 0 below (ctx :nb-streams)
do (when (eql (ctx :streams i :codecpar :codec-type) +AVMEDIA-TYPE-VIDEO+)
(return i))))) |
Didn't work. Will try to post the error messages next week. |
Having looked at the source code for SBCL and CFFI, it seems the SB-ALIEN package has a richer set of operations on foreign types. For example Since ffmpeg has such complex c-ish manipulations perhaps the best approach for me is:
|
Using In CFFI directly, you're always working with pointers, so you don't need to take the address of anything .. that's all you've got. With |
This is the answer I was looking for: https://stackoverflow.com/questions/35841771/common-lisp-cffi-pointer-to-the-pointer. See the last paragraph
I noticed in an earlier version of cl-autowrap you must of used cffi. See this gist of yours: https://gist.github.com/rpav/5710083. Is the suggestion from the answer (quoted above) doable with sffi? |
Also have you looked at javacpp? it does a very nice job of not only wrapping the c-c++ code, it also writes out the wrapping file with all the documentation from the original include file. Very useful so that one does not have to hunt around for the significance of this or that in other places. |
Now that I am reading more closely your code in parse.lisp (very clever and clean macros!), it seems to me that one could imitate javacpp a bit more (at least in what it does) and also put in options to control the output: i) the same as you do now (basically a macro that gets evaluated and leaves no trace); ii) an output file that is compiled where one sees all the details of the wrapping; iii) also has all the documentation from the original include file. It seems to me that c2ffi probably could (or maybe it does already) also capture any comments from the include file. |
There might also be options to use cffi instead of sffi. |
I have been able to autowrap all (or most all) of the ffmpeg libraries that are used in ffplay. Took a few attempts to get it right but it works!
The next issue is that ffplay uses a number of expressions that look like:
I am sure these can be handled--somehow--however an easy way to do so has not emerged from my experimentation. Is there an easy way to do this?
The text was updated successfully, but these errors were encountered: