2 * Copyright (C) 2008 Zeeshan Ali <zeenix@gmail.com>.
3 * Copyright (C) 2008 Nokia Corporation.
5 * Author: Zeeshan Ali <zeenix@gmail.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.
28 * Represents MediaExport item.
30 public class Rygel.MediaExport.Item : Rygel.MediaItem {
31 public Item.simple (MediaContainer parent,
36 string id = Checksum.compute_for_string (ChecksumType.MD5,
38 var title = file.get_basename ();
41 if (mime.has_prefix ("video/")) {
42 upnp_class = MediaItem.VIDEO_CLASS;
43 } else if (mime.has_prefix ("image/")) {
44 upnp_class = MediaItem.PHOTO_CLASS;
46 upnp_class = MediaItem.AUDIO_CLASS;
49 base (id, parent, title, upnp_class);
50 this.mime_type = mime;
51 this.add_uri (file.get_uri (), null);
54 public static Item? create_from_info (MediaContainer parent,
56 GUPnP.DLNAInformation dlna_info,
60 string id = Checksum.compute_for_string (ChecksumType.MD5,
62 unowned StreamAudioInformation audio_info = null;
63 unowned StreamVideoInformation video_info = null;
65 foreach (unowned StreamInformation stream_info in
66 dlna_info.info.stream_list) {
67 if (audio_info == null &&
68 stream_info.streamtype == Gst.StreamType.AUDIO) {
69 audio_info = (StreamAudioInformation) stream_info;
70 } else if (video_info == null &&
71 (stream_info.streamtype == Gst.StreamType.VIDEO ||
72 stream_info.streamtype == Gst.StreamType.IMAGE)) {
73 video_info = (StreamVideoInformation) stream_info;
77 if (video_info != null) {
78 if (audio_info == null &&
79 video_info.streamtype == Gst.StreamType.IMAGE) {
80 return new Item.photo (parent,
89 return new Item.video (parent,
99 } else if (audio_info != null) {
100 return new Item.audio (parent,
113 private Item.video (MediaContainer parent,
116 GUPnP.DLNAInformation dlna_info,
117 Gst.StreamVideoInformation video_info,
118 Gst.StreamAudioInformation? audio_info,
129 MediaItem.VIDEO_CLASS);
131 this.width = (int) video_info.width;
132 this.height = (int) video_info.height;
133 this.color_depth = (int) video_info.depth;
135 if (video_info.tags != null) {
138 video_info.tags.get_uint (TAG_BITRATE, out tmp);
139 this.bitrate = (int) tmp / 8;
142 if (audio_info != null) {
143 this.n_audio_channels = (int) audio_info.channels;
144 this.sample_freq = (int) audio_info.sample_rate;
148 private Item.photo (MediaContainer parent,
151 GUPnP.DLNAInformation dlna_info,
152 Gst.StreamVideoInformation video_info,
163 MediaItem.PHOTO_CLASS);
165 this.width = (int) video_info.width;
166 this.height = (int) video_info.height;
167 this.color_depth = (int) video_info.depth;
170 private Item.audio (MediaContainer parent,
173 GUPnP.DLNAInformation dlna_info,
174 Gst.StreamAudioInformation audio_info,
185 MediaItem.MUSIC_CLASS);
187 this.n_audio_channels = (int) audio_info.channels;
188 this.sample_freq = (int) audio_info.sample_rate;
191 private Item (MediaContainer parent,
194 GUPnP.DLNAInformation dlna_info,
201 if (dlna_info.info.tags == null ||
202 !dlna_info.info.tags.get_string (TAG_TITLE, out title)) {
203 title = file.get_basename ();
206 base (id, parent, title, upnp_class);
208 if (dlna_info.info.duration > -1) {
209 this.duration = dlna_info.info.duration / Gst.SECOND;
214 if (dlna_info.info.tags != null) {
215 dlna_info.info.tags.get_string (TAG_ARTIST, out this.author);
216 dlna_info.info.tags.get_string (TAG_ALBUM, out this.album);
219 dlna_info.info.tags.get_uint (TAG_TRACK_NUMBER, out tmp);
220 this.track_number = (int) tmp;
223 if (dlna_info.info.tags.get_date (TAG_DATE, out date)) {
224 char[] datestr = new char[30];
225 date.strftime (datestr, "%F");
226 this.date = (string) datestr;
228 TimeVal tv = { (long) mtime, 0 };
229 this.date = tv.to_iso8601 ();
233 this.size = (long) size;
234 this.modified = (int64) mtime;
236 if (dlna_info.name != null) {
237 this.dlna_profile = dlna_info.name;
238 this.mime_type = dlna_info.mime;
240 this.mime_type = mime;
243 this.add_uri (file.get_uri (), null);