2 * Copyright (C) 2012 Openismus GmbH.
3 * Copyright (C) 2012 Intel Corporation.
5 * Author: Jens Georg <jensg@openismus.com>
7 * This file is part of Rygel.
9 * Rygel is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU Lesser General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * Rygel is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU Lesser General Public License for more details.
19 * You should have received a copy of the GNU Lesser General Public License
20 * along with this program; if not, write to the Free Software Foundation,
21 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
25 * Demo application for librygel-server.
27 * Creates a stand-alone UPnP server that exposes the contents of the current
28 * folder or the folder passed as argument.
31 * standalone-server [<folder>]
33 * The server listens on wlan0 and eth0 by default.
37 #include <rygel-server.h>
38 #include <rygel-core.h>
40 int main (int argc, char *argv[])
42 RygelMediaServer *server;
43 RygelSimpleContainer *root_container;
46 GFileEnumerator *enumerator;
54 rygel_media_engine_init (&error);
57 g_print ("Could not initialize media engine: %s\n",
64 g_set_application_name ("Standalone-Server");
66 root_container = rygel_simple_container_new_root ("Sample implementation");
68 path = g_strdup (argv[1]);
70 path = g_get_current_dir ();
73 source_dir = g_file_new_for_commandline_arg (path);
76 enumerator = g_file_enumerate_children (source_dir,
77 G_FILE_ATTRIBUTE_STANDARD_DISPLAY_NAME ","
78 G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE,
79 G_FILE_QUERY_INFO_NONE,
82 info = g_file_enumerator_next_file (enumerator, NULL, NULL);
84 while (info != NULL) {
86 const char *display_name, *content_type;
88 RygelMediaItem *item = NULL;
91 display_name = g_file_info_get_display_name (info);
92 content_type = g_file_info_get_content_type (info);
93 file = g_file_get_child_for_display_name (source_dir, display_name, &error);
95 g_critical ("Failed to get child: %s", error->message);
99 uri = g_file_get_uri (file);
100 g_object_unref (file);
101 id = g_strdup_printf ("%06d", i);
103 if (g_str_has_prefix (content_type, "audio/")) {
104 item = rygel_audio_item_new (id,
107 RYGEL_AUDIO_ITEM_UPNP_CLASS);
108 } else if (g_str_has_prefix (content_type, "video/")) {
109 item = rygel_video_item_new (id,
112 RYGEL_VIDEO_ITEM_UPNP_CLASS);
113 } else if (g_str_has_prefix (content_type, "image/")) {
114 item = rygel_image_item_new (id,
117 RYGEL_IMAGE_ITEM_UPNP_CLASS);
122 RygelMediaObject *object;
124 RYGEL_MEDIA_ITEM (item)->mime_type = g_strdup (content_type);
126 object = RYGEL_MEDIA_OBJECT (item);
127 gee_collection_add (GEE_COLLECTION (object->uris), uri);
128 rygel_simple_container_add_child_item (root_container, item);
132 info = g_file_enumerator_next_file (enumerator, NULL, NULL);
135 server = rygel_media_server_new ("LibRygel sample server",
137 RYGEL_PLUGIN_CAPABILITIES_NONE);
138 rygel_media_device_add_interface (RYGEL_MEDIA_DEVICE (server), "eth0");
139 rygel_media_device_add_interface (RYGEL_MEDIA_DEVICE (server), "wlan0");
141 loop = g_main_loop_new (NULL, FALSE);
142 g_main_loop_run (loop);