tizen 2.0 init
[framework/multimedia/gst-plugins-good0.10.git] / gst / icydemux / gsticydemux.c
1 /* -*- Mode: C; tab-width: 2; indent-tabs-mode: t; c-basic-offset: 2 -*- */
2 /* Copyright 2005 Jan Schmidt <thaytan@mad.scientist.com>
3  *           2006 Michael Smith <msmith@fluendo.com>
4  * Copyright (C) 2003-2004 Benjamin Otte <otte@gnome.org>
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Library General Public
8  * License as published by the Free Software Foundation; either
9  * version 2 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * Library General Public License for more details.
15  *
16  * You should have received a copy of the GNU Library General Public
17  * License along with this library; if not, write to the
18  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19  * Boston, MA 02111-1307, USA.
20  */
21
22 /**
23  * SECTION:element-icydemux
24  *
25  * icydemux accepts data streams with ICY metadata at known intervals, as
26  * transmitted from an upstream element (usually read as response headers from
27  * an HTTP stream). The mime type of the data between the tag blocks is
28  * detected using typefind functions, and the appropriate output mime type set
29  * on outgoing buffers. 
30  *
31  * <refsect2>
32  * <title>Example launch line</title>
33  * |[
34  * gst-launch souphttpsrc location=http://some.server/ iradio-mode=true ! icydemux ! fakesink -t
35  * ]| This pipeline should read any available ICY tag information and output it.
36  * The contents of the stream should be detected, and the appropriate mime
37  * type set on buffers produced from icydemux. (Using gnomevfssrc, neonhttpsrc
38  * or giosrc instead of souphttpsrc should also work.)
39  * </refsect2>
40  */
41 #ifdef HAVE_CONFIG_H
42 #include "config.h"
43 #endif
44 #include <gst/gst.h>
45 #include <gst/gst-i18n-plugin.h>
46 #include <gst/tag/tag.h>
47
48 #include "gsticydemux.h"
49
50 #include <string.h>
51
52 #define ICY_TYPE_FIND_MAX_SIZE (40*1024)
53
54 GST_DEBUG_CATEGORY_STATIC (icydemux_debug);
55 #define GST_CAT_DEFAULT (icydemux_debug)
56
57 static GstStaticPadTemplate sink_factory = GST_STATIC_PAD_TEMPLATE ("sink",
58     GST_PAD_SINK,
59     GST_PAD_ALWAYS,
60     GST_STATIC_CAPS ("application/x-icy, metadata-interval = (int)[0, MAX]")
61     );
62
63 static GstStaticPadTemplate src_factory = GST_STATIC_PAD_TEMPLATE ("src",
64     GST_PAD_SRC,
65     GST_PAD_SOMETIMES,
66     GST_STATIC_CAPS ("ANY")
67     );
68
69 static void gst_icydemux_class_init (GstICYDemuxClass * klass);
70 static void gst_icydemux_base_init (GstICYDemuxClass * klass);
71 static void gst_icydemux_init (GstICYDemux * icydemux);
72 static void gst_icydemux_dispose (GObject * object);
73
74 static GstFlowReturn gst_icydemux_chain (GstPad * pad, GstBuffer * buf);
75 static gboolean gst_icydemux_handle_event (GstPad * pad, GstEvent * event);
76
77 static gboolean gst_icydemux_add_srcpad (GstICYDemux * icydemux,
78     GstCaps * new_caps);
79 static gboolean gst_icydemux_remove_srcpad (GstICYDemux * icydemux);
80
81 static GstStateChangeReturn gst_icydemux_change_state (GstElement * element,
82     GstStateChange transition);
83 static gboolean gst_icydemux_sink_setcaps (GstPad * pad, GstCaps * caps);
84
85 static gboolean gst_icydemux_send_tag_event (GstICYDemux * icydemux,
86     GstTagList * taglist);
87
88 static GstElementClass *parent_class = NULL;
89
90 GType
91 gst_icydemux_get_type (void)
92 {
93   static GType plugin_type = 0;
94
95   if (!plugin_type) {
96     static const GTypeInfo plugin_info = {
97       sizeof (GstICYDemuxClass),
98       (GBaseInitFunc) gst_icydemux_base_init,
99       NULL,
100       (GClassInitFunc) gst_icydemux_class_init,
101       NULL,
102       NULL,
103       sizeof (GstICYDemux),
104       0,
105       (GInstanceInitFunc) gst_icydemux_init,
106     };
107     plugin_type = g_type_register_static (GST_TYPE_ELEMENT,
108         "GstICYDemux", &plugin_info, 0);
109   }
110   return plugin_type;
111 }
112
113 static void
114 gst_icydemux_base_init (GstICYDemuxClass * klass)
115 {
116   GstElementClass *element_class = GST_ELEMENT_CLASS (klass);
117
118   gst_element_class_add_static_pad_template (element_class, &src_factory);
119   gst_element_class_add_static_pad_template (element_class, &sink_factory);
120   gst_element_class_set_details_simple (element_class, "ICY tag demuxer",
121       "Codec/Demuxer/Metadata",
122       "Read and output ICY tags while demuxing the contents",
123       "Jan Schmidt <thaytan@mad.scientist.com>, "
124       "Michael Smith <msmith@fluendo.com>");
125 }
126
127 static void
128 gst_icydemux_class_init (GstICYDemuxClass * klass)
129 {
130   GObjectClass *gobject_class;
131   GstElementClass *gstelement_class;
132
133   gobject_class = (GObjectClass *) klass;
134   gstelement_class = (GstElementClass *) klass;
135
136   parent_class = g_type_class_ref (GST_TYPE_ELEMENT);
137
138   gobject_class->dispose = gst_icydemux_dispose;
139
140   gstelement_class->change_state = gst_icydemux_change_state;
141
142 }
143
144 static void
145 gst_icydemux_reset (GstICYDemux * icydemux)
146 {
147   /* Unknown at the moment (this is a fatal error if don't have a value by the
148    * time we get to our chain function)
149    */
150   icydemux->meta_interval = -1;
151   icydemux->remaining = 0;
152
153   icydemux->typefinding = TRUE;
154
155   gst_caps_replace (&(icydemux->src_caps), NULL);
156
157   gst_icydemux_remove_srcpad (icydemux);
158
159   if (icydemux->cached_tags) {
160     gst_tag_list_free (icydemux->cached_tags);
161     icydemux->cached_tags = NULL;
162   }
163
164   if (icydemux->cached_events) {
165     g_list_foreach (icydemux->cached_events,
166         (GFunc) gst_mini_object_unref, NULL);
167     g_list_free (icydemux->cached_events);
168     icydemux->cached_events = NULL;
169   }
170
171   if (icydemux->meta_adapter) {
172     gst_adapter_clear (icydemux->meta_adapter);
173     g_object_unref (icydemux->meta_adapter);
174     icydemux->meta_adapter = NULL;
175   }
176
177   if (icydemux->typefind_buf) {
178     gst_buffer_unref (icydemux->typefind_buf);
179     icydemux->typefind_buf = NULL;
180   }
181
182   if (icydemux->content_type) {
183     g_free (icydemux->content_type);
184     icydemux->content_type = NULL;
185   }
186 }
187
188 static void
189 gst_icydemux_init (GstICYDemux * icydemux)
190 {
191   GstElementClass *klass = GST_ELEMENT_GET_CLASS (icydemux);
192
193   icydemux->sinkpad =
194       gst_pad_new_from_template (gst_element_class_get_pad_template (klass,
195           "sink"), "sink");
196   gst_pad_set_chain_function (icydemux->sinkpad,
197       GST_DEBUG_FUNCPTR (gst_icydemux_chain));
198   gst_pad_set_event_function (icydemux->sinkpad,
199       GST_DEBUG_FUNCPTR (gst_icydemux_handle_event));
200   gst_pad_set_setcaps_function (icydemux->sinkpad,
201       GST_DEBUG_FUNCPTR (gst_icydemux_sink_setcaps));
202   gst_element_add_pad (GST_ELEMENT (icydemux), icydemux->sinkpad);
203
204   gst_icydemux_reset (icydemux);
205 }
206
207 static gboolean
208 gst_icydemux_sink_setcaps (GstPad * pad, GstCaps * caps)
209 {
210   GstICYDemux *icydemux = GST_ICYDEMUX (GST_PAD_PARENT (pad));
211   GstStructure *structure = gst_caps_get_structure (caps, 0);
212   const gchar *tmp;
213
214   if (!gst_structure_get_int (structure, "metadata-interval",
215           &icydemux->meta_interval))
216     return FALSE;
217
218   /* If incoming caps have the HTTP Content-Type, copy that over */
219   if ((tmp = gst_structure_get_string (structure, "content-type")))
220     icydemux->content_type = g_strdup (tmp);
221
222   /* We have a meta interval, so initialise the rest */
223   icydemux->remaining = icydemux->meta_interval;
224   icydemux->meta_remaining = 0;
225   return TRUE;
226 }
227
228 static void
229 gst_icydemux_dispose (GObject * object)
230 {
231   GstICYDemux *icydemux = GST_ICYDEMUX (object);
232
233   gst_icydemux_reset (icydemux);
234
235   G_OBJECT_CLASS (parent_class)->dispose (object);
236 }
237
238 static gboolean
239 gst_icydemux_add_srcpad (GstICYDemux * icydemux, GstCaps * new_caps)
240 {
241   if (icydemux->src_caps == NULL ||
242       !gst_caps_is_equal (new_caps, icydemux->src_caps)) {
243     gst_caps_replace (&(icydemux->src_caps), new_caps);
244     if (icydemux->srcpad != NULL) {
245       GST_DEBUG_OBJECT (icydemux, "Changing src pad caps to %" GST_PTR_FORMAT,
246           icydemux->src_caps);
247
248       gst_pad_set_caps (icydemux->srcpad, icydemux->src_caps);
249     }
250   } else {
251     /* Caps never changed */
252     gst_caps_unref (new_caps);
253   }
254
255   if (icydemux->srcpad == NULL) {
256     icydemux->srcpad =
257         gst_pad_new_from_template (gst_element_class_get_pad_template
258         (GST_ELEMENT_GET_CLASS (icydemux), "src"), "src");
259     g_return_val_if_fail (icydemux->srcpad != NULL, FALSE);
260
261     gst_pad_use_fixed_caps (icydemux->srcpad);
262
263     if (icydemux->src_caps)
264       gst_pad_set_caps (icydemux->srcpad, icydemux->src_caps);
265
266     GST_DEBUG_OBJECT (icydemux, "Adding src pad with caps %" GST_PTR_FORMAT,
267         icydemux->src_caps);
268
269     gst_pad_set_active (icydemux->srcpad, TRUE);
270     if (!(gst_element_add_pad (GST_ELEMENT (icydemux), icydemux->srcpad)))
271       return FALSE;
272     gst_element_no_more_pads (GST_ELEMENT (icydemux));
273   }
274
275   return TRUE;
276 }
277
278 static gboolean
279 gst_icydemux_remove_srcpad (GstICYDemux * icydemux)
280 {
281   gboolean res = TRUE;
282
283   if (icydemux->srcpad != NULL) {
284     res = gst_element_remove_pad (GST_ELEMENT (icydemux), icydemux->srcpad);
285     g_return_val_if_fail (res != FALSE, FALSE);
286     icydemux->srcpad = NULL;
287   }
288
289   return res;
290 };
291
292 static gchar *
293 gst_icydemux_unicodify (const gchar * str)
294 {
295   const gchar *env_vars[] = { "GST_ICY_TAG_ENCODING",
296     "GST_TAG_ENCODING", NULL
297   };
298
299   return gst_tag_freeform_string_to_utf8 (str, -1, env_vars);
300 }
301
302 /* takes ownership of tag list */
303 static gboolean
304 gst_icydemux_tag_found (GstICYDemux * icydemux, GstTagList * tags)
305 {
306   /* send the tag event if we have finished typefinding and have a src pad */
307   if (icydemux->srcpad)
308     return gst_icydemux_send_tag_event (icydemux, tags);
309
310   /* if we haven't a source pad yet, cache the tags */
311   if (!icydemux->cached_tags) {
312     icydemux->cached_tags = tags;
313   } else {
314     gst_tag_list_insert (icydemux->cached_tags, tags,
315         GST_TAG_MERGE_REPLACE_ALL);
316     gst_tag_list_free (tags);
317   }
318
319   return TRUE;
320 }
321
322 static void
323 gst_icydemux_parse_and_send_tags (GstICYDemux * icydemux)
324 {
325   GstTagList *tags;
326   const guint8 *data;
327   int length, i;
328   gchar *buffer;
329   gchar **strings;
330
331   length = gst_adapter_available (icydemux->meta_adapter);
332
333   data = gst_adapter_peek (icydemux->meta_adapter, length);
334
335   /* Now, copy this to a buffer where we can NULL-terminate it to make things
336    * a bit easier, then do that parsing. */
337   buffer = g_strndup ((const gchar *) data, length);
338
339   tags = gst_tag_list_new ();
340   strings = g_strsplit (buffer, "';", 0);
341
342   for (i = 0; strings[i]; i++) {
343     if (!g_ascii_strncasecmp (strings[i], "StreamTitle=", 12)) {
344       char *title = gst_icydemux_unicodify (strings[i] + 13);
345
346       if (title && *title) {
347         gst_tag_list_add (tags, GST_TAG_MERGE_REPLACE, GST_TAG_TITLE,
348             title, NULL);
349         g_free (title);
350       }
351     } else if (!g_ascii_strncasecmp (strings[i], "StreamUrl=", 10)) {
352       char *url = gst_icydemux_unicodify (strings[i] + 11);
353
354       if (url && *url) {
355         gst_tag_list_add (tags, GST_TAG_MERGE_REPLACE, GST_TAG_HOMEPAGE,
356             url, NULL);
357         g_free (url);
358       }
359     }
360   }
361
362   g_strfreev (strings);
363   g_free (buffer);
364   gst_adapter_clear (icydemux->meta_adapter);
365
366   if (!gst_tag_list_is_empty (tags))
367     gst_icydemux_tag_found (icydemux, tags);
368   else
369     gst_tag_list_free (tags);
370 }
371
372 static gboolean
373 gst_icydemux_handle_event (GstPad * pad, GstEvent * event)
374 {
375   GstICYDemux *icydemux = GST_ICYDEMUX (GST_PAD_PARENT (pad));
376   gboolean result;
377
378   if (GST_EVENT_TYPE (event) == GST_EVENT_TAG) {
379     GstTagList *tags;
380
381     gst_event_parse_tag (event, &tags);
382     result = gst_icydemux_tag_found (icydemux, gst_tag_list_copy (tags));
383     gst_event_unref (event);
384     return result;
385   }
386
387   if (icydemux->typefinding) {
388     switch (GST_EVENT_TYPE (event)) {
389       case GST_EVENT_FLUSH_STOP:
390         g_list_foreach (icydemux->cached_events,
391             (GFunc) gst_mini_object_unref, NULL);
392         g_list_free (icydemux->cached_events);
393         icydemux->cached_events = NULL;
394
395         return gst_pad_event_default (pad, event);
396       default:
397         icydemux->cached_events = g_list_append (icydemux->cached_events,
398             event);
399         return TRUE;
400     }
401   } else {
402     return gst_pad_event_default (pad, event);
403   }
404 }
405
406 static void
407 gst_icydemux_send_cached_events (GstICYDemux * icydemux)
408 {
409   GList *l;
410
411   for (l = icydemux->cached_events; l != NULL; l = l->next) {
412     GstEvent *event = GST_EVENT (l->data);
413
414     gst_pad_push_event (icydemux->srcpad, event);
415   }
416   g_list_free (icydemux->cached_events);
417   icydemux->cached_events = NULL;
418 }
419
420 static GstFlowReturn
421 gst_icydemux_typefind_or_forward (GstICYDemux * icydemux, GstBuffer * buf)
422 {
423   if (icydemux->typefinding) {
424     GstBuffer *tf_buf;
425     GstCaps *caps = NULL;
426     GstTypeFindProbability prob;
427
428     /* If we have a content-type from upstream, let's see if we can shortcut
429      * typefinding */
430     if (G_UNLIKELY (icydemux->content_type)) {
431       if (!g_ascii_strcasecmp (icydemux->content_type, "video/nsv")) {
432         GST_DEBUG ("We have a NSV stream");
433         caps = gst_caps_new_simple ("video/x-nsv", NULL);
434       } else {
435         GST_DEBUG ("Upstream Content-Type isn't supported");
436         g_free (icydemux->content_type);
437         icydemux->content_type = NULL;
438       }
439     }
440
441     if (icydemux->typefind_buf) {
442       icydemux->typefind_buf = gst_buffer_join (icydemux->typefind_buf, buf);
443     } else {
444       icydemux->typefind_buf = buf;
445     }
446
447     /* Only typefind if we haven't already got some caps */
448     if (caps == NULL) {
449       caps = gst_type_find_helper_for_buffer (GST_OBJECT (icydemux),
450           icydemux->typefind_buf, &prob);
451
452       if (caps == NULL) {
453         if (GST_BUFFER_SIZE (icydemux->typefind_buf) < ICY_TYPE_FIND_MAX_SIZE) {
454           /* Just break for more data */
455           return GST_FLOW_OK;
456         }
457
458         /* We failed typefind */
459         GST_ELEMENT_ERROR (icydemux, STREAM, TYPE_NOT_FOUND, (NULL),
460             ("No caps found for contents within an ICY stream"));
461         gst_buffer_unref (icydemux->typefind_buf);
462         icydemux->typefind_buf = NULL;
463         return GST_FLOW_ERROR;
464       }
465     }
466
467     if (!gst_icydemux_add_srcpad (icydemux, caps)) {
468       GST_DEBUG_OBJECT (icydemux, "Failed to add srcpad");
469       gst_caps_unref (caps);
470       gst_buffer_unref (icydemux->typefind_buf);
471       icydemux->typefind_buf = NULL;
472       return GST_FLOW_ERROR;
473     }
474     gst_caps_unref (caps);
475
476     if (icydemux->cached_events) {
477       gst_icydemux_send_cached_events (icydemux);
478     }
479
480     if (icydemux->cached_tags) {
481       gst_icydemux_send_tag_event (icydemux, icydemux->cached_tags);
482       icydemux->cached_tags = NULL;
483     }
484
485     /* Move onto streaming: call ourselves recursively with the typefind buffer
486      * to get that forwarded. */
487     icydemux->typefinding = FALSE;
488
489     tf_buf = icydemux->typefind_buf;
490     icydemux->typefind_buf = NULL;
491     return gst_icydemux_typefind_or_forward (icydemux, tf_buf);
492   } else {
493     if (G_UNLIKELY (icydemux->srcpad == NULL)) {
494       gst_buffer_unref (buf);
495       return GST_FLOW_ERROR;
496     }
497
498     buf = gst_buffer_make_metadata_writable (buf);
499     gst_buffer_set_caps (buf, icydemux->src_caps);
500
501     /* Most things don't care, and it's a pain to track (we should preserve a
502      * 0 offset on the first buffer though if it's there, for id3demux etc.) */
503     if (GST_BUFFER_OFFSET (buf) != 0) {
504       GST_BUFFER_OFFSET (buf) = GST_BUFFER_OFFSET_NONE;
505     }
506
507     return gst_pad_push (icydemux->srcpad, buf);
508   }
509 }
510
511 static void
512 gst_icydemux_add_meta (GstICYDemux * icydemux, GstBuffer * buf)
513 {
514   if (!icydemux->meta_adapter)
515     icydemux->meta_adapter = gst_adapter_new ();
516
517   gst_adapter_push (icydemux->meta_adapter, buf);
518 }
519
520 static GstFlowReturn
521 gst_icydemux_chain (GstPad * pad, GstBuffer * buf)
522 {
523   GstICYDemux *icydemux;
524   guint size, chunk, offset;
525   GstBuffer *sub;
526   GstFlowReturn ret = GST_FLOW_OK;
527
528   icydemux = GST_ICYDEMUX (GST_PAD_PARENT (pad));
529
530   if (G_UNLIKELY (icydemux->meta_interval < 0))
531     goto not_negotiated;
532
533   if (icydemux->meta_interval == 0) {
534     ret = gst_icydemux_typefind_or_forward (icydemux, buf);
535     goto done;
536   }
537
538   /* Go through the buffer, chopping it into appropriate chunks. Forward as
539    * tags or buffers, as appropriate
540    */
541   size = GST_BUFFER_SIZE (buf);
542   offset = 0;
543   while (size) {
544     if (icydemux->remaining) {
545       chunk = (size <= icydemux->remaining) ? size : icydemux->remaining;
546       sub = gst_buffer_create_sub (buf, offset, chunk);
547       offset += chunk;
548       icydemux->remaining -= chunk;
549       size -= chunk;
550
551       /* This buffer goes onto typefinding, and/or directly pushed out */
552       ret = gst_icydemux_typefind_or_forward (icydemux, sub);
553       if (ret != GST_FLOW_OK)
554         goto done;
555     } else if (icydemux->meta_remaining) {
556       chunk = (size <= icydemux->meta_remaining) ?
557           size : icydemux->meta_remaining;
558       sub = gst_buffer_create_sub (buf, offset, chunk);
559       gst_icydemux_add_meta (icydemux, sub);
560
561       offset += chunk;
562       icydemux->meta_remaining -= chunk;
563       size -= chunk;
564
565       if (icydemux->meta_remaining == 0) {
566         /* Parse tags from meta_adapter, send off as tag messages */
567         GST_DEBUG_OBJECT (icydemux, "No remaining metadata, parsing for tags");
568         gst_icydemux_parse_and_send_tags (icydemux);
569
570         icydemux->remaining = icydemux->meta_interval;
571       }
572     } else {
573       /* We need to read a single byte (always safe at this point in the loop)
574        * to figure out how many bytes of metadata exist. 
575        * The 'spec' tells us to read 16 * (byte_value) bytes of metadata after
576        * this (zero is common, and means the metadata hasn't changed).
577        */
578       icydemux->meta_remaining = 16 * GST_BUFFER_DATA (buf)[offset];
579       if (icydemux->meta_remaining == 0)
580         icydemux->remaining = icydemux->meta_interval;
581
582       offset += 1;
583       size -= 1;
584     }
585   }
586
587 done:
588   gst_buffer_unref (buf);
589
590   return ret;
591
592   /* ERRORS */
593 not_negotiated:
594   {
595     GST_WARNING_OBJECT (icydemux, "meta_interval not set, buffer probably had "
596         "no caps set. Try enabling iradio-mode on the http source element");
597     gst_buffer_unref (buf);
598     return GST_FLOW_NOT_NEGOTIATED;
599   }
600 }
601
602 static GstStateChangeReturn
603 gst_icydemux_change_state (GstElement * element, GstStateChange transition)
604 {
605   GstStateChangeReturn ret;
606   GstICYDemux *icydemux = GST_ICYDEMUX (element);
607
608   ret = GST_ELEMENT_CLASS (parent_class)->change_state (element, transition);
609
610   switch (transition) {
611     case GST_STATE_CHANGE_PAUSED_TO_READY:
612       gst_icydemux_reset (icydemux);
613       break;
614     default:
615       break;
616   }
617   return ret;
618 }
619
620 /* takes ownership of tag list */
621 static gboolean
622 gst_icydemux_send_tag_event (GstICYDemux * icydemux, GstTagList * tags)
623 {
624   GstEvent *event;
625
626   gst_element_post_message (GST_ELEMENT (icydemux),
627       gst_message_new_tag (GST_OBJECT (icydemux), gst_tag_list_copy (tags)));
628
629   event = gst_event_new_tag (tags);
630   GST_EVENT_TIMESTAMP (event) = 0;
631
632   GST_DEBUG_OBJECT (icydemux, "Sending tag event on src pad");
633   return gst_pad_push_event (icydemux->srcpad, event);
634
635 }
636
637 static gboolean
638 plugin_init (GstPlugin * plugin)
639 {
640   GST_DEBUG_CATEGORY_INIT (icydemux_debug, "icydemux", 0,
641       "GStreamer ICY tag demuxer");
642
643   return gst_element_register (plugin, "icydemux",
644       GST_RANK_PRIMARY, GST_TYPE_ICYDEMUX);
645 }
646
647 GST_PLUGIN_DEFINE (GST_VERSION_MAJOR,
648     GST_VERSION_MINOR,
649     "icydemux",
650     "Demux ICY tags from a stream",
651     plugin_init, VERSION, GST_LICENSE, GST_PACKAGE_NAME, GST_PACKAGE_ORIGIN)