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