KuriRobot / Kuri-Documentation

Documentation for Kuri the adorable home robot.
MIT License
17 stars 13 forks source link

libmadmux missing functions #33

Closed amalnanavati closed 4 years ago

amalnanavati commented 4 years ago

Like in Issue #25 , our Kuri has three versions of libmadmux. /opt/gizmo-master-cbb8e0c/lib/x86_64-linux-gnu and /opt/gizmo/lib/x86_64-linux-gnu have libmadmux version 0.3.0, and /opt/ros/indigo/lib has libmadmux version 0.2.0.

I have successfully got libmadmux to link to C++ code (see this CMakeLists file as an example). However, regardless of which of the three libmadmux files I link to, I get undefined reference errors when calling the functions: mdx_set_resolution, mdx_force_iframe, and mdx_set_bitrate. Note that the other functions listed in the docs, mdx_open, mdx_close, and mdx_register_cb all work.

The header files in both /opt/gizmo-master-cbb8e0c/include/madmux/madmux.h and /opt/gizmo/include/madmux/madmux.h include those functions. Therefore, the problem must be that the libmadmux.so itself does not include those functions.

Can you shed light on why this might be, and whether you have suggestions for changing the bitrate and resolution of camera streams?

po1 commented 4 years ago

It sounds like you are linking against the correct library at build time, but not at run time. What does your LD_LIBRARY_PATH look like before you run your program?

Also, /opt/gizmo should be a symbolic link to /opt/gizmo-master-cbb8e0c. The leftover madmux lib in /opt/ros/indigo/lib is a known bug. After making a backup, could you try just removing anything pertaining to madmux in /opt/ros/indigo/lib?

amalnanavati commented 4 years ago

Hi @po1,

I solved it! The core of the problem was, in fact, the duplicate madmux packages. The madmux.h files were actually different:

/opt/ros/indigo/include/madmux/madmux.h:

/**
 * madmux.h
 * madmux client library
 *
 * \author Paul
 * \date   2017-06-03
 */

#ifndef MADMUX_H
#define MADMUX_H

#include <stdint.h> /* uint* */

#ifdef __cplusplus
extern "C" {
#endif

struct mdx_stream;

typedef void (*mdx_cb)(uint8_t* buffer, uint32_t size, void* user_data);

/**
 * Open a madmux video channel
 * @param  socket the path to the UNIX socket for that channel
 * @return        the video stream handle
 */
struct mdx_stream* mdx_open(const char* socket);

/**
 * Close a madmux video channel
 * @param stream the stream to close
 */
void mdx_close(struct mdx_stream* stream);

/**
 * Register a callback to receive video frames
 * @param stream    the video stream handle
 * @param cb        the callback
 * @param user_data a pointer to a user data structure
 */
void mdx_register_cb(struct mdx_stream* stream, mdx_cb cb, void* user_data);

#ifdef __cplusplus
}
#endif

#endif /* end of include guard: MADMUX_H */

/opt/gizmo/include/madmux/madmux.h:

/**
 * madmux.h
 * madmux client library
 *
 * \author Paul
 * \date   2017-06-03
 */

#ifndef MADMUX_H
#define MADMUX_H

#include <stdint.h> /* uint* */

#ifdef __cplusplus
extern "C" {
#endif

struct mdx_stream;

typedef void (*mdx_cb)(uint8_t* buffer, uint32_t size, void* user_data);

/**
 * Open a madmux video channel
 * @param  socket the path to the UNIX socket for that channel
 * @return        the video stream handle
 */
struct mdx_stream* mdx_open(const char* socket);

/**
 * Close a madmux video channel
 * @param stream the stream to close
 */
void mdx_close(struct mdx_stream* stream);

/**
 * Register a callback to receive video frames
 * @param stream    the video stream handle
 * @param cb        the callback
 * @param user_data a pointer to a user data structure
 */
void mdx_register_cb(struct mdx_stream* stream, mdx_cb cb, void* user_data);

/**
 * Ask for a single frame on a still channel
 * @param stream    the video stream handle
 */
void mdx_snap(struct mdx_stream* stream);

/**
 * Force an i-frame in an h264 stream
 * @param stream    the video stream handle
 */
void mdx_force_iframe(struct mdx_stream* stream);

/**
 * Set the bitrate of a non-raw stream.
 * @param stream    the video stream handle
 * @param bitrate   bitrate in bps
 */
void mdx_set_bitrate(struct mdx_stream* stream, uint32_t bitrate);

/**
 * Set the resolution of a stream.
 * @param stream    the video stream handle
 * @param width     the width of the video in pixels
 * @param height    the height of the video in pixels
 */
void mdx_set_resolution(struct mdx_stream* stream, uint16_t width,
        uint16_t height);

#ifdef __cplusplus
}
#endif

#endif /* end of include guard: MADMUX_H */

Therefore, although I was linking against the right libmadmux in /opt/gizmo/, catkin was using the wrong .h file from /opt/ros/indigo. I solved this by deleting all traces of madmux from /opt/ros/indigo:

sudo rm -r /opt/ros/indigo/include/madmux sudo rm /opt/ros/indigo/lib/libmadmux.so sudo rm /opt/ros/indigo/lib/libmadmux.so.0 sudo rm /opt/ros/indigo/lib/libmadmux.so.0.2.0 sudo rm -r /opt/ros/indigo/share/madmux

I then re-built my workspace (catkin clean followed by catkin build).

I will post my minimal working example in a comment in case it helps anyone, but as of now this issue is solved for me.

amalnanavati commented 4 years ago

Although this issue is solved (see above), I am posting my minimal working example in case it helps others. If I commented out lines 13-15 of the cpp file (mdx_set_resolution, mdx_force_iframe, and mdx_set_bitrate), it compiled fine. However, if I left them in, I got a linking error (see below).

kuri_camera_linking_issue/src/kuri_camera_linking_issue.cpp:

#include "ros/ros.h"
#include <madmux/madmux.h>

static void callback(uint8_t *buffer, uint32_t size, void *obj) {
  return;
}

int main(int argc, char **argv) {
  ros::init(argc, argv, "kuri_camera_linking_issue");

  mdx_stream* stream = mdx_open("/var/run/madmux/ch1.sock"); // works
  mdx_register_cb(stream, callback, NULL); // works
  mdx_set_resolution(stream, 1240, 720); // undefined reference
  mdx_force_iframe(stream); // undefined reference
  mdx_set_bitrate(stream, 30); // undefined reference
  mdx_close(stream); // works

  return 0;
}

CMakeLists.txt:

cmake_minimum_required(VERSION 2.8.3)
project(kuri_camera_linking_issue)

set(libmadmux_path /opt/gizmo/lib/x86_64-linux-gnu)

find_package(catkin REQUIRED COMPONENTS
  madmux
  roscpp
)

catkin_package(
 CATKIN_DEPENDS madmux roscpp
)

include_directories(
  ${catkin_INCLUDE_DIRS}
)

# find libmadmux
set(libmadmux "libmadmux-NOTFOUND")
find_file(libmadmux libmadmux.so.0.3.0 ${libmadmux_path} NO_DEFAULT_PATH)

if (libmadmux)
  add_executable(kuri_camera_linking_issue src/kuri_camera_linking_issue.cpp)
  target_link_libraries(kuri_camera_linking_issue ${catkin_LIBRARIES} ${libmadmux})
else()
  message(ERROR "Did not find libmadmux")
endif()

package.xml:

<?xml version="1.0"?>
<package format="2">
  <name>kuri_camera_linking_issue</name>
  <version>0.0.0</version>
  <description>The kuri_camera_linking_issue package</description>
  <maintainer email="mayfield@todo.todo">mayfield</maintainer>

  <license>TODO</license>

  <buildtool_depend>catkin</buildtool_depend>
  <build_depend>madmux</build_depend>
  <build_depend>roscpp</build_depend>
  <build_export_depend>madmux</build_export_depend>
  <build_export_depend>roscpp</build_export_depend>
  <exec_depend>madmux</exec_depend>
  <exec_depend>roscpp</exec_depend>

</package>

As I mentioned above, if I compile the code with lines 13-15 included, I get the following error:

mayfield@cococutkuri:~/workspaces/amal_ws$ catkin build kuri_camera_linking_issue
----------------------------------------------------------------------
Profile:                     default
Extending:          [cached] /opt/gizmo:/opt/ros/indigo
Workspace:                   /home/mayfield/workspaces/amal_ws
----------------------------------------------------------------------
Build Space:        [exists] /home/mayfield/workspaces/amal_ws/build
Devel Space:        [exists] /home/mayfield/workspaces/amal_ws/devel
Install Space:      [unused] /home/mayfield/workspaces/amal_ws/install
Log Space:          [exists] /home/mayfield/workspaces/amal_ws/logs
Source Space:       [exists] /home/mayfield/workspaces/amal_ws/src
DESTDIR:            [unused] None
----------------------------------------------------------------------
Devel Space Layout:          linked
Install Space Layout:        None
----------------------------------------------------------------------
Additional CMake Args:       None
Additional Make Args:        None
Additional catkin Make Args: None
Internal Make Job Server:    True
Cache Job Environments:      False
----------------------------------------------------------------------
Whitelisted Packages:        None
Blacklisted Packages:        None
----------------------------------------------------------------------
Workspace configuration appears valid.
----------------------------------------------------------------------
[build] Found '11' packages in 0.0 seconds.
[build] Package table is up to date.
Starting  >>> kuri_camera_linking_issue
___________________________________________________________________________________________________________________________________________________________________________________________________________
Errors     << kuri_camera_linking_issue:make /home/mayfield/workspaces/amal_ws/logs/kuri_camera_linking_issue/build.make.003.log
CMakeFiles/kuri_camera_linking_issue.dir/src/kuri_camera_linking_issue.cpp.o: In function `main':
kuri_camera_linking_issue.cpp:(.text+0xaa): undefined reference to `mdx_set_resolution'
kuri_camera_linking_issue.cpp:(.text+0xb6): undefined reference to `mdx_force_iframe'
kuri_camera_linking_issue.cpp:(.text+0xc7): undefined reference to `mdx_set_bitrate'
collect2: error: ld returned 1 exit status
make[2]: *** [/home/mayfield/workspaces/amal_ws/devel/.private/kuri_camera_linking_issue/lib/kuri_camera_linking_issue/kuri_camera_linking_issue] Error 1
make[1]: *** [CMakeFiles/kuri_camera_linking_issue.dir/all] Error 2
make: *** [all] Error 2
cd /home/mayfield/workspaces/amal_ws/build/kuri_camera_linking_issue; catkin build --get-env kuri_camera_linking_issue | catkin env -si  /usr/bin/make --jobserver-fds=6,7 -j; cd -
...........................................................................................................................................................................................................
Failed     << kuri_camera_linking_issue:make           [ Exited with code 2 ]
Failed    <<< kuri_camera_linking_issue                [ 0.9 seconds ]
[build] Summary: 0 of 1 packages succeeded.
[build]   Ignored:   10 packages were skipped or are blacklisted.
[build]   Warnings:  None.
[build]   Abandoned: None.
[build]   Failed:    1 packages failed.
[build] Runtime: 1.1 seconds total.
mayfield@cococutkuri:~/workspaces/amal_ws$

To be clear, after deleting all traces of madmux from /opt/ros/indigo (see above) this minimal working example compiled and ran fine.