audiostream.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. #ifndef __AUDIOSTREAM_H__
  2. #define __AUDIOSTREAM_H__
  3. #pragma once
  4. #ifdef __cplusplus
  5. extern "C" {
  6. #endif
  7. #include "audioframe.h"
  8. #define AMS2_OPT_AGC 0x04
  9. #define AMS2_OPT_NS 0x08
  10. #define AMS2_OPT_AEC 0x10
  11. /** stream direction flag */
  12. #define STREAM_DIR_NONE 0
  13. #define STREAM_DIR_READ 1
  14. #define STREAM_DIR_WRITE 2
  15. #define STREAM_DIR_BOTH 3
  16. #define EVT_STREAM_BASE 0x00000000
  17. #define STREAM_EVT_FILE_REPLAY (EVT_STREAM_BASE + 0) // file replay
  18. #define STREAM_EVT_FILE_IOERROR (EVT_STREAM_BASE + 1) // io error, param1: GetLastError()
  19. #define STREAM_EVT_RTP_DTMF (EVT_STREAM_BASE + 2) // receive dtmf, for AudioRtpStream
  20. #define STREAM_EVT_RTP_TIMEOUT (EVT_STREAM_BASE + 3) // not receive any peer packet in specified time, for AudioRtpStream
  21. #define STREAM_EVT_FAX_END (EVT_STREAM_BASE + 4) // for fax stream
  22. #define STREAM_EVT_REC_END (EVT_STREAM_BASE + 5) // for recply record
  23. #define STREAM_EVT_PLY_END (EVT_STREAM_BASE + 6) // for recply play
  24. #define STREAM_EVT_TFX_END (EVT_STREAM_BASE + 7) // for recply send fax
  25. #define STREAM_EVT_RFX_END (EVT_STREAM_BASE + 8) // for recply recv fax
  26. #define MAX_DTMF 72
  27. typedef struct audiostream_vtbl_t
  28. {
  29. apr_status_t (*read_frame)(void *self, audioframe_t *frame);
  30. apr_status_t (*write_frame)(void *self, const audioframe_t *frame);
  31. }audiostream_vtbl_t;
  32. typedef struct audiostream_t audiostream_t;
  33. typedef struct audiocontext_t audiocontext_t;
  34. typedef struct audioengine_t audioengine_t;
  35. struct audiostream_t {
  36. audiostream_vtbl_t *vtbl;
  37. int direction;
  38. void *user_data;
  39. #ifdef _WIN32
  40. int(__stdcall* event_handler)(audiostream_t* stream, void* user_data, int evt, int param1, int param2);
  41. #else
  42. int(__attribute__((__stdcall))* event_handler)(audiostream_t* stream, void* user_data, int evt, int param1, int param2);
  43. #endif // _WIN32
  44. audiostream_t *upstream;
  45. audiostream_t *downstream;
  46. audioengine_t *engine;
  47. audiocontext_t *ctx;
  48. };
  49. void audiostream_init(audioengine_t *engine, audiostream_vtbl_t *vtbl, audiostream_t *stream);
  50. static void audiostream_set_upstream(audiostream_t *stream, audiostream_t *upstream){stream->upstream = upstream;}
  51. static audiostream_t* audiostream_get_upstream(audiostream_t *stream) {return stream->upstream;}
  52. static void audiostream_set_downstream(audiostream_t *stream, audiostream_t *downstream) { stream->downstream = downstream;}
  53. static audiostream_t* audiostream_get_downstream(audiostream_t *stream){return stream->downstream;}
  54. static audiocontext_t* audiostream_get_context(audiostream_t *stream){return stream->ctx;}
  55. static void audiostream_set_direction(audiostream_t *stream, int dir){stream->direction =dir;}
  56. static int audiostream_get_direction(audiostream_t *stream) {return stream->direction;}
  57. void audiostream_raise_event(audiostream_t *stream, int evt, int param1, int param2);
  58. // stream utility
  59. /** must be end with NULL */
  60. audiostream_t* audiostream_connect_pipeline(int direction, ...);
  61. void audiostream_disconnect_pipeline(audiostream_t *stream);
  62. #ifdef __cplusplus
  63. } // extern "C" {
  64. #endif
  65. #endif //__AUDIOSTREAM_H__