Add test code for getting video frame 04/140904/3
authorHaejeong Kim <backto.kim@samsung.com>
Thu, 27 Jul 2017 06:08:52 +0000 (15:08 +0900)
committerHaejeong Kim <backto.kim@samsung.com>
Thu, 27 Jul 2017 06:47:54 +0000 (15:47 +0900)
Change-Id: I25ae5287f48837aca7ed27f369cc9aecc353a826

tests/mm_file_test.c

index b39104e..0195355 100755 (executable)
@@ -150,6 +150,8 @@ const char *VideoCodecTypeString[] = {
 FILE *fpFailList = NULL;
 
 static int mmfile_get_file_infomation(void *data, void *user_data, bool file_test);
+static int mmfile_get_video_frame(void *data, void *accurate, bool file_test);
+
 
 inline static int mm_file_is_little_endian(void)
 {
@@ -205,7 +207,10 @@ int main(int argc, char **argv)
                if (S_ISDIR(statbuf.st_mode))   {
                        mmfile_get_file_names(argv[1], mmfile_get_file_infomation, NULL);
                } else {
-                       mmfile_get_file_infomation(argv[1], NULL, file_test);
+                       if (argv[2] == NULL)
+                               mmfile_get_file_infomation(argv[1], NULL, file_test);
+                       else
+                               mmfile_get_video_frame(argv[1], argv[2], file_test);
                }
 
                if (fpFailList != NULL) {
@@ -225,10 +230,10 @@ static int mmfile_get_file_infomation(void *data, void *user_data, bool file_tes
        int audio_track_num = 0;
        int video_track_num = 0;
        int ret = 0;
-       char filename[512];
+       char filename[512] = {0, };
 
-       memset(filename, 0x00, 512);
-       memcpy(filename, (char *)data, strlen((char *)data));
+       memset(filename, 0x00, sizeof(filename));
+       SAFE_STRLCPY(filename, (char *)data, sizeof(filename));
 
        MM_TIME_CHECK_START
 
@@ -492,3 +497,47 @@ static int mmfile_get_file_infomation(void *data, void *user_data, bool file_tes
 
        return 0;
 }
+
+static int mmfile_get_video_frame(void *data, void *accurate, bool file_test)
+{
+       int ret = 0;
+       char filename[512] = {0, };
+       char accurate_mode[10] = {0, };
+       void *_frame = NULL;
+       int _frame_size = 0;
+       int width = 0;
+       int height = 0;
+       bool is_accurate = FALSE;
+       unsigned long long time_stamp = 5 * 1000 * 1000;                //5sec
+
+       memset(filename, 0x00, sizeof(filename));
+       SAFE_STRLCPY(filename, (char *)data, sizeof(filename));
+
+       memset(accurate_mode, 0x00, sizeof(accurate_mode));
+       SAFE_STRLCPY(accurate_mode, (char *)accurate, sizeof(accurate_mode));
+
+       if (strlen(accurate_mode) > 0) {
+               if (strncmp (accurate_mode, "1", 1) == 0)
+                       is_accurate = TRUE;
+       }
+
+       printf("Extracting video frame for [%s] [%llu] accurate [%d]\n", filename, time_stamp, is_accurate);
+
+       if (file_test == TRUE)
+               ret = mm_file_get_video_frame(filename, time_stamp, is_accurate, (unsigned char **)&_frame, &_frame_size, &width, &height);
+       else    {
+               unsigned int file_size = 0;
+               unsigned char *buffer = NULL;
+               /* Read file */
+               READ_FROM_FILE(filename, buffer, file_size);
+
+               ret = mm_file_get_video_frame_from_memory(buffer, file_size, time_stamp, is_accurate, (unsigned char **)&_frame, &_frame_size, &width, &height);
+       }
+
+       if (ret != FILEINFO_ERROR_NONE)
+               printf("Failed to mm_file_get_video_frame() error=[%x]\n", ret);
+       else
+               printf("video_frame[%p], video_frame_len = [%d] width = [%d] height = [%d]\n", _frame, _frame_size, width, height);
+
+       return 0;
+}