gstdspbase.h 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  1. /*
  2. * Copyright (C) 2009-2010 Felipe Contreras
  3. *
  4. * Author: Felipe Contreras <felipe.contreras@gmail.com>
  5. *
  6. * This file may be used under the terms of the GNU Lesser General Public
  7. * License version 2.1, a copy of which is found in LICENSE included in the
  8. * packaging of this file.
  9. */
  10. #ifndef GST_DSP_BASE_H
  11. #define GST_DSP_BASE_H
  12. #include <gst/gst.h>
  13. G_BEGIN_DECLS
  14. #define GST_DSP_BASE(obj) (GstDspBase *)(obj)
  15. #define GST_DSP_BASE_TYPE (gst_dsp_base_get_type())
  16. #define GST_DSP_BASE_CLASS(obj) (GstDspBaseClass *)(obj)
  17. #define GST_DSP_BASE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), GST_DSP_BASE_TYPE, GstDspBaseClass))
  18. /* #define TS_COUNT */
  19. typedef struct _GstDspBase GstDspBase;
  20. typedef struct _GstDspBaseClass GstDspBaseClass;
  21. typedef struct du_port_t du_port_t;
  22. #include "dmm_buffer.h"
  23. #include "sem.h"
  24. #include "async_queue.h"
  25. struct td_buffer;
  26. typedef void (*port_buffer_cb_t) (GstDspBase *base, struct td_buffer *tb);
  27. struct td_buffer {
  28. struct du_port_t *port;
  29. dmm_buffer_t *data;
  30. dmm_buffer_t *comm;
  31. dmm_buffer_t *params;
  32. void *user_data;
  33. bool keyframe;
  34. bool pinned;
  35. bool clean;
  36. };
  37. struct du_port_t {
  38. int id;
  39. struct td_buffer *buffers;
  40. guint num_buffers;
  41. AsyncQueue *queue;
  42. port_buffer_cb_t send_cb;
  43. port_buffer_cb_t recv_cb;
  44. int dir;
  45. };
  46. struct td_codec {
  47. const struct dsp_uuid *uuid;
  48. const char *filename;
  49. void (*setup_params)(GstDspBase *base);
  50. void (*create_args)(GstDspBase *base, unsigned *profile_id, void **arg_data);
  51. bool (*handle_extra_data)(GstDspBase *base, GstBuffer *buf);
  52. void (*flush_buffer)(GstDspBase *base);
  53. void (*send_params)(GstDspBase *base, struct dsp_node *node);
  54. void (*update_params) (GstDspBase *base, struct dsp_node *node, uint32_t msg);
  55. unsigned (*get_latency)(GstDspBase *base, unsigned frame_duration);
  56. };
  57. struct ts_item {
  58. GstClockTime time;
  59. GstClockTime duration;
  60. GstEvent *event;
  61. };
  62. struct _GstDspBase {
  63. GstElement element;
  64. GstPad *sinkpad, *srcpad;
  65. struct td_codec *codec;
  66. int dsp_handle;
  67. void *proc;
  68. struct dsp_node *node;
  69. struct dsp_notification *events[3];
  70. GstFlowReturn status;
  71. unsigned long input_buffer_size;
  72. unsigned long output_buffer_size;
  73. GThread *dsp_thread, *out_thread;
  74. gboolean done;
  75. int deferred_eos;
  76. int eos;
  77. du_port_t *ports[2];
  78. dmm_buffer_t *alg_ctrl;
  79. struct ts_item ts_array[20];
  80. guint ts_in_pos, ts_out_pos, ts_push_pos;
  81. GMutex *ts_mutex;
  82. gulong ts_count;
  83. GstClockTime default_duration;
  84. GSem *flush;
  85. guint alg;
  86. gboolean use_pad_alloc; /**< Use pad_alloc for output buffers. */
  87. gboolean use_pinned; /**< Reuse output buffers. */
  88. guint dsp_error;
  89. void *(*create_node)(GstDspBase *base);
  90. bool (*parse_func)(GstDspBase *base, GstBuffer *buf);
  91. void (*pre_process_buffer)(GstDspBase *base, GstBuffer *buf);
  92. void (*reset)(GstDspBase *base);
  93. void (*flush_buffer)(GstDspBase *base);
  94. void (*got_message)(GstDspBase *self, struct dsp_msg *msg);
  95. bool (*send_buffer)(GstDspBase *self, struct td_buffer *tb);
  96. bool (*send_play_message)(GstDspBase *self);
  97. bool (*send_stop_message)(GstDspBase *self);
  98. GstCaps *tmp_caps;
  99. struct timespec eos_start;
  100. gint eos_timeout; /* how much to wait for the EOS from DSP (ms) */
  101. GstBuffer *codec_data;
  102. bool parsed;
  103. /* hacks */
  104. guint skip_hack; /* don't push x number of buffers */
  105. guint skip_hack_2; /* don't process x number of buffers */
  106. };
  107. struct _GstDspBaseClass {
  108. GstElementClass parent_class;
  109. gboolean (*sink_event)(GstDspBase *base, GstEvent *event);
  110. gboolean (*src_event)(GstDspBase *base, GstEvent *event);
  111. };
  112. GType gst_dsp_base_get_type(void);
  113. du_port_t *du_port_new(int id, int dir);
  114. void du_port_free(du_port_t *p);
  115. void du_port_alloc_buffers(du_port_t *p, guint num_buffers);
  116. gboolean gstdsp_start(GstDspBase *self);
  117. gboolean gstdsp_send_codec_data(GstDspBase *self, GstBuffer *buf);
  118. gboolean gstdsp_set_codec_data_caps(GstDspBase *base, GstBuffer *buf);
  119. gboolean gstdsp_reinit(GstDspBase *base);
  120. void gstdsp_got_error(GstDspBase *self, guint id, const char *message);
  121. void gstdsp_post_error(GstDspBase *self, const char *message);
  122. void gstdsp_send_alg_ctrl(GstDspBase *self, struct dsp_node *node, dmm_buffer_t *b);
  123. void gstdsp_base_flush_buffer(GstDspBase *self);
  124. typedef void (*gstdsp_setup_params_func)(GstDspBase *base, dmm_buffer_t *b);
  125. static inline void gstdsp_port_setup_params(GstDspBase *self,
  126. du_port_t *p,
  127. size_t size,
  128. gstdsp_setup_params_func func)
  129. {
  130. unsigned i;
  131. for (i = 0; i < p->num_buffers; i++) {
  132. dmm_buffer_t *b;
  133. b = dmm_buffer_calloc(self->dsp_handle,
  134. self->proc, size, DMA_BIDIRECTIONAL);
  135. if (func)
  136. func(self, b);
  137. dmm_buffer_map(b);
  138. p->buffers[i].params = b;
  139. }
  140. }
  141. /* this is saner than gst_pad_set_caps() */
  142. static inline bool gst_pad_take_caps(GstPad *pad, GstCaps *caps)
  143. {
  144. bool ret;
  145. ret = gst_pad_set_caps(pad, caps);
  146. gst_caps_unref(caps);
  147. return ret;
  148. }
  149. extern struct td_codec td_mp4vdec_codec;
  150. extern struct td_codec td_h264dec_codec;
  151. extern struct td_codec td_wmvdec_codec;
  152. extern struct td_codec td_jpegdec_codec;
  153. extern struct td_codec td_mp4venc_codec;
  154. extern struct td_codec td_jpegenc_codec;
  155. extern struct td_codec td_h264enc_codec;
  156. extern struct td_codec td_vpp_codec;
  157. extern struct td_codec td_aacdec_codec;
  158. G_END_DECLS
  159. #endif /* GST_DSP_BASE_H */