Ticket #2954: 2954-v4.patch

File 2954-v4.patch, 35.5 KB (added by danielk, 19 years ago)

Updated patch

  • libs/libmythtv/cardutil.h

     
    173173
    174174    // V4L info
    175175    static bool         hasV4L2(int videofd);
    176     static bool         GetV4LInfo(int videofd, QString &card,QString &driver);
     176    static bool         GetV4LInfo(int videofd, QString &card, QString &driver,
     177                                   uint32_t &version);
     178    static bool         GetV4LInfo(int videofd, QString &card, QString &driver)
     179        { uint32_t dummy; return GetV4LInfo(videofd, card, driver, dummy); }
    177180    static InputNames   probeV4LInputs(int videofd, bool &ok);
    178181
    179182  private:
  • libs/libmythtv/mpegrecorder.h

     
    5555    bool OpenV4L2DeviceAsInput(void);
    5656    bool SetIVTVDeviceOptions(int chanfd);
    5757    bool SetV4L2DeviceOptions(int chanfd);
     58    bool SetVBIOptions(int chanfd);
    5859
    5960    void ResetForNewFile(void);
    6061
    6162    bool deviceIsMpegFile;
    6263    int bufferSize;
    6364
     65    // Driver info
     66    QString  card;
     67    QString  driver;
     68    uint32_t version;
     69    bool     usingv4l2;
     70    bool     has_buggy_vbi;
     71    bool     has_v4l2_vbi;
     72
    6473    // State
    6574    bool recording;
    6675    bool encoding;
  • libs/libmythtv/ivtv_myth.h

     
    1 #define IVTV_IOC_FWAPI          0xFFEE7701 /*just some values i picked for now*/
    2 #define IVTV_IOC_ZCOUNT         0xFFEE7702
    3 #ifdef __FreeBSD__
    4 #define IVTV_IOC_G_CODEC        _IOR  ('V', 73, struct ivtv_ioctl_codec)
    5 #define IVTV_IOC_S_CODEC        _IOWR ('V', 74, struct ivtv_ioctl_codec)
    6 #else
    7 #define IVTV_IOC_G_CODEC        0xFFEE7703
    8 #define IVTV_IOC_S_CODEC        0xFFEE7704
    9 #endif
     1/*
     2    Public ivtv API header
     3    Copyright (C) 2003-2004  Kevin Thayer <nufan_wfk at yahoo.com>
    104
    11 #define IVTV_MBOX_MAX_DATA 16
     5    VBI portions:
     6    Copyright (C) 2004  Hans Verkuil <hverkuil@xs4all.nl>
    127
    13 #define IVTV_SLICED_TELETEXT_B  (1 << 0)
    14 #define IVTV_SLICED_CAPTION_625 (1 << 1)
    15 #define IVTV_SLICED_CAPTION_525 (1 << 2)
    16 #define IVTV_SLICED_WSS_625     (1 << 3)
    17 #define IVTV_SLICED_VPS         (1 << 4)
     8    This program is free software; you can redistribute it and/or modify
     9    it under the terms of the GNU General Public License as published by
     10    the Free Software Foundation; either version 2 of the License, or
     11    (at your option) any later version.
    1812
    19 struct ivtv_sliced_vbi_format {
    20         unsigned long service_set;      /* one or more of the IVTV_SLICED_ defines */
    21         unsigned long packet_size;      /* the size in bytes of the ivtv_sliced_data packet */
    22         unsigned long io_size;          /* maximum number of bytes passed by one read() call */
    23         unsigned long reserved;
    24 };
     13    This program is distributed in the hope that it will be useful,
     14    but WITHOUT ANY WARRANTY; without even the implied warranty of
     15    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     16    GNU General Public License for more details.
    2517
    26 /* This structure is the same as the proposed v4l2_sliced_data structure */
    27 /* id is one of the VBI_SLICED_ flags. */
    28 struct ivtv_sliced_data {
    29         unsigned long id;
    30         unsigned long line;
    31         unsigned char *data;
    32 };
     18    You should have received a copy of the GNU General Public License
     19    along with this program; if not, write to the Free Software
     20    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
     21 */
    3322
    34 /* The four bit VBI data type found in the embedded VBI data of an
    35    MPEG stream has one of the following values: */
    36 #define VBI_TYPE_TELETEXT       0x1     // Teletext (uses lines 6-22 for PAL, 10-21 for NTSC)
    37 #define VBI_TYPE_CC             0x4     // Closed Captions (line 21 NTSC, line 22 PAL)
    38 #define VBI_TYPE_WSS            0x5     // Wide Screen Signal (line 20 NTSC, line 23 PAL)
    39 #define VBI_TYPE_VPS            0x7     // Video Programming System (PAL) (line 16)
     23#ifndef _LINUX_IVTV_H
     24#define _LINUX_IVTV_H
    4025
    41 /* allow direct access to the saa7115 registers for testing */
    42 #define SAA7115_GET_REG         0xFFEE7705
    43 #define SAA7115_SET_REG         0xFFEE7706
     26#define __u32 uint32_t
     27#define __u64 uint64_t
    4428
    45 /* to set audio options */
    46 #define DECODER_SET_AUDIO       0xFFEE7707
    47 #define DECODER_AUDIO_32_KHZ    0
    48 #define DECODER_AUDIO_441_KHZ   1
    49 #define DECODER_AUDIO_48_KHZ    2
     29/* NOTE: the ioctls in this file will eventually be replaced by v4l2 API
     30   ioctls. */
    5031
    51 #define IVTV_IOC_PLAY           0xFFEE7781
    52 #define IVTV_IOC_PAUSE          0xFFEE7782
    53 #define IVTV_IOC_FRAMESYNC      0xFFEE7783
    54 #define IVTV_IOC_GET_TIMING     0xFFEE7784
    55 #define IVTV_IOC_S_SLOW_FAST    0xFFEE7785
    56 #define IVTV_IOC_S_START_DECODE 0xFFEE7786
    57 #define IVTV_IOC_S_STOP_DECODE  0xFFEE7787
    58 #define IVTV_IOC_S_OSD          0xFFEE7788
    59 #define IVTV_IOC_GET_FB         0xFFEE7789
     32/* device ioctls should use the range 29-199 */
     33#define IVTV_IOC_START_DECODE      _IOW ('@', 29, struct ivtv_cfg_start_decode)
     34#define IVTV_IOC_STOP_DECODE       _IOW ('@', 30, struct ivtv_cfg_stop_decode)
     35#define IVTV_IOC_G_SPEED           _IOR ('@', 31, struct ivtv_speed)
     36#define IVTV_IOC_S_SPEED           _IOW ('@', 32, struct ivtv_speed)
     37#define IVTV_IOC_DEC_STEP          _IOW ('@', 33, int)
     38#define IVTV_IOC_DEC_FLUSH         _IOW ('@', 34, int)
     39#define IVTV_IOC_PAUSE_BLACK       _IO  ('@', 35)
     40#define IVTV_IOC_STOP              _IO  ('@', 36)
     41#define IVTV_IOC_PLAY              _IO  ('@', 37)
     42#define IVTV_IOC_PAUSE             _IO  ('@', 38)
     43#define IVTV_IOC_FRAMESYNC         _IOR ('@', 39, struct ivtv_ioctl_framesync)
     44#define IVTV_IOC_GET_TIMING        _IOR ('@', 40, struct ivtv_ioctl_framesync)
     45#define IVTV_IOC_S_SLOW_FAST       _IOW ('@', 41, struct ivtv_slow_fast)
     46#define IVTV_IOC_GET_FB            _IOR ('@', 44, int)
     47#define IVTV_IOC_S_GOP_END         _IOWR('@', 50, int)
     48#define IVTV_IOC_S_VBI_PASSTHROUGH _IOW ('@', 51, int)
     49#define IVTV_IOC_G_VBI_PASSTHROUGH _IOR ('@', 52, int)
     50#define IVTV_IOC_PASSTHROUGH       _IOW ('@', 53, int)
     51#define IVTV_IOC_PAUSE_ENCODE      _IO  ('@', 56)
     52#define IVTV_IOC_RESUME_ENCODE     _IO  ('@', 57)
     53#define IVTV_IOC_DEC_SPLICE        _IOW ('@', 58, int)
     54#define IVTV_IOC_DEC_FAST_STOP     _IOW ('@', 59, int)
     55#define IVTV_IOC_PREP_FRAME_YUV    _IOW ('@', 60, struct ivtvyuv_ioctl_dma_host_to_ivtv_args)
     56#define IVTV_IOC_G_YUV_INTERLACE   _IOR ('@', 61, struct ivtv_ioctl_yuv_interlace)
     57#define IVTV_IOC_S_YUV_INTERLACE   _IOW ('@', 62, struct ivtv_ioctl_yuv_interlace)
     58#define IVTV_IOC_G_PTS             _IOR ('@', 63, u64)
    6059
    61 #define IVTV_IOC_START_DECODE  _IOW ('@', 29, struct ivtv_cfg_start_decode)
    62 #define IVTV_IOC_STOP_DECODE   _IOW ('@', 30, struct ivtv_cfg_stop_decode)
    63 #define IVTV_IOC_G_SPEED       _IOR ('@', 31, struct ivtv_speed)
    64 #define IVTV_IOC_S_SPEED       _IOW ('@', 32, struct ivtv_speed)
    65 #define IVTV_IOC_DEC_STEP      _IOW ('@', 33, int)
    66 #define IVTV_IOC_DEC_FLUSH     _IOW ('@', 34, int)
    67 #define IVTV_IOC_S_VBI_MODE    _IOWR('@', 35, struct ivtv_sliced_vbi_format)
    68 #define IVTV_IOC_G_VBI_MODE    _IOR ('@', 36, struct ivtv_sliced_vbi_format)
    69 #define IVTV_IOC_S_VBI_EMBED   _IOW ('@', 54, int)
    70 #define IVTV_IOC_G_VBI_EMBED   _IOR ('@', 55, int)
    71 
    72 /* ioctl for MSP_SET_MATRIX will have to be registered */
    73 #define MSP_SET_MATRIX     _IOW('m',17,struct msp_matrix)
    74 
    75 
    7660/* Custom v4l controls */
    7761#ifndef V4L2_CID_PRIVATE_BASE
    7862#define V4L2_CID_PRIVATE_BASE                   0x08000000
    79 #endif
     63#endif /* V4L2_CID_PRIVATE_BASE */
    8064
    81 #define V4L2_CID_IVTV_FREQ      (V4L2_CID_PRIVATE_BASE)
    82 #define V4L2_CID_IVTV_ENC       (V4L2_CID_PRIVATE_BASE + 1)
    83 #define V4L2_CID_IVTV_BITRATE   (V4L2_CID_PRIVATE_BASE + 2)
    84 #define V4L2_CID_IVTV_MONO      (V4L2_CID_PRIVATE_BASE + 3)
    85 #define V4L2_CID_IVTV_JOINT     (V4L2_CID_PRIVATE_BASE + 4)
    86 #define V4L2_CID_IVTV_EMPHASIS  (V4L2_CID_PRIVATE_BASE + 5)
    87 #define V4L2_CID_IVTV_CRC       (V4L2_CID_PRIVATE_BASE + 6)
    88 #define V4L2_CID_IVTV_COPYRIGHT (V4L2_CID_PRIVATE_BASE + 7)
    89 #define V4L2_CID_IVTV_GEN       (V4L2_CID_PRIVATE_BASE + 8)
     65#define V4L2_CID_IVTV_FREQ      (V4L2_CID_PRIVATE_BASE + 0) /* old control */
     66#define V4L2_CID_IVTV_ENC       (V4L2_CID_PRIVATE_BASE + 1) /* old control */
     67#define V4L2_CID_IVTV_BITRATE   (V4L2_CID_PRIVATE_BASE + 2) /* old control */
     68#define V4L2_CID_IVTV_MONO      (V4L2_CID_PRIVATE_BASE + 3) /* old control */
     69#define V4L2_CID_IVTV_JOINT     (V4L2_CID_PRIVATE_BASE + 4) /* old control */
     70#define V4L2_CID_IVTV_EMPHASIS  (V4L2_CID_PRIVATE_BASE + 5) /* old control */
     71#define V4L2_CID_IVTV_CRC       (V4L2_CID_PRIVATE_BASE + 6) /* old control */
     72#define V4L2_CID_IVTV_COPYRIGHT (V4L2_CID_PRIVATE_BASE + 7) /* old control */
     73#define V4L2_CID_IVTV_GEN       (V4L2_CID_PRIVATE_BASE + 8) /* old control */
    9074
    91 #define IVTV_V4L2_AUDIO_MENUCOUNT 9 /* # of v4l controls */
     75#define V4L2_CID_IVTV_DEC_SMOOTH_FF     (V4L2_CID_PRIVATE_BASE + 9)
     76#define V4L2_CID_IVTV_DEC_FR_MASK       (V4L2_CID_PRIVATE_BASE + 10)
     77#define V4L2_CID_IVTV_DEC_SP_MUTE       (V4L2_CID_PRIVATE_BASE + 11)
     78#define V4L2_CID_IVTV_DEC_FR_FIELD      (V4L2_CID_PRIVATE_BASE + 12)
     79#define V4L2_CID_IVTV_DEC_AUD_SKIP      (V4L2_CID_PRIVATE_BASE + 13)
     80#define V4L2_CID_IVTV_DEC_NUM_BUFFERS   (V4L2_CID_PRIVATE_BASE + 14)
     81#define V4L2_CID_IVTV_DEC_PREBUFFER     (V4L2_CID_PRIVATE_BASE + 15)
    9282
    93 #define IVTV_DEC_PRIVATE_BASE   (V4L2_CID_PRIVATE_BASE + IVTV_V4L2_AUDIO_MENUCOUNT)
    94 
    95 #define V4L2_CID_IVTV_DEC_SMOOTH_FF     (IVTV_DEC_PRIVATE_BASE + 0)
    96 #define V4L2_CID_IVTV_DEC_FR_MASK       (IVTV_DEC_PRIVATE_BASE + 1)
    97 #define V4L2_CID_IVTV_DEC_SP_MUTE       (IVTV_DEC_PRIVATE_BASE + 2)
    98 #define V4L2_CID_IVTV_DEC_FR_FIELD      (IVTV_DEC_PRIVATE_BASE + 3)
    99 #define V4L2_CID_IVTV_DEC_AUD_SKIP      (IVTV_DEC_PRIVATE_BASE + 4)
    100 #define V4L2_CID_IVTV_DEC_NUM_BUFFERS   (IVTV_DEC_PRIVATE_BASE + 5)
    101 #define V4L2_CID_IVTV_DEC_PREBUFFER     (IVTV_DEC_PRIVATE_BASE + 6)
    102 
    103 #define IVTV_V4L2_DEC_MENUCOUNT 7
    104 
    105 struct ivtv_ioctl_fwapi {
    106         uint32_t cmd;
    107         uint32_t result;
    108         int32_t args;
    109         uint32_t data[IVTV_MBOX_MAX_DATA];
    110 };
    111 
    11283struct ivtv_ioctl_framesync {
    113         uint32_t frame;
    114         uint64_t pts;
    115         uint64_t scr;
     84        __u32 frame;
     85        __u64 pts;
     86        __u64 scr;
    11687};
    11788
    11889struct ivtv_speed {
    119         int scale;      /* 1-?? (50 for now) */
    120         int smooth;     /* Smooth mode when in slow/fast mode */
    121         int speed;      /* 0 = slow, 1 = fast */
    122         int direction;  /* 0 = forward, 1 = reverse (not supportd */
    123         int fr_mask;    /* 0 = I, 1 = I,P, 2 = I,P,B    2 = default!*/
    124         int b_per_gop;  /* frames per GOP (reverse only) */
    125         int aud_mute;   /* Mute audio while in slow/fast mode */
    126         int fr_field;   /* 1 = show every field, 0 = show every frame */
    127         int mute;       /* # of audio frames to mute on playback resume */
     90        int scale;              /* 1-?? (50 for now) */
     91        int smooth;             /* Smooth mode when in slow/fast mode */
     92        int speed;              /* 0 = slow, 1 = fast */
     93        int direction;          /* 0 = forward, 1 = reverse (not supportd */
     94        int fr_mask;            /* 0 = I, 1 = I,P, 2 = I,P,B    2 = default! */
     95        int b_per_gop;          /* frames per GOP (reverse only) */
     96        int aud_mute;           /* Mute audio while in slow/fast mode */
     97        int fr_field;           /* 1 = show every field, 0 = show every frame */
     98        int mute;               /* # of audio frames to mute on playback resume */
    12899};
    129100
    130101struct ivtv_slow_fast {
    131         int speed; /* 0 = slow, 1 = fast */
    132         int scale; /* 1-?? (50 for now) */
    133 };     
     102        int speed;              /* 0 = slow, 1 = fast */
     103        int scale;              /* 1-?? (50 for now) */
     104};
    134105
    135106struct ivtv_cfg_start_decode {
    136         uint32_t    gop_offset;        /*Frames in GOP to skip before starting */
    137         uint32_t     muted_audio_frames;/* #of audio frames to mute */
     107        __u32 gop_offset;       /*Frames in GOP to skip before starting */
     108        __u32 muted_audio_frames;       /* #of audio frames to mute */
    138109};
    139110
    140111struct ivtv_cfg_stop_decode {
    141         int             hide_last; /* 1 = show black after stop,
    142                                       0 = show last frame */
    143         uint64_t        pts_stop; /* PTS to stop at */
     112        int hide_last;          /* 1 = show black after stop,
     113                                   0 = show last frame */
     114        __u64 pts_stop; /* PTS to stop at */
    144115};
    145116
    146 
    147 /* For use with IVTV_IOC_G_CODEC and IVTV_IOC_S_CODEC */
    148 struct ivtv_ioctl_codec {
    149         uint32_t aspect;
    150         uint32_t audio_bitmask;
    151         uint32_t bframes;
    152         uint32_t bitrate_mode;
    153         uint32_t bitrate;
    154         uint32_t bitrate_peak;
    155         uint32_t dnr_mode;
    156         uint32_t dnr_spatial;
    157         uint32_t dnr_temporal;
    158         uint32_t dnr_type;
    159         uint32_t framerate;
    160         uint32_t framespergop;
    161         uint32_t gop_closure;
    162         uint32_t pulldown;
    163         uint32_t stream_type;
     117struct ivtv_ioctl_yuv_interlace{
     118        int interlace_mode; /* Takes one of IVTV_YUV_MODE_xxxxxx values */
     119        int threshold; /* If mode is auto then if src_height <= this value treat as progressive otherwise treat as interlaced */
    164120};
     121#define IVTV_YUV_MODE_INTERLACED        0
     122#define IVTV_YUV_MODE_PROGRESSIVE       1
     123#define IVTV_YUV_MODE_AUTO              2
    165124
    166 
    167 struct msp_matrix {
    168     int input;
    169     int output;
    170 };
    171 
    172125/* Framebuffer external API */
    173 /* NOTE: These must *exactly* match the structures and constants in driver/ivtv.h */
    174126
    175127struct ivtvfb_ioctl_state_info {
    176   unsigned long status;
    177   unsigned long alpha;
     128        unsigned long status;
     129        unsigned long alpha;
    178130};
    179131
     132struct ivtvfb_ioctl_colorkey {
     133    int state;
     134    __u32 colorKey;
     135};
     136
    180137struct ivtvfb_ioctl_blt_copy_args {
    181   int x, y, width, height, source_offset, source_stride;
     138        int x, y, width, height, source_offset, source_stride;
    182139};
    183140
    184141struct ivtvfb_ioctl_blt_fill_args {
    185     int rasterop, alpha_mode, alpha_mask, width, height, x, y;
    186     unsigned int destPixelMask, colour;
     142        int rasterop, alpha_mode, alpha_mask, width, height, x, y;
     143        unsigned int destPixelMask, colour;
    187144
    188145};
    189146
    190147struct ivtvfb_ioctl_dma_host_to_ivtv_args {
    191   void* source;
    192   unsigned long dest_offset;
    193   int count;
     148        void *source;
     149        unsigned long dest_offset;
     150        int count;
    194151};
    195152
     153struct ivtvyuv_ioctl_dma_host_to_ivtv_args {
     154        void *y_source;
     155        void *uv_source;
     156        unsigned int yuv_type;
     157        int src_x;
     158        int src_y;
     159        unsigned int src_w;
     160        unsigned int src_h;
     161        int dst_x;
     162        int dst_y;
     163        unsigned int dst_w;
     164        unsigned int dst_h;
     165        int srcBuf_width;
     166        int srcBuf_height;
     167};
     168
    196169struct ivtvfb_ioctl_get_frame_buffer {
    197   void* mem;
    198   int  size;
    199   int  sizex;
    200   int  sizey;
     170        void *mem;
     171        int size;
     172        int sizex;
     173        int sizey;
    201174};
    202175
    203176struct ivtv_osd_coords {
    204   unsigned long offset;
    205   unsigned long max_offset;
    206   int pixel_stride;
    207   int lines;
    208   int x;
    209   int y;
     177        unsigned long offset;
     178        unsigned long max_offset;
     179        int pixel_stride;
     180        int lines;
     181        int x;
     182        int y;
    210183};
    211184
    212185struct rectangle {
    213   int x0;
    214   int y0;
    215   int x1;
    216   int y1;
     186        int x0;
     187        int y0;
     188        int x1;
     189        int y1;
    217190};
    218191
     192struct ivtvfb_ioctl_set_window {
     193        int width;
     194        int height;
     195        int left;
     196        int top;
     197};
     198
     199
     200
     201/* Framebuffer ioctls should use the range 1 - 28 */
    219202#define IVTVFB_IOCTL_GET_STATE          _IOR('@', 1, struct ivtvfb_ioctl_state_info)
    220203#define IVTVFB_IOCTL_SET_STATE          _IOW('@', 2, struct ivtvfb_ioctl_state_info)
    221204#define IVTVFB_IOCTL_PREP_FRAME         _IOW('@', 3, struct ivtvfb_ioctl_dma_host_to_ivtv_args)
     
    224207#define IVTVFB_IOCTL_SET_ACTIVE_BUFFER  _IOW('@', 6, struct ivtv_osd_coords)
    225208#define IVTVFB_IOCTL_GET_FRAME_BUFFER   _IOR('@', 7, struct ivtvfb_ioctl_get_frame_buffer)
    226209#define IVTVFB_IOCTL_BLT_FILL           _IOW('@', 8, struct ivtvfb_ioctl_blt_fill_args)
     210#define IVTVFB_IOCTL_PREP_FRAME_BUF     _IOW('@', 9, struct ivtvfb_ioctl_dma_host_to_ivtv_args)
     211#define IVTVFB_IOCTL_SET_WINDOW         _IOW('@', 11, struct ivtvfb_ioctl_set_window)
     212#define IVTVFB_IOCTL_GET_COLORKEY       _IOW('@', 12, struct ivtvfb_ioctl_colorkey)
     213#define IVTVFB_IOCTL_SET_COLORKEY       _IOW('@', 13, struct ivtvfb_ioctl_colorkey)
    227214
    228215#define IVTVFB_STATUS_ENABLED           (1 << 0)
    229216#define IVTVFB_STATUS_GLOBAL_ALPHA      (1 << 1)
    230217#define IVTVFB_STATUS_LOCAL_ALPHA       (1 << 2)
    231218#define IVTVFB_STATUS_FLICKER_REDUCTION (1 << 3)
    232219
    233 #define IVTV_IOCTL_SET_DEBUG_LEVEL _IOWR('@', 98, int *)
    234 #define IVTV_IOCTL_GET_DEBUG_LEVEL _IOR('@', 99, int *)
     220/********************************************************************/
     221/* Old stuff */
     222
     223/* Good for versions 0.2.0 through 0.7.x */
     224#define IVTV_IOC_G_CODEC      _IOR ('@', 48, struct ivtv_ioctl_codec)
     225#define IVTV_IOC_S_CODEC      _IOW ('@', 49, struct ivtv_ioctl_codec)
     226
     227/* For use with IVTV_IOC_G_CODEC and IVTV_IOC_S_CODEC */
     228struct ivtv_ioctl_codec {
     229        __u32 aspect;
     230        __u32 audio_bitmask;
     231        __u32 bframes;
     232        __u32 bitrate_mode;
     233        __u32 bitrate;
     234        __u32 bitrate_peak;
     235        __u32 dnr_mode;
     236        __u32 dnr_spatial;
     237        __u32 dnr_temporal;
     238        __u32 dnr_type;
     239        __u32 framerate;
     240        __u32 framespergop;
     241        __u32 gop_closure;
     242        __u32 pulldown;
     243        __u32 stream_type;
     244};
     245
     246/********************************************************************/
     247
     248/* Good for versions 0.2.0 through 0.3.x */
     249#define IVTV_IOC_S_VBI_MODE   _IOWR('@', 35, struct ivtv_sliced_vbi_format)
     250#define IVTV_IOC_G_VBI_MODE   _IOR ('@', 36, struct ivtv_sliced_vbi_format)
     251
     252/* Good for version 0.2.0 through 0.3.7 */
     253#define IVTV_IOC_S_VBI_EMBED  _IOW ('@', 54, int)
     254#define IVTV_IOC_G_VBI_EMBED  _IOR ('@', 55, int)
     255
     256/* Good for version 0.2.0 through 0.3.7 */
     257struct ivtv_sliced_vbi_format {
     258        unsigned long service_set;      /* one or more of the IVTV_SLICED_ defines */
     259        unsigned long packet_size;      /* the size in bytes of the ivtv_sliced_data packet */
     260        unsigned long io_size;          /* maximum number of bytes passed by one read() call */
     261        unsigned long reserved;
     262};
     263
     264/* Good for version 0.2.0 through 0.3.7 */
     265struct ivtv_sliced_data {
     266        unsigned long id;
     267        unsigned long line;
     268        unsigned char *data;
     269};
     270
     271/* Good for version 0.2.0 through 0.3.7 for IVTV_IOC_G_VBI_MODE */
     272/* Good for version 0.3.8 through 0.7.x for IVTV_IOC_S_VBI_PASSTHROUGH */
     273#define VBI_TYPE_TELETEXT 0x1 // Teletext (uses lines 6-22 for PAL, 10-21 for NTSC)
     274#define VBI_TYPE_CC       0x4 // Closed Captions (line 21 NTSC, line 22 PAL)
     275#define VBI_TYPE_WSS      0x5 // Wide Screen Signal (line 20 NTSC, line 23 PAL)
     276#define VBI_TYPE_VPS      0x7 // Video Programming System (PAL) (line 16)
     277
     278#endif /* _LINUX_IVTV_H */
  • libs/libmythtv/cardutil.cpp

     
    483483#endif // !USING_V4L
    484484}
    485485
    486 bool CardUtil::GetV4LInfo(int videofd, QString &card, QString &driver)
     486bool CardUtil::GetV4LInfo(
     487    int videofd, QString &card, QString &driver, uint32_t &version)
    487488{
    488489    card = driver = QString::null;
     490    version = 0;
    489491
    490492    if (videofd < 0)
    491493        return false;
     
    498500    {
    499501        card.setAscii((char*)capability.card);
    500502        driver.setAscii((char*)capability.driver);
     503        version = capability.version;
    501504    }
    502505    else // Fallback to V4L1 query
    503506    {
  • libs/libmythtv/mpegrecorder.cpp

     
    3333#include "tv_rec.h"
    3434#include "videodev_myth.h"
    3535#include "util.h"
     36#include "cardutil.h"
    3637
    3738// ivtv header
    3839extern "C" {
     
    7778    // Debugging variables
    7879    deviceIsMpegFile(false),
    7980    bufferSize(4096),
     81    // Driver info
     82    card(QString::null),      driver(QString::null),
     83    version(0),               usingv4l2(false),
     84    has_buggy_vbi(true),      has_v4l2_vbi(false),
    8085    // State
    8186    recording(false),         encoding(false),
    8287    errored(false),
     
    311316        return false;
    312317    }
    313318
     319    if (CardUtil::GetV4LInfo(chanfd, card, driver, version))
     320    {
     321#define KERNEL_VERSION(a,b,c) (((a) << 16) + ((b) << 8) + (c))
     322        usingv4l2     = (version >= KERNEL_VERSION(0, 8, 0));
     323        has_v4l2_vbi  = (version >= KERNEL_VERSION(0, 3, 8));
     324        has_buggy_vbi = (version <  KERNEL_VERSION(0, 10, 0));
     325    }
     326
     327    VERBOSE(VB_IMPORTANT, QString("IVTV VBI usingv4l2(%1) has_v4l2_vbi(%2) "
     328                                  "has_buggy_vbi(%3)")
     329            .arg(usingv4l2).arg(has_v4l2_vbi).arg(has_buggy_vbi));
     330
    314331    struct v4l2_format vfmt;
    315332    bzero(&vfmt, sizeof(vfmt));
    316333
     
    374391                "If you are using an AverMedia M179 card this is normal.");
    375392    }
    376393
    377     if (!SetV4L2DeviceOptions(chanfd) && !SetIVTVDeviceOptions(chanfd))
     394    bool ok = true;
     395    if (usingv4l2)
     396        ok = SetV4L2DeviceOptions(chanfd);
     397    else
     398    {
     399        ok = SetIVTVDeviceOptions(chanfd);
     400        if (!ok)
     401            usingv4l2 = ok = SetV4L2DeviceOptions(chanfd);
     402    }
     403
     404    if (!ok)
    378405        return false;
    379406
     407    SetVBIOptions(chanfd);
     408
    380409    readfd = open(videodevice.ascii(), O_RDWR | O_NONBLOCK);
    381410    if (readfd < 0)
    382411    {
     
    425454
    426455    keyframedist = (ivtvcodec.framerate) ? 12 : keyframedist;
    427456
    428     if (vbimode)
     457    return true;
     458}
     459
     460static int streamtype_ivtv_to_v4l2(int st)
     461{
     462    switch (st)
    429463    {
    430 #ifdef IVTV_IOC_S_VBI_MODE
    431         struct ivtv_sliced_vbi_format vbifmt;
    432         bzero(&vbifmt, sizeof(struct ivtv_sliced_vbi_format));
    433         vbifmt.service_set = (1 == vbimode) ? VBI_TYPE_TELETEXT : VBI_TYPE_CC;
    434 
    435         if (ioctl(chanfd, IVTV_IOC_S_VBI_MODE, &vbifmt) < 0)
    436 #endif // IVTV_IOC_S_VBI_MODE
    437         {
    438 #ifdef V4L2_CAP_SLICED_VBI_CAPTURE
    439             struct v4l2_format vbi_fmt;
    440             bzero(&vbi_fmt, sizeof(struct v4l2_format));
    441             vbi_fmt.type = V4L2_BUF_TYPE_SLICED_VBI_CAPTURE;
    442             vbi_fmt.fmt.sliced.service_set = (1 == vbimode) ?
    443                 V4L2_SLICED_VBI_625 : V4L2_SLICED_VBI_525;
    444 
    445             if (ioctl(chanfd, VIDIOC_S_FMT, &vbi_fmt) < 0)
    446 #endif // V4L2_CAP_SLICED_VBI_CAPTURE
    447             {
    448                 VERBOSE(VB_IMPORTANT, "Can't enable VBI recording" + ENO);
    449             }
    450         }
    451 
    452 #ifdef IVTV_IOC_S_VBI_EMBED
    453         int embedon = 1;
    454         if (ioctl(chanfd, IVTV_IOC_S_VBI_EMBED, &embedon) < 0)
    455 #endif // IVTV_IOC_S_VBI_EMBED
    456         {
    457             VERBOSE(VB_IMPORTANT, LOC + "Can't enable VBI recording (2)"+ENO);
    458         }
    459 
    460 #ifdef IVTV_IOC_G_VBI_MODE
    461         ioctl(chanfd, IVTV_IOC_G_VBI_MODE, &vbifmt);
    462 
    463         VERBOSE(VB_RECORD, LOC + QString(
    464                     "VBI service:%1, packet size:%2, io size:%3")
    465                 .arg(vbifmt.service_set).arg(vbifmt.packet_size)
    466                 .arg(vbifmt.io_size));
    467 #endif // IVTV_IOC_G_VBI_MODE
     464        case 0:  return V4L2_MPEG_STREAM_TYPE_MPEG2_PS;
     465        case 1:  return V4L2_MPEG_STREAM_TYPE_MPEG2_TS;
     466        case 2:  return V4L2_MPEG_STREAM_TYPE_MPEG1_VCD;
     467        case 3:  return V4L2_MPEG_STREAM_TYPE_MPEG2_PS;  /* PES A/V    */
     468        case 5:  return V4L2_MPEG_STREAM_TYPE_MPEG2_PS;  /* PES V      */
     469        case 7:  return V4L2_MPEG_STREAM_TYPE_MPEG2_PS;  /* PES A      */
     470        case 10: return V4L2_MPEG_STREAM_TYPE_MPEG2_DVD;
     471        case 11: return V4L2_MPEG_STREAM_TYPE_MPEG1_VCD; /* VCD */
     472        case 12: return V4L2_MPEG_STREAM_TYPE_MPEG2_SVCD;
     473        case 13: return V4L2_MPEG_STREAM_TYPE_MPEG2_DVD; /* DVD-Special 1 */
     474        case 14: return V4L2_MPEG_STREAM_TYPE_MPEG2_DVD; /* DVD-Special 2 */
     475        default: return V4L2_MPEG_STREAM_TYPE_MPEG2_TS;
    468476    }
    469 
    470     return true;
    471477}
    472478
    473479bool MpegRecorder::SetV4L2DeviceOptions(int chanfd)
    474480{
    475     static const int kNumControls = 7;
     481    static const uint kNumControls = 7;
    476482    struct v4l2_ext_controls ctrls;
    477483    struct v4l2_ext_control ext_ctrl[kNumControls];
     484    QString control_description[kNumControls] =
     485    {
     486        "Audio Sampling Frequency",
     487        "Video Aspect ratio",
     488        "Audio Encoding",
     489        "Audio L2 Bitrate",
     490        "Video Average Bitrate",
     491        "Video Peak Bitrate",
     492        "MPEG Stream type",
     493    };
    478494
    479495    // Set controls
    480496    bzero(&ctrls,    sizeof(struct v4l2_ext_controls));
     
    512528    ext_ctrl[5].value = maxbitrate * 1000;
    513529
    514530    ext_ctrl[6].id    = V4L2_CID_MPEG_STREAM_TYPE;
    515     ext_ctrl[6].value = V4L2_MPEG_STREAM_TYPE_MPEG2_PS;
     531    ext_ctrl[6].value = streamtype_ivtv_to_v4l2(streamtype);
     532    // only PS supported with new API (at least as of 0.8.0)
     533    //ext_ctrl[6].value = V4L2_MPEG_STREAM_TYPE_MPEG2_PS;
    516534
    517     ctrls.ctrl_class  = V4L2_CTRL_CLASS_MPEG;
    518     ctrls.count       = kNumControls;
    519     ctrls.controls    = ext_ctrl;
     535    for (uint i = 0; i < kNumControls; i++)
     536    {
     537        int value = ext_ctrl[i].value;
    520538
    521     if (ioctl(chanfd, VIDIOC_S_EXT_CTRLS, &ctrls) < 0)
    522     {
    523         if (ctrls.error_idx >= ctrls.count)
     539        ctrls.ctrl_class  = V4L2_CTRL_CLASS_MPEG;
     540        ctrls.count       = 1;
     541        ctrls.controls    = ext_ctrl + i;
     542
     543        if (ioctl(chanfd, VIDIOC_S_EXT_CTRLS, &ctrls) < 0)
    524544        {
    525545            VERBOSE(VB_IMPORTANT, LOC_ERR +
    526                     "Could not set MPEG controls" + ENO);
     546                    QString("Could not set %1 to %2")
     547                    .arg(control_description[i]).arg(value) + ENO);
    527548        }
    528         else
    529         {
    530             VERBOSE(VB_IMPORTANT, LOC_ERR +
    531                     QString("Could not set MPEG controls %1 through %2.")
    532                     .arg(ctrls.error_idx)
    533                     .arg(ext_ctrl[ctrls.error_idx].value) + ENO);
    534         }
    535         return false;
    536549    }
    537550
    538551    // Get controls
     
    552565
    553566    keyframedist = ext_ctrl[0].value;
    554567
    555     // VBI is not yet working as of July 11th, 2006 with IVTV driver.
    556     // V4L2_CID_MPEG_STREAM_VBI_FMT needs to be finished/supported first.
    557     if (vbimode)
     568    return true;
     569}
     570
     571bool MpegRecorder::SetVBIOptions(int chanfd)
     572{
     573    if (!vbimode)
     574        return true;
     575
     576    if (has_buggy_vbi)
    558577    {
     578        VERBOSE(VB_IMPORTANT, LOC_WARN + "VBI recording with broken drivers."
     579                "\n\t\t\tUpgrade to ivtv 0.10.0 if you experience problems.");
     580    }
     581
     582    /****************************************************************/
     583    /** First tell driver which services we want to capture.       **/
     584
     585#ifdef IVTV_IOC_S_VBI_EMBED
     586    // used for ivtv driver versions 0.2.0-3.7.0
     587    if (!has_v4l2_vbi)
     588    {
     589        struct ivtv_sliced_vbi_format vbifmt;
     590        bzero(&vbifmt, sizeof(struct ivtv_sliced_vbi_format));
     591        vbifmt.service_set = (1 == vbimode) ? VBI_TYPE_TELETEXT : VBI_TYPE_CC;
     592
     593        if (ioctl(chanfd, IVTV_IOC_S_VBI_MODE, &vbifmt) < 0)
     594        {
     595            VERBOSE(VB_IMPORTANT, LOC_WARN +
     596                    "Can't enable VBI recording (1)" + ENO);
     597
     598            return false;
     599        }
     600
     601        if (ioctl(chanfd, IVTV_IOC_G_VBI_MODE, &vbifmt) >= 0)
     602        {
     603            VERBOSE(VB_RECORD, LOC + QString(
     604                        "VBI service:%1, packet size:%2, io size:%3")
     605                    .arg(vbifmt.service_set).arg(vbifmt.packet_size)
     606                    .arg(vbifmt.io_size));
     607        }
     608    }
     609#endif // IVTV_IOC_S_VBI_EMBED
     610
     611#ifdef IVTV_IOC_S_VBI_PASSTHROUGH
     612    // used for ivtv driver versions 0.3.8-0.7.x
     613    if (has_v4l2_vbi)
     614    {
     615        int embedon = (1 == vbimode) ? VBI_TYPE_TELETEXT : VBI_TYPE_CC;
     616
     617        if (ioctl(chanfd, IVTV_IOC_S_VBI_PASSTHROUGH, &embedon) < 0)
     618        {
     619            VERBOSE(VB_IMPORTANT, LOC_WARN +
     620                    "Can't enable VBI recording (2)" + ENO);
     621
     622            return false;
     623        }
     624    }
     625#endif // IVTV_IOC_S_VBI_PASSTHROUGH
     626
     627#ifdef V4L2_CAP_SLICED_VBI_CAPTURE
     628    // valid for ivtv driver versions 0.3.8+
     629    if (has_v4l2_vbi)
     630    {
    559631        struct v4l2_format vbifmt;
    560632        bzero(&vbifmt, sizeof(struct v4l2_format));
    561633        vbifmt.type = V4L2_BUF_TYPE_SLICED_VBI_CAPTURE;
    562         /* vbifmt.fmt.sliced.service_set = (1==vbimode) ?
    563                                            VBI_TYPE_TELETEXT : VBI_TYPE_CC; */
    564         if (1 == vbimode)
    565             vbifmt.fmt.sliced.service_set |= V4L2_SLICED_VBI_625;
    566         else
    567             vbifmt.fmt.sliced.service_set |= V4L2_SLICED_VBI_525;
     634        vbifmt.fmt.sliced.service_set |= (1 == vbimode) ?
     635            V4L2_SLICED_VBI_625 : V4L2_SLICED_VBI_525;
    568636
    569637        if (ioctl(chanfd, VIDIOC_S_FMT, &vbifmt) < 0)
    570638        {
    571             VERBOSE(VB_IMPORTANT, "Can't enable VBI recording" + ENO);
     639            VERBOSE(VB_IMPORTANT, LOC_WARN +
     640                    "Can't enable VBI recording (3)" + ENO);
     641
     642            return false;
    572643        }
    573644
    574         struct v4l2_ext_control vbi_fmt;
    575         vbi_fmt.id    = V4L2_CID_MPEG_STREAM_VBI_FMT;
    576         vbi_fmt.value = V4L2_MPEG_STREAM_VBI_FMT_IVTV;
     645        if (ioctl(chanfd, VIDIOC_G_FMT, &vbifmt) >= 0)
     646        {
     647            VERBOSE(VB_RECORD, LOC + QString("VBI service: %1, io size: %2")
     648                    .arg(vbifmt.fmt.sliced.service_set)
     649                    .arg(vbifmt.fmt.sliced.io_size));
     650        }
     651    }
     652#endif // V4L2_CAP_SLICED_VBI_CAPTURE
     653
     654    /****************************************************************/
     655    /** Second, tell driver to embed the captions in the stream.   **/
     656
     657#ifdef IVTV_IOC_S_VBI_EMBED
     658    // used for ivtv driver versions 0.2.0-0.7.x
     659    if (!usingv4l2)
     660    {
     661        int embedon = 1;
     662        if (ioctl(chanfd, IVTV_IOC_S_VBI_EMBED, &embedon) < 0)
     663        {
     664            VERBOSE(VB_IMPORTANT, LOC_WARN +
     665                    "Can't enable VBI recording (4)" + ENO);
     666
     667            return false;
     668        }
     669    }
     670#endif // IVTV_IOC_S_VBI_EMBED
     671
     672#ifdef V4L2_CAP_SLICED_VBI_CAPTURE
     673    // used for ivtv driver versions 0.8.0+
     674    if (usingv4l2)
     675    {
     676        struct v4l2_ext_control vbi_ctrl;
     677        vbi_ctrl.id      = V4L2_CID_MPEG_STREAM_VBI_FMT;
     678        vbi_ctrl.value   = V4L2_MPEG_STREAM_VBI_FMT_IVTV;
     679
     680        struct v4l2_ext_controls ctrls;
     681        bzero(&ctrls, sizeof(struct v4l2_ext_controls));
    577682        ctrls.ctrl_class = V4L2_CTRL_CLASS_MPEG;
    578683        ctrls.count      = 1;
    579         ctrls.controls   = &vbi_fmt;
     684        ctrls.controls   = &vbi_ctrl;
     685
    580686        if (ioctl(chanfd, VIDIOC_S_EXT_CTRLS, &ctrls) < 0)
    581687        {
    582             VERBOSE(VB_IMPORTANT, LOC + "Can't enable VBI recording (2)"+ENO);
     688            VERBOSE(VB_IMPORTANT, LOC_WARN +
     689                    "Can't enable VBI recording (5)" + ENO);
     690
     691            return false;
    583692        }
    584 
    585         ioctl(chanfd, VIDIOC_G_FMT, &vbifmt);
    586 
    587         VERBOSE(VB_RECORD, LOC + QString(
    588                 "VBI service:%1, io size:%3")
    589                 .arg(vbifmt.fmt.sliced.service_set)
    590                 .arg(vbifmt.fmt.sliced.io_size));
    591693    }
     694#endif // V4L2_CAP_SLICED_VBI_CAPTURE
    592695
    593696    return true;
    594697}
  • libs/libmythtv/recordingprofile.cpp

     
    847847    class Width : public SpinBoxSetting, public CodecParamStorage
    848848    {
    849849      public:
    850         Width(const RecordingProfile &parent, int maxwidth = 704,
     850        Width(const RecordingProfile &parent,
     851              uint defaultwidth, uint maxwidth,
    851852              bool transcoding = false) :
    852853            SpinBoxSetting(this, transcoding ? 0 : 160,
    853854                           maxwidth, 16, false,
     
    855856            CodecParamStorage(this, parent, "width")
    856857        {
    857858            setLabel(QObject::tr("Width"));
    858             setValue(480);
    859             if (transcoding)
    860                 setHelpText(QObject::tr("If the width is set to 'Auto', "
    861                             "the width will be calculated based on the height "
    862                             "and the recording's physical aspect ratio."));
     859            setValue(defaultwidth);
     860
     861            QString help = (transcoding) ?
     862                QObject::tr("If the width is set to 'Auto', the width "
     863                            "will be calculated based on the height and "
     864                            "the recording's physical aspect ratio.") :
     865                QObject::tr("Width to use for encoding. "
     866                            "Note: PVR-150 and PVR-500 devices do not "
     867                            "function correctly unless this is set to 720.");
     868
     869            setHelpText(help);
    863870        };
    864871    };
    865872
    866873    class Height: public SpinBoxSetting, public CodecParamStorage
    867874    {
    868875      public:
    869         Height(const RecordingProfile &parent, int maxheight=576,
     876        Height(const RecordingProfile &parent,
     877               uint defaultheight, uint maxheight,
    870878               bool transcoding = false):
    871879            SpinBoxSetting(this, transcoding ? 0 : 160,
    872880                           maxheight, 16, false,
     
    874882            CodecParamStorage(this, parent, "height")
    875883        {
    876884            setLabel(QObject::tr("Height"));
    877             setValue(480);
    878             if (transcoding)
    879                 setHelpText(QObject::tr("If the height is set to 'Auto', "
    880                             "the height will be calculated based on the width "
    881                             "and the recording's physical aspect ratio."));
     885            setValue(defaultheight);
     886
     887            QString help = (transcoding) ?
     888                QObject::tr("If the height is set to 'Auto', the height "
     889                            "will be calculated based on the width and "
     890                            "the recording's physical aspect ratio.") :
     891                QObject::tr("Height to use for encoding. "
     892                            "Note: PVR-150 and PVR-500 devices do not "
     893                            "function correctly unless this is set to "
     894                            "480 or 576 for NTSC and PAL, respectively.");
     895
     896            setHelpText(help);
    882897        };
    883898    };
    884899
     
    894909            labelName = profName + "->" + QObject::tr("Image size");
    895910        setLabel(labelName);
    896911
    897         QString fullsize, halfsize;
    898         int maxwidth, maxheight;
    899         bool transcoding = false;
    900         if (profName.left(11) == "Transcoders") {
    901             maxwidth = 1920;
    902             maxheight = 1088;
    903             transcoding = true;
    904         } else if ((tvFormat.lower() == "ntsc") ||
    905                    (tvFormat.lower() == "ntsc-jp")) {
    906             maxwidth = 720;
    907             maxheight = 480;
    908         } else if (tvFormat.lower() == "atsc") {
    909             maxwidth = 1920;
    910             maxheight = 1088;
    911         } else {
    912             maxwidth = 768;
    913             maxheight = 576;
     912        QSize defaultsize(768, 576), maxsize(768, 576);
     913        bool transcoding = profName.left(11) == "Transcoders";
     914        bool ivtv = profName.left(34) == "MPEG-2 Encoders (PVR-x50, PVR-500)";
     915
     916        if (transcoding)
     917        {
     918            maxsize     = QSize(1920, 1088);
     919            defaultsize = QSize(480, 480);
    914920        }
     921        else if (tvFormat.lower().left(4) == "ntsc")
     922        {
     923            maxsize     = QSize(720, 480);
     924            defaultsize = (ivtv) ? QSize(720, 480) : QSize(480, 480);
     925        }
     926        else if (tvFormat.lower() == "atsc")
     927        {
     928            maxsize     = QSize(1920, 1088);
     929            defaultsize = QSize(1920, 1088);
     930        }
     931        else
     932        {
     933            maxsize     = QSize(768, 576);
     934            defaultsize = (ivtv) ? QSize(720, 576) : QSize(480, 576);
     935        }
    915936
    916         imgSize->addChild(new Width(parent, maxwidth, transcoding));
    917         imgSize->addChild(new Height(parent, maxheight, transcoding));
     937        imgSize->addChild(new Width(parent, defaultsize.width(),
     938                                    maxsize.width(), transcoding));
     939        imgSize->addChild(new Height(parent, defaultsize.height(),
     940                                     maxsize.height(), transcoding));
     941
    918942        addChild(imgSize);
    919943    };
    920944};
     
    10011025{
    10021026    MSqlQuery result(MSqlQuery::InitCon());
    10031027    result.prepare(
    1004         "SELECT cardtype "
     1028        "SELECT cardtype, profilegroups.name "
    10051029        "FROM profilegroups, recordingprofiles "
    10061030        "WHERE profilegroups.id     = recordingprofiles.profilegroup AND "
    10071031        "      recordingprofiles.id = :PROFILEID");
     
    10131037    else if (result.next())
    10141038    {
    10151039        type = result.value(0).toString();
     1040        if (profileName.isEmpty())
     1041            profileName = result.value(1).toString();
    10161042        isEncoder = CardUtil::IsEncoder(type);
    10171043    }
    10181044