2 * Copyright (c) 2003 by Siarzuk Zharski <imker@gmx.li>
4 * This file may be used under the terms of the BSD License
6 * Skeletal part of this code was inherired from original BeOS sample code,
7 * that is distributed under the terms of the Be Sample Code License.
11 #include <support/Autolock.h>
12 #include <media/MediaFormats.h>
24 MediaAddOn::MediaAddOn(image_id imid
)
27 /* Customize these parameters to match those of your node */
28 fFlavorInfo
.name
= "USB Vision";
29 fFlavorInfo
.info
= "USB Vision";
30 fFlavorInfo
.kinds
= B_BUFFER_PRODUCER
| B_CONTROLLABLE
| B_PHYSICAL_INPUT
;
31 fFlavorInfo
.flavor_flags
= 0;
32 fFlavorInfo
.internal_id
= 0;
33 fFlavorInfo
.possible_count
= 1;
34 fFlavorInfo
.in_format_count
= 0;
35 fFlavorInfo
.in_format_flags
= 0;
36 fFlavorInfo
.in_formats
= NULL
;
37 fFlavorInfo
.out_format_count
= 1;
38 fFlavorInfo
.out_format_flags
= 0;
39 fMediaFormat
.type
= B_MEDIA_RAW_VIDEO
;
40 fMediaFormat
.u
.raw_video
= media_raw_video_format::wildcard
;
41 fMediaFormat
.u
.raw_video
.interlace
= 1;
42 fMediaFormat
.u
.raw_video
.display
.format
= B_RGB32
;
43 fFlavorInfo
.out_formats
= &fMediaFormat
;
45 fInitStatus
= B_NO_INIT
;
52 MediaAddOn::~MediaAddOn()
54 if(fInitStatus
== B_OK
){
61 MediaAddOn::InitCheck(const char **out_failure_text
)
63 if (fInitStatus
< B_OK
) {
64 *out_failure_text
= "Unknown error";
72 MediaAddOn::CountFlavors()
74 if (fInitStatus
< B_OK
)
77 /* This addon only supports a single flavor, as defined in the
83 * The pointer to the flavor received only needs to be valid between
84 * successive calls to BMediaAddOn::GetFlavorAt().
87 MediaAddOn::GetFlavorAt(int32 n
, const flavor_info
**out_info
)
89 if (fInitStatus
< B_OK
)
95 /* Return the flavor defined in the constructor */
96 *out_info
= &fFlavorInfo
;
101 MediaAddOn::InstantiateNodeFor(
102 const flavor_info
*info
, BMessage
*config
, status_t
*out_error
)
106 if (fInitStatus
< B_OK
)
109 if (info
->internal_id
!= fFlavorInfo
.internal_id
)
112 /* At most one instance of the node should be instantiated at any given
113 * time. The locking for this restriction may be found in the VideoProducer
115 node
= new VideoProducer(this, fFlavorInfo
.name
, fFlavorInfo
.internal_id
);
116 if (node
&& (node
->InitCheck() < B_OK
)) {
125 make_media_addon(image_id imid
)
127 return new MediaAddOn(imid
);
130 bool MediaAddOn::USBVisionInit()
132 //TODO - support for multiple devices !!!
133 fDriverFD
= open("/dev/video/usb_vision/0", O_RDWR
);
135 fInitStatus
= ENODEV
;
136 return (fDriverFD
>= 0);
139 void MediaAddOn::USBVisionUninit()
140 { //TODO - correct work on detach device from usb port ...
144 status_t
MediaAddOn::USBVisionWriteRegister(uint8 reg
, uint8
*data
, uint8 len
/*= sizeof(uint8)*/)
146 status_t status
= ENODEV
;
148 xet_nt100x_reg ri
= {reg
, len
};
149 memcpy(ri
.data
, data
, len
);
150 status
= ioctl(fDriverFD
, NT_IOCTL_WRITE_REGISTER
, &ri
, sizeof(ri
));
155 status_t
MediaAddOn::USBVisionReadRegister(uint8 reg
, uint8
*data
, uint8 len
/* = sizeof(uint8)*/)
157 status_t status
= ENODEV
;
159 xet_nt100x_reg ri
= {reg
, len
};
160 if((status
= ioctl(fDriverFD
, NT_IOCTL_READ_REGISTER
, &ri
, sizeof(ri
))) == B_OK
){
161 memcpy(data
, ri
.data
, ri
.data_length
);