POSIX.Memory_Mapping.Map_Memory
From: Adrian Hoe (byhoe_at_greenlime.com)
Date: 01/29/05
- Next message: Mark Lorenzen: "Re: POSIX.Memory_Mapping.Map_Memory"
- Previous message: Stefan Merwitz: "Re: Input a string (again)"
- Next in thread: Mark Lorenzen: "Re: POSIX.Memory_Mapping.Map_Memory"
- Reply: Mark Lorenzen: "Re: POSIX.Memory_Mapping.Map_Memory"
- Maybe reply: zhenggen: "Fw: POSIX.Memory_Mapping.Map_Memory"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: 29 Jan 2005 07:58:27 -0800
Hi,
I am working on video_device with Video_4_Linux based on the work of
Anders Gidenstam. According to latest V4L documentation, capturing with
Read has been deprecated and the only method now is by the use of mmap.
I open a device and read the device with the following procedures, Open
and Map_Image as below. In Procedure Map_Image, I make a call to
Map_Memory (POSIX.Memory_Mapping) and raise an exception:
POSIX.POSIX_ERROR : PERMISSION_DENIED
-----------------------------------------------------------------------
...
type Intensity is new Natural range 0..255;
for Intensity'Size use 8;
type Bitmap is array (Positive range <>) of Intensity;
type Bitmap_Access is access Bitmap;
...
private
type Image_Type is new Ada.Finalization.Controlled with
record
Class : Image_Class;
Width : Natural := 0;
Height : Natural := 0;
BM : Bitmap_Access := null;
end record;
------------------------------------------------------------------------
procedure Open (Device : out Video_Device;
File_Name : in String) is
Win : Video_Window;
begin
if Is_Character_Special_File (To_POSIX_String (File_Name)) then
Device.Fd := Open (To_POSIX_String (File_Name),
Read_Only);
Get_Capture_Window (Device, Win);
Device.Width := Win.Width;
Device.Height := Win.Height;
else
raise IO_Error;
end if;
end Open;
-- Close video device.
procedure Close (Device : in Video_Device) is
begin
POSIX.IO.Close (Device.Fd);
Put_Line ("Device closed");
end Close;
-- Map image
procedure Map_Image (Device : in Video_Device;
Image : in out Image_Type) is
package Convert is new System.Address_To_Access_Conversions
(Bitmap_Access);
use Convert;
Buf_Size : Natural;
begin
if Get_Width (Image) /= Device.Width or
Get_Height (Image) /= Device.Height then
case Get_Class (Image) is
when Grey =>
Buf_Size := Device.Width * Device.Height;
when Color =>
Buf_Size := Device.Width * Device.Height * 3;
end case;
declare
Map : System.Address;
begin
-- Permission Denied exception was raised here at the line below!!!
Map := Map_Memory (System.Storage_Elements.Storage_Offset
(Buf_Size),
POSIX.Memory_Mapping.Allow_Read +
POSIX.Memory_Mapping.Allow_Write,
POSIX.Memory_Mapping.Map_Shared,
Device.Fd,
0);
Set_Bitmap (Image,
Device.Width,
Device.Height,
Bitmap_Access (Convert.To_Pointer (Map).all));
end;
end if;
end Map_Image;
--------------------------------------------------------------------------
What could I have missed? Any pointer please?
Best regards,
-- Adrian Hoe
- Next message: Mark Lorenzen: "Re: POSIX.Memory_Mapping.Map_Memory"
- Previous message: Stefan Merwitz: "Re: Input a string (again)"
- Next in thread: Mark Lorenzen: "Re: POSIX.Memory_Mapping.Map_Memory"
- Reply: Mark Lorenzen: "Re: POSIX.Memory_Mapping.Map_Memory"
- Maybe reply: zhenggen: "Fw: POSIX.Memory_Mapping.Map_Memory"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]