summaryrefslogtreecommitdiff
path: root/toxav/codec.h
diff options
context:
space:
mode:
Diffstat (limited to 'toxav/codec.h')
-rw-r--r--toxav/codec.h81
1 files changed, 15 insertions, 66 deletions
diff --git a/toxav/codec.h b/toxav/codec.h
index 526a80d5..b13203f1 100644
--- a/toxav/codec.h
+++ b/toxav/codec.h
@@ -42,32 +42,7 @@
42 42
43#define PAIR(TYPE1__, TYPE2__) struct { TYPE1__ first; TYPE2__ second; } 43#define PAIR(TYPE1__, TYPE2__) struct { TYPE1__ first; TYPE2__ second; }
44 44
45typedef void (*CSAudioCallback) (void *agent, int32_t call_idx, const int16_t *PCM, uint16_t size, void *data); 45typedef struct CSession_s {
46typedef void (*CSVideoCallback) (void *agent, int32_t call_idx, const vpx_image_t *img, void *data);
47
48/**
49 * Codec capabilities
50 */
51typedef enum {
52 cs_AudioEncoding = 1 << 0,
53 cs_AudioDecoding = 1 << 1,
54 cs_VideoEncoding = 1 << 2,
55 cs_VideoDecoding = 1 << 3
56} CSCapabilities;
57
58/**
59 * Codec errors.
60 */
61typedef enum {
62 cs_ErrorSettingVideoResolution = -30,
63 cs_ErrorSettingVideoBitrate = -31,
64 cs_ErrorSplittingVideoPayload = -32,
65} CSError;
66
67/**
68 * Codec session - controling codec
69 */
70typedef struct CSSession_s {
71 46
72 /* VIDEO 47 /* VIDEO
73 * 48 *
@@ -76,12 +51,10 @@ typedef struct CSSession_s {
76 51
77 /* video encoding */ 52 /* video encoding */
78 vpx_codec_ctx_t v_encoder[1]; 53 vpx_codec_ctx_t v_encoder[1];
79 bool v_encoding;
80 uint32_t frame_counter; 54 uint32_t frame_counter;
81 55
82 /* video decoding */ 56 /* video decoding */
83 vpx_codec_ctx_t v_decoder[1]; 57 vpx_codec_ctx_t v_decoder[1];
84 bool v_decoding;
85 void *vbuf_raw; /* Un-decoded data */ 58 void *vbuf_raw; /* Un-decoded data */
86 59
87 /* Data handling */ 60 /* Data handling */
@@ -107,10 +80,13 @@ typedef struct CSSession_s {
107 80
108 /* audio encoding */ 81 /* audio encoding */
109 OpusEncoder *audio_encoder; 82 OpusEncoder *audio_encoder;
83 int32_t last_encoding_sampling_rate;
84 int32_t last_encoding_channel_count;
85 int32_t last_encoding_bitrate;
110 86
111 /* audio decoding */ 87 /* audio decoding */
112 OpusDecoder *audio_decoder; 88 OpusDecoder *audio_decoder;
113 int32_t last_packet_channels; 89 int32_t last_packet_channel_count;
114 int32_t last_packet_sampling_rate; 90 int32_t last_packet_sampling_rate;
115 int32_t last_packet_frame_duration; 91 int32_t last_packet_frame_duration;
116 struct JitterBuffer_s *j_buf; 92 struct JitterBuffer_s *j_buf;
@@ -120,55 +96,28 @@ typedef struct CSSession_s {
120 * 96 *
121 * 97 *
122 */ 98 */
123 void *agent; /* Pointer to ToxAV TODO make this pointer to ToxAV*/ 99 ToxAV *av;
124 int32_t friend_id; 100 int32_t friend_id;
125 101
126 PAIR(toxav_receive_audio_frame_cb *, void *) acb; /* Audio frame receive callback */ 102 PAIR(toxav_receive_audio_frame_cb *, void *) acb; /* Audio frame receive callback */
127 PAIR(toxav_receive_video_frame_cb *, void *) vcb; /* Video frame receive callback */ 103 PAIR(toxav_receive_video_frame_cb *, void *) vcb; /* Video frame receive callback */
128 104
129 pthread_mutex_t queue_mutex[1]; 105 pthread_mutex_t queue_mutex[1];
130} CSSession; 106} CSession;
131 107
132 108
133/** 109void cs_do(CSession *cs);
134 * Generic
135 */
136void cs_do(CSSession *cs);
137
138/* Make sure to be called BEFORE corresponding rtp_new */ 110/* Make sure to be called BEFORE corresponding rtp_new */
139CSSession *cs_new(uint32_t peer_mvfpsz); 111CSession *cs_new(uint32_t peer_mvfpsz);
140/* Make sure to be called AFTER corresponding rtp_kill */ 112/* Make sure to be called AFTER corresponding rtp_kill */
141void cs_kill(CSSession *cs); 113void cs_kill(CSession *cs);
142
143
144/**
145 * VIDEO HANDLING
146 */
147void cs_init_video_splitter_cycle(CSSession *cs);
148int cs_update_video_splitter_cycle(CSSession* cs, const uint8_t* payload, uint16_t length);
149const uint8_t *cs_iterate_split_video_frame(CSSession *cs, uint16_t *size);
150
151int cs_set_sending_video_resolution(CSSession *cs, uint16_t width, uint16_t height);
152int cs_set_sending_video_bitrate(CSSession *cs, uint32_t bitrate);
153
154int cs_enable_video_sending(CSSession* cs, uint32_t bitrate);
155int cs_enable_video_receiving(CSSession* cs);
156
157void cs_disable_video_sending(CSSession* cs);
158void cs_disable_video_receiving(CSSession* cs);
159
160/**
161 * AUDIO HANDLING
162 */
163int cs_set_sending_audio_bitrate(CSSession* cs, int32_t rate);
164
165int cs_enable_audio_sending(CSSession* cs, uint32_t bitrate);
166int cs_enable_audio_receiving(CSSession* cs);
167
168void cs_disable_audio_sending(CSSession* cs);
169void cs_disable_audio_receiving(CSSession* cs);
170 114
115void cs_init_video_splitter_cycle(CSession *cs);
116int cs_update_video_splitter_cycle(CSession* cs, const uint8_t* payload, uint16_t length);
117const uint8_t *cs_iterate_split_video_frame(CSession *cs, uint16_t *size);
171 118
119int cs_reconfigure_video_encoder(CSession* cs, int32_t bitrate, uint16_t width, uint16_t height);
120int cs_reconfigure_audio_encoder(CSession* cs, int32_t bitrate, int32_t sampling_rate, uint8_t channels);
172 121
173 122
174/* Internal. Called from rtp_handle_message */ 123/* Internal. Called from rtp_handle_message */