| OLD | NEW |
| 1 /* Copyright (c) 2011 Xiph.Org Foundation | 1 /* Copyright (c) 2011 Xiph.Org Foundation |
| 2 Written by Jean-Marc Valin */ | 2 Written by Jean-Marc Valin */ |
| 3 /* | 3 /* |
| 4 Redistribution and use in source and binary forms, with or without | 4 Redistribution and use in source and binary forms, with or without |
| 5 modification, are permitted provided that the following conditions | 5 modification, are permitted provided that the following conditions |
| 6 are met: | 6 are met: |
| 7 | 7 |
| 8 - Redistributions of source code must retain the above copyright | 8 - Redistributions of source code must retain the above copyright |
| 9 notice, this list of conditions and the following disclaimer. | 9 notice, this list of conditions and the following disclaimer. |
| 10 | 10 |
| (...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 152 opus_int32 Fs, | 152 opus_int32 Fs, |
| 153 int channels, | 153 int channels, |
| 154 int streams, | 154 int streams, |
| 155 int coupled_streams, | 155 int coupled_streams, |
| 156 const unsigned char *mapping, | 156 const unsigned char *mapping, |
| 157 int application | 157 int application |
| 158 ) | 158 ) |
| 159 { | 159 { |
| 160 int coupled_size; | 160 int coupled_size; |
| 161 int mono_size; | 161 int mono_size; |
| 162 int i; | 162 int i, ret; |
| 163 char *ptr; | 163 char *ptr; |
| 164 | 164 |
| 165 if ((channels>255) || (channels<1) || (coupled_streams>streams) || | 165 if ((channels>255) || (channels<1) || (coupled_streams>streams) || |
| 166 (coupled_streams+streams>255) || (streams<1) || (coupled_streams<0)) | 166 (coupled_streams+streams>255) || (streams<1) || (coupled_streams<0)) |
| 167 return OPUS_BAD_ARG; | 167 return OPUS_BAD_ARG; |
| 168 | 168 |
| 169 st->layout.nb_channels = channels; | 169 st->layout.nb_channels = channels; |
| 170 st->layout.nb_streams = streams; | 170 st->layout.nb_streams = streams; |
| 171 st->layout.nb_coupled_streams = coupled_streams; | 171 st->layout.nb_coupled_streams = coupled_streams; |
| 172 | 172 |
| 173 for (i=0;i<st->layout.nb_channels;i++) | 173 for (i=0;i<st->layout.nb_channels;i++) |
| 174 st->layout.mapping[i] = mapping[i]; | 174 st->layout.mapping[i] = mapping[i]; |
| 175 if (!validate_layout(&st->layout) || !validate_encoder_layout(&st->layout)) | 175 if (!validate_layout(&st->layout) || !validate_encoder_layout(&st->layout)) |
| 176 return OPUS_BAD_ARG; | 176 return OPUS_BAD_ARG; |
| 177 ptr = (char*)st + align(sizeof(OpusMSEncoder)); | 177 ptr = (char*)st + align(sizeof(OpusMSEncoder)); |
| 178 coupled_size = opus_encoder_get_size(2); | 178 coupled_size = opus_encoder_get_size(2); |
| 179 mono_size = opus_encoder_get_size(1); | 179 mono_size = opus_encoder_get_size(1); |
| 180 | 180 |
| 181 for (i=0;i<st->layout.nb_coupled_streams;i++) | 181 for (i=0;i<st->layout.nb_coupled_streams;i++) |
| 182 { | 182 { |
| 183 opus_encoder_init((OpusEncoder*)ptr, Fs, 2, application); | 183 ret = opus_encoder_init((OpusEncoder*)ptr, Fs, 2, application); |
| 184 if(ret!=OPUS_OK)return ret; |
| 184 ptr += align(coupled_size); | 185 ptr += align(coupled_size); |
| 185 } | 186 } |
| 186 for (;i<st->layout.nb_streams;i++) | 187 for (;i<st->layout.nb_streams;i++) |
| 187 { | 188 { |
| 188 opus_encoder_init((OpusEncoder*)ptr, Fs, 1, application); | 189 ret = opus_encoder_init((OpusEncoder*)ptr, Fs, 1, application); |
| 190 if(ret!=OPUS_OK)return ret; |
| 189 ptr += align(mono_size); | 191 ptr += align(mono_size); |
| 190 } | 192 } |
| 191 return OPUS_OK; | 193 return OPUS_OK; |
| 192 } | 194 } |
| 193 | 195 |
| 194 OpusMSEncoder *opus_multistream_encoder_create( | 196 OpusMSEncoder *opus_multistream_encoder_create( |
| 195 opus_int32 Fs, | 197 opus_int32 Fs, |
| 196 int channels, | 198 int channels, |
| 197 int streams, | 199 int streams, |
| 198 int coupled_streams, | 200 int coupled_streams, |
| 199 const unsigned char *mapping, | 201 const unsigned char *mapping, |
| 200 int application, | 202 int application, |
| 201 int *error | 203 int *error |
| 202 ) | 204 ) |
| 203 { | 205 { |
| 204 int ret; | 206 int ret; |
| 205 OpusMSEncoder *st = (OpusMSEncoder *)opus_alloc(opus_multistream_encoder_get_
size(streams, coupled_streams)); | 207 OpusMSEncoder *st; |
| 208 if ((channels>255) || (channels<1) || (coupled_streams>streams) || |
| 209 (coupled_streams+streams>255) || (streams<1) || (coupled_streams<0)) |
| 210 { |
| 211 if (error) |
| 212 *error = OPUS_BAD_ARG; |
| 213 return NULL; |
| 214 } |
| 215 st = (OpusMSEncoder *)opus_alloc(opus_multistream_encoder_get_size(streams, c
oupled_streams)); |
| 206 if (st==NULL) | 216 if (st==NULL) |
| 207 { | 217 { |
| 208 if (error) | 218 if (error) |
| 209 *error = OPUS_ALLOC_FAIL; | 219 *error = OPUS_ALLOC_FAIL; |
| 210 return NULL; | 220 return NULL; |
| 211 } | 221 } |
| 212 ret = opus_multistream_encoder_init(st, Fs, channels, streams, coupled_stream
s, mapping, application); | 222 ret = opus_multistream_encoder_init(st, Fs, channels, streams, coupled_stream
s, mapping, application); |
| 213 if (ret != OPUS_OK) | 223 if (ret != OPUS_OK) |
| 214 { | 224 { |
| 215 opus_free(st); | 225 opus_free(st); |
| (...skipping 424 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 640 OpusMSDecoder *opus_multistream_decoder_create( | 650 OpusMSDecoder *opus_multistream_decoder_create( |
| 641 opus_int32 Fs, | 651 opus_int32 Fs, |
| 642 int channels, | 652 int channels, |
| 643 int streams, | 653 int streams, |
| 644 int coupled_streams, | 654 int coupled_streams, |
| 645 const unsigned char *mapping, | 655 const unsigned char *mapping, |
| 646 int *error | 656 int *error |
| 647 ) | 657 ) |
| 648 { | 658 { |
| 649 int ret; | 659 int ret; |
| 650 OpusMSDecoder *st = (OpusMSDecoder *)opus_alloc(opus_multistream_decoder_get_
size(streams, coupled_streams)); | 660 OpusMSDecoder *st; |
| 661 if ((channels>255) || (channels<1) || (coupled_streams>streams) || |
| 662 (coupled_streams+streams>255) || (streams<1) || (coupled_streams<0)) |
| 663 { |
| 664 if (error) |
| 665 *error = OPUS_BAD_ARG; |
| 666 return NULL; |
| 667 } |
| 668 st = (OpusMSDecoder *)opus_alloc(opus_multistream_decoder_get_size(streams, c
oupled_streams)); |
| 651 if (st==NULL) | 669 if (st==NULL) |
| 652 { | 670 { |
| 653 if (error) | 671 if (error) |
| 654 *error = OPUS_ALLOC_FAIL; | 672 *error = OPUS_ALLOC_FAIL; |
| 655 return NULL; | 673 return NULL; |
| 656 } | 674 } |
| 657 ret = opus_multistream_decoder_init(st, Fs, channels, streams, coupled_stream
s, mapping); | 675 ret = opus_multistream_decoder_init(st, Fs, channels, streams, coupled_stream
s, mapping); |
| 658 if (error) | 676 if (error) |
| 659 *error = ret; | 677 *error = ret; |
| 660 if (ret != OPUS_OK) | 678 if (ret != OPUS_OK) |
| 661 { | 679 { |
| 662 opus_free(st); | 680 opus_free(st); |
| 663 st = NULL; | 681 st = NULL; |
| 664 } | 682 } |
| 665 return st; | 683 return st; |
| 666 | |
| 667 | |
| 668 } | 684 } |
| 669 | 685 |
| 670 typedef void (*opus_copy_channel_out_func)( | 686 typedef void (*opus_copy_channel_out_func)( |
| 671 void *dst, | 687 void *dst, |
| 672 int dst_stride, | 688 int dst_stride, |
| 673 int dst_channel, | 689 int dst_channel, |
| 674 const opus_val16 *src, | 690 const opus_val16 *src, |
| 675 int src_stride, | 691 int src_stride, |
| 676 int frame_size | 692 int frame_size |
| 677 ); | 693 ); |
| (...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 901 | 917 |
| 902 va_start(ap, request); | 918 va_start(ap, request); |
| 903 | 919 |
| 904 coupled_size = opus_decoder_get_size(2); | 920 coupled_size = opus_decoder_get_size(2); |
| 905 mono_size = opus_decoder_get_size(1); | 921 mono_size = opus_decoder_get_size(1); |
| 906 ptr = (char*)st + align(sizeof(OpusMSDecoder)); | 922 ptr = (char*)st + align(sizeof(OpusMSDecoder)); |
| 907 switch (request) | 923 switch (request) |
| 908 { | 924 { |
| 909 case OPUS_GET_BANDWIDTH_REQUEST: | 925 case OPUS_GET_BANDWIDTH_REQUEST: |
| 910 case OPUS_GET_SAMPLE_RATE_REQUEST: | 926 case OPUS_GET_SAMPLE_RATE_REQUEST: |
| 927 case OPUS_GET_GAIN_REQUEST: |
| 928 case OPUS_GET_LAST_PACKET_DURATION_REQUEST: |
| 911 { | 929 { |
| 912 OpusDecoder *dec; | 930 OpusDecoder *dec; |
| 913 /* For int32* GET params, just query the first stream */ | 931 /* For int32* GET params, just query the first stream */ |
| 914 opus_int32 *value = va_arg(ap, opus_int32*); | 932 opus_int32 *value = va_arg(ap, opus_int32*); |
| 915 dec = (OpusDecoder*)ptr; | 933 dec = (OpusDecoder*)ptr; |
| 916 ret = opus_decoder_ctl(dec, request, value); | 934 ret = opus_decoder_ctl(dec, request, value); |
| 917 } | 935 } |
| 918 break; | 936 break; |
| 919 case OPUS_GET_FINAL_RANGE_REQUEST: | 937 case OPUS_GET_FINAL_RANGE_REQUEST: |
| 920 { | 938 { |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1000 | 1018 |
| 1001 va_end(ap); | 1019 va_end(ap); |
| 1002 return ret; | 1020 return ret; |
| 1003 } | 1021 } |
| 1004 | 1022 |
| 1005 | 1023 |
| 1006 void opus_multistream_decoder_destroy(OpusMSDecoder *st) | 1024 void opus_multistream_decoder_destroy(OpusMSDecoder *st) |
| 1007 { | 1025 { |
| 1008 opus_free(st); | 1026 opus_free(st); |
| 1009 } | 1027 } |
| OLD | NEW |