00001 /* 00002 * dv1394.h - DV input/output over IEEE 1394 on OHCI chips 00003 * Copyright (C)2001 Daniel Maas <dmaas@dcine.com> 00004 * receive, proc_fs by Dan Dennedy <dan@dennedy.org> 00005 * 00006 * based on: 00007 * video1394.h - driver for OHCI 1394 boards 00008 * Copyright (C)1999,2000 Sebastien Rougeaux <sebastien.rougeaux@anu.edu.au> 00009 * Peter Schlaile <udbz@rz.uni-karlsruhe.de> 00010 * 00011 * This program is free software; you can redistribute it and/or modify 00012 * it under the terms of the GNU Lesser Public License as published by 00013 * the Free Software Foundation; either version 2.1 of the License, or 00014 * (at your option) any later version. 00015 * 00016 * This program is distributed in the hope that it will be useful, 00017 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00018 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00019 * GNU Lesser Public License for more details. 00020 * 00021 * You should have received a copy of the GNU Lesser Public License 00022 * along with this program; if not, write to the Free Software Foundation, 00023 * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 00024 */ 00025 00026 #ifndef _DV_1394_H 00027 #define _DV_1394_H 00028 00029 #include <sys/types.h> 00030 #include <sys/ioctl.h> 00031 00032 /* This is the public user-space interface. Try not to break it. */ 00033 00034 #define DV1394_API_VERSION 0x20011127 00035 00036 /* ******************** 00037 ** ** 00038 ** DV1394 API ** 00039 ** ** 00040 ******************** 00041 00042 There are two methods of operating the DV1394 DV output device. 00043 00044 1) 00045 00046 The simplest is an interface based on write(): simply write 00047 full DV frames of data to the device, and they will be transmitted 00048 as quickly as possible. The FD may be set for non-blocking I/O, 00049 in which case you can use select() or poll() to wait for output 00050 buffer space. 00051 00052 To set the DV output parameters (e.g. whether you want NTSC or PAL 00053 video), use the DV1394_INIT ioctl, passing in the parameters you 00054 want in a struct dv1394_init. 00055 00056 Example 1: 00057 To play a raw .DV file: cat foo.DV > /dev/dv1394 00058 (cat will use write() internally) 00059 00060 Example 2: 00061 static struct dv1394_init init = { 00062 0x63, (broadcast channel) 00063 4, (four-frame ringbuffer) 00064 DV1394_NTSC, (send NTSC video) 00065 0, 0 (default empty packet rate) 00066 } 00067 00068 ioctl(fd, DV1394_INIT, &init); 00069 00070 while(1) { 00071 read( <a raw DV file>, buf, DV1394_NTSC_FRAME_SIZE ); 00072 write( <the dv1394 FD>, buf, DV1394_NTSC_FRAME_SIZE ); 00073 } 00074 00075 2) 00076 00077 For more control over buffering, and to avoid unnecessary copies 00078 of the DV data, you can use the more sophisticated the mmap() interface. 00079 First, call the DV1394_INIT ioctl to specify your parameters, 00080 including the number of frames in the ringbuffer. Then, calling mmap() 00081 on the dv1394 device will give you direct access to the ringbuffer 00082 from which the DV card reads your frame data. 00083 00084 The ringbuffer is simply one large, contiguous region of memory 00085 containing two or more frames of packed DV data. Each frame of DV data 00086 is 120000 bytes (NTSC) or 144000 bytes (PAL). 00087 00088 Fill one or more frames in the ringbuffer, then use the DV1394_SUBMIT_FRAMES 00089 ioctl to begin I/O. You can use either the DV1394_WAIT_FRAMES ioctl 00090 or select()/poll() to wait until the frames are transmitted. Next, you'll 00091 need to call the DV1394_GET_STATUS ioctl to determine which ringbuffer 00092 frames are clear (ready to be filled with new DV data). Finally, use 00093 DV1394_SUBMIT_FRAMES again to send the new data to the DV output. 00094 00095 00096 Example: here is what a four-frame ringbuffer might look like 00097 during DV transmission: 00098 00099 00100 frame 0 frame 1 frame 2 frame 3 00101 00102 *--------------------------------------* 00103 | CLEAR | DV data | DV data | CLEAR | 00104 *--------------------------------------* 00105 <ACTIVE> 00106 00107 transmission goes in this direction --->>> 00108 00109 00110 The DV hardware is currently transmitting the data in frame 1. 00111 Once frame 1 is finished, it will automatically transmit frame 2. 00112 (if frame 2 finishes before frame 3 is submitted, the device 00113 will continue to transmit frame 2, and will increase the dropped_frames 00114 counter each time it repeats the transmission). 00115 00116 00117 If you called DV1394_GET_STATUS at this instant, you would 00118 receive the following values: 00119 00120 n_frames = 4 00121 active_frame = 1 00122 first_clear_frame = 3 00123 n_clear_frames = 2 00124 00125 At this point, you should write new DV data into frame 3 and optionally 00126 frame 0. Then call DV1394_SUBMIT_FRAMES to inform the device that 00127 it may transmit the new frames. 00128 00129 */ 00130 00131 00132 /* maximum number of frames in the ringbuffer */ 00133 #define DV1394_MAX_FRAMES 32 00134 00135 /* number of *full* isochronous packets per DV frame */ 00136 #define DV1394_NTSC_PACKETS_PER_FRAME 250 00137 #define DV1394_PAL_PACKETS_PER_FRAME 300 00138 00139 /* size of one frame's worth of DV data, in bytes */ 00140 #define DV1394_NTSC_FRAME_SIZE (480 * DV1394_NTSC_PACKETS_PER_FRAME) 00141 #define DV1394_PAL_FRAME_SIZE (480 * DV1394_PAL_PACKETS_PER_FRAME) 00142 00143 00144 enum pal_or_ntsc { 00145 DV1394_NTSC = 0, 00146 DV1394_PAL 00147 }; 00148 00149 00150 /* this is the argument to DV1394_INIT */ 00151 struct dv1394_init { 00152 /* DV1394_API_VERSION */ 00153 unsigned int api_version; 00154 00155 /* isochronous transmission channel to use */ 00156 unsigned int channel; 00157 00158 /* number of frames in the ringbuffer. Must be at least 2 00159 and at most DV1394_MAX_FRAMES. */ 00160 unsigned int n_frames; 00161 00162 /* send/receive PAL or NTSC video format */ 00163 enum pal_or_ntsc format; 00164 00165 /* the following are used only for transmission */ 00166 00167 /* set these to zero unless you want a 00168 non-default empty packet rate (see below) */ 00169 unsigned long cip_n; 00170 unsigned long cip_d; 00171 00172 /* set this to zero unless you want a 00173 non-default SYT cycle offset (default = 3 cycles) */ 00174 unsigned int syt_offset; 00175 }; 00176 00177 /* Q: What are cip_n and cip_d? */ 00178 00179 /* 00180 A: DV video streams do not utilize 100% of the potential bandwidth offered 00181 by IEEE 1394 (FireWire). To achieve the correct rate of data transmission, 00182 DV devices must periodically insert empty packets into the 1394 data stream. 00183 Typically there is one empty packet per 14-16 data-carrying packets. 00184 00185 Some DV devices will accept a wide range of empty packet rates, while others 00186 require a precise rate. If the dv1394 driver produces empty packets at 00187 a rate that your device does not accept, you may see ugly patterns on the 00188 DV output, or even no output at all. 00189 00190 The default empty packet insertion rate seems to work for many people; if 00191 your DV output is stable, you can simply ignore this discussion. However, 00192 we have exposed the empty packet rate as a parameter to support devices that 00193 do not work with the default rate. 00194 00195 The decision to insert an empty packet is made with a numerator/denominator 00196 algorithm. Empty packets are produced at an average rate of CIP_N / CIP_D. 00197 You can alter the empty packet rate by passing non-zero values for cip_n 00198 and cip_d to the INIT ioctl. 00199 00200 */ 00201 00202 struct dv1394_status { 00203 /* this embedded init struct returns the current dv1394 00204 parameters in use */ 00205 struct dv1394_init init; 00206 00207 /* the ringbuffer frame that is currently being 00208 displayed. (-1 if the device is not transmitting anything) */ 00209 int active_frame; 00210 00211 /* index of the first buffer (ahead of active_frame) that 00212 is ready to be filled with data */ 00213 unsigned int first_clear_frame; 00214 00215 /* how many buffers, including first_clear_buffer, are 00216 ready to be filled with data */ 00217 unsigned int n_clear_frames; 00218 00219 /* how many times the DV output has underflowed 00220 since the last call to DV1394_GET_STATUS */ 00221 unsigned int dropped_frames; 00222 00223 /* N.B. The dropped_frames counter is only a lower bound on the actual 00224 number of dropped frames, with the special case that if dropped_frames 00225 is zero, then it is guaranteed that NO frames have been dropped 00226 since the last call to DV1394_GET_STATUS. 00227 */ 00228 }; 00229 00230 /* Get the driver ready to transmit video. pass a struct dv1394_init* as 00231 * the parameter (see below), or NULL to get default parameters */ 00232 #define DV1394_INIT _IOW('#', 0x06, struct dv1394_init) 00233 00234 /* Stop transmitting video and free the ringbuffer */ 00235 #define DV1394_SHUTDOWN _IO ('#', 0x07) 00236 00237 /* Submit N new frames to be transmitted, where the index of the first new 00238 * frame is first_clear_buffer, and the index of the last new frame is 00239 * (first_clear_buffer + N) % n_frames */ 00240 #define DV1394_SUBMIT_FRAMES _IO ('#', 0x08) 00241 00242 /* Block until N buffers are clear (pass N as the parameter) Because we 00243 * re-transmit the last frame on underrun, there will at most be n_frames 00244 * - 1 clear frames at any time */ 00245 #define DV1394_WAIT_FRAMES _IO ('#', 0x09) 00246 00247 /* Capture new frames that have been received, where the index of the 00248 * first new frame is first_clear_buffer, and the index of the last new 00249 * frame is (first_clear_buffer + N) % n_frames */ 00250 #define DV1394_RECEIVE_FRAMES _IO ('#', 0x0a) 00251 00252 /* Tell card to start receiving DMA */ 00253 #define DV1394_START_RECEIVE _IO ('#', 0x0b) 00254 00255 /* Pass a struct dv1394_status* as the parameter */ 00256 #define DV1394_GET_STATUS _IOR('#', 0x0c, struct dv1394_status) 00257 00258 #endif /* _DV_1394_H */
1.4.2