[Linux-hls-cvs] qosman/demos mpcore-fb.c,NONE,1.1 mpcore-fb.h,NONE,1.1 Makefile,1.2,1.3 mpcore.c,1.1
Status: Pre-Alpha
Brought to you by:
lucabe
|
From: Luca A. <lu...@us...> - 2004-07-25 09:57:44
|
Update of /cvsroot/linux-hls/qosman/demos In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv13492/demos Modified Files: Makefile mpcore.c mpcore.h mpdemo.c ppsdemo.c Added Files: mpcore-fb.c mpcore-fb.h Log Message: Update to the demos: New FB-based demo Index: mpcore.h =================================================================== RCS file: /cvsroot/linux-hls/qosman/demos/mpcore.h,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** mpcore.h 9 Apr 2004 13:41:31 -0000 1.1 --- mpcore.h 25 Jul 2004 09:57:30 -0000 1.2 *************** *** 12,17 **** void file_set_end(void); FILE *file_open(char *fname, ImageDesc *img); ! struct controls *window_prepare(int w, int h); ! void frame_display(struct controls *c, ImageDesc *img, unsigned char *b); #endif /* __MP_CORE_H__ */ --- 12,20 ---- void file_set_end(void); FILE *file_open(char *fname, ImageDesc *img); ! struct controls *window_prepare(ImageDesc *img); ! void frame_display(struct controls *c, ImageDesc *img, unsigned char *b, int i); ! void events_update(void); ! void pbar_update(struct controls *c, float l); + #define output_init gtk_init #endif /* __MP_CORE_H__ */ --- NEW FILE: mpcore-fb.c --- #include <sys/mman.h> #include <sys/ioctl.h> #include <sys/types.h> #include <sys/stat.h> #include <fcntl.h> #include <stdlib.h> #include <unistd.h> #include <stdio.h> #include <errno.h> #include <string.h> #include <linux/fb.h> #include <mpeg.h> #include "mpcore-fb.h" #define FULLCOLOR static int end = 0; static char *fbdevname = "/dev/fb0"; static struct fb_cmap old_cmap; static struct fb_cmap *cmap_bw(int size) { int i; unsigned short int *red, *green, *blue; struct fb_cmap *cmap; red = malloc(size * sizeof(red[0])); if(!red) { fprintf(stderr, "Can't allocate red palette with %d entries.\n", size); return NULL; } for(i = 0; i < size; i++) { red[i] = (65535 / (size - 1)) * i; } green = malloc(size * sizeof(green[0])); if(!green) { fprintf(stderr, "Can't allocate green palette with %d entries.\n", size); free(red); return NULL; } for(i = 0; i< size; i++) { green[i] = (65535 / (size - 1)) * i; } blue = malloc(size * sizeof(blue[0])); if(!blue) { fprintf(stderr, "Can't allocate blue palette with %d entries.\n", size); free(red); free(green); return NULL; } for(i = 0; i< size; i++) { blue[i] = (65535 / (size - 1)) * i; } cmap = malloc(sizeof(struct fb_cmap)); if(!cmap) { fprintf(stderr, "Can't allocate color map\n"); free(red); free(green); free(blue); return NULL; } cmap->start = 0; cmap->transp = 0; cmap->len = size; cmap->red = red; cmap->blue = blue; cmap->green = green; cmap->transp = NULL; return cmap; } static struct fb_cmap *cmap_color(int size, ColormapEntry *mpmap) { int i; unsigned short int *red, *green, *blue; struct fb_cmap *cmap; printf("Colormap Size: %d\n", size); red = malloc(size * sizeof(red[0])); if(!red) { fprintf(stderr, "Can't allocate red palette with %d entries.\n", size); return NULL; } green = malloc(size * sizeof(green[0])); if(!green) { fprintf(stderr, "Can't allocate green palette with %d entries.\n", size); free(red); return NULL; } blue = malloc(size * sizeof(blue[0])); if(!blue) { fprintf(stderr, "Can't allocate blue palette with %d entries.\n", size); free(red); free(green); return NULL; } for(i = 0; i < size; i++) { red[i] = mpmap[i].red /* * 256 */; blue[i] = mpmap[i].blue /* * 256 */; green[i] = mpmap[i].green /* * 256 */; printf("%d ---> R: %d G: %d B: %d\n", i, red[i], green[i], blue[i]); } cmap = malloc(sizeof(struct fb_cmap)); if(!cmap) { fprintf(stderr, "Can't allocate color map\n"); free(red); free(green); free(blue); return NULL; } cmap->start = 0; cmap->transp = 0; cmap->len = size; cmap->red = red; cmap->blue = blue; cmap->green = green; cmap->transp = NULL; return cmap; } void events_update(void) { } void pbar_update(struct controls *c, float l) { } int file_end(void) { return end; } void file_set_end(void) { end = 1; } void frame_display(struct controls *c, ImageDesc *img, unsigned char *b, int id) { int i; #ifndef FULLCOLOR if (c->bpp * 8 != img->Depth) { fprintf(stderr, "(%d != %d) Screen BPP != Img BPP!!! :(\n", c->bpp, img->Depth); exit(-1); } #endif for (i = 0; i < img->Height; i++) { memcpy(c->fb_line_len / 2 * id + c->b + i * c->fb_line_len, b + i * img->Width * c->bpp, img->Width * c->bpp); } } FILE *file_open(char *fname, ImageDesc *img) { FILE *f; int i; f = fopen(fname, "rb"); if (fname == NULL) { perror("Error opening:"); exit(-1); } #ifdef FULLCOLOR SetMPEGOption(MPEG_DITHER, FULL_COLOR_DITHER); #else SetMPEGOption(MPEG_DITHER, /*GRAY_DITHER*/ FS4_DITHER); #endif if (!OpenMPEG(f, img)) { fprintf(stderr, "OpenMPEG on %s failed\n", fname); exit(-1); } printf("H: %d\tW: %d\tD: %d\n", img->Height, img->Width, img->Depth); printf("PS: %d\tSize: %d\tBMP: %d\n", img->PixelSize, img->Size, img->BitmapPad); printf("Rate: %d\tbr: %d\tcmap Size: %d\n", img->PictureRate, img->BitRate, img->ColormapSize); for (i = 0; i < img->ColormapSize; i++) { printf("%d ---> R: %d G: %d B: %d\n", i, img->Colormap[i].red, img->Colormap[i].green, img->Colormap[i].blue); } return f; } struct controls *window_prepare(ImageDesc *img) { int res; struct fb_var_screeninfo fb_vinfo; struct fb_fix_screeninfo fb_finfo; struct controls *p; struct fb_cmap *cmap; p = malloc(sizeof(struct controls)); if (p == NULL) { return NULL; } p->fbdev_fd = open(fbdevname, O_RDWR); if (p->fbdev_fd == -1) { perror("Cannot open FB device"); free(p); return NULL; } res = ioctl(p->fbdev_fd, FBIOGET_VSCREENINFO, &fb_vinfo); if (res < 0) { perror("Error opening fbdev"); close(p->fbdev_fd); free(p); return NULL; } #if 0 p->fbtty_fd = open("dev/tty", O_RDWR); if (fbtty_fd < 0) { perror("Error opening /dev/tty"); return NULL; } #endif printf("Bits per Pixel: %d\n", fb_vinfo.bits_per_pixel); printf("Red.Len: %d\n", fb_vinfo.red.length); printf("Blue.Len: %d\n", fb_vinfo.blue.length); printf("Green.Len: %d\n", fb_vinfo.green.length); res = ioctl(p->fbdev_fd, FBIOGET_FSCREENINFO, &fb_finfo); if (res < 0) { perror("Can't get FSCREENINFO"); close(p->fbdev_fd); free(p); return NULL; } #ifdef FULLCOLOR fb_vinfo.bits_per_pixel = 32; res = ioctl(p->fbdev_fd, FBIOPUT_VSCREENINFO, &fb_vinfo); if (res < 0) { perror("Error opening fbdev"); close(p->fbdev_fd); free(p); return NULL; } #endif p->fb_line_len = fb_finfo.line_length; p->fb_size = fb_finfo.smem_len; p->bpp = fb_vinfo.bits_per_pixel / 8; /* CHECKME! */ p->b = NULL; p->b = (unsigned char *)mmap(0, p->fb_size, PROT_READ | PROT_WRITE, MAP_SHARED, p->fbdev_fd, 0); if (p->b == (unsigned char *) -1) { perror("MMAP"); close(p->fbdev_fd); free(p); return NULL; } #if 0 center = frame_buffer + (out_width - in_width) * fb_pixel_size / 2 + ( (out_height - in_height) / 2 ) * fb_line_len + x_offset * fb_pixel_size + y_offset * fb_line_len; #endif printf("frame_buffer @ %p\n", p->b); #if 0 printf("center @ %p\n", center); printf("pixel per line: %d\n", fb_line_len / fb_pixel_size); memset(frame_buffer, '\0', fb_line_len * fb_yres); #endif #ifdef FULLCOLOR #else #if 0 cmap = cmap_bw(256); #else cmap = cmap_color(img->ColormapSize, img->Colormap); #endif old_cmap.len = 256; old_cmap.start = 0; old_cmap.red = malloc(256 * 2); old_cmap.blue = malloc(256 * 2); old_cmap.green = malloc(256 * 2); old_cmap.transp = malloc(256 * 2); res = ioctl(p->fbdev_fd, FBIOGETCMAP, &old_cmap); if (res) { fprintf(stderr, "can't get cmap: %s\n", strerror(errno)); close(p->fbdev_fd); free(p); return NULL; } res = ioctl(p->fbdev_fd, FBIOPUTCMAP, cmap); if (res) { fprintf(stderr, "can't put cmap: %s\n", strerror(errno)); close(p->fbdev_fd); free(p); return NULL; } free(cmap->red); free(cmap->green); free(cmap->blue); free(cmap); #endif return p; } Index: mpdemo.c =================================================================== RCS file: /cvsroot/linux-hls/qosman/demos/mpdemo.c,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** mpdemo.c 9 Apr 2004 13:39:56 -0000 1.2 --- mpdemo.c 25 Jul 2004 09:57:30 -0000 1.3 *************** *** 43,47 **** --- 43,51 ---- #include <mpeg.h> + #ifdef __FB__ + #include "mpcore-fb.h" + #else #include "mpcore.h" + #endif #if 0 #include <rk/rk.h> *************** *** 65,70 **** static int myid; - #define MAXSLIDE 150 - void save_results(void) { --- 69,72 ---- *************** *** 155,159 **** argc = ac; argv = av; ! gtk_init(&argc, &argv); if (argc != 2) { printf("Gimme the file name, please!!!\n"); --- 157,161 ---- argc = ac; argv = av; ! output_init(&argc, &argv); if (argc != 2) { printf("Gimme the file name, please!!!\n"); *************** *** 175,179 **** i = 0; ! c = window_prepare(img.Width, img.Height); cprintf("[MPEGDemo] Starting to play...\n"); --- 177,181 ---- i = 0; ! c = window_prepare(&img); cprintf("[MPEGDemo] Starting to play...\n"); *************** *** 182,193 **** gettimeofday(&now, NULL); timevect[i] = now.tv_usec + now.tv_sec * 1000000; ! #ifdef VIDEO ! while (gtk_events_pending()) { ! gtk_main_iteration_do(FALSE); ! } ! #endif ! if (gtk_events_pending()) { ! gtk_main_iteration_do(FALSE); ! } if (!file_end()) { moreframes = GetMPEGFrame(rgbbuff); --- 184,188 ---- gettimeofday(&now, NULL); timevect[i] = now.tv_usec + now.tv_sec * 1000000; ! events_update(); if (!file_end()) { moreframes = GetMPEGFrame(rgbbuff); *************** *** 195,208 **** file_set_end(); } ! frame_display(c, &img, rgbbuff); } l = qman_howlate(0); // timevect2[i] = l; l = l / 5000; ! if (l > MAXSLIDE) { ! l = MAXSLIDE; ! } ! gtk_progress_bar_update(GTK_PROGRESS_BAR(c->prbar), ! (float) l / (float) MAXSLIDE); gettimeofday(&now, NULL); --- 190,199 ---- file_set_end(); } ! frame_display(c, &img, rgbbuff, myid); } l = qman_howlate(0); // timevect2[i] = l; l = l / 5000; ! pbar_update(c, l); gettimeofday(&now, NULL); Index: ppsdemo.c =================================================================== RCS file: /cvsroot/linux-hls/qosman/demos/ppsdemo.c,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** ppsdemo.c 9 Apr 2004 13:39:56 -0000 1.2 --- ppsdemo.c 25 Jul 2004 09:57:30 -0000 1.3 *************** *** 146,150 **** i = 0; ! c = window_prepare(img.Width, img.Height); cprintf("Starting...\n"); --- 146,150 ---- i = 0; ! c = window_prepare(&img); cprintf("Starting...\n"); *************** *** 165,169 **** file_set_end(); } ! frame_display(c, &img, rgbbuff); } l = qman_howlate(0); --- 165,169 ---- file_set_end(); } ! frame_display(c, &img, rgbbuff, num); } l = qman_howlate(0); --- NEW FILE: mpcore-fb.h --- #ifndef __MP_CORE_H__ #define __MP_CORE_H__ struct controls { int fb_size; int fb_line_len; int bpp; struct fb_cmap *old_cmap; int fbdev_fd; unsigned char *b; }; int file_end(void); void file_set_end(void); FILE *file_open(char *fname, ImageDesc *img); struct controls *window_prepare(ImageDesc *img); void frame_display(struct controls *c, ImageDesc *img, unsigned char *b, int i); void events_update(void); void pbar_update(struct controls *c, float l); #define output_init(a, b) #endif /* __MP_CORE_H__ */ Index: mpcore.c =================================================================== RCS file: /cvsroot/linux-hls/qosman/demos/mpcore.c,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** mpcore.c 9 Apr 2004 13:41:31 -0000 1.1 --- mpcore.c 25 Jul 2004 09:57:30 -0000 1.2 *************** *** 7,13 **** --- 7,36 ---- #include "mpcore.h" + #define MAXSLIDE 150 + static GdkPixmap *screen; static int end = 0; + + void events_update(void) + { + #ifdef VIDEO + while (gtk_events_pending()) { + gtk_main_iteration_do(FALSE); + } + #endif + if (gtk_events_pending()) { + gtk_main_iteration_do(FALSE); + } + } + + void pbar_update(struct controls *c, float l) + { + if (l > MAXSLIDE) { + l = MAXSLIDE; + } + gtk_progress_bar_update(GTK_PROGRESS_BAR(c->prbar), l / (float)MAXSLIDE); + } + int file_end(void) { *************** *** 20,24 **** } ! void frame_display(struct controls *c, ImageDesc *img, unsigned char *b) { gdk_draw_rgb_32_image(screen, c->gc, 0, 0, img->Width, img->Height, --- 43,47 ---- } ! void frame_display(struct controls *c, ImageDesc *img, unsigned char *b, int i) { gdk_draw_rgb_32_image(screen, c->gc, 0, 0, img->Width, img->Height, *************** *** 81,85 **** ! struct controls *window_prepare(int w, int h) { GdkGC *gc1; --- 104,108 ---- ! struct controls *window_prepare(ImageDesc *img) { GdkGC *gc1; *************** *** 105,109 **** window = gtk_window_new(GTK_WINDOW_TOPLEVEL); ! gtk_window_set_default_size(GTK_WINDOW(window), w, h + 50); vbox = gtk_vbox_new(FALSE, 0); --- 128,132 ---- window = gtk_window_new(GTK_WINDOW_TOPLEVEL); ! gtk_window_set_default_size(GTK_WINDOW(window), img->Width, img->Height + 50); vbox = gtk_vbox_new(FALSE, 0); *************** *** 118,122 **** //drawing area c->d_area = gtk_drawing_area_new(); ! gtk_drawing_area_size(GTK_DRAWING_AREA(c->d_area), w, h); expid = gtk_signal_connect(GTK_OBJECT(c->d_area), "expose_event", GTK_SIGNAL_FUNC(expose_event), NULL); --- 141,145 ---- //drawing area c->d_area = gtk_drawing_area_new(); ! gtk_drawing_area_size(GTK_DRAWING_AREA(c->d_area), img->Width, img->Height); expid = gtk_signal_connect(GTK_OBJECT(c->d_area), "expose_event", GTK_SIGNAL_FUNC(expose_event), NULL); Index: Makefile =================================================================== RCS file: /cvsroot/linux-hls/qosman/demos/Makefile,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** Makefile 9 Apr 2004 13:39:56 -0000 1.2 --- Makefile 25 Jul 2004 09:57:30 -0000 1.3 *************** *** 4,14 **** GTKLIB = `gtk-config --libs` O_OBJS = ! TESTS = mpdemo ppsdemo all: $(TESTS) mpdemo: mpcore.o qtest.o mpdemo.o ../libqos.a gcc qtest.o mpdemo.o mpcore.o -L.. -lqos -L../../lib -lmpeg $(GTKLIB) -o mpdemo ppsdemo: mpcore.o test1.o ppsdemo.o ../libqos.a gcc test1.o mpcore.o ppsdemo.o -L.. -lqos -L../../lib -lmpeg $(GTKLIB) -o ppsdemo --- 4,20 ---- GTKLIB = `gtk-config --libs` O_OBJS = ! TESTS = mpdemo ppsdemo mpdemo-fb txtdemo all: $(TESTS) + mpdemo-fb.o: mpdemo.c + $(CC) $(CFLAGS) -D__FB__ -c mpdemo.c -o mpdemo-fb.o + mpdemo: mpcore.o qtest.o mpdemo.o ../libqos.a gcc qtest.o mpdemo.o mpcore.o -L.. -lqos -L../../lib -lmpeg $(GTKLIB) -o mpdemo + mpdemo-fb: mpcore-fb.o qtest.o mpdemo-fb.o ../libqos.a + gcc qtest.o mpdemo-fb.o mpcore-fb.o -L.. -lqos -L../../lib -lmpeg -o mpdemo-fb + ppsdemo: mpcore.o test1.o ppsdemo.o ../libqos.a gcc test1.o mpcore.o ppsdemo.o -L.. -lqos -L../../lib -lmpeg $(GTKLIB) -o ppsdemo *************** *** 22,27 **** clean: rm -rf *.o ! rm -rf mpdemo ! rm -rf ppsdemo ifeq (deps,$(wildcard deps)) --- 28,32 ---- clean: rm -rf *.o ! rm -rf $(TESTS) ifeq (deps,$(wildcard deps)) |