mp4write.c 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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) {
  28. if(mp4WriteEnable) {
  29. struct stat st = {0};
  30. if(!strncmp(file, "/tmp/", 5)) {
  31. char buf[64];
  32. strncpy(buf, file + 5, 30);
  33. if (stat("/media/mmc/record/tmp", &st) == -1) {
  34. mkdir("/media/mmc/record/tmp", 0700);
  35. }
  36. strcpy(file, "/media/mmc/record/tmp/");
  37. strcat(file, buf);
  38. }
  39. }
  40. return (original_mp4write_start_handler)(handler, file, config);
  41. }
  42. static void __attribute ((constructor)) mp4write_init(void) {
  43. original_mp4write_start_handler = dlsym(dlopen("/system/lib/libmp4rw.so", RTLD_LAZY), "mp4write_start_handler");
  44. }