diff options
author | mannol <eniz_vukovic@hotmail.com> | 2015-04-22 02:09:37 +0200 |
---|---|---|
committer | mannol <eniz_vukovic@hotmail.com> | 2015-04-22 02:09:37 +0200 |
commit | 1bfd93e64a2a6d3bf9c90a9aa89abd29f3d826a7 (patch) | |
tree | 094af1cad749bef83678071476075160d956bfeb /toxav/video.c | |
parent | 3fd0ee5f0873924b4881b0e33eb1c17ea877ab4a (diff) |
Finished refactoring
Diffstat (limited to 'toxav/video.c')
-rw-r--r-- | toxav/video.c | 70 |
1 files changed, 43 insertions, 27 deletions
diff --git a/toxav/video.c b/toxav/video.c index d51cfd4a..039fc2a0 100644 --- a/toxav/video.c +++ b/toxav/video.c | |||
@@ -24,6 +24,7 @@ | |||
24 | 24 | ||
25 | #include "video.h" | 25 | #include "video.h" |
26 | #include "msi.h" | 26 | #include "msi.h" |
27 | #include "rtp.h" | ||
27 | 28 | ||
28 | #include "../toxcore/logger.h" | 29 | #include "../toxcore/logger.h" |
29 | #include "../toxcore/network.h" | 30 | #include "../toxcore/network.h" |
@@ -78,7 +79,9 @@ VCSession* vc_new(ToxAV* av, uint32_t friend_id, toxav_receive_video_frame_cb* c | |||
78 | 79 | ||
79 | vc->linfts = current_time_monotonic(); | 80 | vc->linfts = current_time_monotonic(); |
80 | vc->lcfd = 60; | 81 | vc->lcfd = 60; |
81 | 82 | vc->vcb.first = cb; | |
83 | vc->vcb.second = cb_data; | ||
84 | vc->friend_id = friend_id; | ||
82 | vc->peer_video_frame_piece_size = mvfpsz; | 85 | vc->peer_video_frame_piece_size = mvfpsz; |
83 | 86 | ||
84 | return vc; | 87 | return vc; |
@@ -187,35 +190,25 @@ const uint8_t* vc_iterate_split_video_frame(VCSession* vc, uint16_t* size) | |||
187 | 190 | ||
188 | return vc->split_video_frame; | 191 | return vc->split_video_frame; |
189 | } | 192 | } |
190 | int vc_reconfigure_encoder(VCSession* vc, int32_t bitrate, uint16_t width, uint16_t height) | 193 | int vc_queue_message(void* vcp, struct RTPMessage_s *msg) |
191 | { | ||
192 | if (!vc) | ||
193 | return; | ||
194 | |||
195 | vpx_codec_enc_cfg_t cfg = *vc->v_encoder[0].config.enc; | ||
196 | if (cfg.rc_target_bitrate == bitrate && cfg.g_w == width && cfg.g_h == height) | ||
197 | return 0; /* Nothing changed */ | ||
198 | |||
199 | cfg.rc_target_bitrate = bitrate; | ||
200 | cfg.g_w = width; | ||
201 | cfg.g_h = height; | ||
202 | |||
203 | int rc = vpx_codec_enc_config_set(vc->v_encoder, &cfg); | ||
204 | if ( rc != VPX_CODEC_OK) { | ||
205 | LOGGER_ERROR("Failed to set encoder control setting: %s", vpx_codec_err_to_string(rc)); | ||
206 | return -1; | ||
207 | } | ||
208 | |||
209 | return 0; | ||
210 | } | ||
211 | /* Called from RTP */ | ||
212 | void vc_queue_message(void* vcp, RTPMessage *msg) | ||
213 | { | 194 | { |
214 | /* This function does the reconstruction of video packets. | 195 | /* This function does the reconstruction of video packets. |
215 | * See more info about video splitting in docs | 196 | * See more info about video splitting in docs |
216 | */ | 197 | */ |
217 | if (!vcp || !msg) | 198 | if (!vcp || !msg) |
218 | return; | 199 | return -1; |
200 | |||
201 | if ((msg->header->marker_payloadt & 0x7f) == rtp_TypeDummyVideo % 128) { | ||
202 | LOGGER_WARNING("Got dummy!"); | ||
203 | rtp_free_msg(NULL, msg); | ||
204 | return 0; | ||
205 | } | ||
206 | |||
207 | if ((msg->header->marker_payloadt & 0x7f) != rtp_TypeVideo % 128) { | ||
208 | LOGGER_WARNING("Invalid payload type!"); | ||
209 | rtp_free_msg(NULL, msg); | ||
210 | return -1; | ||
211 | } | ||
219 | 212 | ||
220 | VCSession* vc = vcp; | 213 | VCSession* vc = vcp; |
221 | 214 | ||
@@ -233,7 +226,7 @@ void vc_queue_message(void* vcp, RTPMessage *msg) | |||
233 | Payload *p = malloc(sizeof(Payload) + vc->frame_size); | 226 | Payload *p = malloc(sizeof(Payload) + vc->frame_size); |
234 | 227 | ||
235 | if (p) { | 228 | if (p) { |
236 | LOGGED_LOCK(vc->queue_mutex); | 229 | pthread_mutex_lock(vc->queue_mutex); |
237 | 230 | ||
238 | if (rb_full(vc->vbuf_raw)) { | 231 | if (rb_full(vc->vbuf_raw)) { |
239 | LOGGER_DEBUG("Dropped video frame"); | 232 | LOGGER_DEBUG("Dropped video frame"); |
@@ -251,7 +244,7 @@ void vc_queue_message(void* vcp, RTPMessage *msg) | |||
251 | vc->linfts = current_time_monotonic(); | 244 | vc->linfts = current_time_monotonic(); |
252 | 245 | ||
253 | rb_write(vc->vbuf_raw, p); | 246 | rb_write(vc->vbuf_raw, p); |
254 | LOGGED_UNLOCK(vc->queue_mutex); | 247 | pthread_mutex_unlock(vc->queue_mutex); |
255 | } else { | 248 | } else { |
256 | LOGGER_WARNING("Allocation failed! Program might misbehave!"); | 249 | LOGGER_WARNING("Allocation failed! Program might misbehave!"); |
257 | goto end; | 250 | goto end; |
@@ -288,9 +281,32 @@ void vc_queue_message(void* vcp, RTPMessage *msg) | |||
288 | 281 | ||
289 | end: | 282 | end: |
290 | rtp_free_msg(NULL, msg); | 283 | rtp_free_msg(NULL, msg); |
284 | return 0; | ||
285 | } | ||
286 | int vc_reconfigure_encoder(VCSession* vc, int32_t bitrate, uint16_t width, uint16_t height) | ||
287 | { | ||
288 | if (!vc) | ||
289 | return; | ||
290 | |||
291 | vpx_codec_enc_cfg_t cfg = *vc->v_encoder[0].config.enc; | ||
292 | if (cfg.rc_target_bitrate == bitrate && cfg.g_w == width && cfg.g_h == height) | ||
293 | return 0; /* Nothing changed */ | ||
294 | |||
295 | cfg.rc_target_bitrate = bitrate; | ||
296 | cfg.g_w = width; | ||
297 | cfg.g_h = height; | ||
298 | |||
299 | int rc = vpx_codec_enc_config_set(vc->v_encoder, &cfg); | ||
300 | if ( rc != VPX_CODEC_OK) { | ||
301 | LOGGER_ERROR("Failed to set encoder control setting: %s", vpx_codec_err_to_string(rc)); | ||
302 | return -1; | ||
303 | } | ||
304 | |||
305 | return 0; | ||
291 | } | 306 | } |
292 | 307 | ||
293 | 308 | ||
309 | |||
294 | bool create_video_encoder (vpx_codec_ctx_t* dest, int32_t bitrate) | 310 | bool create_video_encoder (vpx_codec_ctx_t* dest, int32_t bitrate) |
295 | { | 311 | { |
296 | assert(dest); | 312 | assert(dest); |