pcapparse: Take buffer directly from the adapter

No need to make a copy into a new buffer, just take the data
from the adapter.
This commit is contained in:
Olivier Crête 2015-04-10 20:25:49 -04:00
parent a2b093af47
commit c4c9fe60b6
2 changed files with 23 additions and 28 deletions

View file

@ -309,7 +309,6 @@ gst_pcap_parse_reset (GstPcapParse * self)
self->initialized = FALSE; self->initialized = FALSE;
self->swap_endian = FALSE; self->swap_endian = FALSE;
self->cur_packet_size = -1; self->cur_packet_size = -1;
self->buffer_offset = 0;
self->cur_ts = GST_CLOCK_TIME_NONE; self->cur_ts = GST_CLOCK_TIME_NONE;
self->base_ts = GST_CLOCK_TIME_NONE; self->base_ts = GST_CLOCK_TIME_NONE;
self->newsegment_sent = FALSE; self->newsegment_sent = FALSE;
@ -480,10 +479,15 @@ gst_pcap_parse_chain (GstPad * pad, GstObject * parent, GstBuffer * buffer)
if (gst_pcap_parse_scan_frame (self, data, self->cur_packet_size, if (gst_pcap_parse_scan_frame (self, data, self->cur_packet_size,
&payload_data, &payload_size)) { &payload_data, &payload_size)) {
GstBuffer *out_buf; GstBuffer *out_buf;
GstMapInfo map; guintptr offset = payload_data - data;
out_buf = gst_buffer_new_and_alloc (payload_size); self->cur_packet_size -= offset;
if (out_buf) { self->cur_packet_size -= payload_size;
gst_adapter_unmap (self->adapter);
gst_adapter_flush (self->adapter, offset);
out_buf = gst_adapter_take_buffer_fast (self->adapter,
payload_size);
if (GST_CLOCK_TIME_IS_VALID (self->cur_ts)) { if (GST_CLOCK_TIME_IS_VALID (self->cur_ts)) {
if (!GST_CLOCK_TIME_IS_VALID (self->base_ts)) if (!GST_CLOCK_TIME_IS_VALID (self->base_ts))
@ -493,24 +497,17 @@ gst_pcap_parse_chain (GstPad * pad, GstObject * parent, GstBuffer * buffer)
self->cur_ts += self->offset; self->cur_ts += self->offset;
} }
} }
gst_buffer_map (out_buf, &map, GST_MAP_WRITE);
memcpy (map.data, payload_data, payload_size);
gst_buffer_unmap (out_buf, &map);
GST_BUFFER_TIMESTAMP (out_buf) = self->cur_ts; GST_BUFFER_TIMESTAMP (out_buf) = self->cur_ts;
if (list == NULL) if (list == NULL)
list = gst_buffer_list_new (); list = gst_buffer_list_new ();
gst_buffer_list_add (list, out_buf); gst_buffer_list_add (list, out_buf);
} else {
self->buffer_offset += payload_size;
}
}
gst_adapter_unmap (self->adapter); gst_adapter_unmap (self->adapter);
gst_adapter_flush (self->adapter, self->cur_packet_size); gst_adapter_flush (self->adapter, self->cur_packet_size);
} }
}
self->cur_packet_size = -1; self->cur_packet_size = -1;
} else { } else {

View file

@ -84,8 +84,6 @@ struct _GstPcapParse
GstPcapParseLinktype linktype; GstPcapParseLinktype linktype;
gboolean newsegment_sent; gboolean newsegment_sent;
gint64 buffer_offset;
}; };
struct _GstPcapParseClass struct _GstPcapParseClass