📄 idirectfbvideoprovider_openquicktime.c
字号:
/* (c) Copyright 2001 convergence integrated media GmbH. All rights reserved. Written by Denis Oliver Kropp <dok@convergence.de>, Andreas Hundt <andi@convergence.de> and Sven Neumann <sven@convergence.de>. This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.*/#include <stdio.h>#include <stdlib.h>#include <unistd.h>#include <string.h>#include <malloc.h>#include <sys/types.h>#include <sys/time.h>#include <sys/stat.h>#include <sys/ioctl.h>#include <fcntl.h>#include <sys/soundcard.h>#include <pthread.h>#include <directfb.h>#include <directfb_internals.h>#include <misc/util.h>#include <misc/mem.h>#include <core/coredefs.h>#include <core/coretypes.h>#include <core/layers.h>#include <core/state.h>#include <core/surfaces.h>#include <core/gfxcard.h>#include <gfx/convert.h>#include <display/idirectfbsurface.h>#include <openquicktime/openquicktime.h>#include <openquicktime/colormodels.h>static DFBResultProbe( const char *filename );static DFBResultConstruct( IDirectFBVideoProvider *thiz, const char *filename );#include <interface_implementation.h>DFB_INTERFACE_IMPLEMENTATION( IDirectFBVideoProvider, OpenQuicktime )/* * private data struct of IDirectFBVideoProvider */typedef struct { int ref; /* reference counter */ char *filename; quicktime_t *file; struct { int width; int height; float rate; long length; unsigned char *buffer; int yuv; int playing; int seeked; pthread_t thread; pthread_mutex_t lock; } video; struct { int available; int bits; long rate; int channels; long length; int fd; int block_size; int samples_per_block; int playing; int seeked; pthread_t thread; pthread_mutex_t lock; } audio; struct { int supported; unsigned char **lines; } rgb; struct { int supported; unsigned char *lines[3]; } yuv; IDirectFBSurface *destination; DFBRectangle dest_rect; DFBRectangle dest_clip; DVFrameCallback callback; void *ctx;} IDirectFBVideoProvider_OpenQuicktime_data;/* OSS sound playback */static DFBResult OpenSound ( IDirectFBVideoProvider_OpenQuicktime_data *data );static DFBResult CloseSound( IDirectFBVideoProvider_OpenQuicktime_data *data );/* interface implementation */static voidIDirectFBVideoProvider_OpenQuicktime_Destruct( IDirectFBVideoProvider *thiz ){ IDirectFBVideoProvider_OpenQuicktime_data *data; data = (IDirectFBVideoProvider_OpenQuicktime_data*)thiz->priv; thiz->Stop( thiz );#ifdef SEGFAULTS_IN_OPENQUICKTIME quicktime_close( data->file );#endif DFBFREE( data->video.buffer ); DFBFREE( data->rgb.lines ); pthread_mutex_destroy( &data->video.lock ); pthread_mutex_destroy( &data->audio.lock ); DFBFREE( data->filename ); DFBFREE( thiz->priv ); thiz->priv = NULL;#ifndef DFB_DEBUG DFBFREE( thiz );#endif}static DFBResultIDirectFBVideoProvider_OpenQuicktime_AddRef( IDirectFBVideoProvider *thiz ){ INTERFACE_GET_DATA (IDirectFBVideoProvider_OpenQuicktime) data->ref++; return DFB_OK;}static DFBResultIDirectFBVideoProvider_OpenQuicktime_Release( IDirectFBVideoProvider *thiz ){ INTERFACE_GET_DATA (IDirectFBVideoProvider_OpenQuicktime) if (--data->ref == 0) { IDirectFBVideoProvider_OpenQuicktime_Destruct( thiz ); } return DFB_OK;}static DFBResultIDirectFBVideoProvider_OpenQuicktime_GetCapabilities( IDirectFBVideoProvider *thiz, DFBVideoProviderCapabilities *caps ){ INTERFACE_GET_DATA (IDirectFBVideoProvider_OpenQuicktime) if (!caps) return DFB_INVARG; *caps = DVCAPS_BASIC | DVCAPS_SEEK; return DFB_OK;}static DFBResultIDirectFBVideoProvider_OpenQuicktime_GetSurfaceDescription( IDirectFBVideoProvider *thiz, DFBSurfaceDescription *desc ){ INTERFACE_GET_DATA (IDirectFBVideoProvider_OpenQuicktime) if (!desc) return DFB_INVARG; desc->flags = DSDESC_WIDTH | DSDESC_HEIGHT | DSDESC_PIXELFORMAT; desc->width = quicktime_video_width( data->file, 0 ); desc->height = quicktime_video_height( data->file, 0 ); desc->pixelformat = DSPF_YUY2; return DFB_OK;}static voidRGB888_to_RGB332( void *d, void *s, int len ){ int i; __u8 *dst = (__u8*) d; __u8 *src = (__u8*) s; for (i=0; i<len; i++) { dst[i] = PIXEL_RGB332( src[0], src[1], src[2] ); src += 3; }}static voidRGB888_to_RGB15( void *d, void *s, int len ){ int i; __u16 *dst = (__u16*) d; __u8 *src = (__u8*) s; for (i=0; i<len; i++) { dst[i] = PIXEL_RGB15( src[0], src[1], src[2] ); src += 3; }}static voidRGB888_to_RGB16( void *d, void *s, int len ){ int i; __u16 *dst = (__u16*) d; __u8 *src = (__u8*) s; for (i=0; i<len; i++) { dst[i] = PIXEL_RGB16( src[0], src[1], src[2] ); src += 3; }}static voidRGB888_to_RGB24( void *d, void *s, int len ){ int i; __u8 *dst = (__u8*) d; __u8 *src = (__u8*) s; for (i=0; i<len*3; i+=3) { dst[i+0] = src[i+2]; dst[i+1] = src[i+1]; dst[i+2] = src[i+0]; }}static voidRGB888_to_RGB32( void *d, void *s, int len ){ int i; __u32 *dst = (__u32*) d; __u8 *src = (__u8*) s; for (i=0; i<len; i++) { dst[i] = PIXEL_RGB32( src[0], src[1], src[2] ); src += 3; }}static voidRGB888_to_ARGB( void *d, void *s, int len ){ int i; __u32 *dst = (__u32*) d; __u8 *src = (__u8*) s; for (i=0; i<len; i++) { dst[i] = PIXEL_ARGB( 0xff, src[0], src[1], src[2] ); src += 3; }}static voidWriteRGBFrame( IDirectFBVideoProvider_OpenQuicktime_data *data ){ unsigned char *ptr; unsigned int pitch; CoreSurface *surface; IDirectFBSurface_data *dst_data; int i, off_x, off_y; dst_data = (IDirectFBSurface_data*) data->destination->priv; surface = dst_data->surface; dfb_surface_soft_lock( surface, DSLF_WRITE, (void**)&ptr, &pitch, 0 ); ptr += data->dest_clip.y * pitch + data->dest_clip.x * DFB_BYTES_PER_PIXEL (surface->format); off_x = data->dest_clip.x - data->dest_rect.x; off_y = data->dest_clip.y - data->dest_rect.y; switch (surface->format) { case DSPF_RGB332: for (i=off_y; i<data->dest_clip.h; i++) { RGB888_to_RGB332( ptr, data->rgb.lines[i] + off_x * 4, data->dest_clip.w ); ptr += pitch; } break; case DSPF_RGB15: for (i=off_y; i<data->dest_clip.h; i++) { RGB888_to_RGB15( ptr, data->rgb.lines[i] + off_x * 4, data->dest_clip.w ); ptr += pitch; } break; case DSPF_RGB16: for (i=off_y; i<data->dest_clip.h; i++) { RGB888_to_RGB16( ptr, data->rgb.lines[i] + off_x * 4, data->dest_clip.w ); ptr += pitch; } break; case DSPF_RGB24: for (i=off_y; i<data->dest_clip.h; i++) { RGB888_to_RGB24( ptr, data->rgb.lines[i] + off_x * 4, data->dest_clip.w ); ptr += pitch; } break; case DSPF_RGB32: for (i=off_y; i<data->dest_clip.h; i++) { RGB888_to_RGB32( ptr, data->rgb.lines[i] + off_x * 4, data->dest_clip.w ); ptr += pitch; } break; case DSPF_ARGB: for (i=off_y; i<data->dest_clip.h; i++) { RGB888_to_ARGB( ptr, data->rgb.lines[i] + off_x * 4, data->dest_clip.w ); ptr += pitch; } break; default: break; } dfb_surface_unlock( dst_data->surface, 0 );}static void
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -