[FFmpeg-devel] [PATCH] G.729 initialization routine (skeleton)
Vladimir Voroshilov
voroshil
Fri Jun 5 09:24:39 CEST 2009
Hi, All.
Routines in patch just checks the passed sample_rate for supported modes.
After check it properly initializes "format" and "subframe_size"
context members.
All other initialization code will be added later (LSP structures
initialization in LSP patch and so on).
Hopefully it is enough small and clean for easy review.
Is such patches enough good ?
Should i post remaining (i don't want to post all patches at the same
time, since not all patches are
ready yet).
--
Regards,
Vladimir Voroshilov mailto:voroshil at gmail.com
JID: voroshil at gmail.com, voroshil at jabber.ru
ICQ: 95587719
-------------- next part --------------
>From 02ea4848b318e8c189f5eb48abdba500c15937e0 Mon Sep 17 00:00:00 2001
From: Vladimir Voroshilov <voroshil at gmail.com>
Date: Fri, 5 Jun 2009 00:47:25 +0700
Subject: [PATCH] Initialization routine
diff --git ffmpeg-r19088.orig/libavcodec/g729dec.c ffmpeg-r19088.mod/libavcodec/g729dec.c
index 0b70a75..b86874a 100644
--- ffmpeg-r19088.orig/libavcodec/g729dec.c
+++ ffmpeg-r19088.mod/libavcodec/g729dec.c
@@ -81,6 +81,16 @@ typedef struct {
int mr_energy;
} G729_format_description;
+typedef enum {
+ FORMAT_G729_8K = 0,
+ FORMAT_G729_4K4,
+} G729_formats;
+
+typedef struct {
+ G729_formats format; ///< format index from formats array
+ int subframe_size; ///< number of samples produced from one subframe
+} G729_Context;
+
/**
* \brief pseudo random number generator
*/
@@ -97,11 +107,45 @@ static inline int g729_get_parity(uint8_t value)
return (0x6996966996696996ULL >> (value >> 2)) & 1;
}
+/**
+ * \brief G.729 decoder initialization
+ * \param avctx private data structure
+ * \return 0 on success, non-zero otherwise
+ *
+ * For decoder initialization Table 9 from section 4.3 of the specification
+ * is used.
+ */
+static int g729_decoder_init(AVCodecContext * avctx)
+{
+ G729_Context* ctx = avctx->priv_data;
+
+ if (avctx->sample_rate == 8000)
+ ctx->format = FORMAT_G729_8K;
+#ifdef G729_SUPPORT_4400
+ else if (avctx->sample_rate == 4400)
+ ctx->format = FORMAT_G729_4K4;
+#endif
+ else {
+ av_log(avctx, AV_LOG_ERROR, "Sample rate %d is not supported.\n", avctx->sample_rate);
+ return AVERROR_NOFMT;
+ }
+
if (avctx->channels != 1) {
av_log(avctx, AV_LOG_ERROR, "Only mono sound is supported (requested channels: %d).\n", avctx->channels);
return AVERROR_NOFMT;
}
+ /* subframe size in 2-byte samples
+ 1st ">>1" : bytes -> samples
+ 2nd ">>1" : frame -> subframe */
+ ctx->subframe_size = formats[ctx->format].unpacked_frame_size >> 2;
+
+ assert(ctx->subframe_size > 0 && ctx->subframe_size <= MAX_SUBFRAME_SIZE);
+
+ avctx->frame_size = 2 * ctx->subframe_size;
+ return 0;
+}
+
ff_acelp_weighted_vector_sum(
fc + pitch_delay_int[i],
fc + pitch_delay_int[i],
--
1.6.0.4
More information about the ffmpeg-devel
mailing list