4 * Copyright (C) 2008 Adam Williams <broadcast at earthling dot net>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 #ifndef DEVICE1394OUTPUT_H
23 #define DEVICE1394OUTPUT_H
29 #include "audiodevice.inc"
30 #include "condition.inc"
33 #include "ieee1394-ioctl.h"
37 #include "video1394.h"
38 #include "videodevice.inc"
40 // Common 1394 output for audio and video
42 // This runs continuously to keep the VTR warm.
43 // Takes encoded DV frames and PCM audio. Does the 1394 encryption on the fly.
44 class Device1394Output : public Thread
47 Device1394Output(VideoDevice *vdevice);
48 Device1394Output(AudioDevice *adevice);
64 // Write frame with timed blocking.
66 void write_frame(VFrame *input);
69 // Write audio with timed blocking.
71 void write_samples(char *data, int samples);
72 long get_audio_position();
76 // This object is shared between audio and video. Return what the driver is
77 // based on whether vdevice or adevice exists.
80 // Set IOCTL numbers based on kernel version
83 void encrypt(unsigned char *output,
88 void increment_counter(int *counter);
89 void decrement_counter(int *counter);
98 int current_outbuffer;
102 // Encoder for audio frames
106 // Block while waiting for the first buffer to be allocated
107 Condition *start_lock;
108 Mutex *position_lock;
110 // Provide timed blocking for writing routines.
112 Condition *video_lock;
113 Condition *audio_lock;
115 struct dv1394_status status;
120 struct video1394_mmap output_mmap;
121 struct video1394_queue_variable output_queue;
122 // raw1394handle_t avc_handle;
123 VFrame *temp_frame, *temp_frame2;
124 // Encoder for making DV frames
127 unsigned int cip_n, cip_d;
128 unsigned int cip_counter;
129 unsigned char f50_60;
130 unsigned char *output_buffer;
132 unsigned int packet_sizes[321];
133 unsigned char continuity_counter;
144 VideoDevice *vdevice;
145 AudioDevice *adevice;
149 int video1394_listen_channel;
150 int video1394_unlisten_channel;
151 int video1394_listen_queue_buffer;
152 int video1394_listen_wait_buffer;
153 int video1394_talk_channel;
154 int video1394_untalk_channel;
155 int video1394_talk_queue_buffer;
156 int video1394_talk_wait_buffer;
157 int video1394_listen_poll_buffer;
159 // To keep track of the delay between putting the audio in the buffer
160 // and when it is actually presented on the DV device
161 long *position_presented;