~ubuntu-branches/ubuntu/trusty/libav/trusty-proposed

« back to all changes in this revision

Viewing changes to libavcodec/libgsm.c

  • Committer: Package Import Robot
  • Author(s): Reinhard Tartler
  • Date: 2013-10-22 23:24:08 UTC
  • mfrom: (1.3.36 sid)
  • Revision ID: package-import@ubuntu.com-20131022232408-b8tvvn4pyzri9mi3
Tags: 6:9.10-1ubuntu1
* Build all -extra flavors from this source package, as libav got demoted
  from main to universe, cf LP: #1243235
* Simplify debian/rules to follow exactly the code that debian executes
* New upstream (LP: #1180288) fixes lots of security issues (LP: #1242802)
* Merge from unstable, remaining changes:
  - build-depend on libtiff5-dev rather than libtiff4-dev,
    avoids FTBFS caused by imlib
  - follow the regular debian codepaths

Show diffs side-by-side

added added

removed removed

Lines of Context:
29
29
 
30
30
#include <gsm/gsm.h>
31
31
 
 
32
#include "libavutil/channel_layout.h"
 
33
#include "libavutil/common.h"
32
34
#include "avcodec.h"
 
35
#include "internal.h"
33
36
#include "gsm.h"
34
37
 
35
38
static av_cold int libgsm_encode_init(AVCodecContext *avctx) {
57
60
    avctx->priv_data = gsm_create();
58
61
 
59
62
    switch(avctx->codec_id) {
60
 
    case CODEC_ID_GSM:
 
63
    case AV_CODEC_ID_GSM:
61
64
        avctx->frame_size = GSM_FRAME_SIZE;
62
65
        avctx->block_align = GSM_BLOCK_SIZE;
63
66
        break;
64
 
    case CODEC_ID_GSM_MS: {
 
67
    case AV_CODEC_ID_GSM_MS: {
65
68
        int one = 1;
66
69
        gsm_option(avctx->priv_data, GSM_OPT_WAV49, &one);
67
70
        avctx->frame_size = 2*GSM_FRAME_SIZE;
69
72
        }
70
73
    }
71
74
 
 
75
#if FF_API_OLD_ENCODE_AUDIO
72
76
    avctx->coded_frame= avcodec_alloc_frame();
73
 
    avctx->coded_frame->key_frame= 1;
 
77
    if (!avctx->coded_frame) {
 
78
        gsm_destroy(avctx->priv_data);
 
79
        return AVERROR(ENOMEM);
 
80
    }
 
81
#endif
74
82
 
75
83
    return 0;
76
84
}
77
85
 
78
86
static av_cold int libgsm_encode_close(AVCodecContext *avctx) {
 
87
#if FF_API_OLD_ENCODE_AUDIO
79
88
    av_freep(&avctx->coded_frame);
 
89
#endif
80
90
    gsm_destroy(avctx->priv_data);
81
91
    avctx->priv_data = NULL;
82
92
    return 0;
83
93
}
84
94
 
85
 
static int libgsm_encode_frame(AVCodecContext *avctx,
86
 
                               unsigned char *frame, int buf_size, void *data) {
87
 
    // we need a full block
88
 
    if(buf_size < avctx->block_align) return 0;
 
95
static int libgsm_encode_frame(AVCodecContext *avctx, AVPacket *avpkt,
 
96
                               const AVFrame *frame, int *got_packet_ptr)
 
97
{
 
98
    int ret;
 
99
    gsm_signal *samples = (gsm_signal *)frame->data[0];
 
100
    struct gsm_state *state = avctx->priv_data;
 
101
 
 
102
    if ((ret = ff_alloc_packet(avpkt, avctx->block_align))) {
 
103
        av_log(avctx, AV_LOG_ERROR, "Error getting output packet\n");
 
104
        return ret;
 
105
    }
89
106
 
90
107
    switch(avctx->codec_id) {
91
 
    case CODEC_ID_GSM:
92
 
        gsm_encode(avctx->priv_data,data,frame);
 
108
    case AV_CODEC_ID_GSM:
 
109
        gsm_encode(state, samples, avpkt->data);
93
110
        break;
94
 
    case CODEC_ID_GSM_MS:
95
 
        gsm_encode(avctx->priv_data,data,frame);
96
 
        gsm_encode(avctx->priv_data,((short*)data)+GSM_FRAME_SIZE,frame+32);
 
111
    case AV_CODEC_ID_GSM_MS:
 
112
        gsm_encode(state, samples,                  avpkt->data);
 
113
        gsm_encode(state, samples + GSM_FRAME_SIZE, avpkt->data + 32);
97
114
    }
98
 
    return avctx->block_align;
 
115
 
 
116
    *got_packet_ptr = 1;
 
117
    return 0;
99
118
}
100
119
 
101
120
 
102
121
AVCodec ff_libgsm_encoder = {
103
122
    .name           = "libgsm",
104
123
    .type           = AVMEDIA_TYPE_AUDIO,
105
 
    .id             = CODEC_ID_GSM,
 
124
    .id             = AV_CODEC_ID_GSM,
106
125
    .init           = libgsm_encode_init,
107
 
    .encode         = libgsm_encode_frame,
 
126
    .encode2        = libgsm_encode_frame,
108
127
    .close          = libgsm_encode_close,
109
 
    .sample_fmts = (const enum AVSampleFormat[]){AV_SAMPLE_FMT_S16,AV_SAMPLE_FMT_NONE},
110
 
    .long_name = NULL_IF_CONFIG_SMALL("libgsm GSM"),
 
128
    .sample_fmts    = (const enum AVSampleFormat[]){ AV_SAMPLE_FMT_S16,
 
129
                                                     AV_SAMPLE_FMT_NONE },
 
130
    .long_name      = NULL_IF_CONFIG_SMALL("libgsm GSM"),
111
131
};
112
132
 
113
133
AVCodec ff_libgsm_ms_encoder = {
114
134
    .name           = "libgsm_ms",
115
135
    .type           = AVMEDIA_TYPE_AUDIO,
116
 
    .id             = CODEC_ID_GSM_MS,
 
136
    .id             = AV_CODEC_ID_GSM_MS,
117
137
    .init           = libgsm_encode_init,
118
 
    .encode         = libgsm_encode_frame,
 
138
    .encode2        = libgsm_encode_frame,
119
139
    .close          = libgsm_encode_close,
120
 
    .sample_fmts = (const enum AVSampleFormat[]){AV_SAMPLE_FMT_S16,AV_SAMPLE_FMT_NONE},
121
 
    .long_name = NULL_IF_CONFIG_SMALL("libgsm GSM Microsoft variant"),
 
140
    .sample_fmts    = (const enum AVSampleFormat[]){ AV_SAMPLE_FMT_S16,
 
141
                                                     AV_SAMPLE_FMT_NONE },
 
142
    .long_name      = NULL_IF_CONFIG_SMALL("libgsm GSM Microsoft variant"),
122
143
};
123
144
 
124
145
typedef struct LibGSMDecodeContext {
129
150
static av_cold int libgsm_decode_init(AVCodecContext *avctx) {
130
151
    LibGSMDecodeContext *s = avctx->priv_data;
131
152
 
132
 
    if (avctx->channels > 1) {
133
 
        av_log(avctx, AV_LOG_ERROR, "Mono required for GSM, got %d channels\n",
134
 
               avctx->channels);
135
 
        return -1;
136
 
    }
137
 
 
138
 
    if (!avctx->channels)
139
 
        avctx->channels = 1;
140
 
 
141
 
    if (!avctx->sample_rate)
142
 
        avctx->sample_rate = 8000;
143
 
 
144
 
    avctx->sample_fmt = AV_SAMPLE_FMT_S16;
 
153
    avctx->channels       = 1;
 
154
    avctx->channel_layout = AV_CH_LAYOUT_MONO;
 
155
    avctx->sample_rate    = 8000;
 
156
    avctx->sample_fmt     = AV_SAMPLE_FMT_S16;
145
157
 
146
158
    s->state = gsm_create();
147
159
 
148
160
    switch(avctx->codec_id) {
149
 
    case CODEC_ID_GSM:
 
161
    case AV_CODEC_ID_GSM:
150
162
        avctx->frame_size  = GSM_FRAME_SIZE;
151
163
        avctx->block_align = GSM_BLOCK_SIZE;
152
164
        break;
153
 
    case CODEC_ID_GSM_MS: {
 
165
    case AV_CODEC_ID_GSM_MS: {
154
166
        int one = 1;
155
167
        gsm_option(s->state, GSM_OPT_WAV49, &one);
156
168
        avctx->frame_size  = 2 * GSM_FRAME_SIZE;
188
200
 
189
201
    /* get output buffer */
190
202
    s->frame.nb_samples = avctx->frame_size;
191
 
    if ((ret = avctx->get_buffer(avctx, &s->frame)) < 0) {
 
203
    if ((ret = ff_get_buffer(avctx, &s->frame)) < 0) {
192
204
        av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n");
193
205
        return ret;
194
206
    }
213
225
 
214
226
    gsm_destroy(s->state);
215
227
    s->state = gsm_create();
216
 
    if (avctx->codec_id == CODEC_ID_GSM_MS)
 
228
    if (avctx->codec_id == AV_CODEC_ID_GSM_MS)
217
229
        gsm_option(s->state, GSM_OPT_WAV49, &one);
218
230
}
219
231
 
220
232
AVCodec ff_libgsm_decoder = {
221
233
    .name           = "libgsm",
222
234
    .type           = AVMEDIA_TYPE_AUDIO,
223
 
    .id             = CODEC_ID_GSM,
 
235
    .id             = AV_CODEC_ID_GSM,
224
236
    .priv_data_size = sizeof(LibGSMDecodeContext),
225
237
    .init           = libgsm_decode_init,
226
238
    .close          = libgsm_decode_close,
227
239
    .decode         = libgsm_decode_frame,
228
240
    .flush          = libgsm_flush,
229
241
    .capabilities   = CODEC_CAP_DR1,
230
 
    .long_name = NULL_IF_CONFIG_SMALL("libgsm GSM"),
 
242
    .long_name      = NULL_IF_CONFIG_SMALL("libgsm GSM"),
231
243
};
232
244
 
233
245
AVCodec ff_libgsm_ms_decoder = {
234
246
    .name           = "libgsm_ms",
235
247
    .type           = AVMEDIA_TYPE_AUDIO,
236
 
    .id             = CODEC_ID_GSM_MS,
 
248
    .id             = AV_CODEC_ID_GSM_MS,
237
249
    .priv_data_size = sizeof(LibGSMDecodeContext),
238
250
    .init           = libgsm_decode_init,
239
251
    .close          = libgsm_decode_close,
240
252
    .decode         = libgsm_decode_frame,
241
253
    .flush          = libgsm_flush,
242
254
    .capabilities   = CODEC_CAP_DR1,
243
 
    .long_name = NULL_IF_CONFIG_SMALL("libgsm GSM Microsoft variant"),
 
255
    .long_name      = NULL_IF_CONFIG_SMALL("libgsm GSM Microsoft variant"),
244
256
};