void gss_program_add_jpeg_block (GssProgram * program, GssTransaction * t) { GString *s = t->s; if (program->state == GSS_PROGRAM_STATE_RUNNING) { if (program->jpegsink) { GSS_P ("<img id='id%d' src='/%s-snapshot.jpeg' alt='snapshot'>", t->id, GSS_OBJECT_NAME (program)); if (t->script == NULL) t->script = g_string_new (""); g_string_append_printf (t->script, "$(document).ready(function() {\n" "document.getElementById('id%d').src=" "'/%s-snapshot.jpeg?_=' + new Date().getTime();\n" "var refreshId = setInterval(function() {\n" "document.getElementById('id%d').src=" "'/%s-snapshot.jpeg?_=' + new Date().getTime();\n" " }, 1000);\n" "});\n", t->id, GSS_OBJECT_NAME (program), t->id, GSS_OBJECT_NAME (program)); t->id++; } else { GSS_P ("<img src='/no-snapshot.jpg' alt='no snapshot'>\n"); } } else { GSS_P ("<img src='/offline.jpg' alt='offline'>\n"); } }
static void gss_program_add_resources (GssProgram * program) { char *s; s = g_strdup_printf ("/%s", GSS_OBJECT_NAME (program)); program->resource = gss_server_add_resource (GSS_OBJECT_SERVER (program), s, GSS_RESOURCE_UI, GSS_TEXT_HTML, gss_program_get_resource, NULL, gss_config_post_resource, program); g_free (s); s = g_strdup_printf ("/%s.frag", GSS_OBJECT_NAME (program)); gss_server_add_resource (GSS_OBJECT_SERVER (program), s, GSS_RESOURCE_UI, GSS_TEXT_PLAIN, gss_program_frag_resource, NULL, NULL, program); g_free (s); s = g_strdup_printf ("/%s.list", GSS_OBJECT_NAME (program)); gss_server_add_resource (GSS_OBJECT_SERVER (program), s, GSS_RESOURCE_UI, GSS_TEXT_PLAIN, gss_program_list_resource, NULL, NULL, program); g_free (s); s = g_strdup_printf ("/%s-snapshot.png", GSS_OBJECT_NAME (program)); gss_server_add_resource (GSS_OBJECT_SERVER (program), s, GSS_RESOURCE_UI, "image/png", gss_program_png_resource, NULL, NULL, program); g_free (s); s = g_strdup_printf ("/%s-snapshot.jpeg", GSS_OBJECT_NAME (program)); gss_server_add_resource (GSS_OBJECT_SERVER (program), s, 0, "image/jpeg", gss_program_jpeg_resource, NULL, NULL, program); g_free (s); }
static void gss_server_resource_main_page (GssTransaction * t) { GString *s; GList *g; s = t->s = g_string_new (""); gss_html_header (t); GSS_P ("<ul class='thumbnails'>\n"); for (g = t->server->programs; g; g = g_list_next (g)) { GssProgram *program = g->data; if (program->is_archive) continue; GSS_P ("<li class='span4'>\n"); GSS_P ("<div class='thumbnail'>\n"); GSS_P ("<a href=\"/%s%s%s\">", GSS_OBJECT_NAME (program), t->session ? "?session_id=" : "", t->session ? t->session->session_id : ""); gss_program_add_jpeg_block (program, t); GSS_P ("</a>\n"); GSS_P ("<h5>%s</h5>\n", GSS_OBJECT_SAFE_TITLE (program)); GSS_P ("</div>\n"); GSS_P ("</li>\n"); } GSS_P ("</ul>\n"); if (t->server->enable_vod) { GSS_P ("<ul class='thumbnails'>\n"); for (g = t->server->programs; g; g = g_list_next (g)) { GssProgram *program = g->data; if (!program->is_archive) continue; GSS_P ("<li class='span4'>\n"); GSS_P ("<div class='thumbnail'>\n"); GSS_P ("<a href=\"/%s%s%s\">", GSS_OBJECT_NAME (program), t->session ? "?session_id=" : "", t->session ? t->session->session_id : ""); gss_program_add_jpeg_block (program, t); GSS_P ("</a>\n"); GSS_P ("<h5>%s</h5>\n", GSS_OBJECT_SAFE_TITLE (program)); GSS_P ("</div>\n"); GSS_P ("</li>\n"); } GSS_P ("</ul>\n"); } gss_html_footer (t); }
void gss_vod_setup (GssServer * server) { GDir *dir; dir = g_dir_open (server->archive_dir, 0, NULL); if (dir) { const gchar *name = g_dir_read_name (dir); while (name) { if (g_str_has_suffix (name, ".webm")) { GssProgram *program; GssStream *stream; char *s; program = gss_server_add_program (server, name); program->is_archive = TRUE; stream = gss_stream_new (GSS_STREAM_TYPE_WEBM, 640, 360, 600); gss_program_add_stream (program, stream); s = g_strdup_printf ("%s-%dx%d-%dkbps%s.%s", GSS_OBJECT_NAME (program), stream->width, stream->height, stream->bitrate / 1000, gss_stream_type_get_mod (stream->type), gss_stream_type_get_ext (stream->type)); gst_object_set_name (GST_OBJECT (stream), s); g_free (s); s = g_strdup_printf ("/%s", GSS_OBJECT_NAME (stream)); gss_server_add_resource (GSS_OBJECT_SERVER (program), s, GSS_RESOURCE_HTTP_ONLY, gss_stream_type_get_content_type (stream->type), vod_resource_chunked, NULL, NULL, program); g_free (s); } name = g_dir_read_name (dir); } g_dir_close (dir); } }
static void gss_server_resource_list (GssTransaction * t) { GString *s; GList *g; s = t->s = g_string_new (""); for (g = t->server->programs; g; g = g_list_next (g)) { GssProgram *program = g->data; GSS_P ("%s\n", GSS_OBJECT_NAME (program)); } }
/** * gss_program_add_stream_table: * @program: The program to fetch the streams from. * @s: The string to append the streams to. * * This function populates the list of streams in the rendered page * by iterating through the streams in the passed in program. * */ void gss_program_add_stream_table (GssProgram * program, GString * s) { GList *g; gboolean have_hls = FALSE; GSS_A ("<table class='table table-striped table-bordered " "table-condensed'>\n"); GSS_A ("<thead>\n"); GSS_A ("<tr>\n"); GSS_A ("<th>Type</th>\n"); GSS_A ("<th>Size</th>\n"); GSS_A ("<th>Bitrate</th>\n"); GSS_A ("<th></th>\n"); GSS_A ("<th></th>\n"); GSS_A ("</tr>\n"); GSS_A ("</thead>\n"); GSS_A ("<tbody>\n"); for (g = program->streams; g; g = g_list_next (g)) { GssStream *stream = g->data; GSS_A ("<tr>\n"); GSS_P ("<td>%s</td>\n", gss_stream_type_get_name (stream->type)); GSS_P ("<td>%dx%d</td>\n", stream->width, stream->height); GSS_P ("<td>%d kbps</td>\n", stream->bitrate / 1000); GSS_P ("<td><a href=\"%s\">stream</a></td>\n", stream->location); GSS_P ("<td><a href=\"%s\">playlist</a></td>\n", stream->playlist_location); GSS_A ("</tr>\n"); if (stream->type == GSS_STREAM_TYPE_M2TS_H264BASE_AAC || stream->type == GSS_STREAM_TYPE_M2TS_H264MAIN_AAC) { have_hls = TRUE; } } if (have_hls) { GSS_A ("<tr>\n"); GSS_P ("<td colspan='5'><a href='/%s.m3u8'>HLS</a></td>\n", GSS_OBJECT_NAME (program)); GSS_A ("</tr>\n"); } GSS_A ("<tr>\n"); GSS_P ("<td colspan='5'><a class='btn btn-mini' href='/'>" "<i class='icon-plus'></i>Add</a></td>\n"); GSS_A ("</tr>\n"); GSS_A ("</tbody>\n"); GSS_A ("</table>\n"); }
GssProgram * gss_server_get_program_by_name (GssServer * server, const char *name) { GList *g; g_return_val_if_fail (GSS_IS_SERVER (server), NULL); g_return_val_if_fail (name != NULL, NULL); for (g = server->programs; g; g = g_list_next (g)) { GssProgram *program = g->data; if (strcmp (GSS_OBJECT_NAME (program), name) == 0) { return program; } } return NULL; }
static void vod_resource_chunked (GssTransaction * t) { GssProgram *program = (GssProgram *) t->resource->priv; GssVOD *vod; char *chunk; int len; char *s; vod = g_malloc0 (sizeof (GssVOD)); vod->msg = t->msg; vod->client = t->client; vod->server = t->server; s = g_strdup_printf ("%s/%s", t->server->archive_dir, GSS_OBJECT_NAME (program)); vod->fd = open (s, O_RDONLY); if (vod->fd < 0) { GST_WARNING_OBJECT (program, "file not found %s", s); g_free (s); g_free (vod); soup_message_set_status (t->msg, SOUP_STATUS_NOT_FOUND); return; } g_free (s); soup_message_set_status (t->msg, SOUP_STATUS_OK); soup_message_headers_set_encoding (t->msg->response_headers, SOUP_ENCODING_CHUNKED); chunk = g_malloc (SIZE); len = read (vod->fd, chunk, 65536); if (len < 0) { GST_ERROR_OBJECT (program, "read error"); } soup_message_body_append (t->msg->response_body, SOUP_MEMORY_TAKE, chunk, len); g_signal_connect (t->msg, "wrote-chunk", G_CALLBACK (vod_wrote_chunk), vod); g_signal_connect (t->msg, "finished", G_CALLBACK (vod_finished), vod); }
void gss_program_add_video_block (GssProgram * program, GssTransaction * t, int max_width) { GString *s = t->s; GList *g; int width = 0; int height = 0; int flash_only = TRUE; if (program->state != GSS_PROGRAM_STATE_RUNNING) { GSS_P ("<img src='/offline.jpg' alt='offline'>\n"); return; } if (program->streams == NULL) { if (program->jpegsink) { gss_html_append_image_printf (s, "/%s-snapshot.jpeg", 0, 0, "snapshot image", GSS_OBJECT_NAME (program)); } else { GSS_P ("<img src='/no-snapshot.jpg' alt='no snapshot'>\n"); } } for (g = program->streams; g; g = g_list_next (g)) { GssStream *stream = g->data; if (stream->width > width) width = stream->width; if (stream->height > height) height = stream->height; if (stream->type != GSS_STREAM_TYPE_FLV_H264BASE_AAC) { flash_only = FALSE; } } if (max_width != 0 && width > max_width) { height = max_width * 9 / 16; width = max_width; } if (GSS_OBJECT_SERVER (program)->enable_html5_video && !flash_only) { GSS_P ("<video controls=\"controls\" autoplay=\"autoplay\" " "id=video width=\"%d\" height=\"%d\">\n", width, height); for (g = g_list_last (program->streams); g; g = g_list_previous (g)) { GssStream *stream = g->data; if (stream->type == GSS_STREAM_TYPE_WEBM) { GSS_P ("<source src=\"%s\" type='video/webm; codecs=\"vp8, vorbis\"'>\n", stream->location); } } for (g = g_list_last (program->streams); g; g = g_list_previous (g)) { GssStream *stream = g->data; if (stream->type == GSS_STREAM_TYPE_OGG_THEORA_VORBIS) { GSS_P ("<source src=\"%s\" type='video/ogg; codecs=\"theora, vorbis\"'>\n", stream->location); } } for (g = g_list_last (program->streams); g; g = g_list_previous (g)) { GssStream *stream = g->data; if (stream->type == GSS_STREAM_TYPE_M2TS_H264BASE_AAC || stream->type == GSS_STREAM_TYPE_M2TS_H264MAIN_AAC) { GSS_P ("<source src=\"/%s.m3u8\" >\n", GSS_OBJECT_NAME (program)); break; } } } if (GSS_OBJECT_SERVER (program)->enable_cortado) { for (g = program->streams; g; g = g_list_next (g)) { GssStream *stream = g->data; if (stream->type == GSS_STREAM_TYPE_OGG_THEORA_VORBIS) { GSS_P ("<applet code=\"com.fluendo.player.Cortado.class\"\n" " archive=\"/cortado.jar\" width=\"%d\" height=\"%d\">\n" " <param name=\"url\" value=\"%s\"></param>\n" "</applet>\n", width, height, stream->location); break; } } } if (GSS_OBJECT_SERVER (program)->enable_flash) { for (g = program->streams; g; g = g_list_next (g)) { GssStream *stream = g->data; if (stream->type == GSS_STREAM_TYPE_FLV_H264BASE_AAC) { if (t->server->enable_osplayer) { GSS_P (" <object width='%d' height='%d' id='flvPlayer' " "type=\"application/x-shockwave-flash\" " "data=\"OSplayer.swf\">\n" " <param name='allowFullScreen' value='true'>\n" " <param name=\"allowScriptAccess\" value=\"always\"> \n" " <param name=\"movie\" value=\"OSplayer.swf\"> \n" " <param name=\"flashvars\" value=\"" "movie=%s" "&btncolor=0x333333" "&accentcolor=0x31b8e9" "&txtcolor=0xdddddd" "&volume=30" "&autoload=on" "&autoplay=off" "&vTitle=TITLE" "&showTitle=yes\">\n", width, height + 24, stream->location); if (program->enable_snapshot) { gss_html_append_image_printf (s, "/%s-snapshot.png", 0, 0, "snapshot image", GSS_OBJECT_NAME (program)); } GSS_P (" </object>\n"); } else if (t->server->enable_flowplayer) { GSS_P ("<a href='%s' style='display:block;width:%dpx;height:%dpx' id='player'>\n", stream->location, width, height); GSS_P ("Click to play video.\n"); #if 0 if (program->enable_snapshot) { gss_html_append_image_printf (s, "/%s-snapshot.png", 0, 0, "snapshot image", GSS_OBJECT_NAME (program)); } #endif GSS_P ("</a>\n"); } break; } } } else { if (program->enable_snapshot) { gss_html_append_image_printf (s, "/%s-snapshot.png", 0, 0, "snapshot image", GSS_OBJECT_NAME (program)); } } if (GSS_OBJECT_SERVER (program)->enable_html5_video && !flash_only) { GSS_A ("</video>\n"); } }