[Gst/MQTT/Sink] Update the message header at every publish
authorWook Song <wook16.song@samsung.com>
Tue, 27 Apr 2021 01:59:31 +0000 (10:59 +0900)
committerDongju Chae <dongju.chae@samsung.com>
Mon, 10 May 2021 06:01:57 +0000 (15:01 +0900)
In order to reduce memory copying overhead, the previous implementation
updates the message header only once at the first publish moment. This
might be a little bit effective but cannot handle the incoming buffers
with variable sizes. To overcome such restriction, the message header
will be updated at every publish moment.

Signed-off-by: Wook Song <wook16.song@samsung.com>
gst/mqtt/mqttsink.c

index 8e0bdcb..bbf9c98 100644 (file)
@@ -657,11 +657,6 @@ gst_mqtt_sink_render (GstBaseSink * basesink, GstBuffer * in_buf)
 
   /** Allocate a message buffer */
   if ((!self->mqtt_msg_buf) && (self->mqtt_msg_buf_size == 0)) {
-    if (!_mqtt_set_msg_buf_hdr (in_buf, &self->mqtt_msg_hdr)) {
-      ret = GST_FLOW_ERROR;
-      goto ret_with;
-    }
-
     if (self->max_msg_buf_size == 0) {
       self->mqtt_msg_buf_size = in_buf_size + GST_MQTT_LEN_MSG_HDR;
     } else {
@@ -682,13 +677,15 @@ gst_mqtt_sink_render (GstBaseSink * basesink, GstBuffer * in_buf)
       ret = GST_FLOW_ERROR;
       goto ret_with;
     }
-
-    msg_pub = self->mqtt_msg_buf;
-    memcpy (msg_pub, &self->mqtt_msg_hdr, sizeof (self->mqtt_msg_hdr));
-  } else {
-    msg_pub = self->mqtt_msg_buf;
   }
 
+  msg_pub = self->mqtt_msg_buf;
+
+  if (!_mqtt_set_msg_buf_hdr (in_buf, &self->mqtt_msg_hdr)) {
+    ret = GST_FLOW_ERROR;
+    goto ret_with;
+  }
+  memcpy (msg_pub, &self->mqtt_msg_hdr, sizeof (self->mqtt_msg_hdr));
   _put_timestamp_to_msg_buf_hdr (self, in_buf, (GstMQTTMessageHdr *) msg_pub);
 
   in_buf_mem = gst_buffer_get_all_memory (in_buf);