mjpeg_plugin.c 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. #include "video_player_defs.h"
  2. #include "vp_engine.h"
  3. #include <soc_dsp.h>
  4. #include "video_mem.h"
  5. #include <jpeg_hal.h>
  6. #include <file_stream.h>
  7. #define IMAGE_BUF_SIZE (VIDEO_PIXEL_WIDTH*VIDEO_PIXEL_HEIGHT*2)
  8. #define PADDING_ALIGN_SIZE 1024
  9. #define FRAME_DEC_TIMEOUT (300*1000)
  10. //static int frame_num = 0;
  11. typedef struct {
  12. void *dsp_handle;
  13. ve_video_info_t vinfo;
  14. struct acts_ringbuf *aud_ringbuf;
  15. } mjpeg_plugin_data_t;
  16. static mjpeg_plugin_data_t *plugin_data = NULL;
  17. static void *open(void *arg)
  18. {
  19. ve_video_info_t *vinfo = (ve_video_info_t *)arg;
  20. mjpeg_plugin_data_t *data;
  21. data = video_mem_malloc(sizeof(mjpeg_plugin_data_t));
  22. if(data == NULL)
  23. {
  24. SYS_LOG_ERR("data malloc error %d\n", __LINE__);
  25. return NULL;
  26. }
  27. memset(data, 0, sizeof(mjpeg_plugin_data_t));
  28. plugin_data = data;
  29. memcpy(&plugin_data->vinfo, vinfo, sizeof(ve_video_info_t));
  30. //frame_num = 0;
  31. SYS_LOG_INF("ok");
  32. return data;
  33. }
  34. static int decode(void *dhandle, av_buf_t *av_buf)
  35. {
  36. mjpeg_plugin_data_t *data = (mjpeg_plugin_data_t *)dhandle;
  37. ve_video_info_t *vinfo = &data->vinfo;
  38. int ret;
  39. uint32_t time_before, time_after;
  40. time_before = os_uptime_get_32();
  41. ret = jpg_decode(av_buf->data, av_buf->data_len, av_buf->outbuf, 1, vinfo->width,
  42. 0, 0, vinfo->width, vinfo->height);
  43. if(ret != vinfo->width * vinfo->height * 2) {
  44. SYS_LOG_ERR("### _jpg_decode fail %d", ret);
  45. return EN_DECERR;
  46. }
  47. time_after = os_uptime_get_32();
  48. //SYS_LOG_INF("### frame[%d, %d], time: %d\n", frame_num, ori_len, k_cyc_to_us_floor32(k_cycle_get_32() - start_time));
  49. //frame_num ++;
  50. SYS_LOG_DBG("### spend time:%d", time_after - time_before);
  51. return EN_NORMAL;
  52. }
  53. static int dispose(void *dhandle)
  54. {
  55. mjpeg_plugin_data_t *data = (mjpeg_plugin_data_t *)dhandle;
  56. if (data)
  57. video_mem_free(data);
  58. plugin_data = NULL;
  59. return 0;
  60. }
  61. static dec_plugin_t mjpeg_plugin = {
  62. "mjpeg",
  63. open,
  64. decode,
  65. dispose
  66. };
  67. dec_plugin_t * mjpeg_api(void)
  68. {
  69. return &mjpeg_plugin;
  70. }