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