astobj2: Add backtrace to log_bad_ao2.
[asterisk/asterisk.git] / funcs / func_frame_trace.c
index 61582a6..e8c1094 100644 (file)
@@ -31,7 +31,7 @@
 
 #include "asterisk.h"
 
-ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
+ASTERISK_REGISTER_FILE()
 
 #include "asterisk/module.h"
 #include "asterisk/channel.h"
@@ -140,7 +140,7 @@ static struct ast_frame *hook_event_cb(struct ast_channel *chan, struct ast_fram
        }
 
        if (show_frame) {
-               ast_verbose("%s on Channel %s\n", event == AST_FRAMEHOOK_EVENT_READ ? "<--Read" : "--> Write", chan->name);
+               ast_verbose("%s on Channel %s\n", event == AST_FRAMEHOOK_EVENT_READ ? "<--Read" : "--> Write", ast_channel_name(chan));
                print_frame(frame);
        }
        return frame;
@@ -157,6 +157,11 @@ static int frame_trace_helper(struct ast_channel *chan, const char *cmd, char *d
        };
        int i = 0;
 
+       if (!chan) {
+               ast_log(LOG_WARNING, "No channel was provided to %s function.\n", cmd);
+               return -1;
+       }
+
        if (!(framedata = ast_calloc(1, sizeof(*framedata)))) {
                return 0;
        }
@@ -180,6 +185,7 @@ static int frame_trace_helper(struct ast_channel *chan, const char *cmd, char *d
                        id = datastore->data;
                        ast_framehook_detach(chan, *id);
                        ast_channel_datastore_remove(chan, datastore);
+                       ast_datastore_free(datastore);
                }
 
                if (!(datastore = ast_datastore_alloc(&frame_trace_datastore, NULL))) {
@@ -209,25 +215,26 @@ static void print_frame(struct ast_frame *frame)
        switch (frame->frametype) {
        case AST_FRAME_DTMF_END:
                ast_verbose("FrameType: DTMF END\n");
-               ast_verbose("Digit: %d\n", frame->subclass.integer);
+               ast_verbose("Digit: 0x%02X '%c'\n", (unsigned)frame->subclass.integer,
+                       frame->subclass.integer < ' ' ? ' ' : frame->subclass.integer);
                break;
        case AST_FRAME_VOICE:
                ast_verbose("FrameType: VOICE\n");
-               ast_verbose("Codec: %s\n", ast_getformatname(&frame->subclass.format));
+               ast_verbose("Codec: %s\n", ast_format_get_name(frame->subclass.format));
                ast_verbose("MS: %ld\n", frame->len);
                ast_verbose("Samples: %d\n", frame->samples);
                ast_verbose("Bytes: %d\n", frame->datalen);
                break;
        case AST_FRAME_VIDEO:
                ast_verbose("FrameType: VIDEO\n");
-               ast_verbose("Codec: %s\n", ast_getformatname(&frame->subclass.format));
+               ast_verbose("Codec: %s\n", ast_format_get_name(frame->subclass.format));
                ast_verbose("MS: %ld\n", frame->len);
                ast_verbose("Samples: %d\n", frame->samples);
                ast_verbose("Bytes: %d\n", frame->datalen);
                break;
        case AST_FRAME_CONTROL:
                ast_verbose("FrameType: CONTROL\n");
-               switch (frame->subclass.integer) {
+               switch ((enum ast_control_frame_type) frame->subclass.integer) {
                case AST_CONTROL_HANGUP:
                        ast_verbose("SubClass: HANGUP\n");
                        break;
@@ -318,7 +325,48 @@ static void print_frame(struct ast_frame *frame)
                case AST_CONTROL_INCOMPLETE:
                        ast_verbose("SubClass: INCOMPLETE\n");
                        break;
+               case AST_CONTROL_END_OF_Q:
+                       ast_verbose("SubClass: END_OF_Q\n");
+                       break;
+               case AST_CONTROL_UPDATE_RTP_PEER:
+                       ast_verbose("SubClass: UPDATE_RTP_PEER\n");
+                       break;
+               case AST_CONTROL_PVT_CAUSE_CODE:
+                       ast_verbose("SubClass: PVT_CAUSE_CODE\n");
+                       break;
+               case AST_CONTROL_MASQUERADE_NOTIFY:
+                       /* Should never happen. */
+                       ast_assert(0);
+                       break;
+               case AST_CONTROL_STREAM_STOP:
+                       ast_verbose("SubClass: STREAM_STOP\n");
+                       break;
+               case AST_CONTROL_STREAM_SUSPEND:
+                       ast_verbose("SubClass: STREAM_SUSPEND\n");
+                       break;
+               case AST_CONTROL_STREAM_RESTART:
+                       ast_verbose("SubClass: STREAM_RESTART\n");
+                       break;
+               case AST_CONTROL_STREAM_REVERSE:
+                       ast_verbose("SubClass: STREAM_REVERSE\n");
+                       break;
+               case AST_CONTROL_STREAM_FORWARD:
+                       ast_verbose("SubClass: STREAM_FORWARD\n");
+                       break;
+               case AST_CONTROL_RECORD_CANCEL:
+                       ast_verbose("SubClass: RECORD_CANCEL\n");
+                       break;
+               case AST_CONTROL_RECORD_STOP:
+                       ast_verbose("SubClass: RECORD_STOP\n");
+                       break;
+               case AST_CONTROL_RECORD_SUSPEND:
+                       ast_verbose("SubClass: RECORD_SUSPEND\n");
+                       break;
+               case AST_CONTROL_RECORD_MUTE:
+                       ast_verbose("SubClass: RECORD_MUTE\n");
+                       break;
                }
+
                if (frame->subclass.integer == -1) {
                        ast_verbose("SubClass: %d\n", frame->subclass.integer);
                }
@@ -347,7 +395,16 @@ static void print_frame(struct ast_frame *frame)
                break;
        case AST_FRAME_DTMF_BEGIN:
                ast_verbose("FrameType: DTMF BEGIN\n");
-               ast_verbose("Digit: %d\n", frame->subclass.integer);
+               ast_verbose("Digit: 0x%02X '%c'\n", (unsigned)frame->subclass.integer,
+                       frame->subclass.integer < ' ' ? ' ' : frame->subclass.integer);
+               break;
+       case AST_FRAME_BRIDGE_ACTION:
+               ast_verbose("FrameType: Bridge\n");
+               ast_verbose("SubClass: %d\n", frame->subclass.integer);
+               break;
+       case AST_FRAME_BRIDGE_ACTION_SYNC:
+               ast_verbose("Frametype: Synchronous Bridge\n");
+               ast_verbose("Subclass: %d\n", frame->subclass.integer);
                break;
        }
 
@@ -371,5 +428,6 @@ static int load_module(void)
        return res ? AST_MODULE_LOAD_DECLINE : AST_MODULE_LOAD_SUCCESS;
 }
 
-AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Frame Trace for internal ast_frame debugging.");
+AST_MODULE_INFO_STANDARD_EXTENDED(ASTERISK_GPL_KEY, "Frame Trace for internal ast_frame debugging.");
+