diff options
author | irungentoo <irungentoo@gmail.com> | 2014-02-16 20:01:30 -0500 |
---|---|---|
committer | irungentoo <irungentoo@gmail.com> | 2014-02-16 20:01:30 -0500 |
commit | baa4a2f11d9178e7506b24acaf7973cf17e0877d (patch) | |
tree | 67f69779f7078a196e4ba6539b564ca8b1370560 /toxav/media.c | |
parent | 9d1eb27717472f5655242fac7b8123a44f1ff33c (diff) |
Astyled av code.
Diffstat (limited to 'toxav/media.c')
-rw-r--r-- | toxav/media.c | 67 |
1 files changed, 36 insertions, 31 deletions
diff --git a/toxav/media.c b/toxav/media.c index c4894076..2594f99a 100644 --- a/toxav/media.c +++ b/toxav/media.c | |||
@@ -1,5 +1,5 @@ | |||
1 | /** media.c | 1 | /** media.c |
2 | * | 2 | * |
3 | * Audio and video codec intitialization, encoding/decoding and playback | 3 | * Audio and video codec intitialization, encoding/decoding and playback |
4 | * | 4 | * |
5 | * Copyright (C) 2013 Tox project All Rights Reserved. | 5 | * Copyright (C) 2013 Tox project All Rights Reserved. |
@@ -50,8 +50,8 @@ struct jitter_buffer { | |||
50 | struct jitter_buffer *create_queue(int capacity) | 50 | struct jitter_buffer *create_queue(int capacity) |
51 | { | 51 | { |
52 | struct jitter_buffer *q; | 52 | struct jitter_buffer *q; |
53 | q = (struct jitter_buffer *)calloc(sizeof(struct jitter_buffer),1); | 53 | q = (struct jitter_buffer *)calloc(sizeof(struct jitter_buffer), 1); |
54 | q->queue = (RTPMessage **)calloc(sizeof(RTPMessage*), capacity); | 54 | q->queue = (RTPMessage **)calloc(sizeof(RTPMessage *), capacity); |
55 | int i = 0; | 55 | int i = 0; |
56 | 56 | ||
57 | for (i = 0; i < capacity; ++i) { | 57 | for (i = 0; i < capacity; ++i) { |
@@ -200,7 +200,8 @@ int queue(struct jitter_buffer *q, RTPMessage *pk) | |||
200 | 200 | ||
201 | int init_video_decoder(CodecState *cs) | 201 | int init_video_decoder(CodecState *cs) |
202 | { | 202 | { |
203 | if (vpx_codec_dec_init_ver(&cs->v_decoder, VIDEO_CODEC_DECODER_INTERFACE, NULL, 0, VPX_DECODER_ABI_VERSION) != VPX_CODEC_OK) { | 203 | if (vpx_codec_dec_init_ver(&cs->v_decoder, VIDEO_CODEC_DECODER_INTERFACE, NULL, 0, |
204 | VPX_DECODER_ABI_VERSION) != VPX_CODEC_OK) { | ||
204 | fprintf(stderr, "Init video_decoder failed!\n"); | 205 | fprintf(stderr, "Init video_decoder failed!\n"); |
205 | return -1; | 206 | return -1; |
206 | } | 207 | } |
@@ -211,13 +212,13 @@ int init_video_decoder(CodecState *cs) | |||
211 | int init_audio_decoder(CodecState *cs, uint32_t audio_channels) | 212 | int init_audio_decoder(CodecState *cs, uint32_t audio_channels) |
212 | { | 213 | { |
213 | int rc; | 214 | int rc; |
214 | cs->audio_decoder = opus_decoder_create(cs->audio_sample_rate, audio_channels, &rc ); | 215 | cs->audio_decoder = opus_decoder_create(cs->audio_sample_rate, audio_channels, &rc ); |
215 | 216 | ||
216 | if ( rc != OPUS_OK ){ | 217 | if ( rc != OPUS_OK ) { |
217 | fprintf(stderr, "Error while starting audio decoder!\n"); | 218 | fprintf(stderr, "Error while starting audio decoder!\n"); |
218 | return -1; | 219 | return -1; |
219 | } | 220 | } |
220 | 221 | ||
221 | return 0; | 222 | return 0; |
222 | } | 223 | } |
223 | 224 | ||
@@ -226,18 +227,22 @@ int init_video_encoder(CodecState *cs, uint16_t width, uint16_t height, uint32_t | |||
226 | { | 227 | { |
227 | vpx_codec_enc_cfg_t cfg; | 228 | vpx_codec_enc_cfg_t cfg; |
228 | int res = vpx_codec_enc_config_default(VIDEO_CODEC_ENCODER_INTERFACE, &cfg, 0); | 229 | int res = vpx_codec_enc_config_default(VIDEO_CODEC_ENCODER_INTERFACE, &cfg, 0); |
229 | if(res) { | 230 | |
231 | if (res) { | ||
230 | printf("Failed to get config: %s\n", vpx_codec_err_to_string(res)); | 232 | printf("Failed to get config: %s\n", vpx_codec_err_to_string(res)); |
231 | return -1; | 233 | return -1; |
232 | } | 234 | } |
233 | 235 | ||
234 | cfg.rc_target_bitrate = video_bitrate; | 236 | cfg.rc_target_bitrate = video_bitrate; |
235 | cfg.g_w = width; | 237 | cfg.g_w = width; |
236 | cfg.g_h = height; | 238 | cfg.g_h = height; |
237 | if(vpx_codec_enc_init_ver(&cs->v_encoder, VIDEO_CODEC_ENCODER_INTERFACE, &cfg, 0, VPX_ENCODER_ABI_VERSION) != VPX_CODEC_OK) { | 239 | |
240 | if (vpx_codec_enc_init_ver(&cs->v_encoder, VIDEO_CODEC_ENCODER_INTERFACE, &cfg, 0, | ||
241 | VPX_ENCODER_ABI_VERSION) != VPX_CODEC_OK) { | ||
238 | fprintf(stderr, "Failed to initialize encoder\n"); | 242 | fprintf(stderr, "Failed to initialize encoder\n"); |
239 | return -1; | 243 | return -1; |
240 | } | 244 | } |
245 | |||
241 | return 0; | 246 | return 0; |
242 | } | 247 | } |
243 | 248 | ||
@@ -247,57 +252,57 @@ int init_audio_encoder(CodecState *cs, uint32_t audio_channels) | |||
247 | cs->audio_encoder = opus_encoder_create(cs->audio_sample_rate, audio_channels, OPUS_APPLICATION_AUDIO, &err); | 252 | cs->audio_encoder = opus_encoder_create(cs->audio_sample_rate, audio_channels, OPUS_APPLICATION_AUDIO, &err); |
248 | err = opus_encoder_ctl(cs->audio_encoder, OPUS_SET_BITRATE(cs->audio_bitrate)); | 253 | err = opus_encoder_ctl(cs->audio_encoder, OPUS_SET_BITRATE(cs->audio_bitrate)); |
249 | err = opus_encoder_ctl(cs->audio_encoder, OPUS_SET_COMPLEXITY(10)); | 254 | err = opus_encoder_ctl(cs->audio_encoder, OPUS_SET_COMPLEXITY(10)); |
250 | 255 | ||
251 | 256 | ||
252 | return err == OPUS_OK ? 0 : -1; | 257 | return err == OPUS_OK ? 0 : -1; |
253 | } | 258 | } |
254 | 259 | ||
255 | 260 | ||
256 | CodecState* codec_init_session ( uint32_t audio_bitrate, | 261 | CodecState *codec_init_session ( uint32_t audio_bitrate, |
257 | uint16_t audio_frame_duration, | 262 | uint16_t audio_frame_duration, |
258 | uint32_t audio_sample_rate, | 263 | uint32_t audio_sample_rate, |
259 | uint32_t audio_channels, | 264 | uint32_t audio_channels, |
260 | uint16_t video_width, | 265 | uint16_t video_width, |
261 | uint16_t video_height, | 266 | uint16_t video_height, |
262 | uint32_t video_bitrate ) | 267 | uint32_t video_bitrate ) |
263 | { | 268 | { |
264 | CodecState* _retu = calloc(sizeof(CodecState), 1); | 269 | CodecState *_retu = calloc(sizeof(CodecState), 1); |
265 | assert(_retu); | 270 | assert(_retu); |
266 | 271 | ||
267 | _retu->audio_bitrate = audio_bitrate; | 272 | _retu->audio_bitrate = audio_bitrate; |
268 | _retu->audio_sample_rate = audio_sample_rate; | 273 | _retu->audio_sample_rate = audio_sample_rate; |
269 | 274 | ||
270 | /* Encoders */ | 275 | /* Encoders */ |
271 | if (!video_width || !video_height) { | 276 | if (!video_width || !video_height) { |
272 | video_width = 320; | 277 | video_width = 320; |
273 | video_height = 240; | 278 | video_height = 240; |
274 | } | 279 | } |
275 | 280 | ||
276 | if ( 0 == init_video_encoder(_retu, video_width, video_height, video_bitrate) ) | 281 | if ( 0 == init_video_encoder(_retu, video_width, video_height, video_bitrate) ) |
277 | printf("Video encoder initialized!\n"); | 282 | printf("Video encoder initialized!\n"); |
278 | 283 | ||
279 | if ( 0 == init_audio_encoder(_retu, audio_channels) ) | 284 | if ( 0 == init_audio_encoder(_retu, audio_channels) ) |
280 | printf("Audio encoder initialized!\n"); | 285 | printf("Audio encoder initialized!\n"); |
281 | 286 | ||
282 | 287 | ||
283 | /* Decoders */ | 288 | /* Decoders */ |
284 | if ( 0 == init_video_decoder(_retu) ) | 289 | if ( 0 == init_video_decoder(_retu) ) |
285 | printf("Video decoder initialized!\n"); | 290 | printf("Video decoder initialized!\n"); |
286 | 291 | ||
287 | if ( 0 == init_audio_decoder(_retu, audio_channels) ) | 292 | if ( 0 == init_audio_decoder(_retu, audio_channels) ) |
288 | printf("Audio decoder initialized!\n"); | 293 | printf("Audio decoder initialized!\n"); |
289 | 294 | ||
290 | 295 | ||
291 | return _retu; | 296 | return _retu; |
292 | } | 297 | } |
293 | 298 | ||
294 | void codec_terminate_session ( CodecState* cs ) | 299 | void codec_terminate_session ( CodecState *cs ) |
295 | { | 300 | { |
296 | if ( cs->audio_encoder ) { | 301 | if ( cs->audio_encoder ) { |
297 | opus_encoder_destroy(cs->audio_encoder); | 302 | opus_encoder_destroy(cs->audio_encoder); |
298 | printf("Terminated encoder!\n"); | 303 | printf("Terminated encoder!\n"); |
299 | } | 304 | } |
300 | 305 | ||
301 | if ( cs->audio_decoder ) { | 306 | if ( cs->audio_decoder ) { |
302 | opus_decoder_destroy(cs->audio_decoder); | 307 | opus_decoder_destroy(cs->audio_decoder); |
303 | printf("Terminated decoder!\n"); | 308 | printf("Terminated decoder!\n"); |