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
23 #include "condition.h"
27 #include "videodevice.h"
28 #include "vdevicempeg.h"
29 #include "devicempeginput.h"
36 VDeviceMPEG::VDeviceMPEG(VideoDevice *device)
43 VDeviceMPEG::~VDeviceMPEG()
48 int VDeviceMPEG::open_input(char *name)
50 if( video_open ) return 0;
51 /* this is more like - try to open, since a broadcast signal may */
52 /* take time to lock, or not even be there at all. On success, */
53 /* it updates the input config with the actual stream config. */
55 mpeg_input = get_mpeg_input();
56 if( !mpeg_input ) return 1;
57 device->channel->has_subchan = 1;
58 device->channel->has_scanning = 1;
59 device->channel->use_frequency = 1;
62 Channel *channel = device->new_input_source(name);
63 channel->device_index = mpeg_input->get_device_number();
68 if( !mpeg_input->src_stream() ) {
69 int width = mpeg_input->video_width();
70 int height = mpeg_input->video_height();
71 double rate = mpeg_input->video_framerate();
72 device->auto_update(rate, width, height);
73 device->capturing = 1;
75 mpeg_input->src_unlock();
81 int VDeviceMPEG::close_all()
85 mpeg_input->put_mpeg_video();
91 int VDeviceMPEG::read_buffer(VFrame *frame)
93 if( !video_open && open_input() ) return 1;
94 int result = mpeg_input->read_buffer(frame);
98 int VDeviceMPEG::get_best_colormodel(Asset *asset)
100 int result = mpeg_input ? mpeg_input->colormodel() : BC_YUV422P;
104 int VDeviceMPEG::drop_frames(int frames)
106 return !mpeg_input ? 1 : mpeg_input->drop_frames(frames);
109 double VDeviceMPEG::device_timestamp()
111 if( !video_open || !mpeg_input ) return -1.;
112 return mpeg_input->video_timestamp();
115 int VDeviceMPEG::start_toc(const char *path, const char *toc_path)
117 return !mpeg_input ? -1 : mpeg_input->start_toc(path, toc_path);
120 int VDeviceMPEG::start_record(int fd, int bsz)
122 return !mpeg_input ? -1 : mpeg_input->start_record(fd, bsz);
125 int VDeviceMPEG::stop_record()
127 return !mpeg_input ? -1 : mpeg_input->stop_record();
130 int VDeviceMPEG::total_video_streams()
132 return !mpeg_input ? -1 : mpeg_input->total_video_streams();
136 int VDeviceMPEG::set_channel(Channel *channel)
138 device->channel_changed = 0;
139 return !mpeg_input ? -1 : mpeg_input->set_channel(channel);
142 int VDeviceMPEG::set_captioning(int mode)
144 return !mpeg_input ? -1 : (mpeg_input->set_captioning(mode), 0);
147 int VDeviceMPEG::has_signal()
149 return !mpeg_input ? 0 : mpeg_input->has_signal();
153 int VDeviceMPEG::create_channeldb(ArrayList<Channel*> *channeldb)
155 return !mpeg_input ? 1 : mpeg_input->
156 create_channeldb(channeldb);
160 int VDeviceMPEG::get_video_pid(int track)
162 return !mpeg_input ? 1 : mpeg_input->get_video_pid(track);
165 int VDeviceMPEG::get_video_info(int track, int &pid,
166 double &framerate, int &width, int &height, char *title)
168 return !mpeg_input ? 1 : mpeg_input->
169 get_video_info(track, pid, framerate, width, height, title);
172 int VDeviceMPEG::get_thumbnail(int stream, int64_t &position,
173 unsigned char *&thumbnail, int &ww, int &hh)
175 return !mpeg_input ? 1 : mpeg_input->
176 get_thumbnail(stream, position, thumbnail, ww, hh);
179 int VDeviceMPEG::set_skimming(int track, int skim, skim_fn fn, void *vp)
181 return !mpeg_input ? 1 : mpeg_input->
182 set_skimming(track, skim, fn, vp);