static gchar * render_master_m3u8_playlist (Job *job) { GString *master_m3u8_playlist; gchar *p, *value; gint i; master_m3u8_playlist = g_string_new (""); g_string_append_printf (master_m3u8_playlist, M3U8_HEADER_TAG); if (jobdesc_m3u8streaming_version (job->description) == 0) { g_string_append_printf (master_m3u8_playlist, M3U8_VERSION_TAG, 3); } else { g_string_append_printf (master_m3u8_playlist, M3U8_VERSION_TAG, jobdesc_m3u8streaming_version (job->description)); } for (i = 0; i < job->output->encoder_count; i++) { p = g_strdup_printf ("encoder.%d.elements.x264enc.property.bitrate", i); value = jobdesc_element_property_value (job->description, p); if (value != NULL) { GST_INFO ("job %s with m3u8 output, append end tag", job->name); g_string_append_printf (master_m3u8_playlist, M3U8_STREAM_INF_TAG, 1, value); g_string_append_printf (master_m3u8_playlist, "encoder/%d/playlist.m3u8<%%parameters%%>\n", i); g_free (value); } g_free (p); } p = master_m3u8_playlist->str; g_string_free (master_m3u8_playlist, FALSE); return p; }
/* * job_reset: * @job: job object * * reset job stat * */ void job_reset (Job *job) { gchar *stat, **stats, **cpustats; GstDateTime *start_time; gint i; EncoderOutput *encoder; guint version, window_size; *(job->output->state) = JOB_STATE_VOID_PENDING; g_file_get_contents ("/proc/stat", &stat, NULL, NULL); stats = g_strsplit (stat, "\n", 10); cpustats = g_strsplit (stats[0], " ", 10); job->start_ctime = 0; for (i = 1; i < 8; i++) { job->start_ctime += g_ascii_strtoull (cpustats[i], NULL, 10); } job->last_ctime = 0; job->last_utime = 0; job->last_stime = 0; g_free (stat); g_strfreev (stats); g_strfreev (cpustats); start_time = gst_date_time_new_now_local_time (); if (job->last_start_time != NULL) { g_free (job->last_start_time); } job->last_start_time = gst_date_time_to_iso8601_string (start_time); gst_date_time_unref (start_time); /* is live job with m3u8streaming? */ if (!(job->is_live) || !(jobdesc_m3u8streaming (job->description))) { return; } version = jobdesc_m3u8streaming_version (job->description); if (version == 0) { version = 3; } window_size = jobdesc_m3u8streaming_window_size (job->description); for (i = 0; i < job->output->encoder_count; i++) { encoder = &(job->output->encoders[i]); /* encoder dvr sequence */ encoder->sequence = job->output->sequence; /* reset m3u8 playlist */ if (encoder->m3u8_playlist != NULL) { m3u8playlist_free (encoder->m3u8_playlist); } encoder->m3u8_playlist = m3u8playlist_new (version, window_size, 0); } }
/* * job_reset: * @job: job object * * reset job stat * */ void job_reset (Job *job) { gchar *stat, **stats, **cpustats; GstDateTime *start_time; gint i; EncoderOutput *encoder; guint version, window_size; struct sigevent sev; struct mq_attr attr; gchar *name; g_file_get_contents ("/proc/stat", &stat, NULL, NULL); stats = g_strsplit (stat, "\n", 10); cpustats = g_strsplit (stats[0], " ", 10); job->start_ctime = 0; for (i = 1; i < 8; i++) { job->start_ctime += g_ascii_strtoull (cpustats[i], NULL, 10); } job->last_ctime = 0; job->last_utime = 0; job->last_stime = 0; g_free (stat); g_strfreev (stats); g_strfreev (cpustats); start_time = gst_date_time_new_now_local_time (); if (job->last_start_time != NULL) { g_free (job->last_start_time); } job->last_start_time = gst_date_time_to_iso8601_string (start_time); gst_date_time_unref (start_time); /* is live job with m3u8streaming? */ if (!(job->is_live) || !(jobdesc_m3u8streaming (job->description))) { return; } version = jobdesc_m3u8streaming_version (job->description); if (version == 0) { version = 3; } window_size = jobdesc_m3u8streaming_window_size (job->description); for (i = 0; i < job->output->encoder_count; i++) { encoder = &(job->output->encoders[i]); name = g_strdup_printf ("/%s.%d", job->name, i); /* encoder dvr sequence */ encoder->sequence = job->output->sequence; /* reset m3u8 playlist */ if (encoder->m3u8_playlist != NULL) { m3u8playlist_free (encoder->m3u8_playlist); } encoder->m3u8_playlist = m3u8playlist_new (version, window_size, 0); /* reset message queue */ if (encoder->mqdes != -1) { if (mq_close (encoder->mqdes) == -1) { GST_ERROR ("mq_close %s error: %s", name, g_strerror (errno)); } if (mq_unlink (name) == -1) { GST_ERROR ("mq_unlink %s error: %s", name, g_strerror (errno)); } } attr.mq_flags = 0; attr.mq_maxmsg = 10; attr.mq_msgsize = 128; attr.mq_curmsgs = 0; encoder->mqdes = mq_open (name, O_RDONLY | O_CREAT | O_NONBLOCK, 0666, &attr); if (encoder->mqdes == -1) { GST_ERROR ("mq_open error : %s", g_strerror (errno)); } sev.sigev_notify = SIGEV_THREAD; sev.sigev_notify_function = notify_function; sev.sigev_notify_attributes = NULL; sev.sigev_value.sival_ptr = encoder; if (mq_notify (encoder->mqdes, &sev) == -1) { GST_ERROR ("mq_notify error : %s", g_strerror (errno)); } g_free (name); } }