#include <tbm_surface.h>
#include <tbm_surface_internal.h>
#include <string.h>
+#include <time.h>
#include "tdm.h"
#include "tdm_private.h"
static const char *dump_prefix[2] = {"png", "yuv"};
+int tdm_dump_enable;
+static int *tdm_helper_dump_count;
+static char *tdm_helper_dump_path;
+
+INTERN unsigned long
+tdm_helper_get_time_in_millis(void)
+{
+ struct timespec tp;
+
+ if (clock_gettime(CLOCK_MONOTONIC, &tp) == 0)
+ return (tp.tv_sec * 1000) + (tp.tv_nsec / 1000000L);
+
+ return 0;
+}
+
+INTERN unsigned long
+tdm_helper_get_time_in_micros(void)
+{
+ struct timespec tp;
+
+ if (clock_gettime(CLOCK_MONOTONIC, &tp) == 0)
+ return (tp.tv_sec * 1000000) + (tp.tv_nsec / 1000L);
+
+ return 0;
+}
+
static void
_tdm_helper_dump_raw(const char *file, void *data1, int size1, void *data2,
int size2, void *data3, int size3)
case TBM_FORMAT_YVU420:
case TBM_FORMAT_YUV420:
_tdm_helper_dump_raw(file,
- info.planes[0].ptr + info.planes[0].offset,
+ info.planes[0].ptr,
info.planes[0].stride * info.height,
- info.planes[1].ptr + info.planes[1].offset,
+ info.planes[1].ptr,
info.planes[1].stride * (info.height >> 1),
- info.planes[2].ptr + info.planes[2].offset,
+ info.planes[2].ptr,
info.planes[2].stride * (info.height >> 1));
break;
case TBM_FORMAT_NV12:
case TBM_FORMAT_NV21:
_tdm_helper_dump_raw(file,
- info.planes[0].ptr + info.planes[0].offset,
+ info.planes[0].ptr,
info.planes[0].stride * info.height,
- info.planes[1].ptr + info.planes[1].offset,
+ info.planes[1].ptr,
info.planes[1].stride * (info.height >> 1), NULL,
0);
break;
case TBM_FORMAT_YUYV:
case TBM_FORMAT_UYVY:
_tdm_helper_dump_raw(file,
- info.planes[0].ptr + info.planes[0].offset,
+ info.planes[0].ptr,
info.planes[0].stride * info.height, NULL, 0,
NULL, 0);
break;
TDM_INFO("dump %s", file);
}
+
+EXTERN int
+tdm_helper_get_fd(const char *env)
+{
+ const char *value;
+ int fd, newfd, flags, ret;
+
+ value = (const char*)getenv(env);
+ if (!value)
+ return -1;
+
+ ret = sscanf(value, "%d", &fd);
+ if (ret < 0) {
+ TDM_ERR("sscanf failed: %m");
+ return -1;
+ }
+
+ flags = fcntl(fd, F_GETFD);
+ if (flags == -1) {
+ TDM_ERR("fcntl failed: %m");
+ return -1;
+ }
+
+ newfd = dup(fd);
+ if (newfd < 0) {
+ TDM_ERR("dup failed: %m");
+ return -1;
+ }
+
+ TDM_INFO("%s: fd(%d) newfd(%d)", env, fd, newfd);
+
+ fcntl(newfd, F_SETFD, flags | FD_CLOEXEC);
+
+ return newfd;
+}
+
+EXTERN void
+tdm_helper_set_fd(const char *env, int fd)
+{
+ char buf[32];
+ int ret;
+
+ snprintf(buf, sizeof(buf), "%d", fd);
+
+ ret = setenv(env, (const char*)buf, 1);
+ if (ret) {
+ TDM_ERR("setenv failed: %m");
+ return;
+ }
+
+ if (fd >= 0)
+ TDM_INFO("%s: fd(%d)", env, fd);
+}
+
+EXTERN void
+tdm_helper_dump_start(char *dumppath, int *count)
+{
+ if (tdm_helper_dump_count != NULL) {
+ TDM_DBG("tdm_helper_dump is already started.");
+ return;
+ }
+
+ if (dumppath == NULL || count == NULL) {
+ TDM_DBG("tdm_helper_dump dumppath or count is null.");
+ return;
+ }
+
+ tdm_helper_dump_count = count;
+ tdm_helper_dump_path = dumppath;
+
+ tdm_dump_enable = 1;
+
+ TDM_DBG("tdm_helper_dump start.(path : %s)", tdm_helper_dump_path);
+}
+
+EXTERN void
+tdm_helper_dump_stop(void)
+{
+ tdm_helper_dump_path = NULL;
+ tdm_helper_dump_count = NULL;
+
+ tdm_dump_enable = 0;
+
+ TDM_DBG("tdm_helper_dump stop.");
+}
+