~ubuntu-branches/ubuntu/trusty/gst-libav1.0/trusty-proposed

« back to all changes in this revision

Viewing changes to gst-libs/ext/libav/libavcodec/8svx.c

  • Committer: Package Import Robot
  • Author(s): Sebastian Dröge
  • Date: 2013-09-24 17:07:00 UTC
  • mfrom: (1.1.17) (7.1.9 experimental)
  • Revision ID: package-import@ubuntu.com-20130924170700-4dg62s3pwl0pdakz
Tags: 1.2.0-1
* New upstream stable release:
  + debian/control:
    - Build depend on GStreamer and gst-plugins-base >= 1.2.0.

Show diffs side-by-side

added added

removed removed

Lines of Context:
29
29
 */
30
30
 
31
31
#include "avcodec.h"
 
32
#include "internal.h"
 
33
#include "libavutil/common.h"
32
34
 
33
35
/** decoder context */
34
36
typedef struct EightSvxContext {
57
59
 * @param[in,out] state starting value. it is saved for use in the next call.
58
60
 */
59
61
static void delta_decode(uint8_t *dst, const uint8_t *src, int src_size,
60
 
                         uint8_t *state, const int8_t *table, int channels)
 
62
                         uint8_t *state, const int8_t *table)
61
63
{
62
64
    uint8_t val = *state;
63
65
 
64
66
    while (src_size--) {
65
67
        uint8_t d = *src++;
66
68
        val = av_clip_uint8(val + table[d & 0xF]);
67
 
        *dst = val;
68
 
        dst += channels;
 
69
        *dst++ = val;
69
70
        val = av_clip_uint8(val + table[d >> 4]);
70
 
        *dst = val;
71
 
        dst += channels;
 
71
        *dst++ = val;
72
72
    }
73
73
 
74
74
    *state = val;
75
75
}
76
76
 
77
 
static void raw_decode(uint8_t *dst, const int8_t *src, int src_size,
78
 
                       int channels)
 
77
static void raw_decode(uint8_t *dst, const int8_t *src, int src_size)
79
78
{
80
 
    while (src_size--) {
81
 
        *dst = *src++ + 128;
82
 
        dst += channels;
83
 
    }
 
79
    while (src_size--)
 
80
        *dst++ = *src++ + 128;
84
81
}
85
82
 
86
83
/** decode a frame */
89
86
{
90
87
    EightSvxContext *esc = avctx->priv_data;
91
88
    int buf_size;
92
 
    uint8_t *out_data;
93
 
    int ret;
94
 
    int is_compr = (avctx->codec_id != CODEC_ID_PCM_S8_PLANAR);
 
89
    int ch, ret;
 
90
    int is_compr = (avctx->codec_id != AV_CODEC_ID_PCM_S8_PLANAR);
95
91
 
96
92
    /* for the first packet, copy data to buffer */
97
93
    if (avpkt->data) {
141
137
 
142
138
    /* get output buffer */
143
139
    esc->frame.nb_samples = buf_size * (is_compr + 1);
144
 
    if ((ret = avctx->get_buffer(avctx, &esc->frame)) < 0) {
 
140
    if ((ret = ff_get_buffer(avctx, &esc->frame)) < 0) {
145
141
        av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n");
146
142
        return ret;
147
143
    }
148
 
    out_data = esc->frame.data[0];
149
144
 
150
 
    if (is_compr) {
151
 
    delta_decode(out_data, &esc->data[0][esc->data_idx], buf_size,
152
 
                 &esc->fib_acc[0], esc->table, avctx->channels);
153
 
    if (avctx->channels == 2) {
154
 
        delta_decode(&out_data[1], &esc->data[1][esc->data_idx], buf_size,
155
 
                    &esc->fib_acc[1], esc->table, avctx->channels);
156
 
    }
157
 
    } else {
158
 
        int ch;
159
 
        for (ch = 0; ch < avctx->channels; ch++) {
160
 
            raw_decode((int8_t *)&out_data[ch], &esc->data[ch][esc->data_idx],
161
 
                       buf_size, avctx->channels);
 
145
    for (ch = 0; ch < avctx->channels; ch++) {
 
146
        if (is_compr) {
 
147
            delta_decode(esc->frame.data[ch], &esc->data[ch][esc->data_idx],
 
148
                         buf_size, &esc->fib_acc[ch], esc->table);
 
149
        } else {
 
150
            raw_decode(esc->frame.data[ch], &esc->data[ch][esc->data_idx],
 
151
                       buf_size);
162
152
        }
163
153
    }
 
154
 
164
155
    esc->data_idx += buf_size;
165
156
 
166
157
    *got_frame_ptr   = 1;
180
171
    }
181
172
 
182
173
    switch(avctx->codec->id) {
183
 
        case CODEC_ID_8SVX_FIB:
 
174
        case AV_CODEC_ID_8SVX_FIB:
184
175
          esc->table = fibonacci;
185
176
          break;
186
 
        case CODEC_ID_8SVX_EXP:
 
177
        case AV_CODEC_ID_8SVX_EXP:
187
178
          esc->table = exponential;
188
179
          break;
189
 
        case CODEC_ID_PCM_S8_PLANAR:
 
180
        case AV_CODEC_ID_PCM_S8_PLANAR:
190
181
            break;
191
182
        default:
192
183
          return -1;
193
184
    }
194
 
    avctx->sample_fmt = AV_SAMPLE_FMT_U8;
 
185
    avctx->sample_fmt = AV_SAMPLE_FMT_U8P;
195
186
 
196
187
    avcodec_get_frame_defaults(&esc->frame);
197
188
    avctx->coded_frame = &esc->frame;
212
203
AVCodec ff_eightsvx_fib_decoder = {
213
204
  .name           = "8svx_fib",
214
205
  .type           = AVMEDIA_TYPE_AUDIO,
215
 
  .id             = CODEC_ID_8SVX_FIB,
 
206
  .id             = AV_CODEC_ID_8SVX_FIB,
216
207
  .priv_data_size = sizeof (EightSvxContext),
217
208
  .init           = eightsvx_decode_init,
218
209
  .close          = eightsvx_decode_close,
219
210
  .decode         = eightsvx_decode_frame,
220
211
  .capabilities   = CODEC_CAP_DELAY | CODEC_CAP_DR1,
221
212
  .long_name      = NULL_IF_CONFIG_SMALL("8SVX fibonacci"),
 
213
  .sample_fmts    = (const enum AVSampleFormat[]) { AV_SAMPLE_FMT_U8P,
 
214
                                                    AV_SAMPLE_FMT_NONE },
222
215
};
223
216
 
224
217
AVCodec ff_eightsvx_exp_decoder = {
225
218
  .name           = "8svx_exp",
226
219
  .type           = AVMEDIA_TYPE_AUDIO,
227
 
  .id             = CODEC_ID_8SVX_EXP,
 
220
  .id             = AV_CODEC_ID_8SVX_EXP,
228
221
  .priv_data_size = sizeof (EightSvxContext),
229
222
  .init           = eightsvx_decode_init,
230
223
  .close          = eightsvx_decode_close,
231
224
  .decode         = eightsvx_decode_frame,
232
225
  .capabilities   = CODEC_CAP_DELAY | CODEC_CAP_DR1,
233
226
  .long_name      = NULL_IF_CONFIG_SMALL("8SVX exponential"),
 
227
  .sample_fmts    = (const enum AVSampleFormat[]) { AV_SAMPLE_FMT_U8P,
 
228
                                                    AV_SAMPLE_FMT_NONE },
234
229
};
235
230
 
236
231
AVCodec ff_pcm_s8_planar_decoder = {
237
232
    .name           = "pcm_s8_planar",
238
233
    .type           = AVMEDIA_TYPE_AUDIO,
239
 
    .id             = CODEC_ID_PCM_S8_PLANAR,
 
234
    .id             = AV_CODEC_ID_PCM_S8_PLANAR,
240
235
    .priv_data_size = sizeof(EightSvxContext),
241
236
    .init           = eightsvx_decode_init,
242
237
    .close          = eightsvx_decode_close,
243
238
    .decode         = eightsvx_decode_frame,
244
239
    .capabilities   = CODEC_CAP_DELAY | CODEC_CAP_DR1,
245
240
    .long_name      = NULL_IF_CONFIG_SMALL("PCM signed 8-bit planar"),
 
241
    .sample_fmts    = (const enum AVSampleFormat[]) { AV_SAMPLE_FMT_U8P,
 
242
                                                      AV_SAMPLE_FMT_NONE },
246
243
};