summaryrefslogtreecommitdiff
path: root/toxav/codec.h
diff options
context:
space:
mode:
authorirungentoo <irungentoo@gmail.com>2014-11-24 20:24:59 -0500
committerirungentoo <irungentoo@gmail.com>2014-11-24 20:24:59 -0500
commit279c33c01a9ca721b986aabf72fa982936b20c9e (patch)
tree4c0d289c6d74788989024485d44a4f5c7fec6efc /toxav/codec.h
parentc67bc3399faae541d64309412326ae92262b1282 (diff)
parent386c9748d48d3bb4513e8e5c32e2b30a4d6a00d4 (diff)
Merge branch 'master' of https://github.com/mannol/toxcore
Diffstat (limited to 'toxav/codec.h')
-rw-r--r--toxav/codec.h118
1 files changed, 81 insertions, 37 deletions
diff --git a/toxav/codec.h b/toxav/codec.h
index db4fbea0..dd054338 100644
--- a/toxav/codec.h
+++ b/toxav/codec.h
@@ -24,6 +24,9 @@
24#ifndef _CODEC_H_ 24#ifndef _CODEC_H_
25#define _CODEC_H_ 25#define _CODEC_H_
26 26
27#include "toxav.h"
28#include "rtp.h"
29
27#include <stdio.h> 30#include <stdio.h>
28#include <math.h> 31#include <math.h>
29#include <pthread.h> 32#include <pthread.h>
@@ -32,23 +35,30 @@
32#include <vpx/vpx_encoder.h> 35#include <vpx/vpx_encoder.h>
33#include <vpx/vp8dx.h> 36#include <vpx/vp8dx.h>
34#include <vpx/vp8cx.h> 37#include <vpx/vp8cx.h>
38#include <vpx/vpx_image.h>
35#define VIDEO_CODEC_DECODER_INTERFACE (vpx_codec_vp8_dx()) 39#define VIDEO_CODEC_DECODER_INTERFACE (vpx_codec_vp8_dx())
36#define VIDEO_CODEC_ENCODER_INTERFACE (vpx_codec_vp8_cx()) 40#define VIDEO_CODEC_ENCODER_INTERFACE (vpx_codec_vp8_cx())
37 41
38/* Audio encoding/decoding */ 42/* Audio encoding/decoding */
39#include <opus.h> 43#include <opus.h>
40 44
41typedef enum _Capabilities { 45typedef void (*CSAudioCallback) (void *agent, int32_t call_idx, const int16_t *PCM, uint16_t size, void *data);
42 none, 46typedef void (*CSVideoCallback) (void *agent, int32_t call_idx, const vpx_image_t *img, void *data);
47
48typedef enum _CsCapabilities {
43 a_encoding = 1 << 0, 49 a_encoding = 1 << 0,
44 a_decoding = 1 << 1, 50 a_decoding = 1 << 1,
45 v_encoding = 1 << 2, 51 v_encoding = 1 << 2,
46 v_decoding = 1 << 3 52 v_decoding = 1 << 3
47} Capabilities; 53} CsCapabilities;
48 54
49extern const uint16_t min_jbuf_size; 55typedef struct _CSSession {
50 56
51typedef struct _CodecState { 57 /* VIDEO
58 *
59 *
60 */
61 int support_video;
52 62
53 /* video encoding */ 63 /* video encoding */
54 vpx_codec_ctx_t v_encoder; 64 vpx_codec_ctx_t v_encoder;
@@ -56,61 +66,95 @@ typedef struct _CodecState {
56 66
57 /* video decoding */ 67 /* video decoding */
58 vpx_codec_ctx_t v_decoder; 68 vpx_codec_ctx_t v_decoder;
59 int bitrate;
60 int max_width; 69 int max_width;
61 int max_height; 70 int max_height;
62 71
72
73 /* Data handling */
74 uint8_t *frame_buf; /* buffer for split video payloads */
75 uint32_t frame_size; /* largest address written to in frame_buf for current input frame*/
76 uint8_t frameid_in, frameid_out; /* id of input and output video frame */
77 uint32_t last_timestamp; /* calculating cycles */
78
79 /* Limits */
80 uint32_t video_frame_piece_size;
81 uint32_t max_video_frame_size;
82
83 /* Reassembling */
84 uint8_t *split_video_frame;
85 const uint8_t *processing_video_frame;
86 uint16_t processing_video_frame_size;
87
88
89
90 /* AUDIO
91 *
92 *
93 */
94
63 /* audio encoding */ 95 /* audio encoding */
64 OpusEncoder *audio_encoder; 96 OpusEncoder *audio_encoder;
65 int audio_bitrate; 97 int audio_encoder_bitrate;
66 int audio_sample_rate; 98 int audio_encoder_sample_rate;
99 int audio_encoder_frame_duration;
67 int audio_encoder_channels; 100 int audio_encoder_channels;
68 101
69 /* audio decoding */ 102 /* audio decoding */
70 OpusDecoder *audio_decoder; 103 OpusDecoder *audio_decoder;
104 int audio_decoder_bitrate;
105 int audio_decoder_sample_rate;
106 int audio_decoder_frame_duration;
71 int audio_decoder_channels; 107 int audio_decoder_channels;
72 108
73 uint64_t capabilities; /* supports*/ 109 struct _JitterBuffer *j_buf;
110
74 111
75 /* Voice activity detection */ 112 /* Voice activity detection */
76 uint32_t EVAD_tolerance; /* In frames */ 113 uint32_t EVAD_tolerance; /* In frames */
77 uint32_t EVAD_tolerance_cr; 114 uint32_t EVAD_tolerance_cr;
78} CodecState;
79 115
80 116
81typedef struct _JitterBuffer {
82 RTPMessage **queue;
83 uint32_t size;
84 uint32_t capacity;
85 uint16_t bottom;
86 uint16_t top;
87} JitterBuffer;
88 117
89JitterBuffer *create_queue(unsigned int capacity); 118 /* OTHER
90void terminate_queue(JitterBuffer *q); 119 *
91void queue(JitterBuffer *q, RTPMessage *pk); 120 *
92RTPMessage *dequeue(JitterBuffer *q, int *success); 121 */
122
123 uint64_t capabilities; /* supports*/
93 124
125 /* Buffering */
126 void *abuf_raw, *vbuf_raw; /* Un-decoded data */
127 _Bool active;
128 pthread_mutex_t queue_mutex[1];
94 129
95CodecState *codec_init_session ( uint32_t audio_bitrate, 130 void *agent; /* Pointer to ToxAv */
96 uint16_t audio_frame_duration, 131 int32_t call_idx;
97 uint32_t audio_sample_rate, 132} CSSession;
98 uint32_t encoder_audio_channels,
99 uint32_t decoder_audio_channels,
100 uint32_t audio_VAD_tolerance_ms,
101 uint16_t max_video_width,
102 uint16_t max_video_height,
103 uint32_t video_bitrate );
104 133
105void codec_terminate_session(CodecState *cs); 134CSSession *cs_new(const ToxAvCSettings *cs_self, const ToxAvCSettings *cs_peer, uint32_t jbuf_size, int has_video);
135void cs_kill(CSSession *cs);
136
137int cs_split_video_payload(CSSession *cs, const uint8_t *payload, uint16_t length);
138const uint8_t *cs_get_split_video_frame(CSSession *cs, uint16_t *size);
139
140/**
141 * Call playback callbacks
142 */
143void cs_do(CSSession *cs);
144
145void cs_register_audio_callback(CSAudioCallback cb, void *data);
146void cs_register_video_callback(CSVideoCallback cb, void *data);
147
148/* Reconfigure video encoder; return 0 on success or -1 on failure. */
149int cs_set_video_encoder_resolution(CSSession *cs, uint16_t width, uint16_t height);
150int cs_set_video_encoder_bitrate(CSSession *cs, uint32_t video_bitrate);
106 151
107/* Reconfigure video encoder
108 return 0 on success.
109 return -1 on failure. */
110int reconfigure_video_encoder_resolution(CodecState *cs, uint16_t width, uint16_t height);
111int reconfigure_video_encoder_bitrate(CodecState *cs, uint32_t video_bitrate);
112 152
113/* Calculate energy and return 1 if has voice, 0 if not */ 153/* Calculate energy and return 1 if has voice, 0 if not */
114int energy_VAD(CodecState *cs, int16_t *PCM, uint16_t frame_size, float energy); 154int cs_calculate_vad(CSSession *cs, int16_t *PCM, uint16_t frame_size, float energy);
155void cs_set_vad_treshold(CSSession *cs, uint32_t treshold, uint16_t frame_duration);
156
115 157
158/* Internal. Called from rtp_handle_message */
159void queue_message(RTPSession *session, RTPMessage *msg);
116#endif /* _CODEC_H_ */ 160#endif /* _CODEC_H_ */