tv-service  0.1.0
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
tv_service_epg_live_test.c

This is an example of how to use the TV Service's interface to get program information while broadcasting.

Author
Tang Daoguang dguan.nosp@m.g.ta.nosp@m.ng@sa.nosp@m.msun.nosp@m.g.com
/* Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
#include <glib-object.h>
#include <stdlib.h>
#include <stdio.h>
#include <glib.h>
#include <glib/gprintf.h>
static TvServiceLive g_live_handle = NULL;
static TvServiceEpg g_epg_handle = NULL;
static GMainLoop *mainloop = NULL;
static void
print_epg_data (TvServiceEpgEventData * p_epg_data)
{
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 ("description = [%s]\n", p_epg_data->extended_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),
p_epg_data->start_time);
hour = p_epg_data->length_in_seconds / 3600;
min = (p_epg_data->length_in_seconds-hour * 3600) / 60;
sec = p_epg_data->length_in_seconds-hour * 3600 - min * 60;
g_printf ("duration: [%d:%d:%d]\n", hour, min, sec);
}
static gboolean
create_handle ()
{
if (!g_live_handle) {
error = tv_service_live_create (&g_live_handle);
if (error != TVS_ERROR_OK) {
g_printf ("tv_service_live_create failed, error code: [%d]\n", error);
return FALSE;
}
}
if (!g_epg_handle) {
error = tv_service_epg_create (&g_epg_handle);
if (error != TVS_ERROR_OK) {
g_printf ("tv_service_epg_create failed, error code: [%d]\n", error);
return FALSE;
}
}
return TRUE;
}
static void
destroy_handle ()
{
if (g_live_handle) {
tv_service_live_destroy (g_live_handle);
g_live_handle = NULL;
}
if (g_epg_handle) {
tv_service_epg_destroy (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;
TvServiceEpgEventData *p_tvs_data = NULL;
GList *epg_list = (GList *)epg_data;
for (index = 0; index < g_list_length (epg_list); index++) {
p_tvs_data = (TvServiceEpgEventData*)g_list_nth_data (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
live_callback (TvServiceLiveEvent event, gpointer user_data, const gpointer data)
{
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;
tv_service_live_register_callback (g_live_handle, live_callback, NULL);
tv_service_epg_register_callback (g_epg_handle, epg_callback, NULL);
error = tv_service_live_tune (g_live_handle, service_id);
if (error != TVS_ERROR_OK) {
g_printf ("tv_service_live_tune failed, error code: [%d]\n", error);
goto err;
}
error = tv_service_epg_get_current_program (g_epg_handle,
service_id,
epg_event_callback,
NULL);
if (error != TVS_ERROR_OK) {
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;
}