Mercurial > mplayer.hg
comparison stream/tvi_v4l2.c @ 23886:5af94a1df41e
Removing global variables from tv://
Step 5: removing references to old globals from tvi_v4l2.c
author | voroshil |
---|---|
date | Sun, 29 Jul 2007 10:21:48 +0000 |
parents | d65439444b75 |
children | 657236b9eacb |
comparison
equal
deleted
inserted
replaced
23885:ed7579c21164 | 23886:5af94a1df41e |
---|---|
357 | 357 |
358 static void init_audio(priv_t *priv) | 358 static void init_audio(priv_t *priv) |
359 { | 359 { |
360 if (priv->audio_inited) return; | 360 if (priv->audio_inited) return; |
361 | 361 |
362 if (!tv_param_noaudio) { | 362 if (!priv->tv_param->noaudio) { |
363 #if defined(HAVE_ALSA9) || defined(HAVE_ALSA1X) | 363 #if defined(HAVE_ALSA9) || defined(HAVE_ALSA1X) |
364 if (tv_param_alsa) | 364 if (priv->tv_param->alsa) |
365 audio_in_init(&priv->audio_in, AUDIO_IN_ALSA); | 365 audio_in_init(&priv->audio_in, AUDIO_IN_ALSA); |
366 else | 366 else |
367 audio_in_init(&priv->audio_in, AUDIO_IN_OSS); | 367 audio_in_init(&priv->audio_in, AUDIO_IN_OSS); |
368 #else | 368 #else |
369 audio_in_init(&priv->audio_in, AUDIO_IN_OSS); | 369 audio_in_init(&priv->audio_in, AUDIO_IN_OSS); |
379 audio_in_set_channels(&priv->audio_in, 2); | 379 audio_in_set_channels(&priv->audio_in, 2); |
380 } else { | 380 } else { |
381 audio_in_set_channels(&priv->audio_in, 1); | 381 audio_in_set_channels(&priv->audio_in, 1); |
382 } | 382 } |
383 } else { | 383 } else { |
384 if (tv_param_forcechan >= 0) { | 384 if (priv->tv_param->forcechan >= 0) { |
385 audio_in_set_channels(&priv->audio_in, tv_param_forcechan); | 385 audio_in_set_channels(&priv->audio_in, priv->tv_param->forcechan); |
386 } else { | 386 } else { |
387 audio_in_set_channels(&priv->audio_in, 2); | 387 audio_in_set_channels(&priv->audio_in, 2); |
388 } | 388 } |
389 } | 389 } |
390 | 390 |
559 switch(cmd) { | 559 switch(cmd) { |
560 case TVI_CONTROL_IS_VIDEO: | 560 case TVI_CONTROL_IS_VIDEO: |
561 return priv->capability.capabilities & V4L2_CAP_VIDEO_CAPTURE? | 561 return priv->capability.capabilities & V4L2_CAP_VIDEO_CAPTURE? |
562 TVI_CONTROL_TRUE: TVI_CONTROL_FALSE; | 562 TVI_CONTROL_TRUE: TVI_CONTROL_FALSE; |
563 case TVI_CONTROL_IS_AUDIO: | 563 case TVI_CONTROL_IS_AUDIO: |
564 if (tv_param_force_audio) return TVI_CONTROL_TRUE; | 564 if (priv->tv_param->force_audio) return TVI_CONTROL_TRUE; |
565 case TVI_CONTROL_IS_TUNER: | 565 case TVI_CONTROL_IS_TUNER: |
566 return priv->capability.capabilities & V4L2_CAP_TUNER? | 566 return priv->capability.capabilities & V4L2_CAP_TUNER? |
567 TVI_CONTROL_TRUE: TVI_CONTROL_FALSE; | 567 TVI_CONTROL_TRUE: TVI_CONTROL_FALSE; |
568 case TVI_CONTROL_IMMEDIATE: | 568 case TVI_CONTROL_IMMEDIATE: |
569 priv->immediate_mode = 1; | 569 priv->immediate_mode = 1; |
902 info.short_name, strerror(errno)); | 902 info.short_name, strerror(errno)); |
903 } | 903 } |
904 } | 904 } |
905 | 905 |
906 /* stop audio thread */ | 906 /* stop audio thread */ |
907 if (!tv_param_noaudio && priv->audio_grabber_thread) { | 907 if (!priv->tv_param->noaudio && priv->audio_grabber_thread) { |
908 pthread_join(priv->audio_grabber_thread, NULL); | 908 pthread_join(priv->audio_grabber_thread, NULL); |
909 pthread_mutex_destroy(&priv->skew_mutex); | 909 pthread_mutex_destroy(&priv->skew_mutex); |
910 pthread_mutex_destroy(&priv->audio_mutex); | 910 pthread_mutex_destroy(&priv->audio_mutex); |
911 } | 911 } |
912 | 912 |
923 for (i = 0; i < priv->video_buffer_size_current; i++) { | 923 for (i = 0; i < priv->video_buffer_size_current; i++) { |
924 free(priv->video_ringbuffer[i].data); | 924 free(priv->video_ringbuffer[i].data); |
925 } | 925 } |
926 free(priv->video_ringbuffer); | 926 free(priv->video_ringbuffer); |
927 } | 927 } |
928 if (!tv_param_noaudio) { | 928 if (!priv->tv_param->noaudio) { |
929 if (priv->audio_ringbuffer) | 929 if (priv->audio_ringbuffer) |
930 free(priv->audio_ringbuffer); | 930 free(priv->audio_ringbuffer); |
931 if (priv->audio_skew_buffer) | 931 if (priv->audio_skew_buffer) |
932 free(priv->audio_skew_buffer); | 932 free(priv->audio_skew_buffer); |
933 if (priv->audio_skew_delta_buffer) | 933 if (priv->audio_skew_delta_buffer) |
1084 info.short_name, strerror(errno)); | 1084 info.short_name, strerror(errno)); |
1085 uninit(priv); | 1085 uninit(priv); |
1086 return 0; | 1086 return 0; |
1087 } | 1087 } |
1088 | 1088 |
1089 // if (!(priv->capability.capabilities & V4L2_CAP_AUDIO) && !tv_param_force_audio) tv_param_noaudio = 1; | 1089 // if (!(priv->capability.capabilities & V4L2_CAP_AUDIO) && !priv->tv_param->force_audio) priv->tv_param->noaudio = 1; |
1090 | 1090 |
1091 if (priv->capability.capabilities & V4L2_CAP_TUNER) { | 1091 if (priv->capability.capabilities & V4L2_CAP_TUNER) { |
1092 struct v4l2_control control; | 1092 struct v4l2_control control; |
1093 if (tv_param_amode >= 0) { | 1093 if (priv->tv_param->amode >= 0) { |
1094 mp_msg(MSGT_TV, MSGL_V, "%s: setting audio mode\n", info.short_name); | 1094 mp_msg(MSGT_TV, MSGL_V, "%s: setting audio mode\n", info.short_name); |
1095 priv->tuner.audmode = amode2v4l(tv_param_amode); | 1095 priv->tuner.audmode = amode2v4l(priv->tv_param->amode); |
1096 if (ioctl(priv->video_fd, VIDIOC_S_TUNER, &priv->tuner) < 0) { | 1096 if (ioctl(priv->video_fd, VIDIOC_S_TUNER, &priv->tuner) < 0) { |
1097 mp_msg(MSGT_TV, MSGL_ERR, "%s: ioctl set tuner failed: %s\n", | 1097 mp_msg(MSGT_TV, MSGL_ERR, "%s: ioctl set tuner failed: %s\n", |
1098 info.short_name, strerror(errno)); | 1098 info.short_name, strerror(errno)); |
1099 return TVI_CONTROL_FALSE; | 1099 return TVI_CONTROL_FALSE; |
1100 } | 1100 } |
1103 (priv->tuner.audmode == V4L2_TUNER_MODE_MONO) ? " MONO" : "", | 1103 (priv->tuner.audmode == V4L2_TUNER_MODE_MONO) ? " MONO" : "", |
1104 (priv->tuner.audmode == V4L2_TUNER_MODE_STEREO) ? " STEREO" : "", | 1104 (priv->tuner.audmode == V4L2_TUNER_MODE_STEREO) ? " STEREO" : "", |
1105 (priv->tuner.audmode == V4L2_TUNER_MODE_LANG1) ? " LANG1" : "", | 1105 (priv->tuner.audmode == V4L2_TUNER_MODE_LANG1) ? " LANG1" : "", |
1106 (priv->tuner.audmode == V4L2_TUNER_MODE_LANG2) ? " LANG2" : ""); | 1106 (priv->tuner.audmode == V4L2_TUNER_MODE_LANG2) ? " LANG2" : ""); |
1107 | 1107 |
1108 if (tv_param_volume >= 0) { | 1108 if (priv->tv_param->volume >= 0) { |
1109 control.id = V4L2_CID_AUDIO_VOLUME; | 1109 control.id = V4L2_CID_AUDIO_VOLUME; |
1110 control.value = tv_param_volume; | 1110 control.value = priv->tv_param->volume; |
1111 set_control(priv, &control, 0); | 1111 set_control(priv, &control, 0); |
1112 } | 1112 } |
1113 if (tv_param_bass >= 0) { | 1113 if (priv->tv_param->bass >= 0) { |
1114 control.id = V4L2_CID_AUDIO_BASS; | 1114 control.id = V4L2_CID_AUDIO_BASS; |
1115 control.value = tv_param_bass; | 1115 control.value = priv->tv_param->bass; |
1116 set_control(priv, &control, 0); | 1116 set_control(priv, &control, 0); |
1117 } | 1117 } |
1118 if (tv_param_treble >= 0) { | 1118 if (priv->tv_param->treble >= 0) { |
1119 control.id = V4L2_CID_AUDIO_TREBLE; | 1119 control.id = V4L2_CID_AUDIO_TREBLE; |
1120 control.value = tv_param_treble; | 1120 control.value = priv->tv_param->treble; |
1121 set_control(priv, &control, 0); | 1121 set_control(priv, &control, 0); |
1122 } | 1122 } |
1123 if (tv_param_balance >= 0) { | 1123 if (priv->tv_param->balance >= 0) { |
1124 control.id = V4L2_CID_AUDIO_BALANCE; | 1124 control.id = V4L2_CID_AUDIO_BALANCE; |
1125 control.value = tv_param_balance; | 1125 control.value = priv->tv_param->balance; |
1126 set_control(priv, &control, 0); | 1126 set_control(priv, &control, 0); |
1127 } | 1127 } |
1128 } | 1128 } |
1129 | 1129 |
1130 return 1; | 1130 return 1; |
1132 | 1132 |
1133 static int get_capture_buffer_size(priv_t *priv) | 1133 static int get_capture_buffer_size(priv_t *priv) |
1134 { | 1134 { |
1135 int bufsize, cnt; | 1135 int bufsize, cnt; |
1136 | 1136 |
1137 if (tv_param_buffer_size >= 0) { | 1137 if (priv->tv_param->buffer_size >= 0) { |
1138 bufsize = tv_param_buffer_size*1024*1024; | 1138 bufsize = priv->tv_param->buffer_size*1024*1024; |
1139 } else { | 1139 } else { |
1140 #ifdef HAVE_SYS_SYSINFO_H | 1140 #ifdef HAVE_SYS_SYSINFO_H |
1141 struct sysinfo si; | 1141 struct sysinfo si; |
1142 | 1142 |
1143 sysinfo(&si); | 1143 sysinfo(&si); |
1164 int i; | 1164 int i; |
1165 | 1165 |
1166 /* setup audio parameters */ | 1166 /* setup audio parameters */ |
1167 | 1167 |
1168 init_audio(priv); | 1168 init_audio(priv); |
1169 if (!tv_param_noaudio && !priv->audio_inited) return 0; | 1169 if (!priv->tv_param->noaudio && !priv->audio_inited) return 0; |
1170 | 1170 |
1171 /* we need this to size the audio buffer properly */ | 1171 /* we need this to size the audio buffer properly */ |
1172 if (priv->immediate_mode) { | 1172 if (priv->immediate_mode) { |
1173 priv->video_buffer_size_max = 2; | 1173 priv->video_buffer_size_max = 2; |
1174 } else { | 1174 } else { |
1175 priv->video_buffer_size_max = get_capture_buffer_size(priv); | 1175 priv->video_buffer_size_max = get_capture_buffer_size(priv); |
1176 } | 1176 } |
1177 | 1177 |
1178 if (!tv_param_noaudio) { | 1178 if (!priv->tv_param->noaudio) { |
1179 setup_audio_buffer_sizes(priv); | 1179 setup_audio_buffer_sizes(priv); |
1180 priv->audio_skew_buffer = calloc(priv->aud_skew_cnt, sizeof(long long)); | 1180 priv->audio_skew_buffer = calloc(priv->aud_skew_cnt, sizeof(long long)); |
1181 if (!priv->audio_skew_buffer) { | 1181 if (!priv->audio_skew_buffer) { |
1182 mp_msg(MSGT_TV, MSGL_ERR, "cannot allocate skew buffer: %s\n", strerror(errno)); | 1182 mp_msg(MSGT_TV, MSGL_ERR, "cannot allocate skew buffer: %s\n", strerror(errno)); |
1183 return 0; | 1183 return 0; |
1215 pthread_mutex_init(&priv->skew_mutex, NULL); | 1215 pthread_mutex_init(&priv->skew_mutex, NULL); |
1216 pthread_mutex_init(&priv->audio_mutex, NULL); | 1216 pthread_mutex_init(&priv->audio_mutex, NULL); |
1217 } | 1217 } |
1218 | 1218 |
1219 /* setup video parameters */ | 1219 /* setup video parameters */ |
1220 if (!tv_param_noaudio) { | 1220 if (!priv->tv_param->noaudio) { |
1221 if (priv->video_buffer_size_max < (3*priv->standard.frameperiod.denominator) / | 1221 if (priv->video_buffer_size_max < (3*priv->standard.frameperiod.denominator) / |
1222 priv->standard.frameperiod.numerator | 1222 priv->standard.frameperiod.numerator |
1223 *priv->audio_secs_per_block) { | 1223 *priv->audio_secs_per_block) { |
1224 mp_msg(MSGT_TV, MSGL_ERR, "Video buffer shorter than 3 times audio frame duration.\n" | 1224 mp_msg(MSGT_TV, MSGL_ERR, "Video buffer shorter than 3 times audio frame duration.\n" |
1225 "You will probably experience heavy framedrops.\n"); | 1225 "You will probably experience heavy framedrops.\n"); |
1315 | 1315 |
1316 // copies a video frame | 1316 // copies a video frame |
1317 static inline void copy_frame(priv_t *priv, video_buffer_entry *dest, unsigned char *source,int len) | 1317 static inline void copy_frame(priv_t *priv, video_buffer_entry *dest, unsigned char *source,int len) |
1318 { | 1318 { |
1319 dest->framesize=len; | 1319 dest->framesize=len; |
1320 if(tv_param_automute>0){ | 1320 if(priv->tv_param->automute>0){ |
1321 if (ioctl(priv->video_fd, VIDIOC_G_TUNER, &priv->tuner) >= 0) { | 1321 if (ioctl(priv->video_fd, VIDIOC_G_TUNER, &priv->tuner) >= 0) { |
1322 if(tv_param_automute<<8>priv->tuner.signal){ | 1322 if(priv->tv_param->automute<<8>priv->tuner.signal){ |
1323 fill_blank_frame(dest->data,dest->framesize,fcc_vl2mp(priv->format.fmt.pix.pixelformat)); | 1323 fill_blank_frame(dest->data,dest->framesize,fcc_vl2mp(priv->format.fmt.pix.pixelformat)); |
1324 set_mute(priv,1); | 1324 set_mute(priv,1); |
1325 return; | 1325 return; |
1326 } | 1326 } |
1327 } | 1327 } |
1354 info.short_name, strerror(errno)); | 1354 info.short_name, strerror(errno)); |
1355 return 0; | 1355 return 0; |
1356 } | 1356 } |
1357 priv->streamon = 1; | 1357 priv->streamon = 1; |
1358 | 1358 |
1359 if (!tv_param_noaudio) { | 1359 if (!priv->tv_param->noaudio) { |
1360 pthread_create(&priv->audio_grabber_thread, NULL, audio_grabber, priv); | 1360 pthread_create(&priv->audio_grabber_thread, NULL, audio_grabber, priv); |
1361 } | 1361 } |
1362 | 1362 |
1363 for (priv->frames = 0; !priv->shutdown;) | 1363 for (priv->frames = 0; !priv->shutdown;) |
1364 { | 1364 { |
1431 continue; | 1431 continue; |
1432 } | 1432 } |
1433 | 1433 |
1434 /* store the timestamp of the very first frame as reference */ | 1434 /* store the timestamp of the very first frame as reference */ |
1435 if (!priv->frames++) { | 1435 if (!priv->frames++) { |
1436 if (!tv_param_noaudio) pthread_mutex_lock(&priv->skew_mutex); | 1436 if (!priv->tv_param->noaudio) pthread_mutex_lock(&priv->skew_mutex); |
1437 priv->first_frame = (long long)1e6*buf.timestamp.tv_sec + buf.timestamp.tv_usec; | 1437 priv->first_frame = (long long)1e6*buf.timestamp.tv_sec + buf.timestamp.tv_usec; |
1438 if (!tv_param_noaudio) pthread_mutex_unlock(&priv->skew_mutex); | 1438 if (!priv->tv_param->noaudio) pthread_mutex_unlock(&priv->skew_mutex); |
1439 } | 1439 } |
1440 priv->curr_frame = (long long)buf.timestamp.tv_sec*1e6+buf.timestamp.tv_usec; | 1440 priv->curr_frame = (long long)buf.timestamp.tv_sec*1e6+buf.timestamp.tv_usec; |
1441 // fprintf(stderr, "idx = %d, ts = %lf\n", buf.index, (double)(priv->curr_frame) / 1e6); | 1441 // fprintf(stderr, "idx = %d, ts = %lf\n", buf.index, (double)(priv->curr_frame) / 1e6); |
1442 | 1442 |
1443 interval = priv->curr_frame - priv->first_frame; | 1443 interval = priv->curr_frame - priv->first_frame; |
1444 delta = interval - prev_interval; | 1444 delta = interval - prev_interval; |
1445 | 1445 |
1446 if (!priv->immediate_mode) { | 1446 if (!priv->immediate_mode) { |
1447 // interpolate the skew in time | 1447 // interpolate the skew in time |
1448 if (!tv_param_noaudio) pthread_mutex_lock(&priv->skew_mutex); | 1448 if (!priv->tv_param->noaudio) pthread_mutex_lock(&priv->skew_mutex); |
1449 xskew = priv->audio_skew + (interval - priv->audio_skew_measure_time)*priv->audio_skew_factor; | 1449 xskew = priv->audio_skew + (interval - priv->audio_skew_measure_time)*priv->audio_skew_factor; |
1450 if (!tv_param_noaudio) pthread_mutex_unlock(&priv->skew_mutex); | 1450 if (!priv->tv_param->noaudio) pthread_mutex_unlock(&priv->skew_mutex); |
1451 // correct extreme skew changes to avoid (especially) moving backwards in time | 1451 // correct extreme skew changes to avoid (especially) moving backwards in time |
1452 if (xskew - prev_skew > delta*MAX_SKEW_DELTA) { | 1452 if (xskew - prev_skew > delta*MAX_SKEW_DELTA) { |
1453 skew = prev_skew + delta*MAX_SKEW_DELTA; | 1453 skew = prev_skew + delta*MAX_SKEW_DELTA; |
1454 } else if (xskew - prev_skew < -delta*MAX_SKEW_DELTA) { | 1454 } else if (xskew - prev_skew < -delta*MAX_SKEW_DELTA) { |
1455 skew = prev_skew - delta*MAX_SKEW_DELTA; | 1455 skew = prev_skew - delta*MAX_SKEW_DELTA; |