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