~medibuntu-maintainers/mplayer/medibuntu.precise

« back to all changes in this revision

Viewing changes to ffmpeg/libavcodec/adxenc.c

  • Committer: Gauvain Pocentek
  • Date: 2012-03-06 11:59:12 UTC
  • mfrom: (66.1.15 precise)
  • Revision ID: gauvain@pocentek.net-20120306115912-h9d6kt9j0l532oo5
* Merge from Ubuntu:
  - put back faac support
  - recommends apport-hooks-medibuntu
  - change Maintainer, Uploaders & Vcs-* fields.
* New upstream snapshot
* upload to unstable
* Build against external libmpeg2
* drop 51_FTBFS_arm.patch again
* no longer build depend on libcdparanoia-dev on the Hurd
* Fix FTBFS on the hurd.
  Thanks to Samuel Thibault <sthibault@debian.org> (Closes: #654974)
* Fix FTBFS on arm
* New upstream snapshot, Closes: #650339, #643621, #481807
* Imported Upstream version 1.0~rc4+svn34492
* Bump standards version
* Bump dependency on libav >= 4:0.8~, Closes: #653887
* Fix build-indep
* Build mplayer-gui again, Closes: #568514
* Drop debian/all-lang-config-mak.sh, no longer needed
* include .dfsg1 in version number
* remove get-orig-source target
* no longer prune compiler flags from the environment
* No longer advertise nor build 3fdx, mga and dxr3 backends,
  Closes: #496106, #442181, #533546
* beautify mplayer version identification string
* Brown paperbag upload.
* Next try to fix build failure on sparce after recent binutils change.
* Brown paperbag upload.
* Really fix build failure on sparc after recent binutils change.
* Properly set Replaces/Conflicts on mplayer2{,-dbg} to avoid
  file overwrite errors.
* Adjust versioning of mplayer listed in the mplayer-dbg's Depends field.
* Fix build failure on sparc after recent binutils change.
* Urgency medium bumped because of RC-level bugfix
  and speeding up x264 transition.
* Update to my @debian.org email.
* Upload to unstable
* Enable joystick support on Linux only, Closes: #638408
* Rebuild fixes toolchain issue on arm, Closes: #637077
* New upstream snapshot
* following the discussion started by Diego Biurrun <diego@biurrun.de>
  in debian-devel, I have prepared a new packaging of 'mplayer'
  (with code that comes from CVS)
* the upstream tar.bz cannot be distributed by Debian, since it contains
   CSS code; so I am repackaging it 
* I have tried my best to address all known issues:
  - the package contains the detailed Copyright made by Diego Biurrun 
  - the package does not contain CSS code, or  AFAIK other code on which 
     there is active patent enforcement
  - there is a script  debian/cvs-changelog.sh  that shows all changes
     done to files included in this source.
    This should comply with GPLv2 sec 2.a  (in spirit if not in letter)
    For this reason, the source code contains CVS directories.
* needs   make (>= 3.80) for 'html-chunked-$(1)' in DOCS/xml/Makefile

* some corrections, as suggested Diego Biurrun
  - binary codecs should go into /usr/lib/codecs (upstream default)
  - better template 'mplayer/install_codecs'
  - an empty 'font=' in mplayer.conf breaks mplayer: postinst corrected
* correction in 'mplayer/cfgnote'
* better mplayer.postinst and mplayer.config

* New upstream release
* better debian/copyright file
* do not ship a skin
* New upstream release
* changed DEB_BUILD_OPTIONS to DEB_BUILD_CONFIGURE ,
  DEB_BUILD_OPTIONS is used as in debian policy
* use gcc-3.4
* changed xlibs-dev to a long list of dependencies, for Debian/etch
* try to adhere to  http://www.mplayerhq.hu/DOCS/tech/binary-packaging.txt
  (see README.Debian for details)
* removed dependency on xlibmesa-dev, disabled opengl
* New upstream release
* Simon McVittie <hacks@pseudorandom.co.uk> wonderful work:
- Work around Debian bug #267442 (glibc's sys/uio.h and gcc's altivec.h have
  conflicting uses for __vector) by re-ordering #includes
- Fix potential symlink attack in ./configure
- Disable support for binary codecs on platforms for which those codecs
  aren't available; also disable the corresponding Debconf note when it's
  inappropriate
- Changed Build-Depends: so it works in pbuilder
- Explicitly build-depend on libjpeg62-dev, libfontconfig1-dev,
  libungif4-dev 
- Tweak debian/rules to avoid certain errors being ignored
- Use --language=all
* provide a target  'debian/rules get-orig-source' 
  that recreates the orig.tar.gz ; then use the above orig.tar.gz
* rewrote some parts of debian/rules
* don't clean and recompile docs if upstream ships them
* mplayer-doc was shipping too much stuff
* translated man pages where not installed properly
* compile with libdv4-dev
* correct README.Debian
* Forgot build-dep on libtheora
* Must not depend on libxvidcore
* New upstream release
* new release.
* rc1 to become 0.90
* new pre-release
* new pre-release
* gtk bug fixed.
* new release.
* version bumped
* 0.60 pre2 release
* 0.60 pre-release.

Show diffs side-by-side

added added

removed removed

Lines of Context:
19
19
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20
20
 */
21
21
 
22
 
#include "libavutil/intreadwrite.h"
23
22
#include "avcodec.h"
24
23
#include "adx.h"
 
24
#include "bytestream.h"
 
25
#include "put_bits.h"
25
26
 
26
27
/**
27
28
 * @file
32
33
 * adx2wav & wav2adx http://www.geocities.co.jp/Playtown/2004/
33
34
 */
34
35
 
35
 
/* 18 bytes <-> 32 samples */
36
 
 
37
 
static void adx_encode(unsigned char *adx,const short *wav,PREV *prev)
 
36
static void adx_encode(ADXContext *c, uint8_t *adx, const int16_t *wav,
 
37
                       ADXChannelState *prev, int channels)
38
38
{
 
39
    PutBitContext pb;
39
40
    int scale;
40
 
    int i;
41
 
    int s0,s1,s2,d;
42
 
    int max=0;
43
 
    int min=0;
44
 
    int data[32];
 
41
    int i, j;
 
42
    int s0, s1, s2, d;
 
43
    int max = 0;
 
44
    int min = 0;
 
45
    int data[BLOCK_SAMPLES];
45
46
 
46
47
    s1 = prev->s1;
47
48
    s2 = prev->s2;
48
 
    for(i=0;i<32;i++) {
 
49
    for (i = 0, j = 0; j < 32; i += channels, j++) {
49
50
        s0 = wav[i];
50
 
        d = ((s0<<14) - SCALE1*s1 + SCALE2*s2)/BASEVOL;
51
 
        data[i]=d;
52
 
        if (max<d) max=d;
53
 
        if (min>d) min=d;
 
51
        d = ((s0 << COEFF_BITS) - c->coeff[0] * s1 - c->coeff[1] * s2) >> COEFF_BITS;
 
52
        data[j] = d;
 
53
        if (max < d)
 
54
            max = d;
 
55
        if (min > d)
 
56
            min = d;
54
57
        s2 = s1;
55
58
        s1 = s0;
56
59
    }
57
60
    prev->s1 = s1;
58
61
    prev->s2 = s2;
59
62
 
60
 
    /* -8..+7 */
61
 
 
62
 
    if (max==0 && min==0) {
63
 
        memset(adx,0,18);
 
63
    if (max == 0 && min == 0) {
 
64
        memset(adx, 0, BLOCK_SIZE);
64
65
        return;
65
66
    }
66
67
 
67
 
    if (max/7>-min/8) scale = max/7;
68
 
    else scale = -min/8;
 
68
    if (max / 7 > -min / 8)
 
69
        scale = max / 7;
 
70
    else
 
71
        scale = -min / 8;
69
72
 
70
 
    if (scale==0) scale=1;
 
73
    if (scale == 0)
 
74
        scale = 1;
71
75
 
72
76
    AV_WB16(adx, scale);
73
77
 
74
 
    for(i=0;i<16;i++) {
75
 
        adx[i+2] = ((data[i*2]/scale)<<4) | ((data[i*2+1]/scale)&0xf);
76
 
    }
 
78
    init_put_bits(&pb, adx + 2, 16);
 
79
    for (i = 0; i < BLOCK_SAMPLES; i++)
 
80
        put_sbits(&pb, 4, av_clip(data[i] / scale, -8, 7));
 
81
    flush_put_bits(&pb);
77
82
}
78
83
 
79
 
static int adx_encode_header(AVCodecContext *avctx,unsigned char *buf,size_t bufsize)
 
84
#define HEADER_SIZE 36
 
85
 
 
86
static int adx_encode_header(AVCodecContext *avctx, uint8_t *buf, int bufsize)
80
87
{
81
 
#if 0
82
 
    struct {
83
 
        uint32_t offset; /* 0x80000000 + sample start - 4 */
84
 
        unsigned char unknown1[3]; /* 03 12 04 */
85
 
        unsigned char channel; /* 1 or 2 */
86
 
        uint32_t freq;
87
 
        uint32_t size;
88
 
        uint32_t unknown2; /* 01 f4 03 00 */
89
 
        uint32_t unknown3; /* 00 00 00 00 */
90
 
        uint32_t unknown4; /* 00 00 00 00 */
91
 
 
92
 
    /* if loop
93
 
        unknown3 00 15 00 01
94
 
        unknown4 00 00 00 01
95
 
        long loop_start_sample;
96
 
        long loop_start_byte;
97
 
        long loop_end_sample;
98
 
        long loop_end_byte;
99
 
        long
100
 
    */
101
 
    } adxhdr; /* big endian */
102
 
    /* offset-6 "(c)CRI" */
103
 
#endif
104
 
    AV_WB32(buf+0x00,0x80000000|0x20);
105
 
    AV_WB32(buf+0x04,0x03120400|avctx->channels);
106
 
    AV_WB32(buf+0x08,avctx->sample_rate);
107
 
    AV_WB32(buf+0x0c,0); /* FIXME: set after */
108
 
    AV_WB32(buf+0x10,0x01040300);
109
 
    AV_WB32(buf+0x14,0x00000000);
110
 
    AV_WB32(buf+0x18,0x00000000);
111
 
    memcpy(buf+0x1c,"\0\0(c)CRI",8);
112
 
    return 0x20+4;
 
88
    ADXContext *c = avctx->priv_data;
 
89
 
 
90
    if (bufsize < HEADER_SIZE)
 
91
        return AVERROR(EINVAL);
 
92
 
 
93
    bytestream_put_be16(&buf, 0x8000);              /* header signature */
 
94
    bytestream_put_be16(&buf, HEADER_SIZE - 4);     /* copyright offset */
 
95
    bytestream_put_byte(&buf, 3);                   /* encoding */
 
96
    bytestream_put_byte(&buf, BLOCK_SIZE);          /* block size */
 
97
    bytestream_put_byte(&buf, 4);                   /* sample size */
 
98
    bytestream_put_byte(&buf, avctx->channels);     /* channels */
 
99
    bytestream_put_be32(&buf, avctx->sample_rate);  /* sample rate */
 
100
    bytestream_put_be32(&buf, 0);                   /* total sample count */
 
101
    bytestream_put_be16(&buf, c->cutoff);           /* cutoff frequency */
 
102
    bytestream_put_byte(&buf, 3);                   /* version */
 
103
    bytestream_put_byte(&buf, 0);                   /* flags */
 
104
    bytestream_put_be32(&buf, 0);                   /* unknown */
 
105
    bytestream_put_be32(&buf, 0);                   /* loop enabled */
 
106
    bytestream_put_be16(&buf, 0);                   /* padding */
 
107
    bytestream_put_buffer(&buf, "(c)CRI", 6);       /* copyright signature */
 
108
 
 
109
    return HEADER_SIZE;
113
110
}
114
111
 
115
112
static av_cold int adx_encode_init(AVCodecContext *avctx)
116
113
{
117
 
    if (avctx->channels > 2)
118
 
        return -1; /* only stereo or mono =) */
119
 
    avctx->frame_size = 32;
120
 
 
121
 
    avctx->coded_frame= avcodec_alloc_frame();
122
 
    avctx->coded_frame->key_frame= 1;
123
 
 
124
 
//    avctx->bit_rate = avctx->sample_rate*avctx->channels*18*8/32;
125
 
 
126
 
    av_log(avctx, AV_LOG_DEBUG, "adx encode init\n");
 
114
    ADXContext *c = avctx->priv_data;
 
115
 
 
116
    if (avctx->channels > 2) {
 
117
        av_log(avctx, AV_LOG_ERROR, "Invalid number of channels\n");
 
118
        return AVERROR(EINVAL);
 
119
    }
 
120
    avctx->frame_size = BLOCK_SAMPLES;
 
121
 
 
122
    avctx->coded_frame = avcodec_alloc_frame();
 
123
 
 
124
    /* the cutoff can be adjusted, but this seems to work pretty well */
 
125
    c->cutoff = 500;
 
126
    ff_adx_calculate_coeffs(c->cutoff, avctx->sample_rate, COEFF_BITS, c->coeff);
127
127
 
128
128
    return 0;
129
129
}
131
131
static av_cold int adx_encode_close(AVCodecContext *avctx)
132
132
{
133
133
    av_freep(&avctx->coded_frame);
134
 
 
135
134
    return 0;
136
135
}
137
136
 
138
 
static int adx_encode_frame(AVCodecContext *avctx,
139
 
                uint8_t *frame, int buf_size, void *data)
 
137
static int adx_encode_frame(AVCodecContext *avctx, uint8_t *frame,
 
138
                            int buf_size, void *data)
140
139
{
141
 
    ADXContext *c = avctx->priv_data;
142
 
    const short *samples = data;
143
 
    unsigned char *dst = frame;
144
 
    int rest = avctx->frame_size;
145
 
 
146
 
/*
147
 
    input data size =
148
 
    ffmpeg.c: do_audio_out()
149
 
    frame_bytes = enc->frame_size * 2 * enc->channels;
150
 
*/
151
 
 
152
 
//    printf("sz=%d ",buf_size); fflush(stdout);
 
140
    ADXContext *c          = avctx->priv_data;
 
141
    const int16_t *samples = data;
 
142
    uint8_t *dst           = frame;
 
143
    int ch;
 
144
 
153
145
    if (!c->header_parsed) {
154
 
        int hdrsize = adx_encode_header(avctx,dst,buf_size);
155
 
        dst+=hdrsize;
 
146
        int hdrsize;
 
147
        if ((hdrsize = adx_encode_header(avctx, dst, buf_size)) < 0) {
 
148
            av_log(avctx, AV_LOG_ERROR, "output buffer is too small\n");
 
149
            return AVERROR(EINVAL);
 
150
        }
 
151
        dst      += hdrsize;
 
152
        buf_size -= hdrsize;
156
153
        c->header_parsed = 1;
157
154
    }
158
 
 
159
 
    if (avctx->channels==1) {
160
 
        while(rest>=32) {
161
 
            adx_encode(dst,samples,c->prev);
162
 
            dst+=18;
163
 
            samples+=32;
164
 
            rest-=32;
165
 
        }
166
 
    } else {
167
 
        while(rest>=32*2) {
168
 
            short tmpbuf[32*2];
169
 
            int i;
170
 
 
171
 
            for(i=0;i<32;i++) {
172
 
                tmpbuf[i] = samples[i*2];
173
 
                tmpbuf[i+32] = samples[i*2+1];
174
 
            }
175
 
 
176
 
            adx_encode(dst,tmpbuf,c->prev);
177
 
            adx_encode(dst+18,tmpbuf+32,c->prev+1);
178
 
            dst+=18*2;
179
 
            samples+=32*2;
180
 
            rest-=32*2;
181
 
        }
182
 
    }
183
 
    return dst-frame;
 
155
    if (buf_size < BLOCK_SIZE * avctx->channels) {
 
156
        av_log(avctx, AV_LOG_ERROR, "output buffer is too small\n");
 
157
        return AVERROR(EINVAL);
 
158
    }
 
159
 
 
160
    for (ch = 0; ch < avctx->channels; ch++) {
 
161
        adx_encode(c, dst, samples + ch, &c->prev[ch], avctx->channels);
 
162
        dst += BLOCK_SIZE;
 
163
    }
 
164
    return dst - frame;
184
165
}
185
166
 
186
167
AVCodec ff_adpcm_adx_encoder = {
187
 
    "adpcm_adx",
188
 
    AVMEDIA_TYPE_AUDIO,
189
 
    CODEC_ID_ADPCM_ADX,
190
 
    sizeof(ADXContext),
191
 
    adx_encode_init,
192
 
    adx_encode_frame,
193
 
    adx_encode_close,
194
 
    NULL,
195
 
    .sample_fmts = (const enum AVSampleFormat[]){AV_SAMPLE_FMT_S16,AV_SAMPLE_FMT_NONE},
196
 
    .long_name = NULL_IF_CONFIG_SMALL("SEGA CRI ADX ADPCM"),
 
168
    .name           = "adpcm_adx",
 
169
    .type           = AVMEDIA_TYPE_AUDIO,
 
170
    .id             = CODEC_ID_ADPCM_ADX,
 
171
    .priv_data_size = sizeof(ADXContext),
 
172
    .init           = adx_encode_init,
 
173
    .encode         = adx_encode_frame,
 
174
    .close          = adx_encode_close,
 
175
    .sample_fmts    = (const enum AVSampleFormat[]) { AV_SAMPLE_FMT_S16,
 
176
                                                      AV_SAMPLE_FMT_NONE },
 
177
    .long_name      = NULL_IF_CONFIG_SMALL("SEGA CRI ADX ADPCM"),
197
178
};