r125: This commit was manufactured by cvs2svn to create tag 'r1_1_7-last'.
[cinelerra_cv/mob.git] / hvirtual / cinelerra / audio1394.C
blob5e291b218b9384d67819e11b031a058f82f716df
1 #ifdef HAVE_FIREWIRE
7 #include "audio1394.h"
8 #include "playbackconfig.h"
9 #include "device1394input.h"
10 #include "device1394output.h"
11 #include "preferences.h"
12 #include "recordconfig.h"
13 #include "videoconfig.h"
14 #include "videodevice.h"
16 #define SAMPLES_PER_FRAME 2048
18 Audio1394::Audio1394(AudioDevice *device)
19  : AudioLowLevel(device)
21         initialize();
25 Audio1394::~Audio1394()
27         close_all();
30 int Audio1394::initialize()
32         input_thread = 0;
33         output_thread = 0;
36 int Audio1394::open_input()
38         int result = 0;
39         if(!input_thread)
40         {
41 // Lock the channels for the DV format
42                 device->in_channels = 2;
43                 device->in_bits = 16;
44                 bytes_per_sample = device->in_channels * device->in_bits / 8;
47                 input_thread = new Device1394Input;
48                 result = input_thread->open(device->in_config->firewire_port, 
49                         device->in_config->firewire_channel, 
50                         30,
51                         device->in_channels,
52                         device->in_samplerate,
53                         device->in_bits);
54                 if(result)
55                 {
56                         delete input_thread;
57                         input_thread = 0;
58                 }
59         }
61         return result;
64 int Audio1394::open_output()
66         if(!output_thread)
67         {
68 // Lock the channels for the DV format
69                 device->out_channels = 2;
70                 device->out_bits = 16;
71                 bytes_per_sample = device->out_channels * device->out_bits / 8;
73                 output_thread = new Device1394Output;
75 //printf("Audio1394::open_output 1 %s\n", device->out_config->firewire_path);
76                 output_thread->open(device->out_config->firewire_path,
77                         device->out_config->firewire_port,
78                         device->out_config->firewire_channel,
79                         30,
80                         device->out_channels, 
81                         device->out_bits, 
82                         device->out_samplerate,
83                         device->out_config->firewire_syt,
84                         device->out_config->firewire_use_dv1394);
85         }
88 int Audio1394::close_all()
90         if(input_thread)
91         {
92                 delete input_thread;
93         }
95         if(output_thread)
96         {
97                 delete output_thread;
98         }
100         initialize();
101         return 0;
105 int Audio1394::read_buffer(char *buffer, int bytes)
107         if(input_thread)
108         {
109                 input_thread->read_audio(buffer, bytes / bytes_per_sample);
110         }
112         return 0;
115 int Audio1394::write_buffer(char *buffer, int bytes)
117         if(output_thread)
118                 output_thread->write_samples(buffer, bytes / bytes_per_sample);
119         return 0;
122 int64_t Audio1394::device_position()
124         if(output_thread)
125                 return output_thread->get_audio_position();
126         else
127                 return 0;
131 int Audio1394::flush_device()
133         if(output_thread)
134                 output_thread->flush();
135         return 0;
138 int Audio1394::interrupt_playback()
140         if(output_thread)
141                 output_thread->interrupt();
142         return 0;
147 #endif