Example #1
0
/*            snappy's main function             */
int
main (int argc, char *argv[])
{
  UserInterface *ui = NULL;
  GstEngine *engine = NULL;
  ClutterActor *video_texture;
  ClutterGstVideoSink *sink;

  gboolean ok, blind = FALSE, fullscreen = FALSE, hide = FALSE, loop = FALSE;
  gboolean secret = FALSE, tags = FALSE;
  gint ret = 0;
  gchar *uri = NULL;
  gchar *suburi = NULL;
  GList *uri_list;
  GOptionContext *context;
  gchar *data_dir;

  ClutterInitError ci_err;

#ifdef ENABLE_DBUS
  SnappyMP *mp_obj = NULL;
#endif

  context = g_option_context_new ("<media file> - Play movie files");

  clutter_set_windowing_backend (CLUTTER_WINDOWING_X11);
  ci_err = gtk_clutter_init (&argc, &argv);
  if (ci_err != CLUTTER_INIT_SUCCESS)
    goto quit;

  /* Try to find the path for our resources in case snappy was relocated */
  data_dir = g_strdup (SNAPPY_DATA_DIR);
  if (!g_file_test (data_dir, G_FILE_TEST_EXISTS | G_FILE_TEST_IS_DIR)) {
    gchar *root_dir;

#ifdef G_OS_WIN32
    root_dir = g_win32_get_package_installation_directory_of_module (NULL);
#elif !defined(G_OS_UNIX)
    gchar *exec_path;
    gchar *bin_dir;

    exec_path = g_file_read_link ("/proc/self/exe", NULL);
    bin_dir = g_path_get_dirname (exec_path);
    root_dir = g_build_filename (bin_dir, "..", NULL);
    g_free (exec_path);
    g_free (bin_dir);
#else
    root_dir = NULL;
#endif
    if (root_dir != NULL) {
      data_dir = g_build_filename (root_dir, "share", "snappy", NULL);
      g_free (root_dir);
    }
  }

  /* Process command arguments */
  uri_list = process_args (argc, argv, &blind, &fullscreen, &hide,
      &loop, &secret, &suburi, &tags, context);

  gst_init (&argc, &argv);
  clutter_gst_init (NULL, NULL);

  /* User Interface */
  ui = g_new (UserInterface, 1);
  ui->uri_list = uri_list;
  ui->blind = blind;
  ui->fullscreen = fullscreen;
  ui->hide = hide;
  ui->tags = tags;
  ui->data_dir = data_dir;
  interface_init (ui);

  /* Gstreamer engine */
  engine = g_new (GstEngine, 1);
  sink = clutter_gst_video_sink_new ();
  if (sink == NULL) {
    g_print ("ERROR: Failed to create clutter-gst sink element\n");
    return FALSE;
  }
  video_texture = g_object_new (CLUTTER_TYPE_ACTOR, "content",
      g_object_new (CLUTTER_GST_TYPE_CONTENT, "sink", sink, NULL),
      "name", "texture", NULL);

  ok = engine_init (engine, sink);
  if (!ok)
    goto quit;

  engine->secret = secret;
  engine->loop = loop;

  ui->engine = engine;
  ui->texture = video_texture;

  gst_bus_add_watch (engine->bus, bus_call, ui);
  gst_object_unref (engine->bus);

  /* Get uri to load */
  if (uri_list) {
    uri = g_list_first (uri_list)->data;
    /* based on video filename we can guess subtitle file (.srt files only) */
    if (NULL == suburi) {
      gchar suburi_path_guessing[1024]; //buffer
      gchar *uri_no_extension = strip_filename_extension (uri);

      sprintf (suburi_path_guessing, "%s.srt", uri_no_extension);
      /* subtitle file exists, defaults for it */
      if (g_file_test (g_filename_from_uri (suburi_path_guessing, NULL, NULL),
              G_FILE_TEST_EXISTS))
        suburi = suburi_path_guessing;
    }
  }

  /* Load engine and start interface */
  engine_load_uri (engine, uri);
  interface_start (ui, uri);

  /* Load subtitle file if available */
  if (suburi != NULL) {
    suburi = clean_uri (suburi);
    set_subtitle_uri (engine, suburi);
  }

  /* Start playing if we have a URI to play */
  if (uri) {
    change_state (engine, "Paused");
    change_state (engine, "Playing");
  }
#ifdef ENABLE_DBUS
  /* Start MPRIS Dbus object */
  mp_obj = g_new (SnappyMP, 1);
  mp_obj->engine = engine;
  mp_obj->ui = ui;
  load_dlna (mp_obj);
#endif

  /* Main loop */
  gtk_main ();

  /* Close snappy */
  close_down (ui, engine);
#ifdef ENABLE_DBUS
  close_dlna (mp_obj);
#endif

quit:
  g_list_free (uri_list);
  g_option_context_free (context);

  return ret;
}
Example #2
0
int process_input_files(settings_t *settings)
{
    int i = 0;
    int ret = 1;
    int file_type = 0;
    char *current_file = (char *)0;
    char tmpbuf[MAX_BUF_LEN] = {0};
    char output_file[MAX_BUF_LEN] = {0};
    char resampled_wav_file[MAX_BUF_LEN] = {0};
    char input_file_full_path_name[MAX_BUF_LEN] = {0};

    if (settings)
    {
        for(i = 0; i < settings->num_input_files; i++)
        {
            get_full_path_name(settings->input_files[i],
                               input_file_full_path_name,MAX_BUF_LEN);
            current_file = input_file_full_path_name;

            if (settings->verbose)
            {
                printf("Processing file: %s\n",current_file);
            }

            strncpy(tmpbuf,current_file,MAX_BUF_LEN);
            strip_filename_extension(tmpbuf);
            generate_output_filename(settings,tmpbuf,
                                     output_file,MAX_BUF_LEN);

            file_type = get_file_type(current_file);
            switch(file_type)
            {
                case FILE_TYPE_OGG:
                    if (settings->oggdec_enabled &&
                        ogg_decode(settings,current_file,output_file,
                                   oggdec_callback))
                    {
                        fprintf(stderr,"Failed to decode ogg file.\n");
                        return ret;
                    }
                    break;
                case FILE_TYPE_MP3:
                    if (settings->mpgdec_enabled &&
                        mpg_decode(settings,current_file,output_file,
                                   mpgdec_callback))
                    {
                        fprintf(stderr,"Failed to decode mp3 file.\n");
                        return ret;
                    }
                    break;
                case FILE_TYPE_WAV:
                    if (resample_wav_file(settings,current_file,
                                          output_file))
                    {
                        fprintf(stderr,"Failed to resample wav file.\n");
                        return ret;
                    }
                    break;
            }

            /* finally, verify the generated output file */
            if (wav_verify_format(output_file))
            {
                /*
                  if we have sox enabled and we've just generated
                  this wav file, we should try to resample it here
                  to make it a valid format
                */
                if ((file_type != FILE_TYPE_WAV) &&
                    (settings->sox_enabled))
                {
                    strncpy(tmpbuf,current_file,MAX_BUF_LEN);
                    strip_filename_extension(tmpbuf);
                    strncat(tmpbuf,"-resampled",MAX_BUF_LEN-strlen(tmpbuf));
                    generate_output_filename(settings,tmpbuf,
                                             resampled_wav_file,
                                             MAX_BUF_LEN);

                    if (resample_wav_file(settings,output_file,
                                          resampled_wav_file))
                    {
                        fprintf(stderr,"Failed to resample wav file.\n");
                    }
                    else
                    {
                        /* delete the original generated wav file */
                        delete_file(output_file);
                        strncpy(output_file,resampled_wav_file,MAX_BUF_LEN);
                        goto valid_input_wav;
                    }
                }
                fprintf(stderr,"Processed output file %s is "
                        "invalid!  Skipping.\n",output_file);
                continue;
            }
            else
            {
              valid_input_wav:
                /*
                  if all went well up to this point, store the
                  output filename in the settings object
                */
                if (settings_add_output_file(settings,output_file))
                {
                    fprintf(stderr,"Failed to add valid output file "
                            "%s.  Skipping.\n",output_file);
                    continue;
                }
            }
        }
        ret = (settings->num_output_files ? 0 : 1);
    }
    return ret;
}