]> git.sesse.net Git - vlc/blob - test/libvlc/media_player.c
0e028582ea157f3b1a355d343718bb4fa7a4f5cd
[vlc] / test / libvlc / media_player.c
1 /*
2  * media_player.c - libvlc smoke test
3  *
4  * $Id$
5  */
6
7 /**********************************************************************
8  *  Copyright (C) 2007 RĂ©mi Denis-Courmont.                           *
9  *  This program is free software; you can redistribute and/or modify *
10  *  it under the terms of the GNU General Public License as published *
11  *  by the Free Software Foundation; version 2 of the license, or (at *
12  *  your option) any later version.                                   *
13  *                                                                    *
14  *  This program is distributed in the hope that it will be useful,   *
15  *  but WITHOUT ANY WARRANTY; without even the implied warranty of    *
16  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.              *
17  *  See the GNU General Public License for more details.              *
18  *                                                                    *
19  *  You should have received a copy of the GNU General Public License *
20  *  along with this program; if not, you can get it from:             *
21  *  http://www.gnu.org/copyleft/gpl.html                              *
22  **********************************************************************/
23
24 #include "test.h"
25
26 static void wait_playing(libvlc_media_player_t *mp)
27 {
28     libvlc_state_t state;
29     do {
30         state = libvlc_media_player_get_state (mp);
31     } while(state != libvlc_Playing &&
32             state != libvlc_Error &&
33             state != libvlc_Ended );
34
35     state = libvlc_media_player_get_state (mp);
36     assert(state == libvlc_Playing || state == libvlc_Ended);
37 }
38
39 static void wait_paused(libvlc_media_player_t *mp)
40 {
41     libvlc_state_t state;
42     do {
43         state = libvlc_media_player_get_state (mp);
44     } while(state != libvlc_Paused &&
45             state != libvlc_Ended );
46
47     state = libvlc_media_player_get_state (mp);
48     assert(state == libvlc_Paused || state == libvlc_Ended);
49 }
50
51 /* Test a bunch of A/V properties. This most does nothing since the current
52  * test file contains a dummy audio track. This is a smoke test. */
53 static void test_audio_video(libvlc_media_player_t *mp)
54 {
55     bool fs = libvlc_get_fullscreen(mp);
56     libvlc_set_fullscreen(mp, true);
57     assert(libvlc_get_fullscreen(mp));
58     libvlc_set_fullscreen(mp, false);
59     assert(!libvlc_get_fullscreen(mp));
60     libvlc_toggle_fullscreen(mp);
61     assert(libvlc_get_fullscreen(mp));
62     libvlc_toggle_fullscreen(mp);
63     assert(!libvlc_get_fullscreen(mp));
64     libvlc_set_fullscreen(mp, fs);
65     assert(libvlc_get_fullscreen(mp) == fs);
66
67     assert(libvlc_video_get_scale(mp) == 0.); /* default */
68     libvlc_video_set_scale(mp, 0.); /* no-op */
69     libvlc_video_set_scale(mp, 2.5);
70     assert(libvlc_video_get_scale(mp) == 2.5);
71     libvlc_video_set_scale(mp, 0.);
72     libvlc_video_set_scale(mp, 0.); /* no-op */
73     assert(libvlc_video_get_scale(mp) == 0.);
74 }
75
76 static void test_media_player_set_media(const char** argv, int argc)
77 {
78     const char * file = test_default_sample;
79
80     log ("Testing set_media\n");
81
82     libvlc_instance_t *vlc = libvlc_new (argc, argv);
83     assert (vlc != NULL);
84
85     libvlc_media_t *md = libvlc_media_new_path (vlc, file);
86     assert (md != NULL);
87
88     libvlc_media_player_t *mp = libvlc_media_player_new (vlc);
89     assert (mp != NULL);
90
91     libvlc_media_player_set_media (mp, md);
92
93     libvlc_media_release (md);
94
95     libvlc_media_player_play (mp);
96
97     wait_playing (mp);
98
99     libvlc_media_player_stop (mp);
100     libvlc_media_player_release (mp);
101     libvlc_release (vlc);
102 }
103
104 static void test_media_player_play_stop(const char** argv, int argc)
105 {
106     libvlc_instance_t *vlc;
107     libvlc_media_t *md;
108     libvlc_media_player_t *mi;
109     const char * file = test_default_sample;
110
111     log ("Testing play and pause of %s\n", file);
112
113     vlc = libvlc_new (argc, argv);
114     assert (vlc != NULL);
115
116     md = libvlc_media_new_path (vlc, file);
117     assert (md != NULL);
118
119     mi = libvlc_media_player_new_from_media (md);
120     assert (mi != NULL);
121
122     libvlc_media_release (md);
123
124     libvlc_media_player_play (mi);
125
126     wait_playing (mi);
127
128     libvlc_media_player_stop (mi);
129     libvlc_media_player_release (mi);
130     libvlc_release (vlc);
131 }
132
133 static void test_media_player_pause_stop(const char** argv, int argc)
134 {
135     libvlc_instance_t *vlc;
136     libvlc_media_t *md;
137     libvlc_media_player_t *mi;
138     const char * file = test_default_sample;
139
140     log ("Testing pause and stop of %s\n", file);
141
142     vlc = libvlc_new (argc, argv);
143     assert (vlc != NULL);
144
145     md = libvlc_media_new_path (vlc, file);
146     assert (md != NULL);
147
148     mi = libvlc_media_player_new_from_media (md);
149     assert (mi != NULL);
150
151     libvlc_media_release (md);
152
153     libvlc_media_player_play (mi);
154
155     log ("Waiting for playing\n");
156
157     wait_playing (mi);
158
159     libvlc_media_player_set_pause (mi, true);
160     log ("Waiting for pause\n");
161     wait_paused (mi);
162
163     libvlc_media_player_stop (mi);
164     libvlc_media_player_release (mi);
165     libvlc_release (vlc);
166 }
167
168
169 int main (void)
170 {
171     test_init();
172
173     test_media_player_set_media (test_defaults_args, test_defaults_nargs);
174     test_media_player_play_stop (test_defaults_args, test_defaults_nargs);
175     test_media_player_pause_stop (test_defaults_args, test_defaults_nargs);
176
177     return 0;
178 }