/
testtheoraplay.c
72 lines (60 loc) · 1.86 KB
1
2
3
4
5
6
7
8
9
10
/**
* TheoraPlay; multithreaded Ogg Theora/Ogg Vorbis decoding.
*
* Please see the file LICENSE.txt in the source's root directory.
*
* This file written by Ryan C. Gordon.
*/
#include <stdio.h>
#include <unistd.h>
11
#include <string.h>
12
13
#include "theoraplay.h"
14
static void dofile(const char *fname, const THEORAPLAY_VideoFormat vidfmt)
15
{
16
THEORAPLAY_Decoder *decoder = NULL;
17
18
const THEORAPLAY_VideoFrame *video = NULL;
const THEORAPLAY_AudioPacket *audio = NULL;
19
20
printf("Trying file '%s' ...\n", fname);
21
decoder = THEORAPLAY_startDecodeFile(fname, 20, vidfmt);
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
while (THEORAPLAY_isDecoding(decoder))
{
video = THEORAPLAY_getVideo(decoder);
if (video)
{
printf("Got video frame (%u ms)!\n", video->playms);
THEORAPLAY_freeVideo(video);
} // if
audio = THEORAPLAY_getAudio(decoder);
if (audio)
{
printf("Got %d frames of audio (%u ms)!\n", audio->frames, audio->playms);
THEORAPLAY_freeAudio(audio);
} // if
if (!video && !audio)
usleep(10000);
} // while
if (THEORAPLAY_decodingError(decoder))
printf("There was an error decoding this file!\n");
else
printf("done with this file!\n");
THEORAPLAY_stopDecode(decoder);
} // dofile
int main(int argc, char **argv)
{
THEORAPLAY_VideoFormat vidfmt = THEORAPLAY_VIDFMT_YV12;
53
int i;
54
55
56
for (i = 1; i < argc; i++)
{
57
58
59
60
61
62
if (strcmp(argv[i], "--rgb") == 0)
vidfmt = THEORAPLAY_VIDFMT_RGB;
else if (strcmp(argv[i], "--rgba") == 0)
vidfmt = THEORAPLAY_VIDFMT_RGBA;
else if (strcmp(argv[i], "--yv12") == 0)
vidfmt = THEORAPLAY_VIDFMT_YV12;
63
else
64
dofile(argv[i], vidfmt);
65
66
67
68
69
70
71
} // for
printf("done all files!\n");
return 0;
} // main
// end of testtheoraplay.c ...