jack2 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.

149 lines
5.5KB

  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. #ifdef __cplusplus
  28. extern "C"
  29. {
  30. #endif
  31. #include <jack/jack.h>
  32. #include <jack/types.h>
  33. #include <jack/jslist.h>
  34. #include <jack/midiport.h>
  35. // The Packet Header.
  36. #define CELT_MODE 1000 // Magic bitdepth value that indicates CELT compression
  37. #define OPUS_MODE 999 // Magic bitdepth value that indicates OPUS compression
  38. #define MASTER_FREEWHEELS 0x80000000
  39. typedef struct _jacknet_packet_header jacknet_packet_header;
  40. struct _jacknet_packet_header {
  41. // General AutoConf Data
  42. jack_nframes_t capture_channels_audio;
  43. jack_nframes_t playback_channels_audio;
  44. jack_nframes_t capture_channels_midi;
  45. jack_nframes_t playback_channels_midi;
  46. jack_nframes_t period_size;
  47. jack_nframes_t sample_rate;
  48. // Transport Sync
  49. jack_nframes_t sync_state;
  50. jack_nframes_t transport_frame;
  51. jack_nframes_t transport_state;
  52. // Packet loss Detection, and latency reduction
  53. jack_nframes_t framecnt;
  54. jack_nframes_t latency;
  55. jack_nframes_t reply_port;
  56. jack_nframes_t mtu;
  57. jack_nframes_t fragment_nr;
  58. };
  59. typedef union _int_float int_float_t;
  60. union _int_float {
  61. uint32_t i;
  62. float f;
  63. };
  64. // fragment reorder cache.
  65. typedef struct _cache_packet cache_packet;
  66. struct _cache_packet {
  67. int valid;
  68. int num_fragments;
  69. int packet_size;
  70. int mtu;
  71. jack_time_t recv_timestamp;
  72. jack_nframes_t framecnt;
  73. char * fragment_array;
  74. char * packet_buf;
  75. };
  76. typedef struct _packet_cache packet_cache;
  77. struct _packet_cache {
  78. int size;
  79. cache_packet *packets;
  80. int mtu;
  81. struct sockaddr_in master_address;
  82. int master_address_valid;
  83. jack_nframes_t last_framecnt_retreived;
  84. int last_framecnt_retreived_valid;
  85. };
  86. // fragment cache function prototypes
  87. // XXX: Some of these are private.
  88. packet_cache *packet_cache_new(int num_packets, int pkt_size, int mtu);
  89. void packet_cache_free(packet_cache *pkt_cache);
  90. cache_packet *packet_cache_get_packet(packet_cache *pkt_cache, jack_nframes_t framecnt);
  91. cache_packet *packet_cache_get_oldest_packet(packet_cache *pkt_cache);
  92. cache_packet *packet_cache_get_free_packet(packet_cache *pkt_cache);
  93. void cache_packet_reset(cache_packet *pack);
  94. void cache_packet_set_framecnt(cache_packet *pack, jack_nframes_t framecnt);
  95. void cache_packet_add_fragment(cache_packet *pack, char *packet_buf, int rcv_len);
  96. int cache_packet_is_complete(cache_packet *pack);
  97. void packet_cache_drain_socket( packet_cache *pcache, int sockfd );
  98. void packet_cache_reset_master_address( packet_cache *pcache );
  99. float packet_cache_get_fill( packet_cache *pcache, jack_nframes_t expected_framecnt );
  100. int packet_cache_retreive_packet_pointer( packet_cache *pcache, jack_nframes_t framecnt, char **packet_buf, int pkt_size, jack_time_t *timestamp );
  101. int packet_cache_release_packet( packet_cache *pcache, jack_nframes_t framecnt );
  102. int packet_cache_get_next_available_framecnt( packet_cache *pcache, jack_nframes_t expected_framecnt, jack_nframes_t *framecnt );
  103. int packet_cache_get_highest_available_framecnt( packet_cache *pcache, jack_nframes_t *framecnt );
  104. int packet_cache_find_latency( packet_cache *pcache, jack_nframes_t expected_framecnt, jack_nframes_t *framecnt );
  105. // Function Prototypes
  106. int netjack_poll_deadline (int sockfd, jack_time_t deadline);
  107. void netjack_sendto(int sockfd, char *packet_buf, int pkt_size, int flags, struct sockaddr *addr, int addr_size, int mtu);
  108. int get_sample_size(int bitdepth);
  109. void packet_header_hton(jacknet_packet_header *pkthdr);
  110. void packet_header_ntoh(jacknet_packet_header *pkthdr);
  111. 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, int dont_htonl_floats );
  112. 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, int dont_htonl_floats );
  113. // XXX: This is sort of deprecated:
  114. // This one waits forever. an is not using ppoll
  115. int netjack_poll(int sockfd, int timeout);
  116. void decode_midi_buffer (uint32_t *buffer_uint32, unsigned int buffer_size_uint32, jack_default_audio_sample_t* buf);
  117. void encode_midi_buffer (uint32_t *buffer_uint32, unsigned int buffer_size_uint32, jack_default_audio_sample_t* buf);
  118. #ifdef __cplusplus
  119. }
  120. #endif
  121. #endif