Release 4.0.0-preview1-00271
[platform/core/csapi/tizenfx.git] / src / Tizen.Multimedia.Metadata / MetadataExtractor / Metadata.cs
1 /*
2  * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
3  *
4  * Licensed under the Apache License, Version 2.0 (the License);
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an AS IS BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 using System;
18 using System.Diagnostics;
19 using static Interop.MetadataExtractor;
20
21 namespace Tizen.Multimedia
22 {
23     /// <summary>
24     /// Represents the video metadata information.
25     /// </summary>
26     public class VideoMetadata
27     {
28         private VideoMetadata(int streamCount, MetadataExtractor extractor)
29         {
30             Debug.Assert(streamCount > 0);
31
32             StreamCount = streamCount;
33             BitRate = ValueConverter.ToNullableInt(extractor.GetMetadata(MetadataExtractorAttr.VideoBitrate));
34             Fps = ValueConverter.ToNullableInt(extractor.GetMetadata(MetadataExtractorAttr.VideoFps));
35             Width = ValueConverter.ToNullableInt(extractor.GetMetadata(MetadataExtractorAttr.VideoWidth));
36             Height = ValueConverter.ToNullableInt(extractor.GetMetadata(MetadataExtractorAttr.VideoHeight));
37             Codec = extractor.GetMetadata(MetadataExtractorAttr.VideoCodec);
38
39             _description = new Lazy<string>(() => ObjectDescriptionBuilder.BuildWithProperties(this));
40         }
41
42         internal static VideoMetadata From(MetadataExtractor extractor)
43         {
44             var streamCount = ValueConverter.ToInt(extractor.GetMetadata(MetadataExtractorAttr.VideoStreamCount));
45
46             return streamCount > 0 ? new VideoMetadata(streamCount, extractor) : null;
47         }
48
49         /// <summary>
50         /// Gets the bitrate.
51         /// </summary>
52         /// <since_tizen> 3 </since_tizen>
53         /// <value>The bitrate value, or null if the information does not exist.</value>
54         public int? BitRate { get; }
55
56         /// <summary>
57         /// Gets the video fps.
58         /// </summary>
59         /// <since_tizen> 3 </since_tizen>
60         /// <value>The fps value, or null if the information does not exist.</value>
61         public int? Fps { get; }
62
63         /// <summary>
64         /// Gets the width of the video.
65         /// </summary>
66         /// <since_tizen> 3 </since_tizen>
67         /// <value>The width value, or null if the information does not exist.</value>
68         public int? Width { get; }
69
70         /// <summary>
71         /// Gets the height of the video.
72         /// </summary>
73         /// <since_tizen> 3 </since_tizen>
74         /// <value>The height value, or null if the information does not exist.</value>
75         public int? Height { get; }
76
77         /// <summary>
78         /// Gets the codec type of the video.
79         /// </summary>
80         /// <since_tizen> 3 </since_tizen>
81         /// <value>A string representing the codec type, or null if the information does not exist.</value>
82         public string Codec { get; }
83
84         /// <summary>
85         /// Gets the video stream count.
86         /// </summary>
87         /// <since_tizen> 3 </since_tizen>
88         /// <value>The number of video streams.</value>
89         public int StreamCount { get; }
90
91         private Lazy<string> _description;
92
93         /// <summary>
94         /// Returns a string that represents the current object.
95         /// </summary>
96         /// <returns>A string that represents the current object.</returns>
97         public override string ToString() => _description.Value;
98     }
99
100     /// <summary>
101     /// Represents the audio metadata information.
102     /// </summary>
103     public class AudioMetadata
104     {
105         private AudioMetadata(int streamCount, MetadataExtractor extractor)
106         {
107             Debug.Assert(streamCount > 0);
108
109             StreamCount = streamCount;
110             BitRate = ValueConverter.ToNullableInt(extractor.GetMetadata(MetadataExtractorAttr.AudioBitrate));
111             Channels = ValueConverter.ToNullableInt(extractor.GetMetadata(MetadataExtractorAttr.AudioChannels));
112             SampleRate = ValueConverter.ToNullableInt(extractor.GetMetadata(MetadataExtractorAttr.AudioSamplerate));
113             BitPerSample = ValueConverter.ToNullableInt(extractor.GetMetadata(MetadataExtractorAttr.AudioBitPerSample));
114             Codec = extractor.GetMetadata(MetadataExtractorAttr.AudioCodec);
115
116             _description = new Lazy<string>(() => ObjectDescriptionBuilder.BuildWithProperties(this));
117         }
118
119         internal static AudioMetadata From(MetadataExtractor extractor)
120         {
121             var streamCount = ValueConverter.ToInt(extractor.GetMetadata(MetadataExtractorAttr.AudioStreamCount));
122
123             return streamCount > 0 ? new AudioMetadata(streamCount, extractor) : null;
124         }
125
126         /// <summary>
127         /// Gets the audio bitrate.
128         /// </summary>
129         /// <since_tizen> 3 </since_tizen>
130         /// <value>The bit rate value, or null if the information does not exist.</value>
131         public int? BitRate { get; }
132
133         /// <summary>
134         /// Gets the audio channels.
135         /// </summary>
136         /// <since_tizen> 3 </since_tizen>
137         /// <value>The number of the audio channels, or null if the information does not exist.</value>
138         public int? Channels { get; }
139
140         /// <summary>
141         /// Gets the audio sample rate.
142         /// </summary>
143         /// <since_tizen> 3 </since_tizen>
144         /// <value>The sample rate, or null if the information does not exist.</value>
145         public int? SampleRate { get; }
146
147         /// <summary>
148         /// Gets the bit per sample of the audio.
149         /// </summary>
150         /// <since_tizen> 3 </since_tizen>
151         /// <value>The bit per sample, or null if the information does not exist.</value>
152         public int? BitPerSample { get; }
153
154         /// <summary>
155         /// Gets the audio stream count.
156         /// </summary>
157         /// <since_tizen> 3 </since_tizen>
158         /// <value>The number of audio streams.</value>
159         public int StreamCount { get; }
160
161         /// <summary>
162         /// Gets the audio codec type.
163         /// </summary>
164         /// <since_tizen> 3 </since_tizen>
165         public string Codec { get; }
166
167         private Lazy<string> _description;
168
169         /// <summary>
170         /// Returns a string that represents the current object.
171         /// </summary>
172         /// <returns>A string that represents the current object.</returns>
173         public override string ToString() => _description.Value;
174     }
175
176     /// <summary>
177     /// Represents the metadata information of a media.
178     /// </summary>
179     public class Metadata
180     {
181         internal Metadata(MetadataExtractor extractor)
182         {
183             Debug.Assert(extractor != null);
184
185             Video = VideoMetadata.From(extractor);
186             Audio = AudioMetadata.From(extractor);
187
188             Duration = ValueConverter.ToNullableInt(extractor.GetMetadata(MetadataExtractorAttr.Duration));
189             Artist = extractor.GetMetadata(MetadataExtractorAttr.Artist);
190             Title = extractor.GetMetadata(MetadataExtractorAttr.Title);
191             Album = extractor.GetMetadata(MetadataExtractorAttr.Album);
192             AlbumArtist = extractor.GetMetadata(MetadataExtractorAttr.AlbumArtist);
193             Genre = extractor.GetMetadata(MetadataExtractorAttr.Genre);
194             Author = extractor.GetMetadata(MetadataExtractorAttr.Author);
195             Copyright = extractor.GetMetadata(MetadataExtractorAttr.Copyright);
196             DateReleased = extractor.GetMetadata(MetadataExtractorAttr.ReleaseDate);
197             Description = extractor.GetMetadata(MetadataExtractorAttr.Description);
198             Comment = extractor.GetMetadata(MetadataExtractorAttr.Comment);
199             TrackNumber = extractor.GetMetadata(MetadataExtractorAttr.TrackNum);
200             Classification = extractor.GetMetadata(MetadataExtractorAttr.Classification);
201             Rating = extractor.GetMetadata(MetadataExtractorAttr.Rating);
202             Longitude = ValueConverter.ToNullableDouble(extractor.GetMetadata(MetadataExtractorAttr.Longitude));
203             Latitude = ValueConverter.ToNullableDouble(extractor.GetMetadata(MetadataExtractorAttr.Latitude));
204             Altitude = ValueConverter.ToNullableDouble(extractor.GetMetadata(MetadataExtractorAttr.Altitude));
205             Conductor = extractor.GetMetadata(MetadataExtractorAttr.Conductor);
206             UnsyncLyrics = extractor.GetMetadata(MetadataExtractorAttr.UnSyncLyrics);
207             SyncLyricsCount = ValueConverter.ToInt(extractor.GetMetadata(MetadataExtractorAttr.SyncLyricsNum));
208             DateRecorded = extractor.GetMetadata(MetadataExtractorAttr.RecordingDate);
209             Rotation = extractor.GetMetadata(MetadataExtractorAttr.Rotate);
210             Content360 = extractor.GetMetadata(MetadataExtractorAttr.ContentFor360);
211
212             _description = new Lazy<string>(() => ObjectDescriptionBuilder.BuildWithProperties(this));
213         }
214
215         /// <summary>
216         /// Gets the duration of the media.
217         /// </summary>
218         /// <since_tizen> 3 </since_tizen>
219         /// <value>The duration value, or null if the information does not exist.</value>
220         public int? Duration { get; }
221
222         /// <summary>
223         /// Gets the video metadata.
224         /// </summary>
225         /// <since_tizen> 3 </since_tizen>
226         /// <value>The video metadata, or null if the information does not exist.</value>
227         public VideoMetadata Video { get; }
228
229         /// <summary>
230         /// Gets the audio metadata.
231         /// </summary>
232         /// <since_tizen> 3 </since_tizen>
233         /// <value>The audio metadata, or null if the information does not exist.</value>
234         public AudioMetadata Audio { get; }
235
236         /// <summary>
237         /// Gets the artist of the media.
238         /// </summary>
239         /// <since_tizen> 3 </since_tizen>
240         /// <value>A string representing the artist, or null if the information does not exist.</value>
241         public string Artist { get; }
242
243         /// <summary>
244         /// Gets the title of the media.
245         /// </summary>
246         /// <since_tizen> 3 </since_tizen>
247         /// <value>A string representing the title, or null if the information does not exist.</value>
248         public string Title { get; }
249
250         /// <summary>
251         /// Gets the album name of the media.
252         /// </summary>
253         /// <since_tizen> 3 </since_tizen>
254         /// <value>A string representing the album name, or null if the information does not exist.</value>
255         public string Album { get; }
256
257         /// <summary>
258         /// Gets the album artist of the media.
259         /// </summary>
260         /// <since_tizen> 3 </since_tizen>
261         /// <value>A string representing the album artist, or null if the information does not exist.</value>
262         public string AlbumArtist { get; }
263
264         /// <summary>
265         /// Gets the genre of the media.
266         /// </summary>
267         /// <since_tizen> 3 </since_tizen>
268         /// <value>A string representing the genre, or null if the information does not exist.</value>
269         public string Genre { get; }
270
271         /// <summary>
272         /// Gets the author of the media.
273         /// </summary>
274         /// <since_tizen> 3 </since_tizen>
275         /// <value>A string representing the author, or null if the information does not exist.</value>
276         public string Author { get; }
277
278         /// <summary>
279         /// Gets the copyright of the media.
280         /// </summary>
281         /// <since_tizen> 3 </since_tizen>
282         /// <value>A string representing the copyright, or null if the information does not exist.</value>
283         public string Copyright { get; }
284
285         /// <summary>
286         /// Gets the release date of the media.
287         /// </summary>
288         /// <since_tizen> 3 </since_tizen>
289         /// <value>A string representing the release date, or null if the information does not exist.</value>
290         public string DateReleased { get; }
291
292         /// <summary>
293         /// Gets the description of the media.
294         /// </summary>
295         /// <since_tizen> 3 </since_tizen>
296         /// <value>A string representing the description, or null if the information does not exist.</value>
297         public string Description { get; }
298
299         /// <summary>
300         /// Gets the comment of the media.
301         /// </summary>
302         /// <since_tizen> 3 </since_tizen>
303         /// <value>A string representing the comment, or null if the information does not exist.</value>
304         public string Comment { get; }
305
306         /// <summary>
307         /// Gets the track number of the media.
308         /// </summary>
309         /// <since_tizen> 3 </since_tizen>
310         /// <value>A string representing the track number, or null if the information does not exist.</value>
311         public string TrackNumber { get; }
312
313         /// <summary>
314         /// Gets the classification of the media.
315         /// </summary>
316         /// <since_tizen> 3 </since_tizen>
317         /// <value>A string representing the classification, or null if the information does not exist.</value>
318         public string Classification { get; }
319
320         /// <summary>
321         /// Gets the rating of the media.
322         /// </summary>
323         /// <since_tizen> 3 </since_tizen>
324         /// <value>A string representing the rating, or null if the information does not exist.</value>
325         public string Rating { get; }
326
327         /// <summary>
328         /// Gets the longitude of the media.
329         /// </summary>
330         /// <since_tizen> 3 </since_tizen>
331         /// <value>The longitude value, or null if the information does not exist.</value>
332         public double? Longitude { get; }
333
334         /// <summary>
335         /// Gets the latitude of the media.
336         /// </summary>
337         /// <since_tizen> 3 </since_tizen>
338         /// <value>The latitude value, or null if the information does not exist.</value>
339         public double? Latitude { get; }
340
341         /// <summary>
342         /// Gets the altitude of the media.
343         /// </summary>
344         /// <since_tizen> 3 </since_tizen>
345         /// <value>The altitude value, or null if the information does not exist.</value>
346         public double? Altitude { get; }
347
348         /// <summary>
349         /// Gets the conductor of the media.
350         /// </summary>
351         /// <since_tizen> 3 </since_tizen>
352         /// <value>A string representing the conductor, or null if the information does not exist.</value>
353         public string Conductor { get; }
354
355         /// <summary>
356         /// Gets the unsynchronized lyrics of the media.
357         /// </summary>
358         /// <since_tizen> 3 </since_tizen>
359         /// <value>A string representing the unsynchronized lyrics, or null if the information does not exist.</value>
360         public string UnsyncLyrics { get; }
361
362         /// <summary>
363         /// Gets the number of synchronized lyrics of the media.
364         /// </summary>
365         /// <since_tizen> 3 </since_tizen>
366         /// <value>The number of the synchronized lyrics.</value>
367         public int SyncLyricsCount { get; }
368
369         /// <summary>
370         /// Gets the recording date of the media.
371         /// </summary>
372         /// <since_tizen> 3 </since_tizen>
373         /// <value>A string representing the recording date, or null if the information does not exist.</value>
374         public string DateRecorded { get; }
375
376         /// <summary>
377         /// Gets the rotate(orientation) information of the media.
378         /// </summary>
379         /// <since_tizen> 3 </since_tizen>
380         /// <value>A string representing the rotation information, or null if the information does not exist.</value>
381         public string Rotation { get; }
382
383         /// <summary>
384         /// Gets the information for 360 content of the media.
385         /// </summary>
386         /// <since_tizen> 3 </since_tizen>
387         /// <value>A string representing the information for 360 content, or null if the information does not exist.</value>
388         public string Content360 { get; }
389
390         private Lazy<string> _description;
391
392         /// <summary>
393         /// Returns a string that represents the current object.
394         /// </summary>
395         /// <returns>A string that represents the current object.</returns>
396         public override string ToString() => _description.Value;
397     }
398 }