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