[NUI] TCSACR-226 code change (#1032)
[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     /// <since_tizen> 4 </since_tizen>
27     public class VideoMetadata
28     {
29         private VideoMetadata(int streamCount, MetadataExtractor extractor)
30         {
31             Debug.Assert(streamCount > 0);
32
33             StreamCount = streamCount;
34             BitRate = ValueConverter.ToNullableInt(extractor.GetMetadata(MetadataExtractorAttr.VideoBitrate));
35             Fps = ValueConverter.ToNullableInt(extractor.GetMetadata(MetadataExtractorAttr.VideoFps));
36             Width = ValueConverter.ToNullableInt(extractor.GetMetadata(MetadataExtractorAttr.VideoWidth));
37             Height = ValueConverter.ToNullableInt(extractor.GetMetadata(MetadataExtractorAttr.VideoHeight));
38             Codec = extractor.GetMetadata(MetadataExtractorAttr.VideoCodec);
39
40             _description = new Lazy<string>(() => ObjectDescriptionBuilder.BuildWithProperties(this));
41         }
42
43         internal static VideoMetadata From(MetadataExtractor extractor)
44         {
45             var streamCount = ValueConverter.ToInt(extractor.GetMetadata(MetadataExtractorAttr.VideoStreamCount));
46
47             return streamCount > 0 ? new VideoMetadata(streamCount, extractor) : null;
48         }
49
50         /// <summary>
51         /// Gets the bitrate.
52         /// </summary>
53         /// <since_tizen> 4 </since_tizen>
54         /// <value>The bitrate value, or null if the information does not exist.</value>
55         public int? BitRate { get; }
56
57         /// <summary>
58         /// Gets the video fps.
59         /// </summary>
60         /// <since_tizen> 4 </since_tizen>
61         /// <value>The fps value, or null if the information does not exist.</value>
62         public int? Fps { get; }
63
64         /// <summary>
65         /// Gets the width of the video.
66         /// </summary>
67         /// <since_tizen> 4 </since_tizen>
68         /// <value>The width value, or null if the information does not exist.</value>
69         public int? Width { get; }
70
71         /// <summary>
72         /// Gets the height of the video.
73         /// </summary>
74         /// <since_tizen> 4 </since_tizen>
75         /// <value>The height value, or null if the information does not exist.</value>
76         public int? Height { get; }
77
78         /// <summary>
79         /// Gets the codec type of the video.
80         /// </summary>
81         /// <since_tizen> 4 </since_tizen>
82         /// <value>A string representing the codec type, or null if the information does not exist.</value>
83         public string Codec { get; }
84
85         /// <summary>
86         /// Gets the video stream count.
87         /// </summary>
88         /// <since_tizen> 4 </since_tizen>
89         /// <value>The number of video streams.</value>
90         public int StreamCount { get; }
91
92         private Lazy<string> _description;
93
94         /// <summary>
95         /// Returns a string that represents the current object.
96         /// </summary>
97         /// <returns>A string that represents the current object.</returns>
98         /// <since_tizen> 4 </since_tizen>
99         public override string ToString() => _description.Value;
100     }
101
102     /// <summary>
103     /// Represents the audio metadata information.
104     /// </summary>
105     /// <since_tizen> 4 </since_tizen>
106     public class AudioMetadata
107     {
108         private AudioMetadata(int streamCount, MetadataExtractor extractor)
109         {
110             Debug.Assert(streamCount > 0);
111
112             StreamCount = streamCount;
113             BitRate = ValueConverter.ToNullableInt(extractor.GetMetadata(MetadataExtractorAttr.AudioBitrate));
114             Channels = ValueConverter.ToNullableInt(extractor.GetMetadata(MetadataExtractorAttr.AudioChannels));
115             SampleRate = ValueConverter.ToNullableInt(extractor.GetMetadata(MetadataExtractorAttr.AudioSamplerate));
116             BitPerSample = ValueConverter.ToNullableInt(extractor.GetMetadata(MetadataExtractorAttr.AudioBitPerSample));
117             Codec = extractor.GetMetadata(MetadataExtractorAttr.AudioCodec);
118
119             _description = new Lazy<string>(() => ObjectDescriptionBuilder.BuildWithProperties(this));
120         }
121
122         internal static AudioMetadata From(MetadataExtractor extractor)
123         {
124             var streamCount = ValueConverter.ToInt(extractor.GetMetadata(MetadataExtractorAttr.AudioStreamCount));
125
126             return streamCount > 0 ? new AudioMetadata(streamCount, extractor) : null;
127         }
128
129         /// <summary>
130         /// Gets the audio bitrate.
131         /// </summary>
132         /// <since_tizen> 4 </since_tizen>
133         /// <value>The bit rate value, or null if the information does not exist.</value>
134         public int? BitRate { get; }
135
136         /// <summary>
137         /// Gets the audio channels.
138         /// </summary>
139         /// <since_tizen> 4 </since_tizen>
140         /// <value>The number of the audio channels, or null if the information does not exist.</value>
141         public int? Channels { get; }
142
143         /// <summary>
144         /// Gets the audio sample rate.
145         /// </summary>
146         /// <since_tizen> 4 </since_tizen>
147         /// <value>The sample rate, or null if the information does not exist.</value>
148         public int? SampleRate { get; }
149
150         /// <summary>
151         /// Gets the bit per sample of the audio.
152         /// </summary>
153         /// <since_tizen> 4 </since_tizen>
154         /// <value>The bit per sample, or null if the information does not exist.</value>
155         public int? BitPerSample { get; }
156
157         /// <summary>
158         /// Gets the audio stream count.
159         /// </summary>
160         /// <since_tizen> 4 </since_tizen>
161         /// <value>The number of audio streams.</value>
162         public int StreamCount { get; }
163
164         /// <summary>
165         /// Gets the audio codec type.
166         /// </summary>
167         /// <since_tizen> 4 </since_tizen>
168         public string Codec { get; }
169
170         private Lazy<string> _description;
171
172         /// <summary>
173         /// Returns a string that represents the current object.
174         /// </summary>
175         /// <returns>A string that represents the current object.</returns>
176         /// <since_tizen> 4 </since_tizen>
177         public override string ToString() => _description.Value;
178     }
179
180     /// <summary>
181     /// Represents the metadata information of a media.
182     /// </summary>
183     /// <since_tizen> 3 </since_tizen>
184     public class Metadata
185     {
186         internal Metadata(MetadataExtractor extractor)
187         {
188             Debug.Assert(extractor != null);
189
190             Video = VideoMetadata.From(extractor);
191             Audio = AudioMetadata.From(extractor);
192
193             Duration = ValueConverter.ToNullableInt(extractor.GetMetadata(MetadataExtractorAttr.Duration));
194             Artist = extractor.GetMetadata(MetadataExtractorAttr.Artist);
195             Title = extractor.GetMetadata(MetadataExtractorAttr.Title);
196             Album = extractor.GetMetadata(MetadataExtractorAttr.Album);
197             AlbumArtist = extractor.GetMetadata(MetadataExtractorAttr.AlbumArtist);
198             Genre = extractor.GetMetadata(MetadataExtractorAttr.Genre);
199 #pragma warning disable CS0618 // Type or member is obsolete
200             Author = extractor.GetMetadata(MetadataExtractorAttr.Composer);
201 #pragma warning restore CS0618 // Type or member is obsolete
202             Composer = extractor.GetMetadata(MetadataExtractorAttr.Composer);
203             Copyright = extractor.GetMetadata(MetadataExtractorAttr.Copyright);
204             DateReleased = extractor.GetMetadata(MetadataExtractorAttr.ReleaseDate);
205             Description = extractor.GetMetadata(MetadataExtractorAttr.Description);
206             Comment = extractor.GetMetadata(MetadataExtractorAttr.Comment);
207             TrackNumber = extractor.GetMetadata(MetadataExtractorAttr.TrackNum);
208             Classification = extractor.GetMetadata(MetadataExtractorAttr.Classification);
209             Rating = extractor.GetMetadata(MetadataExtractorAttr.Rating);
210             Longitude = ValueConverter.ToNullableDouble(extractor.GetMetadata(MetadataExtractorAttr.Longitude));
211             Latitude = ValueConverter.ToNullableDouble(extractor.GetMetadata(MetadataExtractorAttr.Latitude));
212             Altitude = ValueConverter.ToNullableDouble(extractor.GetMetadata(MetadataExtractorAttr.Altitude));
213             Conductor = extractor.GetMetadata(MetadataExtractorAttr.Conductor);
214             UnsyncLyrics = extractor.GetMetadata(MetadataExtractorAttr.UnSyncLyrics);
215             SyncLyricsCount = ValueConverter.ToInt(extractor.GetMetadata(MetadataExtractorAttr.SyncLyricsNum));
216             DateRecorded = extractor.GetMetadata(MetadataExtractorAttr.RecordingDate);
217             Rotation = extractor.GetMetadata(MetadataExtractorAttr.Rotate);
218             Content360 = extractor.GetMetadata(MetadataExtractorAttr.ContentFor360);
219
220             _description = new Lazy<string>(() => ObjectDescriptionBuilder.BuildWithProperties(this));
221         }
222
223         /// <summary>
224         /// Gets the duration of the media.
225         /// </summary>
226         /// <since_tizen> 4 </since_tizen>
227         /// <value>The duration value, or null if the information does not exist.</value>
228         public int? Duration { get; }
229
230         /// <summary>
231         /// Gets the video metadata.
232         /// </summary>
233         /// <since_tizen> 4 </since_tizen>
234         /// <value>The video metadata, or null if the information does not exist.</value>
235         public VideoMetadata Video { get; }
236
237         /// <summary>
238         /// Gets the audio metadata.
239         /// </summary>
240         /// <since_tizen> 4 </since_tizen>
241         /// <value>The audio metadata, or null if the information does not exist.</value>
242         public AudioMetadata Audio { get; }
243
244         /// <summary>
245         /// Gets the artist of the media.
246         /// </summary>
247         /// <since_tizen> 3 </since_tizen>
248         /// <value>A string representing the artist, or null if the information does not exist.</value>
249         public string Artist { get; }
250
251         /// <summary>
252         /// Gets the title of the media.
253         /// </summary>
254         /// <since_tizen> 3 </since_tizen>
255         /// <value>A string representing the title, or null if the information does not exist.</value>
256         public string Title { get; }
257
258         /// <summary>
259         /// Gets the album name of the media.
260         /// </summary>
261         /// <since_tizen> 3 </since_tizen>
262         /// <value>A string representing the album name, or null if the information does not exist.</value>
263         public string Album { get; }
264
265         /// <summary>
266         /// Gets the album artist of the media.
267         /// </summary>
268         /// <since_tizen> 3 </since_tizen>
269         /// <value>A string representing the album artist, or null if the information does not exist.</value>
270         public string AlbumArtist { get; }
271
272         /// <summary>
273         /// Gets the genre of the media.
274         /// </summary>
275         /// <since_tizen> 3 </since_tizen>
276         /// <value>A string representing the genre, or null if the information does not exist.</value>
277         public string Genre { get; }
278
279         /// <summary>
280         /// Gets the author of the media.
281         /// </summary>
282         /// <since_tizen> 3 </since_tizen>
283         /// <value>A string representing the author, or null if the information does not exist.</value>
284         [Obsolete("Please do not use! This will be deprecated. Please use Composer instead.")]
285         public string Author { get; }
286
287         /// <summary>
288         /// Gets the composer of the media.
289         /// </summary>
290         /// <since_tizen> 6 </since_tizen>
291         /// <value>A string representing the composer, or null if the information does not exist.</value>
292         public string Composer { get; }
293
294         /// <summary>
295         /// Gets the copyright of the media.
296         /// </summary>
297         /// <since_tizen> 3 </since_tizen>
298         /// <value>A string representing the copyright, or null if the information does not exist.</value>
299         public string Copyright { get; }
300
301         /// <summary>
302         /// Gets the release date of the media.
303         /// </summary>
304         /// <since_tizen> 4 </since_tizen>
305         /// <value>A string representing the release date, or null if the information does not exist.</value>
306         public string DateReleased { get; }
307
308         /// <summary>
309         /// Gets the description of the media.
310         /// </summary>
311         /// <since_tizen> 3 </since_tizen>
312         /// <value>A string representing the description, or null if the information does not exist.</value>
313         public string Description { get; }
314
315         /// <summary>
316         /// Gets the comment of the media.
317         /// </summary>
318         /// <since_tizen> 3 </since_tizen>
319         /// <value>A string representing the comment, or null if the information does not exist.</value>
320         public string Comment { get; }
321
322         /// <summary>
323         /// Gets the track number of the media.
324         /// </summary>
325         /// <since_tizen> 3 </since_tizen>
326         /// <value>A string representing the track number, or null if the information does not exist.</value>
327         public string TrackNumber { get; }
328
329         /// <summary>
330         /// Gets the classification of the media.
331         /// </summary>
332         /// <since_tizen> 3 </since_tizen>
333         /// <value>A string representing the classification, or null if the information does not exist.</value>
334         public string Classification { get; }
335
336         /// <summary>
337         /// Gets the rating of the media.
338         /// </summary>
339         /// <since_tizen> 3 </since_tizen>
340         /// <value>A string representing the rating, or null if the information does not exist.</value>
341         public string Rating { get; }
342
343         /// <summary>
344         /// Gets the longitude of the media.
345         /// </summary>
346         /// <since_tizen> 4 </since_tizen>
347         /// <value>The longitude value, or null if the information does not exist.</value>
348         public double? Longitude { get; }
349
350         /// <summary>
351         /// Gets the latitude of the media.
352         /// </summary>
353         /// <since_tizen> 4 </since_tizen>
354         /// <value>The latitude value, or null if the information does not exist.</value>
355         public double? Latitude { get; }
356
357         /// <summary>
358         /// Gets the altitude of the media.
359         /// </summary>
360         /// <since_tizen> 4 </since_tizen>
361         /// <value>The altitude value, or null if the information does not exist.</value>
362         public double? Altitude { get; }
363
364         /// <summary>
365         /// Gets the conductor of the media.
366         /// </summary>
367         /// <since_tizen> 3 </since_tizen>
368         /// <value>A string representing the conductor, or null if the information does not exist.</value>
369         public string Conductor { get; }
370
371         /// <summary>
372         /// Gets the unsynchronized lyrics of the media.
373         /// </summary>
374         /// <since_tizen> 4 </since_tizen>
375         /// <value>A string representing the unsynchronized lyrics, or null if the information does not exist.</value>
376         public string UnsyncLyrics { get; }
377
378         /// <summary>
379         /// Gets the number of synchronized lyrics of the media.
380         /// </summary>
381         /// <since_tizen> 4 </since_tizen>
382         /// <value>The number of the synchronized lyrics.</value>
383         public int SyncLyricsCount { get; }
384
385         /// <summary>
386         /// Gets the recording date of the media.
387         /// </summary>
388         /// <since_tizen> 4 </since_tizen>
389         /// <value>A string representing the recording date, or null if the information does not exist.</value>
390         public string DateRecorded { get; }
391
392         /// <summary>
393         /// Gets the rotate(orientation) information of the media.
394         /// </summary>
395         /// <since_tizen> 4 </since_tizen>
396         /// <value>A string representing the rotation information, or null if the information does not exist.</value>
397         public string Rotation { get; }
398
399         /// <summary>
400         /// Gets the information for 360 content of the media.
401         /// </summary>
402         /// <since_tizen> 3 </since_tizen>
403         /// <value>A string representing the information for 360 content, or null if the information does not exist.</value>
404         public string Content360 { get; }
405
406         private Lazy<string> _description;
407
408         /// <summary>
409         /// Returns a string that represents the current object.
410         /// </summary>
411         /// <returns>A string that represents the current object.</returns>
412         /// <since_tizen> 3 </since_tizen>
413         public override string ToString() => _description.Value;
414     }
415 }