Thread: g_assert(recording); <--- checks if recording is null

  1. #1
    Registered User
    Join Date
    Jul 2012
    Posts
    8

    g_assert(recording); <--- checks if recording is null

    I want to create lirc command to stop recording. I have 3 files for this:
    File: record.c

    Code:
    ...
    #include "rec_tech.h"
    ...
    void stop_rec_button_clicked_cb(GtkButton *button, gpointer data)
    {
        Recording *recording = data;
        close_status_window();
        recording_stop(recording);
    }
    ...
    File: rec_tech.c

    Code:
    ...
    void recording_stop(Recording *recording)
    {
        g_assert(recording);
    
        GstState state;
        gst_element_get_state(recording->pipeline, &state, NULL, GST_CLOCK_TIME_NONE);
        if (state != GST_STATE_PLAYING) {
            GST_DEBUG ("pipeline in wrong state: %s", gst_element_state_get_name (state));
        } else {
            gst_element_set_state(recording->pipeline, GST_STATE_NULL);
        }
        gst_object_unref(GST_OBJECT(recording->pipeline));
        g_free(recording->filename);
        g_free(recording->station);
        g_free(recording);
    }   
    ...
    File: lirc.c

    Code:
    ...
    #include <lirc/lirc_client.h>
    #include "lirc.h"
    #include "rec_tech.h"
    #include "record.h"
    
    static void execute_lirc_command (char *cmd)
    {
            printf("lirc command: %s\n", cmd);
    
            if (strcasecmp (cmd, "stop recording") == 0) {
                stop_rec_button_clicked_cb(NULL, data);
            }
    ...

    "data" isn't defined in execute_lirc_command.
    How to add appropriate value for it for lirc to worc and recording stop
    Thanks

  2. #2
    Registered User
    Join Date
    May 2012
    Posts
    1,066
    I think the LIRC mailing list is a better place to ask.

    Bye, Andreas

  3. #3
    Registered User
    Join Date
    Jul 2012
    Posts
    8
    Update:

    File: record.c

    Code:
    ...
    #include "rec_tech.h"
    ...
    void stop_rec_button_clicked_cb(GtkButton *button, gpointer data)
    {
        Recording *recording = data;
        close_status_window();
        recording_stop(recording);
    }
    ...
    File: rec_tech.c

    Code:
    ...
    void recording_stop(Recording *recording)
    {
        g_assert(recording);
    
        GstState state;
        gst_element_get_state(recording->pipeline, &state, NULL, GST_CLOCK_TIME_NONE);
        if (state != GST_STATE_PLAYING) {
            GST_DEBUG ("pipeline in wrong state: %s", gst_element_state_get_name (state));
        } else {
            gst_element_set_state(recording->pipeline, GST_STATE_NULL);
        }
        gst_object_unref(GST_OBJECT(recording->pipeline));
        g_free(recording->filename);
        g_free(recording->station);
        g_free(recording);
    }   
    ...
    file rec_tech.h

    Code:
    ...
    #ifndef _REC_TECH_H
    #define _REC_TECH_H
    #include <gst/gst.h>
    ....
    typedef struct {
        GstElement* pipeline;
        char* filename;
        char* station;
    } Recording;
    
    Recording*
    recording_start(const char* filename);
    
    void
    recording_stop(Recording* recording);
    ...
    File: lirc.c

    Code:
    ...
    #include <lirc/lirc_client.h>
    #include "lirc.h"
    #include "rec_tech.h"
    #include "record.h"
    
    static void execute_lirc_command (char *cmd)
    {
            printf("lirc command: %s\n", cmd);
    
            if (strcasecmp (cmd, "stop recording") == 0) {
                stop_rec_button_clicked_cb(NULL, data);
            }
    ...
    When I try to compile get error in file lirc.c
    Code:
    error: 'data' undeclared (first use in this function)
    If in lirc.c add line Recording *data;
    Code:
    ...
    #include <lirc/lirc_client.h>
    #include "lirc.h"
    #include "rec_tech.h"
    #include "record.h"
    
    Recording *data;    
    static void execute_lirc_command (char *cmd)
    {
            printf("lirc command: %s\n", cmd);
    
            if (strcasecmp (cmd, "stop recording") == 0) {
                stop_rec_button_clicked_cb(NULL, data);
            }
    ...
    get this run-time error:
    Code:
    ERROR:rec_tech.c:recording_stop: assertion failed: (recording)

  4. #4
    Algorithm Dissector iMalc's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    6,318
    You've giving it an uninitialised pointer when it is probably expecting a pointer to an object, or an array of objects. Also, those objects themselves seem to contain pointers which may need to be set to point to something.

    But basically we can't help much more than that because your problem is with this lirc library thying that you are using and not with C itself. Search the LIRC mailing list and also search for examples of doing what you want to do. Read the documentation of those lirc functions.
    My homepage
    Advice: Take only as directed - If symptoms persist, please see your debugger

    Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Recording
    By MadCow257 in forum Tech Board
    Replies: 0
    Last Post: 06-20-2006, 11:24 AM
  2. Recording
    By cerin in forum A Brief History of Cprogramming.com
    Replies: 4
    Last Post: 03-30-2005, 08:20 AM
  3. Recording Sounds
    By subdene in forum C++ Programming
    Replies: 2
    Last Post: 01-25-2003, 01:04 PM
  4. recording
    By xlordt in forum Linux Programming
    Replies: 9
    Last Post: 02-18-2002, 10:35 AM
  5. recording in C++
    By Unregistered in forum C++ Programming
    Replies: 4
    Last Post: 11-16-2001, 01:47 PM