summaryrefslogtreecommitdiff
path: root/tests/test-start-stop.c
blob: 9bc1ea98ae992b59aded8c7825fd182caf20d727 (plain)
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
/*
 * Clutter-GStreamer.
 *
 * GStreamer integration library for Clutter.
 *
 * test-start-stop.c - Test switching between 2 media files.
 *
 * Authored by Shuang He <shuang.he@intel.com>
 *
 * Copyright (C) 2009 Intel Corporation
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the
 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 * Boston, MA 02111-1307, USA.
 */

#include <stdlib.h>

#include <clutter/clutter.h>
#include <clutter-gst/clutter-gst.h>

char *video_files[] = {NULL, NULL};

void
on_error (ClutterGstPlayer *player)
{
  g_print ("error\n");
  clutter_main_quit ();
}

gboolean
test (gpointer data)
{
  static int count = 1;
  static ClutterGstPlayback *player = NULL;
  static char *uri[2] = {NULL, NULL};
  const char *playing_uri = NULL;

  /* Check until we get video playing */
  if (!clutter_gst_player_get_playing (CLUTTER_GST_PLAYER (data)))
    return TRUE;

  if (CLUTTER_GST_PLAYBACK (data) != player)
    {
      player = CLUTTER_GST_PLAYBACK (data);
      count = 1;
      g_free(uri[0]);
      uri[0] = NULL;
      g_free(uri[1]);
      uri[1] = NULL;
    }

  clutter_gst_playback_set_filename (player, video_files[count & 1]);
  g_print ("playing %s\n", video_files[count & 1]);

  if (uri[count & 1] == NULL)
    {
      uri[count & 1] = g_strdup (clutter_gst_playback_get_uri (player));
      g_assert (uri[count & 1] != NULL);
    }

  /* See if it's still playing */
  g_assert (clutter_gst_player_get_playing (CLUTTER_GST_PLAYER (player)));

  /* See if it's already change to play correct file */
  playing_uri = clutter_gst_playback_get_uri (player);
  g_assert_cmpstr (playing_uri, ==, uri[count & 1]);

  if (count ++ > 10)
    {
      clutter_gst_player_set_playing (CLUTTER_GST_PLAYER (player), FALSE);
      clutter_main_quit ();
      return FALSE;
    }

  return TRUE;
}


int
main (int argc, char *argv[])
{
  ClutterInitError    error;
  ClutterColor        stage_color = { 0x00, 0x00, 0x00, 0x00 };
  ClutterActor       *stage = NULL;
  ClutterActor       *video = NULL;
  ClutterGstPlayback *player = NULL;

  if (argc < 3)
    {
      g_print ("%s video1 video2\n", argv[0]);
      exit (1);
    }

  video_files[0] = argv[1];
  video_files[1] = argv[2];

  error = clutter_gst_init (&argc, &argv);
  g_assert (error == CLUTTER_INIT_SUCCESS);

  stage = clutter_stage_new ();
  clutter_actor_set_background_color (stage, &stage_color);

  player = clutter_gst_playback_new ();

  video = g_object_new (CLUTTER_TYPE_ACTOR,
                        "content", g_object_new (CLUTTER_GST_TYPE_ASPECTRATIO,
                                                 "player", player,
                                                 NULL),
                        "width", clutter_actor_get_width (stage),
                        "height", clutter_actor_get_height (stage),
                        NULL);
  clutter_actor_add_child (stage, video);

  g_signal_connect (player,
                    "error",
                    G_CALLBACK(on_error),
                    video);
  g_timeout_add (5000, test, player);
  clutter_gst_playback_set_filename (player, video_files[0]);
  clutter_gst_player_set_audio_volume (CLUTTER_GST_PLAYER (player), 0.5);
  clutter_gst_player_set_playing (CLUTTER_GST_PLAYER (player), TRUE);

  clutter_actor_show (stage);
  clutter_main ();

  return EXIT_SUCCESS;
}