aboutsummaryrefslogtreecommitdiffstats
path: root/dvb-t/fi-Rovaniemi_Karhuvaara_Marrasjarvi
diff options
context:
space:
mode:
Diffstat (limited to 'dvb-t/fi-Rovaniemi_Karhuvaara_Marrasjarvi')
0 files changed, 0 insertions, 0 deletions
'#n76'>76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574
/*
 * test_av.c - Test for audio and video MPEG decoder API.
 *
 * Copyright (C) 2000 - 2002 convergence GmbH
 * Ralph Metzler <rjkm@convergence.de>
 * Marcus Metzler <mocm@convergence.de>
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public License
 * as published by the Free Software Foundation; either version 2.1
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 */

#include <sys/ioctl.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <time.h>
#include <unistd.h>

#include <linux/types.h>
#include <linux/dvb/audio.h>
#include <linux/dvb/video.h>

int audioStop(int fd, char *arg)
{
	if (arg)
		return -1;
	if (ioctl(fd, AUDIO_STOP) == -1)
		perror("AUDIO_STOP");
	return 0;
}

int audioPlay(int fd, char *arg)
{
	if (arg)
		return -1;
	if (ioctl(fd, AUDIO_PLAY)  == -1)
		perror("AUDIO_PLAY");
	return 0;
}

int audioPause(int fd, char *arg)
{
	if (arg)
		return -1;
	if (ioctl(fd, AUDIO_PAUSE) == -1)
		perror("AUDIO_PAUSE");
	return 0;
}


int audioContinue(int fd, char *arg)
{
	if (arg)
		return -1;
	if (ioctl(fd, AUDIO_CONTINUE) == -1)
		perror("AUDIO_CONTINUE");
	return 0;
}

int audioSelectSource(int fd, char *arg)
{
	int source;
	if (!arg)
		return -1;
	source = atoi(arg);
	if (ioctl(fd, AUDIO_SELECT_SOURCE, source) == -1)
		perror("AUDIO_SELECT_SOURCE");
	return 0;
}

int audioSetMute(int fd, char *arg)
{
	int mute;
	if (!arg)
		return -1;
	mute = atoi(arg);
	if (ioctl(fd, AUDIO_SET_MUTE, mute) == -1)
		perror("AUDIO_SET_MUTE");
	return 0;
}

int audioSetAVSync(int fd, char *arg)
{
	int _sync;
	if (!arg)
		return -1;
	_sync = atoi(arg);
	if (ioctl(fd, AUDIO_SET_AV_SYNC, _sync) == -1)
		perror("AUDIO_SET_AV_SYNC");
	return 0;
}

int audioSetBypassMode(int fd, char *arg)
{
	int byp;
	if (!arg)
		return -1;
	byp = atoi(arg);
	if (ioctl(fd, AUDIO_SET_BYPASS_MODE, byp) == -1)
		perror("AUDIO_SET_BYPASS_MODE");
	return 0;
}

int audioChannelSelect(int fd, char *arg)
{
	int chan;
	if (!arg)
		return -1;
	chan = atoi(arg);
	if (ioctl(fd, AUDIO_CHANNEL_SELECT, chan) == -1)
		perror("AUDIO_CHANNEL_SELECT");
	return 0;
}

int audioGetStatus(int fd, char *arg)
{
	struct audio_status _stat;

	if (arg)
		return -1;
	if (ioctl(fd, AUDIO_GET_STATUS, &_stat) == -1) {
		perror("AUDIO_GET_STATUS");
		return 0;
	}

	printf("Audio Status:\n");
	printf("  Sync State          : %s\n",
	       (_stat.AV_sync_state ? "SYNC" : "NO SYNC"));
	printf("  Mute State          : %s\n",
	       (_stat.mute_state ? "muted" : "not muted"));
	printf("  Play State          : ");
	switch ((int)_stat.play_state){
	case AUDIO_STOPPED:
		printf("STOPPED (%d)\n",_stat.play_state);
		break;
	case AUDIO_PLAYING:
		printf("PLAYING (%d)\n",_stat.play_state);
		break;
	case AUDIO_PAUSED:
		printf("PAUSED (%d)\n",_stat.play_state);
		break;
	default:
		printf("unknown (%d)\n",_stat.play_state);
		break;
	}

	printf("  Stream Source       : ");
	switch((int)_stat.stream_source){
	case AUDIO_SOURCE_DEMUX:
		printf("DEMUX (%d)\n",_stat.stream_source);
		break;
	case AUDIO_SOURCE_MEMORY:
		printf("MEMORY (%d)\n",_stat.stream_source);
		break;
	default:
		printf("unknown (%d)\n",_stat.stream_source);
		break;
	}

	printf("  Channel Select      : ");
	switch((int)_stat.channel_select){
	case AUDIO_STEREO:
		printf("Stereo (%d)\n",_stat.channel_select);
		break;
	case AUDIO_MONO_LEFT:
		printf("Mono left(%d)\n",_stat.channel_select);
		break;
	case AUDIO_MONO_RIGHT:
		printf("Mono right (%d)\n",_stat.channel_select);
		break;
	default:
		printf("unknown (%d)\n",_stat.channel_select);
		break;
	}
	printf("  Bypass Mode         : %s\n",
	       (_stat.bypass_mode ? "ON" : "OFF"));

	return 0;

}

int videoStop(int fd, char *arg)
{
	if (arg)
		return -1;
	if (ioctl(fd, VIDEO_STOP) == -1)
		perror("VIDEO_STOP");
	return 0;
}

int videoPlay(int fd, char *arg)
{
	if (arg)
		return -1;
	if (ioctl(fd, VIDEO_PLAY) == -1)
		perror("VIDEO_PLAY");
	return 0;
}


int videoFreeze(int fd, char *arg)
{
	if (arg)
		return -1;
	if (ioctl(fd, VIDEO_FREEZE) == -1)
		perror("VIDEO_FREEZE");
	return 0;
}


int videoContinue(int fd, char *arg)
{
	if (arg)
		return -1;
	if (ioctl(fd, VIDEO_CONTINUE) == -1)
		perror("VIDEO_CONTINUE");
	return 0;
}

int videoFormat(int fd, char *arg)
{
	int format;
	if (!arg)
		return -1;
	format = atoi(arg);
	if (ioctl(fd, VIDEO_SET_FORMAT, format) == -1)
		perror("VIDEO_SET_FORMAT");
	return 0;
}

int videoDisplayFormat(int fd, char *arg)
{
	int format;
	if (!arg)
		return -1;
	format = atoi(arg);
	if (ioctl(fd, VIDEO_SET_DISPLAY_FORMAT, format) == -1)
		perror("VIDEO_SET_DISPLAY_FORMAT");
	return 0;
}

int videoSelectSource(int fd, char *arg)
{
	int source;
	if (!arg)
		return -1;
	source = atoi(arg);
	if (ioctl(fd, VIDEO_SELECT_SOURCE, source) == -1)
		perror("VIDEO_SELECT_SOURCE");
	return 0;
}



int videoSetBlank(int fd, char *arg)
{
	int blank;
	if (!arg)
		return -1;
	blank = atoi(arg);
	if (ioctl(fd, VIDEO_SET_BLANK, blank) == -1)
		perror("VIDEO_SET_BLANK");
	return 0;
}

int videoFastForward(int fd, char *arg)
{
	int frames;
	if (!arg)
		return -1;
	frames = atoi(arg);
	if (ioctl(fd, VIDEO_FAST_FORWARD, frames) == -1)
		perror("VIDEO_FAST_FORWARD");
	return 0;
}

int videoSlowMotion(int fd, char *arg)
{
	int frames;
	if (!arg)
		return -1;
	frames = atoi(arg);
	if (ioctl(fd, VIDEO_SLOWMOTION, frames) == -1)
		perror("VIDEO_SLOWMOTION");
	return 0;
}

int videoGetStatus(int fd, char *arg)
{
	struct video_status _stat;

	if (arg)
		return -1;
	if (ioctl(fd, VIDEO_GET_STATUS, &_stat) == -1){
		perror("VIDEO_GET_STATUS");
		return 0;
	}

	printf("Video Status:\n");
	printf("  Blank State          : %s\n",
	       (_stat.video_blank ? "BLANK" : "STILL"));
	printf("  Play State           : ");
	switch ((int)_stat.play_state){
	case VIDEO_STOPPED:
		printf("STOPPED (%d)\n",_stat.play_state);
		break;
	case VIDEO_PLAYING:
		printf("PLAYING (%d)\n",_stat.play_state);
		break;
	case VIDEO_FREEZED:
		printf("FREEZED (%d)\n",_stat.play_state);
		break;
	default:
		printf("unknown (%d)\n",_stat.play_state);
		break;
	}

	printf("  Stream Source        : ");
	switch((int)_stat.stream_source){
	case VIDEO_SOURCE_DEMUX:
		printf("DEMUX (%d)\n",_stat.stream_source);
		break;
	case VIDEO_SOURCE_MEMORY:
		printf("MEMORY (%d)\n",_stat.stream_source);
		break;
	default:
		printf("unknown (%d)\n",_stat.stream_source);
		break;
	}

	printf("  Format (Aspect Ratio): ");
	switch((int)_stat.video_format){
	case VIDEO_FORMAT_4_3:
		printf("4:3 (%d)\n",_stat.video_format);
		break;
	case VIDEO_FORMAT_16_9:
		printf("16:9 (%d)\n",_stat.video_format);
		break;
	case VIDEO_FORMAT_221_1:
		printf("2.21:1 (%d)\n",_stat.video_format);
		break;
	default:
		printf("unknown (%d)\n",_stat.video_format);
		break;
	}

	printf("  Display Format       : ");
	switch((int)_stat.display_format){
	case VIDEO_PAN_SCAN:
		printf("Pan&Scan (%d)\n",_stat.display_format);
		break;
	case VIDEO_LETTER_BOX:
		printf("Letterbox (%d)\n",_stat.display_format);
		break;
	case VIDEO_CENTER_CUT_OUT:
		printf("Center cutout (%d)\n",_stat.display_format);
		break;
	default:
		printf("unknown (%d)\n",_stat.display_format);
		break;
	}
	return 0;
}

int videoGetSize(int fd, char *arg)
{
	video_size_t size;

	if (arg)
		return -1;
	if (ioctl(fd, VIDEO_GET_SIZE, &size) == -1){
		perror("VIDEO_GET_SIZE");
		return 0;
	}

	printf("Video Size: %ux%u ", size.w, size.h);
	switch (size.aspect_ratio) {
	case VIDEO_FORMAT_4_3:
		printf("4:3 (%d)\n", size.aspect_ratio);
		break;
	case VIDEO_FORMAT_16_9:
		printf("16:9 (%d)\n", size.aspect_ratio);
		break;
	case VIDEO_FORMAT_221_1:
		printf("2.21:1 (%d)\n", size.aspect_ratio);
		break;
	default:
		printf("unknown aspect ratio (%d)\n", size.aspect_ratio);
		break;
	}
	return 0;
}

int videoStillPicture(int fd, char *arg)
{
	int sifd;
	struct stat st;
	struct video_still_picture sp;

	if (!arg)
		return -1;
	sifd = open(arg, O_RDONLY);
	if (sifd == -1) {
		perror("open stillimage file");
		printf("(%s)\n", arg);
		return 0;
	}
	fstat(sifd, &st);

	sp.iFrame = (char *) malloc(st.st_size);
	sp.size = st.st_size;
	printf("I-frame size: %d\n", sp.size);

	if (!sp.iFrame) {
		printf("No memory for I-Frame\n");
		return 0;
	}

	printf("read: %d bytes\n", (int) read(sifd,sp.iFrame,sp.size));
	if (ioctl(fd, VIDEO_STILLPICTURE, &sp) == -1)
		perror("VIDEO_STILLPICTURE");
	return 0;
}

typedef int (* cmd_func_t)(int fd, char *args);
typedef struct {
	char *cmd;
	char *param_help;
	cmd_func_t cmd_func;
} cmd_t;
cmd_t audio_cmds[] =
{
	{ "stop", "", audioStop },
	{ "play", "", audioPlay },
	{ "pause", "", audioPause },
	{ "continue", "", audioContinue },
	{ "source", "n: 0 demux, 1 memory", audioSelectSource },
	{ "mute", "n: 0 unmute, 1 mute", audioSetMute },
	{ "avsync", "n: 0 unsync, 1 sync", audioSetAVSync },
	{ "bypass", "n: 0 normal, 1 bypass", audioSetBypassMode },
	{ "channel", "n: 0 stereo, 1 left, 2 right", audioChannelSelect },
	{ "status", "", audioGetStatus },
	{ NULL, NULL, NULL }
};
cmd_t video_cmds[] =
{
	{ "stop", "", videoStop },
	{ "play", "", videoPlay },
	{ "freeze", "", videoFreeze },
	{ "continue", "", videoContinue },
	{ "source", "n: 0 demux, 1 memory", videoSelectSource },
	{ "blank", "n: 0 normal, 1 blank", videoSetBlank },
	{ "ff", "n: number of frames", videoFastForward },
	{ "slow", "n: number of frames", videoSlowMotion },
	{ "status", "", videoGetStatus },
	{ "size", "", videoGetSize },
	{ "stillpic", "filename", videoStillPicture},
	{ "format", "n: 0 4:3, 1 16:9", videoFormat},
	{ "dispformat", "n: 0 pan&scan, 1 letter box, 2 center cut out", videoDisplayFormat},
	{ NULL, NULL, NULL }
};
int usage(void)
{
	int i;
	printf ("commands begin with a for audio and v for video:\n\n"
	        "q : quit\n");
	for (i=0; audio_cmds[i].cmd; i++)
		printf("a %s %s\n", audio_cmds[i].cmd, audio_cmds[i].param_help);
	for (i=0; video_cmds[i].cmd; i++)
		printf("v %s %s\n", video_cmds[i].cmd, video_cmds[i].param_help);
	printf("\n");
	return 0;
}

int syntax_error(void)
{
	fprintf(stderr, "syntax error\n");
	return 0;
}

int process_kbd_input(int vfd, int afd)
{
	char buf[256], *cmd;
	int i;

	if (!fgets(buf, sizeof(buf), stdin))
		return -1;
	cmd = strtok(buf, " \n\t");
	if (!cmd) {
		printf("enter command or h + enter for help\n");
		return 0;
	}
	if (cmd[0] == 'q' || !strcmp(cmd, "quit"))
		return -1;
	if (cmd[0] == 'h' || !strcmp(cmd, "help"))
		return usage();
	if (cmd[0] == 'a' || !strcmp(cmd, "audio")) {
		cmd = strtok(NULL, " \n\t");
		if (!cmd)
			return syntax_error();
		for (i=0; audio_cmds[i].cmd; i++) {
			if (!strcmp(cmd, audio_cmds[i].cmd)) {
				cmd = strtok(NULL, " \n\t");
				printf("calling '%s', arg '%s'\n", audio_cmds[i].cmd, cmd);
				if (audio_cmds[i].cmd_func(afd, cmd))
					syntax_error();
				return 0;
			}
		}
		return syntax_error();
	} else if (buf[0] == 'v') {
		cmd = strtok(NULL, " \n\t");
		if (!cmd)
			return usage();
		for (i=0; video_cmds[i].cmd; i++) {
			if (!strcmp(cmd, video_cmds[i].cmd)) {
				cmd = strtok(NULL, " \n\t");
				printf("calling '%s', arg '%s'\n", video_cmds[i].cmd, cmd);
				if (video_cmds[i].cmd_func(vfd, cmd))
					syntax_error();
				return 0;
			}
		}
		return syntax_error();
	} else
		return syntax_error();
	return 0;
}

int main(void)
{
	int vfd, afd;
	char *videodev = "/dev/dvb/adapter0/video0";
	char *audiodev = "/dev/dvb/adapter0/audio0";

	if (getenv("VIDEO"))
		videodev = getenv("VIDEO");
	if (getenv("AUDIO"))
		videodev = getenv("AUDIO");

	printf("using video device '%s'\n", videodev);
	printf("using audio device '%s'\n", audiodev);
	printf("enter command or h + enter for help\n");

	if ((vfd = open(videodev, O_RDWR | O_NONBLOCK)) < 0) {
		perror("open video device");
		return 1;
	}
	if ((afd = open(audiodev, O_RDWR | O_NONBLOCK)) < 0) {
		perror("open audio device");
		return 1;
	}

	while (process_kbd_input(vfd, afd) == 0)
		;

	close(vfd);
	close(afd);
	return 0;
}