summaryrefslogtreecommitdiff
path: root/feature/src/vp-thumb-gen.c
blob: 5c66d50c7a50d60ebc9146455774d253e338a927 (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
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
/*
* Copyright (c) 2000-2015 Samsung Electronics Co., Ltd All Rights Reserved
*
* 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 <pthread.h>
#include <metadata_extractor.h>
#include <image_util.h>
#include <image_util_internal.h>

#include "vp-feature-common.h"

#include "vp-feature-util.h"
#include "vp-file-util.h"
#include "vp-thumb-gen.h"
#include "vp-util.h"


static pthread_t g_thread_id;
static pthread_mutex_t g_mutex = PTHREAD_MUTEX_INITIALIZER;


#define	THUMB_GEN_FILE_NAME_PREFIX	"%s/thumb_%02d.jpg"
#define	THUMB_GEN_FILE_NAME_PREFIX_LEN	14


typedef struct _ThumbGen {
	metadata_extractor_h meta_h;

	char *szMediaURL;
	bool bIsRealize;

	int nSrcWidth;
	int nSrcHeight;
	int nDuration;
	bool bResize;

	int nRotate;

	int nStartPosition;
	int nEndPosition;
	int nStartIdx;
	int nDestWidth;
	int nDestHeight;
	int nGenCount;
	int nInterval;
	char *szSaveDir;
	bool bAcuurate;
	bool bScale;
	bool bIsStart;
	bool bIsCancle;
	void *pUserData;

	int nGenIdx;

	vp_thumb_gen_progress_cb progress_cb;
	vp_thumb_gen_complete_cb complete_cb;
	vp_thumb_gen_cancle_cb cancle_cb;

	Ecore_Pipe *pProgressPipe;
	Ecore_Pipe *pCompletePipe;
	Ecore_Pipe *pCanclePipe;
} ThumbGen;


static void _vp_thumb_gen_destroy_handle(ThumbGen *pThumbGen);


/* callback functions */


/* internal functions */
static void _vp_thumb_gen_lock()
{
	pthread_mutex_lock(&g_mutex);
}

static void _vp_thumb_gen_unlock()
{
	pthread_mutex_unlock(&g_mutex);
}

static void *_vp_thumb_gen_thread_loop(void *pUserData)
{
	if (pUserData == NULL) {
		return NULL;
	}

	ThumbGen *pThumbGen = (ThumbGen *) pUserData;

	while (1) {
		_vp_thumb_gen_lock();
		if (pThumbGen->bIsRealize == FALSE) {
			vp_dbgW(" == pThumbGen->bIsRealize is Fail ==");
			_vp_thumb_gen_unlock();
			break;
		}

		bool bRunStatus = FALSE;
		if (pThumbGen->bIsStart && pThumbGen->nGenCount > 0) {
			bRunStatus = TRUE;
		}
		_vp_thumb_gen_unlock();

		if (bRunStatus) {
			bool bSuccess = TRUE;
			char *szURL = NULL;
			void *pFrame = NULL;
			int nFrameSize = 0;
			unsigned long nPosition = 0;
			int nRet = METADATA_EXTRACTOR_ERROR_NONE;
			unsigned char *pSaveBuf = NULL;
			unsigned char *pRotBuf = NULL;
			_vp_thumb_gen_lock();

			vp_dbgW("idx : %d", pThumbGen->nGenIdx);
			int nSrcWidth = pThumbGen->nSrcWidth;
			int nSrcHeight = pThumbGen->nSrcHeight;
			int nSaveWidth = pThumbGen->nDestWidth;
			int nSaveHeight = pThumbGen->nDestHeight;
			int nFileNameSize =
				strlen(pThumbGen->szSaveDir) +
				THUMB_GEN_FILE_NAME_PREFIX_LEN;
			bool bResize = pThumbGen->bResize;

			szURL = calloc(1, sizeof(char) * nFileNameSize);

			if (szURL != NULL) {
				snprintf(szURL, nFileNameSize,
					THUMB_GEN_FILE_NAME_PREFIX,
					pThumbGen->szSaveDir,
					pThumbGen->nGenIdx + pThumbGen->nStartIdx);
			}

			nPosition =
				pThumbGen->nStartPosition +
				(pThumbGen->nGenIdx * pThumbGen->nInterval);

			nRet =
				metadata_extractor_get_frame_at_time(pThumbGen->meta_h,
						nPosition,
						pThumbGen->bAcuurate,
						&pFrame,
						&nFrameSize);
			if (nRet != METADATA_EXTRACTOR_ERROR_NONE) {
				vp_dbgE
				("metadata_extractor_get_frame_at_time is fail : [0x%x]",
				 nRet);
				bSuccess = FALSE;
			}
			_vp_thumb_gen_unlock();

			if (pFrame == NULL) {
				vp_dbgE("pFrame is NULL");
				bSuccess = FALSE;
			}

			if (bSuccess) {
				if (bResize) {
					unsigned int nResizBufSize = 0;

					nRet = image_util_calculate_buffer_size(nSaveWidth,
										nSaveHeight,
										IMAGE_UTIL_COLORSPACE_RGB888,
										&nResizBufSize);
					if (nRet != IMAGE_UTIL_ERROR_NONE) {
						vp_dbgE
						("image_util_calculate_buffer_size is fail : [0x%x]",
						 nRet);
						bSuccess = FALSE;
					}
					vp_dbgW("ResizeBuf Size : %d", nResizBufSize);

					pSaveBuf =
						calloc(1, sizeof(unsigned char) * nResizBufSize);
					if (pSaveBuf == NULL) {
						vp_dbgE("pSaveBuf alloc fail");
						bSuccess = FALSE;
					} else {
						nRet = vp_util_image_resize(pSaveBuf,
									    &nSaveWidth,
									    &nSaveHeight,
									    (unsigned char *)
									    pFrame, nSrcWidth,
									    nSrcHeight,
									    IMAGE_UTIL_COLORSPACE_RGB888);
						if (nRet != IMAGE_UTIL_ERROR_NONE) {
							vp_dbgE
							("vp_util_image_resize is fail : [0x%x]",
							 nRet);
							bSuccess = FALSE;
						}
					}
				} else {
					pSaveBuf = (unsigned char *) pFrame;
				}
			}

			if (pThumbGen->nRotate != 0) {
				image_util_rotation_e nRot = IMAGE_UTIL_ROTATION_NONE;
				if (pThumbGen->nRotate == 90) {
					nRot = IMAGE_UTIL_ROTATION_90;
				} else if (pThumbGen->nRotate == 180) {
					nRot = IMAGE_UTIL_ROTATION_180;
				} else if (pThumbGen->nRotate == 270) {
					nRot = IMAGE_UTIL_ROTATION_270;
				}

				if (nRot != IMAGE_UTIL_ROTATION_NONE) {
					unsigned int nResizBufSize = 0;
					int nSrcW = nSaveWidth;
					int nSrcH = nSaveHeight;
					nRet = image_util_calculate_buffer_size(nSaveWidth,
										nSaveHeight,
										IMAGE_UTIL_COLORSPACE_RGB888,
										&nResizBufSize);
					if (nRet != IMAGE_UTIL_ERROR_NONE) {
						vp_dbgE
						("image_util_calculate_buffer_size is fail : [0x%x]",
						 nRet);
						bSuccess = FALSE;
					}

					pRotBuf =
						calloc(1, sizeof(unsigned char) * nResizBufSize);
					if (pRotBuf == NULL) {
						vp_dbgE("pRotBuf alloc fail");
						bSuccess = FALSE;
					} else {
						vp_dbgW("ResizeBuf Size : %d", nResizBufSize);
						nRet = vp_util_image_rotate(pRotBuf,
									    &nSaveWidth,
									    &nSaveHeight,
									    nRot, pSaveBuf,
									    nSrcW, nSrcH,
									    IMAGE_UTIL_COLORSPACE_RGB888);
						if (nRet != IMAGE_UTIL_ERROR_NONE) {
							vp_dbgE
							("vp_util_image_rotate is fail : [0x%x]",
							 nRet);
							bSuccess = FALSE;
						}
					}
				}
			}

			if (bSuccess) {
				vp_sdbg("w:%d, h:%d, URL : %s", nSaveWidth, nSaveHeight,
					szURL);
				if (pRotBuf) {
					nRet = image_util_encode_jpeg(pRotBuf,
								      nSaveWidth,
								      nSaveHeight,
								      IMAGE_UTIL_COLORSPACE_RGB888,
								      100, szURL);
					if (nRet != IMAGE_UTIL_ERROR_NONE) {
						vp_dbgE("image_util_encode_jpeg is fail : [0x%x]",
							nRet);
						bSuccess = FALSE;
					}
				} else {
					nRet = image_util_encode_jpeg(pSaveBuf,
								      nSaveWidth,
								      nSaveHeight,
								      IMAGE_UTIL_COLORSPACE_RGB888,
								      100, szURL);
					if (nRet != IMAGE_UTIL_ERROR_NONE) {
						vp_dbgE("image_util_encode_jpeg is fail : [0x%x]",
							nRet);
						bSuccess = FALSE;
					}
				}
			}

			if (bResize) {
				VP_FREE(pSaveBuf);
			}
			VP_FREE(pRotBuf);
			VP_FREE(pFrame);

			_vp_thumb_gen_lock();
			if (pThumbGen->progress_cb) {
				vp_dbgW(" ==> %p, %p", pThumbGen, pThumbGen->progress_cb);
				pThumbGen->progress_cb(bSuccess, pThumbGen->nGenIdx,
						       szURL, nPosition,
						       pThumbGen->pUserData);
			}

			pThumbGen->nGenIdx++;
			VP_FREE(szURL);
			_vp_thumb_gen_unlock();

			if (pThumbGen->nGenIdx == pThumbGen->nGenCount) {
				/* call complete callback */
				pThumbGen->bIsStart = FALSE;

				vp_thumb_gen_complete_cb func = pThumbGen->complete_cb;

				if (func) {
					func(pThumbGen->nGenCount, pThumbGen->pUserData);
				}
				pthread_exit(0);
			}

		}

		_vp_thumb_gen_lock();
		if (pThumbGen->bIsCancle) {
			if (pThumbGen->cancle_cb) {
				vp_dbgW(" ==> %p, %p", pThumbGen, pThumbGen->cancle_cb);
				pThumbGen->cancle_cb(pThumbGen->pUserData);
			}

			pThumbGen->bIsStart = FALSE;
		}
		_vp_thumb_gen_unlock();

		usleep(1000);
	}
	vp_dbgW(" == Thread End ==");

	return NULL;
}


static void _vp_thumb_gen_destroy_handle(ThumbGen *pThumbGen)
{
	if (pThumbGen == NULL) {
		vp_dbgE("hThumbGen is NULL");
		return;
	}

	int nRet = METADATA_EXTRACTOR_ERROR_NONE;
	_vp_thumb_gen_lock();

	pThumbGen->progress_cb = NULL;
	pThumbGen->complete_cb = NULL;
	pThumbGen->cancle_cb = NULL;

	nRet = metadata_extractor_destroy(pThumbGen->meta_h);
	if (nRet != METADATA_EXTRACTOR_ERROR_NONE) {
		vp_dbgE("metadata_extractor_destroy is fail : [0x%x]", nRet);
	}

	VP_FREE(pThumbGen->szMediaURL);
	VP_FREE(pThumbGen->szSaveDir);

	VP_FREE(pThumbGen);

	_vp_thumb_gen_unlock();

}


/* external functions */
vp_thumb_gen_h vp_thumb_gen_create(const char *szMediaURL)
{
	if (szMediaURL == NULL) {
		vp_dbgE("szMediaURL is NULL");
		return NULL;
	}

	ThumbGen *pThumbGen = calloc(1, sizeof(ThumbGen));
	if (pThumbGen == NULL) {
		vp_dbgE("ThumbGen alloc is fail");
		return NULL;
	}


	VP_STRDUP(pThumbGen->szMediaURL, szMediaURL);

	int nRet = METADATA_EXTRACTOR_ERROR_NONE;
	nRet = metadata_extractor_create(&(pThumbGen->meta_h));
	if (nRet != METADATA_EXTRACTOR_ERROR_NONE) {
		_vp_thumb_gen_destroy_handle(pThumbGen);
		vp_dbgE("metadata_extractor_create is fail : [0x%x]", nRet);
		return NULL;
	}

	nRet = metadata_extractor_set_path(pThumbGen->meta_h, szMediaURL);
	if (nRet != METADATA_EXTRACTOR_ERROR_NONE) {
		_vp_thumb_gen_destroy_handle(pThumbGen);
		vp_dbgE("metadata_extractor_set_path is fail : [0x%x]", nRet);
		return NULL;
	}

	char *szVal = NULL;

	nRet =
		metadata_extractor_get_metadata(pThumbGen->meta_h,
						METADATA_DURATION, &szVal);
	if (nRet != METADATA_EXTRACTOR_ERROR_NONE) {
		_vp_thumb_gen_destroy_handle(pThumbGen);
		vp_dbgE("metadata_extractor_get_metadata is fail : [0x%x]", nRet);
		return NULL;
	}
	pThumbGen->nDuration = atoi(szVal);
	VP_FREE(szVal);

	nRet =
		metadata_extractor_get_metadata(pThumbGen->meta_h,
						METADATA_ROTATE, &szVal);
	if (nRet != METADATA_EXTRACTOR_ERROR_NONE) {
		_vp_thumb_gen_destroy_handle(pThumbGen);
		vp_dbgE("metadata_extractor_get_metadata is fail : [0x%x]", nRet);
		return NULL;
	}

	if (szVal == NULL) {

		pThumbGen->nRotate = 0;
	} else {
		pThumbGen->nRotate = atoi(szVal);
		VP_FREE(szVal);
	}

	nRet =
		metadata_extractor_get_metadata(pThumbGen->meta_h,
						METADATA_VIDEO_WIDTH, &szVal);
	if (nRet != METADATA_EXTRACTOR_ERROR_NONE) {
		_vp_thumb_gen_destroy_handle(pThumbGen);
		vp_dbgE("metadata_extractor_get_metadata is fail : [0x%x]", nRet);
		return NULL;
	}
	pThumbGen->nSrcWidth = atoi(szVal);
	VP_FREE(szVal);

	nRet =
		metadata_extractor_get_metadata(pThumbGen->meta_h,
						METADATA_VIDEO_HEIGHT, &szVal);
	if (nRet != METADATA_EXTRACTOR_ERROR_NONE) {
		_vp_thumb_gen_destroy_handle(pThumbGen);
		vp_dbgE("metadata_extractor_get_metadata is fail : [0x%x]", nRet);
		return NULL;
	}
	pThumbGen->nSrcHeight = atoi(szVal);
	VP_FREE(szVal);

	pthread_mutex_init(&g_mutex, NULL);

	return (vp_thumb_gen_h) pThumbGen;
}

void vp_thumb_gen_destroy(vp_thumb_gen_h hThumbGen)
{
	if (hThumbGen == NULL) {
		vp_dbgE("hThumbGen is NULL");
		return;
	}
	vp_dbgW("");

	ThumbGen *pThumbGen = (ThumbGen *) hThumbGen;

	vp_thumb_gen_unrealize((vp_thumb_gen_h) pThumbGen);
	_vp_thumb_gen_destroy_handle(pThumbGen);

	pthread_mutex_destroy(&g_mutex);

}

bool vp_thumb_gen_realize(vp_thumb_gen_h hThumbGen)
{
	if (hThumbGen == NULL) {
		vp_dbgE("hThumbGen is NULL");
		return FALSE;
	}

	ThumbGen *pThumbGen = (ThumbGen *) hThumbGen;

	pThumbGen->bIsRealize = TRUE;

	if (pThumbGen->bScale) {
		int nResultW = 0;
		int nResultH = 0;
		if (!vp_feature_util_calc_aspect_size(pThumbGen->nSrcWidth,
						      pThumbGen->nSrcHeight,
						      pThumbGen->nDestWidth,
						      pThumbGen->nDestHeight,
						      0, 0,
						      &nResultW, &nResultH)) {
			vp_dbgE("vp_feature_util_calc_aspect_size is fail");

		} else {
			pThumbGen->nDestWidth = nResultW;
			pThumbGen->nDestHeight = nResultH;
		}
		if (pThumbGen->nDestWidth % 2 != 0) {
			pThumbGen->nDestWidth += 1;
		}
		if (pThumbGen->nDestHeight % 2 != 0) {
			pThumbGen->nDestHeight += 1;
		}

	}
#if 1
	if (pthread_create
			(&g_thread_id, NULL, _vp_thumb_gen_thread_loop,
			 (void *) pThumbGen) != 0) {
		vp_dbgE("pthread_create fail");
		pThumbGen->bIsRealize = FALSE;
		return FALSE;
	}
#else
	int status = 0;
	pthread_attr_t thread_attr;

	status = pthread_attr_init(&thread_attr);
	if (0 == status) {
		status = pthread_attr_setdetachstate(&thread_attr,
						     PTHREAD_CREATE_DETACHED);
		if (0 == status) {
			if (pthread_create
					(&g_thread_id, &thread_attr, _vp_thumb_gen_thread_loop,
					 (void *) pThumbGen) != 0) {
				vp_dbgE("pthread_create fail");
				pThumbGen->bIsRealize = FALSE;
				return FALSE;
			}
		} else {
			vp_dbgE("pthread_attr_setdetachstate fail");
			pThumbGen->bIsRealize = FALSE;
			return FALSE;
		}
	} else {
		vp_dbgE("pthread_attr_init fail");
		pThumbGen->bIsRealize = FALSE;
		return FALSE;
	}

	if (pthread_attr_destroy(&thread_attr) != 0) {
		vp_dbgE("Cannot destroy the attribute object");
		pThumbGen->bIsRealize = FALSE;
		return FALSE;
	}
#endif
	return TRUE;
}

bool vp_thumb_gen_unrealize(vp_thumb_gen_h hThumbGen)
{
	if (hThumbGen == NULL) {
		vp_dbgE("hThumbGen is NULL");
		return FALSE;
	}

	ThumbGen *pThumbGen = (ThumbGen *) hThumbGen;

	_vp_thumb_gen_lock();
	pThumbGen->bIsStart = FALSE;
	_vp_thumb_gen_unlock();

	if (pThumbGen->bIsRealize == TRUE) {
		_vp_thumb_gen_lock();
		pThumbGen->bIsRealize = FALSE;
		_vp_thumb_gen_unlock();

		int status = 0;
		pthread_join(g_thread_id, (void **) &status);

		//pthread_detach(g_thread_id);
	}

	return TRUE;
}

bool vp_thumb_gen_is_realize(vp_thumb_gen_h hThumbGen, bool *bIsRealize)
{
	if (hThumbGen == NULL) {
		vp_dbgE("hThumbGen is NULL");
		return FALSE;
	}

	ThumbGen *pThumbGen = (ThumbGen *) hThumbGen;

	*bIsRealize = pThumbGen->bIsRealize;

	return TRUE;
}

bool vp_thumb_gen_set_dest_size(vp_thumb_gen_h hThumbGen, int nWidth,
				int nHeight)
{
	if (hThumbGen == NULL) {
		vp_dbgE("hThumbGen is NULL");
		return FALSE;
	}

	ThumbGen *pThumbGen = (ThumbGen *) hThumbGen;

	_vp_thumb_gen_lock();

	pThumbGen->nDestWidth = nWidth;
	pThumbGen->nDestHeight = nHeight;

	if (nWidth != pThumbGen->nSrcWidth
			|| nHeight != pThumbGen->nSrcHeight) {
		pThumbGen->bResize = TRUE;
	}

	_vp_thumb_gen_unlock();

	return TRUE;
}

bool vp_thumb_gen_set_save_directory(vp_thumb_gen_h hThumbGen,
				     char *szSaveDir)
{
	if (hThumbGen == NULL) {
		vp_dbgE("hThumbGen is NULL");
		return FALSE;
	}

	ThumbGen *pThumbGen = (ThumbGen *) hThumbGen;

	_vp_thumb_gen_lock();

	if (!vp_file_exists(szSaveDir)) {
		if (!vp_mkdir(szSaveDir)) {
			vp_dbgE("Make directory Fail : %s", szSaveDir);
		}
	}

	VP_STRDUP(pThumbGen->szSaveDir, szSaveDir);

	_vp_thumb_gen_unlock();

	return TRUE;
}

bool vp_thumb_gen_set_start_position(vp_thumb_gen_h hThumbGen,
				     int nPosition)
{
	if (hThumbGen == NULL) {
		vp_dbgE("hThumbGen is NULL");
		return FALSE;
	}

	ThumbGen *pThumbGen = (ThumbGen *) hThumbGen;

	_vp_thumb_gen_lock();

	pThumbGen->nStartPosition = nPosition;

	_vp_thumb_gen_unlock();

	return TRUE;
}

bool vp_thumb_gen_set_end_position(vp_thumb_gen_h hThumbGen,
				   int nPosition)
{
	if (hThumbGen == NULL) {
		vp_dbgE("hThumbGen is NULL");
		return FALSE;
	}

	ThumbGen *pThumbGen = (ThumbGen *) hThumbGen;

	_vp_thumb_gen_lock();

	pThumbGen->nEndPosition = nPosition;

	_vp_thumb_gen_unlock();

	return TRUE;
}

bool vp_thumb_gen_set_start_index(vp_thumb_gen_h hThumbGen, int nIdx)
{
	if (hThumbGen == NULL) {
		vp_dbgE("hThumbGen is NULL");
		return FALSE;
	}

	ThumbGen *pThumbGen = (ThumbGen *) hThumbGen;

	_vp_thumb_gen_lock();

	pThumbGen->nStartIdx = nIdx;

	_vp_thumb_gen_unlock();

	return TRUE;
}

bool vp_thumb_gen_set_count(vp_thumb_gen_h hThumbGen, int nCount)
{
	if (hThumbGen == NULL) {
		vp_dbgE("hThumbGen is NULL");
		return FALSE;
	}

	if (nCount <= 0) {
		vp_dbgE("Invalid  nCount ");
		return FALSE;
	}

	ThumbGen *pThumbGen = (ThumbGen *) hThumbGen;

	_vp_thumb_gen_lock();

	pThumbGen->nGenCount = nCount;
	if (pThumbGen->nEndPosition <= 0) {
		vp_dbgW("It doesn't set value of end position.");
		pThumbGen->nEndPosition = pThumbGen->nDuration;
	}
	pThumbGen->nInterval =
		(pThumbGen->nEndPosition - pThumbGen->nStartPosition) / nCount;

	_vp_thumb_gen_unlock();

	return TRUE;
}


bool vp_thumb_gen_set_acuurate(vp_thumb_gen_h hThumbGen, bool bAcuurate)
{
	if (hThumbGen == NULL) {
		vp_dbgE("hThumbGen is NULL");
		return FALSE;
	}

	ThumbGen *pThumbGen = (ThumbGen *) hThumbGen;

	_vp_thumb_gen_lock();

	pThumbGen->bAcuurate = bAcuurate;

	_vp_thumb_gen_unlock();

	return TRUE;
}

bool vp_thumb_gen_set_scale(vp_thumb_gen_h hThumbGen, bool bSacle)
{
	if (hThumbGen == NULL) {
		vp_dbgE("hThumbGen is NULL");
		return FALSE;
	}

	ThumbGen *pThumbGen = (ThumbGen *) hThumbGen;

	_vp_thumb_gen_lock();

	pThumbGen->bScale = bSacle;

	_vp_thumb_gen_unlock();

	return TRUE;
}

bool vp_thumb_gen_start(vp_thumb_gen_h hThumbGen)
{
	if (hThumbGen == NULL) {
		vp_dbgE("hThumbGen is NULL");
		return FALSE;
	}

	ThumbGen *pThumbGen = (ThumbGen *) hThumbGen;

	if (pThumbGen->bIsRealize == FALSE) {
		vp_dbgE("Not yet realize state");
		return FALSE;
	}

	if (pThumbGen->bIsStart == TRUE) {
		vp_dbgE("Already thumb gen start");
		return FALSE;
	}

	_vp_thumb_gen_lock();

	pThumbGen->bIsStart = TRUE;

	_vp_thumb_gen_unlock();

	return TRUE;
}

bool vp_thumb_gen_cancle(vp_thumb_gen_h hThumbGen)
{
	if (hThumbGen == NULL) {
		vp_dbgE("hThumbGen is NULL");
		return FALSE;
	}

	ThumbGen *pThumbGen = (ThumbGen *) hThumbGen;

	if (pThumbGen->bIsRealize == FALSE) {
		vp_dbgE("Not yet realize state");
		return FALSE;
	}

	if (pThumbGen->bIsCancle == TRUE) {
		vp_dbgE("Already thumb gen cancles");
		return FALSE;
	}

	_vp_thumb_gen_lock();

	pThumbGen->bIsCancle = TRUE;

	_vp_thumb_gen_unlock();

	return TRUE;
}

bool vp_thumb_gen_set_user_data(vp_thumb_gen_h hThumbGen, void *pUserData)
{
	if (hThumbGen == NULL) {
		vp_dbgE("hThumbGen is NULL");
		return FALSE;
	}

	ThumbGen *pThumbGen = (ThumbGen *) hThumbGen;

	_vp_thumb_gen_lock();

	pThumbGen->pUserData = pUserData;

	_vp_thumb_gen_unlock();

	return TRUE;
}

bool vp_thumb_gen_set_progress_cb(vp_thumb_gen_h hThumbGen,
				  vp_thumb_gen_progress_cb progress_cb)
{
	if (hThumbGen == NULL) {
		vp_dbgE("hThumbGen is NULL");
		return FALSE;
	}

	ThumbGen *pThumbGen = (ThumbGen *) hThumbGen;

	_vp_thumb_gen_lock();

	pThumbGen->progress_cb = progress_cb;

	_vp_thumb_gen_unlock();

	return TRUE;
}

bool vp_thumb_gen_set_complete_cb(vp_thumb_gen_h hThumbGen,
				  vp_thumb_gen_complete_cb complete_cb)
{
	if (hThumbGen == NULL) {
		vp_dbgE("hThumbGen is NULL");
		return FALSE;
	}

	ThumbGen *pThumbGen = (ThumbGen *) hThumbGen;

	_vp_thumb_gen_lock();

	pThumbGen->complete_cb = complete_cb;

	_vp_thumb_gen_unlock();

	return TRUE;
}

bool vp_thumb_gen_set_cancle_cb(vp_thumb_gen_h hThumbGen,
				vp_thumb_gen_cancle_cb cancle_cb)
{
	if (hThumbGen == NULL) {
		vp_dbgE("hThumbGen is NULL");
		return FALSE;
	}

	ThumbGen *pThumbGen = (ThumbGen *) hThumbGen;

	_vp_thumb_gen_lock();

	pThumbGen->cancle_cb = cancle_cb;

	_vp_thumb_gen_unlock();

	return TRUE;
}