DVB streams

Egor Shibeko <[email protected]>
Newsgroups gmane.comp.video.xine.user
Message-ID <20080716120613.18c5bfc0.egor.shibeko__34107.0628063337$1216209995$gmane$org@gmail.com>
Hello,

The task is to check if the DVB TS is OK. The streams are sent by getstream. I used the sources as in the attached files, but sometimes it failed to get elementary streams (usually, either audio or video stream), i.e. xine_get_stream_info returned 1 for XINE_STREAM_INFO_HAS_AUDIO, but returned 0 for XINE_STREAM_INFO_AUDIO_CHANNELS even if I tried with long timeout. Then I checked it in some seconds and it was OK.

What it could be connected with?

Thank You.
-- 
Egor Shibeko <[email protected]>

-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/

_______________________________________________
xine-user mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/xine-user
xine_checker.c (text/x-csrc, 4.9 KB)
#include "xine_checker.h"
#include "log.h"

#include <stdio.h>

enum { stream_state_unknown = 0, stream_state_finished, stream_state_ok };

struct stream_context
{
	struct xine_checker *checker;
	const char *uri;
	#if 0
	xine_stream_t *st;
	#endif
	int state;
};

static inline struct log *xine_checker_log(const struct xine_checker *checker)
{
	return (struct log *)checker->log;
}

static inline struct log *stream_context_log(const struct stream_context *ctx)
{
	return xine_checker_log(ctx->checker);
}

static inline int stream_context_init(struct stream_context *ctx, struct xine_checker *checker, const char *uri)
{
	ctx->checker = checker;
	ctx->uri = uri;

	#if 0
	ctx->st = xine_stream_new(checker->xine, checker->ao, checker->vo);
	if (ctx->st == NULL)
	{
		log_error(xine_checker_log(checker), "failed to create xine stream object, error code %d", xine_get_error(NULL));
		return 0;
	}
	#endif

	ctx->state = stream_state_unknown;

	return 1;
}

static inline void stream_context_deinit(struct stream_context *ctx)
{
	#if 0
	xine_dispose(ctx->st);
	#endif
}

static inline xine_stream_t *stream_context_get_stream(struct stream_context *ctx)
{
	return ctx->checker->st;
}

static void xine_event_cb(void *user_data, const xine_event_t *event)
{
	struct stream_context *ctx = user_data;
	uint32_t has_audio, audio_flag;
	uint32_t has_video, video_flag;

	switch (event->type)
	{
	case XINE_EVENT_UI_PLAYBACK_FINISHED:
		if (ctx->state == stream_state_unknown)
			ctx->state = stream_state_finished;
		break;
	case XINE_EVENT_UI_CHANNELS_CHANGED:
		has_audio = xine_get_stream_info(stream_context_get_stream(ctx), XINE_STREAM_INFO_HAS_AUDIO);
		audio_flag = xine_get_stream_info(stream_context_get_stream(ctx), XINE_STREAM_INFO_AUDIO_CHANNELS);

		has_video = xine_get_stream_info(stream_context_get_stream(ctx), XINE_STREAM_INFO_HAS_VIDEO);
		video_flag = xine_get_stream_info(stream_context_get_stream(ctx), XINE_STREAM_INFO_VIDEO_RATIO);

		log_xtreme(xine_checker_log(ctx->checker), "%s: %u/%u, %u/%u", ctx->uri,
			has_audio, audio_flag, has_video, video_flag);
		if ((!has_audio || audio_flag != 0) && (!has_video || video_flag != 0))
			ctx->state = stream_state_ok;
		break;
	}
}

static inline int stream_context_check(struct stream_context *ctx, double timeout)
{
	xine_event_queue_t *queue;
	time_t start_time;

	ctx->state = stream_state_unknown;

	queue = xine_event_new_queue(stream_context_get_stream(ctx));
	if (queue != NULL)
	{
		xine_event_create_listener_thread(queue, xine_event_cb, ctx);

		if (!xine_open(stream_context_get_stream(ctx), ctx->uri))
			log_error(stream_context_log(ctx), "failed to open uri %s, error code %d",
				ctx->uri, xine_get_error(stream_context_get_stream(ctx)));
		else
		{
			if (!xine_play(stream_context_get_stream(ctx), 0, 0))
				log_error(stream_context_log(ctx), "failed to play uri %s, error code %d",
					ctx->uri, xine_get_error(stream_context_get_stream(ctx)));
			else
			{
				log_xtreme(stream_context_log(ctx), "%s: check timeout %.2lf", ctx->uri, timeout);
				start_time = time(NULL);
				while (ctx->state == stream_state_unknown && difftime(time(NULL), start_time) < timeout)
					usleep(100);
				log_xtreme(stream_context_log(ctx), "%s: check result %d", ctx->uri, ctx->state);
			}
			xine_close(stream_context_get_stream(ctx));
		}

		xine_event_dispose_queue(queue);
	}

	return ctx->state == stream_state_ok;
}

int xine_checker_init(struct xine_checker *checker, struct log *log)
{
	checker->log = log;

	checker->xine = xine_new();
	if (checker->xine == NULL)
		log_error(log, "failed to create xine object");
	else
	{
		xine_init(checker->xine);
		checker->ao = xine_open_audio_driver(checker->xine, "none", NULL);
		if (checker->ao == NULL)
			log_error(log, "failed to create audio driver object");
		else
		{
			checker->vo = xine_open_video_driver(checker->xine, "none", XINE_VISUAL_TYPE_NONE, NULL);
			if (checker->vo == NULL)
				log_error(log, "failed to create video driver object");
			else
			{
				checker->st = xine_stream_new(checker->xine, checker->ao, checker->vo);
				if (checker->st != NULL)
					return 1;
				log_error(log, "failed to create xine stream object, error code %d", xine_get_error(NULL));
				xine_close_video_driver(checker->xine, checker->vo);
			}
			xine_close_audio_driver(checker->xine, checker->ao);
		}
		xine_exit(checker->xine);
	}

	return 0;
}

void xine_checker_deinit(struct xine_checker *checker)
{
	xine_dispose(checker->st);
	xine_close_video_driver(checker->xine, checker->vo);
	xine_close_audio_driver(checker->xine, checker->ao);
	xine_exit(checker->xine);
}

int xine_checker_check_uri(struct xine_checker *checker, const char *uri, double timeout)
{
	struct stream_context ctx;
	int result = 0;

	if (timeout <= 0.0)
	{
		log_error(xine_checker_log(checker), "failed to check uri %s: invalid timeout %.2lf", uri, timeout);
		return 0;
	}

	if (stream_context_init(&ctx, checker, uri))
	{
		result = stream_context_check(&ctx, timeout);
		stream_context_deinit(&ctx);
	}

	return result;
}
xine_checker.h (text/x-chdr, 437 B)
#ifndef _XINE_CHECKER_H_
#define _XINE_CHECKER_H_

#include <xine.h>

struct log;

struct xine_checker
{
	struct log *log;

	xine_t *xine;
	xine_audio_port_t *ao;
	xine_video_port_t *vo;
	xine_stream_t *st;
};

int xine_checker_init(struct xine_checker *checker, struct log *log);
void xine_checker_deinit(struct xine_checker *checker);

int xine_checker_check_uri(struct xine_checker *checker, const char *uri, double timeout);

#endif
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.