This is an example of how to use the TV Service's interface to get program information while broadcasting.
#include <glib-object.h>
#include <stdlib.h>
#include <stdio.h>
#include <glib.h>
#include <glib/gprintf.h>
static GMainLoop *mainloop = NULL;
static void
{
gint hour = 0;
gint min = 0;
gint sec = 0;
if (!p_epg_data)
return;
g_printf (
"service_id = [%d]\n", p_epg_data->
service_id);
g_printf (
"title = [%s]\n", p_epg_data->
title_text);
g_printf (
"current time = [%u]\n", p_epg_data->
current_time);
GDateTime *g_time = g_date_time_new_from_unix_utc (p_epg_data->
start_time);
g_printf ("Start time: [%d.%d.%d-%d:%d:%d], UTC: [%d]\n",
g_date_time_get_year (g_time),
g_date_time_get_month (g_time),
g_date_time_get_day_of_month (g_time),
g_date_time_get_hour (g_time),
g_date_time_get_minute (g_time),
g_date_time_get_second (g_time),
g_printf ("duration: [%d:%d:%d]\n", hour, min, sec);
}
static gboolean
create_handle ()
{
if (!g_live_handle) {
g_printf ("tv_service_live_create failed, error code: [%d]\n", error);
return FALSE;
}
}
if (!g_epg_handle) {
g_printf ("tv_service_epg_create failed, error code: [%d]\n", error);
return FALSE;
}
}
return TRUE;
}
static void
destroy_handle ()
{
if (g_live_handle) {
g_live_handle = NULL;
}
if (g_epg_handle) {
g_epg_handle = NULL;
}
return;
}
void
exit_handler (int signum)
{
destroy_handle ();
g_main_loop_quit (mainloop);
return;
}
gboolean
timeout_handler (gpointer user_data)
{
destroy_handle ();
g_main_loop_quit(mainloop);
return TRUE;
}
static void
epg_event_callback (
tvs_epg_event_e type, gpointer epg_data, gpointer user_data)
{
guint index=0;
GList *epg_list = (GList *)epg_data;
for (index = 0; index < g_list_length (epg_list); index++) {
if (NULL != p_tvs_data) {
g_printf ("EPG data info index: [%d]\n", index);
print_epg_data (p_tvs_data);
}
}
return;
}
static void
{
gboolean *lock_status;
switch (event) {
lock_status = (gboolean*) data;
g_printf ("tv_service_callback: get tuner locked callback:%d\n", *lock_status);
break;
g_printf ("event channel lock\n");
break;
g_printf ("event channel unlock\n");
break;
g_printf ("event auto destroy\n");
g_live_handle = NULL;
g_printf ("event auto destroy finish\n");
break;
default:
g_printf ("get callback_type: %d\n", event);
}
return;
}
static void
epg_callback (
tvs_epg_event_e type, gpointer user_data,
const gpointer data)
{
switch (type) {
g_printf ("epg auto destroy\n");
g_epg_handle = NULL;
break;
default:
g_printf ("event type[%d]\n", type);
break;
}
return;
}
int
main (int argc, char *argv[])
{
gint service_id = 0;
mainloop = g_main_loop_new (NULL, FALSE);
service_id = 1;
if (create_handle () != TRUE)
goto err;
g_printf ("tv_service_live_tune failed, error code: [%d]\n", error);
goto err;
}
service_id,
epg_event_callback,
NULL);
g_printf ("tv_service_epg_get_current_program failed, error code: [%d]\n", error);
goto err;
}
signal (SIGINT, exit_handler);
g_timeout_add_seconds (30, timeout_handler, NULL);
g_main_loop_run (mainloop);
err:
return 0;
}