Ticket #11319 (closed defect: fixed)

Opened 3 years ago

Last modified 3 years ago

Scratch looks for wrong libv4l2.so file

Reported by: godiard Owned by: dsd
Priority: normal Milestone: 11.3.0
Component: build-system Version: not specified
Keywords: Cc: dmoco
Action Needed: test in build Verified: no
Deployments affected: Blocked By:
Blocking:

Description

To use the camera, the Scratch activity need the package libv4l-devel. The package weight 14 KB.

The plugin was compiled with the simple Makefile provided in the sources:

 http://www.assembla.com/code/scratchonlinux/subversion/nodes/trunk/scratch/src/plugins/camera/Makefile

Attachments

Change-libv4l-shared-library-detection.patch Download (0.8 KB) - added by dmoco 3 years ago.
Diff to remove link dependency and correct lib name for libv4l2

Change History

Changed 3 years ago by dsd

  • next_action changed from add to build to diagnose

I think there is something wrong with your compile setup. Maybe you didn't have the devel package installed on your compile box? Works for me:

[dsd@polyethylene camera]$ make
rm -f *.o ../../../Plugins/so.CameraPlugin
gcc  -fPIC -c *.c
sqCamera-linux.c: In function ‘libCon’:
sqCamera-linux.c:184:10: warning: assignment from incompatible pointer type [enabled by default]
gcc -shared -lv4l2 *.o -o ../../../Plugins/so.CameraPlugin
[dsd@polyethylene camera]$ ldd ../../../Plugins/so.CameraPlugin
	linux-gate.so.1 =>  (0x009b0000)
	libv4l2.so.0 => /usr/lib/libv4l2.so.0 (0x002b9000)
	libc.so.6 => /lib/libc.so.6 (0x00110000)
	libv4lconvert.so.0 => /usr/lib/libv4lconvert.so.0 (0x002c4000)
	libpthread.so.0 => /lib/libpthread.so.0 (0x0029c000)
	/lib/ld-linux.so.2 (0x005ab000)
	librt.so.1 => /lib/librt.so.1 (0x0033c000)
	libm.so.6 => /lib/libm.so.6 (0x00d63000)
	libjpeg.so.62 => /usr/lib/libjpeg.so.62 (0x00764000)
[dsd@polyethylene camera]$ rpm -q -f /usr/lib/libv4l2.so.0
libv4l-0.8.5-1.fc15.i686

i.e. the plugin linked against libv4l2.so.0 which is found in the libv4l package, not libv4l-devel

Changed 3 years ago by godiard

I don't understand why, but the ldd output looks different:

[olpc@xo-d7-1b-bb arm]$ ldd CameraPlugin 
	libv4l2.so.0 => /usr/lib/libv4l2.so.0 (0x401cf000)
	libc.so.6 => /lib/libc.so.6 (0x401e1000)
	libgcc_s.so.1 => /lib/libgcc_s.so.1 (0x400dc000)
	libv4lconvert.so.0 => /usr/lib/libv4lconvert.so.0 (0x40322000)
	libpthread.so.0 => /lib/libpthread.so.0 (0x40061000)
	/lib/ld-linux.so.3 (0x400b7000)
	librt.so.1 => /lib/librt.so.1 (0x40104000)
	libm.so.6 => /lib/libm.so.6 (0x40398000)

The libv4l2 line looks similar, but in my case, I don't have a line for linux-gate and libjpeg. Any idea?

Changed 3 years ago by godiard

I think i have found a problem:

The code in the plugin is looking at the file libv4l2.so:

 http://trac.assembla.com/scratchonlinux/browser/trunk/scratch/src/plugins/camera/sqCamera-linux.c#L189

What is the right solution here?

Changed 3 years ago by dsd

Heh, weird code. It tries to dlopen libv4l2 if it cannot be found. However, the Makefile links the resultant plugin against libv4l2, so if libv4l2 could not be found then the code would crash before running in the first place.

I'd push for the solution of dropping dlopen and just calling v4l2_open() and friends directly.

Changed 3 years ago by dmoco

No, the dependency on libv4l2 should be removed and dlopen() code kept intact. The aim was to support systems without libv4l2 but use it if available. In this way the plug-in could be built & used where a webcam natively supports the format required by Scratch and if not then libv4l2 could be installed and the plug-in will automatically take advantage of it to get the format required.

Changed 3 years ago by dsd

  • cc dmoco added

But the plugin is already unconditionally linked against libv4l2 at compile time. If libv4l2 is not available on the build host, it will fail to compile/link. If libv4l2 is not available on the runtime host, it will fail at the runtime linking stages, before any of this code has a chance to execute.

Changed 3 years ago by dmoco

Could you please remove the dependency from the  make file and try again? IIRC  dlopen() with flag RTLD_LAZY should work as intended.

Changed 3 years ago by dsd

Yes, removing the compile-time link against libv4l2 is one of the steps needed if you are to get things to work as you have described above.

However, there is still one problem after that. Scratch calls dlopen() on "libv4l2.so" however installing the libv4l2 package on Fedora/Ubuntu/openSUSE/etc will *not* result in a file existing with that name. A symlink named "libv4l2.so" does appear if you install the libv4l development package on those distros, which additionally installs development tools and headers, as well as development tools and headers for libv4l2's dependencies.

So in addition to removing the compile-time link against libv4l2, I suspect you also mean to dlopen libv4l2.so.0, which is the name of the library as installed by libtool and as shipped on all major distros.

Any chance these changes could be made in the Scratch svn repository upstream?

Thanks for your help.

Changed 3 years ago by dmoco

re "libv4l2.so/.0", well spotted! Though it's possible that the device/s that this plug-in was originally create for may have dropped links to preserve space (eg, Nokia internet tablets). Equally likely I just dumped the lib on the device for testing :-) So go with what you feel is correct.

Re upstream changes, if godiard or yourself want access then join up, I'm sure Amos will be happy to welcome you.

Thanks for your help.

...and thanks for all your effort!

Changed 3 years ago by dmoco

Diff to remove link dependency and correct lib name for libv4l2

Changed 3 years ago by dmoco

Diff supplied by godiard applied upstream (rev 81)

Changed 3 years ago by dsd

  • next_action changed from diagnose to add to build

Fixed in Scratch-20 supplied by Gonzalo

Changed 3 years ago by dsd

  • summary changed from Scratch need libv4l-devel package to Scratch looks for wrong libv4l2.so file

Changed 3 years ago by dsd

  • milestone changed from Not Triaged to 11.3.0

Changed 3 years ago by dsd

  • next_action changed from add to build to test in build

test in 11.3.0 candidate build 882

Changed 3 years ago by dsd

camera works on on Scratch-20 on 11.3.0 build 882 on XO-1.75

Changed 3 years ago by manuq

  • status changed from new to closed
  • resolution set to fixed

Confirmed, clicked on camera button, in costumes tab, it's working in build 883, XO-1.75.

Note: See TracTickets for help on using tickets.