mirror of https://github.com/FFmpeg/FFmpeg.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
138 lines
4.4 KiB
138 lines
4.4 KiB
20 years ago
|
/*
|
||
11 years ago
|
* Interface to libgsm for GSM encoding
|
||
20 years ago
|
* Copyright (c) 2005 Alban Bedel <albeu@free.fr>
|
||
18 years ago
|
* Copyright (c) 2006, 2007 Michel Bardiaux <mbardiaux@mediaxim.be>
|
||
20 years ago
|
*
|
||
14 years ago
|
* This file is part of Libav.
|
||
18 years ago
|
*
|
||
14 years ago
|
* Libav is free software; you can redistribute it and/or
|
||
20 years ago
|
* modify it under the terms of the GNU Lesser General Public
|
||
|
* License as published by the Free Software Foundation; either
|
||
18 years ago
|
* version 2.1 of the License, or (at your option) any later version.
|
||
20 years ago
|
*
|
||
14 years ago
|
* Libav is distributed in the hope that it will be useful,
|
||
20 years ago
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||
|
* Lesser General Public License for more details.
|
||
|
*
|
||
|
* You should have received a copy of the GNU Lesser General Public
|
||
14 years ago
|
* License along with Libav; if not, write to the Free Software
|
||
19 years ago
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||
20 years ago
|
*/
|
||
19 years ago
|
|
||
20 years ago
|
/**
|
||
15 years ago
|
* @file
|
||
11 years ago
|
* Interface to libgsm for GSM encoding
|
||
20 years ago
|
*/
|
||
|
|
||
18 years ago
|
// The idiosyncrasies of GSM-in-WAV are explained at http://kbs.cs.tu-berlin.de/~jutta/toast.html
|
||
|
|
||
12 years ago
|
#include "config.h"
|
||
|
#if HAVE_GSM_H
|
||
|
#include <gsm.h>
|
||
|
#else
|
||
15 years ago
|
#include <gsm/gsm.h>
|
||
12 years ago
|
#endif
|
||
20 years ago
|
|
||
12 years ago
|
#include "libavutil/common.h"
|
||
11 years ago
|
|
||
13 years ago
|
#include "avcodec.h"
|
||
13 years ago
|
#include "internal.h"
|
||
13 years ago
|
#include "gsm.h"
|
||
20 years ago
|
|
||
13 years ago
|
static av_cold int libgsm_encode_init(AVCodecContext *avctx) {
|
||
17 years ago
|
if (avctx->channels > 1) {
|
||
|
av_log(avctx, AV_LOG_ERROR, "Mono required for GSM, got %d channels\n",
|
||
|
avctx->channels);
|
||
20 years ago
|
return -1;
|
||
17 years ago
|
}
|
||
17 years ago
|
|
||
13 years ago
|
if (avctx->sample_rate != 8000) {
|
||
|
av_log(avctx, AV_LOG_ERROR, "Sample rate 8000Hz required for GSM, got %dHz\n",
|
||
|
avctx->sample_rate);
|
||
|
if (avctx->strict_std_compliance > FF_COMPLIANCE_UNOFFICIAL)
|
||
|
return -1;
|
||
|
}
|
||
|
if (avctx->bit_rate != 13000 /* Official */ &&
|
||
|
avctx->bit_rate != 13200 /* Very common */ &&
|
||
|
avctx->bit_rate != 0 /* Unknown; a.o. mov does not set bitrate when decoding */ ) {
|
||
|
av_log(avctx, AV_LOG_ERROR, "Bitrate 13000bps required for GSM, got %dbps\n",
|
||
|
avctx->bit_rate);
|
||
|
if (avctx->strict_std_compliance > FF_COMPLIANCE_UNOFFICIAL)
|
||
|
return -1;
|
||
|
}
|
||
20 years ago
|
|
||
|
avctx->priv_data = gsm_create();
|
||
19 years ago
|
|
||
18 years ago
|
switch(avctx->codec_id) {
|
||
12 years ago
|
case AV_CODEC_ID_GSM:
|
||
18 years ago
|
avctx->frame_size = GSM_FRAME_SIZE;
|
||
|
avctx->block_align = GSM_BLOCK_SIZE;
|
||
|
break;
|
||
12 years ago
|
case AV_CODEC_ID_GSM_MS: {
|
||
18 years ago
|
int one = 1;
|
||
|
gsm_option(avctx->priv_data, GSM_OPT_WAV49, &one);
|
||
|
avctx->frame_size = 2*GSM_FRAME_SIZE;
|
||
|
avctx->block_align = GSM_MS_BLOCK_SIZE;
|
||
|
}
|
||
|
}
|
||
|
|
||
20 years ago
|
return 0;
|
||
|
}
|
||
|
|
||
13 years ago
|
static av_cold int libgsm_encode_close(AVCodecContext *avctx) {
|
||
20 years ago
|
gsm_destroy(avctx->priv_data);
|
||
|
avctx->priv_data = NULL;
|
||
|
return 0;
|
||
|
}
|
||
|
|
||
13 years ago
|
static int libgsm_encode_frame(AVCodecContext *avctx, AVPacket *avpkt,
|
||
|
const AVFrame *frame, int *got_packet_ptr)
|
||
|
{
|
||
|
int ret;
|
||
|
gsm_signal *samples = (gsm_signal *)frame->data[0];
|
||
|
struct gsm_state *state = avctx->priv_data;
|
||
|
|
||
|
if ((ret = ff_alloc_packet(avpkt, avctx->block_align))) {
|
||
|
av_log(avctx, AV_LOG_ERROR, "Error getting output packet\n");
|
||
|
return ret;
|
||
|
}
|
||
18 years ago
|
|
||
|
switch(avctx->codec_id) {
|
||
12 years ago
|
case AV_CODEC_ID_GSM:
|
||
13 years ago
|
gsm_encode(state, samples, avpkt->data);
|
||
18 years ago
|
break;
|
||
12 years ago
|
case AV_CODEC_ID_GSM_MS:
|
||
13 years ago
|
gsm_encode(state, samples, avpkt->data);
|
||
|
gsm_encode(state, samples + GSM_FRAME_SIZE, avpkt->data + 32);
|
||
18 years ago
|
}
|
||
13 years ago
|
|
||
|
*got_packet_ptr = 1;
|
||
|
return 0;
|
||
20 years ago
|
}
|
||
|
|
||
|
|
||
14 years ago
|
AVCodec ff_libgsm_encoder = {
|
||
14 years ago
|
.name = "libgsm",
|
||
11 years ago
|
.long_name = NULL_IF_CONFIG_SMALL("libgsm GSM"),
|
||
14 years ago
|
.type = AVMEDIA_TYPE_AUDIO,
|
||
12 years ago
|
.id = AV_CODEC_ID_GSM,
|
||
13 years ago
|
.init = libgsm_encode_init,
|
||
13 years ago
|
.encode2 = libgsm_encode_frame,
|
||
13 years ago
|
.close = libgsm_encode_close,
|
||
13 years ago
|
.sample_fmts = (const enum AVSampleFormat[]){ AV_SAMPLE_FMT_S16,
|
||
|
AV_SAMPLE_FMT_NONE },
|
||
20 years ago
|
};
|
||
|
|
||
14 years ago
|
AVCodec ff_libgsm_ms_encoder = {
|
||
14 years ago
|
.name = "libgsm_ms",
|
||
11 years ago
|
.long_name = NULL_IF_CONFIG_SMALL("libgsm GSM Microsoft variant"),
|
||
14 years ago
|
.type = AVMEDIA_TYPE_AUDIO,
|
||
12 years ago
|
.id = AV_CODEC_ID_GSM_MS,
|
||
13 years ago
|
.init = libgsm_encode_init,
|
||
13 years ago
|
.encode2 = libgsm_encode_frame,
|
||
13 years ago
|
.close = libgsm_encode_close,
|
||
13 years ago
|
.sample_fmts = (const enum AVSampleFormat[]){ AV_SAMPLE_FMT_S16,
|
||
|
AV_SAMPLE_FMT_NONE },
|
||
18 years ago
|
};
|