Skip to content
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

How to support CompressedImage ? #22

Open
iceriver97 opened this issue Apr 19, 2023 · 4 comments
Open

How to support CompressedImage ? #22

iceriver97 opened this issue Apr 19, 2023 · 4 comments

Comments

@iceriver97
Copy link

I made the following changes to the code:

  1. in image2rtsp.h:
// GstCaps* gst_caps_new_from_image(const sensor_msgs::Image::ConstPtr &msg);
GstCaps* gst_caps_new_from_image(const sensor_msgs::CompressedImageConstPtr &msg); //my_test
//void imageCallback(const sensor_msgs::Image::ConstPtr& msg, const std::string& topic);
void CompressedImageCallback(const sensor_msgs::CompressedImageConstPtr& msg, const std::string& topic); //my_test
  1. in image2rtsp.cpp
    2.1 Use fixed parameters
GstCaps* Image2RTSPNodelet::gst_caps_new_from_image(const sensor_msgs::CompressedImageConstPtr &msg)
{
    // http://gstreamer.freedesktop.org/data/doc/gstreamer/head/pwg/html/section-types-definitions.html

    // static const ros::M_string known_formats = {{
    //     {sensor_msgs::image_encodings::RGB8, "RGB"},
    //     {sensor_msgs::image_encodings::RGB16, "RGB16"},
    //     {sensor_msgs::image_encodings::RGBA8, "RGBA"},
    //     {sensor_msgs::image_encodings::RGBA16, "RGBA16"},
    //     {sensor_msgs::image_encodings::BGR8, "BGR"},
    //     {sensor_msgs::image_encodings::BGR16, "BGR16"},
    //     {sensor_msgs::image_encodings::BGRA8, "BGRA"},
    //     {sensor_msgs::image_encodings::BGRA16, "BGRA16"},
    //     {sensor_msgs::image_encodings::MONO8, "GRAY8"},
    //     {sensor_msgs::image_encodings::MONO16, "GRAY16_LE"},
    // }};

    // if (msg->is_bigendian) {
    //     ROS_ERROR("GST: big endian image format is not supported");
    //     return nullptr;
    // }

    // auto format = known_formats.find(msg->encoding);
    // if (format == known_formats.end()) {
    //     ROS_ERROR("GST: image format '%s' unknown", msg->encoding.c_str());
    //     return nullptr;
    // }


    // return gst_caps_new_simple("video/x-raw",
    //         "format", G_TYPE_STRING, format->second.c_str(),
    //         "width", G_TYPE_INT, msg->width,
    //         "height", G_TYPE_INT, msg->height,
    //         "framerate", GST_TYPE_FRACTION, 10, 1,
    //         nullptr);
    return gst_caps_new_simple("video/x-raw",
            "format", G_TYPE_STRING, "RGB",
            "width", G_TYPE_INT, 1280,
            "height", G_TYPE_INT, 720,
            "framerate", GST_TYPE_FRACTION, 10, 1,
            nullptr);
}

2.2 change bufsize=720*1280

// my_test satrt
void Image2RTSPNodelet::CompressedImageCallback(const sensor_msgs::CompressedImageConstPtr& msg, const std::string& topic) {
    GstBuffer *buf;

    GstCaps *caps;
    char *gst_type, *gst_format=(char *)"";
    // g_print("Image encoding: %s\n", msg->encoding.c_str());
    if (appsrc[topic] != NULL) {
        // Set caps from message
        caps = gst_caps_new_from_image(msg);
        gst_app_src_set_caps(appsrc[topic], caps);

        // buf = gst_buffer_new_allocate(nullptr, msg->data.size(), nullptr);
        //gst_buffer_fill(buf, 0, msg->data.data(), msg->data.size());
        //std::cout<< msg->data.size()<<std::endl;
        gsize data_size = 2764800;
        buf = gst_buffer_new_allocate(nullptr, data_size, nullptr);
        gst_buffer_fill(buf, 0, msg->data.data(), 2764800);
        GST_BUFFER_FLAG_SET(buf, GST_BUFFER_FLAG_LIVE);

        gst_app_src_push_buffer(appsrc[topic], buf);
    }
}
// my_test end

if no changes as 2.2, will get Error : 80000 < 2764800. i guess 80000 means the size of the CompressedImage.
Apply all the changes, the process will be killed.

@iceriver97
Copy link
Author

@CircusMonkey

@iceriver97
Copy link
Author

@CircusMonkey do u have any ideas?

@zeesee
Copy link

zeesee commented Oct 19, 2023

Hi, is there any update on this? need some help how to stream compressedimage from rtsp

@CircusMonkey
Copy link
Owner

I'm sure that you are aware that I no longer have time to develop this project. I'm happy to merge any pull requests you make to get this working.

Sorry, but in the meantime, this doesn't support compressed images.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants