add libdav1d codec, add remap_a/v_codec option keywords
[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  *
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.
10  *
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.
15  *
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
19  *
20  */
21
22 #ifndef DEVICE1394OUTPUT_H
23 #define DEVICE1394OUTPUT_H
24
25
26
27 #ifdef HAVE_FIREWIRE
28
29 #include "audiodevice.inc"
30 #include "condition.inc"
31 #include "libdv.h"
32 #include "dv1394.h"
33 #include "ieee1394-ioctl.h"
34 #include "mutex.inc"
35 #include "thread.h"
36 #include "vframe.inc"
37 #include "video1394.h"
38 #include "videodevice.inc"
39
40 // Common 1394 output for audio and video
41
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
45 {
46 public:
47         Device1394Output(VideoDevice *vdevice);
48         Device1394Output(AudioDevice *adevice);
49         ~Device1394Output();
50
51         void reset();
52         int open(char *path,
53                 int port,
54                 int channel,
55                 int length,
56                 int channels,
57                 int bits,
58                 int samplerate,
59                 int syt);
60         void start();
61         void run();
62
63
64 // Write frame with timed blocking.
65
66         void write_frame(VFrame *input);
67
68
69 // Write audio with timed blocking.
70
71         void write_samples(char *data, int samples);
72         long get_audio_position();
73         void interrupt();
74         void flush();
75
76 // This object is shared between audio and video.  Return what the driver is
77 // based on whether vdevice or adevice exists.
78         int get_dv1394();
79
80 // Set IOCTL numbers based on kernel version
81         void set_ioctls();
82
83         void encrypt(unsigned char *output,
84                 unsigned char *data,
85                 int data_size);
86
87
88         void increment_counter(int *counter);
89         void decrement_counter(int *counter);
90
91
92         char **buffer;
93         int *buffer_size;
94         int *buffer_valid;
95
96         int total_buffers;
97         int current_inbuffer;
98         int current_outbuffer;
99
100         char *audio_buffer;
101         int audio_samples;
102 // Encoder for audio frames
103         dv_t *encoder;
104
105         Mutex *buffer_lock;
106 // Block while waiting for the first buffer to be allocated
107         Condition *start_lock;
108         Mutex *position_lock;
109
110 // Provide timed blocking for writing routines.
111
112         Condition *video_lock;
113         Condition *audio_lock;
114         int done;
115         struct dv1394_status status;
116
117
118 // Output
119         int output_fd;
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
125         dv_t *audio_encoder;
126         dv_t *video_encoder;
127         unsigned int cip_n, cip_d;
128     unsigned int cip_counter;
129         unsigned char f50_60;
130         unsigned char *output_buffer;
131         int output_number;
132     unsigned int packet_sizes[321];
133     unsigned char  continuity_counter;
134     int unused_buffers;
135         int avc_id;
136         int channels;
137         int samplerate;
138         int bits;
139         int syt;
140         long audio_position;
141         int interrupted;
142         int have_video;
143         int is_pal;
144         VideoDevice *vdevice;
145         AudioDevice *adevice;
146
147         // IOCTL # variables
148    // video1394
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;
158
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;
162
163 };
164
165
166
167
168 #endif
169
170
171
172
173
174 #endif