switch move/swap tracks, add mv trk shortcut, update msg
[goodguy/cinelerra.git] / cinelerra-5.1 / cinelerra / devicempeginput.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 DEVICEMPEGINPUT_H
23 #define DEVICEMPEGINPUT_H
24
25 #include "devicempeginput.inc"
26 #include "audiodevice.h"
27 #include "audiompeg.inc"
28 #include "file.inc"
29 #include "videodevice.h"
30 #include "vdevicempeg.inc"
31 #include "condition.h"
32 #include "garbage.h"
33 #include "linklist.h"
34 #include "channel.h"
35 #include "vframe.h"
36 #include "mutex.h"
37 #include "record.inc"
38 #include "mwindow.inc"
39 //#include "recordconfig.inc"
40 #include <stdint.h>
41 #include "thread.h"
42 #include "libzmpeg3.h"
43
44 #define INPUT_SAMPLES 131072
45 #define BUFFER_TIMEOUT 500000
46
47
48 // This is the common interface for the V4L2 recording devices.
49 // It handles the network connection to the V4L2 dev.
50
51 class DeviceMPEGList : public List<DeviceMPEGInput>
52 {
53 public:
54         DeviceMPEGList() {}
55         ~DeviceMPEGList() { first=last=0; } // no deletes
56 };
57
58 class DeviceMPEG_TOC_Builder : public Thread
59 {
60         int done;
61         DeviceMPEGInput *mpeg_dev;
62 public:
63         DeviceMPEG_TOC_Builder(DeviceMPEGInput *mpeg_dev);
64         ~DeviceMPEG_TOC_Builder();
65         void stop(int wait=0);
66         void start();
67         void run();
68 };
69
70
71 class DeviceMPEGInput : public Garbage, public ListItem<DeviceMPEGInput>
72 {
73         friend class DeviceDVBInput;
74         friend class DeviceV4L2Input;
75         friend class DeviceMPEG_TOC_Builder;
76
77         static Condition in_mpeg_lock;
78         static DeviceMPEGList in_mpeg;
79
80         static DeviceMPEGInput* get_mpeg_device(
81                 DeviceMPEGInput* (*new_device)(const char *name, int no),
82                 const char *name, int no);
83
84         int wait_signal(double tmo, int trys);
85         int get_stream(int reopen=0);
86         int get_channeldb(ArrayList<Channel*> *channeldb);
87         Channel *add_channel( ArrayList<Channel*> *channeldb,
88                 char *name, int element, int major, int minor,
89                 int vstream, int astream, char *enc);
90         int get_channel_table() { return channel ? channel->freqtable : -1; }
91         int get_channel_input() { return channel ? channel->input : -1; }
92         int get_channel_tuner() { return channel ? channel->tuner : -1; }
93         static int get_dev_cmodel(int colormodel);
94
95         virtual int mpeg_fd() = 0;
96         virtual int open_dev(int color_model) = 0;
97         virtual void close_dev() = 0;
98         virtual int status_dev() = 0;
99
100         const char *dev_name;
101         int device_number;
102         VideoDevice *video_device;
103         AudioDevice *audio_device;
104         Channel *channel;
105         Mutex *decoder_lock;
106         Mutex *video_lock;
107         Mutex *audio_lock;
108
109         zmpeg3_t *src;
110         zmpeg3_t *toc;
111         DeviceMPEG_TOC_Builder *toc_builder;
112         int tick_toc();
113         int64_t toc_pos;
114
115         int color_model;
116         int audio_inited, video_inited;
117         int audio_stream, video_stream;
118         int record_fd, captioning;
119         int total_vstreams, total_achannels;
120
121         int height, width;
122         double framerate;
123         int channels, sample_bits, samplerate;
124
125         VFrame **device_buffers;
126         int *buffer_valid;
127         int streamon;
128         int total_buffers;
129 public:
130         DeviceMPEGInput(const char *name, int no);
131         ~DeviceMPEGInput();
132
133         void reset();
134         int open_input();
135         int drop_frames(int frames);
136         int read_buffer(VFrame *data);
137         int read_audio(char *data, int samples);
138         int video_width() { return width; }
139         int video_height() { return height; }
140         double video_framerate() { return framerate; }
141         int audio_channels() { return channels; }
142         int audio_sample_rate() { return samplerate; }
143         int audio_sample_bits() { return sample_bits; }
144         int total_video_streams() { return total_vstreams; }
145         int total_audio_channels() { return total_achannels; }
146         int get_channel() { return channel ? channel->entry : -1; }
147         const char *channel_title() { return !channel ? "--" : channel->title; }
148         int get_device_number() { return device_number; }
149         zmpeg3_t *get_src() { return !src_stream() ? src : 0; }
150         void put_src() { src_unlock(); }
151         int colormodel();
152         void set_device_number(int dev) { device_number = dev; }
153         int set_channel(Channel *channel);
154         void set_captioning(int mode);
155         MWindow *get_mwindow();
156         int create_channeldb(ArrayList<Channel*> *channeldb);
157         int src_stream(Mutex *stream=0);
158         zmpeg3_t *src_lock();
159         void src_unlock();
160         double audio_timestamp();
161         double video_timestamp();
162         int start_toc(const char *path, const char *toc_path);
163         int start_record(int fd, int bsz);
164         int stop_record();
165         int subchannel_count();
166         int subchannel_definition(int subchan, char *name,
167                 int &major, int &minor, int &total_astreams, int &total_vstreams);
168         int subchannel_video_stream(int subchan, int vstream);
169         int subchannel_audio_stream(int subchan, int astream, char *enc=0);
170         int get_video_pid(int track);
171         int get_video_info(int track, int &pid, double &framerate,
172                 int &width, int &height, char *title=0);
173         int get_thumbnail(int stream, int64_t &position,
174                 unsigned char *&thumbnail, int &ww, int &hh);
175         int set_skimming(int track, int skim, skim_fn fn, void *vp);
176
177         static DeviceMPEGInput* get_mpeg_video(VideoDevice *video_device,
178                 DeviceMPEGInput* (*new_device)(const char *name, int no),
179                 const char *name, int no);
180         static DeviceMPEGInput* get_mpeg_audio(AudioDevice *audio_device,
181                 DeviceMPEGInput* (*new_device)(const char *name, int no),
182                 const char *name, int no);
183
184         void put_mpeg_video();
185         void put_mpeg_audio();
186         void audio_reset() { audio_inited = 0; }
187         void video_reset() { video_inited = 0; }
188         virtual int has_signal() { return 1; }
189 };
190
191 #endif