~ubuntu-branches/ubuntu/vivid/mpv/vivid

« back to all changes in this revision

Viewing changes to audio/reorder_ch.c

  • Committer: Package Import Robot
  • Author(s): Alessandro Ghedini
  • Date: 2013-12-29 20:04:26 UTC
  • mfrom: (1.1.9)
  • Revision ID: package-import@ubuntu.com-20131229200426-w0qsj8clnui1pxaw
Tags: 0.3.0-1
* New upstream release
  - Fix --vf=expand example in manpage (Closes: #732271)
* Add 03_waf.patch to provide uncompressed waf scripts and modules
* Switch to waf build script
* Drop libmng-dev Build-Depends (not used anymore)
* Bump Standards-Version to 3.9.5 (no changes needed)
* Enable support for dvdnav
* Install more docs

Show diffs side-by-side

added added

removed removed

Lines of Context:
27
27
#include "chmap.h"
28
28
#include "reorder_ch.h"
29
29
 
30
 
static inline void reorder_to_planar_(void *restrict out, const void *restrict in,
31
 
                                      size_t size, size_t nchan, size_t nmemb)
32
 
{
33
 
    size_t i, c;
34
 
    char *outptr = (char *) out;
35
 
    size_t instep = nchan * size;
36
 
 
37
 
    for (c = 0; c < nchan; ++c) {
38
 
        const char *inptr = ((const char *) in) + c * size;
39
 
        for (i = 0; i < nmemb; ++i, inptr += instep, outptr += size) {
40
 
            memcpy(outptr, inptr, size);
41
 
        }
42
 
    }
43
 
}
44
 
 
45
 
void reorder_to_planar(void *restrict out, const void *restrict in,
46
 
                       size_t size, size_t nchan, size_t nmemb)
47
 
{
48
 
    // special case for mono (nothing to do...)
49
 
    if (nchan == 1)
50
 
        memcpy(out, in, size * nchan * nmemb);
51
 
    // these calls exist to insert an inline copy of to_planar_ here with known
52
 
    // value of size to help the compiler replace the memcpy calls by mov
53
 
    // instructions
54
 
    else if (size == 1)
55
 
        reorder_to_planar_(out, in, 1, nchan, nmemb);
56
 
    else if (size == 2)
57
 
        reorder_to_planar_(out, in, 2, nchan, nmemb);
58
 
    else if (size == 4)
59
 
        reorder_to_planar_(out, in, 4, nchan, nmemb);
60
 
    // general case (calls memcpy a lot, should actually never happen, but
61
 
    // stays here for correctness purposes)
62
 
    else
63
 
        reorder_to_planar_(out, in, size, nchan, nmemb);
64
 
}
65
 
 
66
 
static inline void reorder_to_packed_(uint8_t *out, uint8_t **in,
67
 
                                      size_t size, size_t nchan, size_t nmemb)
68
 
{
69
 
    size_t outstep = nchan * size;
70
 
 
71
 
    for (size_t c = 0; c < nchan; ++c) {
72
 
        char *outptr = out + c * size;
73
 
        char *inptr = in[c];
74
 
        for (size_t i = 0; i < nmemb; ++i, outptr += outstep, inptr += size) {
75
 
            memcpy(outptr, inptr, size);
76
 
        }
77
 
    }
78
 
}
79
 
 
80
 
// out = destination array of packed samples of given size, nmemb frames
81
 
// in[channel] = source array of samples for the given channel
82
 
void reorder_to_packed(uint8_t *out, uint8_t **in,
83
 
                       size_t size, size_t nchan, size_t nmemb)
84
 
{
85
 
    if (nchan == 1)
86
 
        memcpy(out, in, size * nchan * nmemb);
87
 
    // See reorder_to_planar() why this is done this way
88
 
    else if (size == 1)
89
 
        reorder_to_packed_(out, in, 1, nchan, nmemb);
90
 
    else if (size == 2)
91
 
        reorder_to_packed_(out, in, 2, nchan, nmemb);
92
 
    else if (size == 4)
93
 
        reorder_to_packed_(out, in, 4, nchan, nmemb);
94
 
    else
95
 
        reorder_to_packed_(out, in, size, nchan, nmemb);
96
 
}
97
 
 
98
30
#define MAX_SAMPLESIZE 8
99
31
 
100
32
static void reorder_channels_(uint8_t *restrict data, int *restrict ch_order,