Tizen 2.0 Release
[framework/multimedia/gst-plugins-good0.10.git] / gst / rtp / gstrtpj2kdepay.c
1 /* GStreamer
2  * Copyright (C) <2009> 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., 59 Temple Place - Suite 330,
17  * Boston, MA 02111-1307, USA.
18  */
19
20 #ifdef HAVE_CONFIG_H
21 #  include "config.h"
22 #endif
23
24 #include <gst/rtp/gstrtpbuffer.h>
25
26 #include <string.h>
27 #include "gstrtpj2kdepay.h"
28
29 GST_DEBUG_CATEGORY_STATIC (rtpj2kdepay_debug);
30 #define GST_CAT_DEFAULT (rtpj2kdepay_debug)
31
32 static GstStaticPadTemplate gst_rtp_j2k_depay_src_template =
33 GST_STATIC_PAD_TEMPLATE ("src",
34     GST_PAD_SRC,
35     GST_PAD_ALWAYS,
36     GST_STATIC_CAPS ("image/x-jpc")
37     );
38
39 static GstStaticPadTemplate gst_rtp_j2k_depay_sink_template =
40 GST_STATIC_PAD_TEMPLATE ("sink",
41     GST_PAD_SINK,
42     GST_PAD_ALWAYS,
43     GST_STATIC_CAPS ("application/x-rtp, "
44         "media = (string) \"video\", "
45         "payload = (int) " GST_RTP_PAYLOAD_DYNAMIC_STRING ", "
46         "clock-rate = (int) 90000, " "encoding-name = (string) \"JPEG2000\"")
47     );
48
49 typedef enum
50 {
51   J2K_MARKER = 0xFF,
52   J2K_MARKER_SOC = 0x4F,
53   J2K_MARKER_SOT = 0x90,
54   J2K_MARKER_SOP = 0x91,
55   J2K_MARKER_SOD = 0x93,
56   J2K_MARKER_EOC = 0xD9
57 } RtpJ2KMarker;
58
59 #define DEFAULT_BUFFER_LIST             TRUE
60
61 enum
62 {
63   PROP_0,
64   PROP_BUFFER_LIST,
65   PROP_LAST
66 };
67
68 GST_BOILERPLATE (GstRtpJ2KDepay, gst_rtp_j2k_depay, GstBaseRTPDepayload,
69     GST_TYPE_BASE_RTP_DEPAYLOAD);
70
71 static void gst_rtp_j2k_depay_finalize (GObject * object);
72
73 static void gst_rtp_j2k_depay_set_property (GObject * object, guint prop_id,
74     const GValue * value, GParamSpec * pspec);
75 static void gst_rtp_j2k_depay_get_property (GObject * object, guint prop_id,
76     GValue * value, GParamSpec * pspec);
77
78 static GstStateChangeReturn
79 gst_rtp_j2k_depay_change_state (GstElement * element,
80     GstStateChange transition);
81
82 static gboolean gst_rtp_j2k_depay_setcaps (GstBaseRTPDepayload * depayload,
83     GstCaps * caps);
84 static GstBuffer *gst_rtp_j2k_depay_process (GstBaseRTPDepayload * depayload,
85     GstBuffer * buf);
86
87 static void
88 gst_rtp_j2k_depay_base_init (gpointer klass)
89 {
90   GstElementClass *element_class = GST_ELEMENT_CLASS (klass);
91
92   gst_element_class_add_static_pad_template (element_class,
93       &gst_rtp_j2k_depay_src_template);
94   gst_element_class_add_static_pad_template (element_class,
95       &gst_rtp_j2k_depay_sink_template);
96
97   gst_element_class_set_details_simple (element_class,
98       "RTP JPEG 2000 depayloader", "Codec/Depayloader/Network/RTP",
99       "Extracts JPEG 2000 video from RTP packets (RFC 5371)",
100       "Wim Taymans <wim.taymans@gmail.com>");
101 }
102
103 static void
104 gst_rtp_j2k_depay_class_init (GstRtpJ2KDepayClass * klass)
105 {
106   GObjectClass *gobject_class;
107   GstElementClass *gstelement_class;
108   GstBaseRTPDepayloadClass *gstbasertpdepayload_class;
109
110   gobject_class = (GObjectClass *) klass;
111   gstelement_class = (GstElementClass *) klass;
112   gstbasertpdepayload_class = (GstBaseRTPDepayloadClass *) klass;
113
114   gobject_class->finalize = gst_rtp_j2k_depay_finalize;
115
116   gobject_class->set_property = gst_rtp_j2k_depay_set_property;
117   gobject_class->get_property = gst_rtp_j2k_depay_get_property;
118
119   g_object_class_install_property (G_OBJECT_CLASS (klass), PROP_BUFFER_LIST,
120       g_param_spec_boolean ("buffer-list", "Buffer List",
121           "Use Buffer Lists",
122           DEFAULT_BUFFER_LIST, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
123
124   gstelement_class->change_state = gst_rtp_j2k_depay_change_state;
125
126   gstbasertpdepayload_class->set_caps = gst_rtp_j2k_depay_setcaps;
127   gstbasertpdepayload_class->process = gst_rtp_j2k_depay_process;
128
129   GST_DEBUG_CATEGORY_INIT (rtpj2kdepay_debug, "rtpj2kdepay", 0,
130       "J2K Video RTP Depayloader");
131 }
132
133 static void
134 gst_rtp_j2k_depay_init (GstRtpJ2KDepay * rtpj2kdepay,
135     GstRtpJ2KDepayClass * klass)
136 {
137   rtpj2kdepay->buffer_list = DEFAULT_BUFFER_LIST;
138
139   rtpj2kdepay->pu_adapter = gst_adapter_new ();
140   rtpj2kdepay->t_adapter = gst_adapter_new ();
141   rtpj2kdepay->f_adapter = gst_adapter_new ();
142 }
143
144 static void
145 store_mheader (GstRtpJ2KDepay * rtpj2kdepay, guint idx, GstBuffer * buf)
146 {
147   GstBuffer *old;
148
149   GST_DEBUG_OBJECT (rtpj2kdepay, "storing main header %p at index %u", buf,
150       idx);
151   if ((old = rtpj2kdepay->MH[idx]))
152     gst_buffer_unref (old);
153   rtpj2kdepay->MH[idx] = buf;
154 }
155
156 static void
157 clear_mheaders (GstRtpJ2KDepay * rtpj2kdepay)
158 {
159   guint i;
160
161   for (i = 0; i < 8; i++)
162     store_mheader (rtpj2kdepay, i, NULL);
163 }
164
165 static void
166 gst_rtp_j2k_depay_reset (GstRtpJ2KDepay * rtpj2kdepay)
167 {
168   clear_mheaders (rtpj2kdepay);
169   gst_adapter_clear (rtpj2kdepay->pu_adapter);
170   gst_adapter_clear (rtpj2kdepay->t_adapter);
171   gst_adapter_clear (rtpj2kdepay->f_adapter);
172   rtpj2kdepay->next_frag = 0;
173 }
174
175 static void
176 gst_rtp_j2k_depay_finalize (GObject * object)
177 {
178   GstRtpJ2KDepay *rtpj2kdepay;
179
180   rtpj2kdepay = GST_RTP_J2K_DEPAY (object);
181
182   clear_mheaders (rtpj2kdepay);
183
184   g_object_unref (rtpj2kdepay->pu_adapter);
185   g_object_unref (rtpj2kdepay->t_adapter);
186   g_object_unref (rtpj2kdepay->f_adapter);
187
188   G_OBJECT_CLASS (parent_class)->finalize (object);
189 }
190
191 static gboolean
192 gst_rtp_j2k_depay_setcaps (GstBaseRTPDepayload * depayload, GstCaps * caps)
193 {
194   GstStructure *structure;
195   gint clock_rate;
196   GstCaps *outcaps;
197   gboolean res;
198
199   structure = gst_caps_get_structure (caps, 0);
200
201   if (!gst_structure_get_int (structure, "clock-rate", &clock_rate))
202     clock_rate = 90000;
203   depayload->clock_rate = clock_rate;
204
205   outcaps =
206       gst_caps_new_simple ("image/x-jpc", "framerate", GST_TYPE_FRACTION, 0, 1,
207       "fields", G_TYPE_INT, 1, "fourcc", GST_TYPE_FOURCC, GST_MAKE_FOURCC ('s',
208           'Y', 'U', 'V'), NULL);
209   res = gst_pad_set_caps (depayload->srcpad, outcaps);
210   gst_caps_unref (outcaps);
211
212   return res;
213 }
214
215 static void
216 gst_rtp_j2k_depay_clear_pu (GstRtpJ2KDepay * rtpj2kdepay)
217 {
218   gst_adapter_clear (rtpj2kdepay->pu_adapter);
219   rtpj2kdepay->have_sync = FALSE;
220 }
221
222 static GstFlowReturn
223 gst_rtp_j2k_depay_flush_pu (GstBaseRTPDepayload * depayload)
224 {
225   GstRtpJ2KDepay *rtpj2kdepay;
226   GstBuffer *mheader;
227   guint avail, MHF, mh_id;
228
229   rtpj2kdepay = GST_RTP_J2K_DEPAY (depayload);
230
231   /* take all available buffers */
232   avail = gst_adapter_available (rtpj2kdepay->pu_adapter);
233   if (avail == 0)
234     goto done;
235
236   MHF = rtpj2kdepay->pu_MHF;
237   mh_id = rtpj2kdepay->last_mh_id;
238
239   GST_DEBUG_OBJECT (rtpj2kdepay, "flushing PU of size %u", avail);
240
241   if (MHF == 0) {
242     GList *packets, *walk;
243
244     packets = gst_adapter_take_list (rtpj2kdepay->pu_adapter, avail);
245     /* append packets */
246     for (walk = packets; walk; walk = g_list_next (walk)) {
247       GstBuffer *buf = GST_BUFFER_CAST (walk->data);
248       GST_DEBUG_OBJECT (rtpj2kdepay, "append pu packet of size %u",
249           GST_BUFFER_SIZE (buf));
250       gst_adapter_push (rtpj2kdepay->t_adapter, buf);
251     }
252     g_list_free (packets);
253   } else {
254     /* we have a header */
255     GST_DEBUG_OBJECT (rtpj2kdepay, "keeping header %u", mh_id);
256     /* we managed to see the start and end of the header, take all from
257      * adapter and keep in header  */
258     mheader = gst_adapter_take_buffer (rtpj2kdepay->pu_adapter, avail);
259
260     store_mheader (rtpj2kdepay, mh_id, mheader);
261   }
262
263 done:
264   rtpj2kdepay->have_sync = FALSE;
265
266   return GST_FLOW_OK;
267 }
268
269 static GstFlowReturn
270 gst_rtp_j2k_depay_flush_tile (GstBaseRTPDepayload * depayload)
271 {
272   GstRtpJ2KDepay *rtpj2kdepay;
273   guint avail, mh_id;
274   GList *packets, *walk;
275   guint8 end[2];
276   GstFlowReturn ret = GST_FLOW_OK;
277
278   rtpj2kdepay = GST_RTP_J2K_DEPAY (depayload);
279
280   /* flush pending PU */
281   gst_rtp_j2k_depay_flush_pu (depayload);
282
283   /* take all available buffers */
284   avail = gst_adapter_available (rtpj2kdepay->t_adapter);
285   if (avail == 0)
286     goto done;
287
288   mh_id = rtpj2kdepay->last_mh_id;
289
290   GST_DEBUG_OBJECT (rtpj2kdepay, "flushing tile of size %u", avail);
291
292   if (gst_adapter_available (rtpj2kdepay->f_adapter) == 0) {
293     GstBuffer *mheader;
294
295     /* we need a header now */
296     if ((mheader = rtpj2kdepay->MH[mh_id]) == NULL)
297       goto waiting_header;
298
299     /* push header in the adapter */
300     GST_DEBUG_OBJECT (rtpj2kdepay, "pushing header %u", mh_id);
301     gst_adapter_push (rtpj2kdepay->f_adapter, gst_buffer_ref (mheader));
302   }
303
304   /* check for last bytes */
305   gst_adapter_copy (rtpj2kdepay->t_adapter, end, avail - 2, 2);
306
307   /* now append the tile packets to the frame */
308   packets = gst_adapter_take_list (rtpj2kdepay->t_adapter, avail);
309   for (walk = packets; walk; walk = g_list_next (walk)) {
310     GstBuffer *buf = GST_BUFFER_CAST (walk->data);
311
312     if (walk == packets) {
313       guint8 *data;
314       guint size;
315
316       /* first buffer should contain the SOT */
317       data = GST_BUFFER_DATA (buf);
318       size = GST_BUFFER_SIZE (buf);
319
320       if (size < 12)
321         goto invalid_tile;
322
323       if (data[0] == 0xff && data[1] == J2K_MARKER_SOT) {
324         guint Psot, nPsot;
325
326         if (end[0] == 0xff && end[1] == J2K_MARKER_EOC)
327           nPsot = avail - 2;
328         else
329           nPsot = avail;
330
331         Psot = GST_READ_UINT32_BE (&data[6]);
332         if (Psot != nPsot && Psot != 0) {
333           /* Psot must match the size of the tile */
334           GST_DEBUG_OBJECT (rtpj2kdepay, "set Psot from %u to %u", Psot, nPsot);
335           buf = gst_buffer_make_writable (buf);
336           data = GST_BUFFER_DATA (buf);
337           GST_WRITE_UINT32_BE (&data[6], nPsot);
338         }
339       }
340     }
341
342     GST_DEBUG_OBJECT (rtpj2kdepay, "append pu packet of size %u",
343         GST_BUFFER_SIZE (buf));
344     gst_adapter_push (rtpj2kdepay->f_adapter, buf);
345   }
346   g_list_free (packets);
347
348 done:
349   rtpj2kdepay->last_tile = -1;
350
351   return ret;
352
353   /* errors */
354 waiting_header:
355   {
356     GST_DEBUG_OBJECT (rtpj2kdepay, "waiting for header %u", mh_id);
357     gst_adapter_clear (rtpj2kdepay->t_adapter);
358     rtpj2kdepay->last_tile = -1;
359     return ret;
360   }
361 invalid_tile:
362   {
363     GST_ELEMENT_WARNING (rtpj2kdepay, STREAM, DECODE, ("Invalid tile"), (NULL));
364     gst_adapter_clear (rtpj2kdepay->t_adapter);
365     rtpj2kdepay->last_tile = -1;
366     return ret;
367   }
368 }
369
370 static GstFlowReturn
371 gst_rtp_j2k_depay_flush_frame (GstBaseRTPDepayload * depayload)
372 {
373   GstRtpJ2KDepay *rtpj2kdepay;
374   guint8 end[2];
375   guint8 *data;
376   guint avail;
377
378   GstFlowReturn ret = GST_FLOW_OK;
379
380   rtpj2kdepay = GST_RTP_J2K_DEPAY (depayload);
381
382   /* flush pending tile */
383   gst_rtp_j2k_depay_flush_tile (depayload);
384
385   /* last buffer take all data out of the adapter */
386   avail = gst_adapter_available (rtpj2kdepay->f_adapter);
387   if (avail == 0)
388     goto done;
389
390   if (avail > 2) {
391     GstBuffer *outbuf;
392
393     /* take the last bytes of the JPEG 2000 data to see if there is an EOC
394      * marker */
395     gst_adapter_copy (rtpj2kdepay->f_adapter, end, avail - 2, 2);
396
397     if (end[0] != 0xff && end[1] != 0xd9) {
398       GST_DEBUG_OBJECT (rtpj2kdepay, "no EOC marker, adding one");
399
400       /* no EOI marker, add one */
401       outbuf = gst_buffer_new_and_alloc (2);
402       data = GST_BUFFER_DATA (outbuf);
403       data[0] = 0xff;
404       data[1] = 0xd9;
405
406       gst_adapter_push (rtpj2kdepay->f_adapter, outbuf);
407       avail += 2;
408     }
409
410     if (rtpj2kdepay->buffer_list) {
411       GList *list;
412       GstBufferList *buflist;
413       GstBufferListIterator *it;
414
415       GST_DEBUG_OBJECT (rtpj2kdepay, "pushing buffer list of %u bytes", avail);
416       list = gst_adapter_take_list (rtpj2kdepay->f_adapter, avail);
417
418       buflist = gst_buffer_list_new ();
419       it = gst_buffer_list_iterate (buflist);
420       gst_buffer_list_iterator_add_group (it);
421       gst_buffer_list_iterator_add_list (it, list);
422       gst_buffer_list_iterator_free (it);
423
424       ret = gst_base_rtp_depayload_push_list (depayload, buflist);
425     } else {
426       GST_DEBUG_OBJECT (rtpj2kdepay, "pushing buffer of %u bytes", avail);
427       outbuf = gst_adapter_take_buffer (rtpj2kdepay->f_adapter, avail);
428       ret = gst_base_rtp_depayload_push (depayload, outbuf);
429     }
430   } else {
431     GST_WARNING_OBJECT (rtpj2kdepay, "empty packet");
432     gst_adapter_clear (rtpj2kdepay->f_adapter);
433   }
434
435   /* we accept any mh_id now */
436   rtpj2kdepay->last_mh_id = -1;
437
438   /* reset state */
439   rtpj2kdepay->next_frag = 0;
440   rtpj2kdepay->have_sync = FALSE;
441
442 done:
443   /* we can't keep headers with mh_id of 0 */
444   store_mheader (rtpj2kdepay, 0, NULL);
445
446   return ret;
447 }
448
449 static GstBuffer *
450 gst_rtp_j2k_depay_process (GstBaseRTPDepayload * depayload, GstBuffer * buf)
451 {
452   GstRtpJ2KDepay *rtpj2kdepay;
453   guint8 *payload;
454   guint MHF, mh_id, frag_offset, tile, payload_len, j2klen;
455   gint gap;
456   guint32 rtptime;
457
458   rtpj2kdepay = GST_RTP_J2K_DEPAY (depayload);
459
460   payload = gst_rtp_buffer_get_payload (buf);
461   payload_len = gst_rtp_buffer_get_payload_len (buf);
462
463   /* we need at least a header */
464   if (payload_len < 8)
465     goto empty_packet;
466
467   rtptime = gst_rtp_buffer_get_timestamp (buf);
468
469   /* new timestamp marks new frame */
470   if (rtpj2kdepay->last_rtptime != rtptime) {
471     rtpj2kdepay->last_rtptime = rtptime;
472     /* flush pending frame */
473     gst_rtp_j2k_depay_flush_frame (depayload);
474   }
475
476   /*
477    *  0                   1                   2                   3
478    *  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
479    * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
480    * |tp |MHF|mh_id|T|     priority  |           tile number         |
481    * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
482    * |reserved       |             fragment offset                   |
483    * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
484    */
485   MHF = (payload[0] & 0x30) >> 4;
486   mh_id = (payload[0] & 0xe) >> 1;
487
488   if (rtpj2kdepay->last_mh_id == -1)
489     rtpj2kdepay->last_mh_id = mh_id;
490   else if (rtpj2kdepay->last_mh_id != mh_id)
491     goto wrong_mh_id;
492
493   tile = (payload[2] << 8) | payload[3];
494   frag_offset = (payload[5] << 16) | (payload[6] << 8) | payload[7];
495   j2klen = payload_len - 8;
496
497   GST_DEBUG_OBJECT (rtpj2kdepay, "MHF %u, tile %u, frag %u, expected %u", MHF,
498       tile, frag_offset, rtpj2kdepay->next_frag);
499
500   /* calculate the gap between expected frag */
501   gap = frag_offset - rtpj2kdepay->next_frag;
502   /* calculate next frag */
503   rtpj2kdepay->next_frag = frag_offset + j2klen;
504
505   if (gap != 0) {
506     GST_DEBUG_OBJECT (rtpj2kdepay, "discont of %d, clear PU", gap);
507     /* discont, clear pu adapter and resync */
508     gst_rtp_j2k_depay_clear_pu (rtpj2kdepay);
509   }
510
511   /* check for sync code */
512   if (j2klen > 2 && payload[8] == 0xff) {
513     guint marker = payload[9];
514
515     /* packets must start with SOC, SOT or SOP */
516     switch (marker) {
517       case J2K_MARKER_SOC:
518         GST_DEBUG_OBJECT (rtpj2kdepay, "found SOC packet");
519         /* flush the previous frame, should have happened when the timestamp
520          * changed above. */
521         gst_rtp_j2k_depay_flush_frame (depayload);
522         rtpj2kdepay->have_sync = TRUE;
523         break;
524       case J2K_MARKER_SOT:
525         /* flush the previous tile */
526         gst_rtp_j2k_depay_flush_tile (depayload);
527         GST_DEBUG_OBJECT (rtpj2kdepay, "found SOT packet");
528         rtpj2kdepay->have_sync = TRUE;
529         /* we sync on the tile now */
530         rtpj2kdepay->last_tile = tile;
531         break;
532       case J2K_MARKER_SOP:
533         GST_DEBUG_OBJECT (rtpj2kdepay, "found SOP packet");
534         /* flush the previous PU */
535         gst_rtp_j2k_depay_flush_pu (depayload);
536         if (rtpj2kdepay->last_tile != tile) {
537           /* wrong tile, we lose sync and we need a new SOT or SOC to regain
538            * sync. First flush out the previous tile if we have one. */
539           if (rtpj2kdepay->last_tile != -1)
540             gst_rtp_j2k_depay_flush_tile (depayload);
541           /* now we have no more valid tile and no sync */
542           rtpj2kdepay->last_tile = -1;
543           rtpj2kdepay->have_sync = FALSE;
544         } else {
545           rtpj2kdepay->have_sync = TRUE;
546         }
547         break;
548       default:
549         GST_DEBUG_OBJECT (rtpj2kdepay, "no sync packet 0x%02d", marker);
550         break;
551     }
552   }
553
554   if (rtpj2kdepay->have_sync) {
555     GstBuffer *pu_frag;
556
557     if (gst_adapter_available (rtpj2kdepay->pu_adapter) == 0) {
558       /* first part of pu, record state */
559       GST_DEBUG_OBJECT (rtpj2kdepay, "first PU");
560       rtpj2kdepay->pu_MHF = MHF;
561     }
562     /* and push in pu adapter */
563     GST_DEBUG_OBJECT (rtpj2kdepay, "push pu of size %u in adapter", j2klen);
564     pu_frag = gst_rtp_buffer_get_payload_subbuffer (buf, 8, -1);
565     gst_adapter_push (rtpj2kdepay->pu_adapter, pu_frag);
566
567     if (MHF & 2) {
568       /* last part of main header received, we can flush it */
569       GST_DEBUG_OBJECT (rtpj2kdepay, "header end, flush pu");
570       gst_rtp_j2k_depay_flush_pu (depayload);
571     }
572   } else {
573     GST_DEBUG_OBJECT (rtpj2kdepay, "discard packet, no sync");
574   }
575
576   /* marker bit finishes the frame */
577   if (gst_rtp_buffer_get_marker (buf)) {
578     GST_DEBUG_OBJECT (rtpj2kdepay, "marker set, last buffer");
579     /* then flush frame */
580     gst_rtp_j2k_depay_flush_frame (depayload);
581   }
582   return NULL;
583
584   /* ERRORS */
585 empty_packet:
586   {
587     GST_ELEMENT_WARNING (rtpj2kdepay, STREAM, DECODE,
588         ("Empty Payload."), (NULL));
589     return NULL;
590   }
591 wrong_mh_id:
592   {
593     GST_ELEMENT_WARNING (rtpj2kdepay, STREAM, DECODE,
594         ("Invalid mh_id %u, expected %u", mh_id, rtpj2kdepay->last_mh_id),
595         (NULL));
596     gst_rtp_j2k_depay_clear_pu (rtpj2kdepay);
597     return NULL;
598   }
599 }
600
601 static void
602 gst_rtp_j2k_depay_set_property (GObject * object, guint prop_id,
603     const GValue * value, GParamSpec * pspec)
604 {
605   GstRtpJ2KDepay *rtpj2kdepay;
606
607   rtpj2kdepay = GST_RTP_J2K_DEPAY (object);
608
609   switch (prop_id) {
610     case PROP_BUFFER_LIST:
611       rtpj2kdepay->buffer_list = g_value_get_boolean (value);
612       break;
613     default:
614       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
615       break;
616   }
617 }
618
619 static void
620 gst_rtp_j2k_depay_get_property (GObject * object, guint prop_id,
621     GValue * value, GParamSpec * pspec)
622 {
623   GstRtpJ2KDepay *rtpj2kdepay;
624
625   rtpj2kdepay = GST_RTP_J2K_DEPAY (object);
626
627   switch (prop_id) {
628     case PROP_BUFFER_LIST:
629       g_value_set_boolean (value, rtpj2kdepay->buffer_list);
630       break;
631     default:
632       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
633       break;
634   }
635 }
636
637 static GstStateChangeReturn
638 gst_rtp_j2k_depay_change_state (GstElement * element, GstStateChange transition)
639 {
640   GstRtpJ2KDepay *rtpj2kdepay;
641   GstStateChangeReturn ret;
642
643   rtpj2kdepay = GST_RTP_J2K_DEPAY (element);
644
645   switch (transition) {
646     case GST_STATE_CHANGE_NULL_TO_READY:
647       break;
648     case GST_STATE_CHANGE_READY_TO_PAUSED:
649       gst_rtp_j2k_depay_reset (rtpj2kdepay);
650       break;
651     default:
652       break;
653   }
654
655   ret = GST_ELEMENT_CLASS (parent_class)->change_state (element, transition);
656
657   switch (transition) {
658     case GST_STATE_CHANGE_PAUSED_TO_READY:
659       gst_rtp_j2k_depay_reset (rtpj2kdepay);
660       break;
661     case GST_STATE_CHANGE_READY_TO_NULL:
662       break;
663     default:
664       break;
665   }
666   return ret;
667 }
668
669 gboolean
670 gst_rtp_j2k_depay_plugin_init (GstPlugin * plugin)
671 {
672   return gst_element_register (plugin, "rtpj2kdepay",
673       GST_RANK_SECONDARY, GST_TYPE_RTP_J2K_DEPAY);
674 }