~ubuntu-branches/ubuntu/karmic/mplayer/karmic

« back to all changes in this revision

Viewing changes to stream/tvi_v4l.c

  • Committer: Bazaar Package Importer
  • Author(s): Reinhard Tartler
  • Date: 2009-06-06 23:01:52 UTC
  • mfrom: (0.1.6 squeeze) (1.1.5 upstream)
  • Revision ID: james.westby@ubuntu.com-20090606230152-qxn13xfnq65nz088
Tags: 2:1.0~rc3+svn20090426-1ubuntu1
* Switch to debian packaging for the mplayer package
* New upstream release, LP: #336697, #260918, #246675, #243453, #74282
* Fixes security issues: CVE-2008-5616, LP: #308939
* many flv fixes LP: #73271, #347021
* Build and install mencoder
* Bump epoch

Show diffs side-by-side

added added

removed removed

Lines of Context:
20
20
#include <stdio.h>
21
21
#include <errno.h>
22
22
#include <fcntl.h>
23
 
#include <signal.h>
24
23
#include <sys/ioctl.h>
25
24
#include <sys/types.h>
26
25
#include <sys/time.h>
50
49
 
51
50
static tvi_handle_t *tvi_init_v4l(tv_param_t* tv_param);
52
51
 
53
 
tvi_info_t tvi_info_v4l = {
 
52
const tvi_info_t tvi_info_v4l = {
54
53
    tvi_init_v4l,
55
54
    "Video 4 Linux input",
56
55
    "v4l",
142
141
    long                        audio_recv_blocks_total;
143
142
    long                        audio_sent_blocks_total;
144
143
    long                        mjpeg_bufsize;
145
 
#ifdef HAVE_TV_TELETEXT
 
144
#ifdef CONFIG_TV_TELETEXT
146
145
    char                        *vbi_dev;
147
146
    int                         vbi_fd;
148
147
    int                         vbi_bufsize;
169
168
};
170
169
#define PALETTE(x) ((x < sizeof(device_palette2name)/sizeof(char*)) ? device_palette2name[x] : "UNKNOWN")
171
170
 
 
171
static const struct {
 
172
    char* name;
 
173
    int normid;
 
174
    int tuner_flags;
 
175
    int tuner_mode;
 
176
    int input_norm;
 
177
    float fps;
 
178
} supported_norms[]={
 
179
    {"pal",   TV_NORM_PAL,    VIDEO_TUNER_PAL,   VIDEO_MODE_PAL,  VIDEO_MODE_PAL,  PAL_FPS },
 
180
    {"ntsc",  TV_NORM_NTSC,   VIDEO_TUNER_NTSC,  VIDEO_MODE_NTSC, VIDEO_MODE_NTSC, NTSC_FPS},
 
181
    {"secam", TV_NORM_SECAM,  VIDEO_TUNER_SECAM, VIDEO_MODE_SECAM,VIDEO_MODE_SECAM,PAL_FPS },
 
182
    {"palnc", TV_NORM_PALNC,  VIDEO_TUNER_PAL,   VIDEO_MODE_PAL,  3,               PAL_FPS },
 
183
    {"palm",  TV_NORM_PALM,   VIDEO_TUNER_NTSC,  VIDEO_MODE_NTSC, 4,               NTSC_FPS},
 
184
    {"paln",  TV_NORM_PALN,   VIDEO_TUNER_PAL,   VIDEO_MODE_PAL,  5,               PAL_FPS },
 
185
    {"ntscjp",TV_NORM_NTSCJP, VIDEO_TUNER_NTSC,  VIDEO_MODE_NTSC, 6,               NTSC_FPS},
 
186
    {"auto",  -1,             -1,                -1,              VIDEO_MODE_AUTO, -1      },
 
187
    {NULL,    -1,             -1,                -1,              -1      }
 
188
};
 
189
 
172
190
static const char *norm2name(int mode)
173
191
{
174
 
    switch (mode) {
175
 
    case VIDEO_MODE_PAL:
176
 
        return "pal";
177
 
    case VIDEO_MODE_SECAM:
178
 
        return "secam";
179
 
    case VIDEO_MODE_NTSC:
180
 
        return "ntsc";
181
 
    case VIDEO_MODE_AUTO:
182
 
        return "auto";
183
 
    default:
184
 
        return "unknown";
185
 
    }
 
192
    int i;
 
193
    for(i=0;supported_norms[i].name; i++)
 
194
        if(supported_norms[i].input_norm==mode)
 
195
            return supported_norms[i].name;
 
196
    return "unknown";
186
197
};
187
198
 
188
199
static const char *audio_mode2name(int mode)
210
221
    {
211
222
        /* component */
212
223
        case VIDEO_PALETTE_RGB555:
213
 
            return(15);
 
224
            return 15;
214
225
        case VIDEO_PALETTE_RGB565:
215
 
            return(16);
 
226
            return 16;
216
227
        case VIDEO_PALETTE_RGB24:
217
 
            return(24);
 
228
            return 24;
218
229
        case VIDEO_PALETTE_RGB32:
219
 
            return(32);
 
230
            return 32;
220
231
        /* planar */
221
232
        case VIDEO_PALETTE_YUV411P:
222
233
        case VIDEO_PALETTE_YUV420P:
223
234
        case VIDEO_PALETTE_YUV410P:
224
 
            return(12);
 
235
            return 12;
225
236
        /* packed */
226
237
        case VIDEO_PALETTE_YUV422P:
227
238
        case VIDEO_PALETTE_YUV422:
229
240
        case VIDEO_PALETTE_UYVY:
230
241
        case VIDEO_PALETTE_YUV420:
231
242
        case VIDEO_PALETTE_YUV411:
232
 
            return(16);
 
243
            return 16;
233
244
    }
234
 
    return(-1);
 
245
    return -1;
235
246
}
236
247
 
237
248
static int format2palette(int format)
239
250
    switch(format)
240
251
    {
241
252
        case IMGFMT_BGR15:
242
 
            return(VIDEO_PALETTE_RGB555);
 
253
            return VIDEO_PALETTE_RGB555;
243
254
        case IMGFMT_BGR16:
244
 
            return(VIDEO_PALETTE_RGB565);
 
255
            return VIDEO_PALETTE_RGB565;
245
256
        case IMGFMT_BGR24:
246
 
            return(VIDEO_PALETTE_RGB24);
 
257
            return VIDEO_PALETTE_RGB24;
247
258
        case IMGFMT_BGR32:
248
 
            return(VIDEO_PALETTE_RGB32);
 
259
            return VIDEO_PALETTE_RGB32;
249
260
        case IMGFMT_YV12:
250
261
        case IMGFMT_I420:
251
 
            return(VIDEO_PALETTE_YUV420P);
 
262
            return VIDEO_PALETTE_YUV420P;
252
263
        case IMGFMT_YUY2:
253
 
            return(VIDEO_PALETTE_YUV422);
 
264
            return VIDEO_PALETTE_YUV422;
254
265
    case IMGFMT_UYVY:
255
 
       return(VIDEO_PALETTE_UYVY);
 
266
       return VIDEO_PALETTE_UYVY;
256
267
    }
257
 
    return(-1);
 
268
    return -1;
258
269
}
259
270
 
260
271
// sets and sanitizes audio buffer/block sizes
285
296
 
286
297
    h = new_handle();
287
298
    if (!h)
288
 
        return(NULL);
 
299
        return NULL;
289
300
 
290
301
    priv = h->priv;
291
302
 
305
316
    /* allocation failed */
306
317
    if (!priv->video_device) {
307
318
        free_handle(h);
308
 
        return(NULL);
 
319
        return NULL;
309
320
    }
310
321
 
311
322
    priv->tv_param=tv_param;
312
 
    return(h);
 
323
    return h;
313
324
}
314
325
 
315
326
/* retrieves info about audio channels from the BTTV */
616
627
    /* audio init */
617
628
    if (!priv->tv_param->noaudio) {
618
629
 
619
 
#if defined(HAVE_ALSA9) || defined(HAVE_ALSA1X)
 
630
#ifdef CONFIG_ALSA
620
631
        if (priv->tv_param->alsa)
621
632
            audio_in_init(&priv->audio_in, AUDIO_IN_ALSA);
622
633
        else
647
658
        setup_audio_buffer_sizes(priv);
648
659
    }
649
660
 
650
 
    return(1);
 
661
    return 1;
651
662
 
652
663
malloc_failed:
653
664
    if (priv->channels)
657
668
err:
658
669
    if (priv->video_fd != -1)
659
670
        close(priv->video_fd);
660
 
    return(0);
 
671
    return 0;
661
672
}
662
673
 
663
674
static int uninit(priv_t *priv)
664
675
{
665
676
    unsigned long num;
666
677
 
667
 
#ifdef HAVE_TV_TELETEXT
 
678
#ifdef CONFIG_TV_TELETEXT
668
679
    priv->vbi_shutdown=1;
669
680
    if(priv->vbi_grabber_thread)
670
681
        pthread_join(priv->vbi_grabber_thread, NULL);
693
704
        pthread_mutex_destroy(&priv->skew_mutex);
694
705
    }
695
706
    pthread_mutex_destroy(&priv->video_buffer_mutex);
696
 
    pthread_join(priv->video_grabber_thread, NULL);
 
707
    if(priv->video_grabber_thread)
 
708
        pthread_join(priv->video_grabber_thread, NULL);
 
709
 
697
710
    mp_msg(MSGT_TV, MSGL_V, "done\n");
698
711
 
699
712
    if (priv->capability.audios) {
738
751
            free(priv->audio_skew_buffer);
739
752
    }
740
753
 
741
 
    return(1);
 
754
    return 1;
742
755
}
743
756
 
744
757
static int get_capture_buffer_size(priv_t *priv)
768
781
    return cnt;
769
782
}
770
783
 
771
 
#ifdef HAVE_TV_TELETEXT
 
784
#ifdef CONFIG_TV_TELETEXT
772
785
static int vbi_init(priv_t* priv,char* device)
773
786
{
774
787
    int vbi_fd=0;
865
878
 
866
879
    while (!priv->vbi_shutdown){
867
880
        bytes=read(priv->vbi_fd,buf,tsp.bufsize);
 
881
        if(bytes<0 && errno==EINTR)
 
882
            continue;
868
883
        if (bytes!=tsp.bufsize){
869
884
            mp_msg(MSGT_TV,MSGL_WARN,"vbi: expecting bytes: %d, got: %d",tsp.bufsize,bytes);
870
885
            break;
882
897
    free(buf);
883
898
    return NULL;
884
899
}
885
 
#endif //HAVE_TV_TELETEXT
 
900
#endif /* CONFIG_TV_TELETEXT */
886
901
 
887
902
static int start(priv_t *priv)
888
903
{
893
908
    if (ioctl(priv->video_fd, VIDIOCGPICT, &priv->picture) == -1)
894
909
    {
895
910
        mp_msg(MSGT_TV, MSGL_ERR, "ioctl get picture failed: %s\n", strerror(errno));
896
 
        return(0);
 
911
        return 0;
897
912
    }
898
913
 
899
914
    priv->picture.palette = format2palette(priv->format);
984
999
        if (ioctl(priv->video_fd, VIDIOCSPLAYMODE, &pmode) == -1)
985
1000
        {
986
1001
            mp_msg(MSGT_TV, MSGL_ERR, "ioctl set play mode failed: %s\n", strerror(errno));
987
 
//          return(0);
 
1002
//          return 0;
988
1003
        }
989
1004
    }
990
1005
#endif
994
1009
    if (ioctl(priv->video_fd, VIDIOCCAPTURE, &one) == -1)
995
1010
    {
996
1011
        mp_msg(MSGT_TV, MSGL_ERR, "FATAL: ioctl ccapture failed: %s\n", strerror(errno));
997
 
        return(0);
 
1012
        return 0;
998
1013
    }
999
1014
#endif
1000
1015
 
1096
1111
        ioctl(priv->video_fd, VIDIOCSAUDIO, &priv->audio[priv->audio_id]);
1097
1112
    }
1098
1113
 
1099
 
#ifdef HAVE_TV_TELETEXT
 
1114
#ifdef CONFIG_TV_TELETEXT
1100
1115
    /* start vbi thread */
1101
1116
    if(priv->priv_vbi){
1102
1117
        priv->vbi_shutdown = 0;
1115
1130
    pthread_mutex_init(&priv->video_buffer_mutex, NULL);
1116
1131
    /* we'll launch the video capture later, when a first request for a frame arrives */
1117
1132
 
1118
 
    return(1);
 
1133
    return 1;
1119
1134
}
1120
1135
 
1121
1136
 
1129
1144
        case TVI_CONTROL_IS_VIDEO:
1130
1145
        {
1131
1146
            if (priv->capability.type & VID_TYPE_CAPTURE)
1132
 
                return(TVI_CONTROL_TRUE);
1133
 
            return(TVI_CONTROL_FALSE);
 
1147
                return TVI_CONTROL_TRUE;
 
1148
            return TVI_CONTROL_FALSE;
1134
1149
        }
1135
1150
        case TVI_CONTROL_IS_AUDIO:
1136
 
            if (priv->tv_param->force_audio) return(TVI_CONTROL_TRUE);
 
1151
            if (priv->tv_param->force_audio) return TVI_CONTROL_TRUE;
1137
1152
            if (priv->channels[priv->act_channel].flags & VIDEO_VC_AUDIO)
1138
1153
            {
1139
 
                return(TVI_CONTROL_TRUE);
 
1154
                return TVI_CONTROL_TRUE;
1140
1155
            }
1141
 
            return(TVI_CONTROL_FALSE);
 
1156
            return TVI_CONTROL_FALSE;
1142
1157
        case TVI_CONTROL_IS_TUNER:
1143
1158
        {
1144
1159
//          if (priv->capability.type & VID_TYPE_TUNER)
1145
1160
            if (priv->channels[priv->act_channel].flags & VIDEO_VC_TUNER)
1146
 
                return(TVI_CONTROL_TRUE);
1147
 
            return(TVI_CONTROL_FALSE);
 
1161
                return TVI_CONTROL_TRUE;
 
1162
            return TVI_CONTROL_FALSE;
1148
1163
        }
1149
1164
 
1150
1165
        /* ========== VIDEO controls =========== */
1166
1181
                *(int *)arg = output_fmt;
1167
1182
                mp_msg(MSGT_TV, MSGL_V, "Output format: %s\n", vo_format_name(output_fmt));
1168
1183
            }
1169
 
            return(TVI_CONTROL_TRUE);
 
1184
            return TVI_CONTROL_TRUE;
1170
1185
        }
1171
1186
        case TVI_CONTROL_VID_SET_FORMAT:
1172
1187
            priv->format = *(int *)arg;
1178
1193
                priv->format &= ~IMGFMT_RGB_MASK;
1179
1194
                priv->format |= IMGFMT_BGR;
1180
1195
            }
1181
 
            return(TVI_CONTROL_TRUE);
 
1196
            return TVI_CONTROL_TRUE;
1182
1197
        case TVI_CONTROL_VID_GET_PLANES:
1183
1198
            *(int *)arg = 1; /* FIXME, also not needed at this time */
1184
 
            return(TVI_CONTROL_TRUE);
 
1199
            return TVI_CONTROL_TRUE;
1185
1200
        case TVI_CONTROL_VID_GET_BITS:
1186
1201
            *(int *)arg = palette2depth(format2palette(priv->format));
1187
 
            return(TVI_CONTROL_TRUE);
 
1202
            return TVI_CONTROL_TRUE;
1188
1203
        case TVI_CONTROL_VID_GET_WIDTH:
1189
1204
            *(int *)arg = priv->width;
1190
 
            return(TVI_CONTROL_TRUE);
 
1205
            return TVI_CONTROL_TRUE;
1191
1206
        case TVI_CONTROL_VID_CHK_WIDTH:
1192
1207
        {
1193
1208
            int req_width = *(int *)arg;
1195
1210
            mp_msg(MSGT_TV, MSGL_V, "Requested width: %d\n", req_width);
1196
1211
            if ((req_width >= priv->capability.minwidth) &&
1197
1212
                (req_width <= priv->capability.maxwidth))
1198
 
                return(TVI_CONTROL_TRUE);
1199
 
            return(TVI_CONTROL_FALSE);
 
1213
                return TVI_CONTROL_TRUE;
 
1214
            return TVI_CONTROL_FALSE;
1200
1215
        }
1201
1216
        case TVI_CONTROL_VID_SET_WIDTH:
1202
1217
            priv->width = *(int *)arg;
1203
 
            return(TVI_CONTROL_TRUE);
 
1218
            return TVI_CONTROL_TRUE;
1204
1219
        case TVI_CONTROL_VID_GET_HEIGHT:
1205
1220
            *(int *)arg = priv->height;
1206
 
            return(TVI_CONTROL_TRUE);
 
1221
            return TVI_CONTROL_TRUE;
1207
1222
        case TVI_CONTROL_VID_CHK_HEIGHT:
1208
1223
        {
1209
1224
            int req_height = *(int *)arg;
1211
1226
            mp_msg(MSGT_TV, MSGL_V, "Requested height: %d\n", req_height);
1212
1227
            if ((req_height >= priv->capability.minheight) &&
1213
1228
                (req_height <= priv->capability.maxheight))
1214
 
                return(TVI_CONTROL_TRUE);
1215
 
            return(TVI_CONTROL_FALSE);
 
1229
                return TVI_CONTROL_TRUE;
 
1230
            return TVI_CONTROL_FALSE;
1216
1231
        }
1217
1232
        case TVI_CONTROL_VID_SET_HEIGHT:
1218
1233
            priv->height = *(int *)arg;
1219
 
            return(TVI_CONTROL_TRUE);
 
1234
            return TVI_CONTROL_TRUE;
1220
1235
        case TVI_CONTROL_VID_GET_PICTURE:
1221
1236
            if (ioctl(priv->video_fd, VIDIOCGPICT, &priv->picture) == -1)
1222
1237
            {
1223
1238
                mp_msg(MSGT_TV, MSGL_ERR, "ioctl get picture failed: %s\n", strerror(errno));
1224
 
                return(TVI_CONTROL_FALSE);
 
1239
                return TVI_CONTROL_FALSE;
1225
1240
            }
1226
 
            return(TVI_CONTROL_TRUE);
 
1241
            return TVI_CONTROL_TRUE;
1227
1242
        case TVI_CONTROL_VID_SET_PICTURE:
1228
1243
            if (ioctl(priv->video_fd, VIDIOCSPICT, &priv->picture) == -1)
1229
1244
            {
1230
1245
                mp_msg(MSGT_TV, MSGL_ERR, "ioctl set picture failed: %s\n", strerror(errno));
1231
 
                return(TVI_CONTROL_FALSE);
 
1246
                return TVI_CONTROL_FALSE;
1232
1247
            }
1233
 
            return(TVI_CONTROL_TRUE);
 
1248
            return TVI_CONTROL_TRUE;
1234
1249
        case TVI_CONTROL_VID_SET_BRIGHTNESS:
1235
1250
            priv->picture.brightness = (327*(*(int *)arg+100)) + 68;
1236
1251
            return control(priv, TVI_CONTROL_VID_SET_PICTURE, 0);
1261
1276
            return 1;
1262
1277
        case TVI_CONTROL_VID_GET_FPS:
1263
1278
            *(float *)arg=priv->fps;
1264
 
            return(TVI_CONTROL_TRUE);
 
1279
            return TVI_CONTROL_TRUE;
1265
1280
 
1266
1281
        /* ========== TUNER controls =========== */
1267
1282
        case TVI_CONTROL_TUN_GET_FREQ:
1271
1286
            if (ioctl(priv->video_fd, VIDIOCGFREQ, &freq) == -1)
1272
1287
            {
1273
1288
                mp_msg(MSGT_TV, MSGL_ERR, "ioctl get freq failed: %s\n", strerror(errno));
1274
 
                return(TVI_CONTROL_FALSE);
 
1289
                return TVI_CONTROL_FALSE;
1275
1290
            }
1276
1291
 
1277
1292
            /* tuner uses khz not mhz ! */
1278
1293
//          if (priv->tuner.flags & VIDEO_TUNER_LOW)
1279
1294
//              freq /= 1000;
1280
1295
            *(unsigned long *)arg = freq;
1281
 
            return(TVI_CONTROL_TRUE);
 
1296
            return TVI_CONTROL_TRUE;
1282
1297
        }
1283
1298
        case TVI_CONTROL_TUN_SET_FREQ:
1284
1299
        {
1299
1314
            if (ioctl(priv->video_fd, VIDIOCSFREQ, &freq) == -1)
1300
1315
            {
1301
1316
                mp_msg(MSGT_TV, MSGL_ERR, "ioctl set freq failed: %s\n", strerror(errno));
1302
 
                return(TVI_CONTROL_FALSE);
 
1317
                return TVI_CONTROL_FALSE;
1303
1318
            }
1304
1319
            usleep(100000); // wait to suppress noise during switching
1305
1320
 
1308
1323
                ioctl(priv->video_fd, VIDIOCSAUDIO, &priv->audio[priv->audio_id]);
1309
1324
            }
1310
1325
 
1311
 
            return(TVI_CONTROL_TRUE);
 
1326
            return TVI_CONTROL_TRUE;
1312
1327
        }
1313
1328
        case TVI_CONTROL_TUN_GET_TUNER:
1314
1329
        {
1315
1330
            if (ioctl(priv->video_fd, VIDIOCGTUNER, &priv->tuner) == -1)
1316
1331
            {
1317
1332
                mp_msg(MSGT_TV, MSGL_ERR, "ioctl get tuner failed: %s\n", strerror(errno));
1318
 
                return(TVI_CONTROL_FALSE);
 
1333
                return TVI_CONTROL_FALSE;
1319
1334
            }
1320
1335
 
1321
1336
            mp_msg(MSGT_TV, MSGL_V, "Tuner (%s) range: %lu -> %lu\n", priv->tuner.name,
1322
1337
                priv->tuner.rangelow, priv->tuner.rangehigh);
1323
 
            return(TVI_CONTROL_TRUE);
 
1338
            return TVI_CONTROL_TRUE;
1324
1339
        }
1325
1340
        case TVI_CONTROL_TUN_SET_TUNER:
1326
1341
        {
1327
1342
            if (ioctl(priv->video_fd, VIDIOCSTUNER, &priv->tuner) == -1)
1328
1343
            {
1329
1344
                mp_msg(MSGT_TV, MSGL_ERR, "ioctl set tuner failed: %s\n", strerror(errno));
1330
 
                return(TVI_CONTROL_FALSE);
 
1345
                return TVI_CONTROL_FALSE;
1331
1346
            }
1332
 
            return(TVI_CONTROL_TRUE);
 
1347
            return TVI_CONTROL_TRUE;
1333
1348
        }
1334
1349
        case TVI_CONTROL_TUN_SET_NORM:
1335
1350
        {
1336
1351
            int req_mode = *(int *)arg;
 
1352
            int norm_index;
 
1353
            for(norm_index=0;supported_norms[norm_index].name; norm_index++)
 
1354
                if(req_mode==supported_norms[norm_index].normid)
 
1355
                    break;
1337
1356
 
1338
 
            if ((req_mode != TV_NORM_PAL) && (req_mode != TV_NORM_NTSC) && (req_mode != TV_NORM_SECAM)
1339
 
                && (req_mode != TV_NORM_PALNC) && (req_mode != TV_NORM_PALM) && (req_mode != TV_NORM_PALN)
1340
 
                && (req_mode != TV_NORM_NTSCJP)) {
 
1357
            if(!supported_norms[norm_index].name) {
1341
1358
                mp_msg(MSGT_TV, MSGL_ERR, "Unknown norm!\n");
1342
 
                return(TVI_CONTROL_FALSE);
 
1359
                return TVI_CONTROL_FALSE;
1343
1360
            }
1344
1361
 
1345
1362
            if (priv->channels[priv->act_channel].flags & VIDEO_VC_TUNER) {
1346
1363
                int prev_mode;
1347
1364
 
1348
1365
                control(priv, TVI_CONTROL_TUN_GET_TUNER, 0);
1349
 
                if (((req_mode == TV_NORM_PAL
1350
 
                      || req_mode == TV_NORM_PALNC
1351
 
                      || req_mode == TV_NORM_PALN) && !(priv->tuner.flags & VIDEO_TUNER_PAL)) ||
1352
 
                    ((req_mode == TV_NORM_NTSC
1353
 
                      || req_mode == TV_NORM_NTSCJP
1354
 
                      || req_mode == TV_NORM_PALM) && !(priv->tuner.flags & VIDEO_TUNER_NTSC)) ||
1355
 
                    ((req_mode == TV_NORM_SECAM) && !(priv->tuner.flags & VIDEO_TUNER_SECAM)))
 
1366
                if(!(priv->tuner.flags & supported_norms[norm_index].tuner_flags))
1356
1367
                {
1357
1368
                    mp_msg(MSGT_TV, MSGL_ERR, "Tuner isn't capable to set norm!\n");
1358
 
                    return(TVI_CONTROL_FALSE);
 
1369
                    return TVI_CONTROL_FALSE;
1359
1370
                }
1360
1371
 
1361
1372
                prev_mode = priv->tuner.mode;
1362
1373
 
1363
 
                switch(req_mode) {
1364
 
                case TV_NORM_PAL:
1365
 
                case TV_NORM_PALNC:
1366
 
                case TV_NORM_PALN:
1367
 
                    priv->tuner.mode = VIDEO_MODE_PAL;
1368
 
                    break;
1369
 
                case TV_NORM_NTSC:
1370
 
                case TV_NORM_NTSCJP:
1371
 
                case TV_NORM_PALM:
1372
 
                    priv->tuner.mode = VIDEO_MODE_NTSC;
1373
 
                    break;
1374
 
                case TV_NORM_SECAM:
1375
 
                    priv->tuner.mode = VIDEO_MODE_SECAM;
1376
 
                    break;
1377
 
                }
 
1374
                priv->tuner.mode = supported_norms[norm_index].tuner_mode;
1378
1375
 
1379
1376
                if (control(priv, TVI_CONTROL_TUN_SET_TUNER, &priv->tuner) != TVI_CONTROL_TRUE) {
1380
1377
                    // norm setting failed, but maybe it's only because it's fixed
1381
 
                    if (priv->tuner.mode != prev_mode) return(TVI_CONTROL_FALSE); // no it really failed
 
1378
                    if (priv->tuner.mode != prev_mode) return TVI_CONTROL_FALSE; // no it really failed
1382
1379
                }
1383
1380
 
1384
1381
            }
1385
1382
 
1386
 
            switch(req_mode) {
1387
 
            case TV_NORM_PAL:
1388
 
                priv->channels[priv->act_channel].norm = VIDEO_MODE_PAL;
1389
 
                break;
1390
 
            case TV_NORM_NTSC:
1391
 
                priv->channels[priv->act_channel].norm = VIDEO_MODE_NTSC;
1392
 
                break;
1393
 
            case TV_NORM_SECAM:
1394
 
                priv->channels[priv->act_channel].norm = VIDEO_MODE_SECAM;
1395
 
                break;
1396
 
            case TV_NORM_PALNC:
1397
 
                priv->channels[priv->act_channel].norm = 3;
1398
 
                break;
1399
 
            case TV_NORM_PALM:
1400
 
                priv->channels[priv->act_channel].norm = 4;
1401
 
                break;
1402
 
            case TV_NORM_PALN:
1403
 
                priv->channels[priv->act_channel].norm = 5;
1404
 
                break;
1405
 
            case TV_NORM_NTSCJP:
1406
 
                priv->channels[priv->act_channel].norm = 6;
1407
 
                break;
1408
 
            }
 
1383
            priv->channels[priv->act_channel].norm = supported_norms[norm_index].input_norm;
 
1384
 
1409
1385
            if (ioctl(priv->video_fd, VIDIOCSCHAN, &priv->channels[priv->act_channel]) == -1)
1410
1386
            {
1411
1387
                mp_msg(MSGT_TV, MSGL_ERR, "ioctl set chan failed: %s\n", strerror(errno));
1412
 
                return(TVI_CONTROL_FALSE);
 
1388
                return TVI_CONTROL_FALSE;
1413
1389
            }
1414
1390
 
1415
1391
            if (ioctl(priv->video_fd, VIDIOCGCAP, &priv->capability) == -1) {
1416
1392
                mp_msg(MSGT_TV, MSGL_ERR, "ioctl get capabilites failed: %s\n", strerror(errno));
1417
 
                return(TVI_CONTROL_FALSE);
1418
 
            }
1419
 
 
1420
 
            if(req_mode == TV_NORM_PAL || req_mode == TV_NORM_SECAM || req_mode == TV_NORM_PALN || req_mode == TV_NORM_PALNC) {
1421
 
                priv->fps = PAL_FPS;
1422
 
            }
1423
 
 
1424
 
            if(req_mode == TV_NORM_NTSC || req_mode == TV_NORM_NTSCJP || req_mode == TV_NORM_PALM) {
1425
 
                priv->fps = NTSC_FPS;
1426
 
            }
 
1393
                return TVI_CONTROL_FALSE;
 
1394
            }
 
1395
 
 
1396
            priv->fps = supported_norms[norm_index].fps;
1427
1397
 
1428
1398
            if(priv->height > priv->capability.maxheight) {
1429
1399
                priv->height = priv->capability.maxheight;
1433
1403
                priv->width = priv->capability.maxwidth;
1434
1404
            }
1435
1405
 
1436
 
            return(TVI_CONTROL_TRUE);
 
1406
            return TVI_CONTROL_TRUE;
1437
1407
        }
1438
1408
        case TVI_CONTROL_TUN_GET_NORM:
1439
1409
        {
1440
1410
            *(int *)arg = priv->tuner.mode;
1441
1411
 
1442
 
            return(TVI_CONTROL_TRUE);
 
1412
            return TVI_CONTROL_TRUE;
1443
1413
        }
1444
1414
        case TVI_CONTROL_TUN_GET_SIGNAL:
1445
1415
        {
1446
1416
            if (ioctl(priv->video_fd, VIDIOCGTUNER, &priv->tuner) == -1)
1447
1417
            {
1448
1418
                mp_msg(MSGT_TV, MSGL_ERR, "ioctl get tuner failed: %s\n", strerror(errno));
1449
 
                return(TVI_CONTROL_FALSE);
 
1419
                return TVI_CONTROL_FALSE;
1450
1420
            }
1451
1421
            *(int*)arg=100*(priv->tuner.signal>>8)/255;
1452
 
            return(TVI_CONTROL_TRUE);
 
1422
            return TVI_CONTROL_TRUE;
1453
1423
        }
1454
1424
 
1455
1425
        /* ========== AUDIO controls =========== */
1456
1426
        case TVI_CONTROL_AUD_GET_FORMAT:
1457
1427
        {
1458
1428
            *(int *)arg = AF_FORMAT_S16_LE;
1459
 
            return(TVI_CONTROL_TRUE);
 
1429
            return TVI_CONTROL_TRUE;
1460
1430
        }
1461
1431
        case TVI_CONTROL_AUD_GET_CHANNELS:
1462
1432
        {
1463
1433
            *(int *)arg = priv->audio_in.channels;
1464
 
            return(TVI_CONTROL_TRUE);
 
1434
            return TVI_CONTROL_TRUE;
1465
1435
        }
1466
1436
        case TVI_CONTROL_AUD_GET_SAMPLERATE:
1467
1437
        {
1468
1438
            *(int *)arg = priv->audio_in.samplerate;
1469
 
            return(TVI_CONTROL_TRUE);
 
1439
            return TVI_CONTROL_TRUE;
1470
1440
        }
1471
1441
        case TVI_CONTROL_AUD_GET_SAMPLESIZE:
1472
1442
        {
1473
1443
            *(int *)arg = priv->audio_in.bytes_per_sample;
1474
 
            return(TVI_CONTROL_TRUE);
 
1444
            return TVI_CONTROL_TRUE;
1475
1445
        }
1476
1446
        case TVI_CONTROL_AUD_SET_SAMPLERATE:
1477
1447
        {
1478
1448
            if (audio_in_set_samplerate(&priv->audio_in, *(int *)arg) < 0) return TVI_CONTROL_FALSE;
1479
1449
            setup_audio_buffer_sizes(priv);
1480
 
            return(TVI_CONTROL_TRUE);
 
1450
            return TVI_CONTROL_TRUE;
1481
1451
        }
1482
1452
        /* ========== SPECIFIC controls =========== */
1483
1453
        case TVI_CONTROL_SPC_GET_INPUT:
1496
1466
            if (ioctl(priv->video_fd, VIDIOCGCHAN, &priv->channels[i]) == -1)
1497
1467
            {
1498
1468
                mp_msg(MSGT_TV, MSGL_ERR, "ioctl get channel failed: %s\n", strerror(errno));
1499
 
                return(TVI_CONTROL_FALSE);
 
1469
                return TVI_CONTROL_FALSE;
1500
1470
            }
1501
 
            return(TVI_CONTROL_TRUE);
 
1471
            return TVI_CONTROL_TRUE;
1502
1472
        }
1503
1473
 
1504
1474
        case TVI_CONTROL_SPC_SET_INPUT:
1511
1481
            {
1512
1482
                mp_msg(MSGT_TV, MSGL_ERR, "Invalid input requested: %d, valid: 0-%d\n",
1513
1483
                       req_chan, priv->capability.channels - 1);
1514
 
                return(TVI_CONTROL_FALSE);
 
1484
                return TVI_CONTROL_FALSE;
1515
1485
            }
1516
1486
 
1517
1487
            for (i = 0; i < priv->capability.channels; i++)
1523
1493
            if (ioctl(priv->video_fd, VIDIOCSCHAN, &chan) == -1)
1524
1494
            {
1525
1495
                mp_msg(MSGT_TV, MSGL_ERR, "ioctl set chan failed: %s\n", strerror(errno));
1526
 
                return(TVI_CONTROL_FALSE);
 
1496
                return TVI_CONTROL_FALSE;
1527
1497
            }
1528
1498
            mp_msg(MSGT_TV, MSGL_INFO, "Using input '%s'\n", chan.name);
1529
1499
 
1536
1506
 
1537
1507
            /* update local channel list */
1538
1508
            control(priv, TVI_CONTROL_SPC_GET_INPUT, &req_chan);
1539
 
            return(TVI_CONTROL_TRUE);
 
1509
            return TVI_CONTROL_TRUE;
1540
1510
        case TVI_CONTROL_IMMEDIATE:
1541
1511
            priv->immediate_mode = 1;
1542
 
            return(TVI_CONTROL_TRUE);
 
1512
            return TVI_CONTROL_TRUE;
1543
1513
        }
1544
 
#ifdef HAVE_TV_TELETEXT
 
1514
#ifdef CONFIG_TV_TELETEXT
1545
1515
        case TVI_CONTROL_VBI_INIT:
1546
1516
        {
1547
1517
            void* ptr;
1564
1534
#endif
1565
1535
    }
1566
1536
 
1567
 
    return(TVI_CONTROL_UNKNOWN);
 
1537
    return TVI_CONTROL_UNKNOWN;
1568
1538
}
1569
1539
 
1570
1540
static int set_mute(priv_t* priv,int value)
1840
1810
 
1841
1811
static int get_video_framesize(priv_t *priv)
1842
1812
{
1843
 
    return(priv->bytesperline * priv->height);
 
1813
    return priv->bytesperline * priv->height;
1844
1814
}
1845
1815
 
1846
1816
static void *audio_grabber(void *data)
1940
1910
 
1941
1911
static int get_audio_framesize(priv_t *priv)
1942
1912
{
1943
 
    return(priv->audio_in.blocksize);
 
1913
    return priv->audio_in.blocksize;
1944
1914
}