static void child_watch_cb (GPid pid, gint status, Job *job) { /* Close pid */ g_spawn_close_pid (pid); job->age += 1; job->worker_pid = 0; if (WIFEXITED (status) && (WEXITSTATUS (status) == 0)) { GST_ERROR ("Job with pid %d normaly exit, status is %d", pid, WEXITSTATUS (status)); *(job->output->state) = GST_STATE_NULL; job->eos = TRUE; } if (WIFEXITED (status) && (WEXITSTATUS (status) != 0)) { GST_ERROR ("Job with pid %d abnormaly exit, status is %d", pid, WEXITSTATUS (status)); *(job->output->state) = GST_STATE_NULL; job->eos = TRUE; } if (WIFSIGNALED (status)) { gchar *ret; if (*(job->output->state) == GST_STATE_PAUSED) { GST_ERROR ("Job with pid %d exit on an unhandled signal and paused, stopping gstreamill...", pid); *(job->output->state) = GST_STATE_NULL; return; } GST_ERROR ("Job with pid %d exit on an unhandled signal, restart.", pid); job_reset (job); ret = create_job_process (job); if (g_str_has_suffix (ret, "failure")) { /* create process failure, clean from job list */ *(job->output->state) = GST_STATE_NULL; } GST_ERROR ("create_job_process: %s", ret); g_free (ret); } return; }
/** * gstreamill_job_start: * @job: (in): json type of job description. * * Returns: json type of job execution result. */ gchar * gstreamill_job_start (Gstreamill *gstreamill, gchar *job_desc) { gchar *p, *name; Job *job; if (!jobdesc_is_valid (job_desc)) { p = g_strdup_printf ("{\n \"result\": \"failure\",\n \"reason\": \"invalid job\"\n}"); return p; } if (jobdesc_is_live (job_desc)) { GST_ERROR ("live job arrived:\n%s", job_desc); } else { GST_ERROR ("transcode job arrived:\n%s", job_desc); } /* create job object */ name = jobdesc_get_name (job_desc); if (get_job (gstreamill, name) != NULL) { GST_ERROR ("start job failure, duplicated name %s.", name); p = g_strdup_printf ("{\n \"result\": \"failure\",\n \"reason\": \"duplicated name\"\n}"); g_free (name); return p; } job = job_new ("job", job_desc, "name", name, "exe_path", gstreamill->exe_path, NULL); g_free (name); /* job initialize */ job->log_dir = gstreamill->log_dir; g_mutex_init (&(job->access_mutex)); job->is_live = jobdesc_is_live (job_desc); job->eos = FALSE; job->current_access = 0; job->age = 0; job->last_start_time = NULL; if (job_initialize (job, gstreamill->daemon) != 0) { p = g_strdup_printf ("{\n \"result\": \"failure\",\n \"reason\": \"initialize job failure\"\n}"); g_object_unref (job); return p; } if (job->is_live && (job_output_initialize (job) != 0)) { p = g_strdup_printf ("{\n \"result\": \"failure\",\n \"reason\": \"initialize job output failure\"\n}"); g_object_unref (job); return p; } /* reset and start job */ job_reset (job); if (gstreamill->daemon) { guint64 stat; stat = create_job_process (job); if (stat == JOB_STATE_PLAYING) { GST_ERROR ("Start job %s success", job->name); g_mutex_lock (&(gstreamill->job_list_mutex)); gstreamill->job_list = g_slist_append (gstreamill->job_list, job); g_mutex_unlock (&(gstreamill->job_list_mutex)); p = g_strdup_printf ("{\n \"name\": \"%s\",\n\"result\": \"success\"\n}", job->name); } else { GST_ERROR ("Start job %s failure, return stat: %s", job->name, job_state_get_name (stat)); g_object_unref (job); p = g_strdup_printf ("{\n \"result\": \"failure\",\n \"reason\": \"create process failure\"\n}"); } } else { job_encoders_output_initialize (job); if (job_start (job) == 0) { g_mutex_lock (&(gstreamill->job_list_mutex)); gstreamill->job_list = g_slist_append (gstreamill->job_list, job); g_mutex_unlock (&(gstreamill->job_list_mutex)); p = g_strdup ("{\n \"result\": \"success\"\n}"); } else { p = g_strdup_printf ("{\n \"result\": \"failure\",\n \"reason\": \"unknown\"\n}"); } } return p; }
static void child_watch_cb (GPid pid, gint status, Job *job) { /* Close pid */ g_spawn_close_pid (pid); job->age += 1; job->worker_pid = 0; if (WIFEXITED (status) && (WEXITSTATUS (status) == 0)) { GST_ERROR ("Job %s normaly exit, status is %d", job->name, WEXITSTATUS (status)); *(job->output->state) = JOB_STATE_NULL; job->eos = TRUE; return; } if (WIFEXITED (status) && (WEXITSTATUS (status) != 0)) { if (WEXITSTATUS (status) < 100) { GST_ERROR ("Start job failure: subprocess return %d and don't restart it.", WEXITSTATUS (status)); return; } else { GST_ERROR ("Job %s exit on critical error return %d, restart ...", job->name, WEXITSTATUS (status)); job_reset (job); if (create_job_process (job) == JOB_STATE_PLAYING) { GST_ERROR ("Restart job %s success", job->name); } else { /* create process failure, clean from job list */ GST_ERROR ("Restart job %s failure", job->name); *(job->output->state) = JOB_STATE_NULL; } } } if (WIFSIGNALED (status)) { if (*(job->output->state) == JOB_STATE_PAUSED) { GST_ERROR ("Job %s exit on signal and paused, stopping gstreamill...", job->name); *(job->output->state) = JOB_STATE_NULL; return; } if (!job->is_live) { GST_ERROR ("Nonlive job %s exit on an unhandled signal.", job->name); *(job->output->state) = JOB_STATE_NULL; job->eos = TRUE; return; } GST_ERROR ("Live job %s exit on an unhandled signal, restart.", job->name); job_reset (job); if (create_job_process (job) == JOB_STATE_PLAYING) { GST_ERROR ("Restart job %s success", job->name); } else { /* create process failure, clean from job list */ GST_ERROR ("Restart job %s failure", job->name); *(job->output->state) = JOB_STATE_NULL; } } return; }
/** * gstreamill_job_start: * @job: (in): json type of job description. * * Returns: json type of job execution result. */ gchar * gstreamill_job_start (Gstreamill *gstreamill, gchar *job_desc) { gchar *p, *name; Job *job; if (!jobdesc_is_valid (job_desc)) { p = g_strdup ("Invalid job"); return p; } if (jobdesc_is_live (job_desc)) { GST_ERROR ("live job arrived"); } else { GST_ERROR ("transcode job arrived"); } /* create job object */ name = jobdesc_get_name (job_desc); if (get_job (gstreamill, name) != NULL) { GST_ERROR ("start live job failure, duplicated name %s.", name); p = g_strdup_printf ("start live job failure, duplicated name %s.", name); g_free (name); return p; } job = job_new ("job", job_desc, "name", name, NULL); g_free (name); /* job initialize */ job->log_dir = gstreamill->log_dir; g_mutex_init (&(job->access_mutex)); job->is_live = jobdesc_is_live (job_desc); job->eos = FALSE; job->current_access = 0; job->age = 0; job->last_start_time = NULL; if (job_initialize (job, gstreamill->daemon) != 0) { p = g_strdup ("initialize job failure"); g_object_unref (job); return p; } /* reset and start job */ job_reset (job); if (gstreamill->daemon) { p = create_job_process (job); GST_ERROR ("%s: %s", p, job->name); if (g_str_has_suffix (p, "success")) { g_mutex_lock (&(gstreamill->job_list_mutex)); gstreamill->job_list = g_slist_append (gstreamill->job_list, job); g_mutex_unlock (&(gstreamill->job_list_mutex)); } else { g_object_unref (job); } } else { if (job_start (job) == 0) { g_mutex_lock (&(gstreamill->job_list_mutex)); gstreamill->job_list = g_slist_append (gstreamill->job_list, job); g_mutex_unlock (&(gstreamill->job_list_mutex)); p = g_strdup ("success"); } else { p = g_strdup ("failure"); } } return p; }