Credit Andrew - fix vorbis audio which was scratchy and ensure aging plugin does...
[goodguy/cinelerra.git] / cinelerra-5.1 / cinelerra / device1394output.h
1
2 /*
3  * CINELERRA
4  * Copyright (C) 2008 Adam Williams <broadcast at earthling dot net>
5  * Copyright (C) 2003-2016 Cinelerra CV contributors
6  *
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 2 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
20  *
21  */
22
23 #ifndef DEVICE1394OUTPUT_H
24 #define DEVICE1394OUTPUT_H
25
26
27
28 #ifdef HAVE_FIREWIRE
29
30 #include "audiodevice.inc"
31 #include "condition.inc"
32 #include "libdv.h"
33 #include "dv1394.h"
34 #include "ieee1394-ioctl.h"
35 #include "mutex.inc"
36 #include "thread.h"
37 #include "vframe.inc"
38 #include "video1394.h"
39 #include "videodevice.inc"
40
41 // Common 1394 output for audio and video
42
43 // This runs continuously to keep the VTR warm.
44 // Takes encoded DV frames and PCM audio.  Does the 1394 encryption on the fly.
45 class Device1394Output : public Thread
46 {
47 public:
48         Device1394Output(VideoDevice *vdevice);
49         Device1394Output(AudioDevice *adevice);
50         ~Device1394Output();
51
52         void reset();
53         int open(char *path,
54                 int port,
55                 int channel,
56                 int length,
57                 int channels,
58                 int bits,
59                 int samplerate,
60                 int syt);
61         void start();
62         void run();
63
64
65 // Write frame with timed blocking.
66
67         void write_frame(VFrame *input);
68
69
70 // Write audio with timed blocking.
71
72         void write_samples(char *data, int samples);
73         long get_audio_position();
74         void interrupt();
75         void flush();
76
77 // This object is shared between audio and video.  Return what the driver is
78 // based on whether vdevice or adevice exists.
79         int get_dv1394();
80
81 // Set IOCTL numbers based on kernel version
82         void set_ioctls();
83
84         void encrypt(unsigned char *output,
85                 unsigned char *data,
86                 int data_size);
87
88
89         void increment_counter(int *counter);
90         void decrement_counter(int *counter);
91
92
93         char **buffer;
94         int *buffer_size;
95         int *buffer_valid;
96
97         int total_buffers;
98         int current_inbuffer;
99         int current_outbuffer;
100
101         char *audio_buffer;
102         int audio_samples;
103 // Encoder for audio frames
104         dv_t *encoder;
105
106         Mutex *buffer_lock;
107 // Block while waiting for the first buffer to be allocated
108         Condition *start_lock;
109         Mutex *position_lock;
110
111 // Provide timed blocking for writing routines.
112
113         Condition *video_lock;
114         Condition *audio_lock;
115         int done;
116         struct dv1394_status status;
117
118
119 // Output
120         int output_fd;
121         struct video1394_mmap output_mmap;
122         struct video1394_queue_variable output_queue;
123 //      raw1394handle_t avc_handle;
124         VFrame *temp_frame, *temp_frame2;
125 // Encoder for making DV frames
126         dv_t *audio_encoder;
127         dv_t *video_encoder;
128         unsigned int cip_n, cip_d;
129     unsigned int cip_counter;
130         unsigned char f50_60;
131         unsigned char *output_buffer;
132         int output_number;
133     unsigned int packet_sizes[321];
134     unsigned char  continuity_counter;
135     int unused_buffers;
136         int avc_id;
137         int channels;
138         int samplerate;
139         int bits;
140         int syt;
141         long audio_position;
142         int interrupted;
143         int have_video;
144         int is_pal;
145         VideoDevice *vdevice;
146         AudioDevice *adevice;
147
148         // IOCTL # variables
149    // video1394
150    int video1394_listen_channel;
151    int video1394_unlisten_channel;
152    int video1394_listen_queue_buffer;
153    int video1394_listen_wait_buffer;
154    int video1394_talk_channel;
155    int video1394_untalk_channel;
156    int video1394_talk_queue_buffer;
157    int video1394_talk_wait_buffer;
158    int video1394_listen_poll_buffer;
159
160 // To keep track of the delay between putting the audio in the buffer
161 // and when it is actually presented on the DV device
162         long *position_presented;
163
164 };
165
166
167
168
169 #endif
170
171
172
173
174
175 #endif