reduced 'probesize' to 10000 with getting configurable values from ini 46/266746/6 accepted/tizen/unified/20211123.015910 submit/tizen/20211122.073257
authorJiyong Min <jiyong.min@samsung.com>
Thu, 18 Nov 2021 06:29:15 +0000 (15:29 +0900)
committerJiyong Min <jiyong.min@samsung.com>
Mon, 22 Nov 2021 05:36:19 +0000 (14:36 +0900)
[Problem]
 - 'media-scanner' was killed by 'stability-mnonitor' on TV.

[Cause]
 - 'media-scanner' still use a lot of memory usage for few 8k contents.

[Solution]
 - reduced 'probesize' to get stream information in ffmpeg
  'probesize' is a breakthrough in reducing memory usage
  because it affects the number of packets and decoding buffers.

Change-Id: I73887dc617b7774bb265d992d67bea58e91a99a4

formats/ffmpeg/mm_file_format_ffmpeg.c
mm_file_config.ini
packaging/libmm-fileinfo.spec
utils/Makefile.am
utils/include/mm_file_utils.h
utils/mm_file_util_ini.c [new file with mode: 0644]
utils/mm_file_util_tag.c

index b34fee7..7bb1ea6 100644 (file)
@@ -33,6 +33,9 @@
 #include "mm_file_utils.h"
 #include "mm_file_format_ffmpeg.h"
 
+static int g_max_analyze_duration = 0;
+static int g_probesize = 0;
+
 #ifdef __MMFILE_TEST_MODE__
 static void _dump_av_packet(AVPacket *pkt)
 {
@@ -466,10 +469,17 @@ int mmfile_format_read_stream_ffmpg(MMFileFormatContext *formatContext)
         * Please refer to below for detail.
         * https://ffmpeg.org/ffmpeg-formats.html#Format-Options
         */
+       if (g_max_analyze_duration == 0)
+               g_max_analyze_duration = mmfile_get_int_from_ini(MMFILE_INI_MAXANLDURATION, MMFILE_DEFAULT_MAXANLDURATION);
+       if (g_probesize == 0)
+               g_probesize = mmfile_get_int_from_ini(MMFILE_INI_PROBESIZE, MMFILE_DEFAULT_PROBESIZE);
+
        if (formatContext->formatType == MM_FILE_FORMAT_M2TS)
-               pFormatCtx->max_analyze_duration = 100000;      // MPEGTS file timeout set
+               pFormatCtx->max_analyze_duration = g_max_analyze_duration;      // MPEGTS file timeout set
        else
-               pFormatCtx->probesize = 900000;
+               pFormatCtx->probesize = g_probesize;    // the size of the data(packet) to probe stream information
+
+       debug_msg(RELEASE, "max_analyze_duration: %"PRId64", probesize: %"PRId64"", pFormatCtx->max_analyze_duration, pFormatCtx->probesize);
 
        if (formatContext->cdis != 1) {
                if (avformat_find_stream_info(pFormatCtx, NULL) < 0) {
index 86f51bc..bd52884 100644 (file)
@@ -1,4 +1,10 @@
 ;junk_counter_limit
 ; limit loop count for junk-data in mpeg4
+;max_analyze_duration
+; MPEGTS file timeout set
+;probesize
+; the size of the data to probe
 [mm-file-config]
 junk_counter_limit=1000
+max_analyze_duration=100000
+probesize=1000
index a0379c3..7d20629 100644 (file)
@@ -1,6 +1,6 @@
 Name:      libmm-fileinfo
 Summary:    Media Fileinfo
-Version:    1.0.5
+Version:    1.0.6
 Release:    0
 Group:      System/Libraries
 License:    Apache-2.0
index 71775b4..4d7ba10 100755 (executable)
@@ -11,7 +11,8 @@ libmmfile_utils_la_SOURCES = mm_file_util_io.c \
                           mm_file_util_string.c \
                           mm_file_util_locale.c \
                           mm_file_util_validity.c \
-                          mm_file_util_tag.c
+                          mm_file_util_tag.c \
+                          mm_file_util_ini.c
 
 libmmfile_utils_la_CFLAGS = -I$(srcdir)/include \
                       -I$(srcdir)/../include \
index 0338283..ca33d2b 100755 (executable)
@@ -41,8 +41,6 @@ extern "C" {
 #define MMFILE_UTIL_FAIL               -1
 #define MMFILE_UTIL_SUCCESS    0
 
-#define MM_FILE_INI_PATH       "/etc/multimedia/mm_file_config.ini"
-
 #define mmfile_free(ptr)  do { g_free((ptr)); (ptr) = NULL; } while (0)
 
 
@@ -148,7 +146,19 @@ long long  mmfile_tell(MMFileIOHandle *h);
 long long      mmfile_get_size(MMFileIOHandle *h);
 int                    mmfile_close(MMFileIOHandle *h);
 
+/*////////////////////////////////////////////////////////////////////// */
+/*                            INI  API                               // */
+/*////////////////////////////////////////////////////////////////////// */
+#define MMFILE_INI_PATH                "/etc/multimedia/mm_file_config.ini"
+#define MMFILE_INI_JUNKCNTLIMIT                "mm-file-config:junk_counter_limit"
+#define MMFILE_INI_MAXANLDURATION      "mm-file-config:max_analyze_duration"
+#define MMFILE_INI_PROBESIZE           "mm-file-config:probesize"
 
+#define MMFILE_DEFAULT_JUNKCNTLIMIT            1000
+#define MMFILE_DEFAULT_MAXANLDURATION  100000
+#define MMFILE_DEFAULT_PROBESIZE               1000
+
+int mmfile_get_int_from_ini(const char *key, int notfound);
 
 /*////////////////////////////////////////////////////////////////////// */
 /*                            MIME  API                               // */
@@ -186,7 +196,6 @@ char *MMFileUtilGetLocale();
 /*////////////////////////////////////////////////////////////////////// */
 /*                            TAG API                                 // */
 /*////////////////////////////////////////////////////////////////////// */
-
 inline static int __AvMemstr(unsigned char *mem, unsigned char *str, int str_len, int search_range)
 {
        int offset = 0;
diff --git a/utils/mm_file_util_ini.c b/utils/mm_file_util_ini.c
new file mode 100644 (file)
index 0000000..4e17fb2
--- /dev/null
@@ -0,0 +1,44 @@
+/*
+ * libmm-fileinfo
+ *
+ * Copyright (c) 2021 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact: Jiyong Min <jiyong.min@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 <iniparser.h>
+
+#include "mm_file_debug.h"
+#include "mm_file_utils.h"
+
+int mmfile_get_int_from_ini(const char *key, int notfound)
+{
+       dictionary *dict = NULL;
+       int data = 0;
+
+       dict = iniparser_load(MMFILE_INI_PATH);
+       if (!dict) {
+               debug_error(DEBUG, "%s load failed", MMFILE_INI_PATH);
+               return notfound;
+       }
+
+       data = iniparser_getint(dict, key, notfound);
+       debug_msg(DEBUG, "%s: %d", key, data);
+
+       iniparser_freedict(dict);
+
+       return data;
+}
index 2163087..8d0f399 100644 (file)
@@ -25,7 +25,6 @@
 #include <ctype.h>
 #include <vconf.h>
 #include <glib.h>
-#include <iniparser.h>
 #include <stdint.h>
 
 #include "mm_file.h"
@@ -290,7 +289,7 @@ MMFILE_ID3TAG_INFO tag_info_v23[ID3TAG_NUM_V23] = {
        {"TDRC", 660099, AV_ID3TAG_RECDATE},                    /*Recdate for 2.4*/
 };
 
-static int GetJunkCounterLimit(void);
+static int g_junk_counter_limit = 0;
 
 static int GetStringFromTextTagBox(MMFileFormatContext *formatContext, MMFileIOHandle *fp, MMFILE_MP4_BASIC_BOX_HEADER *basic_header, eMMFILE_3GP_TEXT_TAG eTag)
 {
@@ -1902,26 +1901,6 @@ int mm_file_get_bool_value_from_xml_string(const char* xml_str, const char* para
        return MMFILE_UTIL_SUCCESS;
 }
 
-static int g_junk_counter_limit = 0;
-static int GetJunkCounterLimit(void)
-{
-       dictionary *dict = NULL;
-       int data = 0;
-
-       dict = iniparser_load(MM_FILE_INI_PATH);
-       if (!dict) {
-               debug_error(DEBUG, "%s load failed", MM_FILE_INI_PATH);
-               return -1;
-       }
-
-       data = iniparser_getint(dict, "mm-file-config:junk_counter_limit", 0);
-       debug_msg(DEBUG, "mm-file-config:junk_counter_limit= %u", data);
-
-       iniparser_freedict(dict);
-
-       return data;
-}
-
 int ParseSpatialVideoMetadataFromXMLString(const char *xmlStr, MMFileFormatContext *formatContext)
 {
        const char is_spherical_str[] = "<GSpherical:Spherical>";
@@ -2155,7 +2134,7 @@ int MMFileUtilGetMetaDataFromMP4(MMFileFormatContext *formatContext)
        basic_header.start_offset = mmfile_tell(fp);
 
        if (g_junk_counter_limit == 0)
-               g_junk_counter_limit = GetJunkCounterLimit();
+               g_junk_counter_limit = mmfile_get_int_from_ini(MMFILE_INI_JUNKCNTLIMIT, MMFILE_DEFAULT_JUNKCNTLIMIT);
 
        while ((ret != MMFILE_UTIL_FAIL) && ((readed = mmfile_read(fp, (unsigned char *)&basic_header, MMFILE_MP4_BASIC_BOX_HEADER_LEN)) == MMFILE_MP4_BASIC_BOX_HEADER_LEN)) {
                basic_header.size = mmfile_io_be_uint32(basic_header.size);