8763efff773d5698112bdff662122fe8a56977b8
[platform/upstream/gstreamer.git] / gst-libs / gst / pbutils / gstdiscoverer-types.c
1 /* GStreamer
2  * Copyright (C) 2010 Collabora Multimedia
3  *               2010 Nokia Corporation
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Library General Public
7  * License as published by the Free Software Foundation; either
8  * version 2 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * Library General Public License for more details.
14  *
15  * You should have received a copy of the GNU Library General Public
16  * License along with this library; if not, write to the
17  * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
18  * Boston, MA 02110-1301, USA.
19  */
20
21 #ifdef HAVE_CONFIG_H
22 #include "config.h"
23 #endif
24
25 #include "pbutils.h"
26 #include "pbutils-private.h"
27
28 static GstDiscovererStreamInfo
29     * gst_discoverer_info_copy_int (GstDiscovererStreamInfo * info,
30     GHashTable * stream_map);
31
32 static GstDiscovererContainerInfo
33     * gst_stream_container_info_copy_int (GstDiscovererContainerInfo * ptr,
34     GHashTable * stream_map);
35
36 static GstDiscovererAudioInfo
37     * gst_discoverer_audio_info_copy_int (GstDiscovererAudioInfo * ptr);
38
39 static GstDiscovererVideoInfo
40     * gst_discoverer_video_info_copy_int (GstDiscovererVideoInfo * ptr);
41
42 static GstDiscovererSubtitleInfo
43     * gst_discoverer_subtitle_info_copy_int (GstDiscovererSubtitleInfo * ptr);
44
45 /* Per-stream information */
46
47 G_DEFINE_TYPE (GstDiscovererStreamInfo, gst_discoverer_stream_info,
48     G_TYPE_OBJECT);
49
50 static void
51 gst_discoverer_stream_info_init (GstDiscovererStreamInfo * info)
52 {
53   /* Nothing needs initialization */
54 }
55
56 static void
57 gst_discoverer_stream_info_finalize (GObject * object)
58 {
59   GstDiscovererStreamInfo *info = (GstDiscovererStreamInfo *) object;
60
61   if (info->next)
62     g_object_unref ((GObject *) info->next);
63
64   if (info->caps)
65     gst_caps_unref (info->caps);
66
67   if (info->tags)
68     gst_tag_list_unref (info->tags);
69
70   if (info->toc)
71     gst_toc_unref (info->toc);
72
73   g_free (info->stream_id);
74
75   if (info->misc)
76     gst_structure_free (info->misc);
77 }
78
79 static void
80 gst_discoverer_stream_info_class_init (GObjectClass * klass)
81 {
82   klass->finalize = gst_discoverer_stream_info_finalize;
83 }
84
85 static GstDiscovererStreamInfo *
86 gst_discoverer_stream_info_new (void)
87 {
88   return (GstDiscovererStreamInfo *)
89       g_object_new (GST_TYPE_DISCOVERER_STREAM_INFO, NULL);
90 }
91
92 static GstDiscovererStreamInfo *
93 gst_discoverer_info_copy_int (GstDiscovererStreamInfo * info,
94     GHashTable * stream_map)
95 {
96   GstDiscovererStreamInfo *ret;
97   GType ltyp;
98
99   g_return_val_if_fail (info != NULL, NULL);
100
101   ltyp = G_TYPE_FROM_INSTANCE (info);
102
103   if (ltyp == GST_TYPE_DISCOVERER_CONTAINER_INFO) {
104     ret = (GstDiscovererStreamInfo *)
105         gst_stream_container_info_copy_int (
106         (GstDiscovererContainerInfo *) info, stream_map);
107   } else if (ltyp == GST_TYPE_DISCOVERER_AUDIO_INFO) {
108     ret = (GstDiscovererStreamInfo *)
109         gst_discoverer_audio_info_copy_int ((GstDiscovererAudioInfo *) info);
110
111   } else if (ltyp == GST_TYPE_DISCOVERER_VIDEO_INFO) {
112     ret = (GstDiscovererStreamInfo *)
113         gst_discoverer_video_info_copy_int ((GstDiscovererVideoInfo *) info);
114
115   } else if (ltyp == GST_TYPE_DISCOVERER_SUBTITLE_INFO) {
116     ret = (GstDiscovererStreamInfo *)
117         gst_discoverer_subtitle_info_copy_int ((GstDiscovererSubtitleInfo *)
118         info);
119
120   } else
121     ret = gst_discoverer_stream_info_new ();
122
123   if (info->next) {
124     ret->next = gst_discoverer_info_copy_int (info->next, stream_map);
125     ret->next->previous = ret;
126   }
127
128   if (info->caps)
129     ret->caps = gst_caps_copy (info->caps);
130
131   if (info->tags)
132     ret->tags = gst_tag_list_copy (info->tags);
133
134   if (info->toc)
135     ret->toc = gst_toc_ref (info->toc);
136
137   if (info->stream_id)
138     ret->stream_id = g_strdup (info->stream_id);
139
140   if (info->misc)
141     ret->misc = gst_structure_copy (info->misc);
142
143   if (stream_map)
144     g_hash_table_insert (stream_map, info, ret);
145
146   return ret;
147 }
148
149 /* Container information */
150 G_DEFINE_TYPE (GstDiscovererContainerInfo, gst_discoverer_container_info,
151     GST_TYPE_DISCOVERER_STREAM_INFO);
152
153 static void
154 gst_discoverer_container_info_init (GstDiscovererContainerInfo * info)
155 {
156   /* Nothing to initialize */
157 }
158
159 static GstDiscovererContainerInfo *
160 gst_discoverer_container_info_new (void)
161 {
162   return (GstDiscovererContainerInfo *)
163       g_object_new (GST_TYPE_DISCOVERER_CONTAINER_INFO, NULL);
164 }
165
166 static void
167 gst_discoverer_container_info_finalize (GObject * object)
168 {
169   GstDiscovererContainerInfo *info = (GstDiscovererContainerInfo *) object;
170   GList *tmp;
171
172   for (tmp = ((GstDiscovererContainerInfo *) info)->streams; tmp;
173       tmp = tmp->next)
174     g_object_unref ((GObject *) tmp->data);
175
176   gst_discoverer_stream_info_list_free (info->streams);
177
178   gst_discoverer_stream_info_finalize ((GObject *) info);
179 }
180
181 static void
182 gst_discoverer_container_info_class_init (GObjectClass * klass)
183 {
184   klass->finalize = gst_discoverer_container_info_finalize;
185 }
186
187 static GstDiscovererContainerInfo *
188 gst_stream_container_info_copy_int (GstDiscovererContainerInfo * ptr,
189     GHashTable * stream_map)
190 {
191   GstDiscovererContainerInfo *ret;
192   GList *tmp;
193
194   g_return_val_if_fail (ptr != NULL, NULL);
195
196   ret = gst_discoverer_container_info_new ();
197
198   for (tmp = ((GstDiscovererContainerInfo *) ptr)->streams; tmp;
199       tmp = tmp->next) {
200     GstDiscovererStreamInfo *subtop = gst_discoverer_info_copy_int (tmp->data,
201         stream_map);
202     ret->streams = g_list_append (ret->streams, subtop);
203     if (stream_map)
204       g_hash_table_insert (stream_map, tmp->data, subtop);
205   }
206
207   return ret;
208 }
209
210 /* Audio information */
211 G_DEFINE_TYPE (GstDiscovererAudioInfo, gst_discoverer_audio_info,
212     GST_TYPE_DISCOVERER_STREAM_INFO);
213
214 static void
215 gst_discoverer_audio_info_finalize (GObject * object)
216 {
217   GstDiscovererAudioInfo *info = (GstDiscovererAudioInfo *) object;
218
219   g_free (info->language);
220
221   G_OBJECT_CLASS (gst_discoverer_audio_info_parent_class)->finalize (object);
222 }
223
224 static void
225 gst_discoverer_audio_info_class_init (GObjectClass * klass)
226 {
227   klass->finalize = gst_discoverer_audio_info_finalize;
228 }
229
230 static void
231 gst_discoverer_audio_info_init (GstDiscovererAudioInfo * info)
232 {
233   info->language = NULL;
234 }
235
236 static GstDiscovererAudioInfo *
237 gst_discoverer_audio_info_new (void)
238 {
239   return (GstDiscovererAudioInfo *)
240       g_object_new (GST_TYPE_DISCOVERER_AUDIO_INFO, NULL);
241 }
242
243 static GstDiscovererAudioInfo *
244 gst_discoverer_audio_info_copy_int (GstDiscovererAudioInfo * ptr)
245 {
246   GstDiscovererAudioInfo *ret;
247
248   ret = gst_discoverer_audio_info_new ();
249
250   ret->channels = ptr->channels;
251   ret->sample_rate = ptr->sample_rate;
252   ret->depth = ptr->depth;
253   ret->bitrate = ptr->bitrate;
254   ret->max_bitrate = ptr->max_bitrate;
255   ret->language = g_strdup (ptr->language);
256
257   return ret;
258 }
259
260 /* Subtitle information */
261 G_DEFINE_TYPE (GstDiscovererSubtitleInfo, gst_discoverer_subtitle_info,
262     GST_TYPE_DISCOVERER_STREAM_INFO);
263
264 static void
265 gst_discoverer_subtitle_info_init (GstDiscovererSubtitleInfo * info)
266 {
267   info->language = NULL;
268 }
269
270 static void
271 gst_discoverer_subtitle_info_finalize (GObject * object)
272 {
273   GstDiscovererSubtitleInfo *info = (GstDiscovererSubtitleInfo *) object;
274
275   g_free (info->language);
276
277   G_OBJECT_CLASS (gst_discoverer_subtitle_info_parent_class)->finalize (object);
278 }
279
280 static void
281 gst_discoverer_subtitle_info_class_init (GObjectClass * klass)
282 {
283   klass->finalize = gst_discoverer_subtitle_info_finalize;
284 }
285
286 static GstDiscovererSubtitleInfo *
287 gst_discoverer_subtitle_info_new (void)
288 {
289   return (GstDiscovererSubtitleInfo *)
290       g_object_new (GST_TYPE_DISCOVERER_SUBTITLE_INFO, NULL);
291 }
292
293 static GstDiscovererSubtitleInfo *
294 gst_discoverer_subtitle_info_copy_int (GstDiscovererSubtitleInfo * ptr)
295 {
296   GstDiscovererSubtitleInfo *ret;
297
298   ret = gst_discoverer_subtitle_info_new ();
299
300   ret->language = g_strdup (ptr->language);
301
302   return ret;
303 }
304
305 /* Video information */
306 G_DEFINE_TYPE (GstDiscovererVideoInfo, gst_discoverer_video_info,
307     GST_TYPE_DISCOVERER_STREAM_INFO);
308
309 static void
310 gst_discoverer_video_info_class_init (GObjectClass * klass)
311 {
312   /* Nothing to initialize */
313 }
314
315 static void
316 gst_discoverer_video_info_init (GstDiscovererVideoInfo * info)
317 {
318   /* Nothing to initialize */
319 }
320
321 static GstDiscovererVideoInfo *
322 gst_discoverer_video_info_new (void)
323 {
324   return (GstDiscovererVideoInfo *)
325       g_object_new (GST_TYPE_DISCOVERER_VIDEO_INFO, NULL);
326 }
327
328 static GstDiscovererVideoInfo *
329 gst_discoverer_video_info_copy_int (GstDiscovererVideoInfo * ptr)
330 {
331   GstDiscovererVideoInfo *ret;
332
333   ret = gst_discoverer_video_info_new ();
334
335   ret->width = ptr->width;
336   ret->height = ptr->height;
337   ret->depth = ptr->depth;
338   ret->framerate_num = ptr->framerate_num;
339   ret->framerate_denom = ptr->framerate_denom;
340   ret->par_num = ptr->par_num;
341   ret->par_denom = ptr->par_denom;
342   ret->interlaced = ptr->interlaced;
343   ret->bitrate = ptr->bitrate;
344   ret->max_bitrate = ptr->max_bitrate;
345   ret->is_image = ptr->is_image;
346
347   return ret;
348 }
349
350 /* Global stream information */
351 G_DEFINE_TYPE (GstDiscovererInfo, gst_discoverer_info, G_TYPE_OBJECT);
352
353 static void
354 gst_discoverer_info_init (GstDiscovererInfo * info)
355 {
356   /* Nothing needs initialization */
357 }
358
359 static void
360 gst_discoverer_info_finalize (GObject * object)
361 {
362   GstDiscovererInfo *info = (GstDiscovererInfo *) object;
363   g_free (info->uri);
364
365   if (info->stream_info)
366     g_object_unref ((GObject *) info->stream_info);
367
368   if (info->misc)
369     gst_structure_free (info->misc);
370
371   g_list_free (info->stream_list);
372
373   if (info->tags)
374     gst_tag_list_unref (info->tags);
375
376   if (info->toc)
377     gst_toc_unref (info->toc);
378 }
379
380 static GstDiscovererInfo *
381 gst_discoverer_info_new (void)
382 {
383   return (GstDiscovererInfo *) g_object_new (GST_TYPE_DISCOVERER_INFO, NULL);
384 }
385
386 /**
387  * gst_discoverer_info_copy:
388  * @ptr: (transfer none): a #GstDiscovererInfo
389  *
390  * Returns: (transfer full): A copy of the #GstDiscovererInfo
391  */
392 GstDiscovererInfo *
393 gst_discoverer_info_copy (GstDiscovererInfo * ptr)
394 {
395   GstDiscovererInfo *ret;
396   GHashTable *stream_map;
397   GList *tmp;
398
399   g_return_val_if_fail (ptr != NULL, NULL);
400
401   stream_map = g_hash_table_new (g_direct_hash, NULL);
402
403   ret = gst_discoverer_info_new ();
404
405   ret->uri = g_strdup (ptr->uri);
406   if (ptr->stream_info) {
407     ret->stream_info = gst_discoverer_info_copy_int (ptr->stream_info,
408         stream_map);
409   }
410   ret->duration = ptr->duration;
411   if (ptr->misc)
412     ret->misc = gst_structure_copy (ptr->misc);
413
414   /* We need to set up the new list of streams to correspond to old one. The
415    * list just contains a set of pointers to streams in the stream_info tree,
416    * so we keep a map of old stream info objects to the corresponding new
417    * ones and use that to figure out correspondence in stream_list. */
418   for (tmp = ptr->stream_list; tmp; tmp = tmp->next) {
419     GstDiscovererStreamInfo *old_stream = (GstDiscovererStreamInfo *) tmp->data;
420     GstDiscovererStreamInfo *new_stream = g_hash_table_lookup (stream_map,
421         old_stream);
422     g_assert (new_stream != NULL);
423     ret->stream_list = g_list_append (ret->stream_list, new_stream);
424   }
425
426   if (ptr->tags)
427     ret->tags = gst_tag_list_copy (ptr->tags);
428
429   if (ptr->toc)
430     ret->toc = gst_toc_ref (ptr->toc);
431
432   g_hash_table_destroy (stream_map);
433   return ret;
434 }
435
436 static void
437 gst_discoverer_info_class_init (GObjectClass * klass)
438 {
439   klass->finalize = gst_discoverer_info_finalize;
440 }
441
442 /**
443  * gst_discoverer_stream_info_list_free:
444  * @infos: (element-type GstPbutils.DiscovererStreamInfo): a #GList of #GstDiscovererStreamInfo
445  *
446  * Decrements the reference count of all contained #GstDiscovererStreamInfo
447  * and fress the #GList.
448  */
449 void
450 gst_discoverer_stream_info_list_free (GList * infos)
451 {
452   GList *tmp;
453
454   for (tmp = infos; tmp; tmp = tmp->next)
455     gst_discoverer_stream_info_unref ((GstDiscovererStreamInfo *) tmp->data);
456   g_list_free (infos);
457 }
458
459 /**
460  * gst_discoverer_info_get_streams:
461  * @info: a #GstDiscovererInfo
462  * @streamtype: a #GType derived from #GstDiscovererStreamInfo
463  *
464  * Finds the #GstDiscovererStreamInfo contained in @info that match the
465  * given @streamtype.
466  *
467  * Returns: (transfer full) (element-type GstPbutils.DiscovererStreamInfo): A #GList of
468  * matching #GstDiscovererStreamInfo. The caller should free it with
469  * gst_discoverer_stream_info_list_free().
470  */
471 GList *
472 gst_discoverer_info_get_streams (GstDiscovererInfo * info, GType streamtype)
473 {
474   GList *tmp, *res = NULL;
475
476   for (tmp = info->stream_list; tmp; tmp = tmp->next) {
477     GstDiscovererStreamInfo *stmp = (GstDiscovererStreamInfo *) tmp->data;
478
479     if (G_TYPE_CHECK_INSTANCE_TYPE (stmp, streamtype))
480       res = g_list_append (res, gst_discoverer_stream_info_ref (stmp));
481   }
482
483   return res;
484 }
485
486 /**
487  * gst_discoverer_info_get_audio_streams:
488  * @info: a #GstDiscovererInfo
489  *
490  * Finds all the #GstDiscovererAudioInfo contained in @info
491  *
492  * Returns: (transfer full) (element-type GstPbutils.DiscovererStreamInfo): A #GList of
493  * matching #GstDiscovererStreamInfo. The caller should free it with
494  * gst_discoverer_stream_info_list_free().
495  */
496 GList *
497 gst_discoverer_info_get_audio_streams (GstDiscovererInfo * info)
498 {
499   return gst_discoverer_info_get_streams (info, GST_TYPE_DISCOVERER_AUDIO_INFO);
500 }
501
502 /**
503  * gst_discoverer_info_get_video_streams:
504  * @info: a #GstDiscovererInfo
505  *
506  * Finds all the #GstDiscovererVideoInfo contained in @info
507  *
508  * Returns: (transfer full) (element-type GstPbutils.DiscovererStreamInfo): A #GList of
509  * matching #GstDiscovererStreamInfo. The caller should free it with
510  * gst_discoverer_stream_info_list_free().
511  */
512 GList *
513 gst_discoverer_info_get_video_streams (GstDiscovererInfo * info)
514 {
515   return gst_discoverer_info_get_streams (info, GST_TYPE_DISCOVERER_VIDEO_INFO);
516 }
517
518 /**
519  * gst_discoverer_info_get_subtitle_streams:
520  * @info: a #GstDiscovererInfo
521  *
522  * Finds all the #GstDiscovererSubtitleInfo contained in @info
523  *
524  * Returns: (transfer full) (element-type GstPbutils.DiscovererStreamInfo): A #GList of
525  * matching #GstDiscovererStreamInfo. The caller should free it with
526  * gst_discoverer_stream_info_list_free().
527  */
528 GList *
529 gst_discoverer_info_get_subtitle_streams (GstDiscovererInfo * info)
530 {
531   return gst_discoverer_info_get_streams (info,
532       GST_TYPE_DISCOVERER_SUBTITLE_INFO);
533 }
534
535 /**
536  * gst_discoverer_info_get_container_streams:
537  * @info: a #GstDiscovererInfo
538  *
539  * Finds all the #GstDiscovererContainerInfo contained in @info
540  *
541  * Returns: (transfer full) (element-type GstPbutils.DiscovererStreamInfo): A #GList of
542  * matching #GstDiscovererStreamInfo. The caller should free it with
543  * gst_discoverer_stream_info_list_free().
544  */
545 GList *
546 gst_discoverer_info_get_container_streams (GstDiscovererInfo * info)
547 {
548   return gst_discoverer_info_get_streams (info,
549       GST_TYPE_DISCOVERER_CONTAINER_INFO);
550 }
551
552 /**
553  * gst_discoverer_stream_info_get_stream_type_nick:
554  * @info: a #GstDiscovererStreamInfo
555  *
556  * Returns: a human readable name for the stream type of the given @info (ex : "audio",
557  * "container",...).
558  */
559 const gchar *
560 gst_discoverer_stream_info_get_stream_type_nick (GstDiscovererStreamInfo * info)
561 {
562   if (GST_IS_DISCOVERER_CONTAINER_INFO (info))
563     return "container";
564   if (GST_IS_DISCOVERER_AUDIO_INFO (info))
565     return "audio";
566   if (GST_IS_DISCOVERER_VIDEO_INFO (info)) {
567     if (gst_discoverer_video_info_is_image ((GstDiscovererVideoInfo *)
568             info))
569       return "video(image)";
570     else
571       return "video";
572   }
573   if (GST_IS_DISCOVERER_SUBTITLE_INFO (info))
574     return "subtitles";
575   return "unknown";
576 }
577
578 /* ACCESSORS */
579
580
581 #define GENERIC_ACCESSOR_CODE(parent, parenttype, parentgtype, fieldname, type, failval) \
582   type parent##_get_##fieldname(const parenttype info) {                        \
583     g_return_val_if_fail(G_TYPE_CHECK_INSTANCE_TYPE((info), parentgtype), failval); \
584     return (info)->fieldname;                           \
585   }
586
587 /**
588  * gst_discoverer_stream_info_get_previous:
589  * @info: a #GstDiscovererStreamInfo
590  *
591  * Returns: (transfer full): the previous #GstDiscovererStreamInfo in a chain.
592  * %NULL for starting points. Unref with #gst_discoverer_stream_info_unref
593  * after usage.
594  */
595 GstDiscovererStreamInfo *
596 gst_discoverer_stream_info_get_previous (GstDiscovererStreamInfo * info)
597 {
598   g_return_val_if_fail (GST_IS_DISCOVERER_STREAM_INFO (info), NULL);
599
600   if (info->previous)
601     return gst_discoverer_stream_info_ref (info->previous);
602   return NULL;
603 }
604
605 /**
606  * gst_discoverer_stream_info_get_next:
607  * @info: a #GstDiscovererStreamInfo
608  *
609  * Returns: (transfer full): the next #GstDiscovererStreamInfo in a chain. %NULL
610  * for final streams.
611  * Unref with #gst_discoverer_stream_info_unref after usage.
612  */
613 GstDiscovererStreamInfo *
614 gst_discoverer_stream_info_get_next (GstDiscovererStreamInfo * info)
615 {
616   g_return_val_if_fail (GST_IS_DISCOVERER_STREAM_INFO (info), NULL);
617
618   if (info->next)
619     return gst_discoverer_stream_info_ref (info->next);
620   return NULL;
621 }
622
623
624 /**
625  * gst_discoverer_stream_info_get_caps:
626  * @info: a #GstDiscovererStreamInfo
627  *
628  * Returns: (transfer full): the #GstCaps of the stream. Unref with
629  * #gst_caps_unref after usage.
630  */
631 GstCaps *
632 gst_discoverer_stream_info_get_caps (GstDiscovererStreamInfo * info)
633 {
634   g_return_val_if_fail (GST_IS_DISCOVERER_STREAM_INFO (info), NULL);
635
636   if (info->caps)
637     return gst_caps_ref (info->caps);
638   return NULL;
639 }
640
641 /**
642  * gst_discoverer_stream_info_get_tags:
643  * @info: a #GstDiscovererStreamInfo
644  *
645  * Returns: (transfer none): the tags contained in this stream. If you wish to
646  * use the tags after the life-time of @info you will need to copy them.
647  */
648 const GstTagList *
649 gst_discoverer_stream_info_get_tags (GstDiscovererStreamInfo * info)
650 {
651   g_return_val_if_fail (GST_IS_DISCOVERER_STREAM_INFO (info), NULL);
652
653   return info->tags;
654 }
655
656 /**
657  * gst_discoverer_stream_info_get_toc:
658  * @info: a #GstDiscovererStreamInfo
659  *
660  * Returns: (transfer none): the TOC contained in this stream. If you wish to
661  * use the TOC after the life-time of @info you will need to copy it.
662  */
663 const GstToc *
664 gst_discoverer_stream_info_get_toc (GstDiscovererStreamInfo * info)
665 {
666   g_return_val_if_fail (GST_IS_DISCOVERER_STREAM_INFO (info), NULL);
667
668   return info->toc;
669 }
670
671 /**
672  * gst_discoverer_stream_info_get_stream_id:
673  * @info: a #GstDiscovererStreamInfo
674  *
675  * Returns: (transfer none): the stream ID of this stream. If you wish to
676  * use the stream ID after the life-time of @info you will need to copy it.
677  */
678 const gchar *
679 gst_discoverer_stream_info_get_stream_id (GstDiscovererStreamInfo * info)
680 {
681   g_return_val_if_fail (GST_IS_DISCOVERER_STREAM_INFO (info), NULL);
682
683   return info->stream_id;
684 }
685
686 /**
687  * gst_discoverer_stream_info_get_misc:
688  * @info: a #GstDiscovererStreamInfo
689  *
690  * Returns: (transfer none): additional information regarding the stream (for
691  * example codec version, profile, etc..). If you wish to use the #GstStructure
692  * after the life-time of @info you will need to copy it.
693  */
694 const GstStructure *
695 gst_discoverer_stream_info_get_misc (GstDiscovererStreamInfo * info)
696 {
697   g_return_val_if_fail (GST_IS_DISCOVERER_STREAM_INFO (info), NULL);
698
699   return info->misc;
700 }
701
702 /* GstDiscovererContainerInfo */
703
704 /**
705  * gst_discoverer_container_info_get_streams:
706  * @info: a #GstDiscovererStreamInfo
707  *
708  * Returns: (transfer full) (element-type GstPbutils.DiscovererStreamInfo): the list of
709  * #GstDiscovererStreamInfo this container stream offers.
710  * Free with gst_discoverer_stream_info_list_free() after usage.
711  */
712
713 GList *
714 gst_discoverer_container_info_get_streams (GstDiscovererContainerInfo * info)
715 {
716   GList *res = NULL, *tmp;
717
718   g_return_val_if_fail (GST_IS_DISCOVERER_CONTAINER_INFO (info), NULL);
719
720   for (tmp = info->streams; tmp; tmp = tmp->next)
721     res =
722         g_list_append (res,
723         gst_discoverer_stream_info_ref ((GstDiscovererStreamInfo *) tmp->data));
724
725   return res;
726 }
727
728 /* GstDiscovererAudioInfo */
729
730 #define AUDIO_INFO_ACCESSOR_CODE(fieldname, type, failval)              \
731   GENERIC_ACCESSOR_CODE(gst_discoverer_audio_info, GstDiscovererAudioInfo*, \
732                         GST_TYPE_DISCOVERER_AUDIO_INFO,         \
733                         fieldname, type, failval)
734
735 /**
736  * gst_discoverer_audio_info_get_channels:
737  * @info: a #GstDiscovererAudioInfo
738  *
739  * Returns: the number of channels in the stream.
740  */
741
742 AUDIO_INFO_ACCESSOR_CODE (channels, guint, 0);
743
744 /**
745  * gst_discoverer_audio_info_get_sample_rate:
746  * @info: a #GstDiscovererAudioInfo
747  *
748  * Returns: the sample rate of the stream in Hertz.
749  */
750
751 AUDIO_INFO_ACCESSOR_CODE (sample_rate, guint, 0);
752
753 /**
754  * gst_discoverer_audio_info_get_depth:
755  * @info: a #GstDiscovererAudioInfo
756  *
757  * Returns: the number of bits used per sample in each channel.
758  */
759
760 AUDIO_INFO_ACCESSOR_CODE (depth, guint, 0);
761
762 /**
763  * gst_discoverer_audio_info_get_bitrate:
764  * @info: a #GstDiscovererAudioInfo
765  *
766  * Returns: the average or nominal bitrate of the stream in bits/second.
767  */
768
769 AUDIO_INFO_ACCESSOR_CODE (bitrate, guint, 0);
770
771 /**
772  * gst_discoverer_audio_info_get_max_bitrate:
773  * @info: a #GstDiscovererAudioInfo
774  *
775  * Returns: the maximum bitrate of the stream in bits/second.
776  */
777
778 AUDIO_INFO_ACCESSOR_CODE (max_bitrate, guint, 0);
779
780 /**
781  * gst_discoverer_audio_info_get_language:
782  * @info: a #GstDiscovererAudioInfo
783  *
784  * Returns: the language of the stream, or NULL if unknown.
785  */
786
787 AUDIO_INFO_ACCESSOR_CODE (language, const gchar *, NULL);
788
789 /* GstDiscovererVideoInfo */
790
791 #define VIDEO_INFO_ACCESSOR_CODE(fieldname, type, failval)              \
792   GENERIC_ACCESSOR_CODE(gst_discoverer_video_info, GstDiscovererVideoInfo*, \
793                         GST_TYPE_DISCOVERER_VIDEO_INFO,                 \
794                         fieldname, type, failval)
795
796 /**
797  * gst_discoverer_video_info_get_width:
798  * @info: a #GstDiscovererVideoInfo
799  *
800  * Returns: the width of the video stream in pixels.
801  */
802
803 VIDEO_INFO_ACCESSOR_CODE (width, guint, 0);
804
805 /**
806  * gst_discoverer_video_info_get_height:
807  * @info: a #GstDiscovererVideoInfo
808  *
809  * Returns: the height of the video stream in pixels.
810  */
811
812 VIDEO_INFO_ACCESSOR_CODE (height, guint, 0);
813
814 /**
815  * gst_discoverer_video_info_get_depth:
816  * @info: a #GstDiscovererVideoInfo
817  *
818  * Returns: the depth in bits of the video stream.
819  */
820
821 VIDEO_INFO_ACCESSOR_CODE (depth, guint, 0);
822
823 /**
824  * gst_discoverer_video_info_get_framerate_num:
825  * @info: a #GstDiscovererVideoInfo
826  *
827  * Returns: the framerate of the video stream (numerator).
828  */
829
830 VIDEO_INFO_ACCESSOR_CODE (framerate_num, guint, 0);
831
832 /**
833  * gst_discoverer_video_info_get_framerate_denom:
834  * @info: a #GstDiscovererVideoInfo
835  *
836  * Returns: the framerate of the video stream (denominator).
837  */
838
839 VIDEO_INFO_ACCESSOR_CODE (framerate_denom, guint, 0);
840
841 /**
842  * gst_discoverer_video_info_get_par_num:
843  * @info: a #GstDiscovererVideoInfo
844  *
845  * Returns: the Pixel Aspect Ratio (PAR) of the video stream (numerator).
846  */
847
848 VIDEO_INFO_ACCESSOR_CODE (par_num, guint, 0);
849
850 /**
851  * gst_discoverer_video_info_get_par_denom:
852  * @info: a #GstDiscovererVideoInfo
853  *
854  * Returns: the Pixel Aspect Ratio (PAR) of the video stream (denominator).
855  */
856
857 VIDEO_INFO_ACCESSOR_CODE (par_denom, guint, 0);
858
859 /**
860  * gst_discoverer_video_info_is_interlaced:
861  * @info: a #GstDiscovererVideoInfo
862  *
863  * Returns: %TRUE if the stream is interlaced, else %FALSE.
864  */
865 gboolean
866 gst_discoverer_video_info_is_interlaced (const GstDiscovererVideoInfo * info)
867 {
868   g_return_val_if_fail (GST_IS_DISCOVERER_VIDEO_INFO (info), FALSE);
869
870   return info->interlaced;
871 }
872
873 /**
874  * gst_discoverer_video_info_get_bitrate:
875  * @info: a #GstDiscovererVideoInfo
876  *
877  * Returns: the average or nominal bitrate of the video stream in bits/second.
878  */
879
880 VIDEO_INFO_ACCESSOR_CODE (bitrate, guint, 0);
881
882 /**
883  * gst_discoverer_video_info_get_max_bitrate:
884  * @info: a #GstDiscovererVideoInfo
885  *
886  * Returns: the maximum bitrate of the video stream in bits/second.
887  */
888
889 VIDEO_INFO_ACCESSOR_CODE (max_bitrate, guint, 0);
890
891 /**
892  * gst_discoverer_video_info_is_image:
893  * @info: a #GstDiscovererVideoInfo
894  *
895  * Returns: #TRUE if the video stream corresponds to an image (i.e. only contains
896  * one frame).
897  */
898 gboolean
899 gst_discoverer_video_info_is_image (const GstDiscovererVideoInfo * info)
900 {
901   g_return_val_if_fail (GST_IS_DISCOVERER_VIDEO_INFO (info), FALSE);
902
903   return info->is_image;
904 }
905
906 /* GstDiscovererSubtitleInfo */
907
908 #define SUBTITLE_INFO_ACCESSOR_CODE(fieldname, type, failval)                     \
909   GENERIC_ACCESSOR_CODE(gst_discoverer_subtitle_info, GstDiscovererSubtitleInfo*, \
910                         GST_TYPE_DISCOVERER_SUBTITLE_INFO,                        \
911                         fieldname, type, failval)
912
913 /**
914  * gst_discoverer_subtitle_info_get_language:
915  * @info: a #GstDiscovererSubtitleInfo
916  *
917  * Returns: the language of the stream, or NULL if unknown.
918  */
919
920 SUBTITLE_INFO_ACCESSOR_CODE (language, const gchar *, NULL);
921
922 /* GstDiscovererInfo */
923
924 #define DISCOVERER_INFO_ACCESSOR_CODE(fieldname, type, failval)         \
925   GENERIC_ACCESSOR_CODE(gst_discoverer_info, GstDiscovererInfo*,        \
926                         GST_TYPE_DISCOVERER_INFO,                       \
927                         fieldname, type, failval)
928
929 /**
930  * gst_discoverer_info_get_uri:
931  * @info: a #GstDiscovererInfo
932  *
933  * Returns: (transfer none): the URI to which this information corresponds to.
934  * Copy it if you wish to use it after the life-time of @info.
935  */
936
937 DISCOVERER_INFO_ACCESSOR_CODE (uri, const gchar *, NULL);
938
939 /**
940  * gst_discoverer_info_get_result:
941  * @info: a #GstDiscovererInfo
942  *
943  * Returns: the result of the discovery as a #GstDiscovererResult.
944  */
945
946 DISCOVERER_INFO_ACCESSOR_CODE (result, GstDiscovererResult, GST_DISCOVERER_OK);
947
948 /**
949  * gst_discoverer_info_get_stream_info:
950  * @info: a #GstDiscovererInfo
951  *
952  * Returns: (transfer full): the structure (or topology) of the URI as a
953  * #GstDiscovererStreamInfo.
954  * This structure can be traversed to see the original hierarchy. Unref with
955  * gst_discoverer_stream_info_unref() after usage.
956  */
957
958 GstDiscovererStreamInfo *
959 gst_discoverer_info_get_stream_info (GstDiscovererInfo * info)
960 {
961   g_return_val_if_fail (GST_IS_DISCOVERER_INFO (info), NULL);
962
963   if (info->stream_info)
964     return gst_discoverer_stream_info_ref (info->stream_info);
965   return NULL;
966 }
967
968 /**
969  * gst_discoverer_info_get_stream_list:
970  * @info: a #GstDiscovererInfo
971  *
972  * Returns: (transfer full) (element-type GstPbutils.DiscovererStreamInfo): the list of
973  * all streams contained in the #info. Free after usage
974  * with gst_discoverer_stream_info_list_free().
975  */
976 GList *
977 gst_discoverer_info_get_stream_list (GstDiscovererInfo * info)
978 {
979   GList *res = NULL, *tmp;
980
981   g_return_val_if_fail (GST_IS_DISCOVERER_INFO (info), NULL);
982
983   for (tmp = info->stream_list; tmp; tmp = tmp->next)
984     res =
985         g_list_append (res,
986         gst_discoverer_stream_info_ref ((GstDiscovererStreamInfo *) tmp->data));
987
988   return res;
989 }
990
991 /**
992  * gst_discoverer_info_get_duration:
993  * @info: a #GstDiscovererInfo
994  *
995  * Returns: the duration of the URI in #GstClockTime (nanoseconds).
996  */
997
998 DISCOVERER_INFO_ACCESSOR_CODE (duration, GstClockTime, GST_CLOCK_TIME_NONE);
999
1000 /**
1001  * gst_discoverer_info_get_seekable:
1002  * @info: a #GstDiscovererInfo
1003  *
1004  * Returns: the whether the URI is seekable.
1005  */
1006
1007 DISCOVERER_INFO_ACCESSOR_CODE (seekable, gboolean, FALSE);
1008
1009 /**
1010  * gst_discoverer_info_get_misc:
1011  * @info: a #GstDiscovererInfo
1012  *
1013  * Returns: (transfer none): Miscellaneous information stored as a #GstStructure
1014  * (for example: information about missing plugins). If you wish to use the
1015  * #GstStructure after the life-time of @info, you will need to copy it.
1016  */
1017
1018 DISCOVERER_INFO_ACCESSOR_CODE (misc, const GstStructure *, NULL);
1019
1020 /**
1021  * gst_discoverer_info_get_tags:
1022  * @info: a #GstDiscovererInfo
1023  *
1024  * Returns: (transfer none): all tags contained in the URI. If you wish to use
1025  * the tags after the life-time of @info, you will need to copy them.
1026  */
1027
1028 DISCOVERER_INFO_ACCESSOR_CODE (tags, const GstTagList *, NULL);
1029
1030 /**
1031  * gst_discoverer_info_get_toc:
1032  * @info: a #GstDiscovererInfo
1033  *
1034  * Returns: (transfer none): TOC contained in the URI. If you wish to use
1035  * the TOC after the life-time of @info, you will need to copy it.
1036  */
1037
1038 DISCOVERER_INFO_ACCESSOR_CODE (toc, const GstToc *, NULL);
1039
1040 /**
1041  * gst_discoverer_info_ref:
1042  * @info: a #GstDiscovererInfo
1043  *
1044  * Increments the reference count of @info.
1045  *
1046  * Returns: the same #GstDiscovererInfo object
1047  */
1048
1049 /**
1050  * gst_discoverer_info_unref:
1051  * @info: a #GstDiscovererInfo
1052  *
1053  * Decrements the reference count of @info.
1054  */
1055
1056 /**
1057  * gst_discoverer_stream_info_ref:
1058  * @info: a #GstDiscovererStreamInfo
1059  *
1060  * Increments the reference count of @info.
1061  *
1062  * Returns: the same #GstDiscovererStreamInfo object
1063  */
1064
1065 /**
1066  * gst_discoverer_stream_info_unref:
1067  * @info: a #GstDiscovererStreamInfo
1068  *
1069  * Decrements the reference count of @info.
1070  */