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

« back to all changes in this revision

Viewing changes to gst-libs/ext/libav/libavcodec/libvo-amrwbenc.c

  • Committer: Package Import Robot
  • Author(s): Sebastian Dröge
  • Date: 2013-07-30 09:00:15 UTC
  • mfrom: (1.1.16) (7.1.7 experimental)
  • Revision ID: package-import@ubuntu.com-20130730090015-sc1ou2yssu7q5w4e
Tags: 1.1.3-1
* New upstream development snapshot:
  + debian/control:
    - Build depend on GStreamer and gst-plugins-base >= 1.1.3.

Show diffs side-by-side

added added

removed removed

Lines of Context:
20
20
 */
21
21
 
22
22
#include <vo-amrwbenc/enc_if.h>
 
23
#include <stdio.h>
 
24
#include <stdlib.h>
23
25
 
24
 
#include "avcodec.h"
25
26
#include "libavutil/avstring.h"
 
27
#include "libavutil/internal.h"
 
28
#include "libavutil/mem.h"
26
29
#include "libavutil/opt.h"
 
30
#include "avcodec.h"
 
31
#include "internal.h"
 
32
 
 
33
#define MAX_PACKET_SIZE  (1 + (477 + 7) / 8)
27
34
 
28
35
typedef struct AMRWBContext {
29
36
    AVClass *av_class;
34
41
} AMRWBContext;
35
42
 
36
43
static const AVOption options[] = {
37
 
    { "dtx", "Allow DTX (generate comfort noise)", offsetof(AMRWBContext, allow_dtx), AV_OPT_TYPE_INT, { 0 }, 0, 1, AV_OPT_FLAG_AUDIO_PARAM | AV_OPT_FLAG_ENCODING_PARAM },
 
44
    { "dtx", "Allow DTX (generate comfort noise)", offsetof(AMRWBContext, allow_dtx), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 1, AV_OPT_FLAG_AUDIO_PARAM | AV_OPT_FLAG_ENCODING_PARAM },
38
45
    { NULL }
39
46
};
40
47
 
86
93
    s->last_bitrate    = avctx->bit_rate;
87
94
 
88
95
    avctx->frame_size  = 320;
 
96
    avctx->delay       =  80;
 
97
#if FF_API_OLD_ENCODE_AUDIO
89
98
    avctx->coded_frame = avcodec_alloc_frame();
 
99
    if (!avctx->coded_frame)
 
100
        return AVERROR(ENOMEM);
 
101
#endif
90
102
 
91
103
    s->state     = E_IF_init();
92
104
 
102
114
    return 0;
103
115
}
104
116
 
105
 
static int amr_wb_encode_frame(AVCodecContext *avctx,
106
 
                               unsigned char *frame/*out*/,
107
 
                               int buf_size, void *data/*in*/)
 
117
static int amr_wb_encode_frame(AVCodecContext *avctx, AVPacket *avpkt,
 
118
                               const AVFrame *frame, int *got_packet_ptr)
108
119
{
109
120
    AMRWBContext *s = avctx->priv_data;
110
 
    int size;
 
121
    const int16_t *samples = (const int16_t *)frame->data[0];
 
122
    int size, ret;
 
123
 
 
124
    if ((ret = ff_alloc_packet(avpkt, MAX_PACKET_SIZE))) {
 
125
        av_log(avctx, AV_LOG_ERROR, "Error getting output packet\n");
 
126
        return ret;
 
127
    }
111
128
 
112
129
    if (s->last_bitrate != avctx->bit_rate) {
113
130
        s->mode         = get_wb_bitrate_mode(avctx->bit_rate, avctx);
114
131
        s->last_bitrate = avctx->bit_rate;
115
132
    }
116
 
    size = E_IF_encode(s->state, s->mode, data, frame, s->allow_dtx);
117
 
    return size;
 
133
    size = E_IF_encode(s->state, s->mode, samples, avpkt->data, s->allow_dtx);
 
134
    if (size <= 0 || size > MAX_PACKET_SIZE) {
 
135
        av_log(avctx, AV_LOG_ERROR, "Error encoding frame\n");
 
136
        return AVERROR(EINVAL);
 
137
    }
 
138
 
 
139
    if (frame->pts != AV_NOPTS_VALUE)
 
140
        avpkt->pts = frame->pts - ff_samples_to_time_base(avctx, avctx->delay);
 
141
 
 
142
    avpkt->size = size;
 
143
    *got_packet_ptr = 1;
 
144
    return 0;
118
145
}
119
146
 
120
147
AVCodec ff_libvo_amrwbenc_encoder = {
121
148
    .name           = "libvo_amrwbenc",
122
149
    .type           = AVMEDIA_TYPE_AUDIO,
123
 
    .id             = CODEC_ID_AMR_WB,
 
150
    .id             = AV_CODEC_ID_AMR_WB,
124
151
    .priv_data_size = sizeof(AMRWBContext),
125
152
    .init           = amr_wb_encode_init,
126
 
    .encode         = amr_wb_encode_frame,
 
153
    .encode2        = amr_wb_encode_frame,
127
154
    .close          = amr_wb_encode_close,
128
 
    .sample_fmts = (const enum AVSampleFormat[]){AV_SAMPLE_FMT_S16,AV_SAMPLE_FMT_NONE},
129
 
    .long_name = NULL_IF_CONFIG_SMALL("Android VisualOn Adaptive Multi-Rate "
130
 
                                      "(AMR) Wide-Band"),
131
 
    .priv_class = &class,
 
155
    .sample_fmts    = (const enum AVSampleFormat[]){ AV_SAMPLE_FMT_S16,
 
156
                                                     AV_SAMPLE_FMT_NONE },
 
157
    .long_name      = NULL_IF_CONFIG_SMALL("Android VisualOn AMR-WB "
 
158
                                           "(Adaptive Multi-Rate Wide-Band)"),
 
159
    .priv_class     = &class,
132
160
};
133