Coverage Report

Created: 2025-11-16 07:20

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/opus/src/opus_multistream.c
Line
Count
Source
1
/* Copyright (c) 2011 Xiph.Org Foundation
2
   Written by Jean-Marc Valin */
3
/*
4
   Redistribution and use in source and binary forms, with or without
5
   modification, are permitted provided that the following conditions
6
   are met:
7
8
   - Redistributions of source code must retain the above copyright
9
   notice, this list of conditions and the following disclaimer.
10
11
   - Redistributions in binary form must reproduce the above copyright
12
   notice, this list of conditions and the following disclaimer in the
13
   documentation and/or other materials provided with the distribution.
14
15
   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
16
   ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
17
   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
18
   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
19
   OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
20
   EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
21
   PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
22
   PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
23
   LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
24
   NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25
   SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26
*/
27
28
#ifdef HAVE_CONFIG_H
29
#include "config.h"
30
#endif
31
32
#include "opus_multistream.h"
33
#include "opus.h"
34
#include "opus_private.h"
35
#include "stack_alloc.h"
36
#include <stdarg.h>
37
#include "float_cast.h"
38
#include "os_support.h"
39
40
41
int validate_layout(const ChannelLayout *layout)
42
298k
{
43
298k
   int i, max_channel;
44
45
298k
   max_channel = layout->nb_streams+layout->nb_coupled_streams;
46
298k
   if (max_channel>255)
47
0
      return 0;
48
2.39M
   for (i=0;i<layout->nb_channels;i++)
49
2.10M
   {
50
2.10M
      if (layout->mapping[i] >= max_channel && layout->mapping[i] != 255)
51
4
         return 0;
52
2.10M
   }
53
298k
   return 1;
54
298k
}
55
56
57
int get_left_channel(const ChannelLayout *layout, int stream_id, int prev)
58
425k
{
59
425k
   int i;
60
425k
   i = (prev<0) ? 0 : prev+1;
61
713k
   for (;i<layout->nb_channels;i++)
62
497k
   {
63
497k
      if (layout->mapping[i]==stream_id*2)
64
209k
         return i;
65
497k
   }
66
216k
   return -1;
67
425k
}
68
69
int get_right_channel(const ChannelLayout *layout, int stream_id, int prev)
70
437k
{
71
437k
   int i;
72
437k
   i = (prev<0) ? 0 : prev+1;
73
713k
   for (;i<layout->nb_channels;i++)
74
497k
   {
75
497k
      if (layout->mapping[i]==stream_id*2+1)
76
221k
         return i;
77
497k
   }
78
216k
   return -1;
79
437k
}
80
81
int get_mono_channel(const ChannelLayout *layout, int stream_id, int prev)
82
41.4k
{
83
41.4k
   int i;
84
41.4k
   i = (prev<0) ? 0 : prev+1;
85
116k
   for (;i<layout->nb_channels;i++)
86
94.9k
   {
87
94.9k
      if (layout->mapping[i]==stream_id+layout->nb_coupled_streams)
88
20.2k
         return i;
89
94.9k
   }
90
21.2k
   return -1;
91
41.4k
}