9368936b145baf2ba0b923247c6a3cc58c48d70b
[platform/upstream/gst-plugins-good.git] / gst / rtp / gstrtpvrawpay.c
1 /* GStreamer
2  * Copyright (C) <2008> Wim Taymans <wim.taymans@gmail.com>
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Library General Public
6  * License as published by the Free Software Foundation; either
7  * version 2 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * Library General Public License for more details.
13  *
14  * You should have received a copy of the GNU Library General Public
15  * License along with this library; if not, write to the
16  * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
17  * Boston, MA 02110-1301, USA.
18  */
19
20 #ifdef HAVE_CONFIG_H
21 #  include "config.h"
22 #endif
23
24 #include <string.h>
25
26 #include <gst/rtp/gstrtpbuffer.h>
27 #include <gst/video/video.h>
28
29 #include "gstrtpvrawpay.h"
30 #include "gstrtputils.h"
31
32 enum
33 {
34   PROP_CHUNKS_PER_FRAME = 1
35 };
36
37 #define DEFAULT_CHUNKS_PER_FRAME 10
38
39 GST_DEBUG_CATEGORY_STATIC (rtpvrawpay_debug);
40 #define GST_CAT_DEFAULT (rtpvrawpay_debug)
41
42 static GstStaticPadTemplate gst_rtp_vraw_pay_sink_template =
43     GST_STATIC_PAD_TEMPLATE ("sink",
44     GST_PAD_SINK,
45     GST_PAD_ALWAYS,
46     GST_STATIC_CAPS ("video/x-raw, "
47         "format = (string) { RGB, RGBA, BGR, BGRA, AYUV, UYVY, I420, Y41B, UYVP }, "
48         "width = (int) [ 1, 32767 ], " "height = (int) [ 1, 32767 ]; ")
49     );
50
51 static GstStaticPadTemplate gst_rtp_vraw_pay_src_template =
52 GST_STATIC_PAD_TEMPLATE ("src",
53     GST_PAD_SRC,
54     GST_PAD_ALWAYS,
55     GST_STATIC_CAPS ("application/x-rtp, "
56         "media = (string) \"video\", "
57         "payload = (int) " GST_RTP_PAYLOAD_DYNAMIC_STRING ", "
58         "clock-rate = (int) 90000, "
59         "encoding-name = (string) \"RAW\","
60         "sampling = (string) { \"RGB\", \"RGBA\", \"BGR\", \"BGRA\", "
61         "\"YCbCr-4:4:4\", \"YCbCr-4:2:2\", \"YCbCr-4:2:0\", "
62         "\"YCbCr-4:1:1\" },"
63         /* we cannot express these as strings 
64          * "width = (string) [1 32767],"
65          * "height = (string) [1 32767],"
66          */
67         "depth = (string) { \"8\", \"10\", \"12\", \"16\" },"
68         "colorimetry = (string) { \"BT601-5\", \"BT709-2\", \"SMPTE240M\" }"
69         /* optional 
70          * interlace = 
71          * top-field-first = 
72          * chroma-position = (string) 
73          * gamma = (float)
74          */
75     )
76     );
77
78 static gboolean gst_rtp_vraw_pay_setcaps (GstRTPBasePayload * payload,
79     GstCaps * caps);
80 static GstFlowReturn gst_rtp_vraw_pay_handle_buffer (GstRTPBasePayload *
81     payload, GstBuffer * buffer);
82 static void gst_rtp_vraw_pay_get_property (GObject * object, guint prop_id,
83     GValue * value, GParamSpec * pspec);
84 static void gst_rtp_vraw_pay_set_property (GObject * object, guint prop_id,
85     const GValue * value, GParamSpec * pspec);
86
87 G_DEFINE_TYPE (GstRtpVRawPay, gst_rtp_vraw_pay, GST_TYPE_RTP_BASE_PAYLOAD)
88
89      static void gst_rtp_vraw_pay_class_init (GstRtpVRawPayClass * klass)
90 {
91   GstRTPBasePayloadClass *gstrtpbasepayload_class;
92   GstElementClass *gstelement_class;
93   GObjectClass *gobject_class;
94
95   gobject_class = (GObjectClass *) klass;
96   gstelement_class = (GstElementClass *) klass;
97   gstrtpbasepayload_class = (GstRTPBasePayloadClass *) klass;
98
99   gobject_class->set_property = gst_rtp_vraw_pay_set_property;
100   gobject_class->get_property = gst_rtp_vraw_pay_get_property;
101
102   g_object_class_install_property (gobject_class,
103       PROP_CHUNKS_PER_FRAME,
104       g_param_spec_int ("chunks-per-frame", "Chunks per Frame",
105           "Split and send out each frame in multiple chunks to reduce overhead",
106           1, G_MAXINT, DEFAULT_CHUNKS_PER_FRAME,
107           G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)
108       );
109
110   gstrtpbasepayload_class->set_caps = gst_rtp_vraw_pay_setcaps;
111   gstrtpbasepayload_class->handle_buffer = gst_rtp_vraw_pay_handle_buffer;
112
113   gst_element_class_add_static_pad_template (gstelement_class,
114       &gst_rtp_vraw_pay_src_template);
115   gst_element_class_add_static_pad_template (gstelement_class,
116       &gst_rtp_vraw_pay_sink_template);
117
118   gst_element_class_set_static_metadata (gstelement_class,
119       "RTP Raw Video payloader", "Codec/Payloader/Network/RTP",
120       "Payload raw video as RTP packets (RFC 4175)",
121       "Wim Taymans <wim.taymans@gmail.com>");
122
123   GST_DEBUG_CATEGORY_INIT (rtpvrawpay_debug, "rtpvrawpay", 0,
124       "Raw video RTP Payloader");
125 }
126
127 static void
128 gst_rtp_vraw_pay_init (GstRtpVRawPay * rtpvrawpay)
129 {
130   rtpvrawpay->chunks_per_frame = DEFAULT_CHUNKS_PER_FRAME;
131 }
132
133 static gboolean
134 gst_rtp_vraw_pay_setcaps (GstRTPBasePayload * payload, GstCaps * caps)
135 {
136   GstRtpVRawPay *rtpvrawpay;
137   gboolean res;
138   gint pgroup, xinc, yinc;
139   const gchar *depthstr, *samplingstr, *colorimetrystr;
140   gchar *wstr, *hstr;
141   GstVideoInfo info;
142
143   rtpvrawpay = GST_RTP_VRAW_PAY (payload);
144
145   if (!gst_video_info_from_caps (&info, caps))
146     goto invalid_caps;
147
148   rtpvrawpay->vinfo = info;
149
150   if (gst_video_colorimetry_matches (&info.colorimetry,
151           GST_VIDEO_COLORIMETRY_BT601)) {
152     colorimetrystr = "BT601-5";
153   } else if (gst_video_colorimetry_matches (&info.colorimetry,
154           GST_VIDEO_COLORIMETRY_BT709)) {
155     colorimetrystr = "BT709-2";
156   } else if (gst_video_colorimetry_matches (&info.colorimetry,
157           GST_VIDEO_COLORIMETRY_SMPTE240M)) {
158     colorimetrystr = "SMPTE240M";
159   } else {
160     colorimetrystr = "SMPTE240M";
161   }
162
163   xinc = yinc = 1;
164
165   /* these values are the only thing we can do */
166   depthstr = "8";
167
168   switch (GST_VIDEO_INFO_FORMAT (&info)) {
169     case GST_VIDEO_FORMAT_RGBA:
170       samplingstr = "RGBA";
171       pgroup = 4;
172       break;
173     case GST_VIDEO_FORMAT_BGRA:
174       samplingstr = "BGRA";
175       pgroup = 4;
176       break;
177     case GST_VIDEO_FORMAT_RGB:
178       samplingstr = "RGB";
179       pgroup = 3;
180       break;
181     case GST_VIDEO_FORMAT_BGR:
182       samplingstr = "BGR";
183       pgroup = 3;
184       break;
185     case GST_VIDEO_FORMAT_AYUV:
186       samplingstr = "YCbCr-4:4:4";
187       pgroup = 3;
188       break;
189     case GST_VIDEO_FORMAT_UYVY:
190       samplingstr = "YCbCr-4:2:2";
191       pgroup = 4;
192       xinc = 2;
193       break;
194     case GST_VIDEO_FORMAT_Y41B:
195       samplingstr = "YCbCr-4:1:1";
196       pgroup = 6;
197       xinc = 4;
198       break;
199     case GST_VIDEO_FORMAT_I420:
200       samplingstr = "YCbCr-4:2:0";
201       pgroup = 6;
202       xinc = yinc = 2;
203       break;
204     case GST_VIDEO_FORMAT_UYVP:
205       samplingstr = "YCbCr-4:2:2";
206       pgroup = 5;
207       xinc = 2;
208       depthstr = "10";
209       break;
210     default:
211       goto unknown_format;
212       break;
213   }
214
215   if (GST_VIDEO_INFO_IS_INTERLACED (&info)) {
216     yinc *= 2;
217   }
218
219   rtpvrawpay->pgroup = pgroup;
220   rtpvrawpay->xinc = xinc;
221   rtpvrawpay->yinc = yinc;
222
223   GST_DEBUG_OBJECT (payload, "width %d, height %d, sampling %s",
224       GST_VIDEO_INFO_WIDTH (&info), GST_VIDEO_INFO_HEIGHT (&info), samplingstr);
225   GST_DEBUG_OBJECT (payload, "xinc %d, yinc %d, pgroup %d", xinc, yinc, pgroup);
226
227   wstr = g_strdup_printf ("%d", GST_VIDEO_INFO_WIDTH (&info));
228   hstr = g_strdup_printf ("%d", GST_VIDEO_INFO_HEIGHT (&info));
229
230   gst_rtp_base_payload_set_options (payload, "video", TRUE, "RAW", 90000);
231   if (GST_VIDEO_INFO_IS_INTERLACED (&info)) {
232     res = gst_rtp_base_payload_set_outcaps (payload, "sampling", G_TYPE_STRING,
233         samplingstr, "depth", G_TYPE_STRING, depthstr, "width", G_TYPE_STRING,
234         wstr, "height", G_TYPE_STRING, hstr, "colorimetry", G_TYPE_STRING,
235         colorimetrystr, "interlace", G_TYPE_STRING, "true", NULL);
236   } else {
237     res = gst_rtp_base_payload_set_outcaps (payload, "sampling", G_TYPE_STRING,
238         samplingstr, "depth", G_TYPE_STRING, depthstr, "width", G_TYPE_STRING,
239         wstr, "height", G_TYPE_STRING, hstr, "colorimetry", G_TYPE_STRING,
240         colorimetrystr, NULL);
241   }
242   g_free (wstr);
243   g_free (hstr);
244
245   return res;
246
247   /* ERRORS */
248 invalid_caps:
249   {
250     GST_ERROR_OBJECT (payload, "could not parse caps");
251     return FALSE;
252   }
253 unknown_format:
254   {
255     GST_ERROR_OBJECT (payload, "unknown caps format");
256     return FALSE;
257   }
258 }
259
260 static GstFlowReturn
261 gst_rtp_vraw_pay_handle_buffer (GstRTPBasePayload * payload, GstBuffer * buffer)
262 {
263   GstRtpVRawPay *rtpvrawpay;
264   GstFlowReturn ret = GST_FLOW_OK;
265   gfloat packets_per_packline;
266   guint pgroups_per_packet;
267   guint packlines_per_list, buffers_per_list;
268   guint lines_delay;            /* after how many packed lines we push out a buffer list */
269   guint last_line;              /* last pack line number we pushed out a buffer list     */
270   guint line, offset;
271   guint8 *p0, *yp, *up, *vp;
272   guint ystride, uvstride;
273   guint xinc, yinc;
274   guint pgroup;
275   guint mtu;
276   guint width, height;
277   gint field, fields;
278   GstVideoFormat format;
279   GstVideoFrame frame;
280   gint interlaced;
281   gboolean use_buffer_lists;
282   GstBufferList *list = NULL;
283   GstRTPBuffer rtp = { NULL, };
284
285   rtpvrawpay = GST_RTP_VRAW_PAY (payload);
286
287   if (!gst_video_frame_map (&frame, &rtpvrawpay->vinfo, buffer, GST_MAP_READ)) {
288     gst_buffer_unref (buffer);
289     return GST_FLOW_ERROR;
290   }
291
292   GST_LOG_OBJECT (rtpvrawpay, "new frame of %" G_GSIZE_FORMAT " bytes",
293       gst_buffer_get_size (buffer));
294
295   /* get pointer and strides of the planes */
296   p0 = GST_VIDEO_FRAME_PLANE_DATA (&frame, 0);
297   yp = GST_VIDEO_FRAME_COMP_DATA (&frame, 0);
298   up = GST_VIDEO_FRAME_COMP_DATA (&frame, 1);
299   vp = GST_VIDEO_FRAME_COMP_DATA (&frame, 2);
300
301   ystride = GST_VIDEO_FRAME_COMP_STRIDE (&frame, 0);
302   uvstride = GST_VIDEO_FRAME_COMP_STRIDE (&frame, 1);
303
304   mtu = GST_RTP_BASE_PAYLOAD_MTU (payload);
305
306   /* amount of bytes for one pixel */
307   pgroup = rtpvrawpay->pgroup;
308   width = GST_VIDEO_INFO_WIDTH (&rtpvrawpay->vinfo);
309   height = GST_VIDEO_INFO_HEIGHT (&rtpvrawpay->vinfo);
310
311   interlaced = GST_VIDEO_INFO_IS_INTERLACED (&rtpvrawpay->vinfo);
312
313   format = GST_VIDEO_INFO_FORMAT (&rtpvrawpay->vinfo);
314
315   yinc = rtpvrawpay->yinc;
316   xinc = rtpvrawpay->xinc;
317
318   /* after how many packed lines we push out a buffer list */
319   lines_delay = GST_ROUND_UP_4 (height / rtpvrawpay->chunks_per_frame);
320
321   /* calculate how many buffers we expect to store in a single buffer list */
322   pgroups_per_packet = (mtu - (12 + 14)) / pgroup;
323   packets_per_packline = width / (xinc * pgroups_per_packet * 1.0);
324   packlines_per_list = height / (yinc * rtpvrawpay->chunks_per_frame);
325   buffers_per_list = packlines_per_list * packets_per_packline;
326   buffers_per_list = GST_ROUND_UP_8 (buffers_per_list);
327
328   use_buffer_lists = (rtpvrawpay->chunks_per_frame < (height / yinc));
329
330   fields = 1 + interlaced;
331
332   /* start with line 0, offset 0 */
333   for (field = 0; field < fields; field++) {
334     line = field;
335     offset = 0;
336     last_line = 0;
337
338     if (use_buffer_lists)
339       list = gst_buffer_list_new_sized (buffers_per_list);
340
341     /* write all lines */
342     while (line < height) {
343       guint left, pack_line;
344       GstBuffer *out;
345       guint8 *outdata, *headers;
346       gboolean next_line, complete = FALSE;
347       guint length, cont, pixels;
348
349       /* get the max allowed payload length size, we try to fill the complete MTU */
350       left = gst_rtp_buffer_calc_payload_len (mtu, 0, 0);
351       out = gst_rtp_buffer_new_allocate (left, 0, 0);
352
353       if (field == 0) {
354         GST_BUFFER_PTS (out) = GST_BUFFER_PTS (buffer);
355       } else {
356         GST_BUFFER_PTS (out) = GST_BUFFER_PTS (buffer) +
357             GST_BUFFER_DURATION (buffer) / 2;
358       }
359
360       gst_rtp_buffer_map (out, GST_MAP_WRITE, &rtp);
361       outdata = gst_rtp_buffer_get_payload (&rtp);
362
363       GST_LOG_OBJECT (rtpvrawpay, "created buffer of size %u for MTU %u", left,
364           mtu);
365
366       /*
367        *   0                   1                   2                   3
368        *   0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
369        *  +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
370        *  |   Extended Sequence Number    |            Length             |
371        *  +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
372        *  |F|          Line No            |C|           Offset            |
373        *  +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
374        *  |            Length             |F|          Line No            |
375        *  +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
376        *  |C|           Offset            |                               .
377        *  +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+                               .
378        *  .                                                               .
379        *  .                 Two (partial) lines of video data             .
380        *  .                                                               .
381        *  +---------------------------------------------------------------+
382        */
383
384       /* need 2 bytes for the extended sequence number */
385       *outdata++ = 0;
386       *outdata++ = 0;
387       left -= 2;
388
389       /* the headers start here */
390       headers = outdata;
391
392       /* make sure we can fit at least *one* header and pixel */
393       if (!(left > (6 + pgroup))) {
394         gst_rtp_buffer_unmap (&rtp);
395         gst_buffer_unref (out);
396         goto too_small;
397       }
398
399       /* while we can fit at least one header and one pixel */
400       while (left > (6 + pgroup)) {
401         /* we need a 6 bytes header */
402         left -= 6;
403
404         /* get how may bytes we need for the remaining pixels */
405         pixels = width - offset;
406         length = (pixels * pgroup) / xinc;
407
408         if (left >= length) {
409           /* pixels and header fit completely, we will write them and skip to the
410            * next line. */
411           next_line = TRUE;
412         } else {
413           /* line does not fit completely, see how many pixels fit */
414           pixels = (left / pgroup) * xinc;
415           length = (pixels * pgroup) / xinc;
416           next_line = FALSE;
417         }
418         GST_LOG_OBJECT (rtpvrawpay, "filling %u bytes in %u pixels", length,
419             pixels);
420         left -= length;
421
422         /* write length */
423         *outdata++ = (length >> 8) & 0xff;
424         *outdata++ = length & 0xff;
425
426         /* write line no */
427         *outdata++ = ((line >> 8) & 0x7f) | ((field << 7) & 0x80);
428         *outdata++ = line & 0xff;
429
430         if (next_line) {
431           /* go to next line we do this here to make the check below easier */
432           line += yinc;
433         }
434
435         /* calculate continuation marker */
436         cont = (left > (6 + pgroup) && line < height) ? 0x80 : 0x00;
437
438         /* write offset and continuation marker */
439         *outdata++ = ((offset >> 8) & 0x7f) | cont;
440         *outdata++ = offset & 0xff;
441
442         if (next_line) {
443           /* reset offset */
444           offset = 0;
445           GST_LOG_OBJECT (rtpvrawpay, "go to next line %u", line);
446         } else {
447           offset += pixels;
448           GST_LOG_OBJECT (rtpvrawpay, "next offset %u", offset);
449         }
450
451         if (!cont)
452           break;
453       }
454       GST_LOG_OBJECT (rtpvrawpay, "consumed %u bytes",
455           (guint) (outdata - headers));
456
457       /* second pass, read headers and write the data */
458       while (TRUE) {
459         guint offs, lin;
460
461         /* read length and cont */
462         length = (headers[0] << 8) | headers[1];
463         lin = ((headers[2] & 0x7f) << 8) | headers[3];
464         offs = ((headers[4] & 0x7f) << 8) | headers[5];
465         cont = headers[4] & 0x80;
466         pixels = length / pgroup;
467         headers += 6;
468
469         GST_LOG_OBJECT (payload,
470             "writing length %u, line %u, offset %u, cont %d", length, lin, offs,
471             cont);
472
473         switch (format) {
474           case GST_VIDEO_FORMAT_RGB:
475           case GST_VIDEO_FORMAT_RGBA:
476           case GST_VIDEO_FORMAT_BGR:
477           case GST_VIDEO_FORMAT_BGRA:
478           case GST_VIDEO_FORMAT_UYVY:
479           case GST_VIDEO_FORMAT_UYVP:
480             offs /= xinc;
481             memcpy (outdata, p0 + (lin * ystride) + (offs * pgroup), length);
482             outdata += length;
483             break;
484           case GST_VIDEO_FORMAT_AYUV:
485           {
486             gint i;
487             guint8 *datap;
488
489             datap = p0 + (lin * ystride) + (offs * 4);
490
491             for (i = 0; i < pixels; i++) {
492               *outdata++ = datap[2];
493               *outdata++ = datap[1];
494               *outdata++ = datap[3];
495               datap += 4;
496             }
497             break;
498           }
499           case GST_VIDEO_FORMAT_I420:
500           {
501             gint i;
502             guint uvoff;
503             guint8 *yd1p, *yd2p, *udp, *vdp;
504
505             yd1p = yp + (lin * ystride) + (offs);
506             yd2p = yd1p + ystride;
507             uvoff = (lin / yinc * uvstride) + (offs / xinc);
508             udp = up + uvoff;
509             vdp = vp + uvoff;
510
511             for (i = 0; i < pixels; i++) {
512               *outdata++ = *yd1p++;
513               *outdata++ = *yd1p++;
514               *outdata++ = *yd2p++;
515               *outdata++ = *yd2p++;
516               *outdata++ = *udp++;
517               *outdata++ = *vdp++;
518             }
519             break;
520           }
521           case GST_VIDEO_FORMAT_Y41B:
522           {
523             gint i;
524             guint uvoff;
525             guint8 *ydp, *udp, *vdp;
526
527             ydp = yp + (lin * ystride) + offs;
528             uvoff = (lin / yinc * uvstride) + (offs / xinc);
529             udp = up + uvoff;
530             vdp = vp + uvoff;
531
532             for (i = 0; i < pixels; i++) {
533               *outdata++ = *udp++;
534               *outdata++ = *ydp++;
535               *outdata++ = *ydp++;
536               *outdata++ = *vdp++;
537               *outdata++ = *ydp++;
538               *outdata++ = *ydp++;
539             }
540             break;
541           }
542           default:
543             gst_rtp_buffer_unmap (&rtp);
544             gst_buffer_unref (out);
545             goto unknown_sampling;
546         }
547
548         if (!cont)
549           break;
550       }
551
552       if (line >= height) {
553         GST_LOG_OBJECT (rtpvrawpay, "field/frame complete, set marker");
554         gst_rtp_buffer_set_marker (&rtp, TRUE);
555         complete = TRUE;
556       }
557       gst_rtp_buffer_unmap (&rtp);
558       if (left > 0) {
559         GST_LOG_OBJECT (rtpvrawpay, "we have %u bytes left", left);
560         gst_buffer_resize (out, 0, gst_buffer_get_size (out) - left);
561       }
562
563       gst_rtp_copy_meta (GST_ELEMENT_CAST (rtpvrawpay), out, buffer,
564           g_quark_from_static_string (GST_META_TAG_VIDEO_STR));
565
566
567       /* Now either push out the buffer directly */
568       if (!use_buffer_lists) {
569         ret = gst_rtp_base_payload_push (payload, out);
570         continue;
571       }
572
573       /* or add the buffer to buffer list ... */
574       gst_buffer_list_add (list, out);
575
576       /* .. and check if we need to push out the list */
577       pack_line = (line - field) / fields;
578       if (complete || (pack_line > last_line && pack_line % lines_delay == 0)) {
579         GST_LOG_OBJECT (rtpvrawpay, "pushing list of %u buffers up to pack "
580             "line %u", gst_buffer_list_length (list), pack_line);
581         ret = gst_rtp_base_payload_push_list (payload, list);
582         list = NULL;
583         if (!complete)
584           list = gst_buffer_list_new_sized (buffers_per_list);
585         last_line = pack_line;
586       }
587     }
588
589   }
590
591   gst_video_frame_unmap (&frame);
592   gst_buffer_unref (buffer);
593
594   return ret;
595
596   /* ERRORS */
597 unknown_sampling:
598   {
599     GST_ELEMENT_ERROR (payload, STREAM, FORMAT,
600         (NULL), ("unimplemented sampling"));
601     gst_video_frame_unmap (&frame);
602     gst_buffer_unref (buffer);
603     return GST_FLOW_NOT_SUPPORTED;
604   }
605 too_small:
606   {
607     GST_ELEMENT_ERROR (payload, RESOURCE, NO_SPACE_LEFT,
608         (NULL), ("not enough space to send at least one pixel"));
609     gst_video_frame_unmap (&frame);
610     gst_buffer_unref (buffer);
611     return GST_FLOW_NOT_SUPPORTED;
612   }
613 }
614
615 static void
616 gst_rtp_vraw_pay_set_property (GObject * object, guint prop_id,
617     const GValue * value, GParamSpec * pspec)
618 {
619   GstRtpVRawPay *rtpvrawpay;
620
621   rtpvrawpay = GST_RTP_VRAW_PAY (object);
622
623   switch (prop_id) {
624     case PROP_CHUNKS_PER_FRAME:
625       rtpvrawpay->chunks_per_frame = g_value_get_int (value);
626       break;
627     default:
628       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
629       break;
630   }
631 }
632
633 static void
634 gst_rtp_vraw_pay_get_property (GObject * object, guint prop_id,
635     GValue * value, GParamSpec * pspec)
636 {
637   GstRtpVRawPay *rtpvrawpay;
638
639   rtpvrawpay = GST_RTP_VRAW_PAY (object);
640
641   switch (prop_id) {
642     case PROP_CHUNKS_PER_FRAME:
643       g_value_set_int (value, rtpvrawpay->chunks_per_frame);
644       break;
645     default:
646       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
647       break;
648   }
649 }
650
651 gboolean
652 gst_rtp_vraw_pay_plugin_init (GstPlugin * plugin)
653 {
654   return gst_element_register (plugin, "rtpvrawpay",
655       GST_RANK_SECONDARY, GST_TYPE_RTP_VRAW_PAY);
656 }