📄 video_out_dx.c
字号:
/* * video_out_dx.c * Copyright (C) 2000-2003 Michel Lespinasse <walken@zoy.org> * * Contributed by Gildas Bazin <gbazin@netcourrier.com> * * This file is part of mpeg2dec, a free MPEG-2 video stream decoder. * See http://libmpeg2.sourceforge.net/ for updates. * * mpeg2dec is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * mpeg2dec 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 General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */#include "config.h"#ifdef LIBVO_DX#include <stdio.h>#include <stdlib.h>#include <string.h>#include <inttypes.h>#include "mpeg2.h"#include "video_out.h"#include "mpeg2convert.h"#include <ddraw.h>#include <initguid.h>#define USE_OVERLAY_TRIPLE_BUFFERING 0/* * DirectDraw GUIDs. * Defining them here allows us to get rid of the dxguid library during link. */DEFINE_GUID (IID_IDirectDraw2, 0xB3A6F3E0,0x2B43,0x11CF,0xA2,0xDE,0x00,0xAA,0x00,0xB9,0x33,0x56);DEFINE_GUID (IID_IDirectDrawSurface2, 0x57805885,0x6eec,0x11cf,0x94,0x41,0xa8,0x23,0x03,0xc1,0x0e,0x27);#define FOURCC_YV12 0x32315659typedef struct { vo_instance_t vo; int width; int height; HWND window; RECT window_coords; HINSTANCE hddraw_dll; LPDIRECTDRAW2 ddraw; LPDIRECTDRAWSURFACE2 display; LPDIRECTDRAWCLIPPER clipper; LPDIRECTDRAWSURFACE2 frame[3]; int index; LPDIRECTDRAWSURFACE2 overlay; uint8_t * yuv[3]; int stride;} dx_instance_t;static void update_overlay (dx_instance_t * instance){ DDOVERLAYFX ddofx; DWORD dwFlags; memset (&ddofx, 0, sizeof (DDOVERLAYFX)); ddofx.dwSize = sizeof (DDOVERLAYFX); dwFlags = DDOVER_SHOW | DDOVER_KEYDESTOVERRIDE; IDirectDrawSurface2_UpdateOverlay (instance->overlay, NULL, instance->display, &instance->window_coords, dwFlags, &ddofx);}static long FAR PASCAL event_procedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam){ RECT rect_window; POINT point_window; dx_instance_t * instance; switch (message) { case WM_WINDOWPOSCHANGED: instance = (dx_instance_t *) GetWindowLong (hwnd, GWL_USERDATA); /* update the window position and size */ point_window.x = 0; point_window.y = 0; ClientToScreen (hwnd, &point_window); instance->window_coords.left = point_window.x; instance->window_coords.top = point_window.y; GetClientRect (hwnd, &rect_window); instance->window_coords.right = rect_window.right + point_window.x; instance->window_coords.bottom = rect_window.bottom + point_window.y; /* update the overlay */ if (instance->overlay && instance->display) update_overlay (instance); return 0; case WM_CLOSE: /* forbid the user to close the window */ return 0; case WM_DESTROY: /* just destroy the window */ PostQuitMessage (0); return 0; } return DefWindowProc (hwnd, message, wParam, lParam);}static void check_events (dx_instance_t * instance){ MSG msg; while (PeekMessage (&msg, instance->window, 0, 0, PM_REMOVE)) { TranslateMessage (&msg); DispatchMessage (&msg); }}static int create_window (dx_instance_t * instance){ RECT rect_window; WNDCLASSEX wc; wc.cbSize = sizeof (WNDCLASSEX); wc.style = CS_DBLCLKS; wc.lpfnWndProc = (WNDPROC) event_procedure; wc.cbClsExtra = 0; wc.cbWndExtra = 0; wc.hInstance = GetModuleHandle (NULL); wc.hIcon = NULL; wc.hCursor = LoadCursor (NULL, IDC_ARROW); wc.hbrBackground = CreateSolidBrush (RGB (0, 0, 0)); wc.lpszMenuName = NULL; wc.lpszClassName = "libvo_dx"; wc.hIconSm = NULL; if (!RegisterClassEx (&wc)) { fprintf (stderr, "Can not register window class\n"); return 1; } rect_window.top = 10; rect_window.left = 10; rect_window.right = rect_window.left + instance->width; rect_window.bottom = rect_window.top + instance->height; AdjustWindowRect (&rect_window, WS_OVERLAPPEDWINDOW|WS_SIZEBOX, 0); instance->window = CreateWindow ("libvo_dx", "mpeg2dec", WS_OVERLAPPEDWINDOW | WS_SIZEBOX, CW_USEDEFAULT, 0, rect_window.right - rect_window.left, rect_window.bottom - rect_window.top, NULL, NULL, GetModuleHandle (NULL), NULL); if (instance->window == NULL) { fprintf (stderr, "Can not create window\n"); return 1; } /* store a directx_instance pointer into the window local storage * (for later use in event_handler). * We need to use SetWindowLongPtr when it is available in mingw */ SetWindowLong (instance->window, GWL_USERDATA, (LONG) instance); ShowWindow (instance->window, SW_SHOW); return 0;}static LPDIRECTDRAWSURFACE2 alloc_surface (dx_instance_t * instance, DDSURFACEDESC * ddsd){ LPDIRECTDRAWSURFACE surface; LPDIRECTDRAWSURFACE2 surface2; if (DD_OK != IDirectDraw2_CreateSurface (instance->ddraw, ddsd, &surface, NULL) || DD_OK != IDirectDrawSurface_QueryInterface (surface, &IID_IDirectDrawSurface2, (LPVOID *) &surface2)) { fprintf (stderr, "Can not create directDraw frame surface\n"); return NULL; } IDirectDrawSurface_Release (surface); return surface2;}static int dx_init (dx_instance_t *instance){ HRESULT (WINAPI * OurDirectDrawCreate) (GUID *, LPDIRECTDRAW *, IUnknown *); LPDIRECTDRAW ddraw; DDSURFACEDESC ddsd; /* load direct draw DLL */ instance->hddraw_dll = LoadLibrary ("DDRAW.DLL"); if (instance->hddraw_dll == NULL) { fprintf (stderr, "Can not load DDRAW.DLL\n"); return 1; } ddraw = NULL; OurDirectDrawCreate = (void *) GetProcAddress (instance->hddraw_dll, "DirectDrawCreate"); if (OurDirectDrawCreate == NULL || DD_OK != OurDirectDrawCreate (NULL, &ddraw, NULL) || DD_OK != IDirectDraw_QueryInterface (ddraw, &IID_IDirectDraw2, (LPVOID *) &instance->ddraw) || DD_OK != IDirectDraw_SetCooperativeLevel (instance->ddraw, instance->window, DDSCL_NORMAL)) { fprintf (stderr, "Can not initialize directDraw interface\n"); return 1; } IDirectDraw_Release (ddraw); memset (&ddsd, 0, sizeof (DDSURFACEDESC)); ddsd.dwSize = sizeof (DDSURFACEDESC); ddsd.dwFlags = DDSD_CAPS; ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE; instance->display = alloc_surface (instance, &ddsd); if (instance->display == NULL) { fprintf (stderr, "Can not create directDraw display surface\n"); return 1; } if (DD_OK != IDirectDraw2_CreateClipper (instance->ddraw, 0, &instance->clipper, NULL) || DD_OK != IDirectDrawClipper_SetHWnd (instance->clipper, 0, instance->window) || DD_OK != IDirectDrawSurface_SetClipper (instance->display, instance->clipper)) { fprintf (stderr, "Can not initialize directDraw clipper\n"); return 1; } return 0;}static int common_setup (dx_instance_t * instance, int width, int height){ instance->width = width; instance->height = height; instance->index = 0; if (create_window (instance) || dx_init (instance)) return 1; return 0;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -