jack1 codebase
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

122 lines
3.6KB

  1. /*
  2. * NetJack - Packet Handling functions
  3. *
  4. * used by the driver and the jacknet_client
  5. *
  6. * Copyright (C) 2006 Torben Hohn <torbenh@gmx.de>
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation; either version 2 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, write to the Free Software
  20. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  21. *
  22. * $Id: net_driver.c,v 1.16 2006/03/20 19:41:37 torbenh Exp $
  23. *
  24. */
  25. #ifndef __JACK_NET_PACKET_H__
  26. #define __JACK_NET_PACKET_H__
  27. #include <jack/jack.h>
  28. #include <jack/types.h>
  29. #include <jack/engine.h>
  30. #include <netinet/in.h>
  31. // The Packet Header.
  32. typedef struct _jacknet_packet_header jacknet_packet_header;
  33. struct _jacknet_packet_header
  34. {
  35. // General AutoConf Data
  36. jack_nframes_t channels;
  37. jack_nframes_t period_size;
  38. jack_nframes_t sample_rate;
  39. // Transport Sync
  40. jack_nframes_t sync_state;
  41. jack_nframes_t transport_frame;
  42. jack_nframes_t transport_state;
  43. // Packet loss Detection, and latency reduction
  44. jack_nframes_t framecnt;
  45. jack_nframes_t latency;
  46. jack_nframes_t reply_port;
  47. jack_nframes_t mtu;
  48. jack_nframes_t fragment_nr;
  49. };
  50. typedef union _int_float int_float_t;
  51. union _int_float
  52. {
  53. uint32_t i;
  54. float f;
  55. };
  56. // fragment reorder cache.
  57. typedef struct _cache_packet cache_packet;
  58. struct _cache_packet
  59. {
  60. int valid;
  61. int num_fragments;
  62. int packet_size;
  63. int mtu;
  64. jack_nframes_t framecnt;
  65. char * fragment_array;
  66. char * packet_buf;
  67. };
  68. typedef struct _packet_cache packet_cache;
  69. struct _packet_cache
  70. {
  71. int size;
  72. cache_packet *packets;
  73. };
  74. extern packet_cache *global_packcache;
  75. // fragment cache function prototypes
  76. packet_cache *packet_cache_new(int num_packets, int pkt_size, int mtu);
  77. void packet_cache_free(packet_cache *pkt_cache);
  78. cache_packet *packet_cache_get_packet(packet_cache *pkt_cache, jack_nframes_t framecnt);
  79. cache_packet *packet_cache_get_oldest_packet(packet_cache *pkt_cache);
  80. cache_packet *packet_cache_get_free_packet(packet_cache *pkt_cache);
  81. void cache_packet_reset(cache_packet *pack);
  82. void cache_packet_set_framecnt(cache_packet *pack, jack_nframes_t framecnt);
  83. void cache_packet_add_fragment(cache_packet *pack, char *packet_buf, int rcv_len);
  84. int cache_packet_is_complete(cache_packet *pack);
  85. // Function Prototypes
  86. void netjack_sendto(int sockfd, char *packet_buf, int pkt_size, int flags, struct sockaddr *addr, int addr_size, int mtu);
  87. int netjack_recvfrom(int sockfd, char *packet_buf, int pkt_size, int flags, struct sockaddr *addr, socklen_t *addr_size, int mtu);
  88. int netjack_recv(int sockfd, char *packet_buf, int pkt_size, int flags, int mtu);
  89. int get_sample_size(int bitdepth);
  90. void packet_header_hton(jacknet_packet_header *pkthdr);
  91. void packet_header_ntoh(jacknet_packet_header *pkthdr);
  92. void render_payload_to_jack_ports(int bitdepth, void *packet_payload, jack_nframes_t net_period_down, JSList *capture_ports, JSList *capture_srcs, jack_nframes_t nframes);
  93. void render_jack_ports_to_payload(int bitdepth, JSList *playback_ports, JSList *playback_srcs, jack_nframes_t nframes, void *packet_payload, jack_nframes_t net_period_up);
  94. #endif