Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Split this up into separate files.
  • Loading branch information
icculus committed Jun 10, 2011
1 parent c9d5cd4 commit 2184961
Show file tree
Hide file tree
Showing 3 changed files with 116 additions and 73 deletions.
53 changes: 53 additions & 0 deletions test/testtheoraplay.c
@@ -0,0 +1,53 @@
/**
* 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>
#include "theoraplay.h"

int main(int argc, char **argv)
{
THEORAPLAY_Decoder *decoder;
const THEORAPLAY_YuvVideoItem *video = NULL;
const THEORAPLAY_PcmAudioItem *audio = NULL;

int i;
for (i = 1; i < argc; i++)
{
printf("Trying file '%s' ...\n", argv[i]);
decoder = THEORAPLAY_startDecode(argv[i], 20);
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

printf("done with this file!\n");
THEORAPLAY_stopDecode(decoder);
} // for

printf("done all files!\n");
return 0;
} // main

// end of testtheoraplay.c ...

82 changes: 9 additions & 73 deletions theoraplay.c
@@ -1,3 +1,11 @@
/**
* 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.
*/

// I wrote this with a lot of peeking at the Theora example code in
// libtheora-1.1.1/examples/player_example.c, but this is all my own
// code.
Expand All @@ -12,27 +20,10 @@
#include <sys/stat.h>
#include <assert.h>

#include "theoraplay.h"
#include "theora/theoradec.h"
#include "vorbis/codec.h"

typedef struct THEORAPLAY_YuvVideoItem
{
unsigned int playms;
unsigned int width;
unsigned int height;
unsigned char *yuv;
struct THEORAPLAY_YuvVideoItem *next;
} THEORAPLAY_YuvVideoItem;

typedef struct THEORAPLAY_PcmAudioItem
{
unsigned int playms; // playback start time in milliseconds.
int channels;
int frames;
float *samples; // frames * channels float32 samples.
struct THEORAPLAY_PcmAudioItem *next;
} THEORAPLAY_PcmAudioItem;

typedef THEORAPLAY_YuvVideoItem YuvVideoItem;
typedef THEORAPLAY_PcmAudioItem PcmAudioItem;

Expand Down Expand Up @@ -76,18 +67,6 @@ typedef struct TheoraDecoder
PcmAudioItem *audiolisttail;
} TheoraDecoder;

typedef struct THEORAPLAY_Decoder THEORAPLAY_Decoder;
THEORAPLAY_Decoder *THEORAPLAY_startDecode(const char *fname,
const unsigned int maxframes);
void THEORAPLAY_stopDecode(THEORAPLAY_Decoder *decoder);
int THEORAPLAY_isDecoding(THEORAPLAY_Decoder *decoder);

const PcmAudioItem *THEORAPLAY_getAudio(THEORAPLAY_Decoder *decoder);
void THEORAPLAY_freeAudio(const PcmAudioItem *item);

const YuvVideoItem *THEORAPLAY_getVideo(THEORAPLAY_Decoder *decoder);
void THEORAPLAY_FreeVideo(const YuvVideoItem *item);

static void CleanupWorkerThread(TheoraDecoder *ctx);
static int FeedMoreOggData(TheoraDecoder *ctx);
static void QueueOggPage(TheoraDecoder *ctx, ogg_page *page);
Expand Down Expand Up @@ -592,48 +571,5 @@ static void *WorkerThreadEntry(void *_this)
return NULL;
} // WorkerThreadEntry



#if 1
int main(int argc, char **argv)
{
THEORAPLAY_Decoder *decoder;
const THEORAPLAY_YuvVideoItem *video = NULL;
const THEORAPLAY_PcmAudioItem *audio = NULL;

int i;
for (i = 1; i < argc; i++)
{
printf("Trying file '%s' ...\n", argv[i]);
decoder = THEORAPLAY_startDecode(argv[i], 20);
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

printf("done with this file!\n");
THEORAPLAY_stopDecode(decoder);
} // for

printf("done all files!\n");
return 0;
} // main
#endif

// end of theoraplay.cpp ...

54 changes: 54 additions & 0 deletions theoraplay.h
@@ -0,0 +1,54 @@
/**
* 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.
*/

#ifndef _INCL_THEORAPLAY_H_
#define _INCL_THEORAPLAY_H_

#ifdef __cplusplus
extern "C" {
#endif

typedef struct THEORAPLAY_Decoder THEORAPLAY_Decoder;

typedef struct THEORAPLAY_YuvVideoItem
{
unsigned int playms;
unsigned int width;
unsigned int height;
unsigned char *yuv;
struct THEORAPLAY_YuvVideoItem *next;
} THEORAPLAY_YuvVideoItem;

typedef struct THEORAPLAY_PcmAudioItem
{
unsigned int playms; // playback start time in milliseconds.
int channels;
int frames;
float *samples; // frames * channels float32 samples.
struct THEORAPLAY_PcmAudioItem *next;
} THEORAPLAY_PcmAudioItem;

THEORAPLAY_Decoder *THEORAPLAY_startDecode(const char *fname,
const unsigned int maxframes);
void THEORAPLAY_stopDecode(THEORAPLAY_Decoder *decoder);
int THEORAPLAY_isDecoding(THEORAPLAY_Decoder *decoder);

const THEORAPLAY_PcmAudioItem *THEORAPLAY_getAudio(THEORAPLAY_Decoder *decoder);
void THEORAPLAY_freeAudio(const THEORAPLAY_PcmAudioItem *item);

const THEORAPLAY_YuvVideoItem *THEORAPLAY_getVideo(THEORAPLAY_Decoder *decoder);
void THEORAPLAY_freeVideo(const THEORAPLAY_YuvVideoItem *item);

#ifdef __cplusplus
}
#endif

#endif /* include-once blocker. */

/* end of theoraplay.h ... */

0 comments on commit 2184961

Please sign in to comment.