[mythtv] commflag debugging

Chris Pinkham cpinkham at bc2va.org
Sun Jan 1 01:42:05 EST 2006

> I would like to look into some commflag debugging.  I see there are 
> already bits in place to display/dump frames, but the support functions 
> for them dont resolve.  I suspect they are defined in commercial_debug.h, 
> which is commented out in ClassicCommDetector.cpp but doesnt exist within 
> svn.  Curious if anyone knows where I might find it.

commercial_debug.h is something I use locally but never committed to
cvs or svn.  Attached is a copy.

It's a quick hack, but accomplished what I wanted when I threw it
together a few years ago. :)

To use, just uncomment the #include line and recompile.  Also, for some
more verbose debugging than the normal "-v commflag", you can define an
environment variable called DEBUGCOMMFLAG and that will cause a lot more
verbose debugging information to be displayed.


-------------- next part --------------
// This code is meant for use in debugging the CommDetect class and shouldn't
// be used in normal compiled Myth versions.

#include <X11/keysym.h>
#include <X11/Xatom.h>
#include <X11/Xlib.h>
#include <X11/Xutil.h>
#include <X11/extensions/XShm.h>

extern "C" {
#include "../../libs/libavcodec/avcodec.h"

Window comm_root;
Window comm_win;
Window comm_curwin;
GC comm_gc;
Screen *comm_screen;
Display *comm_display;
int comm_width = 0;
int comm_height = 0;
int comm_screen_num;
int comm_depth = 24;
unsigned long comm_white, comm_black;
XImage *comm_image = NULL;
char *comm_buf = NULL;
AVPicture image_in, image_out;
ImgReSampleContext *scontext;
int av_format;


void comm_debug_init( int width, int height )
    comm_display = XOpenDisplay(NULL);

    comm_screen = DefaultScreenOfDisplay(comm_display);
    comm_screen_num = DefaultScreen(comm_display);

    comm_root = DefaultRootWindow(comm_display);

    comm_white = XWhitePixel(comm_display, comm_screen_num);
    comm_black = XBlackPixel(comm_display, comm_screen_num);

    comm_depth = DefaultDepthOfScreen(comm_screen);

    comm_win = XCreateSimpleWindow(comm_display, comm_root, 100,
                                    100, width, height, 0,
                                    comm_white, comm_black );

    XMapRaised(comm_display, comm_win);

    XSync(comm_display, 0);

    comm_gc = XCreateGC(comm_display, comm_win, 0, 0);

    comm_buf = new char[4 * width * height];

    comm_image = XCreateImage(comm_display, DefaultVisual(comm_display, 0),
                              comm_depth, ZPixmap, 0, comm_buf,
                              width, height, 8, 0);

    XSync(comm_display, 0);

    comm_width = width;
    comm_height = height;

    printf( "Commercial Detection debug window created at %dx%dx%d\n",
        comm_width, comm_height, comm_depth );

void comm_debug_show( unsigned char *frame )
    avpicture_fill(&image_in, (uint8_t *)frame, PIX_FMT_YUV420P,
                   comm_width, comm_height);

    switch (comm_depth)
        case 16: av_format = PIX_FMT_RGB565; break;
        case 24: av_format = PIX_FMT_RGBA32;  break;
        case 32: av_format = PIX_FMT_RGBA32; break;
            printf("Unable to display debug video window in %d depth.\n",

    avpicture_fill(&image_out, (uint8_t *)comm_image->data, av_format,
                   comm_width, comm_height);

    img_convert(&image_out, av_format, &image_in, PIX_FMT_YUV420P,
                comm_width, comm_height);

    XPutImage(comm_display, comm_win, comm_gc, comm_image,
                0, 0, 0, 0, comm_width, comm_height );

    XSync(comm_display, 0);

void comm_debug_destroy()
    delete comm_buf;
    XDestroyWindow(comm_display, comm_win);

More information about the mythtv-dev mailing list