summaryrefslogtreecommitdiff
path: root/test/test-thumb.c
blob: e408090b549b4b81b8227740a4bd9db19ca47da8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
/*
 * libmedia-thumbnail
 *
 * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
 *
 * Contact: Hyunjun Ko <zzoon.ko@samsung.com>
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 */

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <pthread.h>
#include <mm_util_imgp.h>
#include <mm_util_jpeg.h>

#include "media-thumbnail.h"
#include "media-thumbnail-private.h"
#include "media-thumb-debug.h"
#include "media-thumb-ipc.h"
#include "media-thumb-util.h"

int save_to_file_with_gdk(unsigned char *data, int w, int h, int is_bgra)
{
	GError *error = NULL;
	
	gdk_pixbuf_save(data,"/mnt/nfs/test.jpg","jpeg", &error, NULL);
	if (error) {
		thumb_dbg ("Error saving image file /mnt/nfs/test.jpg ");
		g_error_free (error);
		return -1;
	}
	return 0;
}

int main(int argc, char *argv[])
{
	int mode;
	int err = -1;
	const char *origin_path = NULL;

	if ((argc != 3) && (argc != 4)) {
		printf("Usage: %s [test mode number] [path]\n", argv[0]);
		return -1;
	}

	mode = atoi(argv[1]);
	origin_path = argv[2];

	if (origin_path && (mode == 1)) {
		printf("Test _thumbnail_get_data\n");

		GdkPixbuf *data = NULL;
		int thumb_size = 0;
		int thumb_w = 0;
		int thumb_h = 0;
		int origin_w = 0;
		int origin_h = 0;
		int alpha = FALSE;

		media_thumb_type thumb_type = MEDIA_THUMB_LARGE;
		//media_thumb_type thumb_type = MEDIA_THUMB_SMALL;
		//media_thumb_format thumb_format = MEDIA_THUMB_BGRA;
		media_thumb_format thumb_format = MEDIA_THUMB_RGB888;
		int is_bgra = 1;
		//int is_bgra = 0;

		long start = thumb_get_debug_time();

		err = _thumbnail_get_data(origin_path, thumb_type, thumb_format, &data, &thumb_size, &thumb_w, &thumb_h, &origin_w, &origin_h, &alpha, tzplatform_getuid(TZ_USER_NAME));
		if (err < 0) {
			printf("_thumbnail_get_data failed - %d\n", err);
			return -1;
		}
	
		printf("Size : %d, W:%d, H:%d\n", thumb_size, thumb_w, thumb_h);	
		printf("Origin W:%d, Origin H:%d\n", origin_w, origin_h);

		err = save_to_file_with_gdk(data, thumb_w, thumb_h, is_bgra);
		if (err < 0) {
			printf("_thumbnail_get_data failed - %d\n", err);
			return -1;
		} else {
			printf("file save success\n");
		}

		SAFE_FREE(data);

		long end = thumb_get_debug_time();
		printf("Time : %f\n", ((double)(end - start) / (double)CLOCKS_PER_SEC));

	} else if (mode == 2) {
		printf("Test thumbnail_request_from_db\n");
		//const char *origin_path = "/opt/media/test/movie1.mp4";
		//const char *origin_path = "/opt/media/test/high.jpg";
		//const char *origin_path = "/opt/media/test/movie2.avi";
		char thumb_path[MAX_PATH_SIZE + 1];

		err = thumbnail_request_from_db(origin_path, thumb_path, sizeof(thumb_path), tzplatform_getuid(TZ_USER_NAME));
		if (err < 0) {
			printf("thumbnail_request_from_db failed : %d\n", err);
			return -1;
		}

		printf("Success!! (%s)\n", thumb_path);
	} else if (mode == 3) {
		printf("Test thumbnail_request_save_to_file\n");
		const char *thumb_path = NULL;

		if (argv[3]) {
		thumb_path = argv[3];
		} else {
			printf("3 mode requires target path of thumbnail\n");
			return -1;
		}

		err = thumbnail_request_save_to_file(origin_path, MEDIA_THUMB_LARGE, thumb_path, tzplatform_getuid(TZ_USER_NAME));
		if (err < 0) {
			printf("thumbnail_request_save_to_file failed : %d\n", err);
			return -1;
		}

		printf("Success!!\n");
	} else if (origin_path && mode == 4) {
		printf("Test thumbnail_generate_hash_code\n");
		printf("Success!!\n");
	} else if (mode == 5) {
		printf("Test thumbnail_request_extract_all_thumbs\n");

		err = thumbnail_request_extract_all_thumbs(tzplatform_getuid(TZ_USER_NAME));
		if (err < 0) {
			printf("thumbnail_request_extract_all_thumbs failed : %d\n", err);
			return -1;
		} else {
			printf("thumbnail_request_extract_all_thumbs success!\n");
		}
	} else if (mode == 6) {
		printf("Test thumbnail_request_cancel_media\n");

		err = thumbnail_request_cancel_media(origin_path,tzplatform_getuid(TZ_USER_NAME));
		if (err < 0) {
			printf("thumbnail_request_cancel_media failed : %d\n", err);
			return -1;
		} else {
			printf("thumbnail_request_cancel_media success!\n");
		}
	} else if (mode == 7) {
		printf("Test thumbnail_request_cancel_all\n");

		err = thumbnail_request_cancel_all();
		if (err < 0) {
			printf("thumbnail_request_cancel_all failed : %d\n", err);
			return -1;
		} else {
			printf("thumbnail_request_cancel_all success!\n");
		}
	}

	thumb_dbg("Test is Completed");

	return 0;
}