subparse: fix off by one offset calculation
[platform/upstream/gstreamer.git] / gst / tcp / gsttcpclientsrc.c
index a666523..d3668b9 100644 (file)
@@ -16,8 +16,8 @@
  *
  * You should have received a copy of the GNU Library General Public
  * License along with this library; if not, write to the
- * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- * Boston, MA 02111-1307, USA.
+ * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
  */
 
 /**
@@ -112,7 +112,7 @@ gst_tcp_client_src_class_init (GstTCPClientSrcClass * klass)
   gst_element_class_add_pad_template (gstelement_class,
       gst_static_pad_template_get (&srctemplate));
 
-  gst_element_class_set_details_simple (gstelement_class,
+  gst_element_class_set_static_metadata (gstelement_class,
       "TCP client source", "Source/Network",
       "Receive data as a client over the network via TCP",
       "Thomas Vander Stichele <thomas at apestaart dot org>");
@@ -179,7 +179,7 @@ gst_tcp_client_src_create (GstPushSrc * psrc, GstBuffer ** outbuf)
   GstFlowReturn ret = GST_FLOW_OK;
   gssize rret;
   GError *err = NULL;
-  guint8 *data;
+  GstMapInfo map;
   gssize avail, read;
 
   src = GST_TCP_CLIENT_SRC (psrc);
@@ -224,13 +224,14 @@ gst_tcp_client_src_create (GstPushSrc * psrc, GstBuffer ** outbuf)
   if (avail > 0) {
     read = MIN (avail, MAX_READ_SIZE);
     *outbuf = gst_buffer_new_and_alloc (read);
-    data = gst_buffer_map (*outbuf, NULL, NULL, GST_MAP_READWRITE);
+    gst_buffer_map (*outbuf, &map, GST_MAP_READWRITE);
     rret =
-        g_socket_receive (src->socket, (gchar *) data, read,
+        g_socket_receive (src->socket, (gchar *) map.data, read,
         src->cancellable, &err);
   } else {
     /* Connection closed */
     *outbuf = NULL;
+    read = 0;
     rret = 0;
   }
 
@@ -238,25 +239,26 @@ gst_tcp_client_src_create (GstPushSrc * psrc, GstBuffer ** outbuf)
     GST_DEBUG_OBJECT (src, "Connection closed");
     ret = GST_FLOW_EOS;
     if (*outbuf) {
-      gst_buffer_unmap (*outbuf, data, read);
+      gst_buffer_unmap (*outbuf, &map);
       gst_buffer_unref (*outbuf);
     }
     *outbuf = NULL;
   } else if (rret < 0) {
     if (g_error_matches (err, G_IO_ERROR, G_IO_ERROR_CANCELLED)) {
-      ret = GST_FLOW_WRONG_STATE;
+      ret = GST_FLOW_FLUSHING;
       GST_DEBUG_OBJECT (src, "Cancelled reading from socket");
     } else {
       ret = GST_FLOW_ERROR;
       GST_ELEMENT_ERROR (src, RESOURCE, READ, (NULL),
           ("Failed to read from socket: %s", err->message));
     }
-    gst_buffer_unmap (*outbuf, data, read);
+    gst_buffer_unmap (*outbuf, &map);
     gst_buffer_unref (*outbuf);
     *outbuf = NULL;
   } else {
     ret = GST_FLOW_OK;
-    gst_buffer_unmap (*outbuf, data, rret);
+    gst_buffer_unmap (*outbuf, &map);
+    gst_buffer_resize (*outbuf, 0, rret);
 
     GST_LOG_OBJECT (src,
         "Returning buffer from _get of size %" G_GSIZE_FORMAT ", ts %"
@@ -288,7 +290,7 @@ get_available_error:
 wrong_state:
   {
     GST_DEBUG_OBJECT (src, "connection to closed, cannot read data");
-    return GST_FLOW_WRONG_STATE;
+    return GST_FLOW_FLUSHING;
   }
 }