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

This is an example of how to use the TV Service's Live APIs.

Author
Liu Kun k2.li.nosp@m.u@sa.nosp@m.msung.nosp@m..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
*
* @author Liu Kun k2.liu@samsung.com
* 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 <signal.h>
#include <stdlib.h>
#include <time.h>
#include <glib/gprintf.h>
#include "tv_service_logger.h"
static GMainLoop *loop = NULL;
static TvServiceLive live_handle = NULL;
gint temp_freq = 0;
gint temp_mod = 0;
gint apid = 0;
gint vpid = 0;
gint ppid = 0;
gint change_freq = 0;
gint change_mod = 0;
gint change_apid = 0;
gint change_vpid = 0;
gint change_ppid = 0;
gint pro_num = 0;
gint change_pro_num = 0;
gint audio_mute;
gint video_mute;
gint tune_type = 0;
gboolean
exit_loop (gpointer user_data)
{
printf ("EXIT LOOP!!!!!!!!!!!\n");
if (live_handle) {
tv_service_live_destroy (live_handle);
}
g_main_loop_quit (loop);
return FALSE;
}
gboolean
change_video_mute (gpointer user_data)
{
TvServiceLive live_handle = user_data;
gboolean mute = FALSE;
tv_service_live_get_video_mute (live_handle, &mute);
printf ("tv_service_live_get_video_mute before setting = %d\n", mute);
tv_service_live_set_video_mute (live_handle, video_mute);
tv_service_live_get_video_mute (live_handle, &mute);
printf ("tv_service_live_get_video_mute after setting = %d\n", mute);
if (video_mute == TRUE) {
video_mute = FALSE;
}
return FALSE;
}
gboolean
change_audio_mute (gpointer user_data)
{
TvServiceLive live_handle = user_data;
gint res;
printf ("Before tv_service_live_set_audio_mute, mute[%d]\n", audio_mute);
res = tv_service_live_set_audio_mute (live_handle, audio_mute);
if (res != TVS_ERROR_OK) {
printf ("ERROR !!! tv_service_live_set_audio_mute fail!\n");
return FALSE;
}
gboolean mute_temp = FALSE;
tv_service_live_get_audio_mute (live_handle, &mute_temp);
printf ("After tv_service_live_set_audio_mute[%d], tv_service_live_get_audio_mute = [%d]\n", audio_mute, mute_temp);
if (audio_mute == TRUE) {
audio_mute = FALSE;
}
return FALSE;
}
gboolean
change_audio_volume(gpointer user_data)
{
gdouble volume = 0;
TvServiceLive live_handle = user_data;
gint res;
res = tv_service_live_get_volume (live_handle, &volume);
if (res != TVS_ERROR_OK) {
printf ("ERROR !!! tv_service_live_get_volume fail!\n");
return FALSE;
}
printf ("tv_service_live_get_volume = %lf\n", volume);
printf ("Before tv_service_live_set_volume, volume[%lf]\n", volume);
res = tv_service_live_set_volume (live_handle, volume);
if (res != TVS_ERROR_OK) {
printf ("ERROR !!! tv_service_live_set_volume fail!\n");
return FALSE;
}
return FALSE;
}
gboolean
change_channel (gpointer user_data)
{
TvServiceLive live_handle = user_data;
if (tune_type == 0) {
printf ("change_channel, handle:%p, freq:%d, mod:%d, apid:%d, vpid:%d, ppid:%d\n",\
live_handle, change_freq, change_mod, change_apid, change_vpid, change_ppid);
if (TVS_ERROR_OK != tv_service_live_tune_full (live_handle, change_freq, change_mod, change_apid, change_vpid, change_ppid)) {
printf ("ERROR !!! In main tv_service_live_tune_full failed!\n");
return FALSE;
}
} else if (tune_type == 1) {
printf ("change_channel, handle:%p, freq:%d, mod:%d, pro_number:%d\n",\
live_handle, change_freq, change_mod, change_pro_num);
if (TVS_ERROR_OK != tv_service_live_tune_by_program_number (live_handle, change_freq, change_mod, change_pro_num)) {
printf ("ERROR !!! In main tv_service_live_tune_by_program_number failed!\n");
return FALSE;
}
}
printf ("change_channel finish\n");
return FALSE;
}
gboolean
__tune_pause(gpointer user_data){
TvServiceLive live_handle = user_data;
}
gboolean
__tune_resume(gpointer user_data){
TvServiceLive live_handle = user_data;
}
gboolean
live_tune_by_program_number (gpointer user_data)
{
TvServiceLive live_handle = user_data;
printf ("Before tv_service_live_tune_by_program_number, handle:%p, freq:%d, mod:%d, pro_num:%d\n",\
live_handle, temp_freq, temp_mod, pro_num);
if (TVS_ERROR_OK != tv_service_live_tune_by_program_number (live_handle, temp_freq, temp_mod, pro_num)) {
printf ("ERROR !!! tv_service_live_tune_by_program_number failed!\n");
return FALSE;
}
return FALSE;
}
static void
app_callback (TvServiceLiveEvent event, gpointer user_data, const gpointer data)
{
switch (event) {
{
gboolean *lock_status = (gboolean *)data;
printf ("tv_service_callback: get tuner locked callback:%d\n", *lock_status);
}
break;
{
printf ("tv_service_callback: set resolution width:%d,height:%d\n", res_data->width,res_data->height);
}
break;
printf ("event channel lock\n");
break;
printf ("event channel unlock\n");
break;
printf ("event auto destroy\n");
live_handle = NULL;
exit_loop (NULL);
break;
default:
printf ("get callback_type: %d\n", event);
}
return;
}
void
signal_handle (int signum)
{
printf ("In signal handle!\n");
if (live_handle) {
tv_service_live_destroy (live_handle);
}
g_main_loop_quit (loop);
exit (0);
return;
}
int
main (int argc, char ** argv)
{
int isSimpleTest = 0;
int isServiceIDTest = 0;
int service_id = 0;
if (argc == 13) {
temp_freq = atoi (argv[1]);
temp_mod = atoi (argv[2]);
vpid = atoi (argv[3]);
apid = atoi (argv[4]);
ppid = atoi (argv[5]);
change_freq = atoi (argv[6]);
change_mod = atoi (argv[7]);
change_vpid = atoi (argv[8]);
change_apid = atoi (argv[9]);
change_ppid = atoi (argv[10]);
pro_num = atoi (argv[11]);
change_pro_num= atoi (argv[12]);
} else if (argc == 6){
temp_freq = atoi (argv[1]);
temp_mod = atoi (argv[2]);
vpid = atoi (argv[3]);
apid = atoi (argv[4]);
ppid = atoi (argv[5]);
isSimpleTest = 1;
} else if (argc == 3){
isServiceIDTest = 1;
service_id = atoi (argv[2]);
printf("This is tune test by service id \n");
printf("service id is %d\n", service_id);
} else if (argc == 4){
isServiceIDTest = 2;
service_id = atoi (argv[2]);
printf("This is tune pause resume test by service id \n");
printf("service id is %d\n", service_id);
} else if (argc == 2){
int input_value = atoi(argv[1]);
printf("This is vconf test\n");
printf("test value is %d\n",input_value);
if(!tv_service_vconf_set_last_channel(input_value))
printf("Fail to set vconf\n");
int value = 0;
if(!tv_service_vconf_get_last_channel(&value))
printf("Fail to get vconf\n");
else
printf("Vconf value is %d\n", value);
return -1;
} else {
printf("usage : tv-service-live-test 485000000 7 17 20 16 473000000 7 17 20 16 1 2\n");
return -1;
}
loop = g_main_loop_new (NULL, FALSE);
if (TVS_ERROR_OK != tv_service_live_create (&live_handle)) {
printf ("ERROR !!! tv_service_live_create failed!\n");
return -1;
}
printf ("After tv_service_live_create\n");
tv_service_live_register_callback (live_handle, app_callback, NULL);
printf ("After tv_service_live_register_callback\n");
if(isServiceIDTest == 1){
if(TVS_ERROR_OK != tv_service_live_tune(live_handle, service_id)) {
printf ("ERROR !!! tv_service_live_tune failed!\n");
return -1;
}
}
else if(isServiceIDTest == 2){
if(TVS_ERROR_OK != tv_service_live_tune(live_handle, service_id)) {
printf ("ERROR !!! tv_service_live_tune failed!\n");
return -1;
}
g_timeout_add_seconds (20, __tune_pause, live_handle);
g_timeout_add_seconds (40, __tune_resume, live_handle);
}
else {
/* tv_service_live_set_tune_full */
printf ("Before tv_service_live_tune_full, handle:%p, freq:%d, mod:%d, vpid:%d, apid:%d, ppid:%d\n",\
live_handle, temp_freq, temp_mod, vpid, apid, ppid);
if(isSimpleTest == 1){
if(TVS_ERROR_OK != tv_service_live_tune_full (live_handle, temp_freq, temp_mod, apid, vpid, ppid)) {
printf ("ERROR !!! tv_service_live_tune_full failed!\n");
return -1;
}
}
else {
if(TVS_ERROR_OK != tv_service_live_tune_full (live_handle, temp_freq, temp_mod, apid, vpid, ppid)) {
printf ("ERROR !!! tv_service_live_tune_full failed!\n");
return -1;
}
g_timeout_add_seconds (3, change_audio_volume, live_handle);
audio_mute = TRUE;
g_timeout_add_seconds (8, change_audio_mute, live_handle);
g_timeout_add_seconds (10, change_audio_mute, live_handle);
video_mute = TRUE;
g_timeout_add_seconds (12, change_video_mute, live_handle);
g_timeout_add_seconds (14, change_video_mute, live_handle);
g_timeout_add_seconds (18, change_channel, live_handle);
// g_timeout_add_seconds (25, live_tune_by_program_number, live_handle);
g_timeout_add_seconds (28, change_audio_volume, live_handle);
audio_mute = TRUE;
g_timeout_add_seconds (33, change_audio_mute, live_handle);
g_timeout_add_seconds (35, change_audio_mute, live_handle);
video_mute = TRUE;
g_timeout_add_seconds (37, change_video_mute, live_handle);
g_timeout_add_seconds (39, change_video_mute, live_handle);
g_timeout_add_seconds (50, exit_loop, NULL);
}
}
//signal (SIGINT, signal_handle);
g_main_loop_run (loop);
if (live_handle) {
tv_service_live_destroy (live_handle);
}
return 0;
}