Imported Upstream version 3.0
[debian/gnuradio] / gr-video-sdl / src / video_sdl_sink_s.h
1 /* -*- c++ -*- */
2 /*
3  * Copyright 2006 Free Software Foundation, Inc.
4  * 
5  * This file is part of GNU Radio
6  * 
7  * GNU Radio is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 2, or (at your option)
10  * any later version.
11  * 
12  * GNU Radio is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU General Public License for more details.
16  * 
17  * You should have received a copy of the GNU General Public License
18  * along with GNU Radio; see the file COPYING.  If not, write to
19  * the Free Software Foundation, Inc., 51 Franklin Street,
20  * Boston, MA 02110-1301, USA.
21  */
22
23 #ifndef INCLUDED_VIDEO_SDL_SINK_S_H
24 #define INCLUDED_VIDEO_SDL_SINK_S_H
25
26 #include <gr_sync_block.h>
27 #include <string>
28 #include <SDL.h>
29
30 /*  fourcc (four character code) */
31 #define vid_fourcc(a,b,c,d) (((unsigned)(a)<<0) | ((unsigned)(b)<<8) | ((unsigned)(c)<<16) | ((unsigned)(d)<<24))
32 #define IMGFMT_YV12  vid_fourcc('Y','V','1','2') /* 12  YVU 4:2:0 */
33
34 class video_sdl_sink_s;
35 typedef boost::shared_ptr<video_sdl_sink_s> video_sdl_sink_s_sptr;
36
37 video_sdl_sink_s_sptr
38 video_sdl_make_sink_s (double framerate,int width=640, int height=480,unsigned int format=IMGFMT_YV12,int dst_width=-1,int dst_height=-1);
39
40 /*!
41  * \brief video sink using SDL
42  *
43  * input signature is one, two or three streams of signed short.
44  * One stream: stream is grey (Y)
45  * two streems: first is grey (Y), second is alternating U and V
46  * Three streams: first is grey (Y), second is U, third is V
47  * Input samples must be in the range [0,255].
48  */
49
50 class video_sdl_sink_s : public gr_sync_block {
51   friend video_sdl_sink_s_sptr
52   video_sdl_make_sink_s (double framerate,int width, int height,unsigned int format,int dst_width,int dst_height);
53
54   int           d_chunk_size;
55
56  protected:
57   video_sdl_sink_s (double framerate,int width, int height,unsigned int format,
58                       int dst_width,int dst_height);
59   void copy_line_pixel_interleaved(unsigned char *dst_pixels_u,unsigned char *dst_pixels_v,
60                           const short * src_pixels,int src_width);
61   void copy_line_line_interleaved(unsigned char *dst_pixels_u,unsigned char *dst_pixels_v,
62                           const short * src_pixels,int src_width);
63   void copy_line_single_plane(unsigned char *dst_pixels,const short * src_pixels,int src_width);
64   void copy_line_single_plane_dec2(unsigned char *dst_pixels,const short * src_pixels,int src_width);
65   int copy_plane_to_surface (int plane,int noutput_items,
66                       const short * src_pixels);
67   float d_framerate;
68   int d_wanted_frametime_ms;
69   int d_width;
70   int d_height;
71   int d_dst_width;
72   int d_dst_height;
73   int d_format;
74   int d_current_line;
75   SDL_Surface *d_screen;
76   SDL_Overlay *d_image;
77   SDL_Rect d_dst_rect;
78   float d_avg_delay;
79   unsigned int d_wanted_ticks;
80
81
82  public:
83   ~video_sdl_sink_s ();
84   
85   int work (int noutput_items,
86                   gr_vector_const_void_star &input_items,
87                   gr_vector_void_star &output_items);
88 };
89
90 #endif /* INCLUDED_VIDEO_SDL_SINK_S_H */