mp4write.c 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. #include <dlfcn.h>
  2. #include <stdio.h>
  3. #include <string.h>
  4. #include <sys/types.h>
  5. #include <sys/stat.h>
  6. #include <unistd.h>
  7. #include <errno.h>
  8. #include <stdlib.h>
  9. #include <string.h>
  10. static int (*original_mp4write_start_handler)(void *handler, char *file, void *config);
  11. static int mp4WriteEnable = 0;
  12. char *mp4Write(int fd, char *tokenPtr) {
  13. char *p = strtok_r(NULL, " \t\r\n", &tokenPtr);
  14. if(!p) return mp4WriteEnable ? "on" : "off";
  15. if(!strcmp(p, "on")) {
  16. mp4WriteEnable = 1;
  17. fprintf(stderr, "[command] mp4write on\n", p);
  18. return "ok";
  19. }
  20. if(!strcmp(p, "off")) {
  21. mp4WriteEnable = 0;
  22. fprintf(stderr, "[command] mp4write off\n", p);
  23. return "ok";
  24. }
  25. return "error in mp4write.c";
  26. }
  27. int mp4write_start_handler(void *handler, char *file, void *config, char *tokenPtr) {
  28. if(mp4WriteEnable) {
  29. const char* folder;
  30. folder = "/media/mmc/record/tmp";
  31. struct stat sb;
  32. printf("[command] mp4write.c: checking for temporary record directory\n");
  33. if (stat(folder, &sb) == 0 && S_ISDIR(sb.st_mode)) {
  34. printf("[command] mp4write.c: temporary directory exists.\n");
  35. } else {
  36. printf("[command] mp4write.c: directory missing, creating directory\n");
  37. mkdir("/media/mmc/record/tmp", 0700);
  38. }
  39. printf("mp4write.c: filename: %s\n", file);
  40. if(!strncmp(file, "/tmp/alarm_", 11)) {
  41. printf("mp4write.c: alarm, skipping\n", file);
  42. return (original_mp4write_start_handler)(handler, file, config);
  43. } else if(!strncmp(file, "/tmp/", 5)) {
  44. char buf[64];
  45. strncpy(buf, file + 5, 30);
  46. strcpy(file, "/media/mmc/record/tmp/");
  47. strcat(file, buf);
  48. }
  49. }
  50. return (original_mp4write_start_handler)(handler, file, config);
  51. }
  52. static void __attribute ((constructor)) mp4write_init(void) {
  53. original_mp4write_start_handler = dlsym(dlopen("/system/lib/libmp4rw.so", RTLD_LAZY), "mp4write_start_handler");
  54. }