subtitle.c 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381
  1. #include <linux/module.h>
  2. #include <linux/spinlock.h>
  3. #include <linux/kernel.h>
  4. #include <linux/device.h>
  5. #include <linux/vmalloc.h>
  6. #include <linux/amlog.h>
  7. MODULE_AMLOG(AMLOG_DEFAULT_LEVEL, 0, LOG_DEFAULT_LEVEL_DESC, LOG_DEFAULT_MASK_DESC);
  8. #define MAX_SUBTITLE_PACKET 10
  9. typedef struct {
  10. int subtitle_size;
  11. int subtitle_pts;
  12. char * data;
  13. } subtitle_data_t;
  14. static subtitle_data_t subtitle_data[MAX_SUBTITLE_PACKET];
  15. static int subtitle_enable = 1;
  16. static int subtitle_total = 0;
  17. static int subtitle_width = 0;
  18. static int subtitle_height = 0;
  19. static int subtitle_type = -1;
  20. static int subtitle_current = 0; // no subtitle
  21. //static int subtitle_size = 0;
  22. //static int subtitle_read_pos = 0;
  23. static int subtitle_write_pos = 0;
  24. static int subtitle_start_pts = 0;
  25. static int subtitle_fps = 0;
  26. static int subtitle_subtype = 0;
  27. //static int *subltitle_address[MAX_SUBTITLE_PACKET];
  28. // total
  29. // curr
  30. // bimap
  31. // text
  32. // type
  33. // info
  34. // pts
  35. // duration
  36. // color pallete
  37. // width/height
  38. static ssize_t show_curr(struct class *class,
  39. struct class_attribute *attr,
  40. char *buf)
  41. {
  42. return sprintf(buf, "%d: current\n", subtitle_current);
  43. }
  44. static ssize_t store_curr(struct class *class,
  45. struct class_attribute *attr,
  46. const char *buf,
  47. size_t size)
  48. {
  49. unsigned curr;
  50. ssize_t r;
  51. r = sscanf(buf, "%d", &curr);
  52. //if ((r != 1))
  53. //return -EINVAL;
  54. subtitle_current = curr;
  55. return size;
  56. }
  57. static ssize_t show_type(struct class *class,
  58. struct class_attribute *attr,
  59. char *buf)
  60. {
  61. return sprintf(buf, "%d: type\n", subtitle_type);
  62. }
  63. static ssize_t store_type(struct class *class,
  64. struct class_attribute *attr,
  65. const char *buf,
  66. size_t size)
  67. {
  68. unsigned type;
  69. ssize_t r;
  70. r = sscanf(buf, "%d", &type);
  71. //if ((r != 1))
  72. // return -EINVAL;
  73. subtitle_type = type;
  74. return size;
  75. }
  76. static ssize_t show_width(struct class *class,
  77. struct class_attribute *attr,
  78. char *buf)
  79. {
  80. return sprintf(buf, "%d: width\n", subtitle_width);
  81. }
  82. static ssize_t store_width(struct class *class,
  83. struct class_attribute *attr,
  84. const char *buf,
  85. size_t size)
  86. {
  87. unsigned width;
  88. ssize_t r;
  89. r = sscanf(buf, "%d", &width);
  90. //if ((r != 1))
  91. //return -EINVAL;
  92. subtitle_width = width;
  93. return size;
  94. }
  95. static ssize_t show_height(struct class *class,
  96. struct class_attribute *attr,
  97. char *buf)
  98. {
  99. return sprintf(buf, "%d: height\n", subtitle_height);
  100. }
  101. static ssize_t store_height(struct class *class,
  102. struct class_attribute *attr,
  103. const char *buf,
  104. size_t size)
  105. {
  106. unsigned height;
  107. ssize_t r;
  108. r = sscanf(buf, "%d", &height);
  109. //if ((r != 1))
  110. //return -EINVAL;
  111. subtitle_height = height;
  112. return size;
  113. }
  114. static ssize_t show_total(struct class *class,
  115. struct class_attribute *attr,
  116. char *buf)
  117. {
  118. return sprintf(buf, "%d: num\n", subtitle_total);
  119. }
  120. static ssize_t store_total(struct class *class,
  121. struct class_attribute *attr,
  122. const char *buf,
  123. size_t size)
  124. {
  125. unsigned total;
  126. ssize_t r;
  127. r = sscanf(buf, "%d", &total);
  128. if ((r <= 0)) {
  129. return -EINVAL;
  130. }
  131. printk("subtitle num is %d\n", total);
  132. subtitle_total = total;
  133. return size;
  134. }
  135. static ssize_t show_enable(struct class *class,
  136. struct class_attribute *attr,
  137. char *buf)
  138. {
  139. if (subtitle_enable) {
  140. return sprintf(buf, "1: enabled\n");
  141. }
  142. return sprintf(buf, "0: disabled\n");
  143. }
  144. static ssize_t store_enable(struct class *class,
  145. struct class_attribute *attr,
  146. const char *buf,
  147. size_t size)
  148. {
  149. unsigned mode;
  150. ssize_t r;
  151. r = sscanf(buf, "%d", &mode);
  152. if ((r != 1)) {
  153. return -EINVAL;
  154. }
  155. printk("subtitle enable is %d\n", mode);
  156. subtitle_enable = mode ? 1 : 0;
  157. return size;
  158. }
  159. static ssize_t show_size(struct class *class,
  160. struct class_attribute *attr,
  161. char *buf)
  162. {
  163. if (subtitle_enable) {
  164. return sprintf(buf, "1: size\n");
  165. }
  166. return sprintf(buf, "0: size\n");
  167. }
  168. static ssize_t store_size(struct class *class,
  169. struct class_attribute *attr,
  170. const char *buf,
  171. size_t size)
  172. {
  173. unsigned ssize;
  174. ssize_t r;
  175. r = sscanf(buf, "%d", &ssize);
  176. if ((r <= 0)) {
  177. return -EINVAL;
  178. }
  179. printk("subtitle size is %d\n", ssize);
  180. subtitle_data[subtitle_write_pos].subtitle_size = ssize;
  181. return size;
  182. }
  183. static ssize_t show_startpts(struct class *class,
  184. struct class_attribute *attr,
  185. char *buf)
  186. {
  187. return sprintf(buf, "%d: pts\n", subtitle_start_pts);
  188. }
  189. static ssize_t store_startpts(struct class *class,
  190. struct class_attribute *attr,
  191. const char *buf,
  192. size_t size)
  193. {
  194. unsigned spts;
  195. ssize_t r;
  196. r = sscanf(buf, "%d", &spts);
  197. if ((r <= 0)) {
  198. return -EINVAL;
  199. }
  200. printk("subtitle start pts is %x\n", spts);
  201. subtitle_start_pts = spts;
  202. return size;
  203. }
  204. static ssize_t show_data(struct class *class,
  205. struct class_attribute *attr,
  206. char *buf)
  207. {
  208. if (subtitle_data[subtitle_write_pos].data) {
  209. return sprintf(buf, "%d\n", (int)(subtitle_data[subtitle_write_pos].data));
  210. }
  211. return sprintf(buf, "0: disabled\n");
  212. }
  213. static ssize_t store_data(struct class *class,
  214. struct class_attribute *attr,
  215. const char *buf,
  216. size_t size)
  217. {
  218. unsigned address;
  219. ssize_t r;
  220. r = sscanf(buf, "%d", &address);
  221. if ((r == 0)) {
  222. return -EINVAL;
  223. }
  224. if (subtitle_data[subtitle_write_pos].subtitle_size > 0) {
  225. subtitle_data[subtitle_write_pos].data = vmalloc((subtitle_data[subtitle_write_pos].subtitle_size));
  226. if (subtitle_data[subtitle_write_pos].data)
  227. memcpy(subtitle_data[subtitle_write_pos].data, (char *)address,
  228. subtitle_data[subtitle_write_pos].subtitle_size);
  229. }
  230. printk("subtitle data address is %x", (unsigned int)(subtitle_data[subtitle_write_pos].data));
  231. subtitle_write_pos++;
  232. if (subtitle_write_pos >= MAX_SUBTITLE_PACKET) {
  233. subtitle_write_pos = 0;
  234. }
  235. return 1;
  236. }
  237. static ssize_t show_fps(struct class *class,
  238. struct class_attribute *attr,
  239. char *buf)
  240. {
  241. return sprintf(buf, "%d: fps\n", subtitle_fps);
  242. }
  243. static ssize_t store_fps(struct class *class,
  244. struct class_attribute *attr,
  245. const char *buf,
  246. size_t size)
  247. {
  248. unsigned ssize;
  249. ssize_t r;
  250. r = sscanf(buf, "%d", &ssize);
  251. if ((r <= 0)) {
  252. return -EINVAL;
  253. }
  254. printk("subtitle fps is %d\n", ssize);
  255. subtitle_fps = ssize;
  256. return size;
  257. }
  258. static ssize_t show_subtype(struct class *class,
  259. struct class_attribute *attr,
  260. char *buf)
  261. {
  262. return sprintf(buf, "%d: subtype\n", subtitle_subtype);
  263. }
  264. static ssize_t store_subtype(struct class *class,
  265. struct class_attribute *attr,
  266. const char *buf,
  267. size_t size)
  268. {
  269. unsigned ssize;
  270. ssize_t r;
  271. r = sscanf(buf, "%d", &ssize);
  272. if ((r <= 0)) {
  273. return -EINVAL;
  274. }
  275. printk("subtitle subtype is %d\n", ssize);
  276. subtitle_subtype = ssize;
  277. return size;
  278. }
  279. static struct class_attribute subtitle_class_attrs[] = {
  280. __ATTR(enable, S_IRUGO | S_IWUSR, show_enable, store_enable),
  281. __ATTR(total, S_IRUGO | S_IWUSR, show_total, store_total),
  282. __ATTR(width, S_IRUGO | S_IWUSR, show_width, store_width),
  283. __ATTR(height, S_IRUGO | S_IWUSR, show_height, store_height),
  284. __ATTR(type, S_IRUGO | S_IWUSR, show_type, store_type),
  285. __ATTR(curr, S_IRUGO | S_IWUSR, show_curr, store_curr),
  286. __ATTR(size, S_IRUGO | S_IWUSR, show_size, store_size),
  287. __ATTR(data, S_IRUGO | S_IWUSR, show_data, store_data),
  288. __ATTR(startpts, S_IRUGO | S_IWUSR, show_startpts, store_startpts),
  289. __ATTR(fps, S_IRUGO | S_IWUSR, show_fps, store_fps),
  290. __ATTR(subtype, S_IRUGO | S_IWUSR, show_subtype, store_subtype),
  291. __ATTR_NULL
  292. };
  293. static struct class subtitle_class = {
  294. .name = "subtitle",
  295. .class_attrs = subtitle_class_attrs,
  296. };
  297. static int __init subtitle_init(void)
  298. {
  299. int r;
  300. r = class_register(&subtitle_class);
  301. if (r) {
  302. amlog_level(LOG_LEVEL_ERROR, "subtitle class create fail.\n");
  303. return r;
  304. }
  305. return (0);
  306. }
  307. static void __exit subtitle_exit(void)
  308. {
  309. class_unregister(&subtitle_class);
  310. }
  311. module_init(subtitle_init);
  312. module_exit(subtitle_exit);
  313. MODULE_DESCRIPTION("AMLOGIC Subtitle management driver");
  314. MODULE_LICENSE("GPL");
  315. MODULE_AUTHOR("Kevin Wang <kevin.wang@amlogic.com>");