media.c 2.7 KB
Newer Older
Pierre's avatar
Pierre committed
1 2 3 4 5 6 7
/*
 * media_player.c - libvlc smoke test
 *
 * $Id$
 */

/**********************************************************************
Pierre's avatar
Pierre committed
8
 *  Copyright (C) 2010 Pierre d'Herbemont.                            *
Pierre's avatar
Pierre committed
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
 *  This program is free software; you can redistribute and/or modify *
 *  it under the terms of the GNU General Public License as published *
 *  by the Free Software Foundation; version 2 of the license, or (at *
 *  your option) any later version.                                   *
 *                                                                    *
 *  This program 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 General Public License for more details.              *
 *                                                                    *
 *  You should have received a copy of the GNU General Public License *
 *  along with this program; if not, you can get it from:             *
 *  http://www.gnu.org/copyleft/gpl.html                              *
 **********************************************************************/

#include "test.h"

static void preparsed_changed(const libvlc_event_t *event, void *user_data)
{
    (void)event;

    int *received = user_data;
    *received = true;
}

static void test_media_preparsed(const char** argv, int argc)
{
36 37
    // We use this image file because "empty.voc" has no track.
    const char * file = SRCDIR"/samples/image.jpg";
Pierre's avatar
Pierre committed
38 39 40 41 42 43 44 45 46

    log ("Testing set_media\n");

    libvlc_instance_t *vlc = libvlc_new (argc, argv);
    assert (vlc != NULL);

    libvlc_media_t *media = libvlc_media_new_path (vlc, file);
    assert (media != NULL);

Pierre's avatar
Pierre committed
47
    volatile int received = false;
Pierre's avatar
Pierre committed
48

Pierre's avatar
Pierre committed
49
    // Check to see if we are properly receiving the event.
Pierre's avatar
Pierre committed
50
    libvlc_event_manager_t *em = libvlc_media_event_manager (media);
51
    libvlc_event_attach (em, libvlc_MediaParsedChanged, preparsed_changed, (void*)&received);
Pierre's avatar
Pierre committed
52

Pierre's avatar
Pierre committed
53 54 55
    // Parse the media. This is synchronous.
    libvlc_media_parse(media);

Pierre's avatar
Pierre committed
56 57 58 59
    // Wait to see if we properly receive preparsed.
    while (!received);

    // We are good, now check Elementary Stream info.
60
    libvlc_media_track_info_t *tracks = NULL;
61
    int num = libvlc_media_get_tracks_info(media, &tracks);
62 63 64 65

#warning libvlc_media_get_tracks_info is a broken function.
    // This is broken.
    // assert(num == 1);
66 67
    if (num != 1)
        printf("WARNING: libvlc_media_get_tracks_info is not working.");
68

69 70
    if (num > 0)
        free(tracks);
Pierre's avatar
Pierre committed
71 72 73 74 75 76 77 78 79 80 81 82 83

    libvlc_media_release (media);
    libvlc_release (vlc);
}

int main (void)
{
    test_init();

    test_media_preparsed (test_defaults_args, test_defaults_nargs);

    return 0;
}