/cpvt.h

http://datacard.googlecode.com/ · C Header · 117 lines · 79 code · 26 blank · 12 comment · 9 complexity · 4a2b3deb3fbc89b312300b66a3ccf8cb MD5 · raw file

  1. /*
  2. Copyright (C) 2010 bg <bg_one@mail.ru>
  3. */
  4. #ifndef CHAN_DATACARD_CPVT_H_INCLUDED
  5. #define CHAN_DATACARD_CPVT_H_INCLUDED
  6. #include <asterisk.h>
  7. #include <asterisk/linkedlists.h> /* AST_LIST_ENTRY() */
  8. #include <asterisk/frame.h> /* AST_FRIENDLY_OFFSET */
  9. #include "export.h" /* EXPORT_DECL EXPORT_DEF */
  10. #include "mixbuffer.h" /* struct mixstream */
  11. #include "mutils.h" /* enum2str() ITEMS_OF() */
  12. #define FRAME_SIZE 320
  13. typedef enum {
  14. CALL_STATE_MIN = 0,
  15. /* values from CLCC */
  16. CALL_STATE_ACTIVE = CALL_STATE_MIN, /*!< comes from CLCC */
  17. CALL_STATE_ONHOLD, /*!< comes from CLCC */
  18. CALL_STATE_DIALING, /*!< comes from CLCC */
  19. CALL_STATE_ALERTING, /*!< comes from CLCC */
  20. CALL_STATE_INCOMING, /*!< comes from CLCC */
  21. CALL_STATE_WAITING, /*!< comes from CLCC */
  22. CALL_STATE_RELEASED, /*!< on CEND or channel_hangup() called */
  23. CALL_STATE_INIT, /*!< channel_call() called */
  24. CALL_STATE_MAX = CALL_STATE_INIT
  25. } call_state_t;
  26. #define CALL_STATES_NUMBER (CALL_STATE_MAX - CALL_STATE_MIN + 1)
  27. typedef enum {
  28. CALL_FLAG_NONE = 0,
  29. CALL_FLAG_HOLD_OTHER = 1, /*!< external, from channel_call() hold other calls and dial this number */
  30. CALL_FLAG_NEED_HANGUP = 2, /*!< internal, require issue AT+CHUP or AT+CHLD=1x for call */
  31. CALL_FLAG_ACTIVATED = 4, /*!< internal, fd attached to channel fds list */
  32. CALL_FLAG_ALIVE = 8, /*!< internal, temporary, still listed in CLCC */
  33. CALL_FLAG_CONFERENCE = 16, /*!< external, from dial() begin conference after activate this call */
  34. CALL_FLAG_MASTER = 32, /*!< internal, channel fd[0] is pvt->audio_fd and fd[1] is timer fd */
  35. CALL_FLAG_BRIDGE_LOOP = 64, /*!< internal, found channel bridged to channel on same device */
  36. CALL_FLAG_BRIDGE_CHECK = 128, /*!< internal, we already do check for bridge loop */
  37. CALL_FLAG_MULTIPARTY = 256, /*!< internal, CLCC mpty is 1 */
  38. } call_flag_t;
  39. /* */
  40. typedef struct cpvt {
  41. AST_LIST_ENTRY (cpvt) entry; /*!< linked list pointers */
  42. struct ast_channel* channel; /*!< Channel pointer */
  43. struct pvt *pvt; /*!< pointer to device structure */
  44. short call_idx; /*!< device call ID */
  45. #define MIN_CALL_IDX 0
  46. #define MAX_CALL_IDX 31
  47. call_state_t state; /*!< see also call_state_t */
  48. int flags; /*!< see also call_flag_t */
  49. /* TODO: join with flags */
  50. unsigned int dir:1; /*!< call direction */
  51. #define CALL_DIR_OUTGOING 0
  52. #define CALL_DIR_INCOMING 1
  53. int rd_pipe[2]; /*!< pipe for split readed from device */
  54. #define PIPE_READ 0
  55. #define PIPE_WRITE 1
  56. struct mixstream mixstream; /*!< mix stream */
  57. char a_read_buf[FRAME_SIZE + AST_FRIENDLY_OFFSET];/*!< audio read buffer */
  58. struct ast_frame a_read_frame; /*!< readed frame buffer */
  59. // size_t write; /*!< write position in pvt->a_write_buf */
  60. // size_t used; /*!< bytes used in pvt->a_write_buf */
  61. // char a_write_buf[FRAME_SIZE * 5]; /*!< audio write buffer */
  62. // struct ringbuffer a_write_rb; /*!< audio ring buffer */
  63. } cpvt_t;
  64. #define CPVT_SET_FLAGS(cpvt, flag) do { (cpvt)->flags |= (flag); } while(0)
  65. #define CPVT_RESET_FLAGS(cpvt, flag) do { (cpvt)->flags &= ~((int)flag); } while(0)
  66. #define CPVT_TEST_FLAG(cpvt, flag) ((cpvt)->flags & (flag))
  67. #define CPVT_TEST_FLAGS(cpvt, flag) (((cpvt)->flags & (flag)) == (flag))
  68. #define CPVT_IS_MASTER(cpvt) CPVT_TEST_FLAG(cpvt, CALL_FLAG_MASTER)
  69. #define CPVT_IS_ACTIVE(cpvt) ((cpvt)->state == CALL_STATE_ACTIVE)
  70. #define CPVT_IS_SOUND_SOURCE(cpvt) ((cpvt)->state == CALL_STATE_ACTIVE || (cpvt)->state == CALL_STATE_DIALING || (cpvt)->state == CALL_STATE_ALERTING)
  71. EXPORT_DECL struct cpvt * cpvt_alloc(struct pvt * pvt, int call_idx, unsigned dir, call_state_t statem);
  72. EXPORT_DECL void cpvt_free(struct cpvt* cpvt);
  73. EXPORT_DECL struct cpvt * pvt_find_cpvt(struct pvt * pvt, int call_idx);
  74. #/* */
  75. INLINE_DECL const char * call_state2str(call_state_t state)
  76. {
  77. static const char * const states[] = {
  78. /* real device states */
  79. "active",
  80. "held",
  81. "dialing",
  82. "alerting",
  83. "incoming",
  84. "waiting",
  85. /* pseudo states */
  86. "released",
  87. "initialize"
  88. };
  89. return enum2str(state, states, ITEMS_OF(states));
  90. }
  91. #endif /* CHAN_DATACARD_CPVT_H_INCLUDED */