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 DEVICEMPEGINPUT_H
23 #define DEVICEMPEGINPUT_H
25 #include "devicempeginput.inc"
26 #include "audiodevice.h"
27 #include "audiompeg.inc"
29 #include "videodevice.h"
30 #include "vdevicempeg.inc"
31 #include "condition.h"
38 #include "mwindow.inc"
39 //#include "recordconfig.inc"
42 #include "libzmpeg3.h"
44 #define INPUT_SAMPLES 131072
45 #define BUFFER_TIMEOUT 500000
48 // This is the common interface for the V4L2 recording devices.
49 // It handles the network connection to the V4L2 dev.
51 class DeviceMPEGList : public List<DeviceMPEGInput>
55 ~DeviceMPEGList() { first=last=0; } // no deletes
58 class DeviceMPEG_TOC_Builder : public Thread
61 DeviceMPEGInput *mpeg_dev;
63 DeviceMPEG_TOC_Builder(DeviceMPEGInput *mpeg_dev);
64 ~DeviceMPEG_TOC_Builder();
65 void stop(int wait=0);
71 class DeviceMPEGInput : public Garbage, public ListItem<DeviceMPEGInput>
73 friend class DeviceDVBInput;
74 friend class DeviceV4L2Input;
75 friend class DeviceMPEG_TOC_Builder;
77 static Condition in_mpeg_lock;
78 static DeviceMPEGList in_mpeg;
80 static DeviceMPEGInput* get_mpeg_device(
81 DeviceMPEGInput* (*new_device)(const char *name, int no),
82 const char *name, int no);
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);
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;
100 const char *dev_name;
102 VideoDevice *video_device;
103 AudioDevice *audio_device;
111 DeviceMPEG_TOC_Builder *toc_builder;
116 int audio_inited, video_inited;
117 int audio_stream, video_stream;
118 int record_fd, captioning;
119 int total_vstreams, total_achannels;
123 int channels, sample_bits, samplerate;
125 VFrame **device_buffers;
130 DeviceMPEGInput(const char *name, int no);
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(); }
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();
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);
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);
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);
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; }