rtsp_rtp.c: Add missing avstring include for av_strlcpy
[mplayer.git] / vidix / sysdep / libdha_win32.c
blobf3c287f92fd6b0383b40586961080da896e53963
1 /*
2 * MAPDEV.h - include file for VxD MAPDEV
3 * Copyright (c) 1996 Vireo Software, Inc.
4 * Modified for libdha by Nick Kurshev.
6 * This file is part of MPlayer.
8 * MPlayer is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * MPlayer is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License along
19 * with MPlayer; if not, write to the Free Software Foundation, Inc.,
20 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
23 #include <windows.h>
24 #include <ddk/ntddk.h>
25 #include "vidix/dhahelperwin/dhahelper.h"
28 This is the request structure that applications use
29 to request services from the MAPDEV VxD.
32 typedef struct MapDevRequest
34 DWORD mdr_ServiceID; /* supplied by caller */
35 LPVOID mdr_PhysicalAddress; /* supplied by caller */
36 DWORD mdr_SizeInBytes; /* supplied by caller */
37 LPVOID mdr_LinearAddress; /* returned by VxD */
38 WORD mdr_Selector; /* returned if 16-bit caller */
39 WORD mdr_Status; /* MDR_xxxx code below */
40 } MAPDEVREQUEST, *PMAPDEVREQUEST;
42 #define MDR_SERVICE_MAP CTL_CODE(FILE_DEVICE_UNKNOWN, 1, METHOD_NEITHER, FILE_ANY_ACCESS)
43 #define MDR_SERVICE_UNMAP CTL_CODE(FILE_DEVICE_UNKNOWN, 2, METHOD_NEITHER, FILE_ANY_ACCESS)
45 #define MDR_STATUS_SUCCESS 1
46 #define MDR_STATUS_ERROR 0
47 /*#include "winioctl.h"*/
48 #define FILE_DEVICE_UNKNOWN 0x00000022
49 #define METHOD_NEITHER 3
52 int IsWinNT(void) {
53 OSVERSIONINFO OSVersionInfo;
54 OSVersionInfo.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
55 GetVersionEx(&OSVersionInfo);
56 return OSVersionInfo.dwPlatformId == VER_PLATFORM_WIN32_NT;
59 static HANDLE hDriver = INVALID_HANDLE_VALUE;
62 /* Memory Map a piece of Real Memory */
63 void *map_phys_mem(unsigned long base, unsigned long size) {
64 if(!IsWinNT()){
65 HANDLE hDevice ;
66 PVOID inBuf[1] ; /* buffer for struct pointer to VxD */
67 DWORD cbBytesReturned ; /* count of bytes returned from VxD */
68 MAPDEVREQUEST req ; /* map device request structure */
69 const PCHAR VxDName = "\\\\.\\MAPDEV.VXD" ;
70 const PCHAR VxDNameAlreadyLoaded = "\\\\.\\MAPDEV" ;
72 hDevice = CreateFile(VxDName, 0,0,0,
73 CREATE_NEW, FILE_FLAG_DELETE_ON_CLOSE, 0) ;
74 if (hDevice == INVALID_HANDLE_VALUE)
75 hDevice = CreateFile(VxDNameAlreadyLoaded, 0,0,0,
76 CREATE_NEW, FILE_FLAG_DELETE_ON_CLOSE, 0) ;
77 if (hDevice == INVALID_HANDLE_VALUE) {
78 fprintf(stderr, "Cannot open driver, error=%08lx\n", GetLastError()) ;
79 exit(1) ; }
81 req.mdr_ServiceID = MDR_SERVICE_MAP ;
82 req.mdr_PhysicalAddress = (PVOID)base ;
83 req.mdr_SizeInBytes = size ;
84 inBuf[0] = &req ;
86 if ( ! DeviceIoControl(hDevice, MDR_SERVICE_MAP, inBuf, sizeof(PVOID),
87 NULL, 0, &cbBytesReturned, NULL) ) {
88 fprintf(stderr, "Failed to map device\n") ; exit(1) ; }
90 return (void*)req.mdr_LinearAddress ;
92 else{
93 dhahelper_t dhahelper_priv;
94 DWORD dwBytesReturned;
95 dhahelper_priv.size = size;
96 dhahelper_priv.base = base;
97 if(hDriver==INVALID_HANDLE_VALUE)hDriver = CreateFile("\\\\.\\DHAHELPER",GENERIC_READ | GENERIC_WRITE,0,NULL,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,NULL);
98 if (!DeviceIoControl(hDriver, IOCTL_DHAHELPER_MAPPHYSTOLIN, &dhahelper_priv,sizeof(dhahelper_t), &dhahelper_priv, sizeof(dhahelper_t),&dwBytesReturned, NULL)){
99 fprintf(stderr,"Unable to map the requested memory region.\n");
100 return NULL;
102 else return dhahelper_priv.ptr;
106 void unmap_phys_mem(void *ptr, unsigned long size) {
107 if(IsWinNT()){
108 dhahelper_t dhahelper_priv;
109 DWORD dwBytesReturned;
110 dhahelper_priv.ptr = ptr;
111 DeviceIoControl(hDriver, IOCTL_DHAHELPER_UNMAPPHYSADDR, &dhahelper_priv,sizeof(dhahelper_t), NULL, 0, &dwBytesReturned, NULL);