Add tool package to separate testsuite binary
[platform/core/multimedia/libmm-streamrecorder.git] / src / mm_streamrecorder_fileinfo.c
1 /*
2  * libmm-streamrecorder
3  *
4  * Copyright (c) 2000 - 2013 Samsung Electronics Co., Ltd. All rights reserved.
5  *
6  * Contact: Hyuntae Kim <ht1211.kim@samsung.com>
7  *
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  * http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  *
20  */
21
22 /*=======================================================================================
23 |  INCLUDE FILES                                                                        |
24 =======================================================================================*/
25 #include <stdio.h>
26 #include <stdarg.h>
27 #include <sys/vfs.h>                    /* struct statfs */
28
29 #include "mm_streamrecorder_internal.h"
30 #include "mm_streamrecorder_util.h"
31 #include "mm_streamrecorder_fileinfo.h"
32
33 /*-----------------------------------------------------------------------
34 |    GLOBAL VARIABLE DEFINITIONS for internal                           |
35 -----------------------------------------------------------------------*/
36
37 /*-----------------------------------------------------------------------
38 |    LOCAL VARIABLE DEFINITIONS for internal                            |
39 -----------------------------------------------------------------------*/
40
41 /*---------------------------------------------------------------------------
42 |    LOCAL FUNCTION PROTOTYPES:                                                                                         |
43 ---------------------------------------------------------------------------*/
44 /* STATIC INTERNAL FUNCTION */
45
46 /*===========================================================================================
47 |                                                                                                                                                                                       |
48 |  FUNCTION DEFINITIONS                                                                                                                                         |
49 ========================================================================================== */
50 /*---------------------------------------------------------------------------
51 |    GLOBAL FUNCTION DEFINITIONS:                                                                                       |
52 ---------------------------------------------------------------------------*/
53
54 gboolean _mmstreamrecorder_update_composition_matrix(FILE *f, int orientation)
55 {
56         /* for 0 degree */
57         guint32 a = 0x00010000;
58         guint32 b = 0;
59         guint32 c = 0;
60         guint32 d = 0x00010000;
61
62         switch (orientation) {
63         case MM_STREAMRECORDER_TAG_VIDEO_ORT_90:        /* 90 degree */
64                 a = 0;
65                 b = 0x00010000;
66                 c = 0xffff0000;
67                 d = 0;
68                 break;
69         case MM_STREAMRECORDER_TAG_VIDEO_ORT_180:       /* 180 degree */
70                 a = 0xffff0000;
71                 d = 0xffff0000;
72                 break;
73         case MM_STREAMRECORDER_TAG_VIDEO_ORT_270:       /* 270 degree */
74                 a = 0;
75                 b = 0xffff0000;
76                 c = 0x00010000;
77                 d = 0;
78                 break;
79         case MM_STREAMRECORDER_TAG_VIDEO_ORT_NONE:      /* 0 degree */
80         default:
81                 break;
82         }
83
84         write_to_32(f, a);
85         write_to_32(f, b);
86         write_to_32(f, 0);
87         write_to_32(f, c);
88         write_to_32(f, d);
89         write_to_32(f, 0);
90         write_to_32(f, 0);
91         write_to_32(f, 0);
92         write_to_32(f, 0x40000000);
93
94         _mmstreamrec_dbg_log("orientation : %d, write data 0x%x 0x%x 0x%x 0x%x", orientation, a, b, c, d);
95
96         return TRUE;
97 }
98
99 guint64 _mmstreamrecorder_get_container_size(const guchar *size)
100 {
101         guint64 result = 0;
102         guint64 temp = 0;
103
104         temp = size[0];
105         result = temp << 24;
106         temp = size[1];
107         result = result | (temp << 16);
108         temp = size[2];
109         result = result | (temp << 8);
110         result = result | size[3];
111
112         _mmstreamrec_dbg_log("result : %lld", (unsigned long long)result);
113
114         return result;
115 }
116
117 gboolean _mmstreamrecorder_update_size(FILE *f, gint64 prev_pos, gint64 curr_pos)
118 {
119         _mmstreamrec_dbg_log("size : %" G_GINT64_FORMAT "", curr_pos - prev_pos);
120         if (fseek(f, prev_pos, SEEK_SET) != 0) {
121                 _mmstreamrec_dbg_err("fseek() fail");
122                 return FALSE;
123         }
124
125         if (!write_to_32(f, curr_pos - prev_pos))
126                 return FALSE;
127
128         if (fseek(f, curr_pos, SEEK_SET) != 0) {
129                 _mmstreamrec_dbg_err("fseek() fail");
130                 return FALSE;
131         }
132
133         return TRUE;
134 }
135
136 gboolean _mmstreamrecorder_write_udta_m4a(FILE *f)
137 {
138         gint64 current_pos, pos;
139
140         _mmstreamrec_dbg_log("");
141
142         if ((pos = ftell(f)) < 0) {
143                 _mmstreamrec_dbg_err("ftell() returns negative value");
144                 return FALSE;
145         }
146
147         if (!write_to_32(f, 0))         /* udta atomic size */
148                 return FALSE;
149
150         if (!write_tag(f, "udta"))      /* user data fourcc */
151                 return FALSE;
152
153         if ((current_pos = ftell(f)) < 0) {
154                 _mmstreamrec_dbg_err("ftell() returns negative value");
155                 return FALSE;
156         }
157
158         if (!_mmstreamrecorder_update_size(f, pos, current_pos))
159                 return FALSE;
160
161         return TRUE;
162 }
163
164 gboolean _mmstreamrecorder_write_udta(FILE *f, _MMStreamRecorderLocationInfo info)
165 {
166         gint64 current_pos, pos;
167
168         _mmstreamrec_dbg_log("");
169
170         if ((pos = ftell(f)) < 0) {
171                 _mmstreamrec_dbg_err("ftell() returns negative value");
172                 return FALSE;
173         }
174
175         if (!write_to_32(f, 0))         /*size */
176                 return FALSE;
177
178         if (!write_tag(f, "udta"))      /* type */
179                 return FALSE;
180
181         if ((current_pos = ftell(f)) < 0) {
182                 _mmstreamrec_dbg_err("ftell() returns negative value");
183                 return FALSE;
184         }
185
186         if (!_mmstreamrecorder_update_size(f, pos, current_pos))
187                 return FALSE;
188
189         return TRUE;
190 }