From: "Adrian Hoe" <byhoe@greenlime.com>
Subject: POSIX.Memory_Mapping.Map_Memory
Date: 29 Jan 2005 07:58:27 -0800
Date: 2005-01-29T07:58:27-08:00 [thread overview]
Message-ID: <1107014307.952357.216870@f14g2000cwb.googlegroups.com> (raw)
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 reply other threads:[~2005-01-29 15:58 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2005-01-29 15:58 Adrian Hoe [this message]
2005-01-29 16:20 ` POSIX.Memory_Mapping.Map_Memory Mark Lorenzen
2005-01-29 16:31 ` POSIX.Memory_Mapping.Map_Memory Adrian Hoe
2005-01-29 18:44 ` POSIX.Memory_Mapping.Map_Memory Mark Lorenzen
2005-01-30 2:45 ` POSIX.Memory_Mapping.Map_Memory Adrian Hoe
2005-01-30 2:48 ` POSIX.Memory_Mapping.Map_Memory Adrian Hoe
2005-01-30 15:39 ` POSIX.Memory_Mapping.Map_Memory Mark Lorenzen
2005-01-30 16:02 ` POSIX.Memory_Mapping.Map_Memory Adrian Hoe
2005-01-30 16:19 ` POSIX.Memory_Mapping.Map_Memory Mark Lorenzen
2005-01-30 16:36 ` POSIX.Memory_Mapping.Map_Memory Mark Lorenzen
2005-01-30 18:51 ` POSIX.Memory_Mapping.Map_Memory Florian Weimer
2005-02-27 6:59 ` POSIX.Memory_Mapping.Map_Memory Adrian Hoe
2005-02-27 13:03 ` POSIX.Memory_Mapping.Map_Memory Mark Lorenzen
2005-01-30 16:05 ` POSIX.Memory_Mapping.Map_Memory Adrian Hoe
2005-01-30 16:22 ` POSIX.Memory_Mapping.Map_Memory Mark Lorenzen
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox