File: gmyth_test_livetv.c

package info (click to toggle)
gmyth 1%3A0.7.1-1
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 2,256 kB
  • ctags: 1,230
  • sloc: ansic: 11,662; sh: 8,936; makefile: 222
file content (157 lines) | stat: -rw-r--r-- 4,420 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
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
#include <glib-object.h>

#include "common.h"

#include <gmyth/gmyth_uri.h>
#include <gmyth/gmyth_backendinfo.h>
#include <gmyth/gmyth_livetv.h>
#include <gmyth/gmyth_file.h>
#include <gmyth/gmyth_file_transfer.h>
#include <gmyth/gmyth_file_local.h>
#include <gmyth/gmyth_common.h>

#define URI_DEFAULT	"myth://192.168.3.165:6543/livetv?channel=9"

static          gboolean
test_livetv_setup(gchar * uri)
{
    GMythLiveTV    *livetv = NULL;
    GMythFile      *file = NULL;
    gchar          *channel_name = NULL;
    gboolean        ret = TRUE;
    gboolean        live_tv = FALSE;

    if (NULL == uri)
        uri = g_strdup(URI_DEFAULT);

    GMythURI       *gmyth_uri = gmyth_uri_new_with_value(uri);

    GMythBackendInfo *backend_info = gmyth_backend_info_new_with_uri(uri);
    live_tv = gmyth_uri_is_livetv(gmyth_uri);
    if (live_tv) {
        livetv = gmyth_livetv_new(backend_info);

        gchar          *ch = gmyth_uri_get_channel_name(gmyth_uri);
        if (ch != NULL)
            channel_name = ch;

        if (channel_name != NULL) {
            if (gmyth_livetv_channel_name_setup(livetv, channel_name) ==
                FALSE) {
                g_debug("LiveTV setup felt down on error.");
                ret = FALSE;
                goto init_failed;
            }
        } else {
            if (gmyth_livetv_setup(livetv) == FALSE) {
                g_debug("LiveTV setup felt down on error");
                ret = FALSE;
                goto init_failed;
            }
        }

        file = GMYTH_FILE(gmyth_livetv_create_file_transfer(livetv));

        if (NULL == file) {
            g_debug("[LiveTV] FileTransfer equals to NULL");
            ret = FALSE;
            goto init_failed;
        }

        /*
         * Check if the file is local to this specific client renderer 
         */
        if (gmyth_uri_is_local_file(gmyth_uri))
            ret = gmyth_file_local_open(GMYTH_FILE_LOCAL(file));
        else
            ret =
                gmyth_file_transfer_open(GMYTH_FILE_TRANSFER(file),
                                         livetv->uri !=
                                         NULL ? gmyth_uri_get_path(livetv->
                                                                   uri) :
                                         livetv->proginfo->pathname->str);

        if (!ret) {
            g_debug
                ("Error: couldn't open the FileTransfer from LiveTV source!");
            goto init_failed;
        }
    } else {

        /*
         * Check if the file is local to this specific client renderer,
         * and tries to open a local connection 
         */
        if (gmyth_uri_is_local_file(gmyth_uri)) {
            g_debug("Opening local file connection to download...");
            file = GMYTH_FILE(gmyth_file_local_new(backend_info));
            ret = gmyth_file_local_open(GMYTH_FILE_LOCAL(file));
        } else {
            g_debug("Opening remote file connection to download...");
            file = GMYTH_FILE(gmyth_file_transfer_new(backend_info));
            ret = gmyth_file_transfer_open(GMYTH_FILE_TRANSFER(file), uri);
        }

    }                           /* if (else) - recorded FileTransfer */

    if (NULL == file) {
        g_debug("FileTransfer is NULL");
        ret = FALSE;
        goto init_failed;
    }
    g_debug("uri = %s", uri);

    if (ret == FALSE) {
        g_debug
            ("MythTV FileTransfer request failed when setting up socket connection!");
        goto init_failed;
    }

    g_debug("MythTV FileTransfer filesize = %lld",
            gmyth_file_get_filesize(file));

  init_failed:
    if (livetv != NULL)
        g_object_unref(livetv);

    if (file != NULL)
        g_object_unref(file);

    // if ( uri != NULL )
    // g_free( uri );

    if (gmyth_uri != NULL)
        g_object_unref(gmyth_uri);

    // if ( backend_info != NULL )
    // g_object_unref( backend_info );

    return ret;

}

gint
main(gint args, const gchar ** argv)
{
    gboolean        ret;

    g_type_init();

    g_thread_init(NULL);

    fprintf(stdout, SYNC_STRING);
    fflush(NULL);
    getchar();

    if (args > 1)
        ret = test_livetv_setup(argv[1]);
    else
        ret = test_livetv_setup(NULL);

    if (!ret)
        g_debug("Error when running LiveTV setup test script!");
    else
        g_debug("LiveTV setup test script finished with success.");

    return (0);
}