diff options
-rw-r--r-- | toxav/codec.c | 45 | ||||
-rw-r--r-- | toxav/codec.h | 5 | ||||
-rw-r--r-- | toxav/rtp.c | 26 | ||||
-rw-r--r-- | toxav/toxav.c | 8 |
4 files changed, 54 insertions, 30 deletions
diff --git a/toxav/codec.c b/toxav/codec.c index 4abb7f8c..fbf78d69 100644 --- a/toxav/codec.c +++ b/toxav/codec.c | |||
@@ -210,6 +210,44 @@ int init_audio_decoder(CodecState *cs, uint32_t audio_channels) | |||
210 | return 0; | 210 | return 0; |
211 | } | 211 | } |
212 | 212 | ||
213 | int reconfigure_video_encoder_resolution(CodecState *cs, uint16_t width, uint16_t height) | ||
214 | { | ||
215 | vpx_codec_enc_cfg_t cfg = *cs->v_encoder.config.enc; | ||
216 | |||
217 | if (cfg.g_w == width && cfg.g_h == height) | ||
218 | return 0; | ||
219 | |||
220 | LOGGER_DEBUG("New video resolution: %u %u", width, height); | ||
221 | cfg.g_w = width; | ||
222 | cfg.g_h = height; | ||
223 | int rc = vpx_codec_enc_config_set(&cs->v_encoder, &cfg); | ||
224 | |||
225 | if ( rc != VPX_CODEC_OK) { | ||
226 | LOGGER_ERROR("Failed to set encoder control setting: %s", vpx_codec_err_to_string(rc)); | ||
227 | return -1; | ||
228 | } | ||
229 | |||
230 | return 0; | ||
231 | } | ||
232 | |||
233 | int reconfigure_video_encoder_bitrate(CodecState *cs, uint32_t video_bitrate) | ||
234 | { | ||
235 | vpx_codec_enc_cfg_t cfg = *cs->v_encoder.config.enc; | ||
236 | |||
237 | if (cfg.rc_target_bitrate == video_bitrate) | ||
238 | return 0; | ||
239 | |||
240 | LOGGER_DEBUG("New video bitrate: %u", video_bitrate); | ||
241 | cfg.rc_target_bitrate = video_bitrate; | ||
242 | int rc = vpx_codec_enc_config_set(&cs->v_encoder, &cfg); | ||
243 | |||
244 | if ( rc != VPX_CODEC_OK) { | ||
245 | LOGGER_ERROR("Failed to set encoder control setting: %s", vpx_codec_err_to_string(rc)); | ||
246 | return -1; | ||
247 | } | ||
248 | |||
249 | return 0; | ||
250 | } | ||
213 | 251 | ||
214 | int init_video_encoder(CodecState *cs, uint16_t width, uint16_t height, uint32_t video_bitrate) | 252 | int init_video_encoder(CodecState *cs, uint16_t width, uint16_t height, uint32_t video_bitrate) |
215 | { | 253 | { |
@@ -222,8 +260,8 @@ int init_video_encoder(CodecState *cs, uint16_t width, uint16_t height, uint32_t | |||
222 | } | 260 | } |
223 | 261 | ||
224 | cfg.rc_target_bitrate = video_bitrate; | 262 | cfg.rc_target_bitrate = video_bitrate; |
225 | cfg.g_w = width; | 263 | cfg.g_w = 8192; |
226 | cfg.g_h = height; | 264 | cfg.g_h = 8192; |
227 | cfg.g_pass = VPX_RC_ONE_PASS; | 265 | cfg.g_pass = VPX_RC_ONE_PASS; |
228 | cfg.g_error_resilient = VPX_ERROR_RESILIENT_DEFAULT | VPX_ERROR_RESILIENT_PARTITIONS; | 266 | cfg.g_error_resilient = VPX_ERROR_RESILIENT_DEFAULT | VPX_ERROR_RESILIENT_PARTITIONS; |
229 | cfg.g_lag_in_frames = 0; | 267 | cfg.g_lag_in_frames = 0; |
@@ -244,6 +282,9 @@ int init_video_encoder(CodecState *cs, uint16_t width, uint16_t height, uint32_t | |||
244 | return -1; | 282 | return -1; |
245 | } | 283 | } |
246 | 284 | ||
285 | if (reconfigure_video_encoder_resolution(cs, width, height) != 0) | ||
286 | return -1; | ||
287 | |||
247 | return 0; | 288 | return 0; |
248 | } | 289 | } |
249 | 290 | ||
diff --git a/toxav/codec.h b/toxav/codec.h index 7ddf2943..d8e9f1a7 100644 --- a/toxav/codec.h +++ b/toxav/codec.h | |||
@@ -102,6 +102,11 @@ CodecState *codec_init_session ( uint32_t audio_bitrate, | |||
102 | 102 | ||
103 | void codec_terminate_session(CodecState *cs); | 103 | void codec_terminate_session(CodecState *cs); |
104 | 104 | ||
105 | /* Reconfigure video encoder | ||
106 | return 0 on success. | ||
107 | return -1 on failure. */ | ||
108 | int reconfigure_video_encoder_resolution(CodecState *cs, uint16_t width, uint16_t height); | ||
109 | int reconfigure_video_encoder_bitrate(CodecState *cs, uint32_t video_bitrate); | ||
105 | 110 | ||
106 | /* Calculate energy and return 1 if has voice, 0 if not */ | 111 | /* Calculate energy and return 1 if has voice, 0 if not */ |
107 | int energy_VAD(CodecState *cs, int16_t *PCM, uint16_t frame_size, float energy); | 112 | int energy_VAD(CodecState *cs, int16_t *PCM, uint16_t frame_size, float energy); |
diff --git a/toxav/rtp.c b/toxav/rtp.c index 39e622bf..521e4b22 100644 --- a/toxav/rtp.c +++ b/toxav/rtp.c | |||
@@ -29,10 +29,6 @@ | |||
29 | #include "rtp.h" | 29 | #include "rtp.h" |
30 | #include <stdlib.h> | 30 | #include <stdlib.h> |
31 | 31 | ||
32 | |||
33 | #define PAYLOAD_ID_VALUE_OPUS 1 | ||
34 | #define PAYLOAD_ID_VALUE_VP8 2 | ||
35 | |||
36 | #define size_32 4 | 32 | #define size_32 4 |
37 | 33 | ||
38 | #define ADD_FLAG_VERSION(_h, _v) do { ( _h->flags ) &= 0x3F; ( _h->flags ) |= ( ( ( _v ) << 6 ) & 0xC0 ); } while(0) | 34 | #define ADD_FLAG_VERSION(_h, _v) do { ( _h->flags ) &= 0x3F; ( _h->flags ) |= ( ( ( _v ) << 6 ) & 0xC0 ); } while(0) |
@@ -68,26 +64,6 @@ inline__ int check_late_message (RTPSession *session, RTPMessage *msg) | |||
68 | return ( msg->header->sequnum < session->rsequnum && msg->header->timestamp < session->timestamp ) ? 0 : -1; | 64 | return ( msg->header->sequnum < session->rsequnum && msg->header->timestamp < session->timestamp ) ? 0 : -1; |
69 | } | 65 | } |
70 | 66 | ||
71 | /** | ||
72 | * @brief Speaks for it self. | ||
73 | * | ||
74 | */ | ||
75 | static const uint32_t payload_table[] = { | ||
76 | 8000, 8000, 8000, 8000, 8000, 8000, 16000, 8000, 8000, 8000, /* 0-9 */ | ||
77 | 44100, 44100, 0, 0, 90000, 8000, 11025, 22050, 0, 0, /* 10-19 */ | ||
78 | 0, 0, 0, 0, 0, 90000, 90000, 0, 90000, 0, /* 20-29 */ | ||
79 | 0, 90000, 90000, 90000, 90000, 0, 0, 0, 0, 0, /* 30-39 */ | ||
80 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 40-49 */ | ||
81 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 50-59 */ | ||
82 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 60-69 */ | ||
83 | PAYLOAD_ID_VALUE_OPUS, PAYLOAD_ID_VALUE_VP8, 0, 0, 0, 0, 0, 0, 0, 0,/* 70-79 */ | ||
84 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 80-89 */ | ||
85 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 90-99 */ | ||
86 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 100-109 */ | ||
87 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 110-119 */ | ||
88 | 0, 0, 0, 0, 0, 0, 0, 0 /* 120-127 */ | ||
89 | }; | ||
90 | |||
91 | 67 | ||
92 | /** | 68 | /** |
93 | * @brief Extracts header from payload. | 69 | * @brief Extracts header from payload. |
@@ -686,7 +662,7 @@ RTPSession *rtp_init_session ( int payload_type, Messenger *messenger, int frien | |||
686 | _retu->csrc = NULL; /* Container */ | 662 | _retu->csrc = NULL; /* Container */ |
687 | _retu->ssrc = random_int(); | 663 | _retu->ssrc = random_int(); |
688 | _retu->marker = 0; | 664 | _retu->marker = 0; |
689 | _retu->payload_type = payload_table[payload_type]; | 665 | _retu->payload_type = payload_type % 128; |
690 | 666 | ||
691 | _retu->dest = friend_num; | 667 | _retu->dest = friend_num; |
692 | 668 | ||
diff --git a/toxav/toxav.c b/toxav/toxav.c index 894c12e4..6ffef077 100644 --- a/toxav/toxav.c +++ b/toxav/toxav.c | |||
@@ -636,6 +636,8 @@ inline__ int toxav_prepare_video_frame(ToxAv *av, int32_t call_index, uint8_t *d | |||
636 | 636 | ||
637 | CallSpecific *call = &av->calls[call_index]; | 637 | CallSpecific *call = &av->calls[call_index]; |
638 | pthread_mutex_lock(call->mutex); | 638 | pthread_mutex_lock(call->mutex); |
639 | |||
640 | reconfigure_video_encoder_resolution(call->cs, input->d_w, input->d_h); | ||
639 | 641 | ||
640 | int rc = vpx_codec_encode(&call->cs->v_encoder, input, call->cs->frame_counter, 1, 0, MAX_ENCODE_TIME_US); | 642 | int rc = vpx_codec_encode(&call->cs->v_encoder, input, call->cs->frame_counter, 1, 0, MAX_ENCODE_TIME_US); |
641 | 643 | ||
@@ -825,11 +827,11 @@ int toxav_get_peer_id ( ToxAv *av, int32_t call_index, int peer ) | |||
825 | * @return int | 827 | * @return int |
826 | * @retval ToxAvError No peer id | 828 | * @retval ToxAvError No peer id |
827 | */ | 829 | */ |
828 | ToxAvCallState toxav_get_call_state(ToxAv* av, int32_t call_index) | 830 | ToxAvCallState toxav_get_call_state(ToxAv *av, int32_t call_index) |
829 | { | 831 | { |
830 | if ( cii(call_index, av->msi_session) || !av->msi_session->calls[call_index] ) | 832 | if ( cii(call_index, av->msi_session) || !av->msi_session->calls[call_index] ) |
831 | return av_CallNonExistant; | 833 | return av_CallNonExistant; |
832 | 834 | ||
833 | return av->msi_session->calls[call_index]->state; | 835 | return av->msi_session->calls[call_index]->state; |
834 | 836 | ||
835 | } | 837 | } |