test/testtheoraplay.c
author Ryan C. Gordon <icculus@icculus.org>
Fri, 26 Aug 2016 01:38:09 -0400
changeset 61 fb533bb8633e
parent 34 e3acfcbbf364
permissions -rw-r--r--
Fixed incorrect video frame timestamps in various circumstances.

The audio should probably respect the Vorbis granule position, too, but we'll
cross that bridge when we come to it.
icculus@2
     1
/**
icculus@2
     2
 * TheoraPlay; multithreaded Ogg Theora/Ogg Vorbis decoding.
icculus@2
     3
 *
icculus@2
     4
 * Please see the file LICENSE.txt in the source's root directory.
icculus@2
     5
 *
icculus@2
     6
 *  This file written by Ryan C. Gordon.
icculus@2
     7
 */
icculus@2
     8
icculus@2
     9
#include <stdio.h>
icculus@2
    10
#include <unistd.h>
icculus@26
    11
#include <string.h>
icculus@2
    12
#include "theoraplay.h"
icculus@2
    13
icculus@26
    14
static void dofile(const char *fname, const THEORAPLAY_VideoFormat vidfmt)
icculus@2
    15
{
icculus@7
    16
    THEORAPLAY_Decoder *decoder = NULL;
icculus@29
    17
    const THEORAPLAY_VideoFrame *video = NULL;
icculus@29
    18
    const THEORAPLAY_AudioPacket *audio = NULL;
icculus@2
    19
icculus@26
    20
    printf("Trying file '%s' ...\n", fname);
icculus@34
    21
    decoder = THEORAPLAY_startDecodeFile(fname, 20, vidfmt);
icculus@26
    22
    while (THEORAPLAY_isDecoding(decoder))
icculus@26
    23
    {
icculus@26
    24
        video = THEORAPLAY_getVideo(decoder);
icculus@26
    25
        if (video)
icculus@26
    26
        {
icculus@26
    27
            printf("Got video frame (%u ms)!\n", video->playms);
icculus@26
    28
            THEORAPLAY_freeVideo(video);
icculus@26
    29
        } // if
icculus@26
    30
icculus@26
    31
        audio = THEORAPLAY_getAudio(decoder);
icculus@26
    32
        if (audio)
icculus@26
    33
        {
icculus@26
    34
            printf("Got %d frames of audio (%u ms)!\n", audio->frames, audio->playms);
icculus@26
    35
            THEORAPLAY_freeAudio(audio);
icculus@26
    36
        } // if
icculus@26
    37
icculus@26
    38
        if (!video && !audio)
icculus@26
    39
            usleep(10000);
icculus@26
    40
    } // while
icculus@26
    41
icculus@26
    42
    if (THEORAPLAY_decodingError(decoder))
icculus@26
    43
        printf("There was an error decoding this file!\n");
icculus@26
    44
    else
icculus@26
    45
        printf("done with this file!\n");
icculus@26
    46
icculus@26
    47
    THEORAPLAY_stopDecode(decoder);
icculus@26
    48
} // dofile
icculus@26
    49
icculus@26
    50
int main(int argc, char **argv)
icculus@26
    51
{
icculus@26
    52
    THEORAPLAY_VideoFormat vidfmt = THEORAPLAY_VIDFMT_YV12;
icculus@2
    53
    int i;
icculus@26
    54
icculus@2
    55
    for (i = 1; i < argc; i++)
icculus@2
    56
    {
icculus@26
    57
        if (strcmp(argv[i], "--rgb") == 0)
icculus@26
    58
            vidfmt = THEORAPLAY_VIDFMT_RGB;
icculus@26
    59
        else if (strcmp(argv[i], "--rgba") == 0)
icculus@26
    60
            vidfmt = THEORAPLAY_VIDFMT_RGBA;
icculus@26
    61
        else if (strcmp(argv[i], "--yv12") == 0)
icculus@26
    62
            vidfmt = THEORAPLAY_VIDFMT_YV12;
icculus@5
    63
        else
icculus@26
    64
            dofile(argv[i], vidfmt);
icculus@2
    65
    } // for
icculus@2
    66
icculus@2
    67
    printf("done all files!\n");
icculus@2
    68
    return 0;
icculus@2
    69
} // main
icculus@2
    70
icculus@2
    71
// end of testtheoraplay.c ...
icculus@2
    72