CircusMonkey / ros_rtsp

ROS node to subscribe to an image and serve it up as a RTSP video feed.
The Unlicense
103 stars 48 forks source link

How to support CompressedImage ? #22

Open iceriver97 opened 1 year ago

iceriver97 commented 1 year ago

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
  2. 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 commented 1 year ago

@CircusMonkey

iceriver97 commented 1 year ago

@CircusMonkey do u have any ideas?

zeesee commented 8 months ago

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

CircusMonkey commented 4 months ago

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.