Merge branch 'plugin-move-rtp-opus'
[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_pad_template (gstelement_class,
114       gst_static_pad_template_get (&gst_rtp_vraw_pay_src_template));
115   gst_element_class_add_pad_template (gstelement_class,
116       gst_static_pad_template_get (&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   gst_video_frame_map (&frame, &rtpvrawpay->vinfo, buffer, GST_MAP_READ);
288
289   GST_LOG_OBJECT (rtpvrawpay, "new frame of %" G_GSIZE_FORMAT " bytes",
290       gst_buffer_get_size (buffer));
291
292   /* get pointer and strides of the planes */
293   p0 = GST_VIDEO_FRAME_PLANE_DATA (&frame, 0);
294   yp = GST_VIDEO_FRAME_COMP_DATA (&frame, 0);
295   up = GST_VIDEO_FRAME_COMP_DATA (&frame, 1);
296   vp = GST_VIDEO_FRAME_COMP_DATA (&frame, 2);
297
298   ystride = GST_VIDEO_FRAME_COMP_STRIDE (&frame, 0);
299   uvstride = GST_VIDEO_FRAME_COMP_STRIDE (&frame, 1);
300
301   mtu = GST_RTP_BASE_PAYLOAD_MTU (payload);
302
303   /* amount of bytes for one pixel */
304   pgroup = rtpvrawpay->pgroup;
305   width = GST_VIDEO_INFO_WIDTH (&rtpvrawpay->vinfo);
306   height = GST_VIDEO_INFO_HEIGHT (&rtpvrawpay->vinfo);
307
308   interlaced = GST_VIDEO_INFO_IS_INTERLACED (&rtpvrawpay->vinfo);
309
310   format = GST_VIDEO_INFO_FORMAT (&rtpvrawpay->vinfo);
311
312   yinc = rtpvrawpay->yinc;
313   xinc = rtpvrawpay->xinc;
314
315   /* after how many packed lines we push out a buffer list */
316   lines_delay = GST_ROUND_UP_4 (height / rtpvrawpay->chunks_per_frame);
317
318   /* calculate how many buffers we expect to store in a single buffer list */
319   pgroups_per_packet = (mtu - (12 + 14)) / pgroup;
320   packets_per_packline = width / (xinc * pgroups_per_packet * 1.0);
321   packlines_per_list = height / (yinc * rtpvrawpay->chunks_per_frame);
322   buffers_per_list = packlines_per_list * packets_per_packline;
323   buffers_per_list = GST_ROUND_UP_8 (buffers_per_list);
324
325   use_buffer_lists = (rtpvrawpay->chunks_per_frame < (height / yinc));
326
327   fields = 1 + interlaced;
328
329   /* start with line 0, offset 0 */
330   for (field = 0; field < fields; field++) {
331     line = field;
332     offset = 0;
333     last_line = 0;
334
335     if (use_buffer_lists)
336       list = gst_buffer_list_new_sized (buffers_per_list);
337
338     /* write all lines */
339     while (line < height) {
340       guint left, pack_line;
341       GstBuffer *out;
342       guint8 *outdata, *headers;
343       gboolean next_line, complete = FALSE;
344       guint length, cont, pixels;
345
346       /* get the max allowed payload length size, we try to fill the complete MTU */
347       left = gst_rtp_buffer_calc_payload_len (mtu, 0, 0);
348       out = gst_rtp_buffer_new_allocate (left, 0, 0);
349
350       if (field == 0) {
351         GST_BUFFER_PTS (out) = GST_BUFFER_PTS (buffer);
352       } else {
353         GST_BUFFER_PTS (out) = GST_BUFFER_PTS (buffer) +
354             GST_BUFFER_DURATION (buffer) / 2;
355       }
356
357       gst_rtp_buffer_map (out, GST_MAP_WRITE, &rtp);
358       outdata = gst_rtp_buffer_get_payload (&rtp);
359
360       GST_LOG_OBJECT (rtpvrawpay, "created buffer of size %u for MTU %u", left,
361           mtu);
362
363       /*
364        *   0                   1                   2                   3
365        *   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
366        *  +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
367        *  |   Extended Sequence Number    |            Length             |
368        *  +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
369        *  |F|          Line No            |C|           Offset            |
370        *  +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
371        *  |            Length             |F|          Line No            |
372        *  +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
373        *  |C|           Offset            |                               .
374        *  +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+                               .
375        *  .                                                               .
376        *  .                 Two (partial) lines of video data             .
377        *  .                                                               .
378        *  +---------------------------------------------------------------+
379        */
380
381       /* need 2 bytes for the extended sequence number */
382       *outdata++ = 0;
383       *outdata++ = 0;
384       left -= 2;
385
386       /* the headers start here */
387       headers = outdata;
388
389       /* make sure we can fit at least *one* header and pixel */
390       if (!(left > (6 + pgroup))) {
391         gst_rtp_buffer_unmap (&rtp);
392         gst_buffer_unref (out);
393         goto too_small;
394       }
395
396       /* while we can fit at least one header and one pixel */
397       while (left > (6 + pgroup)) {
398         /* we need a 6 bytes header */
399         left -= 6;
400
401         /* get how may bytes we need for the remaining pixels */
402         pixels = width - offset;
403         length = (pixels * pgroup) / xinc;
404
405         if (left >= length) {
406           /* pixels and header fit completely, we will write them and skip to the
407            * next line. */
408           next_line = TRUE;
409         } else {
410           /* line does not fit completely, see how many pixels fit */
411           pixels = (left / pgroup) * xinc;
412           length = (pixels * pgroup) / xinc;
413           next_line = FALSE;
414         }
415         GST_LOG_OBJECT (rtpvrawpay, "filling %u bytes in %u pixels", length,
416             pixels);
417         left -= length;
418
419         /* write length */
420         *outdata++ = (length >> 8) & 0xff;
421         *outdata++ = length & 0xff;
422
423         /* write line no */
424         *outdata++ = ((line >> 8) & 0x7f) | ((field << 7) & 0x80);
425         *outdata++ = line & 0xff;
426
427         if (next_line) {
428           /* go to next line we do this here to make the check below easier */
429           line += yinc;
430         }
431
432         /* calculate continuation marker */
433         cont = (left > (6 + pgroup) && line < height) ? 0x80 : 0x00;
434
435         /* write offset and continuation marker */
436         *outdata++ = ((offset >> 8) & 0x7f) | cont;
437         *outdata++ = offset & 0xff;
438
439         if (next_line) {
440           /* reset offset */
441           offset = 0;
442           GST_LOG_OBJECT (rtpvrawpay, "go to next line %u", line);
443         } else {
444           offset += pixels;
445           GST_LOG_OBJECT (rtpvrawpay, "next offset %u", offset);
446         }
447
448         if (!cont)
449           break;
450       }
451       GST_LOG_OBJECT (rtpvrawpay, "consumed %u bytes",
452           (guint) (outdata - headers));
453
454       /* second pass, read headers and write the data */
455       while (TRUE) {
456         guint offs, lin;
457
458         /* read length and cont */
459         length = (headers[0] << 8) | headers[1];
460         lin = ((headers[2] & 0x7f) << 8) | headers[3];
461         offs = ((headers[4] & 0x7f) << 8) | headers[5];
462         cont = headers[4] & 0x80;
463         pixels = length / pgroup;
464         headers += 6;
465
466         GST_LOG_OBJECT (payload,
467             "writing length %u, line %u, offset %u, cont %d", length, lin, offs,
468             cont);
469
470         switch (format) {
471           case GST_VIDEO_FORMAT_RGB:
472           case GST_VIDEO_FORMAT_RGBA:
473           case GST_VIDEO_FORMAT_BGR:
474           case GST_VIDEO_FORMAT_BGRA:
475           case GST_VIDEO_FORMAT_UYVY:
476           case GST_VIDEO_FORMAT_UYVP:
477             offs /= xinc;
478             memcpy (outdata, p0 + (lin * ystride) + (offs * pgroup), length);
479             outdata += length;
480             break;
481           case GST_VIDEO_FORMAT_AYUV:
482           {
483             gint i;
484             guint8 *datap;
485
486             datap = p0 + (lin * ystride) + (offs * 4);
487
488             for (i = 0; i < pixels; i++) {
489               *outdata++ = datap[2];
490               *outdata++ = datap[1];
491               *outdata++ = datap[3];
492               datap += 4;
493             }
494             break;
495           }
496           case GST_VIDEO_FORMAT_I420:
497           {
498             gint i;
499             guint uvoff;
500             guint8 *yd1p, *yd2p, *udp, *vdp;
501
502             yd1p = yp + (lin * ystride) + (offs);
503             yd2p = yd1p + ystride;
504             uvoff = (lin / yinc * uvstride) + (offs / xinc);
505             udp = up + uvoff;
506             vdp = vp + uvoff;
507
508             for (i = 0; i < pixels; i++) {
509               *outdata++ = *yd1p++;
510               *outdata++ = *yd1p++;
511               *outdata++ = *yd2p++;
512               *outdata++ = *yd2p++;
513               *outdata++ = *udp++;
514               *outdata++ = *vdp++;
515             }
516             break;
517           }
518           case GST_VIDEO_FORMAT_Y41B:
519           {
520             gint i;
521             guint uvoff;
522             guint8 *ydp, *udp, *vdp;
523
524             ydp = yp + (lin * ystride) + offs;
525             uvoff = (lin / yinc * uvstride) + (offs / xinc);
526             udp = up + uvoff;
527             vdp = vp + uvoff;
528
529             for (i = 0; i < pixels; i++) {
530               *outdata++ = *udp++;
531               *outdata++ = *ydp++;
532               *outdata++ = *ydp++;
533               *outdata++ = *vdp++;
534               *outdata++ = *ydp++;
535               *outdata++ = *ydp++;
536             }
537             break;
538           }
539           default:
540             gst_rtp_buffer_unmap (&rtp);
541             gst_buffer_unref (out);
542             goto unknown_sampling;
543         }
544
545         if (!cont)
546           break;
547       }
548
549       if (line >= height) {
550         GST_LOG_OBJECT (rtpvrawpay, "field/frame complete, set marker");
551         gst_rtp_buffer_set_marker (&rtp, TRUE);
552         complete = TRUE;
553       }
554       gst_rtp_buffer_unmap (&rtp);
555       if (left > 0) {
556         GST_LOG_OBJECT (rtpvrawpay, "we have %u bytes left", left);
557         gst_buffer_resize (out, 0, gst_buffer_get_size (out) - left);
558       }
559
560       gst_rtp_copy_meta (GST_ELEMENT_CAST (rtpvrawpay), out, buffer,
561           g_quark_from_static_string (GST_META_TAG_VIDEO_STR));
562
563
564       /* Now either push out the buffer directly */
565       if (!use_buffer_lists) {
566         ret = gst_rtp_base_payload_push (payload, out);
567         continue;
568       }
569
570       /* or add the buffer to buffer list ... */
571       gst_buffer_list_add (list, out);
572
573       /* .. and check if we need to push out the list */
574       pack_line = (line - field) / fields;
575       if (complete || (pack_line > last_line && pack_line % lines_delay == 0)) {
576         GST_LOG_OBJECT (rtpvrawpay, "pushing list of %u buffers up to pack "
577             "line %u", gst_buffer_list_length (list), pack_line);
578         ret = gst_rtp_base_payload_push_list (payload, list);
579         list = NULL;
580         if (!complete)
581           list = gst_buffer_list_new_sized (buffers_per_list);
582         last_line = pack_line;
583       }
584     }
585
586   }
587
588   gst_video_frame_unmap (&frame);
589   gst_buffer_unref (buffer);
590
591   return ret;
592
593   /* ERRORS */
594 unknown_sampling:
595   {
596     GST_ELEMENT_ERROR (payload, STREAM, FORMAT,
597         (NULL), ("unimplemented sampling"));
598     gst_video_frame_unmap (&frame);
599     gst_buffer_unref (buffer);
600     return GST_FLOW_NOT_SUPPORTED;
601   }
602 too_small:
603   {
604     GST_ELEMENT_ERROR (payload, RESOURCE, NO_SPACE_LEFT,
605         (NULL), ("not enough space to send at least one pixel"));
606     gst_video_frame_unmap (&frame);
607     gst_buffer_unref (buffer);
608     return GST_FLOW_NOT_SUPPORTED;
609   }
610 }
611
612 static void
613 gst_rtp_vraw_pay_set_property (GObject * object, guint prop_id,
614     const GValue * value, GParamSpec * pspec)
615 {
616   GstRtpVRawPay *rtpvrawpay;
617
618   rtpvrawpay = GST_RTP_VRAW_PAY (object);
619
620   switch (prop_id) {
621     case PROP_CHUNKS_PER_FRAME:
622       rtpvrawpay->chunks_per_frame = g_value_get_int (value);
623       break;
624     default:
625       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
626       break;
627   }
628 }
629
630 static void
631 gst_rtp_vraw_pay_get_property (GObject * object, guint prop_id,
632     GValue * value, GParamSpec * pspec)
633 {
634   GstRtpVRawPay *rtpvrawpay;
635
636   rtpvrawpay = GST_RTP_VRAW_PAY (object);
637
638   switch (prop_id) {
639     case PROP_CHUNKS_PER_FRAME:
640       g_value_set_int (value, rtpvrawpay->chunks_per_frame);
641       break;
642     default:
643       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
644       break;
645   }
646 }
647
648 gboolean
649 gst_rtp_vraw_pay_plugin_init (GstPlugin * plugin)
650 {
651   return gst_element_register (plugin, "rtpvrawpay",
652       GST_RANK_SECONDARY, GST_TYPE_RTP_VRAW_PAY);
653 }