Cannot compile libpdraw-backend using example

I am trying to compile the example of libdpraw-backend using the example provided on this url : User Guide - GroundSDK Tools 7.0

I am using Anafi Parrot on Jetson.

I use cmake & I managed to compile & use easily libpdraw vsink. However it seems I cannot use libpdraw-backend based on the example provided.

#include <pdraw/pdraw_backend.h>

#include <pthread.h>
#include <stdio.h>
#include <string.h>

struct ctx {
  pthread_mutex_t mutex;
  pthread_cond_t cond;
  int completed;
  int status;
};

static void ctx_signal_resp(struct ctx *ctx, int status) {
  pthread_mutex_lock(&ctx->mutex);
  ctx->status = status;
  ctx->completed = 1;
  pthread_cond_signal(&ctx->cond);
  pthread_mutex_unlock(&ctx->mutex);
}

static int ctx_wait_resp(struct ctx *ctx) {
  int status;

  pthread_mutex_lock(&ctx->mutex);
  while (!ctx->completed)
    pthread_cond_wait(&ctx->cond, &ctx->mutex);
  status = ctx->status;
  ctx->completed = 0;
  pthread_mutex_unlock(&ctx->mutex);

  return status;
}

static void pdraw_stop_resp(struct pdraw_backend *pdraw, int status,
                            void *userdata) {
  struct ctx *ctx = userdata;

  printf("pdraw_stop_resp: %d (%s)\n", status, strerror(-status));

  ctx_signal_resp(ctx, status);
}

static void pdraw_demuxer_open_resp(struct pdraw_backend *pdraw,
                                    struct pdraw_demuxer *demuxer, int status,
                                    void *userdata) {
  struct ctx *ctx = userdata;

  printf("pdraw_demuxer_open_resp: %d (%s)\n", status, strerror(-status));

  ctx_signal_resp(ctx, status);
}

static void pdraw_demuxer_close_resp(struct pdraw_backend *pdraw,
                                     struct pdraw_demuxer *demuxer, int status,
                                     void *userdata) {
  struct ctx *ctx = userdata;

  printf("pdraw_demuxer_close_resp: %d (%s)\n", status, strerror(-status));

  ctx_signal_resp(ctx, status);
}

static const struct pdraw_backend_cbs backend_cbs = {
    .stop_resp = pdraw_stop_resp,
};

static const struct pdraw_backend_demuxer_cbs demuxer_cbs = {
    .open_resp = pdraw_demuxer_open_resp,
    .close_resp = pdraw_demuxer_close_resp,
};

int main(int argc, char *argv[]) {
  struct pdraw_backend *pdraw = NULL;
  struct pdraw_demuxer *demuxer = NULL;
  struct ctx ctx = {
      .mutex = PTHREAD_MUTEX_INITIALIZER,
      .cond = PTHREAD_COND_INITIALIZER,
  };
  int ret;

  if (argc < 2) {
    fprintf(stderr, "Missing argument\n");
    return 1;
  }

  ret = pdraw_be_new(&backend_cbs, &ctx, &pdraw);
  if (ret != 0) {
    fprintf(stderr, "pdraw_be_new: %d (%s)\n", ret, strerror(-ret));
    goto exit;
  }

  ret = pdraw_be_demuxer_new_from_url(pdraw, argv[1], &demuxer_cbs, &ctx,
                                      &demuxer);
  if (ret != 0) {
    fprintf(stderr, "pdraw_be_demuxer_new_from_url: %d (%s)\n", ret,
            strerror(-ret));
    goto exit;
  }

  /* Wait for demuxer open resp */
  if (ctx_wait_resp(&ctx) != 0)
    goto exit;

  /* The demuxer is now open. This is the point where your app should go
   * in a waiting state while the video is running. The demuxer will call
   * its `ready_to_play' callback when it is safe to call
   * `pdraw_be_demuxer_play()' to start receiving frames */

  ret = pdraw_be_demuxer_close(pdraw, demuxer);
  if (ret != 0) {
    fprintf(stderr, "pdraw_be_demuxer_close: %d (%s)\n", ret, strerror(-ret));
    goto exit;
  }

  /* Wait for demuxer close resp */
  ctx_wait_resp(&ctx);

  /* Destroy the demuxer before stopping the backend */
  pdraw_be_demuxer_destroy(pdraw, demuxer);

  ret = pdraw_be_stop(pdraw);
  if (ret != 0) {
    fprintf(stderr, "pdraw_be_stop: %d (%s)\n", ret, strerror(-ret));
    goto exit;
  }

  /* Wait for stop resp */
  ctx_wait_resp(&ctx);

exit:
  if (pdraw != NULL)
    pdraw_be_destroy(pdraw);
  pthread_mutex_destroy(&ctx.mutex);
  pthread_cond_destroy(&ctx.cond);
  return ret;
}

I got the following error:

make
-- Found SBIPC: using sbipc::sbipc
-- Configuring done
-- Generating done
-- Build files have been written to: /home/janice/work/poc/anafi_daemon/build
Consolidate compiler generated dependencies of target anafi
[ 16%] Built target anafi
Consolidate compiler generated dependencies of target recorderd
[ 50%] Built target recorderd
[ 58%] Building CXX object CMakeFiles/test-app.dir/src/test/main.cpp.o
/home/janice/work/poc/anafi_daemon/src/test/main.cpp: In function ‘void pdraw_stop_resp(pdraw_backend*, int, void*)’:
/home/janice/work/poc/anafi_daemon/src/test/main.cpp:39:21: error: invalid conversion from ‘void*’ to ‘ctx*’ [-fpermissive]
   39 |   struct ctx *ctx = userdata;
      |                     ^~~~~~~~
      |                     |
      |                     void*
/home/janice/work/poc/anafi_daemon/src/test/main.cpp: In function ‘void pdraw_demuxer_open_resp(pdraw_backend*, pdraw_demuxer*, int, void*)’:
/home/janice/work/poc/anafi_daemon/src/test/main.cpp:49:21: error: invalid conversion from ‘void*’ to ‘ctx*’ [-fpermissive]
   49 |   struct ctx *ctx = userdata;
      |                     ^~~~~~~~
      |                     |
      |                     void*
/home/janice/work/poc/anafi_daemon/src/test/main.cpp: In function ‘void pdraw_demuxer_close_resp(pdraw_backend*, pdraw_demuxer*, int, void*)’:
/home/janice/work/poc/anafi_daemon/src/test/main.cpp:59:21: error: invalid conversion from ‘void*’ to ‘ctx*’ [-fpermissive]
   59 |   struct ctx *ctx = userdata;
      |                     ^~~~~~~~
      |                     |
      |                     void*
/home/janice/work/poc/anafi_daemon/src/test/main.cpp: In function ‘int main(int, char**)’:
/home/janice/work/poc/anafi_daemon/src/test/main.cpp:95:55: error: cannot convert ‘const pdraw_backend_demuxer_cbs*’ to ‘const pdraw_demuxer_params*’
   95 |   ret = pdraw_be_demuxer_new_from_url(pdraw, argv[1], &demuxer_cbs, &ctx,
      |                                                       ^~~~~~~~~~~~
      |                                                       |
      |                                                       const pdraw_backend_demuxer_cbs*
In file included from /home/janice/work/poc/anafi_daemon/src/test/main.cpp:2:
/home/janice/work/poc/anafi_daemon/groundsdk-tools/out/groundsdk-linux/sdk/usr/include/pdraw/pdraw_backend.h:1049:66: note:   initializing argument 3 of ‘int pdraw_be_demuxer_new_from_url(pdraw_backend*, const char*, const pdraw_demuxer_params*, const pdraw_backend_demuxer_cbs*, void*, pdraw_demuxer**)’
 1049 |                               const struct pdraw_demuxer_params *params,
      |                               ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~
make[2]: *** [CMakeFiles/test-app.dir/build.make:76: CMakeFiles/test-app.dir/src/test/main.cpp.o] Error 1
make[1]: *** [CMakeFiles/Makefile2:143: CMakeFiles/test-app.dir/all] Error 2
make: *** [Makefile:91: all] Error 2

Would appreciate any help.

UDPATE:

I managed to fix the compilation error using :

  auto *ctx = static_cast<struct ctx *>(userdata);

To cast C void pointers in C++.

& adding a missing parameters for pdraw_by_demuxer_new_from_url :

  ret = pdraw_be_demuxer_new_from_url(pdraw, argv[1], /*params*/ nullptr,
                                      &demuxer_cbs, &ctx, &demuxer);

I believe the docs might not be up to date on the website.

However now I’m getting :

../groundsdk-tools/out/groundsdk-linux/final/native-wrapper.sh ./test-app rtsp://192.168.42.1/live
I pdraw_session: state change to READY
E pdraw_backend: pdraw_be_demuxer_new_from_url:1720:  err=22(Invalid argument)
pdraw_be_demuxer_new_from_url: -22 (Invalid argument)
I pdraw_session: state change to STOPPING
I pdraw_session: stop: all elements are stopped, closing
I pdraw_session: state change to STOPPED
pdraw_stop_resp: 0 (Success)

is it because of the nullptr parameters ? Is there any solution for this ?

Hi,

According to the pdraw_backend.h documentation:

/**
 * Create a demuxer on a URL (stream or local file).
 * The URL can be either an RTSP URL (starting with "rtsp://") or a local file
 * path (either absolute or relative).
 * The params structure must be provided but all parameters are optional and can
 * be left null. The function returns before the actual opening is done. If the
 * function returns 0, the open_resp callback function will be issued once the
 * open operation is successful (0 status) or has failed (negative errno
 * status). If the function returns a negative errno value (immediate failure),
 * the open_resp callback function will not be issued. Once a demuxer is no
 * longer used, it must be closed and then destroyed
 * (@see the pdraw_be_demuxer_close() function).

The documentation states that a params structure must be provided, even though all its fields are optional. In your code snippet, it looks like nullptr is passed for the const struct pdraw_demuxer_params *params argument.

This is why the function returns -EINVAL. To fix this, you should pass a valid structure pointer, for example:

struct pdraw_demuxer_params params = {};
pdraw_be_demuxer_open(session, url, &params, &demuxer);

This satisfies the requirement while keeping all parameters at their default values.

Regards,
Mathieu

thank you for the response, I manage to run my exec, but I’m having a hard time getting at the same time a recording of the stream (with metadata) & the individual images that I can serve via vipc. Any idea of how I could implement that these two parallel processes ?

Solutions i’m currently pursuing : getting the raw frame buffer using :

/**
 * Get a read-only plane buffer from the frame.
 *
 * @note When no longer used, the buffer must be released with
 * mbuf_raw_video_frame_release_plane().
 *
 * @param frame: The frame.
 * @param plane: The plane index.
 * @param data: [out] The plane buffer.
 * @param len: [out] The plane buffer size.
 *
 * @return 0 on success, negative errno on error.
 */
MBUF_API int mbuf_raw_video_frame_get_plane(struct mbuf_raw_video_frame *frame,
					    unsigned int plane,
					    const void **data,
					    size_t *len);

Or trying to make libpdraw-vsink and libpdraw-backend coexist.

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.