diff options
author | iphydf <iphydf@users.noreply.github.com> | 2016-08-19 13:07:45 +0100 |
---|---|---|
committer | iphydf <iphydf@users.noreply.github.com> | 2016-08-27 01:16:14 +0100 |
commit | 13ae9e9a93a1c02fad9475002c0391b86b7ad7bb (patch) | |
tree | a9575d3582c4f40e051c93ae18dded03fdddc432 /toxav/video.c | |
parent | 1f25fc0ae417bfc47dea4966cb5e43689aa88d5c (diff) |
Move logging to a callback.
This removes the global logger (which by the way was deleted when the first tox
was killed, so other toxes would then stop logging). Various bits of the code
now carry a logger or pass it around. It's a bit less transparent now, but now
there is no need to have a global logger, and clients can decide what to log and
where.
Diffstat (limited to 'toxav/video.c')
-rw-r--r-- | toxav/video.c | 35 |
1 files changed, 18 insertions, 17 deletions
diff --git a/toxav/video.c b/toxav/video.c index 8a832201..300eb377 100644 --- a/toxav/video.c +++ b/toxav/video.c | |||
@@ -36,17 +36,17 @@ | |||
36 | #define MAX_DECODE_TIME_US 0 /* Good quality encode. */ | 36 | #define MAX_DECODE_TIME_US 0 /* Good quality encode. */ |
37 | #define VIDEO_DECODE_BUFFER_SIZE 20 | 37 | #define VIDEO_DECODE_BUFFER_SIZE 20 |
38 | 38 | ||
39 | VCSession *vc_new(ToxAV *av, uint32_t friend_number, toxav_video_receive_frame_cb *cb, void *cb_data) | 39 | VCSession *vc_new(Logger *log, ToxAV *av, uint32_t friend_number, toxav_video_receive_frame_cb *cb, void *cb_data) |
40 | { | 40 | { |
41 | VCSession *vc = calloc(sizeof(VCSession), 1); | 41 | VCSession *vc = calloc(sizeof(VCSession), 1); |
42 | 42 | ||
43 | if (!vc) { | 43 | if (!vc) { |
44 | LOGGER_WARNING("Allocation failed! Application might misbehave!"); | 44 | LOGGER_WARNING(log, "Allocation failed! Application might misbehave!"); |
45 | return NULL; | 45 | return NULL; |
46 | } | 46 | } |
47 | 47 | ||
48 | if (create_recursive_mutex(vc->queue_mutex) != 0) { | 48 | if (create_recursive_mutex(vc->queue_mutex) != 0) { |
49 | LOGGER_WARNING("Failed to create recursive mutex!"); | 49 | LOGGER_WARNING(log, "Failed to create recursive mutex!"); |
50 | free(vc); | 50 | free(vc); |
51 | return NULL; | 51 | return NULL; |
52 | } | 52 | } |
@@ -57,7 +57,7 @@ VCSession *vc_new(ToxAV *av, uint32_t friend_number, toxav_video_receive_frame_c | |||
57 | int rc = vpx_codec_dec_init(vc->decoder, VIDEO_CODEC_DECODER_INTERFACE, NULL, 0); | 57 | int rc = vpx_codec_dec_init(vc->decoder, VIDEO_CODEC_DECODER_INTERFACE, NULL, 0); |
58 | 58 | ||
59 | if (rc != VPX_CODEC_OK) { | 59 | if (rc != VPX_CODEC_OK) { |
60 | LOGGER_ERROR("Init video_decoder failed: %s", vpx_codec_err_to_string(rc)); | 60 | LOGGER_ERROR(log, "Init video_decoder failed: %s", vpx_codec_err_to_string(rc)); |
61 | goto BASE_CLEANUP; | 61 | goto BASE_CLEANUP; |
62 | } | 62 | } |
63 | 63 | ||
@@ -67,7 +67,7 @@ VCSession *vc_new(ToxAV *av, uint32_t friend_number, toxav_video_receive_frame_c | |||
67 | rc = vpx_codec_enc_config_default(VIDEO_CODEC_ENCODER_INTERFACE, &cfg, 0); | 67 | rc = vpx_codec_enc_config_default(VIDEO_CODEC_ENCODER_INTERFACE, &cfg, 0); |
68 | 68 | ||
69 | if (rc != VPX_CODEC_OK) { | 69 | if (rc != VPX_CODEC_OK) { |
70 | LOGGER_ERROR("Failed to get config: %s", vpx_codec_err_to_string(rc)); | 70 | LOGGER_ERROR(log, "Failed to get config: %s", vpx_codec_err_to_string(rc)); |
71 | goto BASE_CLEANUP_1; | 71 | goto BASE_CLEANUP_1; |
72 | } | 72 | } |
73 | 73 | ||
@@ -86,14 +86,14 @@ VCSession *vc_new(ToxAV *av, uint32_t friend_number, toxav_video_receive_frame_c | |||
86 | rc = vpx_codec_enc_init(vc->encoder, VIDEO_CODEC_ENCODER_INTERFACE, &cfg, 0); | 86 | rc = vpx_codec_enc_init(vc->encoder, VIDEO_CODEC_ENCODER_INTERFACE, &cfg, 0); |
87 | 87 | ||
88 | if (rc != VPX_CODEC_OK) { | 88 | if (rc != VPX_CODEC_OK) { |
89 | LOGGER_ERROR("Failed to initialize encoder: %s", vpx_codec_err_to_string(rc)); | 89 | LOGGER_ERROR(log, "Failed to initialize encoder: %s", vpx_codec_err_to_string(rc)); |
90 | goto BASE_CLEANUP_1; | 90 | goto BASE_CLEANUP_1; |
91 | } | 91 | } |
92 | 92 | ||
93 | rc = vpx_codec_control(vc->encoder, VP8E_SET_CPUUSED, 8); | 93 | rc = vpx_codec_control(vc->encoder, VP8E_SET_CPUUSED, 8); |
94 | 94 | ||
95 | if (rc != VPX_CODEC_OK) { | 95 | if (rc != VPX_CODEC_OK) { |
96 | LOGGER_ERROR("Failed to set encoder control setting: %s", vpx_codec_err_to_string(rc)); | 96 | LOGGER_ERROR(log, "Failed to set encoder control setting: %s", vpx_codec_err_to_string(rc)); |
97 | vpx_codec_destroy(vc->encoder); | 97 | vpx_codec_destroy(vc->encoder); |
98 | goto BASE_CLEANUP_1; | 98 | goto BASE_CLEANUP_1; |
99 | } | 99 | } |
@@ -104,6 +104,7 @@ VCSession *vc_new(ToxAV *av, uint32_t friend_number, toxav_video_receive_frame_c | |||
104 | vc->vcb.second = cb_data; | 104 | vc->vcb.second = cb_data; |
105 | vc->friend_number = friend_number; | 105 | vc->friend_number = friend_number; |
106 | vc->av = av; | 106 | vc->av = av; |
107 | vc->log = log; | ||
107 | 108 | ||
108 | return vc; | 109 | return vc; |
109 | 110 | ||
@@ -132,7 +133,7 @@ void vc_kill(VCSession *vc) | |||
132 | 133 | ||
133 | pthread_mutex_destroy(vc->queue_mutex); | 134 | pthread_mutex_destroy(vc->queue_mutex); |
134 | 135 | ||
135 | LOGGER_DEBUG("Terminated video handler: %p", vc); | 136 | LOGGER_DEBUG(vc->log, "Terminated video handler: %p", vc); |
136 | free(vc); | 137 | free(vc); |
137 | } | 138 | } |
138 | void vc_iterate(VCSession *vc) | 139 | void vc_iterate(VCSession *vc) |
@@ -152,7 +153,7 @@ void vc_iterate(VCSession *vc) | |||
152 | free(p); | 153 | free(p); |
153 | 154 | ||
154 | if (rc != VPX_CODEC_OK) | 155 | if (rc != VPX_CODEC_OK) |
155 | LOGGER_ERROR("Error decoding video: %s", vpx_codec_err_to_string(rc)); | 156 | LOGGER_ERROR(vc->log, "Error decoding video: %s", vpx_codec_err_to_string(rc)); |
156 | else { | 157 | else { |
157 | vpx_codec_iter_t iter = NULL; | 158 | vpx_codec_iter_t iter = NULL; |
158 | vpx_image_t *dest = vpx_codec_get_frame(vc->decoder, &iter); | 159 | vpx_image_t *dest = vpx_codec_get_frame(vc->decoder, &iter); |
@@ -181,20 +182,20 @@ int vc_queue_message(void *vcp, struct RTPMessage *msg) | |||
181 | if (!vcp || !msg) | 182 | if (!vcp || !msg) |
182 | return -1; | 183 | return -1; |
183 | 184 | ||
185 | VCSession *vc = vcp; | ||
186 | |||
184 | if (msg->header.pt == (rtp_TypeVideo + 2) % 128) { | 187 | if (msg->header.pt == (rtp_TypeVideo + 2) % 128) { |
185 | LOGGER_WARNING("Got dummy!"); | 188 | LOGGER_WARNING(vc->log, "Got dummy!"); |
186 | free(msg); | 189 | free(msg); |
187 | return 0; | 190 | return 0; |
188 | } | 191 | } |
189 | 192 | ||
190 | if (msg->header.pt != rtp_TypeVideo % 128) { | 193 | if (msg->header.pt != rtp_TypeVideo % 128) { |
191 | LOGGER_WARNING("Invalid payload type!"); | 194 | LOGGER_WARNING(vc->log, "Invalid payload type!"); |
192 | free(msg); | 195 | free(msg); |
193 | return -1; | 196 | return -1; |
194 | } | 197 | } |
195 | 198 | ||
196 | VCSession *vc = vcp; | ||
197 | |||
198 | pthread_mutex_lock(vc->queue_mutex); | 199 | pthread_mutex_lock(vc->queue_mutex); |
199 | free(rb_write(vc->vbuf_raw, msg)); | 200 | free(rb_write(vc->vbuf_raw, msg)); |
200 | { | 201 | { |
@@ -225,7 +226,7 @@ int vc_reconfigure_encoder(VCSession *vc, uint32_t bit_rate, uint16_t width, uin | |||
225 | rc = vpx_codec_enc_config_set(vc->encoder, &cfg); | 226 | rc = vpx_codec_enc_config_set(vc->encoder, &cfg); |
226 | 227 | ||
227 | if (rc != VPX_CODEC_OK) { | 228 | if (rc != VPX_CODEC_OK) { |
228 | LOGGER_ERROR("Failed to set encoder control setting: %s", vpx_codec_err_to_string(rc)); | 229 | LOGGER_ERROR(vc->log, "Failed to set encoder control setting: %s", vpx_codec_err_to_string(rc)); |
229 | return -1; | 230 | return -1; |
230 | } | 231 | } |
231 | } else { | 232 | } else { |
@@ -233,7 +234,7 @@ int vc_reconfigure_encoder(VCSession *vc, uint32_t bit_rate, uint16_t width, uin | |||
233 | * reconfiguring encoder to use resolutions greater than initially set. | 234 | * reconfiguring encoder to use resolutions greater than initially set. |
234 | */ | 235 | */ |
235 | 236 | ||
236 | LOGGER_DEBUG("Have to reinitialize vpx encoder on session %p", vc); | 237 | LOGGER_DEBUG(vc->log, "Have to reinitialize vpx encoder on session %p", vc); |
237 | 238 | ||
238 | cfg.rc_target_bitrate = bit_rate; | 239 | cfg.rc_target_bitrate = bit_rate; |
239 | cfg.g_w = width; | 240 | cfg.g_w = width; |
@@ -244,14 +245,14 @@ int vc_reconfigure_encoder(VCSession *vc, uint32_t bit_rate, uint16_t width, uin | |||
244 | rc = vpx_codec_enc_init(&new_c, VIDEO_CODEC_ENCODER_INTERFACE, &cfg, 0); | 245 | rc = vpx_codec_enc_init(&new_c, VIDEO_CODEC_ENCODER_INTERFACE, &cfg, 0); |
245 | 246 | ||
246 | if (rc != VPX_CODEC_OK) { | 247 | if (rc != VPX_CODEC_OK) { |
247 | LOGGER_ERROR("Failed to initialize encoder: %s", vpx_codec_err_to_string(rc)); | 248 | LOGGER_ERROR(vc->log, "Failed to initialize encoder: %s", vpx_codec_err_to_string(rc)); |
248 | return -1; | 249 | return -1; |
249 | } | 250 | } |
250 | 251 | ||
251 | rc = vpx_codec_control(&new_c, VP8E_SET_CPUUSED, 8); | 252 | rc = vpx_codec_control(&new_c, VP8E_SET_CPUUSED, 8); |
252 | 253 | ||
253 | if (rc != VPX_CODEC_OK) { | 254 | if (rc != VPX_CODEC_OK) { |
254 | LOGGER_ERROR("Failed to set encoder control setting: %s", vpx_codec_err_to_string(rc)); | 255 | LOGGER_ERROR(vc->log, "Failed to set encoder control setting: %s", vpx_codec_err_to_string(rc)); |
255 | vpx_codec_destroy(&new_c); | 256 | vpx_codec_destroy(&new_c); |
256 | return -1; | 257 | return -1; |
257 | } | 258 | } |