ALT Linux repos
S: | 1.5-alt1.38416.2 |
D: | 1.0-alt35.27330.1 |
5.0: | 1.0-alt35.27654.3 |
4.1: | 1.0-alt35.26470.1 |
4.0: | 1.0-alt35.23722.M40.1 |
Group :: Video
RPM: mplayer
Main Changelog Spec Patches Sources Download Gear Bugs and FR Repocop
Patch: ffmpeg-svn-r14967-amr.patch
Download
Download
diff -urN ffmpeg-svn-r14967.orig/libavcodec/libamr.c ffmpeg-svn-r14967/libavcodec/libamr.c
--- ffmpeg-svn-r14967.orig/libavcodec/libamr.c 2008-08-25 22:37:27 +0300
+++ ffmpeg-svn-r14967/libavcodec/libamr.c 2008-08-26 00:49:17 +0300
@@ -65,6 +65,25 @@
#include "avcodec.h"
+#if defined(CONFIG_LIBAMRNBBIN) || defined(CONFIG_LIBAMRWBBIN)
+#include <dlfcn.h>
+static void* dlsymm(void* handle, char type, const char* symbol)
+{
+ void* f = dlsym(handle, symbol);
+ if (!f)
+ av_log( NULL, AV_LOG_ERROR, "AMR-%cB Codec - function '%s' can't be resolved\n", type, symbol);
+ return f;
+}
+#endif
+
+static void amr_decode_fix_avctx(AVCodecContext* avctx, int sample_rate, int frame_size)
+{
+ if(avctx->sample_rate == 0) avctx->sample_rate = sample_rate;
+ if(avctx->channels == 0) avctx->channels = 1;
+ avctx->frame_size = frame_size;
+}
+
+#if defined(CONFIG_LIBAMR_NB) || defined(CONFIG_LIBAMR_NB_FIXED)
#ifdef CONFIG_LIBAMR_NB_FIXED
#define MMS_IO
@@ -77,9 +96,14 @@
#include "amr/e_homing.h"
#else
+#ifdef CONFIG_LIBAMRNBBIN
+static const char* libamrnbnames[] = {"libamrnb.so.3", "libamrnb.so.2"};
+#else
#include <amrnb/interf_dec.h>
#include <amrnb/interf_enc.h>
#endif
+#define amrnb_decode_fix_avctx(avctx) amr_decode_fix_avctx(avctx, 8000, 160)
+#endif
static const char *nb_bitrate_unsupported =
"bitrate not supported: use one of 4.75k, 5.15k, 5.9k, 6.7k, 7.4k, 7.95k, 10.2k or 12.2k\n";
@@ -87,16 +111,28 @@
"bitrate not supported: use one of 6.6k, 8.85k, 12.65k, 14.25k, 15.85k, 18.25k, 19.85k, 23.05k, or 23.85k\n";
/* Common code for fixed and float version*/
+#ifdef CONFIG_LIBAMRNBBIN
+#define Decoder_Interface_init s->amrnb_dec_init
+#define Encoder_Interface_init(S) s->amrnb_enc_init(S, 1)
+#define Decoder_Interface_exit(S) s->amrnb_exit(S); dlclose(s->handle)
+#define Encoder_Interface_exit(S) s->amrnb_exit(S); dlclose(s->handle)
+#define Decoder_Interface_Decode s->amrnb_decode
+#define Encoder_Interface_Encode(S1, S2, S3, S4, S5) s->amrnb_encode(S1, S2, S3, S4, S5, 0)
+#else
typedef struct AMR_bitrates
{
int rate;
enum Mode mode;
} AMR_bitrates;
+#endif
/* Match desired bitrate */
static int getBitrateMode(int bitrate)
{
/* make the correspondance between bitrate and mode */
+#ifdef CONFIG_LIBAMRNBBIN
+ int rates[]={4750, 5150, 5900, 6700, 7400, 7950, 10200, 12200};
+#else
AMR_bitrates rates[]={ {4750,MR475},
{5150,MR515},
{5900,MR59},
@@ -106,37 +142,27 @@
{10200,MR102},
{12200,MR122},
};
+#endif
int i;
for(i=0;i<8;i++)
{
+#ifdef CONFIG_LIBAMRNBBIN
+ if(rates[i]==bitrate)
+ {
+ return i;
+#else
+
if(rates[i].rate==bitrate)
{
return rates[i].mode;
+#endif
}
}
/* no bitrate matching, return an error */
return -1;
}
-static void amr_decode_fix_avctx(AVCodecContext * avctx)
-{
- const int is_amr_wb = 1 + (avctx->codec_id == CODEC_ID_AMR_WB);
-
- if(avctx->sample_rate == 0)
- {
- avctx->sample_rate = 8000 * is_amr_wb;
- }
-
- if(avctx->channels == 0)
- {
- avctx->channels = 1;
- }
-
- avctx->frame_size = 160 * is_amr_wb;
- avctx->sample_fmt = SAMPLE_FMT_S16;
-}
-
#ifdef CONFIG_LIBAMR_NB_FIXED
/* fixed point version*/
/* frame size in serial bitstream file (frame type + serial stream + flags) */
@@ -173,7 +199,7 @@
return -1;
}
- amr_decode_fix_avctx(avctx);
+ amrnb_decode_fix_avctx(avctx);
if(avctx->channels > 1)
{
@@ -360,13 +386,50 @@
void * decState;
int *enstate;
int enc_bitrate;
+#ifdef CONFIG_LIBAMRNBBIN
+ void* handle;
+ void* (*amrnb_dec_init)(void);
+ void* (*amrnb_enc_init)(int dtx, char vad2_code);
+ void (*amrnb_decode)(void *st, unsigned char *bits, short *synth, int bfi);
+ int (*amrnb_encode)(void *st, int mode, short *speech, unsigned char *serial, int forceSpeech, char vad2_code);
+ void (*amrnb_exit)(void *state);
+#endif
} AMRContext;
+#ifdef CONFIG_LIBAMRNBBIN
+static void* dlsymn(void* handle, const char* symbol)
+{
+ return dlsymm(handle, 'N', symbol);
+}
+#endif
+
static int amr_nb_decode_init(AVCodecContext * avctx)
{
AMRContext *s = avctx->priv_data;
+#ifdef CONFIG_LIBAMRNBBIN
+ int i;
+#endif
s->frameCount=0;
+#ifdef CONFIG_LIBAMRNBBIN
+ for(i=0, s->handle=NULL; i<(sizeof(libamrnbnames)/sizeof(char*)) && s->handle==NULL; i++)
+ s->handle = dlopen(libamrnbnames[i], RTLD_LAZY);
+ if (!s->handle)
+ {
+ av_log(avctx, AV_LOG_ERROR, "AMR-NB library ");
+ for(i=0; i<(sizeof(libamrnbnames)/sizeof(char*)); i++) av_log(avctx, AV_LOG_ERROR, "%s ", libamrnbnames[i]);
+ av_log(avctx, AV_LOG_ERROR, "could not be opened! \n%s\n", dlerror());
+ return -1;
+ }
+ s->amrnb_dec_init=(void (*)) dlsymn(s->handle, "Decoder_Interface_init");
+ s->amrnb_exit=(void (*)(void*)) dlsymn(s->handle, "Decoder_Interface_exit");
+ s->amrnb_decode=(void (*)(void *, unsigned char *, short *, int)) dlsymn(s->handle, "GP3Decoder_Interface_Decode");
+ if (!s->amrnb_dec_init || !s->amrnb_exit || !s->amrnb_decode)
+ {
+ dlclose(s->handle);
+ return -1;
+ }
+#endif
s->decState=Decoder_Interface_init();
if(!s->decState)
{
@@ -374,7 +437,7 @@
return -1;
}
- amr_decode_fix_avctx(avctx);
+ amrnb_decode_fix_avctx(avctx);
if(avctx->channels > 1)
{
@@ -388,6 +451,9 @@
static int amr_nb_encode_init(AVCodecContext * avctx)
{
AMRContext *s = avctx->priv_data;
+#ifdef CONFIG_LIBAMRNBBIN
+ int i;
+#endif
s->frameCount=0;
@@ -406,6 +472,25 @@
avctx->frame_size=160;
avctx->coded_frame= avcodec_alloc_frame();
+#ifdef CONFIG_LIBAMRNBBIN
+ for(i=0, s->handle=NULL; i<(sizeof(libamrnbnames)/sizeof(char*)) && s->handle==NULL; i++)
+ s->handle = dlopen(libamrnbnames[i], RTLD_LAZY);
+ if (!s->handle)
+ {
+ av_log(avctx, AV_LOG_ERROR, "AMR-NB library ");
+ for(i=0; i<(sizeof(libamrnbnames)/sizeof(char*)); i++) av_log(avctx, AV_LOG_ERROR, "%s ", libamrnbnames[i]);
+ av_log(avctx, AV_LOG_ERROR, "could not be opened! \n%s\n", dlerror());
+ return -1;
+ }
+ s->amrnb_enc_init=(void* (*)(int, char)) dlsymn(s->handle, "VADxEncoder_Interface_init");
+ s->amrnb_exit=(void (*)(void*)) dlsymn(s->handle, "Encoder_Interface_exit");
+ s->amrnb_encode=(int (*)(void*, int, short*, unsigned char*, int, char)) dlsymn(s->handle, "GP3VADxEncoder_Interface_Encode");
+ if (!s->amrnb_enc_init || !s->amrnb_exit || !s->amrnb_encode)
+ {
+ dlclose(s->handle);
+ return -1;
+ }
+#endif
s->enstate=Encoder_Interface_init(0);
if(!s->enstate)
{
@@ -446,7 +531,11 @@
AMRContext *s = avctx->priv_data;
uint8_t*amrData=buf;
static const uint8_t block_size[16]={ 12, 13, 15, 17, 19, 20, 26, 31, 5, 0, 0, 0, 0, 0, 0, 0 };
+#ifdef CONFIG_LIBAMRNBBIN
+ int dec_mode;
+#else
enum Mode dec_mode;
+#endif
int packet_size;
/* av_log(NULL,AV_LOG_DEBUG,"amr_decode_frame buf=%p buf_size=%d frameCount=%d!!\n",buf,buf_size,s->frameCount); */
@@ -480,11 +569,7 @@
return -1;
}
- written = Encoder_Interface_Encode(s->enstate,
- s->enc_bitrate,
- data,
- frame,
- 0);
+ written = Encoder_Interface_Encode(s->enstate, s->enc_bitrate, data, frame, 0);
/* av_log(NULL,AV_LOG_DEBUG,"amr_nb_encode_frame encoded %u bytes, bitrate %u, first byte was %#02x\n",written, s->enc_bitrate, frame[0] ); */
return written;
@@ -492,8 +577,6 @@
#endif
-#if defined(CONFIG_LIBAMR_NB) || defined(CONFIG_LIBAMR_NB_FIXED)
-
AVCodec libamr_nb_decoder =
{
"libamr_nb",
@@ -531,11 +614,26 @@
#define typedef_h
#endif
+#ifdef CONFIG_LIBAMRWBBIN
+#include <stdint.h>
+static const char* libamrwbnames[] = {"libamrwb.so.3", "libamrwb.so.2"};
+#define Word16 int16_t
+#define E_IF_init s->amrwb_init
+#define E_IF_exit(S) s->amrwb_exit(S); dlclose(s->handle)
+#define E_IF_encode s->amrwb_encode
+#define D_IF_init s->amrwb_init
+#define block_size s->amrwb_block_size
+#define _good_frame 0
+#define D_IF_decode s->amrwb_decode
+#define D_IF_exit(S) s->amrwb_exit(S); dlclose(s->handle)
+#else
#include <amrwb/enc_if.h>
#include <amrwb/dec_if.h>
#include <amrwb/if_rom.h>
+#endif
+
+#define amrwb_decode_fix_avctx(avctx) amr_decode_fix_avctx(avctx, 16000, 320)
-/* Common code for fixed and float version*/
typedef struct AMRWB_bitrates
{
int rate;
@@ -573,12 +671,30 @@
int frameCount;
void *state;
int mode;
+#ifdef CONFIG_LIBAMRWBBIN
+ void* handle;
+ void* (*amrwb_init)(void);
+ void (*amrwb_decode)(void *st, uint8_t *bits, int16_t *synth, int32_t bfi);
+ int (*amrwb_encode)(void *st, int16_t mode, int16_t *speech, uint8_t *serial, int16_t dtx);
+ void (*amrwb_exit)(void *state);
+ uint8_t *amrwb_block_size;
+#endif
Word16 allow_dtx;
} AMRWBContext;
+#ifdef CONFIG_LIBAMRWBBIN
+static void* dlsymw(void* handle, const char* symbol)
+{
+ return dlsymm(handle, 'W', symbol);
+}
+#endif
+
static int amr_wb_encode_init(AVCodecContext * avctx)
{
AMRWBContext *s = avctx->priv_data;
+#ifdef CONFIG_LIBAMRNBBIN
+ int i;
+#endif
s->frameCount=0;
@@ -603,6 +719,25 @@
avctx->frame_size=320;
avctx->coded_frame= avcodec_alloc_frame();
+#ifdef CONFIG_LIBAMRWBBIN
+ for(i=0, s->handle=NULL; i<(sizeof(libamrwbnames)/sizeof(char*)) && s->handle==NULL; i++)
+ s->handle = dlopen(libamrwbnames[i], RTLD_LAZY);
+ if (!s->handle)
+ {
+ av_log(avctx, AV_LOG_ERROR, "AMR-WB library ");
+ for(i=0; i<(sizeof(libamrwbnames)/sizeof(char*)); i++) av_log(avctx, AV_LOG_ERROR, "%s ", libamrwbnames[i]);
+ av_log(avctx, AV_LOG_ERROR, "could not be opened! \n%s\n", dlerror());
+ return -1;
+ }
+ s->amrwb_init=(void (*)) dlsymw(s->handle, "E_IF_init");
+ s->amrwb_exit=(void (*)(void*)) dlsymw(s->handle, "E_IF_exit");
+ s->amrwb_encode=(int (*)(void *, int16_t, int16_t *, uint8_t *, int16_t)) dlsymw(s->handle, "GP3E_IF_encode");
+ if (!s->amrwb_init || !s->amrwb_exit || !s->amrwb_encode)
+ {
+ dlclose(s->handle);
+ return -1;
+ }
+#endif
s->state = E_IF_init();
s->allow_dtx=0;
@@ -637,11 +772,34 @@
static int amr_wb_decode_init(AVCodecContext * avctx)
{
AMRWBContext *s = avctx->priv_data;
+#ifdef CONFIG_LIBAMRNBBIN
+ int i;
+#endif
s->frameCount=0;
+#ifdef CONFIG_LIBAMRWBBIN
+ for(i=0, s->handle=NULL; i<(sizeof(libamrwbnames)/sizeof(char*)) && s->handle==NULL; i++)
+ s->handle = dlopen(libamrwbnames[i], RTLD_LAZY);
+ if (!s->handle)
+ {
+ av_log(avctx, AV_LOG_ERROR, "AMR-WB library ");
+ for(i=0; i<(sizeof(libamrwbnames)/sizeof(char*)); i++) av_log(avctx, AV_LOG_ERROR, "%s ", libamrwbnames[i]);
+ av_log(avctx, AV_LOG_ERROR, "could not be opened! \n%s\n", dlerror());
+ return -1;
+ }
+ s->amrwb_init=(void (*)) dlsymw(s->handle, "D_IF_init");
+ s->amrwb_exit=(void (*)(void*)) dlsymw(s->handle, "D_IF_exit");
+ s->amrwb_block_size=(uint8_t (*)) dlsymw(s->handle, "GP3block_size");
+ s->amrwb_decode=(void (*)(void *, uint8_t *, int16_t *, int32_t)) dlsymw(s->handle, "GP3D_IF_decode");
+ if (!s->amrwb_init || !s->amrwb_exit || !s->amrwb_block_size || !s->amrwb_decode)
+ {
+ dlclose(s->handle);
+ return -1;
+ }
+#endif
s->state = D_IF_init();
- amr_decode_fix_avctx(avctx);
+ amrwb_decode_fix_avctx(avctx);
if(avctx->channels > 1)
{
@@ -660,7 +818,9 @@
uint8_t*amrData=buf;
int mode;
int packet_size;
+#ifndef CONFIG_LIBAMRWBBIN
static const uint8_t block_size[16] = {18, 23, 33, 37, 41, 47, 51, 59, 61, 6, 6, 0, 0, 0, 1, 1};
+#endif
if(buf_size==0) {
/* nothing to do */