gstdspbase.h 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  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 CODEC_ENV_VAR "GSTDSP_CODEC"
  15. #define GST_DSP_BASE(obj) (GstDspBase *)(obj)
  16. #define GST_DSP_BASE_TYPE (gst_dsp_base_get_type())
  17. #define GST_DSP_BASE_CLASS(obj) (GstDspBaseClass *)(obj)
  18. #define GST_DSP_BASE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), GST_DSP_BASE_TYPE, GstDspBaseClass))
  19. #define XDM_APPLIEDCONCEALMENT 9
  20. #define XDM_UNSUPPORTEDINPUT 13
  21. #define XDM_UNSUPPORTEDPARAM 14
  22. #define XDM_FATALERROR 15
  23. #define XDM_ERROR_IS_UNSUPPORTED(x) ((x) & (1 << XDM_UNSUPPORTEDINPUT | 1 << XDM_UNSUPPORTEDPARAM))
  24. #define XDM_ERROR_IS_APPLIEDCONCEALMENT(x) ((x) & (1 << XDM_APPLIEDCONCEALMENT))
  25. #define XDM_ERROR_IS_FATAL(x) ((x) & (1 << XDM_FATALERROR))
  26. /* #define TS_COUNT */
  27. typedef struct _GstDspBase GstDspBase;
  28. typedef struct _GstDspBaseClass GstDspBaseClass;
  29. typedef struct du_port_t du_port_t;
  30. #include "dmm_buffer.h"
  31. #include "sem.h"
  32. #include "async_queue.h"
  33. struct td_buffer;
  34. typedef void (*port_buffer_cb_t) (GstDspBase *base, struct td_buffer *tb);
  35. struct td_buffer {
  36. struct du_port_t *port;
  37. dmm_buffer_t *data;
  38. dmm_buffer_t *comm;
  39. dmm_buffer_t *params;
  40. void *user_data;
  41. bool keyframe;
  42. bool pinned;
  43. bool clean;
  44. };
  45. struct du_port_t {
  46. int id;
  47. struct td_buffer *buffers;
  48. guint num_buffers;
  49. AsyncQueue *queue;
  50. port_buffer_cb_t send_cb;
  51. port_buffer_cb_t recv_cb;
  52. int dir;
  53. };
  54. enum ts_mode {
  55. TS_MODE_PASS, /* copy input ts to output */
  56. TS_MODE_CHECK_IN, /* as above, but check if ascending, or below... */
  57. TS_MODE_CHECK_OUT, /* use ts as provided by socket node, and it not ascending... */
  58. TS_MODE_INTERPOLATE, /* use input ts for keyframes, interpolate for other */
  59. };
  60. struct td_codec {
  61. const struct dsp_uuid *uuid;
  62. const char *filename;
  63. void (*setup_params)(GstDspBase *base);
  64. void (*create_args)(GstDspBase *base, unsigned *profile_id, void **arg_data);
  65. bool (*handle_extra_data)(GstDspBase *base, GstBuffer *buf);
  66. void (*flush_buffer)(GstDspBase *base);
  67. void (*send_params)(GstDspBase *base, struct dsp_node *node);
  68. void (*update_params) (GstDspBase *base, struct dsp_node *node, uint32_t msg);
  69. unsigned (*get_latency)(GstDspBase *base, unsigned frame_duration);
  70. enum ts_mode ts_mode;
  71. };
  72. struct ts_item {
  73. GstClockTime time;
  74. GstClockTime duration;
  75. GSList *events;
  76. };
  77. struct _GstDspBase {
  78. GstElement element;
  79. GstPad *sinkpad, *srcpad;
  80. struct td_codec *codec;
  81. int dsp_handle;
  82. void *proc;
  83. struct dsp_node *node;
  84. struct dsp_notification *events[3];
  85. GstFlowReturn status;
  86. unsigned long input_buffer_size;
  87. unsigned long output_buffer_size;
  88. GThread *dsp_thread, *out_thread;
  89. gboolean done;
  90. int deferred_eos;
  91. int eos;
  92. du_port_t *ports[2];
  93. dmm_buffer_t *alg_ctrl;
  94. struct ts_item ts_array[40];
  95. guint ts_in_pos, ts_out_pos, ts_push_pos;
  96. GMutex *ts_mutex;
  97. GCond *ts_cond;
  98. gulong ts_count;
  99. GstClockTime last_ts, next_ts;
  100. enum ts_mode ts_mode;
  101. GstClockTime default_duration;
  102. GSem *flush;
  103. guint alg;
  104. gboolean use_pad_alloc; /**< Use pad_alloc for output buffers. */
  105. gboolean use_pinned; /**< Reuse output buffers. */
  106. GMutex *pool_mutex;
  107. gint cycle;
  108. guint dsp_error;
  109. void *(*create_node)(GstDspBase *base);
  110. bool (*parse_func)(GstDspBase *base, GstBuffer *buf);
  111. void (*pre_process_buffer)(GstDspBase *base, GstBuffer *buf);
  112. void (*reset)(GstDspBase *base);
  113. void (*flush_buffer)(GstDspBase *base);
  114. void (*got_message)(GstDspBase *self, struct dsp_msg *msg);
  115. GstFlowReturn (*send_buffer)(GstDspBase *self, struct td_buffer *tb);
  116. bool (*send_play_message)(GstDspBase *self);
  117. bool (*send_stop_message)(GstDspBase *self);
  118. GstCaps *tmp_caps;
  119. GstSegment segment;
  120. struct timespec eos_start;
  121. gint eos_timeout; /* how much to wait for the EOS from DSP (ms) */
  122. int qos;
  123. GstBuffer *codec_data;
  124. bool parsed;
  125. bool busy;
  126. /* hacks */
  127. guint skip_hack; /* don't push x number of buffers */
  128. guint skip_hack_2; /* don't process x number of buffers */
  129. guint sn_api;
  130. };
  131. struct _GstDspBaseClass {
  132. GstElementClass parent_class;
  133. gboolean (*sink_event)(GstDspBase *base, GstEvent *event);
  134. gboolean (*src_event)(GstDspBase *base, GstEvent *event);
  135. };
  136. GType gst_dsp_base_get_type(void);
  137. du_port_t *du_port_new(int id, int dir);
  138. void du_port_free(du_port_t *p);
  139. void du_port_alloc_buffers(du_port_t *p, guint num_buffers);
  140. gboolean gstdsp_start(GstDspBase *self);
  141. gboolean gstdsp_send_codec_data(GstDspBase *self, GstBuffer *buf);
  142. gboolean gstdsp_set_codec_data_caps(GstDspBase *base, GstBuffer *buf);
  143. gboolean gstdsp_need_node_reset(GstDspBase *base, GstCaps *new_caps, gint w, gint h);
  144. gboolean gstdsp_reinit(GstDspBase *base);
  145. void gstdsp_got_error(GstDspBase *self, guint id, const char *message);
  146. void gstdsp_post_error(GstDspBase *self, const char *message);
  147. void gstdsp_send_alg_ctrl(GstDspBase *self, struct dsp_node *node, dmm_buffer_t *b);
  148. void gstdsp_base_flush_buffer(GstDspBase *self);
  149. typedef void (*gstdsp_setup_params_func)(GstDspBase *base, dmm_buffer_t *b);
  150. static inline void gstdsp_port_setup_params(GstDspBase *self,
  151. du_port_t *p,
  152. size_t size,
  153. gstdsp_setup_params_func func)
  154. {
  155. unsigned i;
  156. for (i = 0; i < p->num_buffers; i++) {
  157. dmm_buffer_t *b;
  158. b = dmm_buffer_calloc(self->dsp_handle,
  159. self->proc, size, DMA_BIDIRECTIONAL);
  160. if (func)
  161. func(self, b);
  162. dmm_buffer_map(b);
  163. p->buffers[i].params = b;
  164. }
  165. }
  166. /* this is saner than gst_pad_set_caps() */
  167. static inline bool gst_pad_take_caps(GstPad *pad, GstCaps *caps)
  168. {
  169. bool ret;
  170. ret = gst_pad_set_caps(pad, caps);
  171. gst_caps_unref(caps);
  172. return ret;
  173. }
  174. extern struct td_codec td_mp4vdec_codec;
  175. extern struct td_codec td_h264dec_codec;
  176. extern struct td_codec td_wmvdec_codec;
  177. extern struct td_codec td_jpegdec_codec;
  178. extern struct td_codec td_hdmp4vdec_codec;
  179. extern struct td_codec td_hdh264dec_bp_codec;
  180. extern struct td_codec td_hdh264dec_hp_codec;
  181. extern struct td_codec td_hdh264enc_codec;
  182. extern struct td_codec td_mp4venc_codec;
  183. extern struct td_codec td_jpegenc_codec;
  184. extern struct td_codec td_h264enc_codec;
  185. extern struct td_codec td_hdmp4venc_codec;
  186. extern struct td_codec td_vpp_codec;
  187. extern struct td_codec td_aacdec_codec;
  188. extern struct td_codec td_fake_codec;
  189. G_END_DECLS
  190. #endif /* GST_DSP_BASE_H */