Apply the Listener
[profile/tv/apps/native/videoplayer.git] / src / videodata.cpp
1 /*
2  * Copyright (c) 2014 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 #include <Elementary.h>
18 #include <Eina.h>
19 #include <dbg.h>
20 #include "define.h"
21 #include "videodata.h"
22
23 struct videodata {
24         int duration;
25         int position;
26         int width;
27         int height;
28 };
29
30 void videodata_destroy(struct videodata *video_info)
31 {
32         free(video_info);
33         video_info = NULL;
34 }
35
36 struct videodata *videodata_create(media_info_h media_h)
37 {
38         int r;
39         struct videodata *video_info;
40         video_meta_h video_h;
41
42         if (!media_h)
43                 return NULL;
44
45         r = media_info_get_video(media_h, &video_h);
46         if (r != MEDIA_CONTENT_ERROR_NONE || !video_h) {
47                 _ERR("Media video handle fetch error");
48                 return NULL;
49         }
50
51         video_info = (videodata *)calloc(1, sizeof(*video_info));
52         if (!video_info)
53                 goto error;
54
55         r = video_meta_get_duration(video_h, &video_info->duration);
56         if (r != MEDIA_CONTENT_ERROR_NONE) {
57                 _ERR("video meta get duration error");
58                 goto error;
59         }
60
61         r = video_meta_get_width(video_h, &video_info->width);
62         if (r != MEDIA_CONTENT_ERROR_NONE) {
63                 _ERR("video meta get width error");
64                 goto error;
65         }
66
67         r = video_meta_get_height(video_h, &video_info->height);
68         if (r != MEDIA_CONTENT_ERROR_NONE) {
69                 _ERR("video meta get width error");
70                 goto error;
71         }
72
73         r = video_meta_get_played_position(video_h, &video_info->position);
74         if (r != MEDIA_CONTENT_ERROR_NONE) {
75                 _ERR("video meta get played position error");
76                 goto error;
77         }
78
79         video_meta_destroy(video_h);
80
81         return video_info;
82
83 error:
84         video_meta_destroy(video_h);
85         videodata_destroy(video_info);
86
87         return NULL;
88 }
89
90 int videodata_get_duration(const struct videodata *video_info)
91 {
92         if (!video_info)
93                 return -1;
94
95         return video_info->duration;
96 }
97
98 int videodata_get_played_position(const struct videodata *video_info)
99 {
100         if (!video_info)
101                 return -1;
102
103         return video_info->position;
104 }
105
106 int videodata_get_width(const struct videodata *video_info)
107 {
108         if (!video_info)
109                 return -1;
110
111         return video_info->width;
112 }
113
114 int videodata_get_height(const struct videodata *video_info)
115 {
116         if (!video_info)
117                 return -1;
118
119         return video_info->height;
120 }