git migration: Refactor the ASTERISK_FILE_VERSION macro
[asterisk/asterisk.git] / main / abstract_jb.c
index 7841b6a..c703c68 100644 (file)
@@ -35,7 +35,7 @@
 
 #include "asterisk.h"
 
-ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
+ASTERISK_REGISTER_FILE()
 
 #include "asterisk/frame.h"
 #include "asterisk/channel.h"
@@ -360,7 +360,7 @@ static void jb_get_and_deliver(struct ast_channel *chan)
        }
 
        while (now >= jb->next) {
-               interpolation_len = ast_codec_interp_len(&jb->last_format);
+               interpolation_len = ast_format_get_default_ms(jb->last_format);
 
                res = jbimpl->get(jbobj, &f, now, interpolation_len);
 
@@ -371,13 +371,13 @@ static void jb_get_and_deliver(struct ast_channel *chan)
                case AST_JB_IMPL_DROP:
                        jb_framelog("\tJB_GET {now=%ld}: %s frame with ts=%ld and len=%ld\n",
                                now, jb_get_actions[res], f->ts, f->len);
-                       ast_format_copy(&jb->last_format, &f->subclass.format);
+                       ao2_replace(jb->last_format, f->subclass.format);
                        ast_frfree(f);
                        break;
                case AST_JB_IMPL_INTERP:
                        /* interpolate a frame */
                        f = &finterp;
-                       ast_format_copy(&f->subclass.format, &jb->last_format);
+                       f->subclass.format = jb->last_format;
                        f->samples  = interpolation_len * 8;
                        f->src  = "JB interpolation";
                        f->delivery = ast_tvadd(jb->timebase, ast_samp2tv(jb->next, 1000));
@@ -437,7 +437,7 @@ static int create_jb(struct ast_channel *chan, struct ast_frame *frr)
        jb->next = jbimpl->next(jbobj);
 
        /* Init last format for a first time. */
-       ast_format_copy(&jb->last_format, &frr->subclass.format);
+       jb->last_format = ao2_bump(frr->subclass.format);
 
        /* Create a frame log file */
        if (ast_test_flag(jbconf, AST_JB_LOG)) {
@@ -502,6 +502,8 @@ void ast_jb_destroy(struct ast_channel *chan)
                jb->logfile = NULL;
        }
 
+       ao2_cleanup(jb->last_format);
+
        if (ast_test_flag(jb, JB_CREATED)) {
                /* Remove and free all frames still queued in jb */
                while (jbimpl->remove(jbobj, &f) == AST_JB_IMPL_OK) {
@@ -656,7 +658,7 @@ static int jb_put_fixed(void *jb, struct ast_frame *fin, long now)
 static int jb_get_fixed(void *jb, struct ast_frame **fout, long now, long interpl)
 {
        struct fixed_jb *fixedjb = (struct fixed_jb *) jb;
-       struct fixed_jb_frame frame;
+       struct fixed_jb_frame frame = { .data = &ast_null_frame };
        int res;
 
        res = fixed_jb_get(fixedjb, &frame, now, interpl);
@@ -752,7 +754,7 @@ static int jb_put_adaptive(void *jb, struct ast_frame *fin, long now)
 static int jb_get_adaptive(void *jb, struct ast_frame **fout, long now, long interpl)
 {
        jitterbuf *adaptivejb = (jitterbuf *) jb;
-       jb_frame frame;
+       jb_frame frame = { .data = &ast_null_frame };
        int res;
 
        res = jb_get(adaptivejb, &frame, now, interpl);
@@ -820,7 +822,7 @@ struct jb_framedata {
        const struct ast_jb_impl *jb_impl;
        struct ast_jb_conf jb_conf;
        struct timeval start_tv;
-       struct ast_format last_format;
+       struct ast_format *last_format;
        struct ast_timer *timer;
        int timer_interval; /* ms between deliveries */
        int timer_fd;
@@ -842,6 +844,7 @@ static void jb_framedata_destroy(struct jb_framedata *framedata)
                framedata->jb_impl->destroy(framedata->jb_obj);
                framedata->jb_obj = NULL;
        }
+       ao2_cleanup(framedata->last_format);
        ast_free(framedata);
 }
 
@@ -909,7 +912,7 @@ static struct ast_frame *hook_event_cb(struct ast_channel *chan, struct ast_fram
                }
 
                jbframe = ast_frisolate(frame);
-               ast_format_copy(&framedata->last_format, &frame->subclass.format);
+               ao2_replace(framedata->last_format, frame->subclass.format);
 
                if (frame->len && (frame->len != framedata->timer_interval)) {
                        framedata->timer_interval = frame->len;
@@ -921,8 +924,14 @@ static struct ast_frame *hook_event_cb(struct ast_channel *chan, struct ast_fram
                } else {
                        res = framedata->jb_impl->put(framedata->jb_obj, jbframe, now);
                }
+
                if (res == AST_JB_IMPL_OK) {
+                       if (jbframe != frame) {
+                               ast_frfree(frame);
+                       }
                        frame = &ast_null_frame;
+               } else if (jbframe != frame) {
+                       ast_frfree(jbframe);
                }
                putframe = 1;
        }
@@ -949,6 +958,8 @@ static struct ast_frame *hook_event_cb(struct ast_channel *chan, struct ast_fram
                        }
                }
 
+               ast_frfree(frame);
+               frame = &ast_null_frame;
                res = framedata->jb_impl->get(framedata->jb_obj, &frame, now, framedata->timer_interval);
                switch (res) {
                case AST_JB_IMPL_OK:
@@ -959,20 +970,23 @@ static struct ast_frame *hook_event_cb(struct ast_channel *chan, struct ast_fram
                        frame = &ast_null_frame;
                        break;
                case AST_JB_IMPL_INTERP:
-                       if (framedata->last_format.id) {
+                       if (framedata->last_format) {
                                struct ast_frame tmp = { 0, };
+
                                tmp.frametype = AST_FRAME_VOICE;
-                               ast_format_copy(&tmp.subclass.format, &framedata->last_format);
+                               tmp.subclass.format = framedata->last_format;
                                /* example: 8000hz / (1000 / 20ms) = 160 samples */
-                               tmp.samples = ast_format_rate(&framedata->last_format) / (1000 / framedata->timer_interval);
+                               tmp.samples = ast_format_get_sample_rate(framedata->last_format) / (1000 / framedata->timer_interval);
                                tmp.delivery = ast_tvadd(framedata->start_tv, ast_samp2tv(next, 1000));
                                tmp.offset = AST_FRIENDLY_OFFSET;
                                tmp.src  = "func_jitterbuffer interpolation";
+                               ast_frfree(frame);
                                frame = ast_frdup(&tmp);
                                break;
                        }
                        /* else fall through */
                case AST_JB_IMPL_NOFRAME:
+                       ast_frfree(frame);
                        frame = &ast_null_frame;
                        break;
                }
@@ -1052,6 +1066,7 @@ void ast_jb_create_framehook(struct ast_channel *chan, struct ast_jb_conf *jb_co
                        id = datastore->data;
                        ast_framehook_detach(chan, *id);
                        ast_channel_datastore_remove(chan, datastore);
+                       ast_datastore_free(datastore);
                }
                ast_channel_unlock(chan);
                return;
@@ -1084,6 +1099,7 @@ void ast_jb_create_framehook(struct ast_channel *chan, struct ast_jb_conf *jb_co
                        id = datastore->data;
                        ast_framehook_detach(chan, *id);
                        ast_channel_datastore_remove(chan, datastore);
+                       ast_datastore_free(datastore);
                }
 
                if (!(datastore = ast_datastore_alloc(&jb_datastore, NULL))) {
@@ -1109,6 +1125,4 @@ void ast_jb_create_framehook(struct ast_channel *chan, struct ast_jb_conf *jb_co
                framedata = NULL;
        }
        ast_channel_unlock(chan);
-
-       return;
 }